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.Gradient;
  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.     *
  97.     * @return Jacobian of the delay wrt state
  98.     */
  99.     private double[][] rangeErrorJacobianState(final double[] derivatives) {
  100.         final double[][] finiteDifferencesJacobian = new double[1][6];
  101.         System.arraycopy(derivatives, 0, finiteDifferencesJacobian[0], 0, 6);
  102.         return finiteDifferencesJacobian;
  103.     }


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

  116.         final ParameterFunction rangeError = new ParameterFunction() {
  117.             /** {@inheritDoc} */
  118.             @Override
  119.             public double value(final ParameterDriver parameterDriver) {
  120.                 return rangeErrorIonosphericModel(station, state);
  121.             }
  122.         };

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

  125.         return rangeErrorDerivative.value(driver);

  126.     }

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

  139.         for (int i = 0; i < dim; i++) {
  140.             rangeError[i] = derivatives[freeStateParameters + i];
  141.         }

  142.         return rangeError;
  143.     }

  144.     /** {@inheritDoc} */
  145.     @Override
  146.     public List<ParameterDriver> getParametersDrivers() {
  147.         return ionoModel.getParametersDrivers();
  148.     }

  149.     @Override
  150.     public void modify(final EstimatedMeasurement<Range> estimated) {
  151.         final Range           measurement = estimated.getObservedMeasurement();
  152.         final GroundStation   station     = measurement.getStation();
  153.         final SpacecraftState state       = estimated.getStates()[0];

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

  155.         // update estimated derivatives with Jacobian of the measure wrt state
  156.         final IonosphericGradientConverter converter =
  157.                 new IonosphericGradientConverter(state, 6, new InertialProvider(state.getFrame()));
  158.         final FieldSpacecraftState<Gradient> gState = converter.getState(ionoModel);
  159.         final Gradient[] gParameters = converter.getParameters(gState, ionoModel);
  160.         final Gradient gDelay = rangeErrorIonosphericModel(station, gState, gParameters);
  161.         final double[] derivatives = gDelay.getGradient();

  162.         final double[][] djac = rangeErrorJacobianState(derivatives);

  163.         final double[][] stateDerivatives = estimated.getStateDerivatives(0);
  164.         for (int irow = 0; irow < stateDerivatives.length; ++irow) {
  165.             for (int jcol = 0; jcol < stateDerivatives[0].length; ++jcol) {
  166.                 stateDerivatives[irow][jcol] += djac[irow][jcol];
  167.             }
  168.         }
  169.         estimated.setStateDerivatives(0, stateDerivatives);

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

  180.         }

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

  192.         // update estimated value taking into account the ionospheric delay.
  193.         // The ionospheric delay is directly added to the range.
  194.         final double[] newValue = oldValue.clone();
  195.         newValue[0] = newValue[0] + gDelay.getValue();
  196.         estimated.setEstimatedValue(newValue);

  197.     }

  198. }