TurnAroundRangeIonosphericDelayModifier.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.TurnAroundRange;
  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 TurnAroundRange measurement with ionospheric delay.
  35.  * The effect of ionospheric correction on the TurnAroundRange 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.  * @since 9.0
  46.  */
  47. public class TurnAroundRangeIonosphericDelayModifier implements EstimationModifier<TurnAroundRange> {

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

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

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

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

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

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


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

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

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

  126.         return rangeErrorDerivative.value(driver);

  127.     }

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

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

  144.         return rangeError;
  145.     }

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

  151.     @Override
  152.     public void modify(final EstimatedMeasurement<TurnAroundRange> estimated) {
  153.         final TurnAroundRange measurement   = estimated.getObservedMeasurement();
  154.         final GroundStation   masterStation = measurement.getMasterStation();
  155.         final GroundStation   slaveStation  = measurement.getSlaveStation();
  156.         final SpacecraftState state         = estimated.getStates()[0];

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

  158.         // Update estimated derivatives with Jacobian of the measure wrt state
  159.         final IonosphericDSConverter converter =
  160.                 new IonosphericDSConverter(state, 6, new InertialProvider(state.getFrame()));
  161.         final FieldSpacecraftState<DerivativeStructure> dsState = converter.getState(ionoModel);
  162.         final DerivativeStructure[] dsParameters = converter.getParameters(dsState, ionoModel);
  163.         final DerivativeStructure masterDSDelay = rangeErrorIonosphericModel(masterStation, dsState, dsParameters);
  164.         final DerivativeStructure slaveDSDelay = rangeErrorIonosphericModel(slaveStation, dsState, dsParameters);
  165.         final double[] masterDerivatives = masterDSDelay.getAllDerivatives();
  166.         final double[] slaveDerivatives  = masterDSDelay.getAllDerivatives();

  167.         final double[][] masterDjac = rangeErrorJacobianState(masterDerivatives, converter.getFreeStateParameters());
  168.         final double[][] slaveDjac  = rangeErrorJacobianState(slaveDerivatives, converter.getFreeStateParameters());
  169.         final double[][] stateDerivatives = estimated.getStateDerivatives(0);
  170.         for (int irow = 0; irow < stateDerivatives.length; ++irow) {
  171.             for (int jcol = 0; jcol < stateDerivatives[0].length; ++jcol) {
  172.                 stateDerivatives[irow][jcol] += masterDjac[irow][jcol] + slaveDjac[irow][jcol];
  173.             }
  174.         }
  175.         estimated.setStateDerivatives(0, stateDerivatives);

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

  186.         }

  187.         int indexSlave = 0;
  188.         for (final ParameterDriver driver : getParametersDrivers()) {
  189.             if (driver.isSelected()) {
  190.                 // update estimated derivatives with derivative of the modification wrt ionospheric parameters
  191.                 double parameterDerivative = estimated.getParameterDerivatives(driver)[0];
  192.                 final double[] derivatives = rangeErrorParameterDerivative(slaveDerivatives, converter.getFreeStateParameters());
  193.                 parameterDerivative += derivatives[indexSlave];
  194.                 estimated.setParameterDerivatives(driver, parameterDerivative);
  195.                 indexSlave += 1;
  196.             }

  197.         }

  198.         // Update derivatives with respect to master station position
  199.         for (final ParameterDriver driver : Arrays.asList(masterStation.getClockOffsetDriver(),
  200.                                                           masterStation.getEastOffsetDriver(),
  201.                                                           masterStation.getNorthOffsetDriver(),
  202.                                                           masterStation.getZenithOffsetDriver())) {
  203.             if (driver.isSelected()) {
  204.                 double parameterDerivative = estimated.getParameterDerivatives(driver)[0];
  205.                 parameterDerivative += rangeErrorParameterDerivative(masterStation, driver, state);
  206.                 estimated.setParameterDerivatives(driver, parameterDerivative);
  207.             }
  208.         }

  209.         // Update derivatives with respect to slave station position
  210.         for (final ParameterDriver driver : Arrays.asList(slaveStation.getEastOffsetDriver(),
  211.                                                           slaveStation.getNorthOffsetDriver(),
  212.                                                           slaveStation.getZenithOffsetDriver())) {
  213.             if (driver.isSelected()) {
  214.                 double parameterDerivative = estimated.getParameterDerivatives(driver)[0];
  215.                 parameterDerivative += rangeErrorParameterDerivative(slaveStation, driver, state);
  216.                 estimated.setParameterDerivatives(driver, parameterDerivative);
  217.             }
  218.         }

  219.         // Update estimated value taking into account the ionospheric delay.
  220.         // The ionospheric delay is directly added to the TurnAroundRange.
  221.         final double[] newValue = oldValue.clone();
  222.         newValue[0] = newValue[0] + masterDSDelay.getReal() + slaveDSDelay.getReal();
  223.         estimated.setEstimatedValue(newValue);
  224.     }

  225. }