AbstractKalmanEstimator.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.filtering.kalman.KalmanFilter;
  20. import org.hipparchus.linear.MatrixDecomposer;
  21. import org.hipparchus.linear.RealMatrix;
  22. import org.hipparchus.linear.RealVector;
  23. import org.orekit.propagation.conversion.PropagatorBuilder;
  24. import org.orekit.time.AbsoluteDate;
  25. import org.orekit.utils.ParameterDriver;
  26. import org.orekit.utils.ParameterDriversList;
  27. import org.orekit.utils.ParameterDriversList.DelegatingDriver;

  28. /**
  29.  * Base class for Kalman estimators.
  30.  * @author Romain Gerbaud
  31.  * @author Maxime Journot
  32.  * @author Luc Maisonobe
  33.  * @since 11.3
  34.  */
  35. public abstract class AbstractKalmanEstimator {

  36.     /** List of propagator builder. */
  37.     private final List<? extends PropagatorBuilder> builders;

  38.     /** Reference date. */
  39.     private final AbsoluteDate referenceDate;

  40.     /** Observer to retrieve current estimation info. */
  41.     private KalmanObserver observer;

  42.     /** Matrix decomposer for filter. */
  43.     private final MatrixDecomposer decomposer;

  44.     /**
  45.      * Constructor.
  46.      * @param decomposer matrix decomposer for filter
  47.      * @param builders list of propagator builders
  48.      */
  49.     protected AbstractKalmanEstimator(final MatrixDecomposer decomposer,
  50.                                       final List<? extends PropagatorBuilder> builders) {
  51.         this.builders = builders;
  52.         this.referenceDate = builders.get(0).getInitialOrbitDate();
  53.         this.decomposer = decomposer;
  54.         this.observer = null;
  55.     }

  56.     /** Get the orbital parameters supported by this estimator.
  57.      * <p>
  58.      * If there are more than one propagator builder, then the names
  59.      * of the drivers have an index marker in square brackets appended
  60.      * to them in order to distinguish the various orbits. So for example
  61.      * with one builder generating Keplerian orbits the names would be
  62.      * simply "a", "e", "i"... but if there are several builders the
  63.      * names would be "a[0]", "e[0]", "i[0]"..."a[1]", "e[1]", "i[1]"...
  64.      * </p>
  65.      * @param estimatedOnly if true, only estimated parameters are returned
  66.      * @return orbital parameters supported by this estimator
  67.      */
  68.     public ParameterDriversList getOrbitalParametersDrivers(final boolean estimatedOnly) {

  69.         final ParameterDriversList estimated = new ParameterDriversList();
  70.         for (int i = 0; i < builders.size(); ++i) {
  71.             final String suffix = builders.size() > 1 ? "[" + i + "]" : null;
  72.             for (final ParameterDriver driver : builders.get(i).getOrbitalParametersDrivers().getDrivers()) {
  73.                 if (driver.isSelected() || !estimatedOnly) {
  74.                     if (suffix != null && !driver.getName().endsWith(suffix)) {
  75.                         // we add suffix only conditionally because the method may already have been called
  76.                         // and suffixes may have already been appended
  77.                         driver.setName(driver.getName() + suffix);
  78.                     }
  79.                     estimated.add(driver);
  80.                 }
  81.             }
  82.         }
  83.         return estimated;
  84.     }

  85.     /** Get the propagator parameters supported by this estimator.
  86.      * @param estimatedOnly if true, only estimated parameters are returned
  87.      * @return propagator parameters supported by this estimator
  88.      */
  89.     public ParameterDriversList getPropagationParametersDrivers(final boolean estimatedOnly) {

  90.         final ParameterDriversList estimated = new ParameterDriversList();
  91.         for (PropagatorBuilder builder : builders) {
  92.             for (final DelegatingDriver delegating : builder.getPropagationParametersDrivers().getDrivers()) {
  93.                 if (delegating.isSelected() || !estimatedOnly) {
  94.                     for (final ParameterDriver driver : delegating.getRawDrivers()) {
  95.                         estimated.add(driver);
  96.                     }
  97.                 }
  98.             }
  99.         }
  100.         return estimated;
  101.     }


  102.     /** Get the current measurement number.
  103.      * @return current measurement number
  104.      */
  105.     public int getCurrentMeasurementNumber() {
  106.         return getKalmanEstimation().getCurrentMeasurementNumber();
  107.     }

  108.     /** Get the current date.
  109.      * @return current date
  110.      */
  111.     public AbsoluteDate getCurrentDate() {
  112.         return getKalmanEstimation().getCurrentDate();
  113.     }

  114.     /** Set the observer.
  115.      * @param observer the observer
  116.      */
  117.     public void setObserver(final KalmanObserver observer) {
  118.         this.observer = observer;
  119.         observer.init(getKalmanEstimation());
  120.     }

  121.     /** Get the observer.
  122.      * @return the observer
  123.      */
  124.     public KalmanObserver getObserver() {
  125.         return observer;
  126.     }

  127.     /** Get the "physical" estimated state (i.e. not normalized)
  128.      * <p>
  129.      * For the Semi-analytical Kalman Filters
  130.      * it corresponds to the corrected filter correction.
  131.      * In other words, it doesn't represent an orbital state.
  132.      * </p>
  133.      * @return the "physical" estimated state
  134.      */
  135.     public RealVector getPhysicalEstimatedState() {
  136.         return getKalmanEstimation().getPhysicalEstimatedState();
  137.     }

  138.     /** Get the "physical" estimated covariance matrix (i.e. not normalized)
  139.      * @return the "physical" estimated covariance matrix
  140.      */
  141.     public RealMatrix getPhysicalEstimatedCovarianceMatrix() {
  142.         return getKalmanEstimation().getPhysicalEstimatedCovarianceMatrix();
  143.     }

  144.     /** Get the list of estimated measurements parameters.
  145.      * @return the list of estimated measurements parameters
  146.      */
  147.     public ParameterDriversList getEstimatedMeasurementsParameters() {
  148.         return getKalmanEstimation().getEstimatedMeasurementsParameters();
  149.     }

  150.     protected List<? extends PropagatorBuilder> getBuilders() {
  151.         return builders;
  152.     }

  153.     /** Get the provider for kalman filter estimations.
  154.      * @return the provider for Kalman filter estimations
  155.      */
  156.     protected abstract KalmanEstimation getKalmanEstimation();

  157.     /** Get the matrix decomposer.
  158.      * @return the decomposer
  159.      */
  160.     protected MatrixDecomposer getMatrixDecomposer() {
  161.         return decomposer;
  162.     }

  163.     /** Get the reference date.
  164.      * @return the date
  165.      */
  166.     protected AbsoluteDate getReferenceDate() {
  167.         return referenceDate;
  168.     }

  169.     /** Get the Hipparchus filter.
  170.      * @return the filter
  171.      */
  172.     protected abstract KalmanFilter<MeasurementDecorator> getKalmanFilter();

  173.     /** Get the parameter scaling factors.
  174.      * @return the parameters scale
  175.      */
  176.     protected abstract double[] getScale();

  177. }