Skip to main content

Geopack-2008 — GEOPACK-2008 geomagnetic field model for Python

Python Python Package License: GPL v3+ GitHub Stars PyPI

Geopack-2008 (imported as geopack) is a high-performance, self-contained, zero-dependency Python package for the GEOPACK-2008 geomagnetic field model: the International Geomagnetic Reference Field (IGRF), the dipole field, the Tsyganenko (1989) external field model (T89), field-line tracing (TRACE_08), the Shue et al. (1998) and Tsyganenko (1996) magnetopause models, the Sun position computation, the standard solar-terrestrial coordinate transforms (GEO, GSW, GSE, SM, MAG, GEI, GSM), and the cartesian/spherical and WGS84 geodetic coordinate helpers.

It is a Python binding over a C# port of GEOPACK-2008 compiled ahead-of-time with NativeAOT into a shared library (geopack.dylib / geopack.so / geopack.dll), loaded through ctypes from the Python standard library. No .NET runtime is required at runtime, and there are no Python dependencies (no NumPy/SciPy).

  • High performance: native compiled code with SIMD vectorization and other optimized mathematical operations
  • Double precision: accuracy matches the original Fortran code to 12–13 decimal digits
  • Standard library only — no third-party runtime dependencies
  • Thread-safe immutable computation contexts
  • Platform wheels for Linux (x64/arm64), Windows (x64/arm64) and macOS (arm64)

Install

pip install geopack-2008

Pre-built wheels are published to PyPI for Linux (x64/arm64, manylinux), Windows (x64/arm64) and macOS (arm64) — no .NET SDK or C toolchain required.

To build the wheel from source (e.g. for another platform or during development), see BUILDING.md.

Usage

from datetime import datetime

import geopack

ctx = geopack.recalc(1997, 12, 16, 21, 0, 0, vx=-304, vy=13.78, vz=4)
b = ctx.igrf_gsw(1, 1, 1)     # (bx, by, bz) nT in GSW
r = ctx.gsw_to_geo(1, 1, 1)   # (x, y, z) Earth radii in GEO
ctx.close()

# A datetime works too, and contexts are context managers:
with geopack.recalc(datetime(1997, 12, 16, 21, 0), vx=-304, vy=13.78, vz=4) as ctx:
    b = ctx.igrf_gsw(1, 1, 1)

    # Tsyganenko (1989) external field — input GSW, output GSM (nT):
    b = ctx.t89(iopt=3, x=-6.6, y=0, z=0)   # psi defaults to ctx.psi

    # Field-line tracing (TRACE_08): T89 external + IGRF internal.
    line = ctx.trace(-1.02, 0.8, 0.9, direction=geopack.TraceDirection.AntiParallel)
    print(line.actual_point_count, line.end_point, line.termination_reason)

# Context-free T89 (explicit dipole tilt), Sun position and magnetopause models:
b = geopack.t89(iopt=3, psi=0.0, x=-6.6, y=0, z=0)
s = geopack.sun(1997, 12, 16, 21, 0, 0)   # (gst, slong, srasn, sdec), radians

mp = geopack.shu_mgnp(xn_pd=2.0, vel=400.0, bz_imf=0.0, x=10, y=0, z=0)
print(mp.boundary, mp.dist, mp.position)  # Vector3, float, MagnetopausePosition

# Context-free coordinate helpers:
sph = geopack.location_to_spherical(1.0, 1.0, 1.0)   # SphericalVector3(r, theta, phi)
geo = geopack.geodetic_to_geocentric(0.0, 0.0)       # GeocentricCoordinates(r km, theta rad)

A runnable example with all of the above (sun position, IGRF/dipole fields, coordinate transforms, magnetopause models) is in python/example.py:

python3 python/example.py

Implemented models and coordinate systems

Category Model Python API
Internal field IGRF (geomagnetic main field) Context.igrf_gsw, Context.igrf_geo
Internal field Dipole Context.dip
External field Tsyganenko (1989) — T89 Context.t89, geopack.t89
Field-line tracing TRACE_08 (T89 external + IGRF/DIP internal) Context.trace
Magnetopause Shue et al. (1998) geopack.shu_mgnp
Magnetopause Tsyganenko (1996) geopack.t96_mgnp
Sun position Greenwich sidereal time, solar ephemeris geopack.sun
Coordinate helpers CARSPH_08, SPHCAR_08, BCARSP_08, BSPCAR_08, GEODGEO_08 geopack.location_to_*, vector_to_*, geodetic_to_*

