Bug #178

magnetic field declination is NaN for dates like 1995-01-01 or 2005-0101

Added by Luc Maisonobe almost 4 years ago. Updated over 3 years ago.

Status:ClosedStart date:2014-08-14
Priority:NormalDue date:
Assignee:-% Done:


Target version:-


The following code returns a NaN for magnetic field declination:

    public void testIntepolationYYY5() throws OrekitException {
        double decimalYear = GeoMagneticField.getDecimalYear(1, 1, 2005);
        GeoMagneticField field = GeoMagneticFieldFactory.getIGRF(decimalYear);
        GeoMagneticElements e = field.calculateField(1.2, 0.7, -340);
        Assert.assertEquals(-5.6164, e.getDeclination(), 1.0e-4);

magnetic_field.patch Magnifier (13 KB) Thomas Neidhart, 2014-08-15 13:30


#1 Updated by Luc Maisonobe almost 4 years ago

The problem seems to be due to a division by zero in GeoMagneticField.getModel when the decimal year is close to the epoch, but superior to it.
For example 2005.002 when the epoch is 2005.

Replacing the test
if (model.getEpoch() < year)
if (model.getEpoch() < 0.01 * epoch)
seem to be a workaround, but I'm not sure it is the correct way to fix the problem.

#2 Updated by Thomas Neidhart almost 4 years ago

The attached patch fixes the following problems:

  • GeoMagneticField.getDecimalYear() returned a slightly wrong result: e.g. for 1/1/2005 returned 2005.0020 instead of 2005.0
  • fix the GeoMagneticFieldFactory.getModel() method: use proper headMap and tailMap method with inclusive/exclusive behavior
  • add validity check to GeoMagneticField.transformModel(double) method: did not check before if the request year is outside validity period
  • added more unit tests
  • adapted existing tests for IGRF/WMM with sample values / results as they have changed slightly

The results were compared with the online calculator available here: http://www.ngdc.noaa.gov/geomag-web/#igrfwmm
and are more correct than before (less deviation). There are still some slight differences, but I verified the results with 3 different tools and all of them produce different results for the intensity although using the same model (geomag tool, wmm for linux and the online calculator).

#3 Updated by Luc Maisonobe almost 4 years ago

  • Status changed from New to Resolved

The patch has been applied with a small change in the test values (the initial test I made up in the report was not realistic).
See 20df09d0.

Thanks to Thomas for the patch!

#4 Updated by Luc Maisonobe over 3 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF