RangeRateModifierUtil.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-rate measurement.
  33.  * @author Joris Olympio
  34.  * @since 11.2
  35.  */
  36. public class RangeRateModifierUtil {

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

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

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

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

  59.     }

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

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

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

  84.         // update estimated derivatives with Jacobian of the measure wrt state
  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.                 for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {

  94.                     // update estimated derivatives with derivative of the modification wrt modifier parameters
  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.                 for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {

  108.                     // update estimated derivatives with derivative of the modification wrt station parameters
  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. }