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.sequential;
18  
19  import java.util.List;
20  
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  /**
30   * Base class for Kalman estimators.
31   * @author Romain Gerbaud
32   * @author Maxime Journot
33   * @author Luc Maisonobe
34   * @since 11.3
35   */
36  public abstract class AbstractKalmanEstimator {
37  
38      /** List of propagator builder. */
39      private final List<? extends PropagatorBuilder> builders;
40  
41      /**
42       * Constructor.
43       * @param builders list of propagator builders
44       */
45      protected AbstractKalmanEstimator(final List<? extends PropagatorBuilder> builders) {
46          this.builders = builders;
47      }
48  
49      /** Get the orbital parameters supported by this estimator.
50       * <p>
51       * If there are more than one propagator builder, then the names
52       * of the drivers have an index marker in square brackets appended
53       * to them in order to distinguish the various orbits. So for example
54       * with one builder generating Keplerian orbits the names would be
55       * simply "a", "e", "i"... but if there are several builders the
56       * names would be "a[0]", "e[0]", "i[0]"..."a[1]", "e[1]", "i[1]"...
57       * </p>
58       * @param estimatedOnly if true, only estimated parameters are returned
59       * @return orbital parameters supported by this estimator
60       */
61      public ParameterDriversList getOrbitalParametersDrivers(final boolean estimatedOnly) {
62  
63          final ParameterDriversList estimated = new ParameterDriversList();
64          for (int i = 0; i < builders.size(); ++i) {
65              final String suffix = builders.size() > 1 ? "[" + i + "]" : null;
66              for (final ParameterDriver driver : builders.get(i).getOrbitalParametersDrivers().getDrivers()) {
67                  if (driver.isSelected() || !estimatedOnly) {
68                      if (suffix != null && !driver.getName().endsWith(suffix)) {
69                          // we add suffix only conditionally because the method may already have been called
70                          // and suffixes may have already been appended
71                          driver.setName(driver.getName() + suffix);
72                      }
73                      estimated.add(driver);
74                  }
75              }
76          }
77          return estimated;
78      }
79  
80      /** Get the propagator parameters supported by this estimator.
81       * @param estimatedOnly if true, only estimated parameters are returned
82       * @return propagator parameters supported by this estimator
83       */
84      public ParameterDriversList getPropagationParametersDrivers(final boolean estimatedOnly) {
85  
86          final ParameterDriversList estimated = new ParameterDriversList();
87          for (PropagatorBuilder builder : builders) {
88              for (final DelegatingDriver delegating : builder.getPropagationParametersDrivers().getDrivers()) {
89                  if (delegating.isSelected() || !estimatedOnly) {
90                      for (final ParameterDriver driver : delegating.getRawDrivers()) {
91                          estimated.add(driver);
92                      }
93                  }
94              }
95          }
96          return estimated;
97      }
98  
99  
100     /** Get the current measurement number.
101      * @return current measurement number
102      */
103     public int getCurrentMeasurementNumber() {
104         return getKalmanEstimation().getCurrentMeasurementNumber();
105     }
106 
107     /** Get the current date.
108      * @return current date
109      */
110     public AbsoluteDate getCurrentDate() {
111         return getKalmanEstimation().getCurrentDate();
112     }
113 
114     /** Get the "physical" estimated state (i.e. not normalized)
115      * <p>
116      * For the Semi-analytical Kalman Filters
117      * it corresponds to the corrected filter correction.
118      * In other words, it doesn't represent an orbital state.
119      * </p>
120      * @return the "physical" estimated state
121      */
122     public RealVector getPhysicalEstimatedState() {
123         return getKalmanEstimation().getPhysicalEstimatedState();
124     }
125 
126     /** Get the "physical" estimated covariance matrix (i.e. not normalized)
127      * @return the "physical" estimated covariance matrix
128      */
129     public RealMatrix getPhysicalEstimatedCovarianceMatrix() {
130         return getKalmanEstimation().getPhysicalEstimatedCovarianceMatrix();
131     }
132 
133     /** Get the list of estimated measurements parameters.
134      * @return the list of estimated measurements parameters
135      */
136     public ParameterDriversList getEstimatedMeasurementsParameters() {
137         return getKalmanEstimation().getEstimatedMeasurementsParameters();
138     }
139 
140     /** Get the provider for kalman filter estimations.
141      * @return the provider for Kalman filter estimations
142      */
143     protected abstract KalmanEstimation getKalmanEstimation();
144 
145 }