1   /* Copyright 2022-2026 Romain Serra
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;
18  
19  import java.util.Arrays;
20  
21  import org.orekit.propagation.conversion.PropagatorBuilder;
22  import org.orekit.utils.ParameterDriversList;
23  
24  /**
25   * Interface for parameter estimation.
26   * @author Luc Maisonobe
27   * @author Romain Serra
28   * @since 14.0
29   */
30  public interface ParameterEstimator {
31  
32      /**
33       * Getter for the propagator builders.
34       * @return builders
35       */
36      PropagatorBuilder[] getPropagatorBuilders();
37  
38      /** Get the orbital parameters supported by this estimator.
39       * <p>
40       * If there are more than one propagator builder, then the names
41       * of the drivers have an index marker in square brackets appended
42       * to them in order to distinguish the various orbits. So for example
43       * with one builder generating Keplerian orbits the names would be
44       * simply "a", "e", "i"... but if there are several builders the
45       * names would be "a[0]", "e[0]", "i[0]"..."a[1]", "e[1]", "i[1]"...
46       * </p>
47       * @param estimatedOnly if true, only estimated parameters are returned
48       * @return orbital parameters supported by this estimator
49       */
50      default ParameterDriversList getOrbitalParametersDrivers(final boolean estimatedOnly) {
51          final ParameterDriversList estimated = new ParameterDriversList();
52          final PropagatorBuilder[] propagatorBuilders = getPropagatorBuilders();
53          for (int i = 0; i < propagatorBuilders.length; ++i) {
54              final String suffix = propagatorBuilders.length > 1 ? "[" + i + "]" : null;
55              propagatorBuilders[i].getOrbitalParametersDrivers().getDrivers().stream()
56                      .filter(delegatingDriver -> delegatingDriver.isSelected() || !estimatedOnly)
57                      .forEach(delegatingDriver -> {
58                          if (suffix != null && !delegatingDriver.getName().endsWith(suffix)) {
59                              // we add suffix only conditionally because the method may already have been called
60                              // and suffixes may have already been appended
61                              delegatingDriver.setName(delegatingDriver.getName() + suffix);
62                          }
63                          estimated.add(delegatingDriver);
64                      });
65          }
66          return estimated;
67      }
68  
69      /** Get the propagation parameters supported by this estimator.
70       * @param estimatedOnly if true, only estimated parameters are returned
71       * @return propagation parameters supported by this estimator
72       */
73      default ParameterDriversList getPropagationParametersDrivers(final boolean estimatedOnly) {
74          final ParameterDriversList estimated = new ParameterDriversList();
75          Arrays.stream(getPropagatorBuilders())
76                  .flatMap(propagatorBuilder -> propagatorBuilder.getPropagationParametersDrivers().getDrivers().stream())
77                  .filter(delegatingDriver -> delegatingDriver.isSelected() || !estimatedOnly)
78                  .flatMap(delegatingDriver -> delegatingDriver.getRawDrivers().stream())
79                  .forEach(estimated::add);
80          return estimated;
81      }
82  }