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.Arrays;
20  
21  import org.hipparchus.geometry.euclidean.threed.Vector3D;
22  import org.hipparchus.util.FastMath;
23  import org.junit.Assert;
24  import org.junit.Before;
25  import org.junit.Test;
26  import org.orekit.Utils;
27  import org.orekit.bodies.GeodeticPoint;
28  import org.orekit.bodies.OneAxisEllipsoid;
29  import org.orekit.estimation.measurements.EstimatedMeasurement;
30  import org.orekit.estimation.measurements.GroundStation;
31  import org.orekit.estimation.measurements.ObservableSatellite;
32  import org.orekit.estimation.measurements.Range;
33  import org.orekit.frames.FramesFactory;
34  import org.orekit.frames.TopocentricFrame;
35  import org.orekit.orbits.CartesianOrbit;
36  import org.orekit.propagation.SpacecraftState;
37  import org.orekit.propagation.analytical.tle.TLE;
38  import org.orekit.propagation.analytical.tle.TLEPropagator;
39  import org.orekit.utils.Constants;
40  import org.orekit.utils.IERSConventions;
41  import org.orekit.utils.ParameterDriver;
42  import org.orekit.utils.TimeStampedPVCoordinates;
43  
44  public class RelativisticClockRangeModifierTest {
45  
46      @Test
47      public void testRelativisticClockCorrection() {
48  
49          // Station
50          final OneAxisEllipsoid earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
51                                                              Constants.WGS84_EARTH_FLATTENING,
52                                                              FramesFactory.getITRF(IERSConventions.IERS_2010, true));
53          final GeodeticPoint point    = new GeodeticPoint(FastMath.toRadians(42.0), FastMath.toRadians(1.0), 100.0);
54          final TopocentricFrame topo  = new TopocentricFrame(earth, point, "");
55          final GroundStation station  = new GroundStation(topo);
56  
57          // Satellite (GPS orbit from TLE)
58          final TLE tle = new TLE("1 28474U 04045A   20252.59334296 -.00000043  00000-0  00000-0 0  9998",
59                                  "2 28474  55.0265  49.5108 0200271 267.9106 149.0797  2.00552216116165");
60          final TimeStampedPVCoordinates satPV = TLEPropagator.selectExtrapolator(tle).getPVCoordinates(tle.getDate(), FramesFactory.getEME2000());
61          final SpacecraftState state = new SpacecraftState(new CartesianOrbit(satPV, FramesFactory.getEME2000(), Constants.WGS84_EARTH_MU));
62  
63          // Set reference date to station drivers
64          for (ParameterDriver driver : Arrays.asList(station.getClockOffsetDriver(),
65                                                      station.getEastOffsetDriver(),
66                                                      station.getNorthOffsetDriver(),
67                                                      station.getZenithOffsetDriver(),
68                                                      station.getPrimeMeridianOffsetDriver(),
69                                                      station.getPrimeMeridianDriftDriver(),
70                                                      station.getPolarOffsetXDriver(),
71                                                      station.getPolarDriftXDriver(),
72                                                      station.getPolarOffsetYDriver(),
73                                                      station.getPolarDriftYDriver())) {
74              if (driver.getReferenceDate() == null) {
75                  driver.setReferenceDate(state.getDate());
76              }
77          }
78  
79          // Station PV
80          final Vector3D zero = Vector3D.ZERO;
81          final TimeStampedPVCoordinates stationPV = station.getOffsetToInertial(state.getFrame(), state.getDate()).transformPVCoordinates(new TimeStampedPVCoordinates(state.getDate(), zero, zero, zero));
82  
83          // Range measurement
84          final Range range = new Range(station, false, state.getDate(), 26584264.45, 1.0, 1.0, new ObservableSatellite(0));
85          final EstimatedMeasurement<Range> estimated = new EstimatedMeasurement<Range>(range, 0, 0,
86                          new SpacecraftState[] {state},
87                          new TimeStampedPVCoordinates[] {state.getPVCoordinates(), stationPV});
88          estimated.setEstimatedValue(range.getObservedValue()[0]);
89          Assert.assertEquals(0.0, estimated.getObservedValue()[0] - estimated.getEstimatedValue()[0], 1.0e-3);
90  
91          // Measurement modifier
92          final RelativisticClockRangeModifier modifier = new RelativisticClockRangeModifier();
93          modifier.modify(estimated);
94          Assert.assertEquals(0, modifier.getParametersDrivers().size());
95  
96          // Verify
97          Assert.assertEquals(-6.87, estimated.getObservedValue()[0] - estimated.getEstimatedValue()[0], 1.0e-2);
98  
99      }
100 
101     @Before
102     public void setUp() {
103         Utils.setDataRoot("regular-data");
104     }
105 
106 }