RangeModifierUtil.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.  * 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 org.hipparchus.analysis.differentiation.Gradient;
  20. import org.orekit.estimation.measurements.EstimatedMeasurement;
  21. import org.orekit.estimation.measurements.EstimatedMeasurementBase;
  22. import org.orekit.estimation.measurements.EstimationModifier;
  23. import org.orekit.estimation.measurements.GroundStation;
  24. import org.orekit.estimation.measurements.ObservedMeasurement;
  25. import org.orekit.propagation.FieldSpacecraftState;
  26. import org.orekit.propagation.SpacecraftState;
  27. import org.orekit.propagation.integration.AbstractGradientConverter;
  28. import org.orekit.utils.Differentiation;
  29. import org.orekit.utils.ParameterDriver;
  30. import org.orekit.utils.ParameterDriversProvider;
  31. import org.orekit.utils.TimeSpanMap.Span;

  32. /** Utility class modifying theoretical range measurement.
  33.  * @author Maxime Journot
  34.  * @author Joris Olympio
  35.  * @since 11.2
  36.  */
  37. public class RangeModifierUtil {

  38.     /** Private constructor for utility class.*/
  39.     private RangeModifierUtil() {
  40.         // not used
  41.     }

  42.     /** Apply a modifier to an estimated measurement.
  43.      * @param <T> type of the measurement
  44.      * @param estimated estimated measurement to modify
  45.      * @param station ground station
  46.      * @param modelEffect model effect
  47.      * @param modifier applied modifier
  48.      * @since 12.1
  49.      */
  50.     public static <T extends ObservedMeasurement<T>> void modifyWithoutDerivatives(final EstimatedMeasurementBase<T> estimated,
  51.                                                                                    final GroundStation station,
  52.                                                                                    final ParametricModelEffect modelEffect,
  53.                                                                                    final EstimationModifier<T> modifier) {

  54.         final SpacecraftState state    = estimated.getStates()[0];
  55.         final double[]        oldValue = estimated.getEstimatedValue();

  56.         // update estimated value taking into account the delay. The delay is directly added to the range.
  57.         final double[] newValue = oldValue.clone();
  58.         final double delay = modelEffect.evaluate(station, state);
  59.         newValue[0] = newValue[0] + delay;
  60.         estimated.modifyEstimatedValue(modifier, newValue);

  61.     }

  62.     /** Apply a modifier to an estimated measurement.
  63.      * @param <T> type of the measurement
  64.      * @param estimated estimated measurement to modify
  65.      * @param station ground station
  66.      * @param converter gradient converter
  67.      * @param parametricModel parametric modifier model
  68.      * @param modelEffect model effect
  69.      * @param modelEffectGradient model effect gradient
  70.      * @param modifier applied modifier
  71.      */
  72.     public static <T extends ObservedMeasurement<T>> void modify(final EstimatedMeasurement<T> estimated,
  73.                                                                  final ParameterDriversProvider parametricModel,
  74.                                                                  final AbstractGradientConverter converter,
  75.                                                                  final GroundStation station,
  76.                                                                  final ParametricModelEffect modelEffect,
  77.                                                                  final ParametricModelEffectGradient modelEffectGradient,
  78.                                                                  final EstimationModifier<T> modifier) {

  79.         final SpacecraftState state = estimated.getStates()[0];

  80.         // update estimated derivatives with Jacobian of the measure wrt state
  81.         final FieldSpacecraftState<Gradient> gState = converter.getState(parametricModel);
  82.         final Gradient[] gParameters = converter.getParameters(gState, parametricModel);
  83.         final Gradient gDelay = modelEffectGradient.evaluate(station, gState, gParameters);
  84.         final double[] derivatives = gDelay.getGradient();

  85.         final double[][] stateDerivatives = estimated.getStateDerivatives(0);
  86.         for (int jcol = 0; jcol < stateDerivatives[0].length; ++jcol) {
  87.             stateDerivatives[0][jcol] += derivatives[jcol];
  88.         }
  89.         estimated.setStateDerivatives(0, stateDerivatives);

  90.         int index = 0;
  91.         for (final ParameterDriver driver : parametricModel.getParametersDrivers()) {
  92.             if (driver.isSelected()) {
  93.                 // update estimated derivatives with derivative of the modification wrt modifier parameters
  94.                 for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
  95.                     double parameterDerivative = estimated.getParameterDerivatives(driver, span.getStart())[0];
  96.                     parameterDerivative += derivatives[index + converter.getFreeStateParameters()];
  97.                     estimated.setParameterDerivatives(driver, span.getStart(), parameterDerivative);
  98.                     index = index + 1;
  99.                 }
  100.             }

  101.         }

  102.         for (final ParameterDriver driver : Arrays.asList(station.getClockOffsetDriver(),
  103.                                                           station.getEastOffsetDriver(),
  104.                                                           station.getNorthOffsetDriver(),
  105.                                                           station.getZenithOffsetDriver())) {
  106.             if (driver.isSelected()) {
  107.                 // update estimated derivatives with derivative of the modification wrt station parameters
  108.                 for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
  109.                     double parameterDerivative = estimated.getParameterDerivatives(driver, span.getStart())[0];
  110.                     parameterDerivative += Differentiation.differentiate((d, t) -> modelEffect.evaluate(station, state),
  111.                                                                      3, 10.0 * driver.getScale()).value(driver, state.getDate());
  112.                     estimated.setParameterDerivatives(driver, span.getStart(), parameterDerivative);
  113.                 }
  114.             }
  115.         }

  116.         // update estimated value taking into account the delay
  117.         modifyWithoutDerivatives(estimated, station, modelEffect, modifier);

  118.     }

  119. }