1   /* Copyright 2002-2024 Bryan Cazabonne
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    * Bryan Cazabonne 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.Map;
20  
21  import org.hipparchus.random.CorrelatedRandomVectorGenerator;
22  import org.orekit.estimation.measurements.EstimationModifier;
23  import org.orekit.estimation.measurements.FDOA;
24  import org.orekit.estimation.measurements.GroundStation;
25  import org.orekit.estimation.measurements.ObservableSatellite;
26  import org.orekit.propagation.SpacecraftState;
27  import org.orekit.propagation.sampling.OrekitStepInterpolator;
28  import org.orekit.time.AbsoluteDate;
29  import org.orekit.utils.ParameterDriver;
30  
31  /** Builder for {@link FDOA} measurements.
32   * @author Bryan Cazabonne
33   * @since 12.0
34   */
35  public class FDOABuilder extends AbstractMeasurementBuilder<FDOA> {
36  
37      /** Prime ground station. */
38      private final GroundStation primeStation;
39  
40      /** Second ground station. */
41      private final GroundStation secondStation;
42  
43      /** Centre frequency of the signal emitted from the satellite. */
44      private final double centreFrequency;
45  
46      /** Satellite related to this builder. */
47      private final ObservableSatellite satellite;
48  
49      /** Simple constructor.
50       * @param noiseSource noise source, may be null for generating perfect measurements
51       * @param primeStation ground station that gives the date of the measurement
52       * @param secondStation ground station that gives the measurement
53       * @param centreFrequency satellite emitter frequency
54       * @param sigma theoretical standard deviation
55       * @param baseWeight base weight
56       * @param satellite satellite related to this builder
57       */
58      public FDOABuilder(final CorrelatedRandomVectorGenerator noiseSource,
59                         final GroundStation primeStation,
60                         final GroundStation secondStation,
61                         final double centreFrequency,
62                         final double sigma, final double baseWeight,
63                         final ObservableSatellite satellite) {
64          super(noiseSource, sigma, baseWeight, satellite);
65          this.primeStation    = primeStation;
66          this.secondStation   = secondStation;
67          this.centreFrequency = centreFrequency;
68          this.satellite       = satellite;
69      }
70  
71      /** {@inheritDoc} */
72      @Override
73      public FDOA build(final AbsoluteDate date, final Map<ObservableSatellite, OrekitStepInterpolator> interpolators) {
74  
75          final double sigma                  = getTheoreticalStandardDeviation()[0];
76          final double baseWeight             = getBaseWeight()[0];
77          final SpacecraftState[] relevant    = new SpacecraftState[] { interpolators.get(satellite).getInterpolatedState(date) };
78  
79          // create a dummy measurement
80          final FDOA dummy = new FDOA(primeStation, secondStation, centreFrequency, relevant[0].getDate(),
81                                      Double.NaN, sigma, baseWeight, satellite);
82          for (final EstimationModifier<FDOA> modifier : getModifiers()) {
83              dummy.addModifier(modifier);
84          }
85  
86          // set a reference date for parameters missing one
87          for (final ParameterDriver driver : dummy.getParametersDrivers()) {
88              if (driver.getReferenceDate() == null) {
89                  final AbsoluteDate start = getStart();
90                  final AbsoluteDate end   = getEnd();
91                  driver.setReferenceDate(start.durationFrom(end) <= 0 ? start : end);
92              }
93          }
94  
95          // estimate the perfect value of the measurement
96          double fdoa = dummy.estimateWithoutDerivatives(relevant).getEstimatedValue()[0];
97  
98          // add the noise
99          final double[] noise = getNoise();
100         if (noise != null) {
101             fdoa += noise[0];
102         }
103 
104         // generate measurement
105         final FDOA measurement = new FDOA(primeStation, secondStation, centreFrequency, relevant[0].getDate(),
106                                           fdoa, sigma, baseWeight, satellite);
107         for (final EstimationModifier<FDOA> modifier : getModifiers()) {
108             measurement.addModifier(modifier);
109         }
110         return measurement;
111 
112     }
113 
114 }