Determine the magnetic declination for virtually any place on the planet

How to determine the magnetic declination for virtually any place on the planet.

Magnetic declination is the difference between true North and magnetic North. The earth's magnetic field is constantly in motion.

Use the World Magnetic Model (WMM) World Magnetic Model (WMM) | National Centers for Environmental Information (NCEI)

The app WMMdeclination provides the magnetic declination information available in your app through the use of the GMM model at World Magnetic Model Calculator

The app uses a GET request.

You can also get magnetic declination information for any latitude and longitude manually using the calculator at NCEI Geomagnetic Calculators

Magnetic declination can be calculated mathematically from the WMM algorithm or a Web page can do the calculation for you. Use a GET request at a site like World Magnetic Model Calculator to provide an xml or json file which will provide all the magnetic information. Once you have that file, use dictionaries or List blocks to extract what is needed.

The magnetic information for today's date can be read in xml or json format. Decode the file using a dictionary. The app uses json format. The declination value is provided in degrees ( ° ) and west or east of North . The declination is from the model; it is not an actual measurement of the declination.

Textbox1, Textbox2 and Textbox can be replaced by LocationSensor Latitude, Longitude and Altitude*0.001 (to provide the altitude in km; the LS provides this in meters) respectively. Using the dictionary you can also capture all the magnetic information used in WMM.

Latitude and Longitude should be in degrees. Altitude should be input in km. above MSL.

WMMdeclination2.aia (3.6 KB)

Regards,
Steve

4 Likes

I've had a compass app, that includes a declination data GET for a few years that i've integrated into a much larger app. I'd always used the apps where I had a reasonable internet connection. Last night, I was out in the sticks and my whole world came crashing down (that's a bit dramatic, I know).

I've been querying XML data from http://geomag.bgs.ac.uk/web_service/GMModels/wmm/2020/.

In most cases, however, i'd be happy with a rough estimate if internet data times-out.

Could someone share some resources on a mathematically calculated method that i could integrate as a stop-gap if data is not available?

Thanks in advance.

Does that assume that your GPS is still working, in order to get coordinates ?

Yes. GPS was fine. Just no/poor Internet connectivity.

I've found a source of what is essentially a table of declinations that i'd probably just incorporate into the blocks, rather than referencing an external spreadhseet/database.

Just need to work on the code that looks up the list of lists (i'm thinking) based on the phone's GPS lat and long.

... and then maybe set myself a challenge to do some linear interpolation, which would be much more challenging, but provide a much better result.

Like this. How to Perform Bilinear Interpolation in Excel (with Easy Steps)

Now onto a long road.

or use magnetic variation Tables. Use the data only for the area where you are 'out in the sticks' . book of magnetic variation tables - Google Search

Have you noticed, the magnetic field does not vary dramatically over small latitude/longitude changes.
You could also calculate the magnetic field for several points where you expect to need the information but do not have Internet . Record the values and store them. If you don't want to buy a book, use the algorithm to produce a table of values for the latitudes/longitudes of interest.

Also you can use this Historical Declination Viewer to estimate the variation ahead of your trip.

So, i've got it working - mostly. AIA is attached for posterity.

Have my inclination data in a list of lists.

Credit to How to Perform Bilinear Interpolation in Excel (with Easy Steps) for the formula. It took me a while to get the order of operations right when converting to block, but I got there in the end.

A couple of issues:

  1. Haven't resolved how to manually input negative number on my keyboard. For some reason my android won't let me enter the "-" symbol. Won't be a problem when I programmatically enter the Lat/Lon from the GPS.
  2. Haven't limited the data entry of Longitude to +/- 180 and Latitude to +/-90. Won't be a problem when I programmatically enter the Lat/Lon from the GPS.
  3. This is the biggest issue. If I enter a Latitude or Longitude that is a multiple 10 exactly, the formula spits chips because it tries to divide 1 by zero. The GPS could spit out a whole number that will casue the crash in practice. Need to resovle this.

Bilinear_Interpolation.aia (10.5 KB)

While i'm at it, credit to the guy(s) who posted some declination data on github:

Okay, so I've finished these bits of code and I think I now have a working test app that can effectively get GPS coordinates while my phone has no data or is in airplane mode (with location still on).

It relies on the work of @TIMAI2 here: 🟥 Location Services with HTML5 GeoLocation to more effectively/reliably obtain GPS coordinates while offline. I found I needed to extend the timeout period to at least 10000ms for my particular phone.

and a python script from Daniel Agar here: PX4-ECL/geo_lookup/fetch_noaa_table.py at master · PX4/PX4-ECL · GitHub where I modified this script slightly to just obtain sea level declination data table in 5-degree increments (in lieu of 10). This data is imported into the app as a CSV file. This will need to be periodically updated with app updates. If you want to use this yourself, you'll need to obtain your own personal NOAA access key (free, at least for personal use, and limits probably apply).

and the bilinear formula published by Joyanta Mitra here: How to Perform Bilinear Interpolation in Excel (with Easy Steps). This is used to interpolate the above 5 degree declination data to get a more accurate reading on declination at the current location.

Thank you to all those who provided input here. I just wanted to leave this here for closure and to help anyone else in the community who wanted to utilise any of these three main items. Code attached.
Bilinear_Interpolation_V2.aia (17.5 KB)