Omm.java

  1. /* Copyright 2002-2024 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.ndm.odm.omm;

  18. import java.util.List;

  19. import org.orekit.data.DataContext;
  20. import org.orekit.files.ccsds.ndm.NdmConstituent;
  21. import org.orekit.files.ccsds.ndm.odm.OdmCommonMetadata;
  22. import org.orekit.files.ccsds.ndm.odm.KeplerianElements;
  23. import org.orekit.files.ccsds.ndm.odm.OdmHeader;
  24. import org.orekit.files.ccsds.section.Segment;
  25. import org.orekit.orbits.CartesianOrbit;
  26. import org.orekit.orbits.KeplerianOrbit;
  27. import org.orekit.propagation.SpacecraftState;
  28. import org.orekit.propagation.analytical.tle.TLE;
  29. import org.orekit.time.AbsoluteDate;
  30. import org.orekit.time.TimeStamped;
  31. import org.orekit.utils.IERSConventions;

  32. /**
  33.  * This class gathers the informations present in the Orbital Mean-Elements Message (OMM).
  34.  * @author sports
  35.  * @since 6.1
  36.  */
  37. public class Omm extends NdmConstituent<OdmHeader, Segment<OmmMetadata, OmmData>> implements TimeStamped {

  38.     /** Root element for XML files. */
  39.     public static final String ROOT = "omm";

  40.     /** Key for format version. */
  41.     public static final String FORMAT_VERSION_KEY = "CCSDS_OMM_VERS";

  42.     /** Simple constructor.
  43.      * @param header file header
  44.      * @param segments file segments
  45.      * @param conventions IERS conventions
  46.      * @param dataContext used for creating frames, time scales, etc.
  47.      */
  48.     public Omm(final OdmHeader header, final List<Segment<OmmMetadata, OmmData>> segments,
  49.                final IERSConventions conventions, final DataContext dataContext) {
  50.         super(header, segments, conventions, dataContext);
  51.     }

  52.     /** Get the file metadata.
  53.      * @return file metadata
  54.      */
  55.     public OmmMetadata getMetadata() {
  56.         return getSegments().get(0).getMetadata();
  57.     }

  58.     /** Get the file data.
  59.      * @return file data
  60.      */
  61.     public OmmData getData() {
  62.         return getSegments().get(0).getData();
  63.     }

  64.     /** {@inheritDoc} */
  65.     @Override
  66.     public AbsoluteDate getDate() {
  67.         return getData().getKeplerianElementsBlock().getEpoch();
  68.     }

  69.     /** Generate a keplerian orbit.
  70.      * @return generated orbit
  71.      */
  72.     public KeplerianOrbit generateKeplerianOrbit() {
  73.         return getData().getKeplerianElementsBlock().generateKeplerianOrbit(getMetadata().getFrame());
  74.     }

  75.     /** Generate spacecraft state from the {@link CartesianOrbit} generated by generateCartesianOrbit.
  76.      *  Raises an exception if OPM doesn't contain spacecraft mass information.
  77.      * @return the spacecraft state of the OPM
  78.      */
  79.     public SpacecraftState generateSpacecraftState() {
  80.         return new SpacecraftState(generateKeplerianOrbit(), getData().getMass());
  81.     }

  82.     /** Generate TLE from OMM file. Launch Year, Launch Day and Launch Piece are not present in the
  83.      * OMM file, they have to be set manually by the user with the AdditionalData static class.
  84.      * @return the tle
  85.      */
  86.     public TLE generateTLE() {
  87.         final OdmCommonMetadata metadata = getMetadata();
  88.         final KeplerianElements kep = getData().getKeplerianElementsBlock();
  89.         final OmmTle               tle = getData().getTLEBlock();
  90.         return new TLE(tle.getNoradID(), tle.getClassificationType(),
  91.                        metadata.getLaunchYear(), metadata.getLaunchNumber(), metadata.getLaunchPiece(),
  92.                        tle.getEphemerisType(), tle.getElementSetNumber(), kep.getEpoch(),
  93.                        kep.getMeanMotion(), tle.getMeanMotionDot() / 2, tle.getMeanMotionDotDot() / 6,
  94.                        kep.getE(), kep.getI(), kep.getPa(), kep.getRaan(),
  95.                        kep.getAnomaly(), tle.getRevAtEpoch(),
  96.                        tle.getBStar(), getDataContext().getTimeScales().getUTC());
  97.     }

  98. }