World Magnetic Model
The main utility of the World Magnetic Model (WMM) [CBA+20] is to provide magnetic declination for any desired location on the globe.
In addition to the magnetic declination, the WMM also provides the complete geometry of the field from 1 km below the World Geodetic System (WGS 84) [198414] ellipsoid surface to approximately 850 km above it. The magnetic field extends deep into the Earth and far out into space, but the WMM is not valid at these extremes.
Earth’s magnetic field is viewed as a magnetic dipole produced by a sphere of uniform magnetization. The “south” of the dipole lies on the northern Hemipshere and drifts westward at about 55 to 60 km per year, whereas the other pole, just outside the Antarctic Circle, drifts by about 10 to 15 km per year.
The strongest contribution to Earth’s magnetism is the magnetic field produced by the Earth’s liquid-iron outer core, called the “core field”. Magnetic minerals in the crust and upper mantle make a further contribution that can be locally significant. All these fields of “internal” origin and their large scale components are included in the WMM.
“External” magnetic fields, arising from electric currents in the upper atmosphere and near-Earth space, predominantly generated by solar wind, are time-varying and produce secondary magnetic fields, which are not represented in the WMM.
Current estimations include secondary thermal convection currents near Earth’s core-mantle producing local magnetic dipoles. These dipoles are superimposed to approximate the observed multipole nature of the magnetic field. The creation and decay of these inner convections are suspected to yield the magnetic drift.
The magnetic flux density (magnetic field) can be expressed as the gradient of a potential, :
This has a convenient solution expressed in spherical harmonics of degrees:
where is Earth’s mean radius; and are
Gaussian coefficients of degree and order ; ,
, and are the geocentric radius, coelevation and
longitude in spherical polar coordinates; and are the
associated Legendre functions :cite:phofmann2006.
The time-dependent Gauss coefficients are estimated empirically from a least-squares fit using satellite magnetic measurements [LH98]. These coefficients are provided by the NCEI Geomagnetic Modeling Team and British Geological Survey in a file with extension COF [CBA+20].
With degree only dipoles are considered. For the quadrupoles, the octuploles, and so on. The method of this WMM expands to degree and order 12.
The secular variation (SV) is the yearly change of the core field, which is also accounted in the WMM by a linear model. Due to unpredictable changes in the core field, the values of the WMM coefficients are updated every five years (a lustrum). The most recent version is valid from 2020 to 2029.
The geomagnetic field vector B is described by 7 elements:
| Element | Definition | Units | Range | |
|---|---|---|---|---|
| Min | Max | |||
| X | Northerly intensity | nT | -17000 | 43000 |
| Y | Easterly intensity | nT | -18000 | 17000 |
| Z | Vertical intensity (Positive downwards) | nT | -67000 | 62000 |
| H | Horizontal intensity | nT | 0 | 43000 |
| F | Total intensity | nT | 23000 | 67000 |
| I | Inclination angle (a.k.a. dip angle) | degree | -90 | 90 |
| D | Declination angle (a.k.a. magnetic variation) | degree | -180 | 180 |
The quantities X, Y and Z are perpendicular vectors and can be used
to determine the quantities F, I and D, and viceversa.
The vertical direction is perpendicular to the horizontal plane of the WGS 84 ellipsoid model of the Earth.
At a location on the plane of a chosen horizontal coordinate system, grivation is the angle between grid north and magnetic north, i.e., the angle measured clockwise from the direction parallel to the grid’s Northing axis to the horizontal component of the magnetic field at the observer’s location.
Grivation is useful for local surveys, where location is given by grid coordinates rather than by longitude and latitude. It is dependent on the map projection used to define the grid coordinates. In general, it is estimated as:
where is the “convergence-of-meridians” defined as the clockwise angle from the northward meridional arc to the grid Northing direction.
The class WMM contains a couple of methods to load and create a geomagnetic
model from a set of given coefficients. To obtain the magnetic elements at a
certain spot on the Earth, we call the method magnetic_field
>>> wmm = ahrs.utils.WMM() # Create today's magnetic model
>>> wmm.magnetic_field(10.0, -20.0) # Magnetic field at latitude = 10°, longitude = -20°
>>> wmm.D # Magnetic declination [degrees]
-9.122361367239034
>>> wmm.magnetic_field(10.0, -20.0, height=10.5) # 10.5 km above sea level
>>> wmm.D
-9.128404039098971By default, the class WMM will create a model for the day, when the object
is being created. To ask for the values at a different date, we simply pass it
as a parameter.
>>> wmm.magnetic_field(10.0, -20.0, height=10.5, date=datetime.date(2017, 5, 12)) # on 12th May, 2017
>>> wmm.D
-9.73078560629778All main elements are computed at the same time and accessed independently
>>> wmm.X
30499.640469609083
>>> wmm.Y
-5230.267158472566
>>> wmm.Z
-1716.633311360368
>>> wmm.H
30944.850352270452
>>> wmm.F
30992.427998627096
>>> wmm.I
-3.1751692563622993
>>> wmm.GV
-9.73078560629778or in a dictionary
>>> wmm.magnetic_elements
{'X': 30499.640469609083, 'Y': -5230.267158472566, 'Z': -1716.633311360368,
'H': 30944.850352270452, 'F': 30992.427998627096, 'I': -3.1751692563622993,
'D': -9.73078560629778, 'GV': -9.73078560629778}Note
The model in this package includes coefficients for dates between 2015 and 2029 only. Models out of this timespan cannot be built.
The WMM was developed jointly by the National Centers for Environmental Information (NCEI, Boulder CO, USA) (formerly National Geophysical Data Center (NGDC)) and the British Geological Survey (BGS, Edinburgh, Scotland). As part of the regular update cycle of the World Magnetic Model both institutions have released the latest model on December 10th, 2019.
This script is based on the originally conceived one by Christopher Weiss (cmweiss@gmail.com) [Wei16], who adapted it from the geomagc software and World Magnetic Model of the NOAA Satellite and Information Service, National Geophysical Data Center [CBA+20].
License
The WMM source code and binaries are in the public domain and not licensed or under copyright. The information and software may be used freely by the public. As required by 17 U.S.C. 403, third parties producing copyrighted works consisting predominantly of the material produced by U.S. government agencies must provide notice with such work(s) identifying the U.S. Government material incorporated and stating that such material is not subject to copyright protection.
class ahrs.utils.wmm.WMM(date: date | int | float = None, latitude: float = 48.13723, longitude: float = 11.575508, height: float = 0.521, frame: str = 'NED') : This class computes all elements of the World Magnetic Model (WMM) at any given point on Earth.
The main magnetic field is a potential field defined, in
geocentric spherical coordinates (longitude , latitude
and radius ), as the negative spatial gradient of a
scalar potential at a time . This potential can be expanded in
terms of spherical harmonics:
where
and the Schmidt semi-normalized associated Legendre functions
are defined as:
Any object of this class is initialized with the corresponding epoch,
determined by the given date. If no date is given, it is assumed for the
day of the object’s creation.
Once the WMM object is created, the estimation of the geomagnetic elements
is carried out with a call to the method magnetic\_field giving the
location on Earth at which the magnetic elements will be calculated. This
location is given in decimal geodetic coordinates. See examples.
Every WMM object is created with a set of coefficients read from a COF
file, defined by the desired working date of the model. The latest
model available is WMM2025 corresponding to the lustrum 2025-2029.
This class can create models with dates between 2015 and 2029.
Parameters:
: - **date** (*datetime.date, int or float, default: current day*) – Date of desired magnetic field estimation.
- **latitude** (*float, default: 48.137230*) – Latitude, in decimal degrees, in geodetic coordinates.
- **longitude** (*float, default: 11.575508*) – Longitude, in decimal degrees, in geodetic coordinates.
- **height** (*float, default: 0.521*) – Mean Sea Level Height, in kilometers.
- **frame** (*str, default: ‘NED’*) – Local tangent plane coordinate frame. Valid options are right-handed
`'NED'` for North-East-Down and `'ENU'` for East-North-Up.
Variables:
: - **date** (*datetime.date**,* *default: datetime.date.today**(**)*) – Desired date to estimate
- **date\_dec** (*float*) – Desired date to estimate as decimal
- **epoch** (*float*) – Initial time of model in decimal years
- **model** (*str*) – WMM Model identificator
- **modeldate** (*str*) – Release date of WMM Model
- **wmm\_filename** (*str*) – COF File used to build Model
- **degree** (*int*) – Degree of model
- **latitude** (*float*) – Latitude, in decimal degrees, in geodetic coordinates
- **longitude** (*float*) – Longitude in decimal degrees, in geodetic coordinates
- **height** (*float**,* *default: 0.0*) – Mean Sea Level Height in kilometers
- **X** (*float**,* *default: None*) – Northerly intensity, in nT
- **Y** (*float**,* *default: None*) – Easterly intensity, in nT
- **Z** (*float**,* *default: None*) – Vertical intensity, in nT
- **H** (*float**,* *default: None*) – Horizontal intensity, in nT
- **F** (*float**,* *default: None*) – Total intensity, in nT
- **I** (*float**,* *default: None*) – Inclination angle (dip), in degrees
- **D** (*float**,* *default: None*) – Declination angle, in degrees
- **GV** (*float**,* *default: None*) – Grivation, in degrees
Examples
The magnetic field can be computed at the creation of the WMM object by
passing the main parameters to its constructor:
```defaultwmm = ahrs.utils.WMM(datetime.date(2017, 5, 12), latitude=10.0, longitude=-20.0, height=10.5) wmm.magnetic_elements {'X': 30499.640469609083, 'Y': -5230.267158472566, 'Z': -1716.633311360368, 'H': 30944.850352270452, 'F': 30992.427998627096, 'I': -3.1751692563622993, 'D': -9.73078560629778, 'GV': -9.73078560629778}
denormalize\_coefficients(*latitude: float*) → None
: Recursively estimate associated Legendre polynomials and derivatives
done in a recursive way as described by Michael Plett in
[[Ple78](/u/fab8b0a9fec670cf#id60)] for an efficient computation.
Given the Gaussian coefficients, it is possible to estimate the
magnetic field at any latitude on Earth for a certain date.
First, it is assumed that are the Schmidt
semi-normalized functions. A normalization is made so that the
relative strength of terms of same degree but order
are used by comparing their respective Gauss coefficients.
For they are called *Legendre Polynomials* and can be
computed recursively with:
For they are known as *associated Legendre functions*
of degree and order and reduced to:
expressing the associated Legendre functions in terms of the Legendre
polynomials of same degree .
A more general formula to estimate both polynomial and associated
functions is given by:
where is either or ,
whichever is an integer. For a computational improvement, the terms are
calculated recursively.
We have to denormalize the coefficients from Schmidt to Gauss. The
Gauss functions are related to Schmidt functions
as:
where the factors are combined with Gaussian
coefficients to accelerate the computation, because they are
independent of the geographic location. Thus, we denormalize the
coefficients with:
The recursion for is:
where the Kronecker delta is:
Similarly, can be recursively obtained:
where:
Likewise, the gradient is estimated as:
Parameters:
: **latitude** (*float*) – Latitude in spherical geocentric coordinates
*property* geodetic\_vector*: ndarray*
: Magnetic field vector in geodetic coordinates
The magnetic field vector is returned as a 3D vector in geodetic
coordinates.
Example
```default
>>> wmm = WMM(datetime.date(2017, 5, 12), latitude=10.0, longitude=-20.0, height=10.5)
>>> wmm.geodetic_vector
array([ 30499.64046961, -5230.26715847, -1716.63331136])get\_properties(*cof\_file: str*) → Dict[str, str | float]
: Return dictionary of WMM properties from COF file.
Three properties are read and returned in a dictionary:
- `epoch` is the initial time as a float.
- `model` is a string of model used for the required lustrum.
- `modeldate` is the release date of used magnetic model.
Parameters:
: **cof\_file** (*str*) – Path to COF file with the coefficients of the WMM
Returns:
: **properties** – Dictionary with the three WMM properties.
Return type:
: dictionary
Examples
```defaultwmm = ahrs.WMM() wmm.get_properties('my_coefficients.COF') {'model': 'WMM-2020', 'modeldate': '12/10/2019', 'epoch': 2020.0}
load\_coefficients(*cof\_file: str*) → None
: Load model coefficients from COF file.
The model coefficients, also referred to as Gauss coefficients, are
listed in a COF file. These coefficients can be used to compute values
of the fields elements and their annual rates of change at any
location near the surface of the Earth.
The COF file has 6 columns:
- `n` is the degree.
- `m` is the order.
- `g` are time-dependent Gauss coefficients of degree `n` and order `m`.
- `h` are time-dependent Gauss coefficients of degree `n` and order `m`.
- `gd` are secular variations of coefficient `g`.
- `hd` are secular variations of coefficient `h`.
which constitute the *model* of the field. The first-order time
derivatives are called *secular terms*. The units are `nT` for the
main field, and `nT/year` for the secular variation.
The Gauss coefficients are defined for a time as:
\begin{split}\begin{eqnarray}
g_n^m(t) & = & g_n^m(t_0) + (t-t_0) \dot{g}_n^m(t_0) \\
h_n^m(t) & = & h_n^m(t_0) + (t-t_0) \dot{h}_n^m(t_0)
\end{eqnarray}\end{split}
where time is given in decimal years and corresponds to the
epoch read from the corresponding COF file.
Parameters:
: **cof\_file** (*str*) – Path to COF file with the coefficients of the WMM
*property* magnetic\_elements*: Dict[str, float]*
: Main geomagnetic elements in a dictionary
| Element | Definition |
| --- | --- |
| X | Northerly intensity |
| Y | Easterly intensity |
| Z | Vertical intensity (Positive downwards) |
| H | Horizontal intensity |
| F | Total intensity |
| I | Inclination angle (a.k.a. dip angle) |
| D | Declination angle (a.k.a. magnetic variation) |
| GV | Grivation |
Example
```default
>>> wmm = WMM(datetime.date(2017, 5, 12), latitude=10.0, longitude=-20.0, height=10.5)
>>> wmm.magnetic_elements
{'X': 30499.640469609083, 'Y': -5230.267158472566, 'Z': -1716.633311360368,
'H': 30944.850352270452, 'F': 30992.427998627096, 'I': -3.1751692563622993,
'D': -9.73078560629778, 'GV': -9.73078560629778}magnetic\_field(*latitude: float*, *longitude: float*, *height: float = 0.0*, *date: date | int | float = datetime.date(2026, 11, 29)*) → None
: Calculate the geomagnetic field elements for a location on Earth.
The code includes comments with references to equation numbers
corresponding to the ones in the official report.
Having the coefficients and , we
extrapolate them for the desired time as:
where is the difference between the time
and the reference epoch model (`2020.0` for the
newest version.)
The vector components of the main magnetic field are then
calculated with:
Finally, the geomagnetic vector components are rotated into ellipsoidal
reference frame.
These components are used to compute the rest of the magnetic elements:
Note
The use of `arctan2` yields a more precise result than `arctan`,
because it estimates the angle exploring all quadrants.
For polar regions, where the declination changes drastically, the WMM
defines two different grivations (one for each pole) defined as:
Parameters:
: - **latitude** (*float*) – Latitude, in decimal degrees, in geodetic coordinates
- **longitude** (*float*) – Longitude in decimal degrees, in geodetic coordinates
- **height** (*float, default: 0.0*) – Mean Sea Level Height in kilometers
- **date** (*datetime.date, int or float, default: datetime.date.today()*) – Desired date to estimate
reset\_coefficients(*date: date | int | float = None*) → None
: Reset Gauss coefficients to given date.
Given the date, the corresponding coefficients are updated. Basic
properties (epoch, release date, and model id) are read and updated in
the current instance.
The two coefficient tables (arrays) are also updated, where the
attribute c contains the Gaussian coefficients, while the attribute
cd contains the secular Gaussian coefficients.
The lenght of the Gaussian coefficient array determines the degree
of the model. This property updates the value of attribute
`degree`.
Parameters:
: **date** (*datetime.date, int or float, default: current day*) – Date of desired magnetic field estimation.
reset\_date(*date: date | int | float*) → None
: Set date to use with the model.
The WMM requires a date. This date can be given as an instance of
datetime.date or as a decimalized date of the format `YYYY.d`.
If None is given it sets the date to the present day. In addition, the
corresponding COF file is also set.
Please note that only coefficents from year 2015 and later are provided
with this module.
Parameters:
: **date** (*datetime.date, int or float, default: current day*) – Date of desired magnetic field estimation.ahrs.utils.wmm.geodetic2spherical(lat: float, lon: float, h: float, a: float = 6378.137, b: float = 6356.7523142) → Tuple[float, float, float] : Transform geodetic coordinates into spherical geocentric coordinates
The transformation cannot be a simple cylindric to spherical conversion, as
we must also consider a planet’s ellipsoid form. With the aid of its
pre-defined flatness and eccentricity, we can better approximate the values
of the conversion.
In this function the Earth’s major and minor semi-axis are considered.
However, we can convert the coordinates of different ellipsoidal bodies, by
giving the dimensions of its semi-axes.
Notice that the longitude between both systems remains the same.
Parameters:
: - **lat** (*float*) – Latitude, in radians, of point in geodetic coordinates
- **lon** (*float*) – Longitude, in radians, of point in geodetic coordinates
- **h** (*float*) – Height, in kilometers, of point in geodetic coordinates
- **a** (*float, default: 6378.137*) – Major semi-axis, in kilometers. Defaults to Earth’s equatorial radius
- **b** (*float, default: 6356.752314245*) – Minor semi-axis, in kilometers. Defaults to Earth’s polar radius
Returns:
: - **lat\_spheric** (*float*) – Latitude of point in spherical coordinates.
- **lon** (*float*) – Longitue of point in spherical coordinates. Same as geodetic.
- **r** (*float*) – Radial distance of point in spherical coordinates.