STKEphemerisFile.java

  1. /* Copyright 2002-2025 Andrew Goetz
  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.stk;

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

  25. import org.orekit.errors.OrekitException;
  26. import org.orekit.errors.OrekitMessages;
  27. import org.orekit.files.general.EphemerisFile;
  28. import org.orekit.files.stk.STKEphemerisFile.STKEphemerisSegment;
  29. import org.orekit.frames.Frame;
  30. import org.orekit.time.AbsoluteDate;
  31. import org.orekit.utils.CartesianDerivativesFilter;
  32. import org.orekit.utils.TimeStampedPVCoordinates;

  33. /**
  34.  * STK ephemeris file.
  35.  *
  36.  * @author Andrew Goetz
  37.  * @since 12.0
  38.  */
  39. public class STKEphemerisFile implements EphemerisFile<TimeStampedPVCoordinates, STKEphemerisSegment> {

  40.     /** STK version. */
  41.     private final String stkVersion;

  42.     /** Unmodifiable mapping with a single key-value pair from satellite id to ephemeris. */
  43.     private final Map<String, STKEphemeris> satellites;

  44.     /**
  45.      * Constructs a {@link STKEphemerisFile} instance.
  46.      * @param stkVersion STK version string (example: "stk.v.11.0")
  47.      * @param satelliteId satellite id
  48.      * @param ephemeris ephemeris
  49.      */
  50.     public STKEphemerisFile(final String stkVersion, final String satelliteId, final STKEphemeris ephemeris) {
  51.         this.stkVersion = Objects.requireNonNull(stkVersion);
  52.         final Map<String, STKEphemeris> tempMap = new HashMap<>();
  53.         tempMap.put(satelliteId, ephemeris);
  54.         this.satellites = Collections.unmodifiableMap(tempMap);
  55.     }

  56.     /**
  57.      * Returns the STK version string.
  58.      * @return STK version string
  59.      */
  60.     public String getSTKVersion() {
  61.         return stkVersion;
  62.     }

  63.     /**
  64.      * {@inheritDoc}
  65.      * <p>
  66.      * STK ephemeris files define ephemeris for a single satellite, so the returned
  67.      * map will have a single entry.
  68.      * </p>
  69.      */
  70.     @Override
  71.     public Map<String, STKEphemeris> getSatellites() {
  72.         return satellites;
  73.     }

  74.     /**
  75.      * Ephemeris segment from an STK ephemeris file.
  76.      */
  77.     public static class STKEphemerisSegment implements EphemerisFile.EphemerisSegment<TimeStampedPVCoordinates> {

  78.         /** Gravitational parameter (m^3/s^2). */
  79.         private final double mu;

  80.         /** Reference frame. */
  81.         private final Frame frame;

  82.         /** Number of samples to use in interpolation. */
  83.         private final int interpolationSamples;

  84.         /** Cartesian derivatives filter. */
  85.         private final CartesianDerivativesFilter cartesianDerivativesFilter;

  86.         /** Time-sorted time/position/velocity data. */
  87.         private final List<TimeStampedPVCoordinates> timeStampedPVCoordinates;

  88.         /**
  89.          * Constructs a {@link STKEphemerisSegment} instance.
  90.          * @param mu gravitational parameter (m^3/s^2)
  91.          * @param frame frame
  92.          * @param interpolationSamples number of samples to use in interpolation
  93.          * @param cartesianDerivativesFilter Cartesian derivatives filter
  94.          * @param timeStampedPVCoordinates time-sorted time/position/velocity data
  95.          */
  96.         public STKEphemerisSegment(final double mu, final Frame frame, final int interpolationSamples,
  97.                 final CartesianDerivativesFilter cartesianDerivativesFilter,
  98.                 final List<TimeStampedPVCoordinates> timeStampedPVCoordinates) {
  99.             this.mu = mu;
  100.             this.frame = Objects.requireNonNull(frame);
  101.             this.interpolationSamples = interpolationSamples;
  102.             this.cartesianDerivativesFilter = Objects.requireNonNull(cartesianDerivativesFilter);
  103.             this.timeStampedPVCoordinates = Collections.unmodifiableList(new ArrayList<>(timeStampedPVCoordinates));
  104.         }

  105.         @Override
  106.         public double getMu() {
  107.             return mu;
  108.         }

  109.         @Override
  110.         public Frame getFrame() {
  111.             return frame;
  112.         }

  113.         @Override
  114.         public int getInterpolationSamples() {
  115.             return interpolationSamples;
  116.         }

  117.         @Override
  118.         public CartesianDerivativesFilter getAvailableDerivatives() {
  119.             return cartesianDerivativesFilter;
  120.         }

  121.         @Override
  122.         public List<TimeStampedPVCoordinates> getCoordinates() {
  123.             return timeStampedPVCoordinates;
  124.         }

  125.         @Override
  126.         public AbsoluteDate getStart() {
  127.             return timeStampedPVCoordinates.get(0).getDate();
  128.         }

  129.         @Override
  130.         public AbsoluteDate getStop() {
  131.             return timeStampedPVCoordinates.get(timeStampedPVCoordinates.size() - 1).getDate();
  132.         }

  133.     }

  134.     /**
  135.      * Ephemeris from an STK ephemeris file.
  136.      */
  137.     public static class STKEphemeris implements SatelliteEphemeris<TimeStampedPVCoordinates, STKEphemerisSegment> {

  138.         /** Satellite id.*/
  139.         private final String satelliteId;

  140.         /** Gravitational parameter (m^3/s^2). */
  141.         private final double mu;

  142.         /** Unmodifiable list of ephemeris segments. */
  143.         private final List<STKEphemerisSegment> segments;

  144.         /**
  145.          * Constructs a {@link STKEphemeris} instance. This constructor shallowly copies the list of segments provided.
  146.          * @param satelliteId satellite id
  147.          * @param mu gravitational parameter (m^3/s^2)
  148.          * @param segments ephemeris segments
  149.          */
  150.         public STKEphemeris(final String satelliteId, final double mu, final List<STKEphemerisSegment> segments) {
  151.             this.satelliteId = Objects.requireNonNull(satelliteId);
  152.             this.mu = mu;
  153.             this.segments = Collections.unmodifiableList(new ArrayList<>(segments));
  154.         }

  155.         @Override
  156.         public String getId() {
  157.             return satelliteId;
  158.         }

  159.         @Override
  160.         public double getMu() {
  161.             return mu;
  162.         }

  163.         @Override
  164.         public List<STKEphemerisSegment> getSegments() {
  165.             return segments;
  166.         }

  167.         @Override
  168.         public AbsoluteDate getStart() {
  169.             return segments.get(0).getStart();
  170.         }

  171.         @Override
  172.         public AbsoluteDate getStop() {
  173.             return segments.get(segments.size() - 1).getStop();
  174.         }

  175.     }

  176.     /**
  177.      * STK coordinate system.
  178.      * <p>
  179.      * Currently, only Earth-centered coordinate systems are supported.
  180.      * </p>
  181.      */
  182.     public enum STKCoordinateSystem {

  183.         /** International Celestial Reference Frame. */
  184.         ICRF,

  185.         /** Mean equator and mean equinox of the J2000 epoch. */
  186.         J2000,

  187.         /** Central-body-dependent inertial frame, equivalent to ICRF for Earth. */
  188.         INERTIAL,

  189.         /** Fixed frame. */
  190.         FIXED,

  191.         /** True equator and true equinox of date. */
  192.         TRUE_OF_DATE,

  193.         /** Mean equator and mean equinox of date. */
  194.         MEAN_OF_DATE,

  195.         /** True equator and mean equinox of date. */
  196.         TEME_OF_DATE;

  197.         /**
  198.          * Parses a coordinate system from a string.
  199.          * @param s string
  200.          * @return coordinate system
  201.          */
  202.         public static STKCoordinateSystem parse(final String s) {
  203.             final String sUpper = s.toUpperCase(Locale.US);
  204.             switch (sUpper) {
  205.                 case "ICRF":
  206.                     return ICRF;
  207.                 case "J2000":
  208.                     return J2000;
  209.                 case "INERTIAL":
  210.                     return INERTIAL;
  211.                 case "FIXED":
  212.                     return FIXED;
  213.                 case "TRUEOFDATE":
  214.                     return TRUE_OF_DATE;
  215.                 case "MEANOFDATE":
  216.                     return MEAN_OF_DATE;
  217.                 case "TEMEOFDATE":
  218.                     return TEME_OF_DATE;
  219.                 default:
  220.                     throw new OrekitException(OrekitMessages.STK_INVALID_OR_UNSUPPORTED_COORDINATE_SYSTEM, s);
  221.             }
  222.         }

  223.     }

  224. }