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

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

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

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

  77.     }

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

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

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

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

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