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