AbstractMeasurement.java

  1. /* Copyright 2002-2020 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.estimation.measurements;

  18. import java.util.ArrayList;
  19. import java.util.Collections;
  20. import java.util.List;

  21. import org.hipparchus.RealFieldElement;
  22. import org.hipparchus.analysis.differentiation.DSFactory;
  23. import org.hipparchus.analysis.differentiation.DerivativeStructure;
  24. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  25. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  26. import org.hipparchus.util.FastMath;
  27. import org.orekit.propagation.SpacecraftState;
  28. import org.orekit.time.AbsoluteDate;
  29. import org.orekit.time.FieldAbsoluteDate;
  30. import org.orekit.utils.Constants;
  31. import org.orekit.utils.ParameterDriver;
  32. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  33. import org.orekit.utils.TimeStampedPVCoordinates;

  34. /** Abstract class handling measurements boilerplate.
  35.  * @param <T> the type of the measurement
  36.  * @author Luc Maisonobe
  37.  * @since 8.0
  38.  */
  39. public abstract class AbstractMeasurement<T extends ObservedMeasurement<T>>
  40.     implements ObservedMeasurement<T> {

  41.     /** List of the supported parameters. */
  42.     private final List<ParameterDriver> supportedParameters;

  43.     /** Satellites related to this measurement.
  44.      * @since 9.3
  45.      */
  46.     private final List<ObservableSatellite> satellites;

  47.     /** Date of the measurement. */
  48.     private final AbsoluteDate date;

  49.     /** Observed value. */
  50.     private final double[] observed;

  51.     /** Theoretical standard deviation. */
  52.     private final double[] sigma;

  53.     /** Base weight. */
  54.     private final double[] baseWeight;

  55.     /** Modifiers that apply to the measurement.*/
  56.     private final List<EstimationModifier<T>> modifiers;

  57.     /** Enabling status. */
  58.     private boolean enabled;

  59.     /** Simple constructor for mono-dimensional measurements.
  60.      * <p>
  61.      * At construction, a measurement is enabled.
  62.      * </p>
  63.      * @param date date of the measurement
  64.      * @param observed observed value
  65.      * @param sigma theoretical standard deviation
  66.      * @param baseWeight base weight
  67.      * @param satellites satellites related to this measurement
  68.      * @since 9.3
  69.      */
  70.     protected AbstractMeasurement(final AbsoluteDate date, final double observed,
  71.                                   final double sigma, final double baseWeight,
  72.                                   final List<ObservableSatellite> satellites) {

  73.         this.supportedParameters = new ArrayList<ParameterDriver>();
  74.         for (final ParameterDriver parameterDriver : supportedParameters) {
  75.             this.supportedParameters.add(parameterDriver);
  76.         }

  77.         this.date       = date;
  78.         this.observed   = new double[] {
  79.             observed
  80.         };
  81.         this.sigma      = new double[] {
  82.             sigma
  83.         };
  84.         this.baseWeight = new double[] {
  85.             baseWeight
  86.         };

  87.         this.satellites = satellites;

  88.         this.modifiers = new ArrayList<EstimationModifier<T>>();
  89.         setEnabled(true);

  90.     }

  91.     /** Simple constructor, for multi-dimensional measurements.
  92.      * <p>
  93.      * At construction, a measurement is enabled.
  94.      * </p>
  95.      * @param date date of the measurement
  96.      * @param observed observed value
  97.      * @param sigma theoretical standard deviation
  98.      * @param baseWeight base weight
  99.      * @param satellites satellites related to this measurement
  100.      * @since 9.3
  101.      */
  102.     protected AbstractMeasurement(final AbsoluteDate date, final double[] observed,
  103.                                   final double[] sigma, final double[] baseWeight,
  104.                                   final List<ObservableSatellite> satellites) {
  105.         this.supportedParameters = new ArrayList<ParameterDriver>();

  106.         this.date       = date;
  107.         this.observed   = observed.clone();
  108.         this.sigma      = sigma.clone();
  109.         this.baseWeight = baseWeight.clone();

  110.         this.satellites = satellites;

  111.         this.modifiers = new ArrayList<EstimationModifier<T>>();
  112.         setEnabled(true);

  113.     }

  114.     /** Add a parameter driver.
  115.      * @param driver parameter driver to add
  116.      * @since 9.3
  117.      */
  118.     protected void addParameterDriver(final ParameterDriver driver) {
  119.         supportedParameters.add(driver);
  120.     }

  121.     /** {@inheritDoc} */
  122.     @Override
  123.     public List<ParameterDriver> getParametersDrivers() {
  124.         return Collections.unmodifiableList(supportedParameters);
  125.     }

  126.     /** {@inheritDoc} */
  127.     @Override
  128.     public void setEnabled(final boolean enabled) {
  129.         this.enabled = enabled;
  130.     }

  131.     /** {@inheritDoc} */
  132.     @Override
  133.     public boolean isEnabled() {
  134.         return enabled;
  135.     }

  136.     /** {@inheritDoc} */
  137.     @Override
  138.     public int getDimension() {
  139.         return observed.length;
  140.     }

  141.     /** {@inheritDoc} */
  142.     @Override
  143.     public double[] getTheoreticalStandardDeviation() {
  144.         return sigma.clone();
  145.     }

  146.     /** {@inheritDoc} */
  147.     @Override
  148.     public double[] getBaseWeight() {
  149.         return baseWeight.clone();
  150.     }

  151.     /** {@inheritDoc} */
  152.     @Override
  153.     public List<ObservableSatellite> getSatellites() {
  154.         return satellites;
  155.     }

  156.     /** Estimate the theoretical value.
  157.      * <p>
  158.      * The theoretical value does not have <em>any</em> modifiers applied.
  159.      * </p>
  160.      * @param iteration iteration number
  161.      * @param evaluation evaluation number
  162.      * @param states orbital states at measurement date
  163.      * @return theoretical value
  164.      * @see #estimate(int, int, SpacecraftState[])
  165.      */
  166.     protected abstract EstimatedMeasurement<T> theoreticalEvaluation(int iteration, int evaluation, SpacecraftState[] states);

  167.     /** {@inheritDoc} */
  168.     @Override
  169.     public EstimatedMeasurement<T> estimate(final int iteration, final int evaluation, final SpacecraftState[] states) {

  170.         // compute the theoretical value
  171.         final EstimatedMeasurement<T> estimation = theoreticalEvaluation(iteration, evaluation, states);

  172.         // apply the modifiers
  173.         for (final EstimationModifier<T> modifier : modifiers) {
  174.             modifier.modify(estimation);
  175.         }

  176.         return estimation;

  177.     }

  178.     /** {@inheritDoc} */
  179.     @Override
  180.     public AbsoluteDate getDate() {
  181.         return date;
  182.     }

  183.     /** {@inheritDoc} */
  184.     @Override
  185.     public double[] getObservedValue() {
  186.         return observed.clone();
  187.     }

  188.     /** {@inheritDoc} */
  189.     @Override
  190.     public void addModifier(final EstimationModifier<T> modifier) {

  191.         // combine the measurement parameters and the modifier parameters
  192.         supportedParameters.addAll(modifier.getParametersDrivers());

  193.         modifiers.add(modifier);

  194.     }

  195.     /** {@inheritDoc} */
  196.     @Override
  197.     public List<EstimationModifier<T>> getModifiers() {
  198.         return Collections.unmodifiableList(modifiers);
  199.     }

  200.     /** Compute propagation delay on a link leg (typically downlink or uplink).
  201.      * @param adjustableEmitterPV position/velocity of emitter that may be adjusted
  202.      * @param receiverPosition fixed position of receiver at {@code signalArrivalDate},
  203.      * in the same frame as {@code adjustableEmitterPV}
  204.      * @param signalArrivalDate date at which the signal arrives to receiver
  205.      * @return <em>positive</em> delay between signal emission and signal reception dates
  206.      */
  207.     public static double signalTimeOfFlight(final TimeStampedPVCoordinates adjustableEmitterPV,
  208.                                             final Vector3D receiverPosition,
  209.                                             final AbsoluteDate signalArrivalDate) {

  210.         // initialize emission date search loop assuming the state is already correct
  211.         // this will be true for all but the first orbit determination iteration,
  212.         // and even for the first iteration the loop will converge very fast
  213.         final double offset = signalArrivalDate.durationFrom(adjustableEmitterPV.getDate());
  214.         double delay = offset;

  215.         // search signal transit date, computing the signal travel in inertial frame
  216.         final double cReciprocal = 1.0 / Constants.SPEED_OF_LIGHT;
  217.         double delta;
  218.         int count = 0;
  219.         do {
  220.             final double previous   = delay;
  221.             final Vector3D transitP = adjustableEmitterPV.shiftedBy(offset - delay).getPosition();
  222.             delay                   = receiverPosition.distance(transitP) * cReciprocal;
  223.             delta                   = FastMath.abs(delay - previous);
  224.         } while (count++ < 10 && delta >= 2 * FastMath.ulp(delay));

  225.         return delay;

  226.     }

  227.     /** Compute propagation delay on a link leg (typically downlink or uplink).
  228.      * @param adjustableEmitterPV position/velocity of emitter that may be adjusted
  229.      * @param receiverPosition fixed position of receiver at {@code signalArrivalDate},
  230.      * in the same frame as {@code adjustableEmitterPV}
  231.      * @param signalArrivalDate date at which the signal arrives to receiver
  232.      * @return <em>positive</em> delay between signal emission and signal reception dates
  233.      * @param <T> the type of the components
  234.      */
  235.     public static <T extends RealFieldElement<T>> T signalTimeOfFlight(final TimeStampedFieldPVCoordinates<T> adjustableEmitterPV,
  236.                                                                        final FieldVector3D<T> receiverPosition,
  237.                                                                        final FieldAbsoluteDate<T> signalArrivalDate) {

  238.         // Initialize emission date search loop assuming the emitter PV is almost correct
  239.         // this will be true for all but the first orbit determination iteration,
  240.         // and even for the first iteration the loop will converge extremely fast
  241.         final T offset = signalArrivalDate.durationFrom(adjustableEmitterPV.getDate());
  242.         T delay = offset;

  243.         // search signal transit date, computing the signal travel in the frame shared by emitter and receiver
  244.         final double cReciprocal = 1.0 / Constants.SPEED_OF_LIGHT;
  245.         double delta;
  246.         int count = 0;
  247.         do {
  248.             final double previous           = delay.getReal();
  249.             final FieldVector3D<T> transitP = adjustableEmitterPV.shiftedBy(delay.negate().add(offset)).getPosition();
  250.             delay                           = receiverPosition.distance(transitP).multiply(cReciprocal);
  251.             delta                           = FastMath.abs(delay.getReal() - previous);
  252.         } while (count++ < 10 && delta >= 2 * FastMath.ulp(delay.getReal()));

  253.         return delay;

  254.     }

  255.     /** Get Cartesian coordinates as derivatives.
  256.      * <p>
  257.      * The position will correspond to variables {@code firstDerivative},
  258.      * {@code firstDerivative + 1} and {@code firstDerivative + 2}.
  259.      * The velocity will correspond to variables {@code firstDerivative + 3},
  260.      * {@code firstDerivative + 4} and {@code firstDerivative + 5}.
  261.      * The acceleration will correspond to constants.
  262.      * </p>
  263.      * @param state state of the satellite considered
  264.      * @param firstDerivative index of the first derivative
  265.      * @param factory factory for building the derivatives
  266.      * @return Cartesian coordinates as derivatives
  267.      */
  268.     public static TimeStampedFieldPVCoordinates<DerivativeStructure> getCoordinates(final SpacecraftState state,
  269.                                                                                     final int firstDerivative,
  270.                                                                                     final DSFactory factory) {

  271.         // Position of the satellite expressed as a derivative structure
  272.         // The components of the position are the 3 first derivative parameters
  273.         final Vector3D p = state.getPVCoordinates().getPosition();
  274.         final FieldVector3D<DerivativeStructure> pDS =
  275.                         new FieldVector3D<>(factory.variable(firstDerivative + 0, p.getX()),
  276.                                             factory.variable(firstDerivative + 1, p.getY()),
  277.                                             factory.variable(firstDerivative + 2, p.getZ()));

  278.         // Velocity of the satellite expressed as a derivative structure
  279.         // The components of the velocity are the 3 second derivative parameters
  280.         final Vector3D v = state.getPVCoordinates().getVelocity();
  281.         final FieldVector3D<DerivativeStructure> vDS =
  282.                         new FieldVector3D<>(factory.variable(firstDerivative + 3, v.getX()),
  283.                                             factory.variable(firstDerivative + 4, v.getY()),
  284.                                             factory.variable(firstDerivative + 5, v.getZ()));

  285.         // Acceleration of the satellite
  286.         // The components of the acceleration are not derivative parameters
  287.         final Vector3D a = state.getPVCoordinates().getAcceleration();
  288.         final FieldVector3D<DerivativeStructure> aDS =
  289.                         new FieldVector3D<>(factory.constant(a.getX()),
  290.                                             factory.constant(a.getY()),
  291.                                             factory.constant(a.getZ()));

  292.         return new TimeStampedFieldPVCoordinates<>(state.getDate(), pDS, vDS, aDS);

  293.     }

  294. }