SemiAnalyticalMeasurementHandler.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.sequential;

  18. import java.util.List;

  19. import org.hipparchus.exception.MathRuntimeException;
  20. import org.hipparchus.filtering.kalman.KalmanFilter;
  21. import org.hipparchus.filtering.kalman.ProcessEstimate;
  22. import org.orekit.errors.OrekitException;
  23. import org.orekit.estimation.measurements.ObservedMeasurement;
  24. import org.orekit.propagation.SpacecraftState;
  25. import org.orekit.propagation.sampling.OrekitStepHandler;
  26. import org.orekit.propagation.sampling.OrekitStepInterpolator;
  27. import org.orekit.time.AbsoluteDate;

  28. /** {@link org.orekit.propagation.sampling.OrekitStepHandler Step handler} picking up
  29.  * {@link ObservedMeasurement measurements} for both {@link SemiAnalyticalUnscentedKalmanEstimator} and {@link SemiAnalyticalKalmanEstimator}.
  30.  * @author GaĆ«tan Pierre
  31.  * @author Bryan Cazabonne
  32.  * @author Julie Bayard
  33.  * @author Maxime Journot
  34.  * @since 11.3
  35.  */
  36. public class SemiAnalyticalMeasurementHandler implements OrekitStepHandler {

  37.     /** Index of the next measurement component in the model. */
  38.     private int index;

  39.     /** Reference date. */
  40.     private AbsoluteDate referenceDate;

  41.     /** Kalman model. */
  42.     private final SemiAnalyticalProcess model;

  43.     /** Kalman Filter. */
  44.     private final KalmanFilter<MeasurementDecorator> filter;

  45.     /** Underlying measurements. */
  46.     private final List<ObservedMeasurement<?>> observedMeasurements;

  47.     /** Flag indicating if the handler is used by a unscented kalman filter. */
  48.     private final boolean isUnscented;

  49.     /** Simple constructor.
  50.      * <p>
  51.      * Using this constructor, the Kalman filter is supposed to be extended.
  52.      * </p>
  53.      * @param model semi-analytical kalman model
  54.      * @param filter kalman filter instance
  55.      * @param observedMeasurements list of observed measurements
  56.      * @param referenceDate reference date
  57.      * @see #SemiAnalyticalMeasurementHandler(SemiAnalyticalProcess, KalmanFilter, List, AbsoluteDate, boolean)
  58.      */
  59.     public SemiAnalyticalMeasurementHandler(final SemiAnalyticalProcess model,
  60.                                   final KalmanFilter<MeasurementDecorator> filter,
  61.                                   final List<ObservedMeasurement<?>> observedMeasurements,
  62.                                   final AbsoluteDate referenceDate) {
  63.         this(model, filter, observedMeasurements, referenceDate, false);
  64.     }

  65.     /** Simple constructor.
  66.      * @param model semi-analytical kalman model
  67.      * @param filter kalman filter instance
  68.      * @param observedMeasurements list of observed measurements
  69.      * @param referenceDate reference date
  70.      * @param isUnscented true if the Kalman filter is unscented
  71.      * @since 11.3.2
  72.      */
  73.     public SemiAnalyticalMeasurementHandler(final SemiAnalyticalProcess model,
  74.                                   final KalmanFilter<MeasurementDecorator> filter,
  75.                                   final List<ObservedMeasurement<?>> observedMeasurements,
  76.                                   final AbsoluteDate referenceDate,
  77.                                   final boolean isUnscented) {
  78.         this.model                = model;
  79.         this.filter               = filter;
  80.         this.observedMeasurements = observedMeasurements;
  81.         this.referenceDate        = referenceDate;
  82.         this.isUnscented          = isUnscented;
  83.     }

  84.     /** {@inheritDoc} */
  85.     @Override
  86.     public void init(final SpacecraftState s0, final AbsoluteDate t) {
  87.         this.index = 0;
  88.         // Initialize short periodic terms.
  89.         model.initializeShortPeriodicTerms(s0);
  90.         model.updateShortPeriods(s0);
  91.     }

  92.     /** {@inheritDoc} */
  93.     @Override
  94.     public void handleStep(final OrekitStepInterpolator interpolator) {

  95.         // Current date
  96.         final AbsoluteDate currentDate = interpolator.getCurrentState().getDate();

  97.         // Update the short period terms with the current MEAN state
  98.         model.updateShortPeriods(interpolator.getCurrentState());

  99.         // Process the measurements between previous step and current step
  100.         while (index < observedMeasurements.size() && observedMeasurements.get(index).getDate().compareTo(currentDate) < 0) {

  101.             try {

  102.                 // Update predicted spacecraft state
  103.                 model.updateNominalSpacecraftState(interpolator.getInterpolatedState(observedMeasurements.get(index).getDate()));

  104.                 // Process the current observation
  105.                 final MeasurementDecorator decorated = isUnscented ?
  106.                         KalmanEstimatorUtil.decorateUnscented(observedMeasurements.get(index), referenceDate) :
  107.                             KalmanEstimatorUtil.decorate(observedMeasurements.get(index), referenceDate);
  108.                 final ProcessEstimate estimate = filter.estimationStep(decorated);

  109.                 // Finalize the estimation
  110.                 model.finalizeEstimation(observedMeasurements.get(index), estimate);

  111.             } catch (MathRuntimeException mrte) {
  112.                 throw new OrekitException(mrte);
  113.             }

  114.             // Increment the measurement index
  115.             index += 1;

  116.         }

  117.         // Reset the initial state of the propagator
  118.         model.finalizeOperationsObservationGrid();

  119.     }

  120. }