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.gnss;
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.GroundStation;
24  import org.orekit.estimation.measurements.ObservableSatellite;
25  import org.orekit.estimation.measurements.generation.AbstractMeasurementBuilder;
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  
32  /** Builder for {@link Phase} measurements.
33   * @author Luc Maisonobe
34   * @since 10.1
35   */
36  public class PhaseBuilder extends AbstractMeasurementBuilder<Phase> {
37  
38      /** Cache for ambiguities.
39       * @since 12.1
40       */
41      private final AmbiguityCache cache;
42  
43      /** Ground station from which measurement is performed. */
44      private final GroundStation station;
45  
46      /** Wavelength of the phase observed value [m]. */
47      private final double wavelength;
48  
49      /** Satellite related to this builder.
50       * @since 12.0
51       */
52      private final ObservableSatellite satellite;
53  
54      /** Simple constructor.
55       * @param noiseSource noise source, may be null for generating perfect measurements
56       * @param station ground station from which measurement is performed
57       * @param wavelength phase observed value wavelength (m)
58       * @param sigma theoretical standard deviation
59       * @param baseWeight base weight
60       * @param satellite satellite related to this builder
61       * @deprecated as of 12.1, replaced by {@link #PhaseBuilder(CorrelatedRandomVectorGenerator,
62       * GroundStation, double, double, double, ObservableSatellite,
63       * AmbiguityCache)}
64       */
65      @Deprecated
66      public PhaseBuilder(final CorrelatedRandomVectorGenerator noiseSource,
67                          final GroundStation station, final double wavelength,
68                          final double sigma, final double baseWeight,
69                          final ObservableSatellite satellite) {
70          this(noiseSource, station, wavelength, sigma, baseWeight, satellite,
71               AmbiguityCache.DEFAULT_CACHE);
72      }
73  
74      /** Simple constructor.
75       * @param noiseSource noise source, may be null for generating perfect measurements
76       * @param station ground station from which measurement is performed
77       * @param wavelength phase observed value wavelength (m)
78       * @param sigma theoretical standard deviation
79       * @param baseWeight base weight
80       * @param satellite satellite related to this builder
81       * @param cache from which ambiguity drive should come
82       * @since 12.1
83       */
84      public PhaseBuilder(final CorrelatedRandomVectorGenerator noiseSource,
85                          final GroundStation station, final double wavelength,
86                          final double sigma, final double baseWeight,
87                          final ObservableSatellite satellite,
88                          final AmbiguityCache cache) {
89          super(noiseSource, sigma, baseWeight, satellite);
90          this.station    = station;
91          this.wavelength = wavelength;
92          this.satellite  = satellite;
93          this.cache      = cache;
94      }
95  
96      /** {@inheritDoc} */
97      @Override
98      public Phase build(final AbsoluteDate date, final Map<ObservableSatellite, OrekitStepInterpolator> interpolators) {
99  
100         final double sigma                  = getTheoreticalStandardDeviation()[0];
101         final double baseWeight             = getBaseWeight()[0];
102         final SpacecraftState[] relevant    = new SpacecraftState[] { interpolators.get(satellite).getInterpolatedState(date) };
103 
104         // create a dummy measurement
105         final Phase dummy = new Phase(station, relevant[0].getDate(), Double.NaN, wavelength,
106                                       sigma, baseWeight, satellite, cache);
107         for (final EstimationModifier<Phase> modifier : getModifiers()) {
108             dummy.addModifier(modifier);
109         }
110 
111         // set a reference date for parameters missing one
112         for (final ParameterDriver driver : dummy.getParametersDrivers()) {
113             if (driver.getReferenceDate() == null) {
114                 final AbsoluteDate start = getStart();
115                 final AbsoluteDate end   = getEnd();
116                 driver.setReferenceDate(start.durationFrom(end) <= 0 ? start : end);
117             }
118         }
119 
120         // estimate the perfect value of the measurement
121         double phase = dummy.estimateWithoutDerivatives(relevant).getEstimatedValue()[0];
122 
123         // add the noise
124         final double[] noise = getNoise();
125         if (noise != null) {
126             phase += noise[0];
127         }
128 
129         // generate measurement
130         final Phase measurement = new Phase(station, relevant[0].getDate(), phase, wavelength,
131                                             sigma, baseWeight, satellite, cache);
132         for (final EstimationModifier<Phase> modifier : getModifiers()) {
133             measurement.addModifier(modifier);
134         }
135         return measurement;
136 
137     }
138 
139 }