1   /* Copyright 2002-2022 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.geometry.euclidean.threed.Vector3D;
22  import org.hipparchus.stat.descriptive.DescriptiveStatistics;
23  import org.junit.Assert;
24  import org.junit.Test;
25  import org.orekit.attitudes.LofOffset;
26  import org.orekit.estimation.Context;
27  import org.orekit.estimation.EstimationTestUtils;
28  import org.orekit.estimation.measurements.EstimatedMeasurement;
29  import org.orekit.estimation.measurements.EstimationModifier;
30  import org.orekit.estimation.measurements.ObservedMeasurement;
31  import org.orekit.estimation.measurements.gnss.InterSatellitesPhase;
32  import org.orekit.estimation.measurements.gnss.InterSatellitesPhaseMeasurementCreator;
33  import org.orekit.frames.LOFType;
34  import org.orekit.gnss.Frequency;
35  import org.orekit.orbits.CartesianOrbit;
36  import org.orekit.orbits.Orbit;
37  import org.orekit.orbits.OrbitType;
38  import org.orekit.orbits.PositionAngle;
39  import org.orekit.propagation.BoundedPropagator;
40  import org.orekit.propagation.EphemerisGenerator;
41  import org.orekit.propagation.Propagator;
42  import org.orekit.propagation.SpacecraftState;
43  import org.orekit.propagation.conversion.NumericalPropagatorBuilder;
44  import org.orekit.utils.TimeStampedPVCoordinates;
45  
46  public class ShapiroInterSatellitePhaseModifierTest {
47  
48      /** Frequency of the measurements. */
49      private static final Frequency FREQUENCY = Frequency.G01;
50  
51      @Test
52      public void testShapiroOneWay() {
53          doTestShapiro(0.000047764, 0.000086953, 0.000164659);
54      }
55  
56      private void doTestShapiro(final double expectedMin, final double expectedMean, final double expectedMax) {
57   
58          Context context = EstimationTestUtils.eccentricContext("regular-data:potential:tides");
59  
60          final NumericalPropagatorBuilder propagatorBuilder =
61                          context.createBuilder(OrbitType.KEPLERIAN, PositionAngle.TRUE, true,
62                                                1.0e-6, 60.0, 0.001);
63          propagatorBuilder.setAttitudeProvider(new LofOffset(propagatorBuilder.getFrame(), LOFType.LVLH));
64  
65          // create perfect inter-satellites phase measurements without antenna offset
66          final TimeStampedPVCoordinates original = context.initialOrbit.getPVCoordinates();
67          final Orbit closeOrbit = new CartesianOrbit(new TimeStampedPVCoordinates(context.initialOrbit.getDate(),
68                                                                                   original.getPosition().add(new Vector3D(1000, 2000, 3000)),
69                                                                                   original.getVelocity().add(new Vector3D(-0.03, 0.01, 0.02))),
70                                                      context.initialOrbit.getFrame(),
71                                                      context.initialOrbit.getMu());
72          final Propagator closePropagator = EstimationTestUtils.createPropagator(closeOrbit,
73                                                                                  propagatorBuilder);
74          final EphemerisGenerator generator = closePropagator.getEphemerisGenerator();
75          closePropagator.propagate(context.initialOrbit.getDate().shiftedBy(3.5 * closeOrbit.getKeplerianPeriod()));
76          final BoundedPropagator ephemeris = generator.getGeneratedEphemeris();
77          final Propagator p1 = EstimationTestUtils.createPropagator(context.initialOrbit,
78                                                                             propagatorBuilder);
79          final int    ambiguity         = 1234;
80          final double localClockOffset  = 0.137e-6;
81          final double remoteClockOffset = 469.0e-6;
82          List<ObservedMeasurement<?>> measurements =
83                          EstimationTestUtils.createMeasurements(p1,
84                                                                 new InterSatellitesPhaseMeasurementCreator(ephemeris,
85                                                                                                            FREQUENCY,
86                                                                                                            ambiguity,
87                                                                                                            localClockOffset,
88                                                                                                            remoteClockOffset,
89                                                                                                            Vector3D.ZERO,
90                                                                                                            Vector3D.ZERO),
91                                                                 1.0, 3.0, 300.0);
92  
93          final ShapiroInterSatellitePhaseModifier modifier = new ShapiroInterSatellitePhaseModifier(context.initialOrbit.getMu());
94          final Propagator p3 = EstimationTestUtils.createPropagator(context.initialOrbit,
95                                                                     propagatorBuilder);
96          DescriptiveStatistics stat = new DescriptiveStatistics();
97          for (int i = 0; i < measurements.size(); ++i) {
98              InterSatellitesPhase sr = (InterSatellitesPhase) measurements.get(i);
99              SpacecraftState[] states = new SpacecraftState[] {
100                 p3.propagate(sr.getDate()),
101                 ephemeris.propagate(sr.getDate())
102             };
103             EstimatedMeasurement<InterSatellitesPhase> evalNoMod = sr.estimate(0, 0, states);
104 
105             // add modifier
106             sr.addModifier(modifier);
107             boolean found = false;
108             for (final EstimationModifier<InterSatellitesPhase> existing : sr.getModifiers()) {
109                 found = found || existing == modifier;
110             }
111             Assert.assertTrue(found);
112             EstimatedMeasurement<InterSatellitesPhase> eval = sr.estimate(0, 0, states);
113 
114             stat.addValue(eval.getEstimatedValue()[0] - evalNoMod.getEstimatedValue()[0]);
115 
116         }
117 
118         // wavelength
119         final double wavelength = ((InterSatellitesPhase) measurements.get(0)).getWavelength();
120 
121         Assert.assertEquals(expectedMin,  stat.getMin() * wavelength,  1.0e-9);
122         Assert.assertEquals(expectedMean, stat.getMean() * wavelength, 1.0e-9);
123         Assert.assertEquals(expectedMax,  stat.getMax() * wavelength,  1.0e-9);
124 
125     }
126 
127 }
128 
129