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.displacement;
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.data.BodiesElements;
25  import org.orekit.data.FundamentalNutationArguments;
26  import org.orekit.errors.OrekitException;
27  import org.orekit.errors.OrekitMessages;
28  import org.orekit.time.AbsoluteDate;
29  import org.orekit.time.TimeScale;
30  import org.orekit.time.TimeScalesFactory;
31  import org.orekit.utils.IERSConventions;
32  
33  import java.util.List;
34  
35  public class OceanLoadingCoefficientsBLQFactoryTest {
36  
37      @Test
38      public void testTruncated() {
39          try {
40              OceanLoadingCoefficientsBLQFactory factory = new OceanLoadingCoefficientsBLQFactory("^truncated\\.blq$");
41              factory.getSites();
42              Assertions.fail("an exception should have been thrown");
43          } catch (OrekitException oe) {
44              Assertions.assertEquals(OrekitMessages.UNEXPECTED_END_OF_FILE_AFTER_LINE, oe.getSpecifier());
45              Assertions.assertEquals(10, oe.getParts()[1]);
46          }
47      }
48  
49      @Test
50      public void testCorrupted() {
51          try {
52              OceanLoadingCoefficientsBLQFactory factory = new OceanLoadingCoefficientsBLQFactory("^corrupted\\.blq$");
53              factory.getSites();
54              Assertions.fail("an exception should have been thrown");
55          } catch (OrekitException oe) {
56              Assertions.assertEquals(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, oe.getSpecifier());
57              Assertions.assertEquals(11, oe.getParts()[0]);
58          }
59      }
60  
61      @Test
62      public void testOrganization() {
63          TimeScale                          ut1     = TimeScalesFactory.getUT1(IERSConventions.IERS_2010, true);
64          FundamentalNutationArguments       fna     = IERSConventions.IERS_2010.getNutationArguments(ut1);
65          final BodiesElements               el      = fna.evaluateAll(AbsoluteDate.J2000_EPOCH);
66          OceanLoadingCoefficientsBLQFactory factory = new OceanLoadingCoefficientsBLQFactory("^hardisp\\.blq$");
67          List<String> sites = factory.getSites();
68          for (String site : sites) {
69              OceanLoadingCoefficients coeffs = factory.getCoefficients(site);
70              Assertions.assertEquals(3, coeffs.getNbSpecies());
71              Assertions.assertEquals(3, coeffs.getNbTides(0));
72              Assertions.assertEquals(4, coeffs.getNbTides(1));
73              Assertions.assertEquals(4, coeffs.getNbTides(2));
74              for (int i = 0; i < coeffs.getNbSpecies(); ++i) {
75                  for (int j = 1; j < coeffs.getNbTides(i); ++j) {
76                      // for each species, tides are sorted in increasing rate order
77                      Assertions.assertTrue(coeffs.getTide(i, j - 1).getRate(el) < coeffs.getTide(i, j).getRate(el));
78                  }
79              }
80          }
81      }
82  
83      @Test
84      public void testHardisp() {
85          OceanLoadingCoefficientsBLQFactory factory = new OceanLoadingCoefficientsBLQFactory("^hardisp\\.blq$");
86          List<String> sites = factory.getSites();
87          Assertions.assertEquals(2, sites.size());
88          Assertions.assertEquals("Onsala", sites.get(0));
89          Assertions.assertEquals("Reykjavik", sites.get(1));
90  
91          OceanLoadingCoefficients onsalaCoeffs = factory.getCoefficients("OnSaLa");
92          Assertions.assertEquals("Onsala", onsalaCoeffs.getSiteName());
93          Assertions.assertEquals(11.9264, FastMath.toDegrees(onsalaCoeffs.getSiteLocation().getLongitude()), 1.0e-15);
94          Assertions.assertEquals(57.3958, FastMath.toDegrees(onsalaCoeffs.getSiteLocation().getLatitude()),  1.0e-15);
95          Assertions.assertEquals( 0.0000, onsalaCoeffs.getSiteLocation().getAltitude(),                      1.0e-15);
96          Assertions.assertEquals( .00352, onsalaCoeffs.getZenithAmplitude(2, 1),                             1.0e-15);
97          Assertions.assertEquals( .00123, onsalaCoeffs.getZenithAmplitude(2, 2),                             1.0e-15);
98          Assertions.assertEquals( .00035, onsalaCoeffs.getWestAmplitude(2, 0),                               1.0e-15);
99          Assertions.assertEquals( .00008, onsalaCoeffs.getWestAmplitude(2, 3),                               1.0e-15);
100         Assertions.assertEquals( .00029, onsalaCoeffs.getSouthAmplitude(1, 3),                              1.0e-15);
101         Assertions.assertEquals( .00028, onsalaCoeffs.getSouthAmplitude(1, 1),                              1.0e-15);
102         Assertions.assertEquals(  -65.6, FastMath.toDegrees(-onsalaCoeffs.getZenithPhase(1, 2)),            1.0e-15);
103         Assertions.assertEquals( -138.1, FastMath.toDegrees(-onsalaCoeffs.getZenithPhase(1, 0)),            1.0e-15);
104         Assertions.assertEquals( -167.4, FastMath.toDegrees(-onsalaCoeffs.getWestPhase(0, 2)),              1.0e-15);
105         Assertions.assertEquals( -170.0, FastMath.toDegrees(-onsalaCoeffs.getWestPhase(0, 1)),              1.0e-15);
106         Assertions.assertEquals(    5.2, FastMath.toDegrees(-onsalaCoeffs.getSouthPhase(0, 0)),             1.0e-15);
107         Assertions.assertEquals(  109.5, FastMath.toDegrees(-onsalaCoeffs.getSouthPhase(2, 1)),             1.0e-15);
108 
109         // the coordinates for Reykjavik are *known* to be wrong in this test file
110         // these test data have been extracted from the HARDISP.F file in September 2017
111         // and it seems longitude and latitude have been exchanged...
112         // With the file coordinates, Reykjavik would be somewhere in the Indian Ocean, about 1800km East of Madagascar
113         // The error has been reported to IERS conventions center.
114         OceanLoadingCoefficients reykjavikCoeffs = factory.getCoefficients("Reykjavik");
115         Assertions.assertEquals("Reykjavik", reykjavikCoeffs.getSiteName());
116         Assertions.assertEquals( 64.1388, FastMath.toDegrees(reykjavikCoeffs.getSiteLocation().getLongitude()), 1.0e-15);
117         Assertions.assertEquals(-21.9555, FastMath.toDegrees(reykjavikCoeffs.getSiteLocation().getLatitude()),  1.0e-15);
118         Assertions.assertEquals(  0.0000, reykjavikCoeffs.getSiteLocation().getAltitude(),                      1.0e-15);
119         Assertions.assertEquals(  .00034, reykjavikCoeffs.getZenithAmplitude(0, 0),                             1.0e-15);
120         Assertions.assertEquals(  .00034, reykjavikCoeffs.getZenithAmplitude(0, 1),                             1.0e-15);
121         Assertions.assertEquals(  .00004, reykjavikCoeffs.getWestAmplitude(0, 2),                               1.0e-15);
122         Assertions.assertEquals(  .00018, reykjavikCoeffs.getWestAmplitude(1, 0),                               1.0e-15);
123         Assertions.assertEquals(  .00047, reykjavikCoeffs.getSouthAmplitude(1, 2),                              1.0e-15);
124         Assertions.assertEquals(  .00066, reykjavikCoeffs.getSouthAmplitude(1, 1),                              1.0e-15);
125         Assertions.assertEquals(   -52.0, FastMath.toDegrees(-reykjavikCoeffs.getZenithPhase(1, 3)),            1.0e-15);
126         Assertions.assertEquals(   104.1, FastMath.toDegrees(-reykjavikCoeffs.getZenithPhase(2, 3)),            1.0e-15);
127         Assertions.assertEquals(    38.9, FastMath.toDegrees(-reykjavikCoeffs.getWestPhase(2, 0)),              1.0e-15);
128         Assertions.assertEquals(    93.8, FastMath.toDegrees(-reykjavikCoeffs.getWestPhase(2, 2)),              1.0e-15);
129         Assertions.assertEquals(   156.2, FastMath.toDegrees(-reykjavikCoeffs.getSouthPhase(2, 1)),             1.0e-15);
130         Assertions.assertEquals(   179.7, FastMath.toDegrees(-reykjavikCoeffs.getSouthPhase(0, 0)),             1.0e-15);
131 
132     }
133 
134     @Test
135     public void testCompleteFormat() {
136         OceanLoadingCoefficientsBLQFactory factory = new OceanLoadingCoefficientsBLQFactory("^complete-format\\.blq$");
137         List<String> sites = factory.getSites();
138         Assertions.assertEquals(4, sites.size());
139         Assertions.assertEquals("GMRT",           sites.get(0));
140         Assertions.assertEquals("Goldstone",      sites.get(1));
141         Assertions.assertEquals("Noumea",         sites.get(2));
142         Assertions.assertEquals("Pleumeur-Bodou", sites.get(3));
143 
144         OceanLoadingCoefficients noumeaCoeffs = factory.getCoefficients("NOUMEA");
145         Assertions.assertEquals("Noumea", noumeaCoeffs.getSiteName());
146         Assertions.assertEquals(166.4433, FastMath.toDegrees(noumeaCoeffs.getSiteLocation().getLongitude()), 1.0e-15);
147         Assertions.assertEquals(-22.2711, FastMath.toDegrees(noumeaCoeffs.getSiteLocation().getLatitude()),  1.0e-15);
148         Assertions.assertEquals(  0.0000, noumeaCoeffs.getSiteLocation().getAltitude(),                      1.0e-15);
149         Assertions.assertEquals(  .02070, noumeaCoeffs.getZenithAmplitude(2, 1),                             1.0e-15);
150         Assertions.assertEquals(  .00346, noumeaCoeffs.getZenithAmplitude(2, 2),                             1.0e-15);
151         Assertions.assertEquals(  .00153, noumeaCoeffs.getWestAmplitude(2, 0),                               1.0e-15);
152         Assertions.assertEquals(  .00021, noumeaCoeffs.getWestAmplitude(2, 3),                               1.0e-15);
153         Assertions.assertEquals(  .00125, noumeaCoeffs.getSouthAmplitude(1, 3),                              1.0e-15);
154         Assertions.assertEquals(  .00101, noumeaCoeffs.getSouthAmplitude(1, 1),                              1.0e-15);
155         Assertions.assertEquals(  -152.1, FastMath.toDegrees(-noumeaCoeffs.getZenithPhase(1, 2)),            1.0e-15);
156         Assertions.assertEquals(   164.2, FastMath.toDegrees(-noumeaCoeffs.getZenithPhase(1, 0)),            1.0e-15);
157         Assertions.assertEquals(   -89.7, FastMath.toDegrees(-noumeaCoeffs.getWestPhase(0, 2)),              1.0e-15);
158         Assertions.assertEquals(  -133.6, FastMath.toDegrees(-noumeaCoeffs.getWestPhase(0, 1)),              1.0e-15);
159         Assertions.assertEquals(  -179.0, FastMath.toDegrees(-noumeaCoeffs.getSouthPhase(0, 0)),             1.0e-15);
160         Assertions.assertEquals(   -56.2, FastMath.toDegrees(-noumeaCoeffs.getSouthPhase(2, 1)),             1.0e-15);
161 
162     }
163 
164     @Test
165         public void testSeveralFiles() {
166             OceanLoadingCoefficientsBLQFactory factory =
167                             new OceanLoadingCoefficientsBLQFactory("^(?:(?:hardisp)|(?:complete-format))\\.blq$");
168             List<String> sites = factory.getSites();
169             Assertions.assertEquals(6, sites.size());
170             Assertions.assertEquals("GMRT",           sites.get(0));
171             Assertions.assertEquals("Goldstone",      sites.get(1));
172             Assertions.assertEquals("Noumea",         sites.get(2));
173             Assertions.assertEquals("Onsala",         sites.get(3));
174             Assertions.assertEquals("Pleumeur-Bodou", sites.get(4));
175             Assertions.assertEquals("Reykjavik",      sites.get(5));
176     }
177 
178     @BeforeEach
179     public void setUp() throws Exception {
180         Utils.setDataRoot("regular-data:oso-blq");
181     }
182 
183 }