TurnAroundRangeTroposphericDelayModifier.java

  1. /* Copyright 2002-2022 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.Field;
  21. import org.hipparchus.CalculusFieldElement;
  22. import org.hipparchus.analysis.differentiation.Gradient;
  23. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  24. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  25. import org.orekit.attitudes.InertialProvider;
  26. import org.orekit.estimation.measurements.EstimatedMeasurement;
  27. import org.orekit.estimation.measurements.EstimationModifier;
  28. import org.orekit.estimation.measurements.GroundStation;
  29. import org.orekit.estimation.measurements.TurnAroundRange;
  30. import org.orekit.models.earth.troposphere.DiscreteTroposphericModel;
  31. import org.orekit.propagation.FieldSpacecraftState;
  32. import org.orekit.propagation.SpacecraftState;
  33. import org.orekit.utils.Differentiation;
  34. import org.orekit.utils.ParameterDriver;
  35. import org.orekit.utils.ParameterFunction;

  36. /** Class modifying theoretical turn-around TurnAroundRange measurement with tropospheric delay.
  37.  * The effect of tropospheric correction on the TurnAroundRange is directly computed
  38.  * through the computation of the tropospheric delay.
  39.  *
  40.  * In general, for GNSS, VLBI, ... there is hardly any frequency dependence in the delay.
  41.  * For SLR techniques however, the frequency dependence is sensitive.
  42.  *
  43.  * @author Maxime Journot
  44.  * @since 9.0
  45.  */
  46. public class TurnAroundRangeTroposphericDelayModifier implements EstimationModifier<TurnAroundRange> {

  47.     /** Tropospheric delay model. */
  48.     private final DiscreteTroposphericModel tropoModel;

  49.     /** Constructor.
  50.      *
  51.      * @param model  Tropospheric delay model appropriate for the current TurnAroundRange measurement method.
  52.      */
  53.     public TurnAroundRangeTroposphericDelayModifier(final DiscreteTroposphericModel model) {
  54.         tropoModel = model;
  55.     }

  56.     /** Compute the measurement error due to Troposphere.
  57.      * @param station station
  58.      * @param state spacecraft state
  59.      * @return the measurement error due to Troposphere
  60.      */
  61.     private double rangeErrorTroposphericModel(final GroundStation station, final SpacecraftState state) {
  62.         //
  63.         final Vector3D position = state.getPVCoordinates().getPosition();

  64.         // elevation
  65.         final double elevation = station.getBaseFrame().getElevation(position,
  66.                                                                      state.getFrame(),
  67.                                                                      state.getDate());

  68.         // only consider measures above the horizon
  69.         if (elevation > 0) {
  70.             // Delay in meters
  71.             final double delay = tropoModel.pathDelay(elevation, station.getBaseFrame().getPoint(), tropoModel.getParameters(), state.getDate());

  72.             return delay;
  73.         }

  74.         return 0;
  75.     }

  76.     /** Compute the measurement error due to Troposphere.
  77.      * @param <T> type of the element
  78.      * @param station station
  79.      * @param state spacecraft state
  80.      * @param parameters tropospheric model parameters
  81.      * @return the measurement error due to Troposphere
  82.      */
  83.     private <T extends CalculusFieldElement<T>> T rangeErrorTroposphericModel(final GroundStation station,
  84.                                                                           final FieldSpacecraftState<T> state,
  85.                                                                           final T[] parameters) {
  86.         // Field
  87.         final Field<T> field = state.getDate().getField();
  88.         final T zero         = field.getZero();

  89.         //
  90.         final FieldVector3D<T> position = state.getPVCoordinates().getPosition();
  91.         final T dsElevation             = station.getBaseFrame().getElevation(position,
  92.                                                                               state.getFrame(),
  93.                                                                               state.getDate());

  94.         // only consider measures above the horizon
  95.         if (dsElevation.getReal() > 0) {
  96.             // Delay in meters
  97.             final T delay = tropoModel.pathDelay(dsElevation, station.getBaseFrame().getPoint(field), parameters, state.getDate());

  98.             return delay;
  99.         }

  100.         return zero;
  101.     }

  102.     /** Compute the Jacobian of the delay term wrt state using
  103.     * automatic differentiation.
  104.     *
  105.     * @param derivatives tropospheric delay derivatives
  106.     *
  107.     * @return Jacobian of the delay wrt state
  108.     */
  109.     private double[][] rangeErrorJacobianState(final double[] derivatives) {
  110.         final double[][] finiteDifferencesJacobian = new double[1][6];
  111.         System.arraycopy(derivatives, 0, finiteDifferencesJacobian[0], 0, 6);
  112.         return finiteDifferencesJacobian;
  113.     }


  114.     /** Compute the derivative of the delay term wrt parameters.
  115.      *
  116.      * @param station ground station
  117.      * @param driver driver for the station offset parameter
  118.      * @param state spacecraft state
  119.      * @return derivative of the delay wrt station offset parameter
  120.      */
  121.     private double rangeErrorParameterDerivative(final GroundStation station,
  122.                                                  final ParameterDriver driver,
  123.                                                  final SpacecraftState state) {

  124.         final ParameterFunction rangeError = new ParameterFunction() {
  125.             /** {@inheritDoc} */
  126.             @Override
  127.             public double value(final ParameterDriver parameterDriver) {
  128.                 return rangeErrorTroposphericModel(station, state);
  129.             }
  130.         };

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

  132.         return rangeErrorDerivative.value(driver);

  133.     }

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

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

  149.         return rangeError;
  150.     }

  151.     /** {@inheritDoc} */
  152.     @Override
  153.     public List<ParameterDriver> getParametersDrivers() {
  154.         return tropoModel.getParametersDrivers();
  155.     }

  156.     /** {@inheritDoc} */
  157.     @Override
  158.     public void modify(final EstimatedMeasurement<TurnAroundRange> estimated) {
  159.         final TurnAroundRange measurement      = estimated.getObservedMeasurement();
  160.         final GroundStation   primaryStation   = measurement.getPrimaryStation();
  161.         final GroundStation   secondaryStation = measurement.getSecondaryStation();
  162.         final SpacecraftState state            = estimated.getStates()[0];

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

  164.         // Update estimated derivatives with Jacobian of the measure wrt state
  165.         final TroposphericGradientConverter converter =
  166.                 new TroposphericGradientConverter(state, 6, new InertialProvider(state.getFrame()));
  167.         final FieldSpacecraftState<Gradient> gState = converter.getState(tropoModel);
  168.         final Gradient[] gParameters = converter.getParameters(gState, tropoModel);
  169.         final Gradient   primaryGDelay        = rangeErrorTroposphericModel(primaryStation, gState, gParameters);
  170.         final Gradient   secondaryGDelay      = rangeErrorTroposphericModel(secondaryStation, gState, gParameters);
  171.         final double[]   primaryDerivatives   = primaryGDelay.getGradient();
  172.         final double[]   secondaryDerivatives = secondaryGDelay.getGradient();

  173.         final double[][] primaryDjac      = rangeErrorJacobianState(primaryDerivatives);
  174.         final double[][] secondaryDjac    = rangeErrorJacobianState(secondaryDerivatives);
  175.         final double[][] stateDerivatives = estimated.getStateDerivatives(0);
  176.         for (int irow = 0; irow < stateDerivatives.length; ++irow) {
  177.             for (int jcol = 0; jcol < stateDerivatives[0].length; ++jcol) {
  178.                 stateDerivatives[irow][jcol] += primaryDjac[irow][jcol] + secondaryDjac[irow][jcol];
  179.             }
  180.         }
  181.         estimated.setStateDerivatives(0, stateDerivatives);

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

  192.         }

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

  203.         }

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

  215.         // Update derivatives with respect to secondary station position
  216.         for (final ParameterDriver driver : Arrays.asList(secondaryStation.getEastOffsetDriver(),
  217.                                                           secondaryStation.getNorthOffsetDriver(),
  218.                                                           secondaryStation.getZenithOffsetDriver())) {
  219.             if (driver.isSelected()) {
  220.                 double parameterDerivative = estimated.getParameterDerivatives(driver)[0];
  221.                 parameterDerivative += rangeErrorParameterDerivative(secondaryStation, driver, state);
  222.                 estimated.setParameterDerivatives(driver, parameterDerivative);
  223.             }
  224.         }

  225.         // Update estimated value taking into account the tropospheric delay.
  226.         // The tropospheric delay is directly added to the TurnAroundRange.
  227.         final double[] newValue = oldValue.clone();
  228.         newValue[0] = newValue[0] + primaryGDelay.getReal() + secondaryGDelay.getReal();
  229.         estimated.setEstimatedValue(newValue);

  230.     }

  231. }