RangeRateModifierUtil.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 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.      * @deprecated as of 12.1, replaced by {@link #modifyWithoutDerivatives(EstimatedMeasurementBase,
  47.      * GroundStation, ParametricModelEffect, EstimationModifier)}
  48.      */
  49.     @Deprecated
  50.     public static <T extends ObservedMeasurement<T>> void modifyWithoutDerivatives(final EstimatedMeasurementBase<T> estimated,
  51.                                                                                    final GroundStation station,
  52.                                                                                    final ParametricModelEffect modelEffect) {
  53.         modifyWithoutDerivatives(estimated, station, modelEffect, null);
  54.     }

  55.     /** Apply a modifier to an estimated measurement.
  56.      * @param <T> type of the measurement
  57.      * @param estimated estimated measurement to modify
  58.      * @param station ground station
  59.      * @param modelEffect model effect
  60.      * @param modifier applied modifier
  61.      * @since 12.1
  62.      */
  63.     public static <T extends ObservedMeasurement<T>> void modifyWithoutDerivatives(final EstimatedMeasurementBase<T> estimated,
  64.                                                                                    final GroundStation station,
  65.                                                                                    final ParametricModelEffect modelEffect,
  66.                                                                                    final EstimationModifier<T> modifier) {

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

  68.         // update estimated value taking into account the ionospheric delay.
  69.         // The ionospheric delay is directly added to the range.
  70.         final double[] newValue = estimated.getEstimatedValue();
  71.         final double delay = modelEffect.evaluate(station, state);
  72.         newValue[0] = newValue[0] + delay;
  73.         estimated.modifyEstimatedValue(modifier, newValue);

  74.     }

  75.     /** Apply a modifier to an estimated measurement.
  76.      * @param <T> type of the measurement
  77.      * @param estimated estimated measurement to modify
  78.      * @param station ground station
  79.      * @param converter gradient converter
  80.      * @param parametricModel parametric modifier model
  81.      * @param modelEffect model effect
  82.      * @param modelEffectGradient model effect gradient
  83.      * @deprecated as of 12.1, replaced by {@link #modify(EstimatedMeasurement,
  84.      * ParameterDriversProvider, AbstractGradientConverter, GroundStation,
  85.      * ParametricModelEffect, ParametricModelEffectGradient, EstimationModifier)}
  86.      */
  87.     @Deprecated
  88.     public static <T extends ObservedMeasurement<T>> void modify(final EstimatedMeasurement<T> estimated,
  89.                                                                  final ParameterDriversProvider parametricModel,
  90.                                                                  final AbstractGradientConverter converter,
  91.                                                                  final GroundStation station,
  92.                                                                  final ParametricModelEffect modelEffect,
  93.                                                                  final ParametricModelEffectGradient modelEffectGradient) {
  94.         modify(estimated, parametricModel, converter, station,
  95.                modelEffect, modelEffectGradient, null);

  96.     }

  97.     /** Apply a modifier to an estimated measurement.
  98.      * @param <T> type of the measurement
  99.      * @param estimated estimated measurement to modify
  100.      * @param station ground station
  101.      * @param converter gradient converter
  102.      * @param parametricModel parametric modifier model
  103.      * @param modelEffect model effect
  104.      * @param modelEffectGradient model effect gradient
  105.      * @param modifier applied modifier
  106.      * @since 12.1
  107.      */
  108.     public static <T extends ObservedMeasurement<T>> void modify(final EstimatedMeasurement<T> estimated,
  109.                                                                  final ParameterDriversProvider parametricModel,
  110.                                                                  final AbstractGradientConverter converter,
  111.                                                                  final GroundStation station,
  112.                                                                  final ParametricModelEffect modelEffect,
  113.                                                                  final ParametricModelEffectGradient modelEffectGradient,
  114.                                                                  final EstimationModifier<T> modifier) {

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

  116.         // update estimated derivatives with Jacobian of the measure wrt state
  117.         final FieldSpacecraftState<Gradient> gState = converter.getState(parametricModel);
  118.         final Gradient[] gParameters = converter.getParameters(gState, parametricModel);
  119.         final Gradient gDelay = modelEffectGradient.evaluate(station, gState, gParameters);
  120.         final double[] derivatives = gDelay.getGradient();

  121.         // update estimated derivatives with Jacobian of the measure wrt state
  122.         final double[][] stateDerivatives = estimated.getStateDerivatives(0);
  123.         for (int jcol = 0; jcol < stateDerivatives[0].length; ++jcol) {
  124.             stateDerivatives[0][jcol] += derivatives[jcol];
  125.         }
  126.         estimated.setStateDerivatives(0, stateDerivatives);

  127.         int index = 0;
  128.         for (final ParameterDriver driver : parametricModel.getParametersDrivers()) {
  129.             if (driver.isSelected()) {
  130.                 for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {

  131.                     // update estimated derivatives with derivative of the modification wrt ionospheric parameters
  132.                     double parameterDerivative = estimated.getParameterDerivatives(driver, span.getStart())[0];
  133.                     parameterDerivative += derivatives[index + converter.getFreeStateParameters()];
  134.                     estimated.setParameterDerivatives(driver, span.getStart(), parameterDerivative);
  135.                     index = index + 1;
  136.                 }
  137.             }

  138.         }

  139.         for (final ParameterDriver driver : Arrays.asList(station.getClockOffsetDriver(),
  140.                                                           station.getEastOffsetDriver(),
  141.                                                           station.getNorthOffsetDriver(),
  142.                                                           station.getZenithOffsetDriver())) {
  143.             if (driver.isSelected()) {
  144.                 for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {

  145.                     // update estimated derivatives with derivative of the modification wrt station parameters
  146.                     double parameterDerivative = estimated.getParameterDerivatives(driver, span.getStart())[0];
  147.                     parameterDerivative += Differentiation.differentiate((d, t) -> modelEffect.evaluate(station, state),
  148.                                                                          3, 10.0 * driver.getScale()).value(driver, state.getDate());
  149.                     estimated.setParameterDerivatives(driver, span.getStart(), parameterDerivative);
  150.                 }
  151.             }
  152.         }

  153.         // update estimated value taking into account the ionospheric delay.
  154.         modifyWithoutDerivatives(estimated, station, modelEffect, modifier);

  155.     }

  156. }