Skip to main content

planetMagFields

Interactive visualization and analysis of planetary magnetic fields of the Solar System. Try out the interactive 3D web app.

Web App Build workflow Docs DOI PyPI version License: GPL v3 DOI

Software to easily access and analyze information about magnetic fields of planets in our solar system and visualize them in both 2D and 3D.

Prerequisites

Installation

Features and examples

Documentation

Code contribution and reporting issues

Citing planetMagFields

Acknowledgements

Prerequisites

planetMagFields requires NumPy, Matplotlib and SciPy (>= 1.15). Other than that, the following external libraries are used for a few different functions:

  • 2D plotting for map projections other than Hammer : Cartopy library
  • Potential extrapolation: It is preferable to have the SHTns library which can be installed from PyPI, otherwise it falls back to SciPy.
  • Writing vts files for 3D visualisation: PyEVTK library

Installation

planetMagFields can be installed in a few different ways:

Using pip

planetMagFields is available on PyPI and can be installed with

$ python3 -m pip install planetMagFields

From source

$ git clone https://github.com/AnkitBarik/planetMagFields
$ cd planetMagFields
$ python3 -m pip install . --user

Using PYTHONPATH

Download the package from the GitHub repository and add it to PYTHONPATH:

$ git clone https://github.com/AnkitBarik/planetMagFields
$ export PYTHONPATH=$PYTHONPATH:/path/to/planetMagFields

Features and examples

The Planet class

This gives access to all the relevant properties of a planet and has methods to plot the field and write a vts file for 3D visualization. Usage:

from planetmagfields import Planet
p = Planet(name='earth',datDir='planetmagfields/data/')

This displays the some information about the planet

Planet: Earth
l_max = 13
Dipole tilt (degrees) = -9.410531

and gives access to variables associated with the planet such as:

  • p.lmax : maximum spherical harmonic degree till which data is available
  • p.glm, p.hlm: the Gauss coefficients
  • p.Br : computed radial magnetic field at surface
  • p.dipTheta : dipole tilt with respect to the rotation axis
  • p.dipPhi : dipole longitude ( in case zero longitude is known, applicable to Earth )
  • p.idx : indices to get values of Gauss coefficients
  • p.model : the magnetic field model used. Available models can be obtained using the get_models function. Selects the latest available model when unspecified.

Example using IPython:

In [1]: from planetmagfields import Planet

In [2]: p = Planet(name='jupiter',model='jrm09')
Planet: Jupiter
Model: jrm09
l_max = 10
Dipole tilt (degrees) = 10.307870

In [3]: p.glm[p.idx[2,0]]      # g20
Out[3]: 11670.4

In [4]: p.hlm[p.idx[4,2]]      # h42
Out[4]: 27811.2

2D and 3D visualizations

planetMagFields can be used to produce both 2D and 3D visualizations of a planetary field. While doing so, it also provides the option of potential extrapolation using the SHTns library. Two examples are shown below: Earth's surface field and a 3D visualization of Jupiter's field using Paraview. This is done by writing a .vts file using the PyEVTK library.

Documentation

Full list of features with examples as well as the magnetic field models used are described in detail in the documentation, available here: https://ankitbarik.github.io/planetMagFields/

Code contribution and reporting issues

planetMagFields is an open source project and anyone is welcome to contribute to it. If you wish to contribute to this project, please follow the guidelines below:

  • Please make sure the tests pass before opening a pull request.
  • Please follow Python PEP-8 guidelines when it comes to code style.
  • If you wish to add new data file, please name it following the convention <planet>_<model>.dat, where planet and model denote the names of the planet and the magnetic field model being used. See the data directory for examples. Then add an entry for the model under that planet's "models" in planetmagfields/data/models.json with its name and reference ("name", "url"), plus "format" if the file layout differs from the planet's default.
  • If you implement a new feature or data source, please update the documentation accordingly.

Please report any bugs or other issues through GitHub Issues.

Citing planetMagFields

If you're using planetMagFields for your work, please cite the JOSS paper:

Barik et al., (2024). planetMagFields: A Python package for analyzing and plotting planetary magnetic field data. Journal of Open Source Software, 9(97), 6677, https://doi.org/10.21105/joss.06677

@article{Barik2024,
  doi = {10.21105/joss.06677},
  url = {https://doi.org/10.21105/joss.06677},
  year = {2024},
  publisher = {The Open Journal},
  volume = {9},
  number = {97},
  pages = {6677},
  author = {Barik, Ankit and Angappan, Regupathi},
  title = {planetMagFields: A Python package for analyzing and plotting planetary magnetic field data},
  journal = {Journal of Open Source Software}
}

Acknowledgements

I would like to thank Regupathi Angappan for motivating me to create this package, testing it and for writing the Jupyter notebook. I thank Jon Aurnou for testing it out and pointing out runtime errors. I would like to thank Thomas Gastine for comparing the plots with real data and pointing out a normalization error which has been fixed. Thanks a lot to Arthus for adding the setup.py.

Metadata

Release files for planetMagFields 1.9.1

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

Source distribution (sdist)

Source distribution for planetMagFields 1.9.1
File Size Uploaded Provenance Actions
planetmagfields-1.9.1.tar.gz 74.3 kB With provenance Details for planetmagfields-1.9.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for planetMagFields 1.9.1
File Interpreter ABI Platform Actions
planetmagfields-1.9.1-py3-none-any.whl Python 3 none any Details for planetmagfields-1.9.1-py3-none-any.whl

Total release size: 144.7 kB

Release files / planetmagfields-1.9.1.tar.gz

Download URL planetmagfields-1.9.1.tar.gz
Size 74.3 kB
Tags Source
SHA-256 checksum
How to use checksums
38938139734821f58959c9d93109fe741ff5bdc3eb705721deb810faf2586bdb
BLAKE2b-256 checksum
How to use checksums
412a79e79769bd3244dbb1a93bd6af1579dc51a82552c3257cafe5bdb8a70a1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Release files / planetmagfields-1.9.1-py3-none-any.whl

Download URL planetmagfields-1.9.1-py3-none-any.whl
Size 70.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b84e26ab7028c0566503a8a647a2e9a95339d75551bc77ada0c1846f7b47eb1
BLAKE2b-256 checksum
How to use checksums
e03426055706c522e3b39465217a5a80e31a02873af1f5aacacc2fc49d7bf123
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Security for planetMagFields 1.9.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for planetmagfields-1.9.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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