Skip to content
International Geomagnetic Reference Field IGRF12 and IGRF11 -- in Python and Matlab
Python MATLAB Meson CMake
Branch: master
Clone or download
Latest commit 90094a8 Nov 11, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github ci: windows py37 for now till numpy updates ABI Nov 11, 2019
archive ci template, black format, github actions ci Sep 25, 2019
igrf12 vendor datetime2yeardec Nov 11, 2019
reference add initial C code Oct 20, 2019
src add initial C code Oct 20, 2019
tests
.coveragerc setup template Aug 29, 2019
.flake8 project template Nov 11, 2019
.gitattributes linguist vendored Aug 22, 2018
.gitignore ig [ci skip] May 31, 2018
.lgtm.yml ci template, black format, github actions ci Sep 25, 2019
CMakeLists.txt project template Nov 11, 2019
CODE_OF_CONDUCT.md project template Nov 11, 2019
LICENSE.txt ci template, black format, github actions ci Sep 25, 2019
README.md lgtm badge Sep 25, 2019
RunIGRF.py
igrf12.m
meson.build add initial C code Oct 20, 2019
mypy.ini ci template, black format, github actions ci Sep 25, 2019
pyproject.toml ci template, black format, github actions ci Sep 25, 2019
pytest.ini project template Nov 11, 2019
setup.cfg vendor datetime2yeardec Nov 11, 2019
setup.py ci template, black format, github actions ci Sep 25, 2019

README.md

DOI

Actions Status Language grade: Python

Python versions (PyPI) PyPi Download stats

IGRF 2012 in Python

International Geomagnetic Reference Field IGRF12 and IGRF11...in simple, object-oriented Python ≥ 3.6 or Matlab.

image

image

Install

A Fortran compiler is required, such as gfortran:

  • Linux: apt install gfortran

  • Mac: brew install gcc

  • gfortran for Windows (MinGW) Windows only: from Powershell:

    echo "[build]`ncompiler=mingw32" | Out-File -Encoding ASCII ~/pydistutils.cfg

To get the IGRF12 development version, git clone and then:

python -m pip install -e .

Otherwise, for the latest release from PyPi:

python -m pip install igrf12

Optionally, test the install with:

pytest

Windows

If you get ImportError on Windows for the Fortran module, try from the iri2016 directory:

del *.pyd
python setup.py build_ext --inplace --compiler=mingw32

Example

To make the plots in this readme:

igrf12

using as a Python module at geodetic coordinates 65N, 148W:

import igrf12

mag = igrf12.igrf('2010-07-12', glat=65, glon=-148, alt_km=100)

returns an xarray.Dataset:

<xarray.Dataset>
Dimensions:  (alt_km: 1)
Coordinates:
  * alt_km   (alt_km) int64 100
Data variables:
    north    (alt_km) float64 1.122e+04
    east     (alt_km) float64 4.148e+03
    down     (alt_km) float64 5.302e+04
    total    (alt_km) float64 5.436e+04
    incl     (alt_km) float64 77.29
    decl     (alt_km) float64 20.29

The IGRF model may be specified with the igrf12.igrf(model=) option:

  • 11: IGRF11
  • 12: IGRF12

Matlab

Matlab can seamlessly call Python modules, as in igrf12.m. Instead of the $1000 Aerospace Toolbox, use this free IGRF12 for Matlab.

Reference

If you only want the plain Fortran program, you can do:

cmake -B build

cmake --build build --parallel

./testigrf

References

You can’t perform that action at this time.