RangeIonosphericDelayModifier.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.Range;
  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 measurement with ionospheric delay.
  35.  * The effect of ionospheric correction on the range is directly computed
  36.  * through the computation of the ionospheric delay.
  37.  *
  38.  * The ionospheric delay depends on the frequency of the signal (GNSS, VLBI, ...).
  39.  * For optical measurements (e.g. SLR), the ray is not affected by ionosphere charged particles.
  40.  * <p>
  41.  * Since 10.0, state derivatives and ionospheric parameters derivates are computed
  42.  * using automatic differentiation.
  43.  * </p>
  44.  * @author Maxime Journot
  45.  * @author Joris Olympio
  46.  * @since 8.0
  47.  */
  48. public class RangeIonosphericDelayModifier implements EstimationModifier<Range> {

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

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

  53.     /** Constructor.
  54.      *
  55.      * @param model Ionospheric delay model appropriate for the current range measurement method.
  56.      * @param freq frequency of the signal in Hz
  57.      */
  58.     public RangeIonosphericDelayModifier(final IonosphericModel model,
  59.                                          final double freq) {
  60.         ionoModel = model;
  61.         frequency = freq;
  62.     }

  63.     /** Compute the measurement error due to ionosphere.
  64.      * @param station station
  65.      * @param state spacecraft state
  66.      * @return the measurement error due to ionosphere
  67.      */
  68.     private double rangeErrorIonosphericModel(final GroundStation station,
  69.                                               final SpacecraftState state) {
  70.         // Base frame associated with the station
  71.         final TopocentricFrame baseFrame = station.getBaseFrame();
  72.         // delay in meters
  73.         final double delay = ionoModel.pathDelay(state, baseFrame, frequency, ionoModel.getParameters());
  74.         return delay;
  75.     }

  76.     /** Compute the measurement error due to ionosphere.
  77.      * @param <T> type of the element
  78.      * @param station station
  79.      * @param state spacecraft state
  80.      * @param parameters ionospheric model parameters
  81.      * @return the measurement error due to ionosphere
  82.      */
  83.     private <T extends RealFieldElement<T>> T rangeErrorIonosphericModel(final GroundStation station,
  84.                                                                          final FieldSpacecraftState<T> state,
  85.                                                                          final T[] parameters) {
  86.          // Base frame associated with the station
  87.         final TopocentricFrame baseFrame = station.getBaseFrame();
  88.         // delay in meters
  89.         final T delay = ionoModel.pathDelay(state, baseFrame, frequency, parameters);
  90.         return delay;
  91.     }

  92.     /** Compute the Jacobian of the delay term wrt state using
  93.     * automatic differentiation.
  94.     *
  95.     * @param derivatives ionospheric delay derivatives
  96.     * @param freeStateParameters dimension of the state.
  97.     *
  98.     * @return Jacobian of the delay wrt state
  99.     */
  100.     private double[][] rangeErrorJacobianState(final double[] derivatives, final int freeStateParameters) {
  101.         final double[][] finiteDifferencesJacobian = new double[1][6];
  102.         for (int i = 0; i < freeStateParameters; i++) {
  103.             // First element is the value of the delay
  104.             finiteDifferencesJacobian[0][i] = derivatives[i + 1];
  105.         }
  106.         return finiteDifferencesJacobian;
  107.     }


  108.     /** Compute the derivative of the delay term wrt parameters.
  109.     *
  110.     * @param station ground station
  111.     * @param driver driver for the station offset parameter
  112.     * @param state spacecraft state
  113.     * @param delay current ionospheric delay
  114.     * @return derivative of the delay wrt station offset parameter
  115.     */
  116.     private double rangeErrorParameterDerivative(final GroundStation station,
  117.                                                  final ParameterDriver driver,
  118.                                                  final SpacecraftState state,
  119.                                                  final double delay) {

  120.         final ParameterFunction rangeError = new ParameterFunction() {
  121.             /** {@inheritDoc} */
  122.             @Override
  123.             public double value(final ParameterDriver parameterDriver) {
  124.                 return rangeErrorIonosphericModel(station, state);
  125.             }
  126.         };

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

  129.         return rangeErrorDerivative.value(driver);

  130.     }

  131.     /** Compute the derivative of the delay term wrt parameters using
  132.     * automatic differentiation.
  133.     *
  134.     * @param derivatives ionospheric delay derivatives
  135.     * @param freeStateParameters dimension of the state.
  136.     * @return derivative of the delay wrt ionospheric model parameters
  137.     */
  138.     private double[] rangeErrorParameterDerivative(final double[] derivatives, final int freeStateParameters) {
  139.         // 0                               -> value of the delay
  140.         // 1 ... freeStateParameters       -> derivatives of the delay wrt state
  141.         // freeStateParameters + 1 ... n   -> derivatives of the delay wrt ionospheric parameters
  142.         final int dim = derivatives.length - 1 - freeStateParameters;
  143.         final double[] rangeError = new double[dim];

  144.         for (int i = 0; i < dim; i++) {
  145.             rangeError[i] = derivatives[1 + freeStateParameters + i];
  146.         }

  147.         return rangeError;
  148.     }

  149.     /** {@inheritDoc} */
  150.     @Override
  151.     public List<ParameterDriver> getParametersDrivers() {
  152.         return ionoModel.getParametersDrivers();
  153.     }

  154.     @Override
  155.     public void modify(final EstimatedMeasurement<Range> estimated) {
  156.         final Range           measurement = estimated.getObservedMeasurement();
  157.         final GroundStation   station     = measurement.getStation();
  158.         final SpacecraftState state       = estimated.getStates()[0];

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

  160.         // update estimated derivatives with Jacobian of the measure wrt state
  161.         final IonosphericDSConverter converter =
  162.                 new IonosphericDSConverter(state, 6, new InertialProvider(state.getFrame()));
  163.         final FieldSpacecraftState<DerivativeStructure> dsState = converter.getState(ionoModel);
  164.         final DerivativeStructure[] dsParameters = converter.getParameters(dsState, ionoModel);
  165.         final DerivativeStructure dsDelay = rangeErrorIonosphericModel(station, dsState, dsParameters);
  166.         final double[] derivatives = dsDelay.getAllDerivatives();

  167.         final double[][] djac = rangeErrorJacobianState(derivatives, converter.getFreeStateParameters());

  168.         final double[][] stateDerivatives = estimated.getStateDerivatives(0);
  169.         for (int irow = 0; irow < stateDerivatives.length; ++irow) {
  170.             for (int jcol = 0; jcol < stateDerivatives[0].length; ++jcol) {
  171.                 stateDerivatives[irow][jcol] += djac[irow][jcol];
  172.             }
  173.         }
  174.         estimated.setStateDerivatives(0, stateDerivatives);

  175.         int index = 0;
  176.         for (final ParameterDriver driver : getParametersDrivers()) {
  177.             if (driver.isSelected()) {
  178.                 // update estimated derivatives with derivative of the modification wrt ionospheric parameters
  179.                 double parameterDerivative = estimated.getParameterDerivatives(driver)[0];
  180.                 final double[] dDelaydP    = rangeErrorParameterDerivative(derivatives, converter.getFreeStateParameters());
  181.                 parameterDerivative += dDelaydP[index];
  182.                 estimated.setParameterDerivatives(driver, parameterDerivative);
  183.                 index = index + 1;
  184.             }

  185.         }

  186.         for (final ParameterDriver driver : Arrays.asList(station.getClockOffsetDriver(),
  187.                                                           station.getEastOffsetDriver(),
  188.                                                           station.getNorthOffsetDriver(),
  189.                                                           station.getZenithOffsetDriver())) {
  190.             if (driver.isSelected()) {
  191.                 // update estimated derivatives with derivative of the modification wrt station parameters
  192.                 double parameterDerivative = estimated.getParameterDerivatives(driver)[0];
  193.                 parameterDerivative += rangeErrorParameterDerivative(station, driver, state, dsDelay.getValue());
  194.                 estimated.setParameterDerivatives(driver, parameterDerivative);
  195.             }
  196.         }

  197.         // update estimated value taking into account the ionospheric delay.
  198.         // The ionospheric delay is directly added to the range.
  199.         final double[] newValue = oldValue.clone();
  200.         newValue[0] = newValue[0] + dsDelay.getValue();
  201.         estimated.setEstimatedValue(newValue);

  202.     }

  203. }