Load and visualize data from a variety of sources

We demonstrate here how to load data from a variety of data sources and visualize them using SpacePhysicsMakie.jl.

Setup
dir = "tutorials/data_loading"
if isdir(dir)
    cd(dir)
end

Pkg.activate(".")
Pkg.resolve()
Pkg.instantiate()

using CairoMakie, SpacePhysicsMakie

Get data with CDAWeb

CDAWeb.jl provides direct access to NASA’s CDAWeb RESTful services with local caching and fine-grained control over data retrieval.

It could be installed at REPL via using Pkg; Pkg.add("CDAWeb").

Code
import CDAWeb
t0 = "2024-01-02"
t1 = "2024-01-03"
# Fetch ACE magnetic field data
data1 = CDAWeb.get_data("AC_H0_SWE", "V_GSE", t0, t1)
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

Plot the data

Code
tplot(data1, add_title=true)

Get data with Speasy

Speasy.jl provides functions to load data from main Space Physics WebServices (CDA,SSC,AMDA,..).

It could be installed at REPL via using Pkg; Pkg.add("Speasy").

Code
import Speasy

data2 = Speasy.get_data("cda/OMNI_HRO_1MIN/Pressure", t0, t1; sanitize=true)
    CondaPkg Found dependencies: /Users/zijin/.julia/packages/DimensionalData/FWnw9/CondaPkg.toml
    CondaPkg Found dependencies: /Users/zijin/.julia/packages/Speasy/ZygLN/CondaPkg.toml
    CondaPkg Found dependencies: /Users/zijin/.julia/packages/CondaPkg/0UqYV/CondaPkg.toml
    CondaPkg Found dependencies: /Users/zijin/.julia/packages/PythonCall/wkBj7/CondaPkg.toml
    CondaPkg Found dependencies: /Users/zijin/.julia/packages/PySPEDAS/IGdx7/CondaPkg.toml
    CondaPkg Initialising pixi
             /Users/zijin/.julia/artifacts/d2fecc2a9fa3eac2108d3e4d9d155e6ff5dfd0b2/bin/pixi
             init
             --format pixi
             /Users/zijin/src/juliaspacephysics.github.io/tutorials/data_loading/.CondaPkg
✔ Created /Users/zijin/src/juliaspacephysics.github.io/tutorials/data_loading/.CondaPkg/pixi.toml
    CondaPkg Wrote /Users/zijin/src/juliaspacephysics.github.io/tutorials/data_loading/.CondaPkg/pixi.toml
             [dependencies]
             netcdf4 = "*"
             openssl = ">=3, <3.6, >=3, <3.6"
             uv = ">=0.4"
             xarray = "*"
             sqlite = "!=3.49.1"
             numpy = "*"
                              [dependencies.python]
                 channel = "conda-forge"
                 build = "*cp*"
                 version = ">=3.10,<3.14, 3.13.*"
                          [project]
             name = ".CondaPkg"
             platforms = ["osx-arm64"]
             channels = ["conda-forge"]
             channel-priority = "strict"
             description = "automatically generated by CondaPkg.jl"
                          [pypi-dependencies.speasy]
             git = "https://github.com/SciQLop/speasy"
                          [pypi-dependencies.pyspedas]
             git = "https://github.com/spedas/pyspedas"
    CondaPkg Installing packages
             /Users/zijin/.julia/artifacts/d2fecc2a9fa3eac2108d3e4d9d155e6ff5dfd0b2/bin/pixi
             install
             --manifest-path /Users/zijin/src/juliaspacephysics.github.io/tutorials/data_loading/.CondaPkg/pixi.toml
✔ The default environment has been installed.
SpeasyVariable{Float32, 2}: Pressure
  Time Range: 2024-01-02T00:00:00.000000000 to 2024-01-02T23:59:00.000000000
  Units: nPa
  Size: (1440, 1)
  Memory Usage: 18.021 KiB
  Metadata:
    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) 
    FILLVAL: Any[99.98999786376953]
    DEPEND_0: Epoch
    BIN_LOCATION: 0.0
    FIELDNAM: Flow pressure
    VALIDMAX: Any[100.0]
    SCALEMAX: Any[100.0]
    FORMAT: F5.2
    VAR_TYPE: data
    CATDESC: Flow pressure (nPa)
    SCALEMIN: Any[0.0]
    LABLAXIS: Flow pressure
    VALIDMIN: Any[0.0]
    DISPLAY_TYPE: time_series
    UNITS: nPa

