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.models.earth.weather;
18  
19  import org.hipparchus.util.FastMath;
20  import org.junit.jupiter.api.Assertions;
21  import org.junit.jupiter.api.BeforeEach;
22  import org.junit.jupiter.api.Test;
23  import org.orekit.Utils;
24  import org.orekit.bodies.GeodeticPoint;
25  import org.orekit.data.DataContext;
26  import org.orekit.errors.OrekitException;
27  import org.orekit.forces.gravity.potential.GRGSFormatReader;
28  import org.orekit.forces.gravity.potential.GravityFieldFactory;
29  import org.orekit.frames.FramesFactory;
30  import org.orekit.models.earth.Geoid;
31  import org.orekit.models.earth.ReferenceEllipsoid;
32  import org.orekit.models.earth.troposphere.TroposphericModelUtils;
33  import org.orekit.time.AbsoluteDate;
34  import org.orekit.time.TimeScalesFactory;
35  import org.orekit.utils.IERSConventions;
36  
37  public class GlobalPressureTemperatureTest {
38  
39      @BeforeEach
40      public void setUp() throws OrekitException {
41          Utils.setDataRoot("regular-data:potential");
42          GravityFieldFactory.addPotentialCoefficientsReader(new GRGSFormatReader("grim4s4_gr", true));
43      }
44  
45      @Test
46      public void testParameterComputation() {
47  
48          // Site Toulouse, Cité de l'Espace (France): latitude:  43.59°N
49          //                                           longitude: 1.49°E
50          //                                           height:    140 m
51          //
52          // Date: 09 January 2019 at 0h UT
53          //
54          // Expected outputs are obtained by performing the Matlab script gpt.m provided by TU WIEN:
55          // http://vmf.geo.tuwien.ac.at/codes/
56          //
57          // Expected parameters : temperature -> 7.3311 °C
58          //                       pressure    -> 1010.2749 hPa
59          //
60          // The real weather conditions are obtained with www.infoclimat.fr
61          //
62          // Real weather conditions: temperature -> 7.3 °C
63          //                          pressure    -> 1027.5 hPa
64  
65          final AbsoluteDate date = new AbsoluteDate(2019, 1, 8, 0, 0, 0.0, TimeScalesFactory.getUTC());
66          final GeodeticPoint location = new GeodeticPoint(FastMath.toRadians(43.59),
67                                                           FastMath.toRadians(1.49),
68                                                           140.0);
69  
70          // Given by the model
71          final double expectedTemperature = 7.3311;
72          final double expectedPressure    = 1010.2749;
73  
74          final DataContext dataContext = DataContext.getDefault();
75          final Geoid geoid = new Geoid(dataContext.getGravityFields().getNormalizedProvider(9, 9),
76                                        ReferenceEllipsoid.getWgs84(FramesFactory.getITRF(IERSConventions.IERS_2010, true)));
77          final GlobalPressureTemperature model = new GlobalPressureTemperature(geoid,
78                                                                                dataContext.getTimeScales().getUTC());
79          PressureTemperature pt = model.getWeatherParameters(location, date);
80  
81          final double computedTemperature = pt.getTemperature() - 273.15;
82          final double computedPressure    = TroposphericModelUtils.HECTO_PASCAL.fromSI(pt.getPressure());
83  
84          Assertions.assertEquals(expectedPressure,    computedPressure,    0.1);
85          Assertions.assertEquals(expectedTemperature, computedTemperature, 0.1);
86  
87          // Real weather conditions
88          final double realTemperature = 7.3;
89          final double realPressure    = 1027.5;
90  
91          // We test the model accuracy (10°C and 20 hPa)
92          Assertions.assertEquals(realTemperature, computedTemperature,    10);
93          Assertions.assertEquals(realPressure,    computedPressure,       20);
94      }
95  
96      @Test
97      public void testHighAltitude() {
98  
99          // Site Pic du Midi de Bigorre (France): latitude:  42.94°N
100         //                                       longitude: 0.14°E
101         //                                       height:    2877 m
102         //
103         // Date: 09 January 2019 at 0h UT
104         //
105         // Expected outputs are obtained by performing the Matlab script gpt.m provided by TU WIEN:
106         // http://vmf.geo.tuwien.ac.at/codes/
107         //
108         // Expected parameters : temperature -> -9.88 °C
109         //                       pressure    -> 723.33 hPa
110         //
111         // The real weather conditions are obtained by the Laboratoire d'Aérologie de l'Observatoire Midi Pyrénées
112         //
113         // Real weather conditions: temperature -> -8.3 °C
114         //                          pressure    -> 717.9 hPa
115 
116         final AbsoluteDate date = new AbsoluteDate(2019, 1, 8, 0, 0, 0.0, TimeScalesFactory.getUTC());
117         final GeodeticPoint location = new GeodeticPoint(FastMath.toRadians(42.94),
118                                                          FastMath.toRadians(0.14),
119                                                          2877);
120 
121         // Given by the model
122         final double expectedTemperature = -9.88;
123         final double expectedPressure    = 723.33;
124 
125         final DataContext dataContext = DataContext.getDefault();
126         final Geoid geoid = new Geoid(dataContext.getGravityFields().getNormalizedProvider(9, 9),
127                                       ReferenceEllipsoid.getWgs84(FramesFactory.getITRF(IERSConventions.IERS_2010, true)));
128         final GlobalPressureTemperature model = new GlobalPressureTemperature(geoid,
129                                                                               dataContext.getTimeScales().getUTC());
130         PressureTemperature pt = model.getWeatherParameters(location, date);
131 
132 
133         final double computedTemperature = pt.getTemperature() - 273.15;
134         final double computedPressure    = TroposphericModelUtils.HECTO_PASCAL.fromSI(pt.getPressure());
135 
136         Assertions.assertEquals(expectedPressure,    computedPressure,    0.1);
137         Assertions.assertEquals(expectedTemperature, computedTemperature, 0.1);
138 
139         // Real weather conditions
140         final double realTemperature = -8.3;
141         final double realPressure    = 717.9;
142 
143         // We test the model accuracy (10°C and 20 hPa)
144         Assertions.assertEquals(realTemperature, computedTemperature,    10);
145         Assertions.assertEquals(realPressure,    computedPressure,       20);
146     }
147 
148 }