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