RangeRateIonosphericDelayModifier.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.modifiers;

  18. import java.util.Arrays;
  19. import java.util.List;

  20. import org.hipparchus.RealFieldElement;
  21. import org.hipparchus.analysis.differentiation.DerivativeStructure;
  22. import org.orekit.attitudes.InertialProvider;
  23. import org.orekit.estimation.measurements.EstimatedMeasurement;
  24. import org.orekit.estimation.measurements.EstimationModifier;
  25. import org.orekit.estimation.measurements.GroundStation;
  26. import org.orekit.estimation.measurements.RangeRate;
  27. import org.orekit.frames.TopocentricFrame;
  28. import org.orekit.models.earth.ionosphere.IonosphericModel;
  29. import org.orekit.propagation.FieldSpacecraftState;
  30. import org.orekit.propagation.SpacecraftState;
  31. import org.orekit.utils.Differentiation;
  32. import org.orekit.utils.ParameterDriver;
  33. import org.orekit.utils.ParameterFunction;

  34. /** Class modifying theoretical range-rate measurement with ionospheric delay.
  35.  * The effect of ionospheric correction on the range-rate is directly computed
  36.  * through the computation of the ionospheric delay difference with respect to
  37.  * time.
  38.  *
  39.  * The ionospheric delay depends on the frequency of the signal (GNSS, VLBI, ...).
  40.  * For optical measurements (e.g. SLR), the ray is not affected by ionosphere charged particles.
  41.  * <p>
  42.  * Since 10.0, state derivatives and ionospheric parameters derivates are computed
  43.  * using automatic differentiation.
  44.  * </p>
  45.  * @author Joris Olympio
  46.  * @since 8.0
  47.  */
  48. public class RangeRateIonosphericDelayModifier implements EstimationModifier<RangeRate> {

  49.     /** Ionospheric delay model. */
  50.     private final IonosphericModel ionoModel;

  51.     /** Frequency [Hz]. */
  52.     private final double frequency;

  53.     /** Coefficient for measurment configuration (one-way, two-way). */
  54.     private final double fTwoWay;

  55.     /** Constructor.
  56.      *
  57.      * @param model Ionospheric delay model appropriate for the current range-rate measurement method.
  58.      * @param freq frequency of the signal in Hz
  59.      * @param twoWay Flag indicating whether the measurement is two-way.
  60.      */
  61.     public RangeRateIonosphericDelayModifier(final IonosphericModel model,
  62.                                              final double freq, final boolean twoWay) {
  63.         ionoModel = model;
  64.         frequency = freq;

  65.         if (twoWay) {
  66.             fTwoWay = 2.;
  67.         } else {
  68.             fTwoWay = 1.;
  69.         }
  70.     }

  71.     /** Compute the measurement error due to Ionosphere.
  72.      * @param station station
  73.      * @param state spacecraft state
  74.      * @return the measurement error due to Ionosphere
  75.      */
  76.     private double rangeRateErrorIonosphericModel(final GroundStation station, final SpacecraftState state) {
  77.         final double dt = 10; // s
  78.         // Base frame associated with the station
  79.         final TopocentricFrame baseFrame = station.getBaseFrame();
  80.         // delay in meters
  81.         final double delay1 = ionoModel.pathDelay(state, baseFrame, frequency, ionoModel.getParameters());
  82.         // propagate spacecraft state forward by dt
  83.         final SpacecraftState state2 = state.shiftedBy(dt);
  84.         // ionospheric delay dt after in meters
  85.         final double delay2 = ionoModel.pathDelay(state2, baseFrame, frequency, ionoModel.getParameters());
  86.         // delay in meters
  87.         return fTwoWay * (delay2 - delay1) / dt;
  88.     }

  89.     /** Compute the measurement error due to Ionosphere.
  90.      * @param <T> type of the elements
  91.      * @param station station
  92.      * @param state spacecraft state
  93.      * @param parameters ionospheric model parameters
  94.      * @return the measurement error due to Ionosphere
  95.      */
  96.     private <T extends RealFieldElement<T>> T rangeRateErrorIonosphericModel(final GroundStation station,
  97.                                                                              final FieldSpacecraftState<T> state,
  98.                                                                              final T[] parameters) {
  99.         final double dt = 10; // s
  100.         // Base frame associated with the station
  101.         final TopocentricFrame baseFrame = station.getBaseFrame();
  102.         // delay in meters
  103.         final T delay1 = ionoModel.pathDelay(state, baseFrame, frequency, parameters);
  104.         // propagate spacecraft state forward by dt
  105.         final FieldSpacecraftState<T> state2 = state.shiftedBy(dt);
  106.         // ionospheric delay dt after in meters
  107.         final T delay2 = ionoModel.pathDelay(state2, baseFrame, frequency, parameters);
  108.         // delay in meters
  109.         return delay2.subtract(delay1).divide(dt).multiply(fTwoWay);
  110.     }

  111.     /** Compute the Jacobian of the delay term wrt state using
  112.     * automatic differentiation.
  113.     *
  114.     * @param derivatives ionospheric delay derivatives
  115.     * @param freeStateParameters dimension of the state.
  116.     *
  117.     * @return Jacobian of the delay wrt state
  118.     */
  119.     private double[][] rangeRateErrorJacobianState(final double[] derivatives, final int freeStateParameters) {
  120.         final double[][] finiteDifferencesJacobian = new double[1][6];
  121.         for (int i = 0; i < freeStateParameters; i++) {
  122.             // First element is the value of the delay
  123.             finiteDifferencesJacobian[0][i] = derivatives[i + 1];
  124.         }
  125.         return finiteDifferencesJacobian;
  126.     }

  127.     /** Compute the derivative of the delay term wrt parameters.
  128.     *
  129.     * @param station ground station
  130.     * @param driver driver for the station offset parameter
  131.     * @param state spacecraft state
  132.     * @return derivative of the delay wrt station offset parameter
  133.     */
  134.     private double rangeRateErrorParameterDerivative(final GroundStation station,
  135.                                                      final ParameterDriver driver,
  136.                                                      final SpacecraftState state) {

  137.         final ParameterFunction rangeError = new ParameterFunction() {
  138.             /** {@inheritDoc} */
  139.             @Override
  140.             public double value(final ParameterDriver parameterDriver) {
  141.                 return rangeRateErrorIonosphericModel(station, state);
  142.             }
  143.         };

  144.         final ParameterFunction rangeErrorDerivative =
  145.                         Differentiation.differentiate(rangeError, 3, 10.0 * driver.getScale());

  146.         return rangeErrorDerivative.value(driver);

  147.     }

  148.     /** Compute the derivative of the delay term wrt parameters using
  149.     * automatic differentiation.
  150.     *
  151.     * @param derivatives ionospheric delay derivatives
  152.     * @param freeStateParameters dimension of the state.
  153.     * @return derivative of the delay wrt ionospheric model parameters
  154.     */
  155.     private double[] rangeRateErrorParameterDerivative(final double[] derivatives, final int freeStateParameters) {
  156.         // 0                               -> value of the delay
  157.         // 1 ... freeStateParameters       -> derivatives of the delay wrt state
  158.         // freeStateParameters + 1 ... n   -> derivatives of the delay wrt ionospheric parameters
  159.         final int dim = derivatives.length - 1 - freeStateParameters;
  160.         final double[] rangeError = new double[dim];

  161.         for (int i = 0; i < dim; i++) {
  162.             rangeError[i] = derivatives[1 + freeStateParameters + i];
  163.         }

  164.         return rangeError;
  165.     }

  166.     /** {@inheritDoc} */
  167.     @Override
  168.     public List<ParameterDriver> getParametersDrivers() {
  169.         return ionoModel.getParametersDrivers();
  170.     }

  171.     /** {@inheritDoc} */
  172.     @Override
  173.     public void modify(final EstimatedMeasurement<RangeRate> estimated) {

  174.         final RangeRate       measurement = estimated.getObservedMeasurement();
  175.         final GroundStation   station     = measurement.getStation();
  176.         final SpacecraftState state       = estimated.getStates()[0];

  177.         final double[] oldValue = estimated.getEstimatedValue();

  178.         // update estimated derivatives with Jacobian of the measure wrt state
  179.         final IonosphericDSConverter converter =
  180.                 new IonosphericDSConverter(state, 6, new InertialProvider(state.getFrame()));
  181.         final FieldSpacecraftState<DerivativeStructure> dsState = converter.getState(ionoModel);
  182.         final DerivativeStructure[] dsParameters = converter.getParameters(dsState, ionoModel);
  183.         final DerivativeStructure dsDelay = rangeRateErrorIonosphericModel(station, dsState, dsParameters);
  184.         final double[] derivatives = dsDelay.getAllDerivatives();

  185.         // update estimated derivatives with Jacobian of the measure wrt state
  186.         final double[][] djac = rangeRateErrorJacobianState(derivatives, converter.getFreeStateParameters());
  187.         final double[][] stateDerivatives = estimated.getStateDerivatives(0);
  188.         for (int irow = 0; irow < stateDerivatives.length; ++irow) {
  189.             for (int jcol = 0; jcol < stateDerivatives[0].length; ++jcol) {
  190.                 stateDerivatives[irow][jcol] += djac[irow][jcol];
  191.             }
  192.         }
  193.         estimated.setStateDerivatives(0, stateDerivatives);

  194.         int index = 0;
  195.         for (final ParameterDriver driver : getParametersDrivers()) {
  196.             if (driver.isSelected()) {
  197.                 // update estimated derivatives with derivative of the modification wrt ionospheric parameters
  198.                 double parameterDerivative = estimated.getParameterDerivatives(driver)[0];
  199.                 final double[] dDelaydP    = rangeRateErrorParameterDerivative(derivatives, converter.getFreeStateParameters());
  200.                 parameterDerivative += dDelaydP[index];
  201.                 estimated.setParameterDerivatives(driver, parameterDerivative);
  202.                 index = index + 1;
  203.             }

  204.         }

  205.         for (final ParameterDriver driver : Arrays.asList(station.getClockOffsetDriver(),
  206.                                                           station.getEastOffsetDriver(),
  207.                                                           station.getNorthOffsetDriver(),
  208.                                                           station.getZenithOffsetDriver())) {
  209.             if (driver.isSelected()) {
  210.                 // update estimated derivatives with derivative of the modification wrt station parameters
  211.                 double parameterDerivative = estimated.getParameterDerivatives(driver)[0];
  212.                 parameterDerivative += rangeRateErrorParameterDerivative(station, driver, state);
  213.                 estimated.setParameterDerivatives(driver, parameterDerivative);
  214.             }
  215.         }

  216.         // update estimated value taking into account the ionospheric delay.
  217.         // The ionospheric delay is directly added to the range.
  218.         final double[] newValue = oldValue.clone();
  219.         newValue[0] = newValue[0] + dsDelay.getValue();
  220.         estimated.setEstimatedValue(newValue);

  221.     }

  222. }