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