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 org.hipparchus.geometry.euclidean.threed.Vector3D;
20  import org.hipparchus.util.FastMath;
21  import org.junit.jupiter.api.Assertions;
22  import org.junit.jupiter.api.BeforeEach;
23  import org.junit.jupiter.api.Test;
24  import org.orekit.Utils;
25  import org.orekit.bodies.GeodeticPoint;
26  import org.orekit.bodies.OneAxisEllipsoid;
27  import org.orekit.estimation.measurements.EstimatedMeasurement;
28  import org.orekit.estimation.measurements.GroundStation;
29  import org.orekit.estimation.measurements.ObservableSatellite;
30  import org.orekit.estimation.measurements.RangeRate;
31  import org.orekit.frames.FramesFactory;
32  import org.orekit.frames.TopocentricFrame;
33  import org.orekit.orbits.CartesianOrbit;
34  import org.orekit.propagation.SpacecraftState;
35  import org.orekit.propagation.analytical.tle.TLE;
36  import org.orekit.propagation.analytical.tle.TLEPropagator;
37  import org.orekit.utils.Constants;
38  import org.orekit.utils.IERSConventions;
39  import org.orekit.utils.ParameterDriver;
40  import org.orekit.utils.TimeStampedPVCoordinates;
41  
42  import java.util.Arrays;
43  
44  public class RelativisticClockRangeRateModifierTest {
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(), false).transformPVCoordinates(new TimeStampedPVCoordinates(state.getDate(), zero, zero, zero));
82  
83          // Range measurement
84          final RangeRate rangeRate = new RangeRate(station, state.getDate(), 26584264.45, 1.0, 1.0, false, new ObservableSatellite(0));
85          final EstimatedMeasurement<RangeRate> estimated = new EstimatedMeasurement<>(rangeRate, 0, 0,
86                          new SpacecraftState[] {state},
87                          new TimeStampedPVCoordinates[] {state.getPVCoordinates(), stationPV});
88          estimated.setEstimatedValue(rangeRate.getObservedValue()[0]);
89          Assertions.assertEquals(0.0, estimated.getObservedValue()[0] - estimated.getEstimatedValue()[0], 1.0e-3);
90  
91          // Measurement modifier
92          final RelativisticClockRangeRateModifier modifier = new RelativisticClockRangeRateModifier(Constants.WGS84_EARTH_MU);
93          modifier.modify(estimated);
94          Assertions.assertEquals(0, modifier.getParametersDrivers().size());
95  
96          // Verify
97          Assertions.assertEquals(1.68e-3, estimated.getEstimatedValue()[0] - estimated.getObservedValue()[0], 1.0e-5);
98          Assertions.assertEquals(1,
99                                  estimated.getAppliedEffects().entrySet().stream().
100                                 filter(e -> e.getKey().getEffectName().equals("clock relativity")).count());
101 
102     }
103 
104     @BeforeEach
105     public void setUp() {
106         Utils.setDataRoot("regular-data");
107     }
108 
109 }