ODMMetaData.java

  1. /* Copyright 2002-2020 CS Group
  2.  * Licensed to CS Group (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.Collections;
  20. import java.util.List;

  21. import org.orekit.bodies.CelestialBodies;
  22. import org.orekit.bodies.CelestialBody;
  23. import org.orekit.bodies.CelestialBodyFactory;
  24. import org.orekit.errors.OrekitException;
  25. import org.orekit.errors.OrekitMessages;
  26. import org.orekit.frames.Frame;
  27. import org.orekit.time.AbsoluteDate;
  28. import org.orekit.time.TimeScale;

  29. /** This class gathers the meta-data present in the Orbital Data Message (ODM).
  30.  * @author sports
  31.  * @since 6.1
  32.  */
  33. public class ODMMetaData {

  34.     /** ODM file to which these meta-data belong. */
  35.     private final ODMFile odmFile;

  36.     /** Time System: used for metadata, orbit state and covariance data. */
  37.     private CcsdsTimeScale timeSystem;

  38.     /** Spacecraft name for which the orbit state is provided. */
  39.     private String objectName;

  40.     /** Object identifier of the object for which the orbit state is provided. */
  41.     private String objectID;

  42.     /** Launch Year. */
  43.     private int launchYear;

  44.     /** Launch number. */
  45.     private int launchNumber;

  46.     /** Piece of launch (from "A" to "ZZZ"). */
  47.     private String launchPiece;

  48.     /** Origin of reference frame. */
  49.     private String centerName;

  50.     /** Celestial body corresponding to the center name. */
  51.     private CelestialBody centerBody;

  52.     /** Tests whether the body corresponding to the center name can be
  53.      * created through {@link CelestialBodies} in order to obtain the
  54.      * corresponding gravitational coefficient. */
  55.     private boolean hasCreatableBody;

  56.     /** Reference frame in which data are given: used for state vector
  57.      * and Keplerian elements data (and for the covariance reference frame if none is given). */
  58.     private Frame refFrame;

  59.     /** The reference frame specifier, as it appeared in the file. */
  60.     private String refFrameString;

  61.     /** Epoch of reference frame, if not intrinsic to the definition of the
  62.      * reference frame. */
  63.     private String frameEpochString;

  64.     /** Epoch of reference frame, if not intrinsic to the definition of the
  65.      * reference frame. */
  66.     private AbsoluteDate frameEpoch;

  67.     /** Metadata comments. The list contains a string for each line of comment. */
  68.     private List<String> comment;

  69.     /** Create a new meta-data.
  70.      * @param odmFile ODM file to which these meta-data belong
  71.      */
  72.     ODMMetaData(final ODMFile odmFile) {
  73.         this.odmFile = odmFile;
  74.         comment = new ArrayList<String>();
  75.     }

  76.     /** Get the ODM file to which these meta-data belong.
  77.      * @return ODM file to which these meta-data belong
  78.      */
  79.     public ODMFile getODMFile() {
  80.         return odmFile;
  81.     }

  82.     /** Get the Time System that: for OPM, is used for metadata, state vector,
  83.      * maneuver and covariance data, for OMM, is used for metadata, orbit state
  84.      * and covariance data, for OEM, is used for metadata, ephemeris and
  85.      * covariance data.
  86.      * @return the time system
  87.      */
  88.     public CcsdsTimeScale getTimeSystem() {
  89.         return timeSystem;
  90.     }

  91.     /** Set the Time System that: for OPM, is used for metadata, state vector,
  92.      * maneuver and covariance data, for OMM, is used for metadata, orbit state
  93.      * and covariance data, for OEM, is used for metadata, ephemeris and
  94.      * covariance data.
  95.      * @param timeSystem the time system to be set
  96.      */
  97.     void setTimeSystem(final CcsdsTimeScale timeSystem) {
  98.         this.timeSystem = timeSystem;
  99.     }

  100.     /**
  101.      * Get the time scale.
  102.      *
  103.      * @return the time scale.
  104.      * @see #getTimeSystem()
  105.      * @throws OrekitException if there is not corresponding time scale.
  106.      * @since 10.1
  107.      */
  108.     TimeScale getTimeScale() {
  109.         return getTimeSystem().getTimeScale(
  110.                 odmFile.getConventions(),
  111.                 odmFile.getDataContext().getTimeScales());
  112.     }

  113.     /** Get the spacecraft name for which the orbit state is provided.
  114.      * @return the spacecraft name
  115.      */
  116.     public String getObjectName() {
  117.         return objectName;
  118.     }

  119.     /** Set the spacecraft name for which the orbit state is provided.
  120.      * @param objectName the spacecraft name to be set
  121.      */
  122.     void setObjectName(final String objectName) {
  123.         this.objectName = objectName;
  124.     }

  125.     /** Get the spacecraft ID for which the orbit state is provided.
  126.      * @return the spacecraft ID
  127.      */
  128.     public String getObjectID() {
  129.         return objectID;
  130.     }

  131.     /** Set the spacecraft ID for which the orbit state is provided.
  132.      * @param objectID the spacecraft ID to be set
  133.      */
  134.     void setObjectID(final String objectID) {
  135.         this.objectID = objectID;
  136.     }

  137.     /** Set the launch year.
  138.      * @param launchYear launch year
  139.      */
  140.     void setLaunchYear(final int launchYear) {
  141.         this.launchYear = launchYear;
  142.     }

  143.     /** Get the launch year.
  144.      * @return launch year
  145.      */
  146.     public int getLaunchYear() {
  147.         return launchYear;
  148.     }

  149.     /** Set the launch number.
  150.      * @param launchNumber launch number
  151.      */
  152.     void setLaunchNumber(final int launchNumber) {
  153.         this.launchNumber = launchNumber;
  154.     }

  155.     /** Get the launch number.
  156.      * @return launch number
  157.      */
  158.     public int getLaunchNumber() {
  159.         return launchNumber;
  160.     }

  161.     /** Set the piece of launch.
  162.      * @param launchPiece piece of launch
  163.      */
  164.     void setLaunchPiece(final String launchPiece) {
  165.         this.launchPiece = launchPiece;
  166.     }

  167.     /** Get the piece of launch.
  168.      * @return piece of launch
  169.      */
  170.     public String getLaunchPiece() {
  171.         return launchPiece;
  172.     }

  173.     /** Get the origin of reference frame.
  174.      * @return the origin of reference frame.
  175.      */
  176.     public String getCenterName() {
  177.         return centerName;
  178.     }

  179.     /** Set the origin of reference frame.
  180.      * @param centerName the origin of reference frame to be set
  181.      */
  182.     void setCenterName(final String centerName) {
  183.         this.centerName = centerName;
  184.     }

  185.     /** Get the {@link CelestialBody} corresponding to the center name.
  186.      * @return the center body
  187.      */
  188.     public CelestialBody getCenterBody() {
  189.         return centerBody;
  190.     }

  191.     /** Set the {@link CelestialBody} corresponding to the center name.
  192.      * @param centerBody the {@link CelestialBody} to be set
  193.      */
  194.     void setCenterBody(final CelestialBody centerBody) {
  195.         this.centerBody = centerBody;
  196.     }

  197.     /** Get boolean testing whether the body corresponding to the centerName
  198.      * attribute can be created through the {@link CelestialBodies}.
  199.      * @return true if {@link CelestialBody} can be created from centerName
  200.      *         false otherwise
  201.      */
  202.     public boolean getHasCreatableBody() {
  203.         return hasCreatableBody;
  204.     }

  205.     /** Set boolean testing whether the body corresponding to the centerName
  206.      * attribute can be created through the {@link CelestialBodies}.
  207.      * @param hasCreatableBody the boolean to be set.
  208.      */
  209.     void setHasCreatableBody(final boolean hasCreatableBody) {
  210.         this.hasCreatableBody = hasCreatableBody;
  211.     }

  212.     /**
  213.      * Get the reference frame in which data are given: used for state vector and
  214.      * Keplerian elements data (and for the covariance reference frame if none is given).
  215.      *
  216.      * @return the reference frame
  217.      */
  218.     public Frame getFrame() {
  219.         final Frame frame = this.getRefFrame();
  220.         final CelestialBody body = this.getCenterBody();
  221.         if (body == null) {
  222.             throw new OrekitException(OrekitMessages.NO_DATA_LOADED_FOR_CELESTIAL_BODY,
  223.                     this.getCenterName());
  224.         }
  225.         // Just return frame if we don't need to shift the center based on CENTER_NAME
  226.         // MCI and ICRF are the only non-earth centered frames specified in Annex A.
  227.         final String frameString = this.getFrameString();
  228.         final boolean isMci = "MCI".equals(frameString);
  229.         final boolean isIcrf = "ICRF".equals(frameString);
  230.         final boolean isSolarSystemBarycenter =
  231.                 CelestialBodyFactory.SOLAR_SYSTEM_BARYCENTER.equals(body.getName());
  232.         if ((!(isMci || isIcrf) && CelestialBodyFactory.EARTH.equals(body.getName())) ||
  233.                 (isMci && CelestialBodyFactory.MARS.equals(body.getName())) ||
  234.                 (isIcrf && isSolarSystemBarycenter)) {
  235.             return frame;
  236.         }
  237.         // else, translate frame to specified center.
  238.         return new CcsdsModifiedFrame(frame, frameString, body, this.getCenterName());
  239.     }

  240.     /**
  241.      * Get the the value of {@code REF_FRAME} as an Orekit {@link Frame}. The {@code
  242.      * CENTER_NAME} key word has not been applied yet, so the returned frame may not
  243.      * correspond to the reference frame of the data in the file.
  244.      *
  245.      * @return The reference frame specified by the {@code REF_FRAME} keyword.
  246.      * @see #getFrame()
  247.      */
  248.     public Frame getRefFrame() {
  249.         return refFrame;
  250.     }

  251.     /** Set the reference frame in which data are given: used for state vector
  252.      * and Keplerian elements data (and for the covariance reference frame if none is given).
  253.      * @param refFrame the reference frame to be set
  254.      */
  255.     void setRefFrame(final Frame refFrame) {
  256.         this.refFrame = refFrame;
  257.     }

  258.     /**
  259.      * Get the reference frame specifier as it appeared in the file.
  260.      *
  261.      * @return the frame name as it appeared in the file.
  262.      * @see #getFrame()
  263.      */
  264.     public String getFrameString() {
  265.         return this.refFrameString;
  266.     }

  267.     /**
  268.      * Set the reference frame name.
  269.      *
  270.      * @param frame specifier as it appeared in the file.
  271.      */
  272.     void setFrameString(final String frame) {
  273.         this.refFrameString = frame;
  274.     }

  275.     /** Get epoch of reference frame, if not intrinsic to the definition of the
  276.      * reference frame.
  277.      * @return epoch of reference frame
  278.      */
  279.     public String getFrameEpochString() {
  280.         return frameEpochString;
  281.     }

  282.     /** Set epoch of reference frame, if not intrinsic to the definition of the
  283.      * reference frame.
  284.      * @param frameEpochString the epoch of reference frame to be set
  285.      */
  286.     void setFrameEpochString(final String frameEpochString) {
  287.         this.frameEpochString = frameEpochString;
  288.     }

  289.     /** Get epoch of reference frame, if not intrinsic to the definition of the
  290.      * reference frame.
  291.      * @return epoch of reference frame
  292.      */
  293.     public AbsoluteDate getFrameEpoch() {
  294.         return frameEpoch;
  295.     }

  296.     /** Set epoch of reference frame, if not intrinsic to the definition of the
  297.      * reference frame.
  298.      * @param frameEpoch the epoch of reference frame to be set
  299.      */
  300.     void setFrameEpoch(final AbsoluteDate frameEpoch) {
  301.         this.frameEpoch = frameEpoch;
  302.     }

  303.     /** Get the meta-data comment.
  304.      * @return meta-data comment
  305.      */
  306.     public List<String> getComment() {
  307.         return Collections.unmodifiableList(comment);
  308.     }

  309.     /** Set the meta-data comment.
  310.      * @param comment comment to set
  311.      */
  312.     void setComment(final List<String> comment) {
  313.         this.comment = new ArrayList<String>(comment);
  314.     }

  315. }