1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.models.earth.weather;
18
19 import java.io.IOException;
20 import java.net.URISyntaxException;
21 import java.net.URL;
22
23 import org.hipparchus.CalculusFieldElement;
24 import org.hipparchus.Field;
25 import org.hipparchus.util.Binary64Field;
26 import org.hipparchus.util.FastMath;
27 import org.junit.jupiter.api.Assertions;
28 import org.junit.jupiter.api.Test;
29 import org.orekit.Utils;
30 import org.orekit.bodies.FieldGeodeticPoint;
31 import org.orekit.bodies.GeodeticPoint;
32 import org.orekit.data.DataSource;
33 import org.orekit.errors.OrekitException;
34 import org.orekit.errors.OrekitMessages;
35 import org.orekit.models.earth.troposphere.AzimuthalGradientCoefficients;
36 import org.orekit.models.earth.troposphere.FieldAzimuthalGradientCoefficients;
37 import org.orekit.models.earth.troposphere.FieldViennaACoefficients;
38 import org.orekit.models.earth.troposphere.TroposphericModelUtils;
39 import org.orekit.models.earth.troposphere.ViennaACoefficients;
40 import org.orekit.time.AbsoluteDate;
41 import org.orekit.time.FieldAbsoluteDate;
42 import org.orekit.time.TimeScalesFactory;
43 import org.orekit.utils.Constants;
44
45 public class GlobalPressureTemperature3Test {
46
47 private static final double epsilon = 1.0e-12;
48
49 @Test
50 public void testMatlabRef0() throws IOException, URISyntaxException {
51
52 Utils.setDataRoot("regular-data");
53
54
55 final double latitude = FastMath.toRadians(48.20);
56 final double longitude = FastMath.toRadians(16.37);
57 final double height = 156.0;
58
59
60
61 final AbsoluteDate date = AbsoluteDate.createMJDDate(56140, Constants.JULIAN_DAY - 1.0, TimeScalesFactory.getUTC());
62 final URL url = GlobalPressureTemperature3Test.class.getClassLoader().getResource("gpt-grid/gpt3_5.grd");
63 final GlobalPressureTemperature3 model =
64 new GlobalPressureTemperature3(new DataSource(url.toURI()),
65 TimeScalesFactory.getUTC());
66
67 final GeodeticPoint location = new GeodeticPoint(latitude, longitude, height);
68 final ViennaACoefficients a = model.getA(location, date);
69 final PressureTemperatureHumidity pth = model.getWeatherParameters(location, date);
70 final AzimuthalGradientCoefficients gradient = model.getGradientCoefficients(location, date);
71
72 Assertions.assertEquals(0.001258154, a.getAh(), 1.0e-9);
73 Assertions.assertEquals(0.000568212, a.getAw(), 1.0e-9);
74 Assertions.assertEquals(273.15 + 22.060239452, pth.getTemperature(), 1.0e-9);
75 Assertions.assertEquals(1002.577297099, TroposphericModelUtils.HECTO_PASCAL.fromSI(pth.getPressure()), 1.0e-9);
76 Assertions.assertEquals(16.676583415, TroposphericModelUtils.HECTO_PASCAL.fromSI(pth.getWaterVaporPressure()), 1.0e-9);
77 Assertions.assertEquals(281.064766962, pth.getTm(), 1.0e-9);
78 Assertions.assertEquals(2.697732327, pth.getLambda(), 1.0e-9);
79 Assertions.assertEquals(-0.000177344, gradient.getGnh(), 1.0e-9);
80 Assertions.assertEquals(-0.000048308, gradient.getGeh(), 1.0e-9);
81 Assertions.assertEquals(-0.000085318, gradient.getGnw(), 1.0e-9);
82 Assertions.assertEquals(-0.000035866, gradient.getGew(), 1.0e-9);
83
84 }
85
86 @Test
87 public void testMatlabRef1() throws IOException, URISyntaxException {
88
89 Utils.setDataRoot("regular-data");
90
91
92 final double latitude = FastMath.toRadians(77.5);
93 final double longitude = FastMath.toRadians(137.5);
94 final double height = 0.0;
95 final AbsoluteDate date = AbsoluteDate.createMJDDate(58940, 0.0, TimeScalesFactory.getUTC());
96 final URL url = GlobalPressureTemperature3Test.class.getClassLoader().getResource("gpt-grid/gpt3_5.grd");
97 final GlobalPressureTemperature3 model =
98 new GlobalPressureTemperature3(new DataSource(url.toURI()),
99 TimeScalesFactory.getUTC());
100
101 final GeodeticPoint location = new GeodeticPoint(latitude, longitude, height);
102 final ViennaACoefficients a = model.getA(location, date);
103 final PressureTemperatureHumidity pth = model.getWeatherParameters(location, date);
104 final AzimuthalGradientCoefficients gradient = model.getGradientCoefficients(location, date);
105
106 Assertions.assertEquals(0.001171577, a.getAh(), 1.0e-9);
107 Assertions.assertEquals(0.000574057, a.getAw(), 1.0e-9);
108 Assertions.assertEquals(273.15 - 18.589601195, pth.getTemperature(), 1.0e-9);
109 Assertions.assertEquals(1019.900868185, TroposphericModelUtils.HECTO_PASCAL.fromSI(pth.getPressure()), 1.0e-9);
110 Assertions.assertEquals(1.251369020, TroposphericModelUtils.HECTO_PASCAL.fromSI(pth.getWaterVaporPressure()), 1.0e-9);
111 Assertions.assertEquals(250.211896532, pth.getTm(), 1.0e-9);
112 Assertions.assertEquals(1.813332081, pth.getLambda(), 1.0e-9);
113 Assertions.assertEquals(0.000004818, gradient.getGnh(), 1.0e-9);
114 Assertions.assertEquals(0.000154168, gradient.getGeh(), 1.0e-9);
115 Assertions.assertEquals(0.000001018, gradient.getGnw(), 1.0e-9);
116 Assertions.assertEquals(0.000003392, gradient.getGew(), 1.0e-9);
117
118 }
119
120 @Test
121 public void testMatlabRef2() throws IOException, URISyntaxException {
122
123 Utils.setDataRoot("regular-data");
124
125
126 final double latitude = FastMath.toRadians(80.0);
127 final double longitude = FastMath.toRadians(120.0);
128 final double height = 100.0;
129 final AbsoluteDate date = AbsoluteDate.createMJDDate(58940, 0.0, TimeScalesFactory.getUTC());
130 final URL url = GlobalPressureTemperature3Test.class.getClassLoader().getResource("gpt-grid/gpt3_5.grd");
131 final GlobalPressureTemperature3 model =
132 new GlobalPressureTemperature3(new DataSource(url.toURI()),
133 TimeScalesFactory.getUTC());
134
135 final GeodeticPoint location = new GeodeticPoint(latitude, longitude, height);
136 final ViennaACoefficients a = model.getA(location, date);
137 final PressureTemperatureHumidity pth = model.getWeatherParameters(location, date);
138 final AzimuthalGradientCoefficients gradient = model.getGradientCoefficients(location, date);
139
140 Assertions.assertEquals(0.001169367, a.getAh(), 1.0e-9);
141 Assertions.assertEquals(0.000577807, a.getAw(), 1.0e-9);
142 Assertions.assertEquals(273.15 - 19.730175236, pth.getTemperature(), 1.0e-9);
143 Assertions.assertEquals(1005.387362480, TroposphericModelUtils.HECTO_PASCAL.fromSI(pth.getPressure()), 1.0e-9);
144 Assertions.assertEquals(1.034448353, TroposphericModelUtils.HECTO_PASCAL.fromSI(pth.getWaterVaporPressure()), 1.0e-9);
145 Assertions.assertEquals(249.451317840, pth.getTm(), 1.0e-9);
146 Assertions.assertEquals(1.664833031, pth.getLambda(), 1.0e-9);
147 Assertions.assertEquals(0.000056837, gradient.getGnh(), 1.0e-9);
148 Assertions.assertEquals(0.000106616, gradient.getGeh(), 1.0e-9);
149 Assertions.assertEquals(0.000001235, gradient.getGnw(), 1.0e-9);
150 Assertions.assertEquals(0.000001584, gradient.getGew(), 1.0e-9);
151
152 }
153
154 @Test
155 public void testFieldMatlabRef0() throws IOException, URISyntaxException {
156 doTestFieldMatlabRef0(Binary64Field.getInstance());
157 }
158
159 protected <T extends CalculusFieldElement<T>> void doTestFieldMatlabRef0(final Field<T> field)
160 throws IOException, URISyntaxException {
161
162 Utils.setDataRoot("regular-data");
163
164
165 final T latitude = FastMath.toRadians(field.getZero().newInstance(48.20));
166 final T longitude = FastMath.toRadians(field.getZero().newInstance(16.37));
167 final T height = field.getZero().newInstance(156.0);
168
169
170
171 final FieldAbsoluteDate<T> date = FieldAbsoluteDate.createMJDDate(56140,
172 field.getZero().newInstance(Constants.JULIAN_DAY - 1.0),
173 TimeScalesFactory.getUTC());
174 final URL url = GlobalPressureTemperature3Test.class.getClassLoader().getResource("gpt-grid/gpt3_5.grd");
175 final GlobalPressureTemperature3 model =
176 new GlobalPressureTemperature3(new DataSource(url.toURI()),
177 TimeScalesFactory.getUTC());
178
179 final FieldGeodeticPoint<T> location = new FieldGeodeticPoint<>(latitude, longitude, height);
180 final FieldViennaACoefficients<T> a = model.getA(location, date);
181 final FieldPressureTemperatureHumidity<T> pth = model.getWeatherParameters(location, date);
182 final FieldAzimuthalGradientCoefficients<T> gradient = model.getGradientCoefficients(location, date);
183
184 Assertions.assertEquals(0.001258154, a.getAh().getReal(), 1.0e-9);
185 Assertions.assertEquals(0.000568212, a.getAw().getReal(), 1.0e-9);
186 Assertions.assertEquals(273.15 + 22.060239452, pth.getTemperature().getReal(), 1.0e-9);
187 Assertions.assertEquals(1002.577297099, TroposphericModelUtils.HECTO_PASCAL.fromSI(pth.getPressure()).getReal(), 1.0e-9);
188 Assertions.assertEquals(16.676583415, TroposphericModelUtils.HECTO_PASCAL.fromSI(pth.getWaterVaporPressure()).getReal(), 1.0e-9);
189 Assertions.assertEquals(281.064766962, pth.getTm().getReal(), 1.0e-9);
190 Assertions.assertEquals(2.697732327, pth.getLambda().getReal(), 1.0e-9);
191 Assertions.assertEquals(-0.000177344, gradient.getGnh().getReal(), 1.0e-9);
192 Assertions.assertEquals(-0.000048308, gradient.getGeh().getReal(), 1.0e-9);
193 Assertions.assertEquals(-0.000085318, gradient.getGnw().getReal(), 1.0e-9);
194 Assertions.assertEquals(-0.000035866, gradient.getGew().getReal(), 1.0e-9);
195
196 }
197
198 @Test
199 public void testFieldMatlabRef1() throws IOException, URISyntaxException {
200 doTestFieldMatlabRef1(Binary64Field.getInstance());
201 }
202
203 protected <T extends CalculusFieldElement<T>> void doTestFieldMatlabRef1(final Field<T> field)
204 throws IOException, URISyntaxException {
205
206 Utils.setDataRoot("regular-data");
207
208
209 final T latitude = FastMath.toRadians(field.getZero().newInstance(77.5));
210 final T longitude = FastMath.toRadians(field.getZero().newInstance(137.5));
211 final T height = field.getZero().newInstance(0.0);
212 final FieldAbsoluteDate<T> date = FieldAbsoluteDate.createMJDDate(58940, field.getZero().newInstance(0.0), TimeScalesFactory.getUTC());
213 final URL url = GlobalPressureTemperature3Test.class.getClassLoader().getResource("gpt-grid/gpt3_5.grd");
214 final GlobalPressureTemperature3 model =
215 new GlobalPressureTemperature3(new DataSource(url.toURI()),
216 TimeScalesFactory.getUTC());
217
218 final FieldGeodeticPoint<T> location = new FieldGeodeticPoint<>(latitude, longitude, height);
219 final FieldViennaACoefficients<T> a = model.getA(location, date);
220 final FieldPressureTemperatureHumidity<T> pth = model.getWeatherParameters(location, date);
221 final FieldAzimuthalGradientCoefficients<T> gradient = model.getGradientCoefficients(location, date);
222
223 Assertions.assertEquals(0.001171577, a.getAh().getReal(), 1.0e-9);
224 Assertions.assertEquals(0.000574057, a.getAw().getReal(), 1.0e-9);
225 Assertions.assertEquals(273.15 - 18.589601195, pth.getTemperature().getReal(), 1.0e-9);
226 Assertions.assertEquals(1019.900868185, TroposphericModelUtils.HECTO_PASCAL.fromSI(pth.getPressure()).getReal(), 1.0e-9);
227 Assertions.assertEquals(1.251369020, TroposphericModelUtils.HECTO_PASCAL.fromSI(pth.getWaterVaporPressure()).getReal(), 1.0e-9);
228 Assertions.assertEquals(250.211896532, pth.getTm().getReal(), 1.0e-9);
229 Assertions.assertEquals(1.813332081, pth.getLambda().getReal(), 1.0e-9);
230 Assertions.assertEquals(0.000004818, gradient.getGnh().getReal(), 1.0e-9);
231 Assertions.assertEquals(0.000154168, gradient.getGeh().getReal(), 1.0e-9);
232 Assertions.assertEquals(0.000001018, gradient.getGnw().getReal(), 1.0e-9);
233 Assertions.assertEquals(0.000003392, gradient.getGew().getReal(), 1.0e-9);
234
235 }
236
237 @Test
238 public void testFieldMatlabRef2() throws IOException, URISyntaxException {
239 doTestFieldMatlabRef2(Binary64Field.getInstance());
240 }
241
242 protected <T extends CalculusFieldElement<T>> void doTestFieldMatlabRef2(final Field<T> field)
243 throws IOException, URISyntaxException {
244
245 Utils.setDataRoot("regular-data");
246
247
248 final T latitude = FastMath.toRadians(field.getZero().newInstance(80.0));
249 final T longitude = FastMath.toRadians(field.getZero().newInstance(120.0));
250 final T height = field.getZero().newInstance(100.0);
251 final FieldAbsoluteDate<T> date = FieldAbsoluteDate.createMJDDate(58940, field.getZero().newInstance(0.0), TimeScalesFactory.getUTC());
252 final URL url = GlobalPressureTemperature3Test.class.getClassLoader().getResource("gpt-grid/gpt3_5.grd");
253 final GlobalPressureTemperature3 model =
254 new GlobalPressureTemperature3(new DataSource(url.toURI()),
255 TimeScalesFactory.getUTC());
256
257 final FieldGeodeticPoint<T> location = new FieldGeodeticPoint<>(latitude, longitude, height);
258 final FieldViennaACoefficients<T> a = model.getA(location, date);
259 final FieldPressureTemperatureHumidity<T> pth = model.getWeatherParameters(location, date);
260 final FieldAzimuthalGradientCoefficients<T> gradient = model.getGradientCoefficients(location, date);
261
262 Assertions.assertEquals(0.001169367, a.getAh().getReal(), 1.0e-9);
263 Assertions.assertEquals(0.000577807, a.getAw().getReal(), 1.0e-9);
264 Assertions.assertEquals(273.15 - 19.730175236, pth.getTemperature().getReal(), 1.0e-9);
265 Assertions.assertEquals(1005.387362480, TroposphericModelUtils.HECTO_PASCAL.fromSI(pth.getPressure()).getReal(), 1.0e-9);
266 Assertions.assertEquals(1.034448353, TroposphericModelUtils.HECTO_PASCAL.fromSI(pth.getWaterVaporPressure()).getReal(), 1.0e-9);
267 Assertions.assertEquals(249.451317840, pth.getTm().getReal(), 1.0e-9);
268 Assertions.assertEquals(1.664833031, pth.getLambda().getReal(), 1.0e-9);
269 Assertions.assertEquals(0.000056837, gradient.getGnh().getReal(), 1.0e-9);
270 Assertions.assertEquals(0.000106616, gradient.getGeh().getReal(), 1.0e-9);
271 Assertions.assertEquals(0.000001235, gradient.getGnw().getReal(), 1.0e-9);
272 Assertions.assertEquals(0.000001584, gradient.getGew().getReal(), 1.0e-9);
273
274 }
275
276 @Test
277 public void testEquality() throws IOException, URISyntaxException {
278 doTestEquality("gpt-grid/gpt3_5.grd");
279 }
280
281 private void doTestEquality(final String resourceName) throws IOException, URISyntaxException {
282
283 Utils.setDataRoot("regular-data");
284
285
286
287
288
289 final AbsoluteDate date = AbsoluteDate.createMJDDate(56140, Constants.JULIAN_DAY - 1.0, TimeScalesFactory.getUTC());
290 final double latitude = FastMath.toRadians(45.0);
291 final double height = 0.0;
292
293 final URL url = GlobalPressureTemperature3Test.class.getClassLoader().getResource(resourceName);
294 GlobalPressureTemperature3 model = new GlobalPressureTemperature3(new DataSource(url.toURI()),
295 TimeScalesFactory.getUTC());
296
297
298 GeodeticPoint location1 = new GeodeticPoint(latitude, FastMath.toRadians(181.0), height);
299 ViennaACoefficients a1 = model.getA(location1, date);
300 PressureTemperatureHumidity pth1 = model.getWeatherParameters(location1, date);
301 GeodeticPoint location2 = new GeodeticPoint(latitude, FastMath.toRadians(-179.0), height);
302 ViennaACoefficients a2 = model.getA(location2, date);
303 PressureTemperatureHumidity pth2 = model.getWeatherParameters(location2, date);
304
305 Assertions.assertEquals(pth1.getTemperature(), pth2.getTemperature(), epsilon);
306 Assertions.assertEquals(pth1.getPressure(), pth2.getPressure(), epsilon);
307 Assertions.assertEquals(pth1.getWaterVaporPressure(), pth2.getWaterVaporPressure(), epsilon);
308 Assertions.assertEquals(a1.getAh(), a2.getAh(), epsilon);
309 Assertions.assertEquals(a1.getAw(), a2.getAw(), epsilon);
310
311
312 location1 = new GeodeticPoint(latitude, FastMath.toRadians(180.0), height);
313 a1 = model.getA(location1, date);
314 pth1 = model.getWeatherParameters(location1, date);
315 location2 = new GeodeticPoint(latitude, FastMath.toRadians(-180.0), height);
316 a2 = model.getA(location2, date);
317 pth2 = model.getWeatherParameters(location2, date);
318
319 Assertions.assertEquals(pth1.getTemperature(), pth2.getTemperature(), epsilon);
320 Assertions.assertEquals(pth1.getPressure(), pth2.getPressure(), epsilon);
321 Assertions.assertEquals(pth1.getWaterVaporPressure(), pth2.getWaterVaporPressure(), epsilon);
322 Assertions.assertEquals(a1.getAh(), a2.getAh(), epsilon);
323 Assertions.assertEquals(a1.getAw(), a2.getAw(), epsilon);
324
325
326 location1 = new GeodeticPoint(latitude, FastMath.toRadians(0.0), height);
327 a1 = model.getA(location1, date);
328 pth1 = model.getWeatherParameters(location1, date);
329 location2 = new GeodeticPoint(latitude, FastMath.toRadians(360.0), height);
330 a2 = model.getA(location2, date);
331 pth2 = model.getWeatherParameters(location2, date);
332
333 Assertions.assertEquals(pth1.getTemperature(), pth2.getTemperature(), epsilon);
334 Assertions.assertEquals(pth1.getPressure(), pth2.getPressure(), epsilon);
335 Assertions.assertEquals(pth1.getWaterVaporPressure(), pth2.getWaterVaporPressure(), epsilon);
336 Assertions.assertEquals(a1.getAh(), a2.getAh(), epsilon);
337 Assertions.assertEquals(a1.getAw(), a2.getAw(), epsilon);
338
339 }
340
341 @Test
342 public void testCorruptedFileBadData() throws IOException, URISyntaxException {
343
344 Utils.setDataRoot("regular-data");
345
346 final String fileName = "corrupted-bad-data-gpt3_15.grd";
347 final URL url = GlobalPressureTemperature3Test.class.getClassLoader().getResource("gpt-grid/" + fileName);
348 try {
349 new GlobalPressureTemperature3(new DataSource(url.toURI()), TimeScalesFactory.getUTC());
350 Assertions.fail("An exception should have been thrown");
351 } catch (OrekitException oe) {
352 Assertions.assertEquals(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, oe.getSpecifier());
353 Assertions.assertEquals(6, ((Integer) oe.getParts()[0]).intValue());
354 Assertions.assertTrue(((String) oe.getParts()[1]).endsWith(fileName));
355 }
356
357 }
358
359 @Test
360 public void testCorruptedIrregularGrid() throws IOException, URISyntaxException {
361
362 Utils.setDataRoot("regular-data");
363
364 final String fileName = "corrupted-irregular-grid-gpt3_15.grd";
365 final URL url = GlobalPressureTemperature3Test.class.getClassLoader().getResource("gpt-grid/" + fileName);
366 try {
367 new GlobalPressureTemperature3(new DataSource(url.toURI()), TimeScalesFactory.getUTC());
368 Assertions.fail("An exception should have been thrown");
369 } catch (OrekitException oe) {
370 Assertions.assertEquals(OrekitMessages.IRREGULAR_OR_INCOMPLETE_GRID, oe.getSpecifier());
371 Assertions.assertTrue(((String) oe.getParts()[0]).endsWith(fileName));
372 }
373
374 }
375
376 @Test
377 public void testCorruptedIncompleteHeader() throws IOException, URISyntaxException {
378
379 Utils.setDataRoot("regular-data");
380
381 final String fileName = "corrupted-incomplete-header.grd";
382 final URL url = GlobalPressureTemperature3Test.class.getClassLoader().getResource("gpt-grid/" + fileName);
383 try {
384 new GlobalPressureTemperature3(new DataSource(url.toURI()), TimeScalesFactory.getUTC());
385 Assertions.fail("An exception should have been thrown");
386 } catch (OrekitException oe) {
387 Assertions.assertEquals(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, oe.getSpecifier());
388 Assertions.assertEquals(1, ((Integer) oe.getParts()[0]).intValue());
389 Assertions.assertTrue(((String) oe.getParts()[1]).endsWith(fileName));
390 }
391
392 }
393
394 @Test
395 public void testCorruptedMissingSeasonalColumns() throws IOException, URISyntaxException {
396
397 Utils.setDataRoot("regular-data");
398
399 final String fileName = "corrupted-missing-seasonal-columns-gpt3_15.grd";
400 final URL url = GlobalPressureTemperature3Test.class.getClassLoader().getResource("gpt-grid/" + fileName);
401 try {
402 new GlobalPressureTemperature3(new DataSource(url.toURI()), TimeScalesFactory.getUTC());
403 Assertions.fail("An exception should have been thrown");
404 } catch (OrekitException oe) {
405 Assertions.assertEquals(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, oe.getSpecifier());
406 Assertions.assertEquals(1, ((Integer) oe.getParts()[0]).intValue());
407 Assertions.assertTrue(((String) oe.getParts()[1]).endsWith(fileName));
408 }
409
410 }
411
412 @Test
413 public void testCorruptedMissingDataFields() throws IOException, URISyntaxException {
414
415 Utils.setDataRoot("regular-data");
416
417 final String fileName = "corrupted-missing-data-fields-gpt3_15.grd";
418 final URL url = GlobalPressureTemperature3Test.class.getClassLoader().getResource("gpt-grid/" + fileName);
419 try {
420 new GlobalPressureTemperature3(new DataSource(url.toURI()), TimeScalesFactory.getUTC());
421 Assertions.fail("An exception should have been thrown");
422 } catch (OrekitException oe) {
423 Assertions.assertEquals(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, oe.getSpecifier());
424 Assertions.assertEquals(4, ((Integer) oe.getParts()[0]).intValue());
425 Assertions.assertTrue(((String) oe.getParts()[1]).endsWith(fileName));
426 }
427
428 }
429
430 }