1   /* Copyright 2002-2025 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.modifiers;
18  
19  import java.util.List;
20  
21  import org.hipparchus.stat.descriptive.DescriptiveStatistics;
22  import org.junit.jupiter.api.Assertions;
23  import org.junit.jupiter.api.Test;
24  import org.orekit.estimation.Context;
25  import org.orekit.estimation.EstimationTestUtils;
26  import org.orekit.estimation.measurements.EstimatedMeasurementBase;
27  import org.orekit.estimation.measurements.EstimationModifier;
28  import org.orekit.estimation.measurements.GroundStation;
29  import org.orekit.estimation.measurements.ObservedMeasurement;
30  import org.orekit.estimation.measurements.gnss.Phase;
31  import org.orekit.estimation.measurements.gnss.PhaseMeasurementCreator;
32  import org.orekit.gnss.PredefinedGnssSignal;
33  import org.orekit.gnss.RadioWave;
34  import org.orekit.orbits.OrbitType;
35  import org.orekit.orbits.PositionAngleType;
36  import org.orekit.propagation.Propagator;
37  import org.orekit.propagation.SpacecraftState;
38  import org.orekit.propagation.conversion.NumericalPropagatorBuilder;
39  import org.orekit.time.AbsoluteDate;
40  
41  public class ShapiroPhaseModifierTest {
42  
43      /** Radio wave of the measurements. */
44      private static final RadioWave RADIO_WAVE = PredefinedGnssSignal.G01;
45  
46      @Test
47      public void testShapiro() {
48          doTestShapiro(0.006850703, 0.008320738, 0.010297509);
49      }
50  
51      private void doTestShapiro(final double expectedMin, final double expectedMean, final double expectedMax) {
52  
53          Context context = EstimationTestUtils.eccentricContext("regular-data:potential:tides");
54  
55          final NumericalPropagatorBuilder propagatorBuilder =
56                          context.createBuilder(OrbitType.KEPLERIAN, PositionAngleType.TRUE, true,
57                                                1.0e-6, 60.0, 0.001);
58  
59          // create perfect range measurements
60          final Propagator propagator = EstimationTestUtils.createPropagator(context.initialOrbit,
61                                                                             propagatorBuilder);
62          final int    ambiguity         = 1234;
63          final double groundClockOffset =  12.0e-6;
64          for (final GroundStation station : context.stations) {
65              station.getClockOffsetDriver().setValue(groundClockOffset);
66          }
67          final double satClockOffset    = 345.0e-6;
68          List<ObservedMeasurement<?>> measurements =
69                          EstimationTestUtils.createMeasurements(propagator,
70                                                                 new PhaseMeasurementCreator(context, RADIO_WAVE,
71                                                                                             ambiguity,
72                                                                                             satClockOffset),
73                                                                 1.0, 3.0, 300.0);
74  
75          propagator.clearStepHandlers();
76  
77  
78          final ShapiroPhaseModifier modifier = new ShapiroPhaseModifier(context.initialOrbit.getMu());
79  
80          DescriptiveStatistics stat = new DescriptiveStatistics();
81          for (final ObservedMeasurement<?> measurement : measurements) {
82              final AbsoluteDate date = measurement.getDate();
83  
84              final SpacecraftState refstate = propagator.propagate(date);
85  
86              Phase phase = (Phase) measurement;
87              EstimatedMeasurementBase<Phase> evalNoMod = phase.estimateWithoutDerivatives(12, 17, new SpacecraftState[] { refstate });
88              Assertions.assertEquals(12, evalNoMod.getIteration());
89              Assertions.assertEquals(17, evalNoMod.getCount());
90  
91              // add modifier
92              phase.addModifier(modifier);
93              boolean found = false;
94              for (final EstimationModifier<Phase> existing : phase.getModifiers()) {
95                  found = found || existing == modifier;
96              }
97              Assertions.assertTrue(found);
98              EstimatedMeasurementBase<Phase> eval = phase.estimateWithoutDerivatives( new SpacecraftState[] { refstate });
99  
100             stat.addValue(eval.getEstimatedValue()[0] - evalNoMod.getEstimatedValue()[0]);
101             Assertions.assertEquals(1,
102                                     eval.getAppliedEffects().entrySet().stream().
103                                     filter(e -> e.getKey().getEffectName().equals("Shapiro")).count());
104 
105         }
106 
107         // wavelength
108         final double wavelength = ((Phase) measurements.get(0)).getWavelength();
109 
110         Assertions.assertEquals(expectedMin,  stat.getMin() * wavelength,  1.0e-9);
111         Assertions.assertEquals(expectedMean, stat.getMean() * wavelength, 1.0e-9);
112         Assertions.assertEquals(expectedMax,  stat.getMax() * wavelength,  1.0e-9);
113 
114     }
115 
116 }
117 
118