Skip to main content

Python package with Rust bindings to calculate the magnetic field in Jupiter's magnetosphere.

Reason this release was yanked:

This was a test release and should not be used.

Project description

iupitermag

Introduction

iupitermag is a Python package written in Rust to model Jupiter's magnetic field.

Jupiter's Surface Field Strength

Jupiter's internal magnetic field intensity at the 1-bar "surface".

Many other public codes do this or something similar,

More details on Jupiter magnetic field models and these codes can be found in this paper - Wilson, R.J., Vogt, M.F., Provan, G. et al. Internal and External Jovian Magnetic Fields: Community Code to Serve the Magnetospheres of the Outer Planets Community. Space Sci Rev 219, 15 (2023). https://doi.org/10.1007/s11214-023-00961-3

Installation

Installing from source using uv

If you are using uv as your Python package manager, you can run the following commands after cloning and changing into this directory.

$ uv pip install .

Usage

Calculating the internal and current sheet fields at a single point.

All positions should be in the IAU_JUPITER coordinate system.

import iupitermag as im

internal_field = im.InternalField("JRM33")
cs_field = im.CurrentSheetField("CON2020")

r = 10.
theta = 0.
phi = 0.
b_int_rtp = internal_field.calc_field(r, theta, phi)
b_ext_rtp = cs_field.calc_field(r, theta, phi)

# Or, you can the cartesian form.  This calls the spherical version internally.
x = 10.
y = 5.
z = 1.
b_int_xyz = internal_field.calc_field_xyz(x, y, z)
b_ext_xyz = cs_field.calc_field_xyz(x, y, z)

Calculating the internal and current sheet fields for a collection of points.

If you have a collection of points stored as a single numpy array of shape (N, 3), you can use map_calc_field or parmap_calc_field (or their corresponding cartesian versions map_calc_field_xyz and parmap_calc_field_xyz).

points = np.zeros((10000, 3))
points[:, 0] = np.random.random_sample((10000,)) * 10 + 5

b_int = internal_field.map_calc_field(points)
b_ext = cs_field.map_calc_field(points)

b_int = internal_field.parmap_calc_field(points)
b_ext = cs_field.parmap_calc_field(points)

points_xyz = points * 1.

b_int_xyz = internal_field.map_calc_field_xyz(points_xyz)
b_ext_xyz = cs_field.map_calc_field_xyz(point_xyz)

b_int_xyz = internal_field.parmap_calc_field_xyz(points_xyz)
b_ext_xyz = cs_field.parmap_calc_field_xyz(points_xyz)

Based on some benchmarks, you should find parmap_calc_field nearly an order of magnitude faster than map_calc_field or a Python loop over all points calling calc_field repeatedly. parmap_* uses Rayon for parallelizing the calculation. Here are the results of benchmarking different methods to calculate the JRM33 field for different number of points.

Benchmark

As you can see, parmap_ is usually the better option if you have more than 20 or so points. Note that the Python loop version still calls the Rust code internally to calculate the JRM33 field, so even that is faster than a pure-Python implementation (not shown above).

Tracing magnetic field lines

iupitermag can trace magnetic field lines to Jupiter using trace_field_to_planet, which takes as input a collection of starting points (which each result in a separate trace). The coordinates for these starting points should be cartesian.

internal_field = im.InternalField("JRM33")
cs_field = im.CurrentSheetField("CON2020")

starting_positions_xyz = np.array([
    [-10., 0., 0.],
    [-15., 0., 0.],
    [-20., 0., 0.],
    [-25., 0., 0.],
    [10., 0., 0.],
    [15., 0., 0.],
    [20., 0., 0.],
    [25., 0., 0.],
])

trace = im.trace_field_to_planet(starting_positions_xyz, internal_field, cs_field)

Traced field lines

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iupitermag-0.1.0-cp39-abi3-win_amd64.whl (307.2 kB view details)

Uploaded CPython 3.9+Windows x86-64

File details

Details for the file iupitermag-0.1.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: iupitermag-0.1.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 307.2 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for iupitermag-0.1.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 814441d749e58d85e76101c825797944ffd4075fa6313d3c50942fb7398278c7
MD5 cc41c54dfba0664174f99f2a99dca421
BLAKE2b-256 61fbef2e49c3c44fbdf68587744d99ebd9d76e9735c18d0cd31c5c663369aba5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page