RangeRateTroposphericDelayModifier.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.Field;
  21. import org.hipparchus.RealFieldElement;
  22. import org.hipparchus.analysis.differentiation.DerivativeStructure;
  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.     /** Get the station height above mean sea level.
  66.      *
  67.      * @param station  ground station (or measuring station)
  68.      * @return the measuring station height above sea level, m
  69.      */
  70.     private double getStationHeightAMSL(final GroundStation station) {
  71.         // FIXME heigth should be computed with respect to geoid WGS84+GUND = EGM2008 for example
  72.         final double height = station.getBaseFrame().getPoint().getAltitude();
  73.         return height;
  74.     }

  75.     /** Get the station height above mean sea level.
  76.     * @param <T> type of the element
  77.     * @param field field of the elements
  78.     * @param station  ground station (or measuring station)
  79.     * @return the measuring station height above sea level, m
  80.     */
  81.     private <T extends RealFieldElement<T>> T getStationHeightAMSL(final Field<T> field, final GroundStation station) {
  82.         // FIXME heigth should be computed with respect to geoid WGS84+GUND = EGM2008 for example
  83.         final T height = station.getBaseFrame().getPoint(field).getAltitude();
  84.         return height;
  85.     }

  86.     /** Compute the measurement error due to Troposphere.
  87.      * @param station station
  88.      * @param state spacecraft state
  89.      * @return the measurement error due to Troposphere
  90.      */
  91.     public double rangeRateErrorTroposphericModel(final GroundStation station,
  92.                                                   final SpacecraftState state) {
  93.         // The effect of tropospheric correction on the range rate is
  94.         // computed using finite differences.

  95.         final double dt = 10; // s

  96.         // station altitude AMSL in meters
  97.         final double height = getStationHeightAMSL(station);

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

  100.         // elevation
  101.         final double elevation1 = station.getBaseFrame().getElevation(position,
  102.                                                                       state.getFrame(),
  103.                                                                       state.getDate());

  104.         // only consider measures above the horizon
  105.         if (elevation1 > 0) {
  106.             // tropospheric delay in meters
  107.             final double d1 = tropoModel.pathDelay(elevation1, height, tropoModel.getParameters(), state.getDate());

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

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

  112.             // elevation
  113.             final double elevation2 = station.getBaseFrame().getElevation(position2,
  114.                                                                           state2.getFrame(),
  115.                                                                           state2.getDate());

  116.             // tropospheric delay dt after
  117.             final double d2 = tropoModel.pathDelay(elevation2, height, tropoModel.getParameters(), state2.getDate());

  118.             return fTwoWay * (d2 - d1) / dt;
  119.         }

  120.         return 0;
  121.     }


  122.     /** Compute the measurement error due to Troposphere.
  123.      * @param <T> type of the element
  124.      * @param station station
  125.      * @param state spacecraft state
  126.      * @param parameters tropospheric model parameters
  127.      * @return the measurement error due to Troposphere
  128.      */
  129.     public <T extends RealFieldElement<T>> T rangeRateErrorTroposphericModel(final GroundStation station,
  130.                                                                              final FieldSpacecraftState<T> state,
  131.                                                                              final T[] parameters) {
  132.         // Field
  133.         final Field<T> field = state.getDate().getField();
  134.         final T zero         = field.getZero();

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

  137.         final double dt = 10; // s

  138.         // station altitude AMSL in meters
  139.         final T height = getStationHeightAMSL(field, station);

  140.         // spacecraft position and elevation as seen from the ground station
  141.         final FieldVector3D<T> position     = state.getPVCoordinates().getPosition();
  142.         final T elevation1                  = station.getBaseFrame().getElevation(position,
  143.                                                                                   state.getFrame(),
  144.                                                                                   state.getDate());

  145.         // only consider measures above the horizon
  146.         if (elevation1.getReal() > 0) {
  147.             // tropospheric delay in meters
  148.             final T d1 = tropoModel.pathDelay(elevation1, height, parameters, state.getDate());

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

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

  153.             // elevation
  154.             final T elevation2 = station.getBaseFrame().getElevation(position2,
  155.                                                                      state2.getFrame(),
  156.                                                                      state2.getDate());


  157.             // tropospheric delay dt after
  158.             final T d2 = tropoModel.pathDelay(elevation2, height, parameters, state2.getDate());

  159.             return (d2.subtract(d1)).divide(dt).multiply(fTwoWay);
  160.         }

  161.         return zero;
  162.     }

  163.     /** Compute the Jacobian of the delay term wrt state using
  164.     * automatic differentiation.
  165.     *
  166.     * @param derivatives tropospheric delay derivatives
  167.     * @param freeStateParameters dimension of the state.
  168.     *
  169.     * @return Jacobian of the delay wrt state
  170.     */
  171.     private double[][] rangeRateErrorJacobianState(final double[] derivatives, final int freeStateParameters) {
  172.         final double[][] finiteDifferencesJacobian = new double[1][6];
  173.         for (int i = 0; i < freeStateParameters; i++) {
  174.             // First element is the value of the delay
  175.             finiteDifferencesJacobian[0][i] = derivatives[i + 1];
  176.         }
  177.         return finiteDifferencesJacobian;
  178.     }

  179.     /** Compute the derivative of the delay term wrt parameters.
  180.     *
  181.     * @param station ground station
  182.     * @param driver driver for the station offset parameter
  183.     * @param state spacecraft state
  184.     * @return derivative of the delay wrt station offset parameter
  185.     */
  186.     private double rangeRateErrorParameterDerivative(final GroundStation station,
  187.                                                      final ParameterDriver driver,
  188.                                                      final SpacecraftState state) {

  189.         final ParameterFunction rangeError = new ParameterFunction() {
  190.             /** {@inheritDoc} */
  191.             @Override
  192.             public double value(final ParameterDriver parameterDriver) {
  193.                 return rangeRateErrorTroposphericModel(station, state);
  194.             }
  195.         };

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

  198.         return rangeErrorDerivative.value(driver);

  199.     }

  200.     /** Compute the derivative of the delay term wrt parameters using
  201.     * automatic differentiation.
  202.     *
  203.     * @param derivatives tropospheric delay derivatives
  204.     * @param freeStateParameters dimension of the state.
  205.     * @return derivative of the delay wrt tropospheric model parameters
  206.     */
  207.     private double[] rangeRateErrorParameterDerivative(final double[] derivatives, final int freeStateParameters) {
  208.         // 0                               -> value of the delay
  209.         // 1 ... freeStateParameters       -> derivatives of the delay wrt state
  210.         // freeStateParameters + 1 ... n   -> derivatives of the delay wrt tropospheric parameters
  211.         final int dim = derivatives.length - 1 - freeStateParameters;
  212.         final double[] rangeError = new double[dim];

  213.         for (int i = 0; i < dim; i++) {
  214.             rangeError[i] = derivatives[1 + freeStateParameters + i];
  215.         }

  216.         return rangeError;
  217.     }

  218.     /** {@inheritDoc} */
  219.     @Override
  220.     public List<ParameterDriver> getParametersDrivers() {
  221.         return tropoModel.getParametersDrivers();
  222.     }

  223.     /** {@inheritDoc} */
  224.     @Override
  225.     public void modify(final EstimatedMeasurement<RangeRate> estimated) {
  226.         final RangeRate       measurement = estimated.getObservedMeasurement();
  227.         final GroundStation   station     = measurement.getStation();
  228.         final SpacecraftState state       = estimated.getStates()[0];

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

  230.         // update estimated derivatives with Jacobian of the measure wrt state
  231.         final TroposphericDSConverter converter =
  232.                 new TroposphericDSConverter(state, 6, new InertialProvider(state.getFrame()));
  233.         final FieldSpacecraftState<DerivativeStructure> dsState = converter.getState(tropoModel);
  234.         final DerivativeStructure[] dsParameters = converter.getParameters(dsState, tropoModel);
  235.         final DerivativeStructure dsDelay = rangeRateErrorTroposphericModel(station, dsState, dsParameters);
  236.         final double[] derivatives = dsDelay.getAllDerivatives();

  237.         final double[][] djac = rangeRateErrorJacobianState(derivatives, converter.getFreeStateParameters());
  238.         final double[][] stateDerivatives = estimated.getStateDerivatives(0);
  239.         for (int irow = 0; irow < stateDerivatives.length; ++irow) {
  240.             for (int jcol = 0; jcol < stateDerivatives[0].length; ++jcol) {
  241.                 stateDerivatives[irow][jcol] += djac[irow][jcol];
  242.             }
  243.         }
  244.         estimated.setStateDerivatives(0, stateDerivatives);

  245.         int index = 0;
  246.         for (final ParameterDriver driver : getParametersDrivers()) {
  247.             if (driver.isSelected()) {
  248.                 // update estimated derivatives with derivative of the modification wrt tropospheric parameters
  249.                 double parameterDerivative = estimated.getParameterDerivatives(driver)[0];
  250.                 final double[] dDelaydP    = rangeRateErrorParameterDerivative(derivatives, converter.getFreeStateParameters());
  251.                 parameterDerivative += dDelaydP[index];
  252.                 estimated.setParameterDerivatives(driver, parameterDerivative);
  253.                 index += 1;
  254.             }

  255.         }

  256.         for (final ParameterDriver driver : Arrays.asList(station.getClockOffsetDriver(),
  257.                                                           station.getEastOffsetDriver(),
  258.                                                           station.getNorthOffsetDriver(),
  259.                                                           station.getZenithOffsetDriver())) {
  260.             if (driver.isSelected()) {
  261.                 // update estimated derivatives with derivative of the modification wrt station parameters
  262.                 double parameterDerivative = estimated.getParameterDerivatives(driver)[0];
  263.                 parameterDerivative += rangeRateErrorParameterDerivative(station, driver, state);
  264.                 estimated.setParameterDerivatives(driver, parameterDerivative);
  265.             }
  266.         }

  267.         // update estimated value taking into account the tropospheric delay.
  268.         // The tropospheric delay is directly added to the range.
  269.         final double[] newValue = oldValue.clone();
  270.         newValue[0] = newValue[0] + dsDelay.getReal();
  271.         estimated.setEstimatedValue(newValue);

  272.     }

  273. }