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.frames;
18  
19  
20  import java.util.SortedSet;
21  import java.util.TreeSet;
22  
23  import org.hipparchus.util.FastMath;
24  import org.junit.Assert;
25  import org.junit.Test;
26  import org.orekit.data.AbstractFilesLoaderTest;
27  import org.orekit.errors.OrekitException;
28  import org.orekit.errors.OrekitMessages;
29  import org.orekit.time.AbsoluteDate;
30  import org.orekit.time.ChronologicalComparator;
31  import org.orekit.time.TimeScalesFactory;
32  import org.orekit.utils.Constants;
33  import org.orekit.utils.IERSConventions;
34  
35  
36  public class RapidDataAndPredictionColumnsLoaderTest extends AbstractFilesLoaderTest {
37  
38      @Test
39      public void testStartDateDaily1980() {
40          setRoot("rapid-data-columns");
41          IERSConventions.NutationCorrectionConverter converter =
42                  IERSConventions.IERS_1996.getNutationCorrectionConverter();
43          SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
44          new RapidDataAndPredictionColumnsLoader(false, "^finals\\.daily$", manager, () -> utc).fillHistory(converter, history);
45          Assert.assertEquals(new AbsoluteDate(2011, 4, 9, TimeScalesFactory.getUTC()),
46                              new EOPHistory(IERSConventions.IERS_1996, history, true).getStartDate());
47      }
48  
49      @Test
50      public void testEndDateDaily1980() {
51          setRoot("rapid-data-columns");
52          IERSConventions.NutationCorrectionConverter converter =
53                  IERSConventions.IERS_1996.getNutationCorrectionConverter();
54          SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
55          new RapidDataAndPredictionColumnsLoader(false, "^finals\\.daily$", manager, () -> utc).fillHistory(converter, history);
56          Assert.assertEquals(new AbsoluteDate(2011, 10, 6, TimeScalesFactory.getUTC()),
57                              new EOPHistory(IERSConventions.IERS_1996, history, true).getEndDate());
58      }
59  
60      @Test
61      public void testStartDateDaily2000() {
62          setRoot("rapid-data-columns");
63          IERSConventions.NutationCorrectionConverter converter =
64                  IERSConventions.IERS_2003.getNutationCorrectionConverter();
65          SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
66          new RapidDataAndPredictionColumnsLoader(true, "^finals\\.daily$", manager, () -> utc).fillHistory(converter, history);
67          Assert.assertEquals(new AbsoluteDate(2011, 4, 9, TimeScalesFactory.getUTC()),
68                              new EOPHistory(IERSConventions.IERS_2003, history, true).getStartDate());
69      }
70  
71      @Test
72      public void testMissingColumnsPadding1980() {
73          setRoot("rapid-data-columns");
74          IERSConventions.NutationCorrectionConverter converter =
75                  IERSConventions.IERS_1996.getNutationCorrectionConverter();
76          SortedSet<EOPEntry> data = new TreeSet<EOPEntry>(new ChronologicalComparator());
77          new RapidDataAndPredictionColumnsLoader(false, "^finals\\.daily$", manager, () -> utc).fillHistory(converter, data);
78          EOPHistory history = new EOPHistory(IERSConventions.IERS_1996, data, true);
79  
80          // after 2011-05-31, the example daily file has no columns for Bulletin B data
81          // we don't see anything since we fall back to bulletin A
82          AbsoluteDate t1Inf = new AbsoluteDate(2011, 6, 1, TimeScalesFactory.getUTC());
83          Assert.assertEquals(-67.724,    3600000 * FastMath.toDegrees(history.getEquinoxNutationCorrection(t1Inf)[0]), 1.0e-10);
84          Assert.assertEquals(-11.807,    3600000 * FastMath.toDegrees(history.getEquinoxNutationCorrection(t1Inf)[1]), 1.0e-10);
85          Assert.assertEquals(-0.2778790, history.getUT1MinusUTC(t1Inf),                                                1.0e-10);
86          Assert.assertEquals( 0.5773,    1000 * history.getLOD(t1Inf),                                                 1.0e-10);
87          AbsoluteDate t1Sup = t1Inf.shiftedBy(Constants.JULIAN_DAY);
88          Assert.assertEquals(-67.800,    3600000 * FastMath.toDegrees(history.getEquinoxNutationCorrection(t1Sup)[0]), 1.0e-10);
89          Assert.assertEquals(-11.810,    3600000 * FastMath.toDegrees(history.getEquinoxNutationCorrection(t1Sup)[1]), 1.0e-10);
90          Assert.assertEquals(-0.2784173, history.getUT1MinusUTC(t1Sup),                                                1.0e-10);
91          Assert.assertEquals( 0.5055,    1000 * history.getLOD(t1Sup),                                                 1.0e-10);
92  
93          // after 2011-07-06, the example daily file has no columns for LOD
94          AbsoluteDate t2Inf = new AbsoluteDate(2011, 7, 6, TimeScalesFactory.getUTC());
95          Assert.assertEquals(-72.717,    3600000 * FastMath.toDegrees(history.getEquinoxNutationCorrection(t2Inf)[0]), 1.0e-10);
96          Assert.assertEquals(-10.620,    3600000 * FastMath.toDegrees(history.getEquinoxNutationCorrection(t2Inf)[1]), 1.0e-10);
97          Assert.assertEquals(-0.2915826, history.getUT1MinusUTC(t2Inf),                                                1.0e-10);
98          Assert.assertEquals( 0.5020,    1000 * history.getLOD(t2Inf),                                                 1.0e-10);
99          AbsoluteDate t2Sup = t2Inf.shiftedBy(Constants.JULIAN_DAY);
100         Assert.assertEquals(-73.194,    3600000 * FastMath.toDegrees(history.getEquinoxNutationCorrection(t2Sup)[0]), 1.0e-10);
101         Assert.assertEquals(-10.535,    3600000 * FastMath.toDegrees(history.getEquinoxNutationCorrection(t2Sup)[1]), 1.0e-10);
102         Assert.assertEquals(-0.2920866, history.getUT1MinusUTC(t2Sup),                                                1.0e-10);
103         Assert.assertEquals( 0.0,       1000 * history.getLOD(t2Sup),                                                 1.0e-10);
104 
105         // after 2011-09-19, the example daily file has no columns for nutation
106         AbsoluteDate t3Inf = new AbsoluteDate(2011, 9, 19, TimeScalesFactory.getUTC());
107         Assert.assertEquals(-79.889,    3600000 * FastMath.toDegrees(history.getEquinoxNutationCorrection(t3Inf)[0]), 1.0e-10);
108         Assert.assertEquals(-11.125,    3600000 * FastMath.toDegrees(history.getEquinoxNutationCorrection(t3Inf)[1]), 1.0e-10);
109         Assert.assertEquals(-0.3112849, history.getUT1MinusUTC(t3Inf),                                                1.0e-10);
110         Assert.assertEquals( 0.0,       1000 * history.getLOD(t3Inf),                                                 1.0e-10);
111         AbsoluteDate t3Sup = t3Inf.shiftedBy(Constants.JULIAN_DAY);
112         Assert.assertEquals( 0.0,       3600000 * FastMath.toDegrees(history.getEquinoxNutationCorrection(t3Sup)[0]), 1.0e-10);
113         Assert.assertEquals( 0.0,       3600000 * FastMath.toDegrees(history.getEquinoxNutationCorrection(t3Sup)[1]), 1.0e-10);
114         Assert.assertEquals(-0.3115675, history.getUT1MinusUTC(t3Sup),                                                1.0e-10);
115         Assert.assertEquals( 0.0,       1000 * history.getLOD(t3Sup),                                                 1.0e-10);
116 
117     }
118 
119     @Test
120     public void testMissingColumnsPadding2000() {
121         setRoot("rapid-data-columns");
122         IERSConventions.NutationCorrectionConverter converter =
123                 IERSConventions.IERS_2003.getNutationCorrectionConverter();
124         SortedSet<EOPEntry> data = new TreeSet<EOPEntry>(new ChronologicalComparator());
125         new RapidDataAndPredictionColumnsLoader(true, "^finals2000A\\.daily$", manager, () -> utc).fillHistory(converter, data);
126         EOPHistory history = new EOPHistory(IERSConventions.IERS_2003, data, true);
127 
128         // after 2011-05-31, the example daily file has no columns for Bulletin B data
129         // we don't see anything since we fall back to bulletin A
130         AbsoluteDate t1Inf = new AbsoluteDate(2011, 6, 1, TimeScalesFactory.getUTC());
131         Assert.assertEquals(-0.015313,  3600 * FastMath.toDegrees(history.getPoleCorrection(t1Inf).getXp()), 1.0e-10);
132         Assert.assertEquals( 0.403214,  3600 * FastMath.toDegrees(history.getPoleCorrection(t1Inf).getYp()), 1.0e-10);
133         Assert.assertEquals(-0.2778790, history.getUT1MinusUTC(t1Inf),                                       1.0e-10);
134         Assert.assertEquals( 0.5773,    1000 * history.getLOD(t1Inf),                                        1.0e-10);
135         AbsoluteDate t1Sup = t1Inf.shiftedBy(Constants.JULIAN_DAY);
136         Assert.assertEquals(-0.014222,  3600 * FastMath.toDegrees(history.getPoleCorrection(t1Sup).getXp()), 1.0e-10);
137         Assert.assertEquals( 0.404430,  3600 * FastMath.toDegrees(history.getPoleCorrection(t1Sup).getYp()), 1.0e-10);
138         Assert.assertEquals(-0.2784173, history.getUT1MinusUTC(t1Sup),                                       1.0e-10);
139         Assert.assertEquals( 0.5055,    1000 * history.getLOD(t1Sup),                                        1.0e-10);
140 
141         // after 2011-07-06, the example daily file has no columns for LOD
142         AbsoluteDate t2Inf = new AbsoluteDate(2011, 7, 6, TimeScalesFactory.getUTC());
143         Assert.assertEquals( 0.052605,  3600 * FastMath.toDegrees(history.getPoleCorrection(t2Inf).getXp()), 1.0e-10);
144         Assert.assertEquals( 0.440076,  3600 * FastMath.toDegrees(history.getPoleCorrection(t2Inf).getYp()), 1.0e-10);
145         Assert.assertEquals(-0.2915826, history.getUT1MinusUTC(t2Inf),                                       1.0e-10);
146         Assert.assertEquals( 0.5020,    1000 * history.getLOD(t2Inf),                                        1.0e-10);
147         AbsoluteDate t2Sup = t2Inf.shiftedBy(Constants.JULIAN_DAY);
148         Assert.assertEquals( 0.055115,  3600 * FastMath.toDegrees(history.getPoleCorrection(t2Sup).getXp()), 1.0e-10);
149         Assert.assertEquals( 0.440848,  3600 * FastMath.toDegrees(history.getPoleCorrection(t2Sup).getYp()), 1.0e-10);
150         Assert.assertEquals(-0.2920866, history.getUT1MinusUTC(t2Sup),                                       1.0e-10);
151         Assert.assertEquals( 0.0,       1000 * history.getLOD(t2Sup),                                        1.0e-10);
152 
153     }
154 
155     @Test
156     public void testEndDateDaily2000() {
157         setRoot("rapid-data-columns");
158         IERSConventions.NutationCorrectionConverter converter =
159                 IERSConventions.IERS_2003.getNutationCorrectionConverter();
160         SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
161         new RapidDataAndPredictionColumnsLoader(true, "^finals2000A\\.daily$", manager, () -> utc).fillHistory(converter, history);
162         Assert.assertEquals(new AbsoluteDate(2011, 10, 6, TimeScalesFactory.getUTC()),
163                             new EOPHistory(IERSConventions.IERS_2003, history, true).getEndDate());
164     }
165 
166     @Test
167     public void testNoColumns() {
168         setRoot("rapid-data-columns");
169         IERSConventions.NutationCorrectionConverter converter =
170                         IERSConventions.IERS_2010.getNutationCorrectionConverter();
171         SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
172         new RapidDataAndPredictionColumnsLoader(true, "^finals2000A-no-columns\\.daily$", manager, () -> utc).fillHistory(converter, history);
173         EOPHistory eopH = new EOPHistory(IERSConventions.IERS_2010, history, true);
174         Assert.assertEquals(new AbsoluteDate(2011, 4, 16, TimeScalesFactory.getUTC()), eopH.getEndDate());
175         AbsoluteDate testDate = eopH.getEndDate().shiftedBy(-2 * Constants.JULIAN_DAY);
176         Assert.assertEquals(0.0, eopH.getPoleCorrection(testDate).getXp(),                1.0e-15);
177         Assert.assertEquals(0.0, eopH.getPoleCorrection(testDate).getYp(),                1.0e-15);
178         Assert.assertEquals(0.0, eopH.getUT1MinusUTC(testDate),                           1.0e-15);
179         Assert.assertEquals(0.0, eopH.getLOD(testDate),                                   1.0e-15);
180         Assert.assertEquals(0.0, eopH.getNonRotatinOriginNutationCorrection(testDate)[0], 1.0e-15);
181         Assert.assertEquals(0.0, eopH.getNonRotatinOriginNutationCorrection(testDate)[1], 1.0e-15);
182     }
183 
184     @Test
185     public void testPost2070() {
186         setRoot("rapid-data-columns");
187         IERSConventions.NutationCorrectionConverter converter =
188                         IERSConventions.IERS_2010.getNutationCorrectionConverter();
189         SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
190         new RapidDataAndPredictionColumnsLoader(true, "^finals2000A-post-2070\\.daily$", manager, () -> utc).fillHistory(converter, history);
191         Assert.assertEquals(new AbsoluteDate(2075, 4, 16, TimeScalesFactory.getUTC()),
192                             new EOPHistory(IERSConventions.IERS_2010, history, true).getEndDate());
193 
194     }
195 
196     @Test
197     public void testTruncatedLine() {
198         doTestWrongFile("^finals2000A-truncated-line\\.daily$", 3);
199     }
200 
201     @Test
202     public void testWrongDateFormat() {
203         doTestWrongFile("^finals2000A-wrong-date-format\\.daily$", 3);
204     }
205 
206     @Test
207     public void testWrongYear() {
208         doTestWrongFile("^finals2000A-wrong-year\\.daily$", 6);
209     }
210 
211     @Test
212     public void testWrongMonth() {
213         doTestWrongFile("^finals2000A-wrong-month\\.daily$", 5);
214     }
215 
216     @Test
217     public void testWrongDay() {
218         doTestWrongFile("^finals2000A-wrong-day\\.daily$", 4);
219     }
220 
221     @Test
222     public void testWrongPoleAFormat() {
223         doTestWrongFile("^finals2000A-wrong-pole-A-format\\.daily$", 7);
224     }
225 
226     @Test
227     public void testWrongPoleBFormat() {
228         doTestWrongFile("^finals2000A-wrong-pole-B-format\\.daily$", 7);
229     }
230 
231     @Test
232     public void testWrongUT1UTCAFormat() {
233         doTestWrongFile("^finals2000A-wrong-ut1-utc-A-format\\.daily$", 7);
234     }
235 
236     @Test
237     public void testWrongUT1UTCBFormat() {
238         doTestWrongFile("^finals2000A-wrong-ut1-utc-B-format\\.daily$", 7);
239     }
240 
241     @Test
242     public void testWrongLODAFormat() {
243         doTestWrongFile("^finals2000A-wrong-lod-A-format\\.daily$", 7);
244     }
245 
246     @Test
247     public void testWrongNutationAFormat() {
248         doTestWrongFile("^finals2000A-wrong-nutation-A-format\\.daily$", 7);
249     }
250 
251     @Test
252     public void testWrongNutationBFormat() {
253         doTestWrongFile("^finals2000A-wrong-nutation-B-format\\.daily$", 7);
254     }
255 
256     private void doTestWrongFile(String fileName, int lineNumber) {
257         setRoot("rapid-data-columns");
258         IERSConventions.NutationCorrectionConverter converter =
259                         IERSConventions.IERS_2010.getNutationCorrectionConverter();
260         SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
261         try {
262             new RapidDataAndPredictionColumnsLoader(true, fileName, manager, () -> utc).fillHistory(converter, history);
263             Assert.fail("an exception should have been thrown");
264         } catch (OrekitException oe) {
265             Assert.assertEquals(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, oe.getSpecifier());
266             Assert.assertEquals(lineNumber, ((Integer) oe.getParts()[0]).intValue());
267         }
268     }
269 
270 }