WMM Python Module
Project description
WMM Python module
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()
wmm_calc.get_By()
wmm_calc.get_Bz()
wmm_calc.get_Bh()
wmm_calc.get_Bf()
wmm_calc.get_Bdec()
wmm_calc.get_Binc()
wmm_calc.get_dBx()
wmm_calc.get_dBy()
wmm_calc.get_dBz()
wmm_calc.get_dBh()
wmm_calc.get_dBf()
wmm_calc.get_dBdec()
wmm_calc.get_dBinc()
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wmm_calculator-1.4.4.tar.gz.
File metadata
- Download URL: wmm_calculator-1.4.4.tar.gz
- Upload date:
- Size: 19.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de6b346255ab68d03d4cf88a0de4da5a3f93d555de400891af2f7b4177a3a475
|
|
| MD5 |
9ef65695c4eef3e5461cdef84c1a47d9
|
|
| BLAKE2b-256 |
8d810c79f8c8b78eff7fd323feccd7d1688d512c8e7bf95ff4a4dbf874999133
|
File details
Details for the file wmm_calculator-1.4.4-py3-none-any.whl.
File metadata
- Download URL: wmm_calculator-1.4.4-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb247c8c5203f16faa83209117b09825915dfc93016ba1bbb7bd95524ab0aaa6
|
|
| MD5 |
3456e047844f59a81774bfb1881af429
|
|
| BLAKE2b-256 |
f94480191123b4c1cbfc7983969359fef9b52103fe12d8c0bb25b5d7058e2d87
|