PhaseTroposphericDelayModifier.java

  1. /* Copyright 2002-2022 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.CalculusFieldElement;
  21. import org.hipparchus.Field;
  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.     /** Compute the measurement error due to Troposphere.
  55.      * @param station station
  56.      * @param state spacecraft state
  57.      * @param wavelength wavelength of the signal
  58.      * @return the measurement error due to Troposphere
  59.      */
  60.     private double phaseErrorTroposphericModel(final GroundStation station, final SpacecraftState state, final double wavelength) {
  61.         // satellite position
  62.         final Vector3D position = state.getPVCoordinates().getPosition();

  63.         // elevation
  64.         final double elevation = station.getBaseFrame().getElevation(position,
  65.                                                                      state.getFrame(),
  66.                                                                      state.getDate());

  67.         // only consider measures above the horizon
  68.         if (elevation > 0) {
  69.             // delay in meters
  70.             final double delay = tropoModel.pathDelay(elevation, station.getBaseFrame().getPoint(), tropoModel.getParameters(), state.getDate());

  71.             return delay / wavelength;
  72.         }

  73.         return 0;
  74.     }

  75.     /** Compute the measurement error due to Troposphere.
  76.      * @param <T> type of the element
  77.      * @param station station
  78.      * @param state spacecraft state
  79.      * @param parameters tropospheric model parameters
  80.      * @param wavelength of the measurements
  81.      * @return the measurement error due to Troposphere
  82.      */
  83.     private <T extends CalculusFieldElement<T>> T phaseErrorTroposphericModel(final GroundStation station,
  84.                                                                           final FieldSpacecraftState<T> state,
  85.                                                                           final T[] parameters, final double wavelength) {

  86.         // Field
  87.         final Field<T> field = state.getDate().getField();
  88.         final T zero         = field.getZero();

  89.         // satellite elevation
  90.         final FieldVector3D<T> position     = state.getPVCoordinates().getPosition();
  91.         final T elevation                   = station.getBaseFrame().getElevation(position,
  92.                                                                                   state.getFrame(),
  93.                                                                                   state.getDate());


  94.         // only consider measures above the horizon
  95.         if (elevation.getReal() > 0) {
  96.             // delay in meters
  97.             final T delay = tropoModel.pathDelay(elevation, station.getBaseFrame().getPoint(field), parameters, state.getDate());

  98.             return delay.divide(wavelength);
  99.         }

  100.         return zero;
  101.     }

  102.     /** Compute the Jacobian of the delay term wrt state using
  103.     * automatic differentiation.
  104.     *
  105.     * @param derivatives tropospheric delay derivatives
  106.     *
  107.     * @return Jacobian of the delay wrt state
  108.     */
  109.     private double[][] phaseErrorJacobianState(final double[] derivatives) {
  110.         final double[][] finiteDifferencesJacobian = new double[1][6];
  111.         System.arraycopy(derivatives, 0, finiteDifferencesJacobian[0], 0, 6);
  112.         return finiteDifferencesJacobian;
  113.     }

  114.     /** Compute the derivative of the delay term wrt parameters.
  115.      *
  116.      * @param station ground station
  117.      * @param driver driver for the station offset parameter
  118.      * @param state spacecraft state
  119.      * @param wavelength wavelength of the signal
  120.      * @return derivative of the delay wrt station offset parameter
  121.      */
  122.     private double phaseErrorParameterDerivative(final GroundStation station,
  123.                                                  final ParameterDriver driver,
  124.                                                  final SpacecraftState state,
  125.                                                  final double wavelength) {
  126.         final ParameterFunction rangeError = parameterDriver -> phaseErrorTroposphericModel(station, state, wavelength);
  127.         final ParameterFunction phaseErrorDerivative =
  128.                         Differentiation.differentiate(rangeError, 3, 10.0 * driver.getScale());
  129.         return phaseErrorDerivative.value(driver);

  130.     }

  131.     /** Compute the derivative of the delay term wrt parameters using
  132.     * automatic differentiation.
  133.     *
  134.     * @param derivatives tropospheric delay derivatives
  135.     * @param freeStateParameters dimension of the state.
  136.     * @return derivative of the delay wrt tropospheric model parameters
  137.     */
  138.     private double[] phaseErrorParameterDerivative(final double[] derivatives, final int freeStateParameters) {
  139.         // 0 ... freeStateParameters - 1   -> derivatives of the delay wrt state
  140.         // freeStateParameters ... n       -> derivatives of the delay wrt tropospheric parameters
  141.         final int dim = derivatives.length - freeStateParameters;
  142.         final double[] rangeError = new double[dim];

  143.         for (int i = 0; i < dim; i++) {
  144.             rangeError[i] = derivatives[freeStateParameters + i];
  145.         }

  146.         return rangeError;
  147.     }

  148.     /** {@inheritDoc} */
  149.     @Override
  150.     public List<ParameterDriver> getParametersDrivers() {
  151.         return tropoModel.getParametersDrivers();
  152.     }

  153.     /** {@inheritDoc} */
  154.     @Override
  155.     public void modify(final EstimatedMeasurement<Phase> estimated) {
  156.         final Phase           measurement = estimated.getObservedMeasurement();
  157.         final GroundStation   station     = measurement.getStation();
  158.         final SpacecraftState state       = estimated.getStates()[0];

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

  161.         // update estimated derivatives with Jacobian of the measure wrt state
  162.         final ModifierGradientConverter converter = new ModifierGradientConverter(state, 6, new InertialProvider(state.getFrame()));
  163.         final FieldSpacecraftState<Gradient> gState = converter.getState(tropoModel);
  164.         final Gradient[] gParameters = converter.getParameters(gState, tropoModel);
  165.         final Gradient gDelay = phaseErrorTroposphericModel(station, gState, gParameters, measurement.getWavelength());
  166.         final double[] derivatives = gDelay.getGradient();

  167.         // Update state derivatives
  168.         final double[][] djac = phaseErrorJacobianState(derivatives);
  169.         final double[][] stateDerivatives = estimated.getStateDerivatives(0);
  170.         for (int irow = 0; irow < stateDerivatives.length; ++irow) {
  171.             for (int jcol = 0; jcol < stateDerivatives[0].length; ++jcol) {
  172.                 stateDerivatives[irow][jcol] += djac[irow][jcol];
  173.             }
  174.         }
  175.         estimated.setStateDerivatives(0, stateDerivatives);


  176.         // Update tropospheric parameter derivatives
  177.         int index = 0;
  178.         for (final ParameterDriver driver : getParametersDrivers()) {
  179.             if (driver.isSelected()) {
  180.                 // update estimated derivatives with derivative of the modification wrt tropospheric parameters
  181.                 double parameterDerivative = estimated.getParameterDerivatives(driver)[0];
  182.                 final double[] dDelaydP    = phaseErrorParameterDerivative(derivatives, converter.getFreeStateParameters());
  183.                 parameterDerivative += dDelaydP[index];
  184.                 estimated.setParameterDerivatives(driver, parameterDerivative);
  185.                 index = index + 1;
  186.             }
  187.         }

  188.         // Update station parameter derivatives
  189.         for (final ParameterDriver driver : Arrays.asList(station.getClockOffsetDriver(),
  190.                                                           station.getEastOffsetDriver(),
  191.                                                           station.getNorthOffsetDriver(),
  192.                                                           station.getZenithOffsetDriver())) {
  193.             if (driver.isSelected()) {
  194.                 // update estimated derivatives with derivative of the modification wrt station parameters
  195.                 double parameterDerivative = estimated.getParameterDerivatives(driver)[0];
  196.                 parameterDerivative += phaseErrorParameterDerivative(station, driver, state, measurement.getWavelength());
  197.                 estimated.setParameterDerivatives(driver, parameterDerivative);
  198.             }
  199.         }

  200.         // Update estimated value taking into account the tropospheric delay.
  201.         // The tropospheric delay is directly added to the phase.
  202.         final double[] newValue = oldValue.clone();
  203.         newValue[0] = newValue[0] + gDelay.getReal();
  204.         estimated.setEstimatedValue(newValue);
  205.     }

  206. }