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.generation;
18  
19  import java.util.ArrayList;
20  import java.util.Collections;
21  import java.util.List;
22  
23  import org.hipparchus.random.CorrelatedRandomVectorGenerator;
24  import org.orekit.estimation.measurements.EstimationModifier;
25  import org.orekit.estimation.measurements.ObservableSatellite;
26  import org.orekit.estimation.measurements.ObservedMeasurement;
27  import org.orekit.time.AbsoluteDate;
28  
29  
30  /** Base class for {@link MeasurementBuilder measurements builders}.
31   * @param <T> the type of the measurement
32   * @author Luc Maisonobe
33   * @since 9.3
34   */
35  public abstract class AbstractMeasurementBuilder<T extends ObservedMeasurement<T>> implements MeasurementBuilder<T> {
36  
37      /** Noise source (may be null). */
38      private final CorrelatedRandomVectorGenerator noiseSource;
39  
40      /** Modifiers that apply to the measurement.*/
41      private final List<EstimationModifier<T>> modifiers;
42  
43      /** Theoretical standard deviation. */
44      private final double[] sigma;
45  
46      /** Base weight. */
47      private final double[] baseWeight;
48  
49      /** Satellites related to this measurement. */
50      private final ObservableSatellite[] satellites;
51  
52      /** Start of the measurements time span. */
53      private AbsoluteDate spanStart;
54  
55      /** End of the measurements time span. */
56      private AbsoluteDate spanEnd;
57  
58      /** Simple constructor.
59       * @param noiseSource noise source, may be null for generating perfect measurements
60       * @param sigma theoretical standard deviation
61       * @param baseWeight base weight
62       * @param satellites satellites related to this builder
63       */
64      protected AbstractMeasurementBuilder(final CorrelatedRandomVectorGenerator noiseSource,
65                                           final double sigma, final double baseWeight,
66                                           final ObservableSatellite... satellites) {
67          this(noiseSource,
68               new double[] {
69                   sigma
70               }, new double[] {
71                   baseWeight
72               }, satellites);
73      }
74  
75      /** Simple constructor.
76       * @param noiseSource noise source, may be null for generating perfect measurements
77       * @param sigma theoretical standard deviation
78       * @param baseWeight base weight
79       * @param satellites satellites related to this builder
80       */
81      protected AbstractMeasurementBuilder(final CorrelatedRandomVectorGenerator noiseSource,
82                                           final double[] sigma, final double[] baseWeight,
83                                           final ObservableSatellite... satellites) {
84          this.noiseSource = noiseSource;
85          this.modifiers   = new ArrayList<>();
86          this.sigma       = sigma.clone();
87          this.baseWeight  = baseWeight.clone();
88          this.satellites  = satellites.clone();
89      }
90  
91      /** {@inheritDoc}
92       * <p>
93       * This implementation stores the time span of the measurements generation.
94       * </p>
95       */
96      @Override
97      public void init(final AbsoluteDate start, final AbsoluteDate end) {
98          spanStart = start;
99          spanEnd   = end;
100     }
101 
102     /** {@inheritDoc} */
103     @Override
104     public void addModifier(final EstimationModifier<T> modifier) {
105         modifiers.add(modifier);
106     }
107 
108     /** {@inheritDoc} */
109     @Override
110     public List<EstimationModifier<T>> getModifiers() {
111         return Collections.unmodifiableList(modifiers);
112     }
113 
114     /** Get the start of the measurements time span.
115      * @return start of the measurements time span
116      */
117     protected AbsoluteDate getStart() {
118         return spanStart;
119     }
120 
121     /** Get the end of the measurements time span.
122      * @return end of the measurements time span
123      */
124     protected AbsoluteDate getEnd() {
125         return spanEnd;
126     }
127 
128     /** Generate a noise vector.
129      * @return noise vector (null if we generate perfect measurements)
130      */
131     protected double[] getNoise() {
132         return noiseSource == null ? null : noiseSource.nextVector();
133     }
134 
135     /** Get the theoretical standard deviation.
136      * <p>
137      * The theoretical standard deviation is a theoretical value
138      * used for normalizing the residuals. It acts as a weighting
139      * factor to mix appropriately measurements with different units
140      * and different accuracy. The value has the same dimension as
141      * the measurement itself (i.e. when a residual is divided by
142      * this value, it becomes dimensionless).
143      * </p>
144      * @return expected standard deviation
145      * @see #getBaseWeight()
146      */
147     protected double[] getTheoreticalStandardDeviation() {
148         return sigma.clone();
149     }
150 
151     /** Get the base weight associated with the measurement
152      * <p>
153      * The base weight is used on residuals already normalized thanks to
154      * {@link #getTheoreticalStandardDeviation()} to increase or
155      * decrease relative effect of some measurements with respect to
156      * other measurements. It is a dimensionless value, typically between
157      * 0 and 1 (but it can really have any non-negative value).
158      * </p>
159      * @return base weight
160      * @see #getTheoreticalStandardDeviation()
161      */
162     protected double[] getBaseWeight() {
163         return baseWeight.clone();
164     }
165 
166     /** {@inheritDoc} */
167     @Override
168     public ObservableSatellite[] getSatellites() {
169         return satellites.clone();
170     }
171 
172 }