Plot the data

Code
tplot(data2)

Get data using Heliophysics Application Programmer’s Interface (HAPI)

HAPIClient.jl provides functions to load data from HAPI-compliant servers.

It could be installed at REPL via using Pkg; Pkg.add("HAPIClient").

Code
import HAPIClient

vars = HAPIClient.get_data("CDAWeb/AC_H0_MFI/Magnitude,BGSEc", t0, t1)
HAPIVariables: CDAWeb/AC_H0_MFI (https://cdaweb.gsfc.nasa.gov/hapi/data?time.min=2024-01-02T00%3A00%3A00.000Z&parameters=Magnitude%2CBGSEc&format=csv&id=AC_H0_MFI&time.max=2024-01-03T00%3A00%3A00.000Z)
  Magnitude [Time Range: 2024-01-02T00:00:12 to 2024-01-02T23:59:56, Units: nT, Size: (5400,)]
  BGSEc [Time Range: 2024-01-02T00:00:12 to 2024-01-02T23:59:56, Units: nT, Size: (5400, 3)]
Metadata - JSON.Object{String, Any} with 7 entries:
  "HAPI"        => "2.0"
  "resourceURL" => "https://cdaweb.gsfc.nasa.gov/misc/NotesA.html#AC_H0_MFI"
  "contact"     => "N. Ness @ Bartol Research Institute"
  "parameters"  => Any[Object{String, Any}("name"=>"Time", "length"=>24, "units…
  "startDate"   => "1997-09-02T00:00:12Z"
  "stopDate"    => "2025-11-07T23:59:44Z"
  "status"      => Object{String, Any}("code"=>1200, "message"=>"OK")

Plot the data

Code
tplot(vars)

Get data with PySPEDAS

PySPEDAS.jl provides a Julia interface to the PySPEDAS Python package, offering a similar API for Julia users to utilize the existing Python routines.

It could be installed at REPL via using Pkg; Pkg.add("PySPEDAS").

Code
using PySPEDAS.Projects

# Same as more verbose `pyspedas.projects.themis.fgm(...)`
tvars = themis.fgm([t0, t1], time_clip=true, probe="d");
23-Nov-25 23:12:21: Downloading remote index: https://themis.ssl.berkeley.edu/data/themis/thd/l2/fgm/2024/
23-Nov-25 23:12:22: File is current: /Users/zijin/data/themis/thd/l2/fgm/2024/thd_l2_fgm_20240102_v01.cdf

Plot the data

Code
tplot((tvars.thd_fgs_gsm, tvars.thd_fgs_btotal))

Composite plot

Combine all the data into a single plot with multiple panels.

Code
tplot((data1, data2, vars..., tvars.thd_fgs_gsm), add_title=true)

Reproducibility

Code
using Pkg
Pkg.status()
Status `~/src/juliaspacephysics.github.io/tutorials/data_loading/Project.toml`
  [950ff2a9] CDAWeb v0.1.4
  [075ae62b] CDFDatasets v0.1.8 `~/.julia/dev/CDFDatasets`
  [13f3f980] CairoMakie v0.15.7
  [0703355e] DimensionalData v0.29.25
  [0ce0b37c] HAPIClient v0.2.2
  [668d2cef] PySPEDAS v0.1.6
  [0b37b92c] SpaceDataModel v0.2.2 `~/.julia/dev/SpaceDataModel`
  [0c28ffd8] SpacePhysicsMakie v0.2.4 `~/.julia/dev/SpacePhysicsMakie`
  [09b745ad] Speasy v0.4.8
Code
using InteractiveUtils # hide
versioninfo()
Julia Version 1.12.2
Commit ca9b6662be4 (2025-11-20 16:25 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: 1 default, 1 interactive, 1 GC (on 8 virtual cores)
Environment:
  JULIA_PROJECT = @.
  JULIA_LOAD_PATH = @:@stdlib
Back to top