PhaseTroposphericDelayModifier.java

  1. /* Copyright 2002-2025 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.orekit.attitudes.FrameAlignedProvider;
  24. import org.orekit.estimation.measurements.EstimatedMeasurement;
  25. import org.orekit.estimation.measurements.EstimatedMeasurementBase;
  26. import org.orekit.estimation.measurements.EstimationModifier;
  27. import org.orekit.estimation.measurements.GroundStation;
  28. import org.orekit.estimation.measurements.gnss.Phase;
  29. import org.orekit.models.earth.troposphere.TroposphericModel;
  30. import org.orekit.propagation.FieldSpacecraftState;
  31. import org.orekit.propagation.SpacecraftState;
  32. import org.orekit.utils.Differentiation;
  33. import org.orekit.utils.FieldTrackingCoordinates;
  34. import org.orekit.utils.ParameterDriver;
  35. import org.orekit.utils.ParameterFunction;
  36. import org.orekit.utils.TimeSpanMap.Span;
  37. import org.orekit.utils.TrackingCoordinates;

  38. /**
  39.  * Class modifying theoretical phase measurement with tropospheric delay.
  40.  * The effect of tropospheric correction on the phase is directly computed
  41.  * through the computation of the tropospheric delay.
  42.  * @author David Soulard
  43.  * @author Bryan Cazabonne
  44.  * @since 10.2
  45.  */
  46. public class PhaseTroposphericDelayModifier implements EstimationModifier<Phase> {

  47.     /** Tropospheric delay model. */
  48.     private final TroposphericModel tropoModel;

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

  57. /** {@inheritDoc} */
  58.     @Override
  59.         public String getEffectName() {
  60.         return "troposphere";
  61.     }

  62.     /** Compute the measurement error due to Troposphere.
  63.      * @param station station
  64.      * @param state spacecraft state
  65.      * @param wavelength wavelength of the signal
  66.      * @return the measurement error due to Troposphere
  67.      */
  68.     private double phaseErrorTroposphericModel(final GroundStation station, final SpacecraftState state, final double wavelength) {

  69.         // tracking
  70.         final TrackingCoordinates trackingCoordinates =
  71.                         station.getBaseFrame().getTrackingCoordinates(state.getPosition(), state.getFrame(), state.getDate());

  72.         // only consider measures above the horizon
  73.         if (trackingCoordinates.getElevation() > 0) {
  74.             // delay in meters
  75.             final double delay = tropoModel.pathDelay(trackingCoordinates,
  76.                                                       station.getOffsetGeodeticPoint(state.getDate()),
  77.                                                       tropoModel.getParameters(state.getDate()), state.getDate()).
  78.                                  getDelay();

  79.             return delay / wavelength;
  80.         }

  81.         return 0;
  82.     }

  83.     /** Compute the measurement error due to Troposphere.
  84.      * @param <T> type of the element
  85.      * @param station station
  86.      * @param state spacecraft state
  87.      * @param parameters tropospheric model parameters
  88.      * @param wavelength of the measurements
  89.      * @return the measurement error due to Troposphere
  90.      */
  91.     private <T extends CalculusFieldElement<T>> T phaseErrorTroposphericModel(final GroundStation station,
  92.                                                                           final FieldSpacecraftState<T> state,
  93.                                                                           final T[] parameters, final double wavelength) {

  94.         // Field
  95.         final Field<T> field = state.getDate().getField();
  96.         final T zero         = field.getZero();

  97.         // tracking
  98.         final FieldTrackingCoordinates<T> trackingCoordinates =
  99.                         station.getBaseFrame().getTrackingCoordinates(state.getPosition(), state.getFrame(), state.getDate());


  100.         // only consider measures above the horizon
  101.         if (trackingCoordinates.getElevation().getReal() > 0) {
  102.             // delay in meters
  103.             final T delay = tropoModel.pathDelay(trackingCoordinates,
  104.                                                  station.getOffsetGeodeticPoint(state.getDate()),
  105.                                                  parameters, state.getDate()).
  106.                             getDelay();

  107.             return delay.divide(wavelength);
  108.         }

  109.         return zero;
  110.     }

  111.     /** Compute the Jacobian of the delay term wrt state using
  112.     * automatic differentiation.
  113.     *
  114.     * @param derivatives tropospheric delay derivatives
  115.     *
  116.     * @return Jacobian of the delay wrt state
  117.     */
  118.     private double[][] phaseErrorJacobianState(final double[] derivatives) {
  119.         final double[][] finiteDifferencesJacobian = new double[1][6];
  120.         System.arraycopy(derivatives, 0, finiteDifferencesJacobian[0], 0, 6);
  121.         return finiteDifferencesJacobian;
  122.     }

  123.     /** Compute the derivative of the delay term wrt parameters.
  124.      *
  125.      * @param station ground station
  126.      * @param driver driver for the station offset parameter
  127.      * @param state spacecraft state
  128.      * @param wavelength wavelength of the signal
  129.      * @return derivative of the delay wrt station offset parameter
  130.      */
  131.     private double phaseErrorParameterDerivative(final GroundStation station,
  132.                                                  final ParameterDriver driver,
  133.                                                  final SpacecraftState state,
  134.                                                  final double wavelength) {
  135.         final ParameterFunction rangeError = (parameterDriver, date) -> phaseErrorTroposphericModel(station, state, wavelength);
  136.         final ParameterFunction phaseErrorDerivative =
  137.                         Differentiation.differentiate(rangeError, 3, 10.0 * driver.getScale());
  138.         return phaseErrorDerivative.value(driver, state.getDate());

  139.     }

  140.     /** Compute the derivative of the delay term wrt parameters using
  141.     * automatic differentiation.
  142.     *
  143.     * @param derivatives tropospheric delay derivatives
  144.     * @param freeStateParameters dimension of the state.
  145.     * @return derivative of the delay wrt tropospheric model parameters
  146.     */
  147.     private double[] phaseErrorParameterDerivative(final double[] derivatives, final int freeStateParameters) {
  148.         // 0 ... freeStateParameters - 1   -> derivatives of the delay wrt state
  149.         // freeStateParameters ... n       -> derivatives of the delay wrt tropospheric parameters
  150.         return Arrays.copyOfRange(derivatives, freeStateParameters, derivatives.length);
  151.     }

  152.     /** {@inheritDoc} */
  153.     @Override
  154.     public List<ParameterDriver> getParametersDrivers() {
  155.         return tropoModel.getParametersDrivers();
  156.     }

  157.     /** {@inheritDoc} */
  158.     @Override
  159.     public void modifyWithoutDerivatives(final EstimatedMeasurementBase<Phase> estimated) {

  160.         final Phase           measurement = estimated.getObservedMeasurement();
  161.         final GroundStation   station     = measurement.getStation();
  162.         final SpacecraftState state       = estimated.getStates()[0];

  163.         // Update estimated value taking into account the tropospheric delay.
  164.         // The tropospheric delay is directly added to the phase.
  165.         final double[] newValue = estimated.getEstimatedValue();
  166.         final double delay = phaseErrorTroposphericModel(station, state, measurement.getWavelength());
  167.         newValue[0] = newValue[0] + delay;
  168.         estimated.modifyEstimatedValue(this, newValue);

  169.     }

  170.     /** {@inheritDoc} */
  171.     @Override
  172.     public void modify(final EstimatedMeasurement<Phase> estimated) {
  173.         final Phase           measurement = estimated.getObservedMeasurement();
  174.         final GroundStation   station     = measurement.getStation();
  175.         final SpacecraftState state       = estimated.getStates()[0];

  176.         // update estimated derivatives with Jacobian of the measure wrt state
  177.         final ModifierGradientConverter converter = new ModifierGradientConverter(state, 6, new FrameAlignedProvider(state.getFrame()));
  178.         final FieldSpacecraftState<Gradient> gState = converter.getState(tropoModel);
  179.         final Gradient[] gParameters = converter.getParametersAtStateDate(gState, tropoModel);
  180.         final Gradient gDelay = phaseErrorTroposphericModel(station, gState, gParameters, measurement.getWavelength());
  181.         final double[] derivatives = gDelay.getGradient();

  182.         // Update state derivatives
  183.         final double[][] djac = phaseErrorJacobianState(derivatives);
  184.         final double[][] stateDerivatives = estimated.getStateDerivatives(0);
  185.         for (int irow = 0; irow < stateDerivatives.length; ++irow) {
  186.             for (int jcol = 0; jcol < stateDerivatives[0].length; ++jcol) {
  187.                 stateDerivatives[irow][jcol] += djac[irow][jcol];
  188.             }
  189.         }
  190.         estimated.setStateDerivatives(0, stateDerivatives);


  191.         // Update tropospheric parameter derivatives
  192.         int index = 0;
  193.         for (final ParameterDriver driver : getParametersDrivers()) {
  194.             if (driver.isSelected()) {
  195.                 for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {

  196.                     // update estimated derivatives with derivative of the modification wrt tropospheric parameters
  197.                     double parameterDerivative = estimated.getParameterDerivatives(driver, span.getStart())[0];
  198.                     final double[] dDelaydP    = phaseErrorParameterDerivative(derivatives, converter.getFreeStateParameters());
  199.                     parameterDerivative += dDelaydP[index];
  200.                     estimated.setParameterDerivatives(driver, span.getStart(), parameterDerivative);
  201.                     index = index + 1;
  202.                 }
  203.             }
  204.         }

  205.         // Update station parameter derivatives
  206.         for (final ParameterDriver driver : Arrays.asList(station.getClockOffsetDriver(),
  207.                                                           station.getEastOffsetDriver(),
  208.                                                           station.getNorthOffsetDriver(),
  209.                                                           station.getZenithOffsetDriver())) {
  210.             if (driver.isSelected()) {
  211.                 for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
  212.                     // update estimated derivatives with derivative of the modification wrt station parameters
  213.                     double parameterDerivative = estimated.getParameterDerivatives(driver, span.getStart())[0];
  214.                     parameterDerivative += phaseErrorParameterDerivative(station, driver, state, measurement.getWavelength());
  215.                     estimated.setParameterDerivatives(driver, span.getStart(), parameterDerivative);
  216.                 }
  217.             }
  218.         }

  219.         // Update estimated value taking into account the tropospheric delay.
  220.         modifyWithoutDerivatives(estimated);

  221.     }

  222. }