OrekitAttitudeEphemerisFile.java

  1. /* Copyright 2002-2023 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.general;

  18. import java.util.ArrayList;
  19. import java.util.Collections;
  20. import java.util.List;
  21. import java.util.Map;
  22. import java.util.concurrent.ConcurrentHashMap;

  23. import org.orekit.attitudes.BoundedAttitudeProvider;
  24. import org.orekit.attitudes.FixedFrameBuilder;
  25. import org.orekit.attitudes.TabulatedProvider;
  26. import org.orekit.errors.OrekitIllegalArgumentException;
  27. import org.orekit.errors.OrekitMessages;
  28. import org.orekit.frames.Frame;
  29. import org.orekit.propagation.SpacecraftState;
  30. import org.orekit.time.AbsoluteDate;
  31. import org.orekit.utils.AngularDerivativesFilter;
  32. import org.orekit.utils.TimeStampedAngularCoordinates;

  33. /**
  34.  * A class for encapsulating Orekit propagators within an {@link AttitudeEphemerisFile}
  35.  * complaint object that makes for easy serialization to external ephemeris
  36.  * formats like AEM.
  37.  *
  38.  * @author Raphaël Fermé
  39.  * @since 10.3
  40.  *
  41.  */
  42. public class OrekitAttitudeEphemerisFile
  43.     implements AttitudeEphemerisFile<TimeStampedAngularCoordinates,
  44.                                      OrekitAttitudeEphemerisFile.OrekitAttitudeEphemerisSegment> {

  45.     /** Hashmap of satellite ephemeris. **/
  46.     private final Map<String, OrekitSatelliteAttitudeEphemeris> satellites;

  47.     /**
  48.      * Standard default constructor.
  49.      */
  50.     public OrekitAttitudeEphemerisFile() {
  51.         this.satellites = new ConcurrentHashMap<>();
  52.     }

  53.     /** {@inheritDoc} */
  54.     @Override
  55.     public Map<String, OrekitSatelliteAttitudeEphemeris> getSatellites() {
  56.         return Collections.unmodifiableMap(satellites);
  57.     }

  58.     /**
  59.      * Adds a new satellite to this object.
  60.      *
  61.      * @param id
  62.      *            ID to use for this satellite
  63.      * @return the new satellite object
  64.      */
  65.     public OrekitSatelliteAttitudeEphemeris addSatellite(final String id) {
  66.         final OrekitSatelliteAttitudeEphemeris newSat = new OrekitSatelliteAttitudeEphemeris(id);
  67.         this.satellites.put(id, newSat);
  68.         return newSat;
  69.     }

  70.     /**
  71.      * Inner class of {@link OrekitAttitudeEphemerisFile} that defines the
  72.      * {@link OrekitSatelliteAttitudeEphemeris} corresponding object for this ephemeris type.
  73.      *
  74.      */
  75.     public static class OrekitSatelliteAttitudeEphemeris
  76.         implements SatelliteAttitudeEphemeris<TimeStampedAngularCoordinates,
  77.                                               OrekitAttitudeEphemerisFile.OrekitAttitudeEphemerisSegment> {

  78.         /** Default interpolation sample size if it is not specified. **/
  79.         public static final String DEFAULT_INTERPOLATION_METHOD = "LINEAR";

  80.         /** Default interpolation sample size if it is not specified. **/
  81.         public static final int DEFAULT_INTERPOLATION_SIZE = 2;

  82.         /** ID of the space object encapsulated here. **/
  83.         private final String id;

  84.         /** Earliest date of this file. **/
  85.         private AbsoluteDate startDate;

  86.         /** Latest date of this file. **/
  87.         private AbsoluteDate stopDate;

  88.         /** List of segments in the file. **/
  89.         private final List<OrekitAttitudeEphemerisSegment> segments;

  90.         /**
  91.          * Standard constructor for building the satellite Ephemeris object.
  92.          *
  93.          * @param id
  94.          *            the ID of the space object for this data
  95.          */
  96.         public OrekitSatelliteAttitudeEphemeris(final String id) {
  97.             this.id = id;
  98.             this.segments = new ArrayList<>();
  99.         }

  100.         /** {@inheritDoc} */
  101.         @Override
  102.         public String getId() {
  103.             return id;
  104.         }

  105.         /** {@inheritDoc} */
  106.         @Override
  107.         public List<OrekitAttitudeEphemerisSegment> getSegments() {
  108.             return Collections.unmodifiableList(this.segments);
  109.         }

  110.         /** {@inheritDoc} */
  111.         @Override
  112.         public AbsoluteDate getStart() {
  113.             return this.startDate;
  114.         }

  115.         /** {@inheritDoc} */
  116.         @Override
  117.         public AbsoluteDate getStop() {
  118.             return this.stopDate;
  119.         }

  120.         /**
  121.          * Injects pre-computed satellite states into this attitude ephemeris file
  122.          * object, returning the generated {@link OrekitAttitudeEphemerisSegment} that
  123.          * has been stored internally.
  124.          *
  125.          * @param states
  126.          *          a list of {@link SpacecraftState} that will comprise this
  127.          *          new unit
  128.          * @param interpolationMethod
  129.          *          the interpolation method that should be used when processed
  130.          *          by another system
  131.          * @param interpolationSamples
  132.          *          the number of interpolation samples that should be used
  133.          *          when processed by another system
  134.          * @param availableDerivatives derivatives to use for interpolation
  135.          * @return the generated {@link OrekitAttitudeEphemerisSegment}
  136.          */
  137.         public OrekitAttitudeEphemerisSegment addNewSegment(final List<SpacecraftState> states,
  138.                                                             final String interpolationMethod,
  139.                                                             final int interpolationSamples,
  140.                                                             final AngularDerivativesFilter availableDerivatives) {
  141.             final int minimumSampleSize = 2;
  142.             if (states == null || states.size() == 0) {
  143.                 throw new OrekitIllegalArgumentException(OrekitMessages.NULL_ARGUMENT, "states");
  144.             }

  145.             if (interpolationSamples < minimumSampleSize) {
  146.                 throw new OrekitIllegalArgumentException(OrekitMessages.NOT_ENOUGH_DATA,
  147.                         interpolationSamples);
  148.             }

  149.             final AbsoluteDate start = states.get(0).getDate();
  150.             final AbsoluteDate stop = states.get(states.size() - 1).getDate();

  151.             if (this.startDate == null || start.compareTo(this.startDate) < 0) {
  152.                 this.startDate = start;
  153.             }

  154.             if (this.stopDate == null || stop.compareTo(this.stopDate) > 0) {
  155.                 this.stopDate = stop;
  156.             }

  157.             final List<TimeStampedAngularCoordinates> attitudeDataLines = new ArrayList<>();
  158.             for (SpacecraftState state : states) {
  159.                 attitudeDataLines.add(state.getAttitude().getOrientation());
  160.             }

  161.             final OrekitAttitudeEphemerisSegment newSeg =
  162.                             new OrekitAttitudeEphemerisSegment(attitudeDataLines, interpolationMethod, interpolationSamples,
  163.                                                                states.get(0).getFrame(), availableDerivatives);
  164.             this.segments.add(newSeg);
  165.             return newSeg;
  166.         }
  167.     }

  168.     /** Ephemeris segment. */
  169.     public static class OrekitAttitudeEphemerisSegment
  170.         implements AttitudeEphemerisFile.AttitudeEphemerisSegment<TimeStampedAngularCoordinates> {

  171.         /** List of attitude data lines. */
  172.         private List<TimeStampedAngularCoordinates> attitudeDataLines;

  173.         /** The interpolation method to be used. */
  174.         private String interpolationMethod;

  175.         /** The number of interpolation samples. */
  176.         private int interpolationSamples;

  177.         /** Enumerate for selecting which derivatives to use in {@link #attitudeDataLines} interpolation. */
  178.         private AngularDerivativesFilter availableDerivatives;

  179.         /** Reference frame from which attitude is defined. */
  180.         private Frame referenceFrame;

  181.         /**
  182.          * Constructor for OrekitAttitudeEphemerisSegment.
  183.          *
  184.          * @param attitudeDataLines
  185.          *          attitude data lines for this segment.
  186.          * @param interpolationMethod
  187.          *          the interpolation method to use.
  188.          * @param interpolationSamples
  189.          *          the number of samples to use during interpolation.
  190.          * @param referenceFrame
  191.          *          reference frame from which the attitude is defined
  192.          * @param availableDerivatives derivatives to use for interpolation
  193.          */
  194.         public OrekitAttitudeEphemerisSegment(final List<TimeStampedAngularCoordinates> attitudeDataLines,
  195.                                               final String interpolationMethod,
  196.                                               final int interpolationSamples,
  197.                                               final Frame referenceFrame,
  198.                                               final AngularDerivativesFilter availableDerivatives) {
  199.             this.attitudeDataLines    = attitudeDataLines;
  200.             this.interpolationMethod  = interpolationMethod;
  201.             this.interpolationSamples = interpolationSamples;
  202.             this.referenceFrame       = referenceFrame;
  203.             this.availableDerivatives = availableDerivatives;
  204.         }

  205.         /** {@inheritDoc} */
  206.         @Override
  207.         public List<TimeStampedAngularCoordinates> getAngularCoordinates() {
  208.             return Collections.unmodifiableList(attitudeDataLines);
  209.         }

  210.         /** {@inheritDoc} */
  211.         @Override
  212.         public Frame getReferenceFrame() {
  213.             return referenceFrame;
  214.         }

  215.         /** {@inheritDoc} */
  216.         @Override
  217.         public AbsoluteDate getStart() {
  218.             return attitudeDataLines.get(0).getDate();
  219.         }

  220.         /** {@inheritDoc} */
  221.         @Override
  222.         public AbsoluteDate getStop() {
  223.             return attitudeDataLines.get(attitudeDataLines.size() - 1).getDate();
  224.         }

  225.         /** {@inheritDoc} */
  226.         @Override
  227.         public String getInterpolationMethod() {
  228.             return interpolationMethod;
  229.         }

  230.         /** {@inheritDoc} */
  231.         @Override
  232.         public int getInterpolationSamples() {
  233.             return interpolationSamples;
  234.         }

  235.         /** {@inheritDoc} */
  236.         @Override
  237.         public AngularDerivativesFilter getAvailableDerivatives() {
  238.             return availableDerivatives;
  239.         }

  240.         /** {@inheritDoc} */
  241.         @Override
  242.         public BoundedAttitudeProvider getAttitudeProvider() {
  243.             return new TabulatedProvider(getAngularCoordinates(),
  244.                                          getInterpolationSamples(), getAvailableDerivatives(),
  245.                                          getStart(), getStop(),
  246.                                          new FixedFrameBuilder(getReferenceFrame()));
  247.         }

  248.     }

  249. }