TurnAroundRangeTroposphericDelayModifier.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.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.     /** Get the station height above mean sea level.
  57.      *
  58.      * @param station  ground station (or measuring station)
  59.      * @return the measuring station height above sea level, m
  60.      */
  61.     private double getStationHeightAMSL(final GroundStation station) {
  62.         // FIXME height should be computed with respect to geoid WGS84+GUND = EGM2008 for example
  63.         final double height = station.getBaseFrame().getPoint().getAltitude();
  64.         return height;
  65.     }

  66.     /** Get the station height above mean sea level.
  67.     * @param <T> type of the elements
  68.     * @param field field of the elements
  69.     * @param station  ground station (or measuring station)
  70.     * @return the measuring station height above sea level, m
  71.     */
  72.     private <T extends RealFieldElement<T>> T getStationHeightAMSL(final Field<T> field,
  73.                                                                    final GroundStation station) {
  74.         // FIXME heigth should be computed with respect to geoid WGS84+GUND = EGM2008 for example
  75.         final T height = station.getBaseFrame().getPoint(field).getAltitude();
  76.         return height;
  77.     }

  78.     /** Compute the measurement error due to Troposphere.
  79.      * @param station station
  80.      * @param state spacecraft state
  81.      * @return the measurement error due to Troposphere
  82.      */
  83.     private double rangeErrorTroposphericModel(final GroundStation station, final SpacecraftState state) {
  84.         //
  85.         final Vector3D position = state.getPVCoordinates().getPosition();

  86.         // elevation
  87.         final double elevation = station.getBaseFrame().getElevation(position,
  88.                                                                      state.getFrame(),
  89.                                                                      state.getDate());

  90.         // only consider measures above the horizon
  91.         if (elevation > 0) {
  92.             // altitude AMSL in meters
  93.             final double height = getStationHeightAMSL(station);

  94.             // Delay in meters
  95.             final double delay = tropoModel.pathDelay(elevation, height, tropoModel.getParameters(), state.getDate());

  96.             return delay;
  97.         }

  98.         return 0;
  99.     }

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

  113.         //
  114.         final FieldVector3D<T> position = state.getPVCoordinates().getPosition();
  115.         final T dsElevation             = station.getBaseFrame().getElevation(position,
  116.                                                                               state.getFrame(),
  117.                                                                               state.getDate());

  118.         // only consider measures above the horizon
  119.         if (dsElevation.getReal() > 0) {
  120.             // altitude AMSL in meters
  121.             final T height = getStationHeightAMSL(field, station);

  122.             // Delay in meters
  123.             final T delay = tropoModel.pathDelay(dsElevation, height, parameters, state.getDate());

  124.             return delay;
  125.         }

  126.         return zero;
  127.     }

  128.     /** Compute the Jacobian of the delay term wrt state using
  129.     * automatic differentiation.
  130.     *
  131.     * @param derivatives tropospheric delay derivatives
  132.     * @param freeStateParameters dimension of the state.
  133.     *
  134.     * @return Jacobian of the delay wrt state
  135.     */
  136.     private double[][] rangeErrorJacobianState(final double[] derivatives, final int freeStateParameters) {
  137.         final double[][] finiteDifferencesJacobian = new double[1][6];
  138.         for (int i = 0; i < freeStateParameters; i++) {
  139.             // First element is the value of the delay
  140.             finiteDifferencesJacobian[0][i] = derivatives[i + 1];
  141.         }
  142.         return finiteDifferencesJacobian;
  143.     }


  144.     /** Compute the derivative of the delay term wrt parameters.
  145.      *
  146.      * @param station ground station
  147.      * @param driver driver for the station offset parameter
  148.      * @param state spacecraft state
  149.      * @return derivative of the delay wrt station offset parameter
  150.      */
  151.     private double rangeErrorParameterDerivative(final GroundStation station,
  152.                                                  final ParameterDriver driver,
  153.                                                  final SpacecraftState state) {

  154.         final ParameterFunction rangeError = new ParameterFunction() {
  155.             /** {@inheritDoc} */
  156.             @Override
  157.             public double value(final ParameterDriver parameterDriver) {
  158.                 return rangeErrorTroposphericModel(station, state);
  159.             }
  160.         };

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

  162.         return rangeErrorDerivative.value(driver);

  163.     }

  164.     /** Compute the derivative of the delay term wrt parameters using
  165.     * automatic differentiation.
  166.     *
  167.     * @param derivatives tropospheric delay derivatives
  168.     * @param freeStateParameters dimension of the state.
  169.     * @return derivative of the delay wrt tropospheric model parameters
  170.     */
  171.     private double[] rangeErrorParameterDerivative(final double[] derivatives, final int freeStateParameters) {
  172.         // 0                               -> value of the delay
  173.         // 1 ... freeStateParameters       -> derivatives of the delay wrt state
  174.         // freeStateParameters + 1 ... n   -> derivatives of the delay wrt tropospheric parameters
  175.         final int dim = derivatives.length - 1 - freeStateParameters;
  176.         final double[] rangeError = new double[dim];

  177.         for (int i = 0; i < dim; i++) {
  178.             rangeError[i] = derivatives[1 + freeStateParameters + i];
  179.         }

  180.         return rangeError;
  181.     }

  182.     /** {@inheritDoc} */
  183.     @Override
  184.     public List<ParameterDriver> getParametersDrivers() {
  185.         return tropoModel.getParametersDrivers();
  186.     }

  187.     /** {@inheritDoc} */
  188.     @Override
  189.     public void modify(final EstimatedMeasurement<TurnAroundRange> estimated) {
  190.         final TurnAroundRange measurement   = estimated.getObservedMeasurement();
  191.         final GroundStation   masterStation = measurement.getMasterStation();
  192.         final GroundStation   slaveStation  = measurement.getSlaveStation();
  193.         final SpacecraftState state         = estimated.getStates()[0];

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

  195.         // Update estimated derivatives with Jacobian of the measure wrt state
  196.         final TroposphericDSConverter converter =
  197.                 new TroposphericDSConverter(state, 6, new InertialProvider(state.getFrame()));
  198.         final FieldSpacecraftState<DerivativeStructure> dsState = converter.getState(tropoModel);
  199.         final DerivativeStructure[] dsParameters = converter.getParameters(dsState, tropoModel);
  200.         final DerivativeStructure masterDSDelay = rangeErrorTroposphericModel(masterStation, dsState, dsParameters);
  201.         final DerivativeStructure slaveDSDelay = rangeErrorTroposphericModel(slaveStation, dsState, dsParameters);
  202.         final double[] masterDerivatives = masterDSDelay.getAllDerivatives();
  203.         final double[] slaveDerivatives  = masterDSDelay.getAllDerivatives();

  204.         final double[][] masterDjac = rangeErrorJacobianState(masterDerivatives, converter.getFreeStateParameters());
  205.         final double[][] slaveDjac  = rangeErrorJacobianState(slaveDerivatives, converter.getFreeStateParameters());
  206.         final double[][] stateDerivatives = estimated.getStateDerivatives(0);
  207.         for (int irow = 0; irow < stateDerivatives.length; ++irow) {
  208.             for (int jcol = 0; jcol < stateDerivatives[0].length; ++jcol) {
  209.                 stateDerivatives[irow][jcol] += masterDjac[irow][jcol] + slaveDjac[irow][jcol];
  210.             }
  211.         }
  212.         estimated.setStateDerivatives(0, stateDerivatives);

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

  223.         }

  224.         int indexSlave = 0;
  225.         for (final ParameterDriver driver : getParametersDrivers()) {
  226.             if (driver.isSelected()) {
  227.                 // update estimated derivatives with derivative of the modification wrt tropospheric parameters
  228.                 double parameterDerivative = estimated.getParameterDerivatives(driver)[0];
  229.                 final double[] derivatives = rangeErrorParameterDerivative(slaveDerivatives, converter.getFreeStateParameters());
  230.                 parameterDerivative += derivatives[indexSlave];
  231.                 estimated.setParameterDerivatives(driver, parameterDerivative);
  232.                 indexSlave += 1;
  233.             }

  234.         }

  235.         // Update derivatives with respect to master station position
  236.         for (final ParameterDriver driver : Arrays.asList(masterStation.getClockOffsetDriver(),
  237.                                                           masterStation.getEastOffsetDriver(),
  238.                                                           masterStation.getNorthOffsetDriver(),
  239.                                                           masterStation.getZenithOffsetDriver())) {
  240.             if (driver.isSelected()) {
  241.                 double parameterDerivative = estimated.getParameterDerivatives(driver)[0];
  242.                 parameterDerivative += rangeErrorParameterDerivative(masterStation, driver, state);
  243.                 estimated.setParameterDerivatives(driver, parameterDerivative);
  244.             }
  245.         }

  246.         // Update derivatives with respect to slave station position
  247.         for (final ParameterDriver driver : Arrays.asList(slaveStation.getEastOffsetDriver(),
  248.                                                           slaveStation.getNorthOffsetDriver(),
  249.                                                           slaveStation.getZenithOffsetDriver())) {
  250.             if (driver.isSelected()) {
  251.                 double parameterDerivative = estimated.getParameterDerivatives(driver)[0];
  252.                 parameterDerivative += rangeErrorParameterDerivative(slaveStation, driver, state);
  253.                 estimated.setParameterDerivatives(driver, parameterDerivative);
  254.             }
  255.         }

  256.         // Update estimated value taking into account the tropospheric delay.
  257.         // The tropospheric delay is directly added to the TurnAroundRange.
  258.         final double[] newValue = oldValue.clone();
  259.         newValue[0] = newValue[0] + masterDSDelay.getReal() + slaveDSDelay.getReal();
  260.         estimated.setEstimatedValue(newValue);

  261.     }

  262. }