TurnAroundRangeTroposphericDelayModifier.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.  * 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.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.FrameAlignedProvider;
  26. import org.orekit.estimation.measurements.EstimatedMeasurement;
  27. import org.orekit.estimation.measurements.EstimatedMeasurementBase;
  28. import org.orekit.estimation.measurements.EstimationModifier;
  29. import org.orekit.estimation.measurements.GroundStation;
  30. import org.orekit.estimation.measurements.TurnAroundRange;
  31. import org.orekit.models.earth.troposphere.DiscreteTroposphericModel;
  32. import org.orekit.propagation.FieldSpacecraftState;
  33. import org.orekit.propagation.SpacecraftState;
  34. import org.orekit.time.AbsoluteDate;
  35. import org.orekit.utils.Differentiation;
  36. import org.orekit.utils.ParameterDriver;
  37. import org.orekit.utils.ParameterFunction;
  38. import org.orekit.utils.TimeSpanMap.Span;

  39. /** Class modifying theoretical turn-around TurnAroundRange measurement with tropospheric delay.
  40.  * The effect of tropospheric correction on the TurnAroundRange is directly computed
  41.  * through the computation of the tropospheric delay.
  42.  *
  43.  * In general, for GNSS, VLBI, ... there is hardly any frequency dependence in the delay.
  44.  * For SLR techniques however, the frequency dependence is sensitive.
  45.  *
  46.  * @author Maxime Journot
  47.  * @since 9.0
  48.  */
  49. public class TurnAroundRangeTroposphericDelayModifier implements EstimationModifier<TurnAroundRange> {

  50.     /** Tropospheric delay model. */
  51.     private final DiscreteTroposphericModel tropoModel;

  52.     /** Constructor.
  53.      *
  54.      * @param model  Tropospheric delay model appropriate for the current TurnAroundRange measurement method.
  55.      */
  56.     public TurnAroundRangeTroposphericDelayModifier(final DiscreteTroposphericModel model) {
  57.         tropoModel = model;
  58.     }

  59.     /** Compute the measurement error due to Troposphere.
  60.      * @param station station
  61.      * @param state spacecraft state
  62.      * @return the measurement error due to Troposphere
  63.      */
  64.     private double rangeErrorTroposphericModel(final GroundStation station, final SpacecraftState state) {
  65.         //
  66.         final Vector3D position = state.getPosition();

  67.         // elevation
  68.         final double elevation =
  69.                         station.getBaseFrame().getTrackingCoordinates(position, state.getFrame(), state.getDate()).
  70.                         getElevation();

  71.         // only consider measures above the horizon
  72.         if (elevation > 0) {
  73.             // Delay in meters
  74.             final double delay = tropoModel.pathDelay(elevation, station.getBaseFrame().getPoint(), tropoModel.getParameters(state.getDate()), state.getDate());

  75.             return delay;
  76.         }

  77.         return 0;
  78.     }

  79.     /** Compute the measurement error due to Troposphere.
  80.      * @param <T> type of the element
  81.      * @param station station
  82.      * @param state spacecraft state
  83.      * @param parameters tropospheric model parameters
  84.      * @return the measurement error due to Troposphere
  85.      */
  86.     private <T extends CalculusFieldElement<T>> T rangeErrorTroposphericModel(final GroundStation station,
  87.                                                                           final FieldSpacecraftState<T> state,
  88.                                                                           final T[] parameters) {
  89.         // Field
  90.         final Field<T> field = state.getDate().getField();
  91.         final T zero         = field.getZero();

  92.         //
  93.         final FieldVector3D<T> position = state.getPosition();
  94.         final T dsElevation             =
  95.                         station.getBaseFrame().getTrackingCoordinates(position,  state.getFrame(), state.getDate()).
  96.                         getElevation();

  97.         // only consider measures above the horizon
  98.         if (dsElevation.getReal() > 0) {
  99.             // Delay in meters
  100.             final T delay = tropoModel.pathDelay(dsElevation, station.getBaseFrame().getPoint(field), parameters, state.getDate());

  101.             return delay;
  102.         }

  103.         return zero;
  104.     }

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


  117.     /** Compute the derivative of the delay term wrt parameters.
  118.      *
  119.      * @param station ground station
  120.      * @param driver driver for the station offset parameter
  121.      * @param state spacecraft state
  122.      * @return derivative of the delay wrt station offset parameter
  123.      */
  124.     private double rangeErrorParameterDerivative(final GroundStation station,
  125.                                                  final ParameterDriver driver,
  126.                                                  final SpacecraftState state) {

  127.         final ParameterFunction rangeError = new ParameterFunction() {
  128.             /** {@inheritDoc} */
  129.             @Override
  130.             public double value(final ParameterDriver parameterDriver, final AbsoluteDate date) {
  131.                 return rangeErrorTroposphericModel(station, state);
  132.             }
  133.         };

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

  135.         return rangeErrorDerivative.value(driver, state.getDate());

  136.     }

  137.     /** Compute the derivative of the delay term wrt parameters using
  138.     * automatic differentiation.
  139.     *
  140.     * @param derivatives tropospheric delay derivatives
  141.     * @param freeStateParameters dimension of the state.
  142.     * @return derivative of the delay wrt tropospheric model parameters
  143.     */
  144.     private double[] rangeErrorParameterDerivative(final double[] derivatives, final int freeStateParameters) {
  145.         // 0 ... freeStateParameters - 1 -> derivatives of the delay wrt state
  146.         // freeStateParameters ... n     -> derivatives of the delay wrt tropospheric parameters
  147.         final int dim = derivatives.length - freeStateParameters;
  148.         final double[] rangeError = new double[dim];

  149.         for (int i = 0; i < dim; i++) {
  150.             rangeError[i] = derivatives[freeStateParameters + i];
  151.         }

  152.         return rangeError;
  153.     }

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

  159.     /** {@inheritDoc} */
  160.     @Override
  161.     public void modifyWithoutDerivatives(final EstimatedMeasurementBase<TurnAroundRange> estimated) {

  162.         final TurnAroundRange measurement      = estimated.getObservedMeasurement();
  163.         final GroundStation   primaryStation   = measurement.getPrimaryStation();
  164.         final GroundStation   secondaryStation = measurement.getSecondaryStation();
  165.         final SpacecraftState state            = estimated.getStates()[0];

  166.         // Update estimated value taking into account the tropospheric delay.
  167.         // The tropospheric delay is directly added to the TurnAroundRange.
  168.         final double[] newValue       = estimated.getEstimatedValue();
  169.         final double   primaryDelay   = rangeErrorTroposphericModel(primaryStation, state);
  170.         final double   secondaryDelay = rangeErrorTroposphericModel(secondaryStation, state);
  171.         newValue[0] = newValue[0] + primaryDelay + secondaryDelay;
  172.         estimated.setEstimatedValue(newValue);

  173.     }
  174.     /** {@inheritDoc} */
  175.     @Override
  176.     public void modify(final EstimatedMeasurement<TurnAroundRange> estimated) {
  177.         final TurnAroundRange measurement      = estimated.getObservedMeasurement();
  178.         final GroundStation   primaryStation   = measurement.getPrimaryStation();
  179.         final GroundStation   secondaryStation = measurement.getSecondaryStation();
  180.         final SpacecraftState state            = estimated.getStates()[0];

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

  182.         // Update estimated derivatives with Jacobian of the measure wrt state
  183.         final ModifierGradientConverter converter =
  184.                 new ModifierGradientConverter(state, 6, new FrameAlignedProvider(state.getFrame()));
  185.         final FieldSpacecraftState<Gradient> gState = converter.getState(tropoModel);
  186.         final Gradient[] gParameters = converter.getParametersAtStateDate(gState, tropoModel);
  187.         final Gradient   primaryGDelay        = rangeErrorTroposphericModel(primaryStation, gState, gParameters);
  188.         final Gradient   secondaryGDelay      = rangeErrorTroposphericModel(secondaryStation, gState, gParameters);
  189.         final double[]   primaryDerivatives   = primaryGDelay.getGradient();
  190.         final double[]   secondaryDerivatives = secondaryGDelay.getGradient();

  191.         final double[][] primaryDjac      = rangeErrorJacobianState(primaryDerivatives);
  192.         final double[][] secondaryDjac    = rangeErrorJacobianState(secondaryDerivatives);
  193.         final double[][] stateDerivatives = estimated.getStateDerivatives(0);
  194.         for (int irow = 0; irow < stateDerivatives.length; ++irow) {
  195.             for (int jcol = 0; jcol < stateDerivatives[0].length; ++jcol) {
  196.                 stateDerivatives[irow][jcol] += primaryDjac[irow][jcol] + secondaryDjac[irow][jcol];
  197.             }
  198.         }
  199.         estimated.setStateDerivatives(0, stateDerivatives);

  200.         int indexPrimary = 0;
  201.         for (final ParameterDriver driver : getParametersDrivers()) {
  202.             if (driver.isSelected()) {
  203.                 // update estimated derivatives with derivative of the modification wrt tropospheric parameters
  204.                 for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
  205.                     double parameterDerivative = estimated.getParameterDerivatives(driver, span.getStart())[0];
  206.                     final double[] derivatives = rangeErrorParameterDerivative(primaryDerivatives, converter.getFreeStateParameters());
  207.                     parameterDerivative += derivatives[indexPrimary];
  208.                     estimated.setParameterDerivatives(driver, span.getStart(), parameterDerivative);
  209.                     indexPrimary += 1;
  210.                 }
  211.             }

  212.         }

  213.         int indexSecondary = 0;
  214.         for (final ParameterDriver driver : getParametersDrivers()) {
  215.             if (driver.isSelected()) {
  216.                 // update estimated derivatives with derivative of the modification wrt tropospheric parameters
  217.                 for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
  218.                     double parameterDerivative = estimated.getParameterDerivatives(driver, span.getStart())[0];
  219.                     final double[] derivatives = rangeErrorParameterDerivative(secondaryDerivatives, converter.getFreeStateParameters());
  220.                     parameterDerivative += derivatives[indexSecondary];
  221.                     estimated.setParameterDerivatives(driver, span.getStart(), parameterDerivative);
  222.                     indexSecondary += 1;
  223.                 }
  224.             }

  225.         }

  226.         // Update derivatives with respect to primary station position
  227.         for (final ParameterDriver driver : Arrays.asList(primaryStation.getClockOffsetDriver(),
  228.                                                           primaryStation.getEastOffsetDriver(),
  229.                                                           primaryStation.getNorthOffsetDriver(),
  230.                                                           primaryStation.getZenithOffsetDriver())) {
  231.             if (driver.isSelected()) {
  232.                 for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {

  233.                     double parameterDerivative = estimated.getParameterDerivatives(driver, span.getStart())[0];
  234.                     parameterDerivative += rangeErrorParameterDerivative(primaryStation, driver, state);
  235.                     estimated.setParameterDerivatives(driver, span.getStart(), parameterDerivative);
  236.                 }
  237.             }
  238.         }

  239.         // Update derivatives with respect to secondary station position
  240.         for (final ParameterDriver driver : Arrays.asList(secondaryStation.getEastOffsetDriver(),
  241.                                                           secondaryStation.getNorthOffsetDriver(),
  242.                                                           secondaryStation.getZenithOffsetDriver())) {
  243.             if (driver.isSelected()) {
  244.                 for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {

  245.                     double parameterDerivative = estimated.getParameterDerivatives(driver, span.getStart())[0];
  246.                     parameterDerivative += rangeErrorParameterDerivative(secondaryStation, driver, state);
  247.                     estimated.setParameterDerivatives(driver, span.getStart(), parameterDerivative);
  248.                 }
  249.             }
  250.         }

  251.         // Update estimated value taking into account the tropospheric delay.
  252.         // The tropospheric delay is directly added to the TurnAroundRange.
  253.         final double[] newValue = oldValue.clone();
  254.         newValue[0] = newValue[0] + primaryGDelay.getReal() + secondaryGDelay.getReal();
  255.         estimated.setEstimatedValue(newValue);

  256.     }

  257. }