OGMFile.java

  1. /* Copyright 2002-2013 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.orekit.files.ccsds;

  18. import java.util.ArrayList;
  19. import java.util.Arrays;
  20. import java.util.Collection;
  21. import java.util.Collections;
  22. import java.util.HashMap;
  23. import java.util.List;
  24. import java.util.Map;

  25. import org.apache.commons.math3.linear.MatrixUtils;
  26. import org.apache.commons.math3.linear.RealMatrix;
  27. import org.orekit.errors.OrekitException;
  28. import org.orekit.errors.OrekitMessages;
  29. import org.orekit.files.general.SatelliteInformation;
  30. import org.orekit.frames.Frame;
  31. import org.orekit.frames.LOFType;
  32. import org.orekit.orbits.PositionAngle;
  33. import org.orekit.time.AbsoluteDate;

  34. /** This class gathers the general state data present in both OPM and OMM files.
  35.  * <p>
  36.  * This class does not appear in the CCSDS standard, it is only a design
  37.  * feature of Orekit to reduce code duplication.
  38.  * </p>
  39.  * @author sports
  40.  * @since 6.1
  41.  */
  42. public abstract class OGMFile extends ODMFile {

  43.     /** Epoch of state vector and optional Keplerian elements. */
  44.     private AbsoluteDate epoch;

  45.     /** Orbit semi-major axis (m). */
  46.     private double a;

  47.     /** Orbit eccentricity. */
  48.     private double e;

  49.     /** Orbit inclination (rad). */
  50.     private double i;

  51.     /** Orbit right ascension of ascending node (rad). */
  52.     private double raan;

  53.     /** Orbit argument of pericenter (rad). */
  54.     private double pa;

  55.     /** Orbit anomaly (rad). */
  56.     private double anomaly;

  57.     /** Orbit anomaly type (mean or true). */
  58.     private PositionAngle anomalyType;

  59.     /** Spacecraft mass. */
  60.     private double mass;

  61.     /** Solar radiation pressure area (m^2). */
  62.     private double solarRadArea;

  63.     /** Solar radiation pressure coefficient. */
  64.     private double solarRadCoeff;

  65.     /** Drag area (m^2). */
  66.     private double dragArea;

  67.     /** Drag coefficient. */
  68.     private double dragCoeff;

  69.     /** Coordinate system for covariance matrix, for Local Orbital Frames. */
  70.     private LOFType covRefLofType;

  71.     /** Coordinate system for covariance matrix, for absolute frames.
  72.      * If not given it is set equal to refFrame. */
  73.     private Frame covRefFrame;

  74.     /** Position/Velocity covariance matrix. */
  75.     private RealMatrix covarianceMatrix;

  76.     /** Map of user defined parameter keywords and corresponding values. */
  77.     private Map<String, String> userDefinedParameters;

  78.     /** Tests whether the OPM contains Keplerian elements data. */
  79.     private boolean hasKeplerianElements;

  80.     /** Epoch comments. The list contains a string for each line of comment. */
  81.     private List<String> epochComment;

  82.     /** Keplerian elements comments. The list contains a string for each line of comment. */
  83.     private List<String> keplerianElementsComment;

  84.     /** Spacecraft data comments. The list contains a string for each line of comment. */
  85.     private List<String> spacecraftComment;

  86.     /** Covariance matrix data comments. The list contains a string for each line of comment. */
  87.     private List<String> covarianceComment;

  88.     /** Create a new OPM file object. */
  89.     OGMFile() {
  90.         mass                     = Double.NaN;
  91.         userDefinedParameters    = new HashMap<String, String>();
  92.         epochComment             = Collections.emptyList();
  93.         keplerianElementsComment = Collections.emptyList();
  94.         spacecraftComment        = Collections.emptyList();
  95.         covarianceComment        = Collections.emptyList();
  96.     };

  97.     /** Get epoch of state vector, Keplerian elements and covariance matrix data.
  98.      * @return epoch the epoch
  99.      */
  100.     public AbsoluteDate getEpoch() {
  101.         return epoch;
  102.     }

  103.     /** Set epoch of state vector, Keplerian elements and covariance matrix data.
  104.      * @param epoch the epoch to be set
  105.      */
  106.     void setEpoch(final AbsoluteDate epoch) {
  107.         this.epoch = epoch;
  108.     }

  109.     /** Get the orbit semi-major axis.
  110.      * @return the orbit semi-major axis
  111.      */
  112.     public double getA() {
  113.         return a;
  114.     }

  115.     /** Set the orbit semi-major axis.
  116.      * @param a the semi-major axis to be set
  117.      */
  118.     void setA(final double a) {
  119.         this.a = a;
  120.     }

  121.     /** Get the orbit eccentricity.
  122.      * @return the orbit eccentricity
  123.      */
  124.     public double getE() {
  125.         return e;
  126.     }

  127.     /** Set the orbit eccentricity.
  128.      * @param e the eccentricity to be set
  129.      */
  130.     void setE(final double e) {
  131.         this.e = e;
  132.     }

  133.     /** Get the orbit inclination.
  134.      * @return the orbit inclination
  135.      */
  136.     public double getI() {
  137.         return i;
  138.     }

  139.     /**Set the orbit inclination.
  140.      * @param i the inclination to be set
  141.      */
  142.     void setI(final double i) {
  143.         this.i = i;
  144.     }

  145.     /** Get the orbit right ascension of ascending node.
  146.      * @return the orbit right ascension of ascending node
  147.      */
  148.     public double getRaan() {
  149.         return raan;
  150.     }

  151.     /** Set the orbit right ascension of ascending node.
  152.      * @param raan the right ascension of ascending node to be set
  153.      */
  154.     void setRaan(final double raan) {
  155.         this.raan = raan;
  156.     }

  157.     /** Get the orbit argument of pericenter.
  158.      * @return the orbit argument of pericenter
  159.      */
  160.     public double getPa() {
  161.         return pa;
  162.     }

  163.     /** Set the orbit argument of pericenter.
  164.      * @param pa the argument of pericenter to be set
  165.      */
  166.     void setPa(final double pa) {
  167.         this.pa = pa;
  168.     }

  169.     /** Get the orbit anomaly.
  170.      * @return the orbit anomaly
  171.      */
  172.     public double getAnomaly() {
  173.         return anomaly;
  174.     }

  175.     /** Set the orbit anomaly.
  176.      * @param anomaly the anomaly to be set
  177.      */
  178.     void setAnomaly(final double anomaly) {
  179.         this.anomaly = anomaly;
  180.     }

  181.     /** Get the type of anomaly (true or mean).
  182.      * @return the type of anomaly
  183.      */
  184.     public PositionAngle getAnomalyType() {
  185.         return anomalyType;
  186.     }

  187.     /** Set the type of anomaly (true or mean).
  188.      * @param anomalyType the type of anomaly to be set
  189.      */
  190.     void setAnomalyType(final String anomalyType) {
  191.         this.anomalyType = PositionAngle.valueOf(anomalyType);
  192.     }

  193.     /** Get the spacecraft mass.
  194.      * @return the spacecraft mass
  195.      * @exception OrekitException if mass is unknown
  196.      */
  197.     public double getMass() throws OrekitException {
  198.         if (Double.isNaN(mass)) {
  199.             throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_SPACECRAFT_MASS);
  200.         }
  201.         return mass;
  202.     }

  203.     /** Set the spacecraft mass.
  204.      * @param mass the spacecraft mass to be set
  205.      */
  206.     void setMass(final double mass) {
  207.         this.mass = mass;
  208.     }

  209.     /** Get the solar radiation pressure area.
  210.      * @return the solar radiation pressure area
  211.      */
  212.     public double getSolarRadArea() {
  213.         return solarRadArea;
  214.     }

  215.     /** Set the solar radiation pressure area.
  216.      * @param solarRadArea the area to be set
  217.      */
  218.     void setSolarRadArea(final double solarRadArea) {
  219.         this.solarRadArea = solarRadArea;
  220.     }

  221.     /** Get the solar radiation pressure coefficient.
  222.      * @return the solar radiation pressure coefficient
  223.      */
  224.     public double getSolarRadCoeff() {
  225.         return solarRadCoeff;
  226.     }

  227.     /** Get the solar radiation pressure coefficient.
  228.      * @param solarRadCoeff the coefficient to be set
  229.      */
  230.     void setSolarRadCoeff(final double solarRadCoeff) {
  231.         this.solarRadCoeff = solarRadCoeff;
  232.     }

  233.     /** Get the drag area.
  234.      * @return the drag area
  235.      */
  236.     public double getDragArea() {
  237.         return dragArea;
  238.     }

  239.     /** Set the drag area.
  240.      * @param dragArea the area to be set
  241.      */
  242.     void setDragArea(final double dragArea) {
  243.         this.dragArea = dragArea;
  244.     }

  245.     /** Get the drag coefficient.
  246.      * @return the drag coefficient
  247.      */
  248.     public double getDragCoeff() {
  249.         return dragCoeff;
  250.     }

  251.     /** Set the drag coefficient.
  252.      * @param dragCoeff the coefficient to be set
  253.      */
  254.     void setDragCoeff(final double dragCoeff) {
  255.         this.dragCoeff = dragCoeff;
  256.     }

  257.     /** Get coordinate system for covariance matrix, for Local Orbital Frames.
  258.      * <p>
  259.      * The value returned is null if the covariance matrix is given in an
  260.      * absolute frame rather than a Local Orbital Frame. In this case, the
  261.      * method {@link #getCovRefFrame()} must be used instead.
  262.      * </p>
  263.      * @return the coordinate system for covariance matrix, or null if the
  264.      * covariance matrix is given in an absolute frame rather than a Local
  265.      * Orbital Frame
  266.      */
  267.     public LOFType getCovRefLofType() {
  268.         return covRefLofType;
  269.     }

  270.     /** Set coordinate system for covariance matrix, for Local Orbital Frames.
  271.      * @param covRefLofType the coordinate system to be set
  272.      */
  273.     void setCovRefLofType(final LOFType covRefLofType) {
  274.         this.covRefLofType = covRefLofType;
  275.         this.covRefFrame   = null;
  276.     }

  277.     /** Get coordinate system for covariance matrix, for absolute frames.
  278.      * <p>
  279.      * The value returned is null if the covariance matrix is given in a
  280.      * Local Orbital Frame rather than an absolute frame. In this case, the
  281.      * method {@link #getCovRefLofType()} must be used instead.
  282.      * </p>
  283.      * @return the coordinate system for covariance matrix
  284.      */
  285.     public Frame getCovRefFrame() {
  286.         return covRefFrame;
  287.     }

  288.     /** Set coordinate system for covariance matrix.
  289.      * @param covRefFrame the coordinate system to be set
  290.      */
  291.     void setCovRefFrame(final Frame covRefFrame) {
  292.         this.covRefLofType = null;
  293.         this.covRefFrame   = covRefFrame;
  294.     }

  295.     /** Get the Position/Velocity covariance matrix.
  296.      * @return the Position/Velocity covariance matrix
  297.      */
  298.     public RealMatrix getCovarianceMatrix() {
  299.         return covarianceMatrix;
  300.     }

  301.     /** Set an entry in the Position/Velocity covariance matrix.
  302.      * <p>
  303.      * Both m(j, k) and m(k, j) are set.
  304.      * </p>
  305.      * @param j row index (must be between 0 and 5 (inclusive)
  306.      * @param k column index (must be between 0 and 5 (inclusive)
  307.      * @param entry value of the matrix entry
  308.      */
  309.     void setCovarianceMatrixEntry(final int j, final int k, final double entry) {
  310.         covarianceMatrix.setEntry(j, k, entry);
  311.         covarianceMatrix.setEntry(k, j, entry);
  312.     }

  313.     /** Get the map of user defined parameter keywords and their corresponding values.
  314.      * @return the map of user defined parameter keywords and their corresponding values.
  315.      */
  316.     public Map<String, String> getUserDefinedParameters() {
  317.         return userDefinedParameters;
  318.     }

  319.     /** Add a pair keyword-value in the map of user defined parameter keywords and their corresponding values.
  320.      * @param keyword the user defined parameter keyword to be set. Starts with USER_DEFINED_
  321.      * @param value the user defined parameter value to be set
  322.      */
  323.     void setUserDefinedParameters(final String keyword,
  324.                                          final String value) {
  325.         userDefinedParameters.put(keyword, value);
  326.     }

  327.     /** Check whether the OPM contains Keplerian elements data.
  328.      * @return true if OPM contains Keplerian elements data.
  329.      */
  330.     public boolean hasKeplerianElements() {
  331.         return hasKeplerianElements;
  332.     }

  333.     /** Set boolean testing whether the OPM contains Keplerian elements data.
  334.      * @param hasKeplerianElements the boolean to be set.
  335.      */
  336.     void setHasKeplerianElements(final boolean hasKeplerianElements) {
  337.         this.hasKeplerianElements = hasKeplerianElements;
  338.     }

  339.     /** Check whether the OPM contains covariance matrix data.
  340.      * @return true if OPM contains covariance matrix data.
  341.      */
  342.     public boolean hasCovarianceMatrix() {
  343.         return covarianceMatrix != null;
  344.     }

  345.     /** Create a covariance matrix, initialized to zero.
  346.      */
  347.     void createCovarianceMatrix() {
  348.         covarianceMatrix = MatrixUtils.createRealMatrix(6, 6);
  349.     }

  350.     /** Get the comment for epoch.
  351.      * @return comment for epoch
  352.      */
  353.     public List<String> getEpochComment() {
  354.         return Collections.unmodifiableList(epochComment);
  355.     }

  356.     /** Set the comment for epoch.
  357.      * @param comment comment to set
  358.      */
  359.     void setEpochComment(final List<String> comment) {
  360.         epochComment = new ArrayList<String>(comment);
  361.     }

  362.     /** Get the comment for Keplerian elements.
  363.      * @return comment for Keplerian elements
  364.      */
  365.     public List<String> getKeplerianElementsComment() {
  366.         return Collections.unmodifiableList(keplerianElementsComment);
  367.     }

  368.     /** Set the comment for Keplerian elements.
  369.      * @param comment comment to set
  370.      */
  371.     void setKeplerianElementsComment(final List<String> comment) {
  372.         keplerianElementsComment = new ArrayList<String>(comment);
  373.     }

  374.     /** Get the comment for spacecraft.
  375.      * @return comment for spacecraft
  376.      */
  377.     public List<String> getSpacecraftComment() {
  378.         return Collections.unmodifiableList(spacecraftComment);
  379.     }

  380.     /** Set the comment for spacecraft.
  381.      * @param comment comment to set
  382.      */
  383.     void setSpacecraftComment(final List<String> comment) {
  384.         spacecraftComment = new ArrayList<String>(comment);
  385.     }

  386.     /** Get the comment for covariance.
  387.      * @return comment for covariance
  388.      */
  389.     public List<String> getCovarianceComment() {
  390.         return Collections.unmodifiableList(covarianceComment);
  391.     }

  392.     /** Set the comment for covariance.
  393.      * @param comment comment to set
  394.      */
  395.     void setCovarianceComment(final List<String> comment) {
  396.         covarianceComment = new ArrayList<String>(comment);
  397.     }

  398.     /** Get the meta data.
  399.      * @return meta data
  400.      */
  401.     public abstract ODMMetaData getMetaData();

  402.     /** {@inheritDoc} */
  403.     @Override
  404.     public Collection<SatelliteInformation> getSatellites() {
  405.         return Arrays.asList(new SatelliteInformation(getMetaData().getObjectID()));
  406.     }

  407.     /** {@inheritDoc} */
  408.     @Override
  409.     public int getSatelliteCount() {
  410.         return 1;
  411.     }

  412.     /** {@inheritDoc} */
  413.     @Override
  414.     public SatelliteInformation getSatellite(final String satId) {
  415.         if (getMetaData().getObjectID().equals(satId)) {
  416.             return new SatelliteInformation(satId);
  417.         }
  418.         return null;
  419.     }

  420. }