Getting Started with JuliaSpacePhysics

A quick tour of the ecosystem

This tutorial provides a quick introduction to the JuliaSpacePhysics ecosystem, demonstrating how to load, analyze, and visualize space physics data using Julia.

Open In Colab

What is JuliaSpacePhysics?

JuliaSpacePhysics is a collection of Julia packages for space physics research, providing tools for:

  • Data access: Loading data from CDAWeb, HAPI servers, Madrigal database, and other sources
  • Coordinate transformations: Converting between GSE, GSM, SM, and other coordinate systems
  • Magnetic field models: IGRF, Tsyganenko models, and planetary field models
  • Analysis: Plasma wave and instabilities analysis, velocity distribution analysis, minimum variance analysis, and more
Setup: install the required packages
using Pkg
Pkg.add(["CDAWeb", "CairoMakie", "SpacePhysicsMakie"])

Loading Space Physics Data

The ecosystem provides multiple ways to access space physics data. Here we demonstrate using CDAWeb.jl to fetch data from NASA’s Coordinated Data Analysis Web.

Let’s load ACE solar wind velocity data for a day in January 2024:

Code
using CDAWeb

t0 = "2024-01-02"
t1 = "2024-01-03"

ace_velocity = get_data("AC_H0_SWE", t0, t1)["V_GSE"]
V_GSE (3 × 1350)
  Datatype:    Float32
  Dimensions:  nothing × Epoch
  Attributes:
   FILLVAL              = Float32[-1.0f31]
   FIELDNAM             = Solar Wind Velocity (GSE)
   VALIDMAX             = Float32[0.0, 900.0, 900.0]
   SCALEMAX             = Float32[0.0, 500.0, 500.0]
   CATDESC              = Solar Wind Velocity in GSE coord., 3 components
   AVG_TYPE             =  
   VALIDMIN             = Float32[-1800.0, -900.0, -900.0]
   DISPLAY_TYPE         = time_series
   UNITS                = km/s
   VAR_NOTES            = Solar Wind Velocity in GSE coord., 3 components
   DEPEND_0             = Epoch
   LABL_PTR_1           = StaticStrings.StaticString{8}["VX (GSE)", "VY (GSE)", "VZ (GSE)"]
   FORMAT               = f8.1
   VAR_TYPE             = data
   SCALEMIN             = Float32[-1200.0, -500.0, -500.0]
   DICT_KEY             = velocity>solar_wind_GSE

We can also load high-resolution OMNI data which provides solar wind parameters propagated to the Earth’s bow shock:

Code
omni_dataset = get_data("OMNI_HRO_1MIN", t0, t1; clip=true)
omni_pressure = omni_dataset["Pressure"]
View:  1441:2881
 Pressure  (44640)
   Datatype:    Float32
   Dimensions:  Epoch
   Attributes:
    FILLVAL              = Float32[99.99]
    FIELDNAM             = Flow pressure
    VALIDMAX             = Float32[100.0]
    SCALEMAX             = Float32[100.0]
    CATDESC              = Flow pressure (nPa)
    VALIDMIN             = Float32[0.0]
    DISPLAY_TYPE         = time_series
    UNITS                = nPa
    VAR_NOTES            = Derived parameters are obtained from the following equations. Flow pressure = (2*10**-6)*Np*Vp**2 nPa (Np in cm**-3, Vp in km/s, subscript p for proton) 
    DEPEND_0             = Epoch
    BIN_LOCATION         = 0.0
    FORMAT               = F5.2
    VAR_TYPE             = data
    SCALEMIN             = Float32[0.0]
    LABLAXIS             = Flow pressure

Visualizing the Data

SpacePhysicsMakie.jl provides the tplot function for creating publication-quality time-series plots:

Single Variable Plot

Code
using SpacePhysicsMakie, CairoMakie

tplot(ace_velocity, add_title=true)

Multi-Panel Plot

Combine multiple variables into a single figure with stacked panels:

