Skip to main content

WMM Python module

PyPI - Version PyPI - Python Version PyPI - License PyPI Downloads PyPI Downloads

This is a Python implementation of the latest World Magnetic Model(WMM) by the Cooperative Institute For Research in Environmental Sciences (CIRES), University of Colorado. The World Magnetic Model (WMM) is the standard model for navigation, attitude, and heading referencing systems that use the geomagnetic field.

A new version of the model is updated every five years to address changes in Earth’s magnetic field. The current version (WMM2025) was released on December 17, 2024, and will remain valid until late 2029.

For more information about the WMM model, please visit WMM website.

NCEI also developed the World Magnetic Model High Resolution (WMMHR), an advanced magnetic field model with more comprehensive data on the geomagnetic fields than the original World Magnetic Model.

The Python API for WMMHR: https://pypi.org/project/wmmhr/

Table of contents

Installation

The recommended way to install wmm-calculator is via pip

pip install wmm-calculator 

Outputs

It will output the magnetic components(X, Y, Z, H, F, I and D, dX, dY, dZ, dD, dI, dH, dF) and its uncertainty value. To get the detail of the outputs, please see Description of the WMM magnetic components

WMM Python API Quick Start

WARNING: Input arrays of length 3,000,000 require ~ 16GB of memory. However, all input vectors must have the same length.

Get magnetic components

Set up the time and latitude and longtitude and altitude for the WMM model

from wmm import wmm_calc
model = wmm_calc()
lat = [23.35, 24.5]
lon = [40, 45]
alt = [21, 21]

year = [2025, 2026]
month = [12, 1]
day = [6, 15]

# set up time
model.setup_time(year, month, day)
# set up the coordinates
model.setup_env(lat, lon, alt)

Get all of the geomagnetic elements

mag_map = model.get_all()
print(model.get_all())

It will return

{'x': array([33805.9794844 , 33492.10462007]), 'y': array([2167.06741335, 1899.8602046 ]), 'z': array([23844.95317237, 26150.62563705]), 'h': array([33875.36612457, 33545.94671013]), 'f': array([41426.10555998, 42534.52435243]), 'dec': array([3.6678175, 3.2466589]), 'inc': array([35.14180823, 37.93807267]), 'dx': array([ 9.91215814, 14.60583551]), 'dy': array([-2.63505666, -4.26437959]), 'dz': array([40.35078867, 34.39738965]), 'dh': array([ 9.72328589, 14.34088148]), 'df': array([31.17702034, 32.45814375]), 'ddec': array([-0.00552022, -0.00868461]), 'dinc': array([0.03789554, 0.02466632])}

Get uncertainty value

print(model.get_uncertainty())
{'x_uncertainty': 137, 'y_uncertainty': 89, 'z_uncertainty': 141, 'h_uncertainty': 133, 'f_uncertainty': 138, 'declination_uncertainty': array([7.67519380e-06, 7.75056379e-06]), 'inclination_uncertainty': 0.2}

WMM Python API Reference

1. Change the resolution(max degree) of the model

wmm_calc(nmax=12)

The default maximum degree for WMM is 12. Users allow to assign the max degree from 1 to 12 to WMM Python API.

from wmm import wmm_calc
model = wmm_calc(nmax=10)

2. Set up time

setup_time(self, year: Optional[np.ndarray] = None, month: Optional[np.ndarray] = None, day: Optional[np.ndarray] = None, dyear: Optional[np.ndarray] = None):

If users don't call or assign any value to setup_time(), the current time will be used to compute the model. Either by providing year, month, day or deciaml year. When passing the decimal year, please pass the decimal year as float point or array to dyear

from wmm import wmm_calc
model = wmm_calc()
model.setup_time(2024, 12, 30)

or

from wmm import wmm_calc
model = wmm_calc()
model.setup_time(dyear=2025.1)

User allow to assign the date from "2024-11-13" to "2030-01-01"

3. Set up the coordinates

setup_env(self, lat: np.ndarray, lon: np.ndarray, alt: np.ndarray, unit: str = "km", msl: bool = False)

from wmm import wmm_calc
model = wmm_calc()
lat, lon, alt = 50.3, 100.4, 0
model.setup_env(lat, lon, alt, unit="m")

The default unit and type of altitude is km and default in GPS(ellipsoid height). Assign the parameter for unit and msl, if the latitude is not in km or in mean sea level. "m" for meter and "feet" for feet. For example,

from wmm import wmm_calc
model = wmm_calc()
lat, lon, alt = 50.3, 100.4, 0
model.setup_env(lat, lon, alt, unit="m", msl=True)

4. Get the geomagnetic elements

wmm_calc.get_all()

After setting up the time and coordinates for the WMM model, you can get all the geomagnetic elements by

from wmm import wmm_calc
model = wmm_calc()
lat, lon, alt = 50.3, 100.4, 0
year, month, day = 2025, 3, 30
model.setup_env(lat, lon, alt, unit="m", msl=True)
model.setup_time(year, month, day)
mag_map = model.get_all()

which will return all magnetic elements in dict type.

Get single magnetic elements by calling
Click to see the available functions to get single elements

