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.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.     /** 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.     *
  168.     * @return Jacobian of the delay wrt state
  169.     */
  170.     private double[][] rangeRateErrorJacobianState(final double[] derivatives) {
  171.         final double[][] finiteDifferencesJacobian = new double[1][6];
  172.         System.arraycopy(derivatives, 0, finiteDifferencesJacobian[0], 0, 6);
  173.         return finiteDifferencesJacobian;
  174.     }

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

  185.         final ParameterFunction rangeError = new ParameterFunction() {
  186.             /** {@inheritDoc} */
  187.             @Override
  188.             public double value(final ParameterDriver parameterDriver) {
  189.                 return rangeRateErrorTroposphericModel(station, state);
  190.             }
  191.         };

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

  194.         return rangeErrorDerivative.value(driver);

  195.     }

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

  208.         for (int i = 0; i < dim; i++) {
  209.             rangeError[i] = derivatives[freeStateParameters + i];
  210.         }

  211.         return rangeError;
  212.     }

  213.     /** {@inheritDoc} */
  214.     @Override
  215.     public List<ParameterDriver> getParametersDrivers() {
  216.         return tropoModel.getParametersDrivers();
  217.     }

  218.     /** {@inheritDoc} */
  219.     @Override
  220.     public void modify(final EstimatedMeasurement<RangeRate> estimated) {
  221.         final RangeRate       measurement = estimated.getObservedMeasurement();
  222.         final GroundStation   station     = measurement.getStation();
  223.         final SpacecraftState state       = estimated.getStates()[0];

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

  225.         // update estimated derivatives with Jacobian of the measure wrt state
  226.         final TroposphericGradientConverter converter =
  227.                 new TroposphericGradientConverter(state, 6, new InertialProvider(state.getFrame()));
  228.         final FieldSpacecraftState<Gradient> gState = converter.getState(tropoModel);
  229.         final Gradient[] gParameters = converter.getParameters(gState, tropoModel);
  230.         final Gradient gDelay = rangeRateErrorTroposphericModel(station, gState, gParameters);
  231.         final double[] derivatives = gDelay.getGradient();

  232.         final double[][] djac = rangeRateErrorJacobianState(derivatives);
  233.         final double[][] stateDerivatives = estimated.getStateDerivatives(0);
  234.         for (int irow = 0; irow < stateDerivatives.length; ++irow) {
  235.             for (int jcol = 0; jcol < stateDerivatives[0].length; ++jcol) {
  236.                 stateDerivatives[irow][jcol] += djac[irow][jcol];
  237.             }
  238.         }
  239.         estimated.setStateDerivatives(0, stateDerivatives);

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

  250.         }

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

  262.         // update estimated value taking into account the tropospheric delay.
  263.         // The tropospheric delay is directly added to the range.
  264.         final double[] newValue = oldValue.clone();
  265.         newValue[0] = newValue[0] + gDelay.getReal();
  266.         estimated.setEstimatedValue(newValue);

  267.     }

  268. }