RangeRateTroposphericDelayModifier.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.RangeRate;
  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 range-rate measurements with tropospheric delay.
  37.  * The effect of tropospheric correction on the range-rate is directly computed
  38.  * through the computation of the tropospheric delay difference with respect to
  39.  * time.
  40.  *
  41.  * In general, for GNSS, VLBI, ... there is hardly any frequency dependence in the delay.
  42.  * For SLR techniques however, the frequency dependence is sensitive.
  43.  *
  44.  * @author Joris Olympio
  45.  * @since 8.0
  46.  */
  47. public class RangeRateTroposphericDelayModifier implements EstimationModifier<RangeRate> {

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

  50.     /** Two-way measurement factor. */
  51.     private final double fTwoWay;

  52.     /** Constructor.
  53.      *
  54.      * @param model  Tropospheric delay model appropriate for the current range-rate measurement method.
  55.      * @param tw     Flag indicating whether the measurement is two-way.
  56.      */
  57.     public RangeRateTroposphericDelayModifier(final DiscreteTroposphericModel model, final boolean tw) {
  58.         tropoModel = model;
  59.         if (tw) {
  60.             fTwoWay = 2.;
  61.         } else {
  62.             fTwoWay = 1.;
  63.         }
  64.     }

  65.     /** Compute the measurement error due to Troposphere.
  66.      * @param station station
  67.      * @param state spacecraft state
  68.      * @return the measurement error due to Troposphere
  69.      */
  70.     public double rangeRateErrorTroposphericModel(final GroundStation station,
  71.                                                   final SpacecraftState state) {
  72.         // The effect of tropospheric correction on the range rate is
  73.         // computed using finite differences.

  74.         final double dt = 10; // s

  75.         // spacecraft position and elevation as seen from the ground station
  76.         final Vector3D position = state.getPVCoordinates().getPosition();

  77.         // elevation
  78.         final double elevation1 = station.getBaseFrame().getElevation(position,
  79.                                                                       state.getFrame(),
  80.                                                                       state.getDate());

  81.         // only consider measures above the horizon
  82.         if (elevation1 > 0) {
  83.             // tropospheric delay in meters
  84.             final double d1 = tropoModel.pathDelay(elevation1, station.getBaseFrame().getPoint(), tropoModel.getParameters(), state.getDate());

  85.             // propagate spacecraft state forward by dt
  86.             final SpacecraftState state2 = state.shiftedBy(dt);

  87.             // spacecraft position and elevation as seen from the ground station
  88.             final Vector3D position2 = state2.getPVCoordinates().getPosition();

  89.             // elevation
  90.             final double elevation2 = station.getBaseFrame().getElevation(position2,
  91.                                                                           state2.getFrame(),
  92.                                                                           state2.getDate());

  93.             // tropospheric delay dt after
  94.             final double d2 = tropoModel.pathDelay(elevation2, station.getBaseFrame().getPoint(), tropoModel.getParameters(), state2.getDate());

  95.             return fTwoWay * (d2 - d1) / dt;
  96.         }

  97.         return 0;
  98.     }


  99.     /** Compute the measurement error due to Troposphere.
  100.      * @param <T> type of the element
  101.      * @param station station
  102.      * @param state spacecraft state
  103.      * @param parameters tropospheric model parameters
  104.      * @return the measurement error due to Troposphere
  105.      */
  106.     public <T extends CalculusFieldElement<T>> T rangeRateErrorTroposphericModel(final GroundStation station,
  107.                                                                              final FieldSpacecraftState<T> state,
  108.                                                                              final T[] parameters) {
  109.         // Field
  110.         final Field<T> field = state.getDate().getField();
  111.         final T zero         = field.getZero();

  112.         // The effect of tropospheric correction on the range rate is
  113.         // computed using finite differences.

  114.         final double dt = 10; // s

  115.         // spacecraft position and elevation as seen from the ground station
  116.         final FieldVector3D<T> position     = state.getPVCoordinates().getPosition();
  117.         final T elevation1                  = station.getBaseFrame().getElevation(position,
  118.                                                                                   state.getFrame(),
  119.                                                                                   state.getDate());

  120.         // only consider measures above the horizon
  121.         if (elevation1.getReal() > 0) {
  122.             // tropospheric delay in meters
  123.             final T d1 = tropoModel.pathDelay(elevation1, station.getBaseFrame().getPoint(field), parameters, state.getDate());

  124.             // propagate spacecraft state forward by dt
  125.             final FieldSpacecraftState<T> state2 = state.shiftedBy(dt);

  126.             // spacecraft position and elevation as seen from the ground station
  127.             final FieldVector3D<T> position2     = state2.getPVCoordinates().getPosition();

  128.             // elevation
  129.             final T elevation2 = station.getBaseFrame().getElevation(position2,
  130.                                                                      state2.getFrame(),
  131.                                                                      state2.getDate());


  132.             // tropospheric delay dt after
  133.             final T d2 = tropoModel.pathDelay(elevation2, station.getBaseFrame().getPoint(field), parameters, state2.getDate());

  134.             return (d2.subtract(d1)).divide(dt).multiply(fTwoWay);
  135.         }

  136.         return zero;
  137.     }

  138.     /** Compute the Jacobian of the delay term wrt state using
  139.     * automatic differentiation.
  140.     *
  141.     * @param derivatives tropospheric delay derivatives
  142.     *
  143.     * @return Jacobian of the delay wrt state
  144.     */
  145.     private double[][] rangeRateErrorJacobianState(final double[] derivatives) {
  146.         final double[][] finiteDifferencesJacobian = new double[1][6];
  147.         System.arraycopy(derivatives, 0, finiteDifferencesJacobian[0], 0, 6);
  148.         return finiteDifferencesJacobian;
  149.     }

  150.     /** Compute the derivative of the delay term wrt parameters.
  151.     *
  152.     * @param station ground station
  153.     * @param driver driver for the station offset parameter
  154.     * @param state spacecraft state
  155.     * @return derivative of the delay wrt station offset parameter
  156.     */
  157.     private double rangeRateErrorParameterDerivative(final GroundStation station,
  158.                                                      final ParameterDriver driver,
  159.                                                      final SpacecraftState state) {

  160.         final ParameterFunction rangeError = new ParameterFunction() {
  161.             /** {@inheritDoc} */
  162.             @Override
  163.             public double value(final ParameterDriver parameterDriver) {
  164.                 return rangeRateErrorTroposphericModel(station, state);
  165.             }
  166.         };

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

  169.         return rangeErrorDerivative.value(driver);

  170.     }

  171.     /** Compute the derivative of the delay term wrt parameters using
  172.     * automatic differentiation.
  173.     *
  174.     * @param derivatives tropospheric delay derivatives
  175.     * @param freeStateParameters dimension of the state.
  176.     * @return derivative of the delay wrt tropospheric model parameters
  177.     */
  178.     private double[] rangeRateErrorParameterDerivative(final double[] derivatives, final int freeStateParameters) {
  179.         // 0 ... freeStateParameters - 1 -> derivatives of the delay wrt state
  180.         // freeStateParameters ... n     -> derivatives of the delay wrt tropospheric parameters
  181.         final int dim = derivatives.length - freeStateParameters;
  182.         final double[] rangeError = new double[dim];

  183.         for (int i = 0; i < dim; i++) {
  184.             rangeError[i] = derivatives[freeStateParameters + i];
  185.         }

  186.         return rangeError;
  187.     }

  188.     /** {@inheritDoc} */
  189.     @Override
  190.     public List<ParameterDriver> getParametersDrivers() {
  191.         return tropoModel.getParametersDrivers();
  192.     }

  193.     /** {@inheritDoc} */
  194.     @Override
  195.     public void modify(final EstimatedMeasurement<RangeRate> estimated) {
  196.         final RangeRate       measurement = estimated.getObservedMeasurement();
  197.         final GroundStation   station     = measurement.getStation();
  198.         final SpacecraftState state       = estimated.getStates()[0];

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

  200.         // update estimated derivatives with Jacobian of the measure wrt state
  201.         final TroposphericGradientConverter converter =
  202.                 new TroposphericGradientConverter(state, 6, new InertialProvider(state.getFrame()));
  203.         final FieldSpacecraftState<Gradient> gState = converter.getState(tropoModel);
  204.         final Gradient[] gParameters = converter.getParameters(gState, tropoModel);
  205.         final Gradient gDelay = rangeRateErrorTroposphericModel(station, gState, gParameters);
  206.         final double[] derivatives = gDelay.getGradient();

  207.         final double[][] djac = rangeRateErrorJacobianState(derivatives);
  208.         final double[][] stateDerivatives = estimated.getStateDerivatives(0);
  209.         for (int irow = 0; irow < stateDerivatives.length; ++irow) {
  210.             for (int jcol = 0; jcol < stateDerivatives[0].length; ++jcol) {
  211.                 stateDerivatives[irow][jcol] += djac[irow][jcol];
  212.             }
  213.         }
  214.         estimated.setStateDerivatives(0, stateDerivatives);

  215.         int index = 0;
  216.         for (final ParameterDriver driver : getParametersDrivers()) {
  217.             if (driver.isSelected()) {
  218.                 // update estimated derivatives with derivative of the modification wrt tropospheric parameters
  219.                 double parameterDerivative = estimated.getParameterDerivatives(driver)[0];
  220.                 final double[] dDelaydP    = rangeRateErrorParameterDerivative(derivatives, converter.getFreeStateParameters());
  221.                 parameterDerivative += dDelaydP[index];
  222.                 estimated.setParameterDerivatives(driver, parameterDerivative);
  223.                 index += 1;
  224.             }

  225.         }

  226.         for (final ParameterDriver driver : Arrays.asList(station.getClockOffsetDriver(),
  227.                                                           station.getEastOffsetDriver(),
  228.                                                           station.getNorthOffsetDriver(),
  229.                                                           station.getZenithOffsetDriver())) {
  230.             if (driver.isSelected()) {
  231.                 // update estimated derivatives with derivative of the modification wrt station parameters
  232.                 double parameterDerivative = estimated.getParameterDerivatives(driver)[0];
  233.                 parameterDerivative += rangeRateErrorParameterDerivative(station, driver, state);
  234.                 estimated.setParameterDerivatives(driver, parameterDerivative);
  235.             }
  236.         }

  237.         // update estimated value taking into account the tropospheric delay.
  238.         // The tropospheric delay is directly added to the range.
  239.         final double[] newValue = oldValue.clone();
  240.         newValue[0] = newValue[0] + gDelay.getReal();
  241.         estimated.setEstimatedValue(newValue);

  242.     }

  243. }