wmm_calc.get_Bx()

  • Northward component of the Earth's magnetic field, measured in nanoteslas (nT).
  • wmm_calc.get_By()

  • Eastward component of the Earth's magnetic field, measured in nanoteslas (nT).
  • wmm_calc.get_Bz()

  • Downward component of the Earth's magnetic field, measured in nanoteslas (nT).
  • wmm_calc.get_Bh()

  • Horizontal intensity of the Earth's magnetic field, measured in nanoteslas (nT).
  • wmm_calc.get_Bf()

  • Total intensity of the Earth's magnetic field, measured in nanoteslas (nT).
  • wmm_calc.get_Bdec()

  • Rate of change of declination over time, measured in degrees per year.
  • wmm_calc.get_Binc()

  • Rate of inclination change over time, measured in degrees per year.
  • wmm_calc.get_dBx()

  • Rate of change of the northward component over time, measured in nanoteslas per year.
  • wmm_calc.get_dBy()

  • Rate of change of the eastward component over time, measured in nanoteslas per year.
  • wmm_calc.get_dBz()

  • Rate of change of the downward component over time, measured in nanoteslas per year.
  • wmm_calc.get_dBh()

  • Rate of change of horizontal intensity over time, measured in nanoteslas per year.
  • wmm_calc.get_dBf()

  • Rate of change of the total intensity over time, measured in nanoteslas per year.
  • wmm_calc.get_dBdec()

  • Rate of change of declination over time, measured in degrees per year.
  • wmm_calc.get_dBinc()

  • Rate of inclination change over time, measured in degrees per year.
  • for example,

    from wmm import wmm_calc
    model = wmm_calc()
    lat, lon, alt = 50.3, 100.4, 0
    year, month, day = 2025, 3, 30
    model.setup_env(lat, lon, alt, unit="m", msl=True)
    model.setup_time(year, month, day)
    mag_map = model.get_Bh()
    

    5. Get uncertainty value

    wmm_calc.get_uncertainty()

    The WMM Python API includes an error model that providesing uncertainty estimates for every geomagnetic element (X, Y, Z, H, F, I and D) and every location at Earth's surface.

    For more infromation about the error model, please visit World Magnetic Model Accuracy, Limitations, and Error Model

    model = wmm_calc()
    lat = [80.,  0., 80.]
    lon = [  0., 120.,   0.]
    alt = [0., 0., 0.]
    dyear = [2025.,  2025.,  2027.5]
    
    # set up time
    model.setup_time(dyear=dyear)
    # set up the coordinates
    model.setup_env(lat, lon, alt)
    print(model.get_uncertainty())
    

    It will return

    {'x_uncertainty': 137, 'y_uncertainty': 89, 'z_uncertainty': 141, 'h_uncertainty': 133, 'f_uncertainty': 138, 'declination_uncertainty': array([3.98575493e-05, 6.55276509e-06, 3.99539341e-05]), 'inclination_uncertainty': 0.2}
    

    Contacts and contributing to WMM:

    If you have any questions, please email geomag.models@noaa.gov, submit issue or pull request at https://github.com/CIRES-Geomagnetism/wmm.

    Metadata

    Release files for wmm-calculator 1.4.4

    For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

    Source distribution (sdist)

    Source distribution for wmm-calculator 1.4.4
    File Size Uploaded
    wmm_calculator-1.4.4.tar.gz 19.3 kB Details

    Built distribution (wheel)

    Table of built distributions (wheels) for wmm-calculator 1.4.4
    File Interpreter ABI Platform
    wmm_calculator-1.4.4-py3-none-any.whl Python 3 none any Details

    Total release size: 33.9 kB

    Release files / wmm_calculator-1.4.4.tar.gz

    Download URL wmm_calculator-1.4.4.tar.gz
    Size 19.3 kB
    Tags Source
    SHA-256 checksum
    How to use checksums
    de6b346255ab68d03d4cf88a0de4da5a3f93d555de400891af2f7b4177a3a475
    BLAKE2b-256 checksum
    How to use checksums
    8d810c79f8c8b78eff7fd323feccd7d1688d512c8e7bf95ff4a4dbf874999133
    Upload date
    Uploaded using Trusted Publishing?
    What is trusted publishing?
    No
    Uploaded via twine/6.2.0 CPython/3.11.15

    Release files / wmm_calculator-1.4.4-py3-none-any.whl

    Download URL wmm_calculator-1.4.4-py3-none-any.whl
    Size 14.5 kB
    Tags Python 3
    SHA-256 checksum
    How to use checksums
    bb247c8c5203f16faa83209117b09825915dfc93016ba1bbb7bd95524ab0aaa6
    BLAKE2b-256 checksum
    How to use checksums
    f94480191123b4c1cbfc7983969359fef9b52103fe12d8c0bb25b5d7058e2d87
    Upload date
    Uploaded using Trusted Publishing?
    What is trusted publishing?
    No
    Uploaded via twine/6.2.0 CPython/3.11.15

    Release history Release notifications | RSS feed

    This release

    1.4.4 This release

    2 release files

    1.4.3

    2 release files

    1.4.2

    2 release files

    1.4.1

    2 release files

    1.3.6

    2 release files

    1.3.5

    2 release files

    1.3.4

    2 release files

    1.3.3

    2 release files

    1.3.2

    2 release files

    Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page