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


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

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

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

  122.         return rangeErrorDerivative.value(driver);

  123.     }

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

  136.         for (int i = 0; i < dim; i++) {
  137.             rangeError[i] = derivatives[freeStateParameters + i];
  138.         }

  139.         return rangeError;
  140.     }

  141.     /** {@inheritDoc} */
  142.     @Override
  143.     public List<ParameterDriver> getParametersDrivers() {
  144.         return ionoModel.getParametersDrivers();
  145.     }

  146.     @Override
  147.     public void modify(final EstimatedMeasurement<TurnAroundRange> estimated) {
  148.         final TurnAroundRange measurement   = estimated.getObservedMeasurement();
  149.         final GroundStation   masterStation = measurement.getMasterStation();
  150.         final GroundStation   slaveStation  = measurement.getSlaveStation();
  151.         final SpacecraftState state         = estimated.getStates()[0];

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

  153.         // Update estimated derivatives with Jacobian of the measure wrt state
  154.         final IonosphericGradientConverter converter =
  155.                 new IonosphericGradientConverter(state, 6, new InertialProvider(state.getFrame()));
  156.         final FieldSpacecraftState<Gradient> gState = converter.getState(ionoModel);
  157.         final Gradient[] gParameters = converter.getParameters(gState, ionoModel);
  158.         final Gradient masterGDelay = rangeErrorIonosphericModel(masterStation, gState, gParameters);
  159.         final Gradient slaveGDelay = rangeErrorIonosphericModel(slaveStation, gState, gParameters);
  160.         final double[] masterDerivatives = masterGDelay.getGradient();
  161.         final double[] slaveDerivatives  = masterGDelay.getGradient();

  162.         final double[][] masterDjac = rangeErrorJacobianState(masterDerivatives);
  163.         final double[][] slaveDjac  = rangeErrorJacobianState(slaveDerivatives);
  164.         final double[][] stateDerivatives = estimated.getStateDerivatives(0);
  165.         for (int irow = 0; irow < stateDerivatives.length; ++irow) {
  166.             for (int jcol = 0; jcol < stateDerivatives[0].length; ++jcol) {
  167.                 stateDerivatives[irow][jcol] += masterDjac[irow][jcol] + slaveDjac[irow][jcol];
  168.             }
  169.         }
  170.         estimated.setStateDerivatives(0, stateDerivatives);

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

  181.         }

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

  192.         }

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

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

  214.         // Update estimated value taking into account the ionospheric delay.
  215.         // The ionospheric delay is directly added to the TurnAroundRange.
  216.         final double[] newValue = oldValue.clone();
  217.         newValue[0] = newValue[0] + masterGDelay.getReal() + slaveGDelay.getReal();
  218.         estimated.setEstimatedValue(newValue);
  219.     }

  220. }