@SuppressWarnings("unused") private void validate(final GeoMagneticElements ge, final String outputLine) throws Exception { final StringTokenizer st = new StringTokenizer(outputLine); final double year = getYear(st.nextToken()); final String coord = st.nextToken(); final String heightStr = st.nextToken(); final String latStr = st.nextToken(); final String lonStr = st.nextToken(); final double dec = getDegree(st.nextToken(), st.nextToken()); final double inc = getDegree(st.nextToken(), st.nextToken()); final double h = Double.valueOf(st.nextToken()); final double x = Double.valueOf(st.nextToken()); final double y = Double.valueOf(st.nextToken()); final double z = Double.valueOf(st.nextToken()); final double f = Double.valueOf(st.nextToken()); final double eps = 1e-1; Assert.assertEquals(h, ge.getHorizontalIntensity(), eps); Assert.assertEquals(f, ge.getTotalIntensity(), eps); Assert.assertEquals(x, ge.getFieldVector().getX(), eps); Assert.assertEquals(y, ge.getFieldVector().getY(), eps); Assert.assertEquals(z, ge.getFieldVector().getZ(), eps); Assert.assertEquals(dec, ge.getDeclination(), eps); Assert.assertEquals(inc, ge.getInclination(), eps); }
@Test public void testIGRF() throws Exception { // test values from sample coordinate file // provided as part of the geomag 7.0 distribution available at // http://www.ngdc.noaa.gov/IAGA/vmod/igrf.html // modification: the julian day calculation of geomag is slightly different // to the one from the WMM code, we use the WMM convention thus the outputs // have been adapted. runSampleFile(FieldModel.IGRF, "sample_coords.txt", "sample_out_IGRF12.txt"); final double eps = 1e-1; final double degreeEps = 1e-2; for (int i = 0; i < igrfTestValues.length; i++) { final GeoMagneticField model = GeoMagneticFieldFactory.getIGRF(igrfTestValues[i][0]); final GeoMagneticElements result = model.calculateField(igrfTestValues[i][2], igrfTestValues[i][3], igrfTestValues[i][1]); final Vector3D b = result.getFieldVector(); // X Assert.assertEquals(igrfTestValues[i][4], b.getX(), eps); // Y Assert.assertEquals(igrfTestValues[i][5], b.getY(), eps); // Z Assert.assertEquals(igrfTestValues[i][6], b.getZ(), eps); // H Assert.assertEquals(igrfTestValues[i][7], result.getHorizontalIntensity(), eps); // F Assert.assertEquals(igrfTestValues[i][8], result.getTotalIntensity(), eps); // inclination Assert.assertEquals(igrfTestValues[i][9], result.getInclination(), degreeEps); // declination Assert.assertEquals(igrfTestValues[i][10], result.getDeclination(), degreeEps); } }
@Test public void testWMMWithHeightAboveMSL() throws Exception { // test results for test values provided as part of the WMM2015 Report // using height above MSL instead of height above ellipsoid // the results have been obtained from the NOAA online calculator: // http://www.ngdc.noaa.gov/geomag-web/#igrfwmm final double[][] testValues = { // Date Alt Lat Lon X Y Z H F I D // km deg deg nT nT nT nT nT deg deg {2015.0, 100, 80, 0, 6314.2, -471.6, 52269.1, 6331.8, 52651.2, 83.093, -4.271}, {2015.0, 100, 0, 120, 37534.4, 364.3, -10773.1, 37536.2, 39051.6, -16.013, 0.556}, {2015.0, 100, -80, 240, 5613.2, 14791.9, -50379.6, 15821.1, 52805.4, -72.565, 69.219} }; final Geoid geoid = new Geoid(potential, WGS84); final double eps = 1e-1; final double degreeEps = 1e-2; for (int i = 0; i < testValues.length; i++) { final AbsoluteDate date = new AbsoluteDate(2015, 1, 1, TimeScalesFactory.getUTC()); final GeoMagneticField model = GeoMagneticFieldFactory.getWMM(testValues[i][0]); final double undulation = geoid.getUndulation( FastMath.toRadians(testValues[i][2]), FastMath.toRadians(testValues[i][3]), date); final GeoMagneticElements result = model.calculateField( testValues[i][2], testValues[i][3], testValues[i][1] + undulation / 1000d); // X Assert.assertEquals(testValues[i][4], result.getFieldVector().getX(), eps); // Y Assert.assertEquals(testValues[i][5], result.getFieldVector().getY(), eps); // Z Assert.assertEquals(testValues[i][6], result.getFieldVector().getZ(), eps); // H Assert.assertEquals(testValues[i][7], result.getHorizontalIntensity(), eps); // F Assert.assertEquals(testValues[i][8], result.getTotalIntensity(), eps); // inclination Assert.assertEquals(testValues[i][9], result.getInclination(), degreeEps); // declination Assert.assertEquals(testValues[i][10], result.getDeclination(), degreeEps); } }
@Test public void testLoadOriginalWMMModel() throws Exception { GeoMagneticModelLoader loader = new GeoMagneticModelLoader(); InputStream input = getResource("WMM2015.COF"); loader.loadData(input, "WMM2015.COF"); Collection<GeoMagneticField> models = loader.getModels(); Assert.assertNotNull(models); Assert.assertEquals(1, models.size()); GeoMagneticField wmmModel = models.iterator().next(); Assert.assertEquals("WMM-2015", wmmModel.getModelName()); Assert.assertEquals(2015, wmmModel.getEpoch(), 1e-9); final double eps = 1e-1; final double degreeEps = 1e-2; for (int i = 0; i < wmmTestValues.length; i++) { if (wmmTestValues[i][0] != wmmModel.getEpoch()) { continue; } final GeoMagneticElements result = wmmModel.calculateField(wmmTestValues[i][2], wmmTestValues[i][3], wmmTestValues[i][1]); // X Assert.assertEquals(wmmTestValues[i][4], result.getFieldVector().getX(), eps); // Y Assert.assertEquals(wmmTestValues[i][5], result.getFieldVector().getY(), eps); // Z Assert.assertEquals(wmmTestValues[i][6], result.getFieldVector().getZ(), eps); // H Assert.assertEquals(wmmTestValues[i][7], result.getHorizontalIntensity(), eps); // F Assert.assertEquals(wmmTestValues[i][8], result.getTotalIntensity(), eps); // inclination Assert.assertEquals(wmmTestValues[i][9], result.getInclination(), degreeEps); // declination Assert.assertEquals(wmmTestValues[i][10], result.getDeclination(), degreeEps); } }