Giter Site home page Giter Site logo

pleiszenburg / pycrgi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zzyztyy/pyigrf

4.0 2.0 1.0 2.96 MB

pyCRGI is a Python package offering the IGRF-13 (International Geomagnetic Reference Field) model.

License: MIT License

Python 2.48% Makefile 0.01% HTML 97.51%
igrf igrf13 magnetic-fields-calculations magnetic-field geomagnetism

pycrgi's Introduction

pyCRGI

pyCRGI is a cleaned-up and modernized fork of pyIGRF. Be aware that there are a number of small function and module name differences to the original pyIGRF package. The fork's main goals are verified results, tests, speed and ease of maintainability. This is work in progress.

  • package structure cleanup, allowing proper testing and packaging
  • type annotations
  • doc strings completed and prepared for Sphinx autodoc
  • debug mode via environment variable PYCGIR_DEBUG=1
  • pure Python 3 implementation without dependency to numpy
  • JIT-compiled implementation depending on numba and numpy, installation target jited
  • array implementation depending on numba and numpy, installation target array
  • unit tests via test makefile target
  • verification of field's values against original Fortran implementation
  • verification of field's annual/seasonal variation -> huge differences to original Fortran implementation
  • benchmark
  • clean up and add missing relevant coordinate system conversions

benchmark on an AMD Epyc 7443p

What is pyCRGI?

pyCRGI is a Python package offering the IGRF-13 (International Geomagnetic Reference Field) model. You can use it to calculate the magnetic field's intensity and to transform coordinates between GeoGraphical and GeoMagnetic. The package offers different implementations, pure Python and Python JIT-compiled via numba. The project's name is literally the French equivalent of pyIGRF, the project that pyCRGI was once forked from: Champ de Référence Géomagnétique International.

How to Install?

Use pip to install the latest development version from Github:

pip install git+https://github.com/pleiszenburg/pyCRGI.git@master

How to Use it?

First import the package, either as pure Python 3 or JIT-compiled via numba and numpy:

from pyCRGI.pure import get_value, get_variation # pure Python 3
# or
from pyCRGI.jited import get_value, get_variation # JIT-compiled via `numba` and `numpy`
# or
from pyCRGI.array import get_value, get_variation # array implementation via `numba` and `numpy`

As an alternative to pyCRGI.jited, there is also an experimental, structurally different JIT-compiled version named pyCRGI.jited2 available. In the latter implementation, the handling of coefficients differs from the original Fortran implementation that pyCRGI & pyIGRF are based on. It can serve as a foundation for a CUDA-based implementation.

You can calculate the magnetic field's intensity:

get_value(lat, lon, alt, year)

You can calculate the annual variation of the magnetic field's intensity:

get_variation(lat, lon, alt, year)

The return value is a tuple (or array) of seven floating point numbers representing the local magnetic field:

  • D: declination (+ve east) [degree]
  • I: inclination (+ve down) [degree]
  • H: horizontal intensity [nT]
  • X: north component [nT]
  • Y: east component [nT]
  • Z: vertical component (+ve down) [nT]
  • F: total intensity [nT]

If you want to use the IGRF-13 model in a more flexible manner, you can use the functions geodetic2geocentric and get_syn. They are somewhat closer to the original Fortran implementation.

Another function, get_coeffs, can be used to get g[m][n] or h[m][n] corresponding to the IGRF's formula.

Alternatives

This project was originally forked from pyIGRF:

There are other, independent implementations named pyIGRF, not to be confused with the previously mentioned one:

The official IGRF implementations by IAGA are available via the NOAA website:

A good, modern and pure Python implementation:

Another Python implementation is part of the navtools package:

Another Python wrapper around a cleaned-up version of IAGA's Fortran code is maintained as part of the space physics project:

A more or less undocumented, pure Python implementation can be found here:

The IGRF is not to be confused with the World Magnetic Model (WMM). Recent implementations of the WMM accessible via Python are maintained as part of the space physics project:

References

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.