AbstractMeasurement.java

  1. /* Copyright 2002-2018 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.errors.OrekitException;
  28. import org.orekit.propagation.SpacecraftState;
  29. import org.orekit.time.AbsoluteDate;
  30. import org.orekit.time.FieldAbsoluteDate;
  31. import org.orekit.utils.Constants;
  32. import org.orekit.utils.ParameterDriver;
  33. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  34. import org.orekit.utils.TimeStampedPVCoordinates;

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

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

  44.     /** Indices of the propagators related to this measurement.
  45.      * @since 9.0
  46.      */
  47.     private final List<Integer> propagatorsIndices;

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

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

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

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

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

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

  60.     /** Simple constructor for mono-dimensional measurements.
  61.      * <p>
  62.      * At construction, a measurement is enabled.
  63.      * </p>
  64.      * @param date date of the measurement
  65.      * @param observed observed value
  66.      * @param sigma theoretical standard deviation
  67.      * @param baseWeight base weight
  68.      * @param propagatorsIndices indices of the propagators related to this measurement
  69.      * @param supportedParameters supported parameters
  70.      * @throws OrekitException may be used in classes that extends this one
  71.      */
  72.     protected AbstractMeasurement(final AbsoluteDate date, final double observed,
  73.                                   final double sigma, final double baseWeight,
  74.                                   final List<Integer> propagatorsIndices,
  75.                                   final ParameterDriver... supportedParameters) throws OrekitException {

  76.         this.supportedParameters = new ArrayList<ParameterDriver>(supportedParameters.length);
  77.         for (final ParameterDriver parameterDriver : supportedParameters) {
  78.             this.supportedParameters.add(parameterDriver);
  79.         }

  80.         this.date       = date;
  81.         this.observed   = new double[] {
  82.             observed
  83.         };
  84.         this.sigma      = new double[] {
  85.             sigma
  86.         };
  87.         this.baseWeight = new double[] {
  88.             baseWeight
  89.         };

  90.         this.propagatorsIndices = propagatorsIndices;

  91.         this.modifiers = new ArrayList<EstimationModifier<T>>();
  92.         setEnabled(true);

  93.     }

  94.     /** Simple constructor, for multi-dimensional measurements.
  95.      * <p>
  96.      * At construction, a measurement is enabled.
  97.      * </p>
  98.      * @param date date of the measurement
  99.      * @param observed observed value
  100.      * @param sigma theoretical standard deviation
  101.      * @param baseWeight base weight
  102.      * @param propagatorsIndices indices of the propagators related to this measurement
  103.      * @param supportedParameters supported parameters
  104.      * @throws OrekitException may be used in classes that extends this one
  105.      */
  106.     protected AbstractMeasurement(final AbsoluteDate date, final double[] observed,
  107.                                   final double[] sigma, final double[] baseWeight,
  108.                                   final List<Integer> propagatorsIndices,
  109.                                   final ParameterDriver... supportedParameters) throws OrekitException {
  110.         this.supportedParameters = new ArrayList<ParameterDriver>(supportedParameters.length);
  111.         for (final ParameterDriver parameterDriver : supportedParameters) {
  112.             this.supportedParameters.add(parameterDriver);
  113.         }

  114.         this.date       = date;
  115.         this.observed   = observed.clone();
  116.         this.sigma      = sigma.clone();
  117.         this.baseWeight = baseWeight.clone();

  118.         this.propagatorsIndices = propagatorsIndices;

  119.         this.modifiers = new ArrayList<EstimationModifier<T>>();
  120.         setEnabled(true);

  121.     }

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

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

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

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

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

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

  152.     /** {@inheritDoc} */
  153.     @Override
  154.     public List<Integer> getPropagatorsIndices() {
  155.         return propagatorsIndices;
  156.     }

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

  170.     /** {@inheritDoc} */
  171.     @Override
  172.     public EstimatedMeasurement<T> estimate(final int iteration, final int evaluation, final SpacecraftState[] states)
  173.         throws OrekitException {

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

  176.         // apply the modifiers
  177.         for (final EstimationModifier<T> modifier : modifiers) {
  178.             modifier.modify(estimation);
  179.         }

  180.         return estimation;

  181.     }

  182.     /** {@inheritDoc} */
  183.     @Override
  184.     public AbsoluteDate getDate() {
  185.         return date;
  186.     }

  187.     /** {@inheritDoc} */
  188.     @Override
  189.     public double[] getObservedValue() {
  190.         return observed.clone();
  191.     }

  192.     /** {@inheritDoc} */
  193.     @Override
  194.     public void addModifier(final EstimationModifier<T> modifier)
  195.         throws OrekitException {

  196.         // combine the measurement parameters and the modifier parameters
  197.         supportedParameters.addAll(modifier.getParametersDrivers());

  198.         modifiers.add(modifier);

  199.     }

  200.     /** {@inheritDoc} */
  201.     @Override
  202.     public List<EstimationModifier<T>> getModifiers() {
  203.         return Collections.unmodifiableList(modifiers);
  204.     }

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

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

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

  230.         return delay;

  231.     }

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

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

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

  258.         return delay;

  259.     }

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

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

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

  290.         // Acceleration of the satellite
  291.         // The components of the acceleration are not derivative parameters
  292.         final Vector3D a = state.getPVCoordinates().getAcceleration();
  293.         final FieldVector3D<DerivativeStructure> aDS =
  294.                         new FieldVector3D<>(factory.constant(a.getX()),
  295.                                             factory.constant(a.getY()),
  296.                                             factory.constant(a.getZ()));

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

  298.     }

  299. }