WMM2025 World Magnetic Model...in simple Python.
The NOAA C reference implementation is wrapped with ctypes and exposed through a small NumPy-based API.
Tested on Linux, Mac and Windows.
At this time Visual Studio (MSVC) is not supported since MSVC doesn't export function symbols without additional headers,
which is typically done with something like SWIG.
On Windows use MinGW (the build selects the "MinGW Makefiles" generator unless CMAKE_GENERATOR is set).
Requirements: Python, NumPy, CMake (>= 3.14) and a C compiler.
git clone https://github.com/Navigraph/wmm2025
python -m pip install -e wmm2025This Python wrapper of WMM2025 uses a build-on-run technique.
The first time you import wmm2025, you will see messages from CMake and your C compiler.
The shared library is built into src/wmm2025/build/ and is rebuilt automatically
if CMakeLists.txt or any C source/header is newer than the built library.
All functions take geodetic latitude and longitude in degrees, altitude in km above the ellipsoid and time as a decimal year.
Field components (north, east, down, total) are in nT, decl and incl in degrees.
import wmm2025
mag = wmm2025.wmm_point(glat, glon, alt_km, yeardec)
# dict: glat, glon, north, east, down, total, incl, decl, timeglats and glons are 2-D arrays in numpy.meshgrid layout, evaluated at a single altitude:
import numpy as np
import wmm2025
lon, lat = np.meshgrid(np.arange(-180, 181, 10), np.arange(-90, 91, 10))
mag = wmm2025.wmm(lat, lon, alt_km, yeardec)
# dict: glat, glon (1-D axes), north, east, down, total, incl, decl (2-D), timeEvaluate many points at once. Each argument is either a scalar (held constant) or an array; all arrays must have the same shape:
mag = wmm2025.transect(glats, glons, alt_km, yeardec)
# dict: north, east, down, total, decl, incl (arrays, or floats if all inputs are scalars)The C layer keeps global state, so calls are serialized with a lock and are thread-safe but not parallel. For parallelism use separate processes.
RunWMM2025.py plots declination and inclination contours (requires matplotlib, available via the plot extra):
python -m pip install -e wmm2025[plot]
python RunWMM2025.py 2025.62 0where the arguments are the decimal year and the altitude in km.
python -m pip install -e wmm2025[tests,lint]
flake8
mypy
pytest- WMM2025 inclination map
- WMM2025 declination map
- WMM2025 test values