The IRBEM Python wrapper exposes the full Fortran library through two high-level classes,Documentation Index
Fetch the complete documentation index at: https://mintlify.com/PRBEM/IRBEM/llms.txt
Use this file to discover all available pages before exploring further.
MagFields and Coords, both found in python/IRBEM/IRBEM.py. Under the hood, Python’s built-in ctypes module loads the compiled shared object (libirbem.so on Linux/macOS, libirbem.dll on Windows) and marshals all arguments and return values between Python types and the Fortran ABI. You never call the Fortran subroutines directly — the classes handle all array sizing, type conversion, and output packaging for you.
Installation
Compile the Fortran source
Follow the instructions in Verify the shared object was created before continuing:
README.install at the top of the IRBEM repository to build the shared library. After a successful build you should find a file named libirbem.so (Linux/macOS) or libirbem.dll (Windows) in the top-level IRBEM directory.Install the Python package
Change into the The package requires Python ≥ 3.6 and the following dependencies (installed automatically):
python/ subdirectory and install with pip. A system-wide install requires sudo; use --user to install for the current user only.numpy >= 1.12, scipy >= 0.14, python-dateutil, and wheel. The optional pandas package is supported but not required.Verify the installation
Run one of the provided test and visualisation scripts to confirm everything is working end-to-end:If the wrapper raises
"Either none or multiple .so files found in the sources folder!" check that exactly one libirbem.so file exists in the IRBEM root before the Python package directory is searched.The Python wrapper is developed and tested on Linux and Python versions greater than 3.6. Windows users can run the wrapper through the Windows Subsystem for Linux (WSL).
The two classes
| Class | Purpose |
|---|---|
MagFields | Magnetic coordinates, field tracing, drift shells, mirror points, and foot points |
Coords | Coordinate system transformations (GDZ, GEO, GSM, GSE, SM, GEI, MAG, SPH, RLL) |
MagFields
MagFields wraps IRBEM’s magnetic field subroutines. All configuration (field model, coordinate system, options) is supplied once at construction time and shared across every subsequent method call.
Constructor
Explicit path to the compiled shared object (
libirbem.so or libirbem.dll). When omitted, the wrapper searches for the shared object in the top-level IRBEM directory automatically.The external magnetic field model. Accepts either the integer index or the corresponding string name from the lookup table below.
| Index | String | Model |
|---|---|---|
| 0 | 'None' | No external field |
| 1 | 'MF75' | Mead–Fairfield 1975 |
| 2 | 'TS87' | Tsyganenko 1987 (Stern & Tsyganenko) |
| 3 | 'TL87' | Tsyganenko–Longo 1987 |
| 4 | 'T89' | Tsyganenko 1989 |
| 5 | 'OPQ77' | Olson–Pfitzer Quiet 1977 |
| 6 | 'OPD88' | Olson–Pfitzer Dynamic 1988 |
| 7 | 'T96' | Tsyganenko 1996 |
| 8 | 'OM97' | Ostapenko–Maltsev 1997 |
| 9 | 'T01' | Tsyganenko 2001 |
| 10 | 'T01S' | Tsyganenko 2001 (storm) |
| 11 | 'T04' | Tsyganenko–Sitnov 2004 |
| 12 | 'A00' | Alexeev 2000 |
| 13 | 'T07' | Tsyganenko–Sitnov 2007 |
| 14 | 'MT' | Mead–Tsyganenko |
Input coordinate system.
0 = GDZ (altitude km, latitude °, East longitude °). See the coordinate system table in the Coords section for all available values.A list of five integers controlling optional computations. Refer to the IRBEM HTML documentation for the full option descriptions. A common choice is
[1, 0, 0, 0, 0] to enable L* computation.When
True, prints a status message before each Fortran call. Useful for debugging silent crashes caused by type mismatches at the Fortran boundary.Input dictionaries
EveryMagFields method accepts two dictionaries: X for the spacecraft position and time, and maginput for the magnetic field model driving parameters.
X — position and time
sysaxes=0 (GDZ), x1 is altitude in km, x2 is geodetic latitude in degrees, and x3 is East longitude in degrees. The dateTime value may be an ISO-8601 string, a datetime.datetime object, or a pandas.Timestamp.
maginput — model driving parameters
-9999). Values may be scalars (int, float) or arrays/lists of equal length for multi-point calls.
Methods
make_lstar(X, maginput)
Computes magnetic coordinates at the spacecraft position: McIlwain L shell, L*, local field magnitude, minimum field magnitude, the second adiabatic invariant integral J, and magnetic local time.
dict with keys:
| Key | Description |
|---|---|
Lm | McIlwain L shell |
MLT | Magnetic local time (hours) |
blocal | Local magnetic field magnitude (nT) |
bmin | Minimum field on the field line (nT) |
Lstar | Roederer L* (drift shell) |
xj | Integral invariant J (related to second adiabatic invariant) |
drift_shell(X, maginput)
Traces a complete drift shell for a particle whose mirror point is at the input location. Returns the positions of all 48 field lines that make up the shell.
dict with keys:
| Key | Description |
|---|---|
Lm | McIlwain L shell (scalar) |
lstar | L* / drift shell parameter (scalar) |
blocal | Local B array, shape (48, 1000) |
bmin | Minimum B on shell (scalar, nT) |
xj | Integral invariant J (scalar) |
POSIT | GEO Cartesian positions, shape (48, 1000, 3) |
Nposit | Number of valid points per field line, shape (48,) |
drift_bounce_orbit(X, maginput, alpha=90, R0=1)
Traces a complete drift-bounce orbit for a particle with a specified local pitch angle. Returns 25 azimuths (vs. 48 for drift_shell) and only positions between the mirror points.
Local pitch angle in degrees.
Minimum radial distance allowed along the drift path, in units of Earth radii. Use
R0 < 1 to work inside the drift loss cone.dict — same keys as drift_shell plus:
| Key | Description |
|---|---|
bmirr | Mirror field magnitude (nT) |
hmin | Altitude of the minimum-altitude point along the orbit (km) |
hmin_lon | East longitude (GDZ °) of the minimum-altitude point |
find_mirror_point(X, maginput, alpha)
Finds the magnitude and GEO location of the mirror point along the field line passing through X for a given local pitch angle.
Local pitch angle in degrees.
dict:
| Key | Description |
|---|---|
blocal | Local field magnitude at input point (nT) |
bmin | Field magnitude at the mirror point (nT) |
POSIT | GEO Cartesian coordinates of the mirror point, shape (3,) |
find_foot_point(X, maginput, stopAlt, hemiFlag)
Traces the field line from X to find where it crosses the altitude stopAlt in the chosen hemisphere.
Target footprint altitude above Earth’s surface in kilometres.
Hemisphere selection:
0— same magnetic hemisphere as the starting point+1— northern magnetic hemisphere-1— southern magnetic hemisphere+2— opposite magnetic hemisphere to the starting point
dict:
| Key | Description |
|---|---|
XFOOT | Footprint location in GDZ coordinates [alt_km, lat_deg, lon_deg] |
BFOOT | Magnetic field vector at footprint in GEO coordinates (nT) |
BFOOTMAG | Magnetic field magnitude at footprint (nT) |
trace_field_line(X, maginput, R0=1)
Traces the complete field line that passes through X down to a reference sphere of radius R0.
Radius of the reference surface in Earth radii. The field line is traced until it reaches this radius in both hemispheres.
dict:
| Key | Description |
|---|---|
POSIT | GEO Cartesian positions along the line, shape (Nposit, 3) |
Nposit | Total number of traced points |
lm | McIlwain L shell |
blocal | Local B magnitude at each point, shape (Nposit,) |
bmin | Minimum B on the field line (nT) |
xj | Integral invariant J |
find_magequator(X, maginput)
Traces the field line from X and returns the coordinates and field magnitude at the magnetic equator (where |B| is minimum).
dict:
| Key | Description |
|---|---|
bmin | Field magnitude at the magnetic equator (nT) |
XGEO | GEO Cartesian coordinates of the magnetic equator, shape (3,) |
get_field_multi(X, maginput)
Computes the full GEO magnetic field vector and magnitude at one or more input locations.
dict:
| Key | Description |
|---|---|
BxGEO | X component of the field in GEO coordinates (nT) |
ByGEO | Y component of the field in GEO coordinates (nT) |
BzGEO | Z component of the field in GEO coordinates (nT) |
Bl | Total field magnitude (nT) |
get_mlt(X)
Returns the Magnetic Local Time (MLT) from a Cartesian GEO position and date. Unlike most other methods, X must supply GEO Cartesian coordinates regardless of the sysaxes set at construction.
float — MLT in hours (0–24).
bounce_period(X, maginput, E, Erest=511, R0=1, alpha=90, interpNum=100000)
Calculates the bounce period for a particle with kinetic energy E in an arbitrary magnetic field model. This method is not a direct IRBEM Fortran call; it uses trace_field_line and numerical integration.
Particle kinetic energy in keV. A single value or an array.
Particle rest energy in keV. Default is the electron rest mass (511 keV). Change this to compute bounce periods for other species.
Reference surface radius in Earth radii.
Local pitch angle in degrees.
Number of interpolation samples along the field line. Larger values improve accuracy at the cost of speed.
float or np.ndarray — bounce period(s) in seconds.
mirror_point_altitude(X, maginput, R0=1)
Calculates the mirror point altitude for locally mirroring particles in the opposite hemisphere. Complements find_mirror_point, which works in the same hemisphere.
Reference surface radius in Earth radii.
float — mirror point altitude in km.
Coords
Coords wraps IRBEM’s coordinate transformation subroutines. It shares the same path and verbose constructor keyword arguments as MagFields but has no kext, sysaxes, or options — coordinate transforms do not depend on a magnetic field model.
Constructor
transform(time, pos, sysaxesIn, sysaxesOut)
Transforms one or more position vectors from one coordinate system to another.
One datetime or a list/array of datetimes (or ISO-8601 strings) at which the positions are defined.
Position vector(s). For a single point pass a list of 3 values; for multiple points pass an
(N, 3) array-like.Source coordinate system (integer index or 3-letter string).
Target coordinate system (integer index or 3-letter string).
| Index | Code | Description |
|---|---|---|
| 0 | GDZ | Geodetic: altitude (km), latitude (°), East longitude (°) |
| 1 | GEO | Geographic Cartesian (Re) |
| 2 | GSM | Geocentric Solar Magnetospheric Cartesian (Re) |
| 3 | GSE | Geocentric Solar Ecliptic Cartesian (Re) |
| 4 | SM | Solar Magnetic Cartesian (Re) |
| 5 | GEI | Geocentric Equatorial Inertial Cartesian (Re) |
| 6 | MAG | Geomagnetic Cartesian (Re) |
| 7 | SPH | Geographic Spherical: radial distance (Re), latitude (°), East longitude (°) |
| 8 | RLL | Radial distance (Re), latitude (°), East longitude (°) — preferred over SPH |
np.ndarray — transformed positions. Shape (3,) for a single point, (N, 3) for multiple points.
Coords.coords_transform() is a deprecated alias for Coords.transform(). Use transform() in all new code.