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.GroundStation;
  23. import org.orekit.estimation.measurements.ObservedMeasurement;
  24. import org.orekit.propagation.FieldSpacecraftState;
  25. import org.orekit.propagation.SpacecraftState;
  26. import org.orekit.propagation.integration.AbstractGradientConverter;
  27. import org.orekit.utils.Differentiation;
  28. import org.orekit.utils.ParameterDriver;
  29. import org.orekit.utils.ParameterDriversProvider;
  30. import org.orekit.utils.TimeSpanMap.Span;

  31. /** Utility class modifying theoretical range-rate measurement.
  32.  * @author Joris Olympio
  33.  * @since 11.2
  34.  */
  35. public class RangeRateModifierUtil {

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

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

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

  50.         // update estimated value taking into account the ionospheric delay.
  51.         // The ionospheric delay is directly added to the range.
  52.         final double[] newValue = estimated.getEstimatedValue();
  53.         final double delay = modelEffect.evaluate(station, state);
  54.         newValue[0] = newValue[0] + delay;
  55.         estimated.setEstimatedValue(newValue);

  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 converter gradient converter
  62.      * @param parametricModel parametric modifier model
  63.      * @param modelEffect model effect
  64.      * @param modelEffectGradient model effect gradient
  65.      */
  66.     public static <T extends ObservedMeasurement<T>> void modify(final EstimatedMeasurement<T> estimated,
  67.                                                                  final ParameterDriversProvider parametricModel,
  68.                                                                  final AbstractGradientConverter converter,
  69.                                                                  final GroundStation station,
  70.                                                                  final ParametricModelEffect modelEffect,
  71.                                                                  final ParametricModelEffectGradient modelEffectGradient) {

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

  73.         // update estimated derivatives with Jacobian of the measure wrt state
  74.         final FieldSpacecraftState<Gradient> gState = converter.getState(parametricModel);
  75.         final Gradient[] gParameters = converter.getParameters(gState, parametricModel);
  76.         final Gradient gDelay = modelEffectGradient.evaluate(station, gState, gParameters);
  77.         final double[] derivatives = gDelay.getGradient();

  78.         // update estimated derivatives with Jacobian of the measure wrt state
  79.         final double[][] stateDerivatives = estimated.getStateDerivatives(0);
  80.         for (int jcol = 0; jcol < stateDerivatives[0].length; ++jcol) {
  81.             stateDerivatives[0][jcol] += derivatives[jcol];
  82.         }
  83.         estimated.setStateDerivatives(0, stateDerivatives);

  84.         int index = 0;
  85.         for (final ParameterDriver driver : parametricModel.getParametersDrivers()) {
  86.             if (driver.isSelected()) {
  87.                 for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {

  88.                     // update estimated derivatives with derivative of the modification wrt ionospheric parameters
  89.                     double parameterDerivative = estimated.getParameterDerivatives(driver, span.getStart())[0];
  90.                     parameterDerivative += derivatives[index + converter.getFreeStateParameters()];
  91.                     estimated.setParameterDerivatives(driver, span.getStart(), parameterDerivative);
  92.                     index = index + 1;
  93.                 }
  94.             }

  95.         }

  96.         for (final ParameterDriver driver : Arrays.asList(station.getClockOffsetDriver(),
  97.                                                           station.getEastOffsetDriver(),
  98.                                                           station.getNorthOffsetDriver(),
  99.                                                           station.getZenithOffsetDriver())) {
  100.             if (driver.isSelected()) {
  101.                 for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {

  102.                     // update estimated derivatives with derivative of the modification wrt station parameters
  103.                     double parameterDerivative = estimated.getParameterDerivatives(driver, span.getStart())[0];
  104.                     parameterDerivative += Differentiation.differentiate((d, t) -> modelEffect.evaluate(station, state),
  105.                                                                          3, 10.0 * driver.getScale()).value(driver, state.getDate());
  106.                     estimated.setParameterDerivatives(driver, span.getStart(), parameterDerivative);
  107.                 }
  108.             }
  109.         }

  110.         // update estimated value taking into account the ionospheric delay.
  111.         modifyWithoutDerivatives(estimated, station, modelEffect);

  112.     }

  113. }