IIRVSegment.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.annotation.DefaultDataContext;
  19. import org.orekit.files.general.EphemerisFile;
  20. import org.orekit.frames.Frame;
  21. import org.orekit.time.AbsoluteDate;
  22. import org.orekit.utils.CartesianDerivativesFilter;
  23. import org.orekit.utils.Constants;
  24. import org.orekit.utils.TimeStampedPVCoordinates;

  25. import java.util.ArrayList;
  26. import java.util.Collections;
  27. import java.util.List;

  28. /**
  29.  * Ephemeris segment from an IIRV file. Each IIRV file (i.e. {@link IIRVMessage}) is defined as containing only one
  30.  * {@link IIRVSegment}.
  31.  *
  32.  * @author Nick LaFarge
  33.  * @since 13.0
  34.  */
  35. public class IIRVSegment implements EphemerisFile.EphemerisSegment<TimeStampedPVCoordinates> {

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

  38.     /** Number of samples to use in interpolation. */
  39.     private final int interpolationSamples;

  40.     /** Cartesian derivatives filter: IIRV always contains position & velocity data. */
  41.     private final CartesianDerivativesFilter cartesianDerivativesFilter;

  42.     /** Year of the first vector in the file (day of year, but not year itself, is embedded within an IIRV message). */
  43.     private final int startYear;

  44.     /** IIRV message consisting of sequential {@link IIRVVector} instances, sorted by {@link org.orekit.files.iirv.terms.SequenceNumberTerm}. */
  45.     private final IIRVMessage iirvMessage;

  46.     /**
  47.      * Constructs a {@link IIRVSegment} instance  with default values.
  48.      * <p>
  49.      * Default gravitational parameter is {@link Constants#IERS96_EARTH_MU}. Default number of
  50.      * interpolation samples is 7.
  51.      *
  52.      * @param startYear   Year associated with the beginning of the IIRV message
  53.      * @param iirvMessage IIRV message consisting of sequential {@link IIRVVector} instances, sorted by
  54.      *                    {@link org.orekit.files.iirv.terms.SequenceNumberTerm}.
  55.      */
  56.     public IIRVSegment(final int startYear, final IIRVMessage iirvMessage) {
  57.         this(Constants.IERS96_EARTH_MU, 7, startYear, iirvMessage);
  58.     }

  59.     /**
  60.      * Constructs a {@link IIRVSegment} instance.
  61.      *
  62.      * @param mu                   gravitational parameter (m^3/s^2)
  63.      * @param interpolationSamples number of samples to use in interpolation
  64.      * @param startYear            Year associated with the beginning of the IIRV message
  65.      * @param iirvMessage          IIRV message consisting of sequential {@link IIRVVector} instances, sorted by
  66.      *                             {@link org.orekit.files.iirv.terms.SequenceNumberTerm}.
  67.      */
  68.     public IIRVSegment(final double mu, final int interpolationSamples, final int startYear, final IIRVMessage iirvMessage) {
  69.         this.mu = mu;
  70.         this.interpolationSamples = interpolationSamples;
  71.         this.cartesianDerivativesFilter = CartesianDerivativesFilter.USE_PV;
  72.         this.startYear = startYear;
  73.         this.iirvMessage = iirvMessage;
  74.     }

  75.     /** {@inheritDoc} */
  76.     @Override
  77.     public double getMu() {
  78.         return mu;
  79.     }

  80.     /** {@inheritDoc} */
  81.     @Override
  82.     @DefaultDataContext
  83.     public Frame getFrame() {
  84.         return iirvMessage.getVectors().get(0).getFrame();
  85.     }

  86.     /** {@inheritDoc} */
  87.     @Override
  88.     public int getInterpolationSamples() {
  89.         return interpolationSamples;
  90.     }

  91.     /** {@inheritDoc} */
  92.     @Override
  93.     public CartesianDerivativesFilter getAvailableDerivatives() {
  94.         return cartesianDerivativesFilter;
  95.     }

  96.     /** {@inheritDoc} */
  97.     @Override
  98.     public AbsoluteDate getStart() {
  99.         return getCoordinates().get(0).getDate();
  100.     }

  101.     /** {@inheritDoc} */
  102.     @Override
  103.     public AbsoluteDate getStop() {
  104.         return getCoordinates().get(getCoordinates().size() - 1).getDate();
  105.     }

  106.     /** {@inheritDoc} */
  107.     @Override
  108.     public List<TimeStampedPVCoordinates> getCoordinates() {
  109.         int year = startYear;
  110.         final List<IIRVVector> iirvVectors = iirvMessage.getVectors();

  111.         final ArrayList<TimeStampedPVCoordinates> coordinates = new ArrayList<>();
  112.         coordinates.add(iirvVectors.get(0).getTimeStampedPVCoordinates(year));

  113.         for (int i = 1; i < iirvVectors.size(); i++) {
  114.             final IIRVVector prev = iirvVectors.get(i - 1);
  115.             final IIRVVector next = iirvVectors.get(i);

  116.             // Increase the year counter if the previous day is greater than the current day
  117.             if (prev.getDayOfYear().value() > next.getDayOfYear().value()) {
  118.                 year++;
  119.             }
  120.             coordinates.add(next.getTimeStampedPVCoordinates(year));
  121.         }
  122.         return Collections.unmodifiableList(coordinates);
  123.     }

  124.     /**
  125.      * Gets the IIRV message for this segment.
  126.      *
  127.      * @return IIRV message for this segment
  128.      */
  129.     public IIRVMessage getIIRVMessage() {
  130.         return iirvMessage;
  131.     }

  132.     /**
  133.      * Gets the start year for this segment.
  134.      *
  135.      * @return start year for this segment.
  136.      */
  137.     public int getStartYear() {
  138.         return startYear;
  139.     }
  140. }