PhaseTroposphericDelayModifier.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.  * The ASF 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.gnss.Phase;
  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. /**
  37.  * Class modifying theoretical phase measurement with tropospheric delay.
  38.  * The effect of tropospheric correction on the phase is directly computed
  39.  * through the computation of the tropospheric delay.
  40.  * @author David Soulard
  41.  * @author Bryan Cazabonne
  42.  * @since 10.2
  43.  */
  44. public class PhaseTroposphericDelayModifier implements EstimationModifier<Phase> {

  45.     /** Tropospheric delay model. */
  46.     private final DiscreteTroposphericModel tropoModel;

  47.     /** Constructor.
  48.      *
  49.      * @param model  Tropospheric delay model appropriate for the current range measurement method.
  50.      */
  51.     public PhaseTroposphericDelayModifier(final DiscreteTroposphericModel model) {
  52.         tropoModel          = model;
  53.     }

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

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

  75.     /** Compute the measurement error due to Troposphere.
  76.      * @param station station
  77.      * @param state spacecraft state
  78.      * @param wavelength wavelength of the signal
  79.      * @return the measurement error due to Troposphere
  80.      */
  81.     private double phaseErrorTroposphericModel(final GroundStation station, final SpacecraftState state, final double wavelength) {
  82.         // satellite position
  83.         final Vector3D position = state.getPVCoordinates().getPosition();

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

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

  92.             // delay in meters
  93.             final double delay = tropoModel.pathDelay(elevation, height, tropoModel.getParameters(), state.getDate());

  94.             return delay / wavelength;
  95.         }

  96.         return 0;
  97.     }

  98.     /** Compute the measurement error due to Troposphere.
  99.      * @param <T> type of the element
  100.      * @param station station
  101.      * @param state spacecraft state
  102.      * @param parameters tropospheric model parameters
  103.      * @param wavelength of the measurements
  104.      * @return the measurement error due to Troposphere
  105.      */
  106.     private <T extends RealFieldElement<T>> T phaseErrorTroposphericModel(final GroundStation station,
  107.                                                                           final FieldSpacecraftState<T> state,
  108.                                                                           final T[] parameters, final double wavelength) {

  109.         // Field
  110.         final Field<T> field = state.getDate().getField();
  111.         final T zero         = field.getZero();

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


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

  121.             // delay in meters
  122.             final T delay = tropoModel.pathDelay(elevation, height, parameters, state.getDate());

  123.             return delay.divide(wavelength);
  124.         }

  125.         return zero;
  126.     }

  127.     /** Compute the Jacobian of the delay term wrt state using
  128.     * automatic differentiation.
  129.     *
  130.     * @param derivatives tropospheric delay derivatives
  131.     *
  132.     * @return Jacobian of the delay wrt state
  133.     */
  134.     private double[][] phaseErrorJacobianState(final double[] derivatives) {
  135.         final double[][] finiteDifferencesJacobian = new double[1][6];
  136.         System.arraycopy(derivatives, 0, finiteDifferencesJacobian[0], 0, 6);
  137.         return finiteDifferencesJacobian;
  138.     }

  139.     /** Compute the derivative of the delay term wrt parameters.
  140.      *
  141.      * @param station ground station
  142.      * @param driver driver for the station offset parameter
  143.      * @param state spacecraft state
  144.      * @param wavelength wavelength of the signal
  145.      * @return derivative of the delay wrt station offset parameter
  146.      */
  147.     private double phaseErrorParameterDerivative(final GroundStation station,
  148.                                                  final ParameterDriver driver,
  149.                                                  final SpacecraftState state,
  150.                                                  final double wavelength) {
  151.         final ParameterFunction rangeError = parameterDriver -> phaseErrorTroposphericModel(station, state, wavelength);
  152.         final ParameterFunction phaseErrorDerivative =
  153.                         Differentiation.differentiate(rangeError, 3, 10.0 * driver.getScale());
  154.         return phaseErrorDerivative.value(driver);

  155.     }

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

  168.         for (int i = 0; i < dim; i++) {
  169.             rangeError[i] = derivatives[freeStateParameters + i];
  170.         }

  171.         return rangeError;
  172.     }

  173.     /** {@inheritDoc} */
  174.     @Override
  175.     public List<ParameterDriver> getParametersDrivers() {
  176.         return tropoModel.getParametersDrivers();
  177.     }

  178.     /** {@inheritDoc} */
  179.     @Override
  180.     public void modify(final EstimatedMeasurement<Phase> estimated) {
  181.         final Phase           measurement = estimated.getObservedMeasurement();
  182.         final GroundStation   station     = measurement.getStation();
  183.         final SpacecraftState state       = estimated.getStates()[0];

  184.         // Old range value
  185.         final double[] oldValue = estimated.getEstimatedValue();

  186.         // update estimated derivatives with Jacobian of the measure wrt state
  187.         final TroposphericGradientConverter converter = new TroposphericGradientConverter(state, 6, new InertialProvider(state.getFrame()));
  188.         final FieldSpacecraftState<Gradient> gState = converter.getState(tropoModel);
  189.         final Gradient[] gParameters = converter.getParameters(gState, tropoModel);
  190.         final Gradient gDelay = phaseErrorTroposphericModel(station, gState, gParameters, measurement.getWavelength());
  191.         final double[] derivatives = gDelay.getGradient();

  192.         // Update state derivatives
  193.         final double[][] djac = phaseErrorJacobianState(derivatives);
  194.         final double[][] stateDerivatives = estimated.getStateDerivatives(0);
  195.         for (int irow = 0; irow < stateDerivatives.length; ++irow) {
  196.             for (int jcol = 0; jcol < stateDerivatives[0].length; ++jcol) {
  197.                 stateDerivatives[irow][jcol] += djac[irow][jcol];
  198.             }
  199.         }
  200.         estimated.setStateDerivatives(0, stateDerivatives);


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

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

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

  231. }