1   /* Copyright 2022-2025 Luc Maisonobe
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.files.sp3;
18  
19  import java.util.List;
20  
21  import org.hipparchus.geometry.euclidean.threed.Vector3D;
22  import org.junit.jupiter.api.Assertions;
23  import org.junit.jupiter.api.BeforeEach;
24  import org.junit.jupiter.api.Test;
25  import org.orekit.Utils;
26  import org.orekit.data.DataSource;
27  import org.orekit.data.UnixCompressFilter;
28  import org.orekit.time.AbstractTimeInterpolator;
29  
30  public class SP3CoordinateHermiteInterpolatorTest {
31  
32      @Test
33      public void testNoRates() {
34          final String ex = "/sp3/gbm18432.sp3.Z";
35  
36          final SP3Parser           parser      = new SP3Parser();
37          final DataSource          compressed  = new DataSource(ex, () -> getClass().getResourceAsStream(ex));
38          final SP3                 file        = parser.parse(new UnixCompressFilter().filter(compressed));
39          final List<SP3Coordinate> coordinates = file.getEphemeris("G03").getSegments().get(0).getCoordinates();
40  
41          Assertions.assertEquals(288, coordinates.size());
42  
43          SP3CoordinateHermiteInterpolator interpolator =
44                          new SP3CoordinateHermiteInterpolator(6,
45                                                               AbstractTimeInterpolator.DEFAULT_EXTRAPOLATION_THRESHOLD_SEC,
46                                                               false);
47  
48          // check one of the sample points
49          SP3Coordinate pointA = coordinates.get(117);
50          SP3Coordinate interpolated = interpolator.interpolate(pointA.getDate(), coordinates);
51  
52          // interpolation adds derivatives that were not present in the file
53          SP3TestUtils.checkEquals(pointA,
54                                   new SP3Coordinate(interpolated.getDate(),
55                                                     interpolated.getPosition(), interpolated.getPositionAccuracy(),
56                                                     Vector3D.ZERO, interpolated.getVelocityAccuracy(),
57                                                     interpolated.getClockCorrection(), interpolated.getClockAccuracy(),
58                                                     0.0, interpolated.getClockRateAccuracy(),
59                                                     false, false, false, false));
60          Assertions.assertEquals(2836.973124,  interpolated.getVelocity().getNorm(), 1.0e-6);
61          Assertions.assertEquals(1.126333e-11, interpolated.getClockRateChange(),    1.0e-17);
62  
63          // check between sample points
64          SP3Coordinate pointB  = coordinates.get(118);
65          SP3Coordinate between = interpolator.interpolate(pointA.getDate().shiftedBy(0.5 * file.getHeader().getEpochInterval()),
66                                                           coordinates);
67          Assertions.assertEquals(426076.123,
68                                  Vector3D.distance(pointA.getPosition(), between.getPosition()),
69                                  1.0e-3);
70          Assertions.assertEquals(427183.849,
71                                  Vector3D.distance(pointB.getPosition(), between.getPosition()),
72                                  1.0e-3);
73          Assertions.assertEquals(853194.644,
74                                  Vector3D.distance(pointA.getPosition(), pointB.getPosition()),
75                                  1.0e-3);
76  
77      }
78  
79      @Test
80      public void testRates() {
81          final String ex = "/sp3/issue895-minutes-increment.sp3";
82  
83          final SP3Parser           parser      = new SP3Parser();
84          final DataSource          source      = new DataSource(ex, () -> getClass().getResourceAsStream(ex));
85          final SP3                 file        = parser.parse(source);
86          final List<SP3Coordinate> coordinates = file.getEphemeris("L51").getSegments().get(0).getCoordinates();
87  
88          Assertions.assertEquals(91, coordinates.size());
89  
90          SP3CoordinateHermiteInterpolator interpolator =
91                          new SP3CoordinateHermiteInterpolator(6,
92                                                               AbstractTimeInterpolator.DEFAULT_EXTRAPOLATION_THRESHOLD_SEC,
93                                                               true);
94  
95          // check one of the sample points
96          SP3Coordinate pointA = coordinates.get(54);
97          SP3Coordinate interpolated = interpolator.interpolate(pointA.getDate(), coordinates);
98  
99          SP3TestUtils.checkEquals(pointA, interpolated);
100         Assertions.assertEquals(5996.687746,                       interpolated.getVelocity().getNorm(), 1.0e-6);
101         Assertions.assertTrue(Double.isNaN(interpolated.getClockRateChange()));
102 
103         // check between sample points
104         SP3Coordinate pointB  = coordinates.get(55);
105         SP3Coordinate between = interpolator.interpolate(pointA.getDate().shiftedBy(0.5 * file.getHeader().getEpochInterval()),
106                                                          coordinates);
107         Assertions.assertEquals(359788.254,
108                                 Vector3D.distance(pointA.getPosition(), between.getPosition()),
109                                 1.0e-3);
110         Assertions.assertEquals(359793.589,
111                                 Vector3D.distance(pointB.getPosition(), between.getPosition()),
112                                 1.0e-3);
113         Assertions.assertEquals(719498.945,
114                                 Vector3D.distance(pointA.getPosition(), pointB.getPosition()),
115                                 1.0e-3);
116 
117     }
118 
119     @BeforeEach
120     public void setUp() {
121         Utils.setDataRoot("regular-data");
122     }
123 
124 }