Skip to main content

Magnetic variation (aka declination) for aviation navigation

Project description

The magvar module

This module provides the function

`magnetic_variation(date, latitude, longitude, elevation)`

date must be a float - the Julian date. Example: 2022.1 is in February.

latitude is in radians, positive for north, negative for south.

longitude is in radians, positive for east, negative for west.

elevation is in meters.

This returns what the geo-scientists would call 'declination' but what aviators call 'magnetic variation'.

The result is in radians, and is negative for EAST "east is least" and positive for WEST.

For example:

>>> from geomag import magnetic_variation
>>> from math import degrees, radians

>>> degrees(magnetic_variation(2022.05,
                               radians(25.7953611),
                               radians(-80.2901158),
                               3)
6.9474...

This shows the magnetic variation for the Miami Internation Airport (KMIA) as 6.9 degrees WEST, which matches what the sectional chart for January 2022.

Building from COF files

This distribution includes WMM2010.COF, WMM2015.COF, WMM2020.COF, and WMM2025.COF.

These files were downloaded from the National Centers for Environmental Information (NCEI), formerly known as the National Geophysical Data Center (NGDC).

[NCEI](https://www.ncei.noaa.gov/products/world-magnetic-model)

The file wmm.c contains static data compiled from these .COF files.

To generate the file from scratch, use the `compile-cof' script:

$ ./compile-cof WMM2010.COF WMM2015.COF WMM2020.COF WMM2025.COF >wmm.c

This incorporates all models, so you can get the magnetic variation for any latitude and longitude from any date from January 1, 2010.

If you're tight on space, and only need the current magnetic model:

$ ./compile-cof WMM2025.COF >wmm.c

Testing the Software

The test subdirectory has test values from the NCEI.

Test the Python:

$ cd test
$ python3 test_values.py *.txt

Test the C code:

$ cd test
$ make
$ ./test_magvar *.txt
$ make clean

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

magvar-1.1.tar.gz (30.9 kB view details)

Uploaded Source

File details

Details for the file magvar-1.1.tar.gz.

File metadata

  • Download URL: magvar-1.1.tar.gz
  • Upload date:
  • Size: 30.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for magvar-1.1.tar.gz
Algorithm Hash digest
SHA256 9e85b2201f1ccc296733db01ebca17c729836a2d112d619497861d2dceec4593
MD5 71afb77168fd1209f61381c5cd55fec6
BLAKE2b-256 f4fdc3d78cacef8dafaa10db215586310e72e9dddc4100b0f9f5c0e89d9aab87

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page