Supported coordinate systems (see CoordinateSystem): GEO (geographic), GSW (geocentric solar wind), GSE (geocentric solar ecliptic), SM (solar magnetic), MAG (geomagnetic), GEI (geocentric solar equatorial inertial) and GSM (geocentric solar magnetospheric).

API

All coordinates are in Earth radii; magnetic fields are in nT; angles are in radians; solar wind velocity is in km/s.

  • recalc(date_or_year, month=None, day=None, hour=0, minute=0, second=0, vx=-400, vy=0, vz=0) -> Context
  • Context methods:
    • fields: igrf_gsw(x,y,z) -> Vector3, dip(x,y,z) -> Vector3, igrf_geo(r,theta,phi) -> SphericalVector3 (Br, Btheta, Bphi), t89(iopt,x,y,z, psi=None) -> Vector3, property psi (dipole tilt, radians)
    • tracing: trace(x, y, z, direction=TraceDirection.AntiParallel, ds_max=0.1, err=0.0001, r_lim=60.0, r0=1.0, iopt=1, parmod=None, ex_model=ExternalFieldModel.T89, in_model=InternalFieldModel.IgrfGsw, l_max=500) -> TraceResult — points, end_point, actual_point_count, termination_reason (TraceTermination.BoundaryReached or MaximumPointsExceeded); parmod is a 10-element sequence (None = zeros)
    • transforms: gsw_to_gse, gse_to_gsw, geo_to_mag, mag_to_geo, gei_to_geo, geo_to_gei, mag_to_sm, sm_to_mag, sm_to_gsw, gsw_to_sm, geo_to_gsw, gsw_to_geo — each (x,y,z) -> Vector3
    • lifecycle: close(), context manager
  • sun(...) -> Sun(gst, slong, srasn, sdec) — no context needed
  • shu_mgnp(xn_pd, vel, bz_imf, x, y, z) and t96_mgnp(xn_pd, vel, x, y, z) return MagnetopauseResult(boundary, dist, position) — no context needed
  • t89(iopt, psi, x, y, z, parmod=None) -> Vector3 — Tsyganenko (1989) external field, input GSW, output GSM (nT); parmod is a dummy accepted for parity with the .NET IT89.Calculate contract (unused) — no context needed
  • Coordinate helpers — no context needed:
    • location_to_spherical(x, y, z) -> SphericalVector3 (CARSPH_08)
    • location_to_cartesian(r, theta, phi) -> Vector3 (SPHCAR_08)
    • vector_to_spherical(bx, by, bz, x, y, z) -> SphericalVector3 (BCARSP_08)
    • vector_to_cartesian(br, btheta, bphi, r, theta, phi) -> Vector3 (BSPCAR_08)
    • geodetic_to_geocentric(latitude, altitude) -> GeocentricCoordinates (latitude in radians, altitude in km; GEODGEO_08)
    • geocentric_to_geodetic(r, theta) -> GeodeticCoordinates (GEODGEO_08)

Context.igrf_geo returns SphericalVector3(r, theta, phi) (previously a Vector3); indexing and iteration over the result are unchanged.

GEOPACK_LIBRARY environment variable points the loader at a specific library path if the packaged one is not present.

How to Cite

If you use this software in your research, please cite it — see the How to Cite section of the main repository README (APA and BibTeX entries with a Zenodo DOI).

References

