AbstractMeasurement.java

  1. /* Copyright 2002-2017 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.      */
  71.     protected AbstractMeasurement(final AbsoluteDate date, final double observed,
  72.                                   final double sigma, final double baseWeight,
  73.                                   final List<Integer> propagatorsIndices,
  74.                                   final ParameterDriver... supportedParameters) {

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

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

  89.         this.propagatorsIndices = propagatorsIndices;

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

  92.     }

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

  112.         this.date       = date;
  113.         this.observed   = observed.clone();
  114.         this.sigma      = sigma.clone();
  115.         this.baseWeight = baseWeight.clone();

  116.         this.propagatorsIndices = propagatorsIndices;

  117.         this.modifiers = new ArrayList<EstimationModifier<T>>();
  118.         setEnabled(true);

  119.     }

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

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

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

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

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

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

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

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

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

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

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

  178.         return estimation;

  179.     }

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

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

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

  194.         // combine the measurement parameters and the modifier parameters
  195.         supportedParameters.addAll(modifier.getParametersDrivers());

  196.         modifiers.add(modifier);

  197.     }

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

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

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

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

  228.         return delay;

  229.     }

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

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

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

  256.         return delay;

  257.     }

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

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

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

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

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

  296.     }

  297. }