1   /* Copyright 2011-2012 Space Applications Services
2    * Licensed to CS Communication & Systèmes (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.troposphere;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.hipparchus.Field;
21  import org.hipparchus.util.Binary64Field;
22  import org.hipparchus.util.FastMath;
23  import org.hipparchus.util.Precision;
24  import org.junit.jupiter.api.Assertions;
25  import org.junit.jupiter.api.BeforeAll;
26  import org.junit.jupiter.api.BeforeEach;
27  import org.junit.jupiter.api.Test;
28  import org.orekit.Utils;
29  import org.orekit.bodies.FieldGeodeticPoint;
30  import org.orekit.bodies.GeodeticPoint;
31  import org.orekit.models.earth.weather.FieldPressureTemperatureHumidity;
32  import org.orekit.time.AbsoluteDate;
33  import org.orekit.time.FieldAbsoluteDate;
34  import org.orekit.utils.FieldTrackingCoordinates;
35  import org.orekit.utils.TrackingCoordinates;
36  
37  public class FixedTroposphericModelTest {
38  
39      private static double epsilon = 1e-6;
40  
41      private TroposphericModel model;
42  
43      @Test
44      public void testModel() {
45          // check with (artificial) test values from tropospheric-delay.txt
46          Assertions.assertEquals(2.5d,
47                                  model.pathDelay(new TrackingCoordinates(0.0, FastMath.toRadians(90d), 0.0),
48                                                  new GeodeticPoint(0., 0., 0.),
49                                                  TroposphericModelUtils.STANDARD_ATMOSPHERE,
50                                                  null, AbsoluteDate.J2000_EPOCH).getDelay(),
51                                  epsilon);
52          Assertions.assertEquals(20.8d,
53                                  model.pathDelay(new TrackingCoordinates(0.0, FastMath.toRadians(0d), 0.0),
54                                                  new GeodeticPoint(0., 0., 0.),
55                                                  TroposphericModelUtils.STANDARD_ATMOSPHERE,
56                                                  null, AbsoluteDate.J2000_EPOCH).getDelay(),
57                                  epsilon);
58  
59          Assertions.assertEquals(12.1d,
60                                  model.pathDelay(new TrackingCoordinates(0.0, FastMath.toRadians(0d), 0.0),
61                                                  new GeodeticPoint(0., 0., 5000.),
62                                                  TroposphericModelUtils.STANDARD_ATMOSPHERE,
63                                                  null, AbsoluteDate.J2000_EPOCH).getDelay(),
64                                  epsilon);
65          Assertions.assertEquals(2.5d,
66                                  model.pathDelay(new TrackingCoordinates(0.0, FastMath.toRadians(90d), 0.0),
67                                                  new GeodeticPoint(0., 0., 5000.),
68                                                  TroposphericModelUtils.STANDARD_ATMOSPHERE,
69                                                  null, AbsoluteDate.J2000_EPOCH).getDelay(),
70                                  epsilon);
71  
72          // interpolation between two elevation angles in the table
73          final double delay = model.pathDelay(new TrackingCoordinates(0.0, FastMath.toRadians(35d), 0.0),
74                                               new GeodeticPoint(0., 0., 1200.),
75                                               TroposphericModelUtils.STANDARD_ATMOSPHERE,
76                                               null, AbsoluteDate.J2000_EPOCH).getDelay();
77          Assertions.assertTrue(Precision.compareTo(delay, 6.4d, epsilon) < 0);
78          Assertions.assertTrue(Precision.compareTo(delay, 3.2d, epsilon) > 0);
79  
80          // sanity checks
81          Assertions.assertEquals(12.1d,
82                                  model.pathDelay(new TrackingCoordinates(0.0, FastMath.toRadians(-20d), 0.0),
83                                                  new GeodeticPoint(0., 0., 5000.),
84                                                  TroposphericModelUtils.STANDARD_ATMOSPHERE,
85                                                  null, AbsoluteDate.J2000_EPOCH).getDelay(),
86                                  epsilon);
87          Assertions.assertEquals(2.5d,
88                                  model.pathDelay(new TrackingCoordinates(0.0, FastMath.toRadians(90d),0.0),
89                                                  new GeodeticPoint(0., 0., 100000.),
90                                                  TroposphericModelUtils.STANDARD_ATMOSPHERE,
91                                                  null, AbsoluteDate.J2000_EPOCH).getDelay(),
92                                  epsilon);
93      }
94  
95      @Test
96      public void testFieldModel() {
97          doTestFieldModel(Binary64Field.getInstance());
98      }
99  
100     private <T extends CalculusFieldElement<T>> void doTestFieldModel(final Field<T> field) {
101         final T zero = field.getZero();
102         // check with (artificial) test values from tropospheric-delay.txt
103         Assertions.assertEquals(2.5d,
104                                 model.pathDelay(new FieldTrackingCoordinates<>(zero, zero.newInstance(FastMath.toRadians(90d)), zero),
105                                                 new FieldGeodeticPoint<T>(zero, zero, zero),
106                                                 new FieldPressureTemperatureHumidity<T>(field, TroposphericModelUtils.STANDARD_ATMOSPHERE),
107                                                 null, FieldAbsoluteDate.getJ2000Epoch(field)).getDelay().getReal(),
108                                 epsilon);
109         Assertions.assertEquals(20.8d,
110                                 model.pathDelay(new FieldTrackingCoordinates<>(zero, zero.newInstance(FastMath.toRadians(0d)), zero),
111                                                 new FieldGeodeticPoint<T>(zero, zero, zero),
112                                                 new FieldPressureTemperatureHumidity<T>(field, TroposphericModelUtils.STANDARD_ATMOSPHERE),
113                                                 null, FieldAbsoluteDate.getJ2000Epoch(field)).getDelay().getReal(),
114                                 epsilon);
115 
116         Assertions.assertEquals(12.1d,
117                                 model.pathDelay(new FieldTrackingCoordinates<>(zero, zero.newInstance(FastMath.toRadians(0d)), zero),
118                                                 new FieldGeodeticPoint<T>(zero, zero, zero.add(5000.0)),
119                                                 new FieldPressureTemperatureHumidity<T>(field, TroposphericModelUtils.STANDARD_ATMOSPHERE),
120                                                 null, FieldAbsoluteDate.getJ2000Epoch(field)).getDelay().getReal(),
121                                 epsilon);
122         Assertions.assertEquals(2.5d,
123                                 model.pathDelay(new FieldTrackingCoordinates<>(zero, zero.newInstance(FastMath.toRadians(90d)), zero),
124                                                 new FieldGeodeticPoint<T>(zero, zero, zero.add(5000.0)),
125                                                 new FieldPressureTemperatureHumidity<T>(field, TroposphericModelUtils.STANDARD_ATMOSPHERE),
126                                                 null, FieldAbsoluteDate.getJ2000Epoch(field)).getDelay().getReal(),
127                                 epsilon);
128 
129         // interpolation between two elevation angles in the table
130         final double delay = model.pathDelay(new FieldTrackingCoordinates<>(zero, zero.newInstance(FastMath.toRadians(35d)), zero),
131                                              new FieldGeodeticPoint<T>(zero, zero, zero.add(1200.0)),
132                                              new FieldPressureTemperatureHumidity<T>(field, TroposphericModelUtils.STANDARD_ATMOSPHERE),
133                                              null, FieldAbsoluteDate.getJ2000Epoch(field)).getDelay().getReal();
134         Assertions.assertTrue(Precision.compareTo(delay, 6.4d, epsilon) < 0);
135         Assertions.assertTrue(Precision.compareTo(delay, 3.2d, epsilon) > 0);
136 
137         // sanity checks
138         Assertions.assertEquals(12.1d,
139                                 model.pathDelay(new FieldTrackingCoordinates<>(zero, zero.newInstance(FastMath.toRadians(-20d)), zero),
140                                                 new FieldGeodeticPoint<T>(zero, zero, zero.add(5000.0)),
141                                                 new FieldPressureTemperatureHumidity<T>(field, TroposphericModelUtils.STANDARD_ATMOSPHERE),
142                                                 null, FieldAbsoluteDate.getJ2000Epoch(field)).getDelay().getReal(),
143                                 epsilon);
144         Assertions.assertEquals(2.5d,
145                                 model.pathDelay(new FieldTrackingCoordinates<>(zero, zero.newInstance(FastMath.toRadians(90d)), zero),
146                                                 new FieldGeodeticPoint<T>(zero, zero, zero.add(100000.0)),
147                                                 new FieldPressureTemperatureHumidity<T>(field, TroposphericModelUtils.STANDARD_ATMOSPHERE),
148                                                 null, FieldAbsoluteDate.getJ2000Epoch(field)).getDelay().getReal(),
149                                 epsilon);
150     }
151 
152     @Test
153     public void testSymmetry() {
154         for (int elevation = 0; elevation < 90; elevation += 10) {
155             final double delay1 = model.pathDelay(new TrackingCoordinates(0.0, FastMath.toRadians(elevation), 0.0),
156                                                   new GeodeticPoint(0., 0., 100.),
157                                                   TroposphericModelUtils.STANDARD_ATMOSPHERE, null, AbsoluteDate.J2000_EPOCH).getDelay();
158             final double delay2 = model.pathDelay(new TrackingCoordinates(0.0, FastMath.toRadians(180 - elevation), 0.0),
159                                                   new GeodeticPoint(0., 0., 100.),
160                                                   TroposphericModelUtils.STANDARD_ATMOSPHERE, null, AbsoluteDate.J2000_EPOCH).getDelay();
161 
162             Assertions.assertEquals(delay1, delay2, epsilon);
163         }
164     }
165 
166     @Test
167     public void testFieldSymmetry() {
168         doTestFieldSymmetry(Binary64Field.getInstance());
169     }
170 
171     private <T extends CalculusFieldElement<T>> void doTestFieldSymmetry(final Field<T> field) {
172         final T zero = field.getZero();
173         for (int elevation = 0; elevation < 90; elevation += 10) {
174             final T delay1 = model.pathDelay(new FieldTrackingCoordinates<>(zero, zero.newInstance(FastMath.toRadians(elevation)), zero),
175                                              new FieldGeodeticPoint<T>(zero, zero, zero.add(100.)),
176                                              new FieldPressureTemperatureHumidity<T>(field, TroposphericModelUtils.STANDARD_ATMOSPHERE),
177                                              null,
178                                              FieldAbsoluteDate.getJ2000Epoch(field)).getDelay();
179             final T delay2 = model.pathDelay(new FieldTrackingCoordinates<>(zero, zero.newInstance(FastMath.toRadians(180 - elevation)), zero),
180                                              new FieldGeodeticPoint<T>(zero, zero, zero.add(100.)),
181                                              new FieldPressureTemperatureHumidity<T>(field, TroposphericModelUtils.STANDARD_ATMOSPHERE),
182                                                              null,
183                                              FieldAbsoluteDate.getJ2000Epoch(field)).getDelay();
184 
185             Assertions.assertEquals(delay1.getReal(), delay2.getReal(), epsilon);
186         }
187     }
188 
189     @BeforeAll
190     public static void setUpGlobal() {
191         Utils.setDataRoot("atmosphere");
192     }
193 
194     @BeforeEach
195     public void setUp() throws Exception {
196         model = FixedTroposphericDelay.getDefaultModel();
197     }
198 }