IIRVEphemerisFile.java

  1. /* Copyright 2024-2025 The Johns Hopkins University Applied Physics Laboratory
  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.  * ADS 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.iirv;

  18. import org.orekit.errors.OrekitInternalError;
  19. import org.orekit.files.general.EphemerisFile;
  20. import org.orekit.time.AbsoluteDate;
  21. import org.orekit.utils.TimeStampedPVCoordinates;

  22. import java.util.Collections;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.Map;

  26. /**
  27.  * Class for associating a the {@link IIRVEphemeris} ephemeris state data (obtained from an {@link IIRVMessage})
  28.  * to a single satellite, identified by its IIRV {@link org.orekit.files.iirv.terms.VehicleIdCodeTerm}.
  29.  */
  30. public class IIRVEphemerisFile implements EphemerisFile<TimeStampedPVCoordinates, IIRVSegment> {

  31.     /** Unmodifiable mapping with a single key-value pair from satellite id to ephemeris. */
  32.     private final Map<String, IIRVEphemerisFile.IIRVEphemeris> satellites;

  33.     /**
  34.      * Constructs a {@link IIRVEphemerisFile} instance.
  35.      *
  36.      * @param ephemeris IIRV ephemeris data.
  37.      */
  38.     public IIRVEphemerisFile(final IIRVEphemerisFile.IIRVEphemeris ephemeris) {
  39.         final Map<String, IIRVEphemerisFile.IIRVEphemeris> tempMap = new HashMap<>();
  40.         tempMap.put(ephemeris.getId(), ephemeris);
  41.         this.satellites = Collections.unmodifiableMap(tempMap);
  42.     }

  43.     /**
  44.      * Constructs a {@link IIRVEphemerisFile} instance from a {@link IIRVMessage}.
  45.      *
  46.      * @param mu                   gravitational parameter (m^3/s^2)
  47.      * @param interpolationSamples number of samples to use in interpolation
  48.      * @param startYear            Year associated with the beginning of the IIRV message
  49.      * @param iirvMessage          IIRV message
  50.      */
  51.     public IIRVEphemerisFile(final double mu,
  52.                              final int interpolationSamples,
  53.                              final int startYear,
  54.                              final IIRVMessage iirvMessage) {
  55.         this(new IIRVEphemerisFile.IIRVEphemeris(new IIRVSegment(mu, interpolationSamples, startYear, iirvMessage)));
  56.     }

  57.     /**
  58.      * Constructs a {@link IIRVEphemerisFile} instance from a {@link IIRVMessage} with default values.
  59.      * <p>
  60.      * See {@link IIRVSegment#IIRVSegment(int, IIRVMessage)} for default value information.
  61.      *
  62.      * @param startYear   Year associated with the beginning of the IIRV message
  63.      * @param iirvMessage IIRV message
  64.      */
  65.     public IIRVEphemerisFile(final int startYear, final IIRVMessage iirvMessage) {
  66.         this(new IIRVEphemerisFile.IIRVEphemeris(new IIRVSegment(startYear, iirvMessage)));
  67.     }


  68.     /**
  69.      * {@inheritDoc}
  70.      * <p>
  71.      * STK ephemeris files define ephemeris for a single satellite, so the returned
  72.      * map will have a single entry.
  73.      * </p>
  74.      */
  75.     @Override
  76.     public Map<String, IIRVEphemerisFile.IIRVEphemeris> getSatellites() {
  77.         return satellites;
  78.     }

  79.     /**
  80.      * Gets the {@link IIRVEphemeris} associated with this file.
  81.      *
  82.      * @return {@link IIRVEphemeris} associated with this file.
  83.      */
  84.     public IIRVEphemeris getIIRVEphemeris() {
  85.         if (satellites.size() != 1) {
  86.             // This should never happen
  87.             throw new OrekitInternalError(null);
  88.         }
  89.         return satellites.values().iterator().next();
  90.     }

  91.     /**
  92.      * Gets the IIRV message containing the ephemeris data.
  93.      *
  94.      * @return IIRVMessage containing the ephemeris data.
  95.      */
  96.     public IIRVMessage getIIRV() {
  97.         return getIIRVEphemeris().getIIRV();
  98.     }

  99.     /**
  100.      * Gets the start year for this file.
  101.      *
  102.      * @return start year for this file.
  103.      */
  104.     public int getStartYear() {
  105.         return getIIRVEphemeris().getStartYear();
  106.     }

  107.     /**
  108.      * Ephemeris from an IIRV file.
  109.      */
  110.     public static class IIRVEphemeris implements SatelliteEphemeris<TimeStampedPVCoordinates, IIRVSegment> {

  111.         /** Ephemeris segment. */
  112.         private final IIRVSegment segment;

  113.         /**
  114.          * Constructs a {@link IIRVSegment} instance.
  115.          * <p>
  116.          * An IIRV file contains ephemeris data for a single satellite; thus each {@link IIRVEphemeris} instance
  117.          * contains only a single {@link IIRVSegment}.
  118.          *
  119.          * @param segment ephemeris segments
  120.          */
  121.         public IIRVEphemeris(final IIRVSegment segment) {
  122.             this.segment = segment;
  123.         }

  124.         /** {@inheritDoc} */
  125.         @Override
  126.         public String getId() {
  127.             return segment.getIIRVMessage().getSatelliteID();
  128.         }

  129.         /** {@inheritDoc} */
  130.         @Override
  131.         public double getMu() {
  132.             return segment.getMu();
  133.         }

  134.         /**
  135.          * Get the {@link IIRVSegment} for this satellite.
  136.          *
  137.          * @return {@link IIRVSegment} for this satellite.
  138.          * @see #getSegment()
  139.          */
  140.         public IIRVSegment getSegment() {
  141.             return segment;
  142.         }

  143.         /** {@inheritDoc} */
  144.         @Override
  145.         public List<IIRVSegment> getSegments() {
  146.             return Collections.singletonList(segment);
  147.         }

  148.         /** {@inheritDoc} */
  149.         @Override
  150.         public AbsoluteDate getStart() {
  151.             return segment.getStart();
  152.         }

  153.         /** {@inheritDoc} */
  154.         @Override
  155.         public AbsoluteDate getStop() {
  156.             return segment.getStop();
  157.         }

  158.         /**
  159.          * Gets the {@link IIRVMessage} containing the ephemeris data for this object's {@link IIRVSegment}.
  160.          *
  161.          * @return {@link IIRVMessage} containing the ephemeris data for this object's {@link IIRVSegment}.
  162.          */
  163.         public IIRVMessage getIIRV() {
  164.             return segment.getIIRVMessage();
  165.         }

  166.         /**
  167.          * Gets the start year of the ephemeris data.
  168.          *
  169.          * @return start year of the ephemeris data
  170.          */
  171.         public int getStartYear() {
  172.             return segment.getStartYear();
  173.         }

  174.     }

  175. }