The implementation is based on the GEOPACK-2008 library and the following scientific works:

  1. Tsyganenko, N. A. (1989). A magnetospheric magnetic field model with a warped tail current sheet. Planetary and Space Science, 37(1), 5–20. https://doi.org/10.1016/0032-0633(89)90066-4

  2. Tsyganenko, N. A. (1996). Effects of the solar wind conditions on the global magnetospheric configuration as deduced from data-based field models. ESA SP-389, 181–185.

  3. Shue, J.-H., et al. (1998). Magnetopause location under extreme solar wind conditions. Journal of Geophysical Research, 103(A8), 17691–17700. https://doi.org/10.1029/98JA01103

  4. Hapgood, M. A. (1992). Space physics coordinate transformations: A user guide. Planetary and Space Science, 40(5), 711–717. https://doi.org/10.1016/0032-0633(92)90012-D

  5. Tsyganenko, N. A. (2002). A model of the near magnetosphere with a dawn-dusk asymmetry 1. Mathematical structure. Journal of Geophysical Research, 107(A8). https://doi.org/10.1029/2001JA000219

  6. Tsyganenko, N. A., & Sitnov, M. I. (2005). Modeling the dynamics of the inner magnetosphere during strong geomagnetic storms. Journal of Geophysical Research: Space Physics, 110(A3), A03208. https://doi.org/10.1029/2004JA010798

Metadata

Release files for Geopack-2008 2.7.0

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

Built distributions (wheels)

Table of built distributions (wheels) for Geopack-2008 2.7.0
File Actions
geopack_2008-2.7.0-py3-none-win_arm64.whl Python 3 none Windows ARM64 Details for geopack_2008-2.7.0-py3-none-win_arm64.whl
geopack_2008-2.7.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for geopack_2008-2.7.0-py3-none-win_amd64.whl
geopack_2008-2.7.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details for geopack_2008-2.7.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
geopack_2008-2.7.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.28+ ARM64, Linux glibc 2.27+ ARM64 Details for geopack_2008-2.7.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
geopack_2008-2.7.0-py3-none-macosx_14_0_arm64.whl Python 3 none macOS 14.0+ ARM64 Details for geopack_2008-2.7.0-py3-none-macosx_14_0_arm64.whl

Total release size: 3.6 MB

Release files / geopack_2008-2.7.0-py3-none-win_arm64.whl

Download URL geopack_2008-2.7.0-py3-none-win_arm64.whl
Size 703.9 kB
Tags Python 3 Windows ARM64
SHA-256 checksum
How to use checksums
56cbe5379671f2043ba46d3fab64a0d7f47e0b292612d0dd8fcbbf592f561bc5
BLAKE2b-256 checksum
How to use checksums
8727c6fbc2ce80566aef2a79986828064ac619c277952ab87112484b1e90511e
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 15, 2026.

Transparency log

Release files / geopack_2008-2.7.0-py3-none-win_amd64.whl

Download URL geopack_2008-2.7.0-py3-none-win_amd64.whl
Size 734.3 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
bd1df2625009bf3baba6036d1ff07cc702f46d1def2675a3c863764b3575f887
BLAKE2b-256 checksum
How to use checksums
7df6ebc35cb7fbf3fa6aaaf8f1701dd9236d6ccc8140c8a5fab2189851e6b8c5
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 15, 2026.

Transparency log

Release files / geopack_2008-2.7.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL geopack_2008-2.7.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 744.5 kB
Tags Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
2936a0e84c87b95e8f73b2147b1e1948d72f3b7cce767550612d5a9526ea41a9
BLAKE2b-256 checksum
How to use checksums
f064697562796b485d37f4f672d53b404a2f81303c84b9641b1dcf6efbc6509a
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 15, 2026.

Transparency log

Release files / geopack_2008-2.7.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl

Download URL geopack_2008-2.7.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Size 718.6 kB
Tags Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
85e4f776e3826ac54a0c147f0bf4dc38d98c132123c5ad2b79eb63270039c721
BLAKE2b-256 checksum
How to use checksums
2c01b9e9abc2a9da41788c67dbce52b0b49a0ea682d46f8d9d5e0506f1bd94eb
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 15, 2026.

Transparency log

Release files / geopack_2008-2.7.0-py3-none-macosx_14_0_arm64.whl

Download URL geopack_2008-2.7.0-py3-none-macosx_14_0_arm64.whl
Size 702.6 kB
Tags Python 3 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
d899443a09e1dc60f7627014a673c13c2ea879ccad0cc76f83e5f6e742f993e7
BLAKE2b-256 checksum
How to use checksums
1727eac0f2020d9a04592839a3a48480bfd4df3d14f8437b07cc9828f2287e9d
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 15, 2026.

Transparency log

Security for Geopack-2008 2.7.0

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

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for geopack_2008-2.7.0-py3-none-win_arm64.whl

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 15, 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