AbstractStateCovarianceInterpolator.java

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

  18. import org.orekit.frames.Frame;
  19. import org.orekit.frames.LOFType;
  20. import org.orekit.orbits.Orbit;
  21. import org.orekit.orbits.OrbitType;
  22. import org.orekit.orbits.PositionAngleType;
  23. import org.orekit.time.AbsoluteDate;
  24. import org.orekit.time.AbstractTimeInterpolator;
  25. import org.orekit.time.TimeInterpolator;
  26. import org.orekit.time.TimeStampedPair;

  27. import java.util.List;
  28. import java.util.stream.Collectors;
  29. import java.util.stream.Stream;

  30. /**
  31.  * Abstract class for orbit and state covariance interpolator.
  32.  *
  33.  * @author Vincent Cucchietti
  34.  * @see Orbit
  35.  * @see StateCovariance
  36.  * @see TimeStampedPair
  37.  */
  38. public abstract class AbstractStateCovarianceInterpolator
  39.         extends AbstractTimeInterpolator<TimeStampedPair<Orbit, StateCovariance>> {

  40.     /** Default position angle for covariance expressed in Cartesian elements. */
  41.     public static final PositionAngleType DEFAULT_POSITION_ANGLE = PositionAngleType.MEAN;

  42.     /** Default column dimension for position-velocity state covariance. */
  43.     public static final int COLUMN_DIM = 6;

  44.     /** Default row dimension for position-velocity state covariance. */
  45.     public static final int ROW_DIM = 6;

  46.     /** Output frame. */
  47.     private final Frame outFrame;

  48.     /** Output local orbital frame. */
  49.     private final LOFType outLOF;

  50.     /** Output orbit type. */
  51.     private final OrbitType outOrbitType;

  52.     /** Output position angle type. */
  53.     private final PositionAngleType outPositionAngleType;

  54.     /** Orbit interpolator. */
  55.     private final TimeInterpolator<Orbit> orbitInterpolator;

  56.     /**
  57.      * Constructor.
  58.      *
  59.      * @param interpolationPoints number of interpolation points
  60.      * @param extrapolationThreshold extrapolation threshold beyond which the propagation will fail
  61.      * @param orbitInterpolator orbit interpolator
  62.      * @param outLOF local orbital frame
  63.      *
  64.      * @see Frame
  65.      * @see OrbitType
  66.      * @see PositionAngleType
  67.      */
  68.     public AbstractStateCovarianceInterpolator(final int interpolationPoints, final double extrapolationThreshold,
  69.                                                final TimeInterpolator<Orbit> orbitInterpolator,
  70.                                                final LOFType outLOF) {
  71.         super(interpolationPoints, extrapolationThreshold);
  72.         this.orbitInterpolator = orbitInterpolator;
  73.         this.outLOF            = outLOF;
  74.         this.outFrame          = null;
  75.         this.outOrbitType      = OrbitType.CARTESIAN;
  76.         this.outPositionAngleType = DEFAULT_POSITION_ANGLE;
  77.     }

  78.     /**
  79.      * Constructor.
  80.      *
  81.      * @param interpolationPoints number of interpolation points
  82.      * @param extrapolationThreshold extrapolation threshold beyond which the propagation will fail
  83.      * @param orbitInterpolator orbit interpolator
  84.      * @param outFrame desired output covariance frame
  85.      * @param outPositionAngleType desired output position angle
  86.      * @param outOrbitType desired output orbit type
  87.      *
  88.      * @see Frame
  89.      * @see OrbitType
  90.      * @see PositionAngleType
  91.      */
  92.     public AbstractStateCovarianceInterpolator(final int interpolationPoints, final double extrapolationThreshold,
  93.                                                final TimeInterpolator<Orbit> orbitInterpolator,
  94.                                                final Frame outFrame,
  95.                                                final OrbitType outOrbitType,
  96.                                                final PositionAngleType outPositionAngleType) {
  97.         super(interpolationPoints, extrapolationThreshold);
  98.         this.orbitInterpolator = orbitInterpolator;
  99.         this.outLOF            = null;
  100.         this.outFrame          = outFrame;
  101.         this.outOrbitType      = outOrbitType;
  102.         this.outPositionAngleType = outPositionAngleType;
  103.     }

  104.     /**
  105.      * Interpolate orbit and associated covariance.
  106.      *
  107.      * @param interpolationData interpolation data
  108.      *
  109.      * @return interpolated orbit and associated covariance
  110.      */
  111.     @Override
  112.     public TimeStampedPair<Orbit, StateCovariance> interpolate(final InterpolationData interpolationData) {

  113.         // Interpolate orbit at interpolation date
  114.         final Orbit interpolatedOrbit = interpolateOrbit(interpolationData.getInterpolationDate(),
  115.                                                          interpolationData.getNeighborList());

  116.         // Rebuild state covariance
  117.         final StateCovariance covarianceInOrbitFrame =
  118.                 computeInterpolatedCovarianceInOrbitFrame(interpolationData.getNeighborList(), interpolatedOrbit);

  119.         // Output new blended StateCovariance instance in desired output
  120.         return expressCovarianceInDesiredOutput(interpolatedOrbit, covarianceInOrbitFrame);
  121.     }

  122.     /** Get output frame.
  123.      * @return output frame. Can be null.
  124.      */
  125.     public Frame getOutFrame() {
  126.         return outFrame;
  127.     }

  128.     /** Get output local orbital frame.
  129.      * @return output local orbital frame. Can be null.
  130.      */
  131.     public LOFType getOutLOF() {
  132.         return outLOF;
  133.     }

  134.     /** Get output orbit type.
  135.      * @return output orbit type.
  136.      */
  137.     public OrbitType getOutOrbitType() {
  138.         return outOrbitType;
  139.     }

  140.     /** Get output position angle type.
  141.      * @return output position angle.
  142.      */
  143.     public PositionAngleType getOutPositionAngleType() {
  144.         return outPositionAngleType;
  145.     }

  146.     /** Get orbit interpolator.
  147.      * @return orbit interpolator.
  148.      */
  149.     public TimeInterpolator<Orbit> getOrbitInterpolator() {
  150.         return orbitInterpolator;
  151.     }

  152.     /**
  153.      * Interpolate orbit at given interpolation date.
  154.      *
  155.      * @param interpolationDate interpolation date
  156.      * @param neighborList neighbor list
  157.      *
  158.      * @return interpolated orbit
  159.      */
  160.     protected Orbit interpolateOrbit(final AbsoluteDate interpolationDate,
  161.                                      final List<TimeStampedPair<Orbit, StateCovariance>> neighborList) {

  162.         // Build orbit list from uncertain orbits
  163.         final List<Orbit> orbits = buildOrbitList(neighborList);

  164.         return orbitInterpolator.interpolate(interpolationDate, orbits);
  165.     }

  166.     /**
  167.      * Compute the interpolated covariance expressed in the interpolated orbit frame.
  168.      *
  169.      * @param uncertainStates list of orbits and associated covariances
  170.      * @param interpolatedOrbit interpolated orbit
  171.      *
  172.      * @return interpolated covariance expressed in the interpolated orbit frame
  173.      */
  174.     protected abstract StateCovariance computeInterpolatedCovarianceInOrbitFrame(
  175.             List<TimeStampedPair<Orbit, StateCovariance>> uncertainStates,
  176.             Orbit interpolatedOrbit);

  177.     /**
  178.      * Express covariance in output configuration defined at this instance construction.
  179.      *
  180.      * @param interpolatedOrbit interpolated orbit
  181.      * @param covarianceInOrbitFrame covariance expressed in interpolated orbit frame
  182.      *
  183.      * @return covariance in desired output configuration
  184.      */
  185.     protected TimeStampedPair<Orbit, StateCovariance> expressCovarianceInDesiredOutput(final Orbit interpolatedOrbit,
  186.                                                                                        final StateCovariance covarianceInOrbitFrame) {

  187.         final StateCovariance covarianceOutput;

  188.         // Output frame is defined
  189.         if (outLOF == null) {

  190.             // Output frame is pseudo inertial
  191.             if (outFrame.isPseudoInertial()) {
  192.                 final StateCovariance covarianceInOutputFrame =
  193.                         covarianceInOrbitFrame.changeCovarianceFrame(interpolatedOrbit, outFrame);

  194.                 covarianceOutput =
  195.                         covarianceInOutputFrame.changeCovarianceType(interpolatedOrbit, outOrbitType, outPositionAngleType);
  196.             }
  197.             // Output frame is not pseudo inertial
  198.             else {
  199.                 covarianceOutput = covarianceInOrbitFrame.changeCovarianceFrame(interpolatedOrbit, outFrame);
  200.             }

  201.         }
  202.         // Output local orbital frame is defined
  203.         else {
  204.             covarianceOutput = covarianceInOrbitFrame.changeCovarianceFrame(interpolatedOrbit, outLOF);
  205.         }

  206.         return new TimeStampedPair<>(interpolatedOrbit, covarianceOutput);
  207.     }

  208.     /**
  209.      * Build an orbit list from cached samples.
  210.      *
  211.      * @param neighborList neighbor list
  212.      *
  213.      * @return orbit list
  214.      */
  215.     private List<Orbit> buildOrbitList(final List<TimeStampedPair<Orbit, StateCovariance>> neighborList) {

  216.         // Get samples stream
  217.         final Stream<TimeStampedPair<Orbit, StateCovariance>> uncertainStateStream = neighborList.stream();

  218.         // Map to orbit
  219.         final Stream<Orbit> orbitStream = uncertainStateStream.map(TimeStampedPair::getFirst);

  220.         // Convert to list
  221.         return orbitStream.collect(Collectors.toList());
  222.     }
  223. }