Code
tplot((ace_velocity, omni_pressure), add_title=true)

Magnetic Field Models

The ecosystem includes sophisticated magnetic field models for Earth and other planets. This section demonstrates how to use Tsyganenko models for Earth’s magnetosphere and planetary field models for other solar system bodies.

First, install the required packages:

Code
using Pkg
Pkg.add(["PlanetaryMagneticFields", "TsyganenkoModels", "SpaceDataModel", "DimensionalData", "CDAWeb", "CairoMakie", "GeoMakie", "SpacePhysicsMakie"])
   Resolving package versions...
     Project No packages added to or removed from `~/src/juliaspacephysics.github.io/Project.toml`
    Manifest No packages added to or removed from `~/src/juliaspacephysics.github.io/Manifest.toml`

Earth Magnetosphere: Tsyganenko Models

Let’s fetch MMS1 spacecraft data, then calculate the magnetic field along the trajectory using the Tsyganenko-IGRF combined model TsyIGRF provided by TsyganenkoModels.jl:

Code
using TsyganenkoModels
using CDAWeb, DimensionalData
using SpacePhysicsMakie, CairoMakie
using SpaceDataModel

dataset = CDAWeb.get_data("MMS1_MEC_SRVY_L2_EPHT89Q", "2015-10-16", "2015-10-17")
r = dataset["mms1_mec_r_gsm"] |> DimArray
v = dataset["mms1_mec_v_gsm"] |> DimArray
tplot([r, v])
Code
model = TsyIGRF()

Bgsm = setmeta(
    model(r; scale=1 / 6371.2),
    "LABLAXIS" => "mms1_mec_r_gsm_bt89", "UNITS" => "nT", "LABL_PTR_1" => ["Bx", "By", "Bz"],
)
tplot([r, v, Bgsm])

Planetary Magnetic Fields

The PlanetaryMagneticFields.jl package provides models for magnetic fields of planets throughout the solar system. Here we visualize Jupiter’s magnetic field using the JRM09 model:

Code
using PlanetaryMagneticFields
using GeoMakie

model = JRM09() # Load Jupiter's JRM09 model

plot_fieldmap(model;
    r=1.0,
    axis=(; title="Jupiter Radial Magnetic Field (JRM09)"),
)

Next Steps

This tutorial covered the basics of loading and visualizing space physics data. To learn more:

Environment Info

Code
using Pkg
Pkg.status()
versioninfo()
Status `~/src/juliaspacephysics.github.io/Project.toml`
  [950ff2a9] CDAWeb v0.2.0
  [075ae62b] CDFDatasets v0.1.12 `~/.julia/dev/CDFDatasets`
  [13f3f980] CairoMakie v0.15.8
  [0703355e] DimensionalData v0.29.25
  [db073c08] GeoMakie v0.7.16
  [548c34cc] PlanetaryMagneticFields v0.1.1
  [0b37b92c] SpaceDataModel v0.2.4
  [0c28ffd8] SpacePhysicsMakie v0.2.4
  [31d49243] TimeseriesUtilities v0.1.5
  [14dfbe45] TsyganenkoModels v0.1.2
  [1986cc42] Unitful v1.28.0
  [276b4fcb] WGLMakie v0.13.8
Julia Version 1.12.4
Commit 01a2eadb047 (2026-01-06 16:56 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: macOS (arm64-apple-darwin24.0.0)
  CPU: 12 × Apple M2 Max
  WORD_SIZE: 64
  LLVM: libLLVM-18.1.7 (ORCJIT, apple-m2)
  GC: Built with stock GC
Threads: 8 default, 1 interactive, 8 GC (on 8 virtual cores)
Environment:
  JULIA_PROJECT = @.
  JULIA_CONDAPKG_OPENSSL_VERSION = ignore
  JULIA_NUM_THREADS = auto
  JULIA_LOAD_PATH = @:@stdlib

References

Back to top