PhaseTroposphericDelayModifier.java

  1. /* Copyright 2002-2024 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.DiscreteTroposphericModel;
  30. import org.orekit.propagation.FieldSpacecraftState;
  31. import org.orekit.propagation.SpacecraftState;
  32. import org.orekit.utils.Differentiation;
  33. import org.orekit.utils.ParameterDriver;
  34. import org.orekit.utils.ParameterFunction;
  35. import org.orekit.utils.TimeSpanMap.Span;

  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.         // elevation
  62.         final double elevation =
  63.                         station.getBaseFrame().getTrackingCoordinates(state.getPosition(), state.getFrame(), state.getDate()).
  64.                         getElevation();

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

  69.             return delay / wavelength;
  70.         }

  71.         return 0;
  72.     }

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

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

  87.         // satellite elevation
  88.         final T elevation =
  89.                         station.getBaseFrame().getTrackingCoordinates(state.getPosition(), state.getFrame(), state.getDate()).
  90.                         getElevation();


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

  95.             return delay.divide(wavelength);
  96.         }

  97.         return zero;
  98.     }

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

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

  127.     }

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

  140.         for (int i = 0; i < dim; i++) {
  141.             rangeError[i] = derivatives[freeStateParameters + i];
  142.         }

  143.         return rangeError;
  144.     }

  145.     /** {@inheritDoc} */
  146.     @Override
  147.     public List<ParameterDriver> getParametersDrivers() {
  148.         return tropoModel.getParametersDrivers();
  149.     }

  150.     /** {@inheritDoc} */
  151.     @Override
  152.     public void modifyWithoutDerivatives(final EstimatedMeasurementBase<Phase> estimated) {

  153.         final Phase           measurement = estimated.getObservedMeasurement();
  154.         final GroundStation   station     = measurement.getStation();
  155.         final SpacecraftState state       = estimated.getStates()[0];

  156.         // Update estimated value taking into account the tropospheric delay.
  157.         // The tropospheric delay is directly added to the phase.
  158.         final double[] newValue = estimated.getEstimatedValue();
  159.         final double delay = phaseErrorTroposphericModel(station, state, measurement.getWavelength());
  160.         newValue[0] = newValue[0] + delay;
  161.         estimated.setEstimatedValue(newValue);

  162.     }

  163.     /** {@inheritDoc} */
  164.     @Override
  165.     public void modify(final EstimatedMeasurement<Phase> estimated) {
  166.         final Phase           measurement = estimated.getObservedMeasurement();
  167.         final GroundStation   station     = measurement.getStation();
  168.         final SpacecraftState state       = estimated.getStates()[0];

  169.         // update estimated derivatives with Jacobian of the measure wrt state
  170.         final ModifierGradientConverter converter = new ModifierGradientConverter(state, 6, new FrameAlignedProvider(state.getFrame()));
  171.         final FieldSpacecraftState<Gradient> gState = converter.getState(tropoModel);
  172.         final Gradient[] gParameters = converter.getParametersAtStateDate(gState, tropoModel);
  173.         final Gradient gDelay = phaseErrorTroposphericModel(station, gState, gParameters, measurement.getWavelength());
  174.         final double[] derivatives = gDelay.getGradient();

  175.         // Update state derivatives
  176.         final double[][] djac = phaseErrorJacobianState(derivatives);
  177.         final double[][] stateDerivatives = estimated.getStateDerivatives(0);
  178.         for (int irow = 0; irow < stateDerivatives.length; ++irow) {
  179.             for (int jcol = 0; jcol < stateDerivatives[0].length; ++jcol) {
  180.                 stateDerivatives[irow][jcol] += djac[irow][jcol];
  181.             }
  182.         }
  183.         estimated.setStateDerivatives(0, stateDerivatives);


  184.         // Update tropospheric parameter derivatives
  185.         int index = 0;
  186.         for (final ParameterDriver driver : getParametersDrivers()) {
  187.             if (driver.isSelected()) {
  188.                 for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {

  189.                     // update estimated derivatives with derivative of the modification wrt tropospheric parameters
  190.                     double parameterDerivative = estimated.getParameterDerivatives(driver, span.getStart())[0];
  191.                     final double[] dDelaydP    = phaseErrorParameterDerivative(derivatives, converter.getFreeStateParameters());
  192.                     parameterDerivative += dDelaydP[index];
  193.                     estimated.setParameterDerivatives(driver, span.getStart(), parameterDerivative);
  194.                     index = index + 1;
  195.                 }
  196.             }
  197.         }

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

  212.         // Update estimated value taking into account the tropospheric delay.
  213.         modifyWithoutDerivatives(estimated);

  214.     }

  215. }