RangeTroposphericDelayModifier.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.Range;
  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 measurement with tropospheric delay.
  37.  * The effect of tropospheric correction on the range 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.  * @author Joris Olympio
  45.  * @since 8.0
  46.  */
  47. public class RangeTroposphericDelayModifier implements EstimationModifier<Range> {

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

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

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

  67.     /** Get the station height above mean sea level.
  68.     * @param <T> type of the elements
  69.     * @param field field of the elements
  70.     * @param station  ground station (or measuring station)
  71.     * @return the measuring station height above sea level, m
  72.     */
  73.     private <T extends RealFieldElement<T>> T getStationHeightAMSL(final Field<T> field, 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.         // satellite elevation
  114.         final FieldVector3D<T> position     = state.getPVCoordinates().getPosition();
  115.         final T elevation                   = station.getBaseFrame().getElevation(position,
  116.                                                                                   state.getFrame(),
  117.                                                                                   state.getDate());


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

  122.             // delay in meters
  123.             final T delay = tropoModel.pathDelay(elevation, 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.     *
  133.     * @return Jacobian of the delay wrt state
  134.     */
  135.     private double[][] rangeErrorJacobianState(final double[] derivatives) {
  136.         final double[][] finiteDifferencesJacobian = new double[1][6];
  137.         System.arraycopy(derivatives, 0, finiteDifferencesJacobian[0], 0, 6);
  138.         return finiteDifferencesJacobian;
  139.     }

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

  150.         final ParameterFunction rangeError = new ParameterFunction() {
  151.             /** {@inheritDoc} */
  152.             @Override
  153.             public double value(final ParameterDriver parameterDriver) {
  154.                 return rangeErrorTroposphericModel(station, state);
  155.             }
  156.         };

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

  159.         return rangeErrorDerivative.value(driver);

  160.     }

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

  173.         for (int i = 0; i < dim; i++) {
  174.             rangeError[i] = derivatives[freeStateParameters + i];
  175.         }

  176.         return rangeError;
  177.     }

  178.     /** {@inheritDoc} */
  179.     @Override
  180.     public List<ParameterDriver> getParametersDrivers() {
  181.         return tropoModel.getParametersDrivers();
  182.     }

  183.     /** {@inheritDoc} */
  184.     @Override
  185.     public void modify(final EstimatedMeasurement<Range> estimated) {
  186.         final Range           measurement = estimated.getObservedMeasurement();
  187.         final GroundStation   station     = measurement.getStation();
  188.         final SpacecraftState state       = estimated.getStates()[0];

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

  190.         // update estimated derivatives with Jacobian of the measure wrt state
  191.         final TroposphericGradientConverter converter =
  192.                 new TroposphericGradientConverter(state, 6, new InertialProvider(state.getFrame()));
  193.         final FieldSpacecraftState<Gradient> gState = converter.getState(tropoModel);
  194.         final Gradient[] gParameters = converter.getParameters(gState, tropoModel);
  195.         final Gradient gDelay = rangeErrorTroposphericModel(station, gState, gParameters);
  196.         final double[] derivatives = gDelay.getGradient();

  197.         final double[][] djac = rangeErrorJacobianState(derivatives);

  198.         final double[][] stateDerivatives = estimated.getStateDerivatives(0);
  199.         for (int irow = 0; irow < stateDerivatives.length; ++irow) {
  200.             for (int jcol = 0; jcol < stateDerivatives[0].length; ++jcol) {
  201.                 stateDerivatives[irow][jcol] += djac[irow][jcol];
  202.             }
  203.         }
  204.         estimated.setStateDerivatives(0, stateDerivatives);

  205.         int index = 0;
  206.         for (final ParameterDriver driver : getParametersDrivers()) {
  207.             if (driver.isSelected()) {
  208.                 // update estimated derivatives with derivative of the modification wrt tropospheric parameters
  209.                 double parameterDerivative = estimated.getParameterDerivatives(driver)[0];
  210.                 final double[] dDelaydP    = rangeErrorParameterDerivative(derivatives, converter.getFreeStateParameters());
  211.                 parameterDerivative += dDelaydP[index];
  212.                 estimated.setParameterDerivatives(driver, parameterDerivative);
  213.                 index = index + 1;
  214.             }

  215.         }

  216.         for (final ParameterDriver driver : Arrays.asList(station.getClockOffsetDriver(),
  217.                                                           station.getEastOffsetDriver(),
  218.                                                           station.getNorthOffsetDriver(),
  219.                                                           station.getZenithOffsetDriver())) {
  220.             if (driver.isSelected()) {
  221.                 // update estimated derivatives with derivative of the modification wrt station parameters
  222.                 double parameterDerivative = estimated.getParameterDerivatives(driver)[0];
  223.                 parameterDerivative += rangeErrorParameterDerivative(station, driver, state);
  224.                 estimated.setParameterDerivatives(driver, parameterDerivative);
  225.             }
  226.         }

  227.         // update estimated value taking into account the tropospheric delay.
  228.         // The tropospheric delay is directly added to the range.
  229.         final double[] newValue = oldValue.clone();
  230.         newValue[0] = newValue[0] + gDelay.getReal();
  231.         estimated.setEstimatedValue(newValue);

  232.     }

  233. }