Tutorial
This tutorial demonstrates how to use Speasy.jl to access space physics data.
Basic Data Retrieval
The simplest way to get data is using string identifiers with get_data
:
using Speasy
# Get IMF data from AMDA
imf_data = get_data("amda/imf", "2016-6-2", "2016-6-3")
SpeasyVariable{Float32, 2}: imf
Time Range: 2016-06-02T00:00:15 to 2016-06-02T23:59:59
Units: nT
Size: (5400, 3)
Memory Usage: 150.260 KiB
Metadata:
FILLVAL: Any[NaN]
FIELDNAM: b_gse
SI_CONVERSION: 1e-9>T
VALIDMAX: Any[3.4028234663852886e38]
TENSOR_ORDER: 0
TENSOR_FRAME: GSE
CATDESC: imf
VALIDMIN: Any[-3.4028234663852886e38]
DISPLAY_TYPE: time_series
UNITS: nT
VAR_NOTES:
DEPEND_0: AMDA_TIME
LABL_PTR_1: Any["bx", "by", "bz"]
FORMAT: F11.4
VAR_TYPE: data
DATA: N/A
Find the available datasets and parameters
Speasy.list_datasets
— Functionlist_datasets(provider, [term...])
Find the available datasets for a given provider, optionally filtered by search terms (only datasets containing all specified terms will be returned.)
Examples
# List all datasets from AMDA provider
list_datasets(:amda)
# List CDA datasets containing "OMNI"
list_datasets(:cda, :OMNI)
# List CDA datasets containing both "OMNI" and "HRO"
list_datasets(:cda, :OMNI, :HRO)
# output
4-element Vector{String}:
"OMNI_HRO_1MIN"
"OMNI_HRO2_1MIN"
"OMNI_HRO_5MIN"
"OMNI_HRO2_5MIN"
See also: list_parameters
Speasy.list_parameters
— Functionlist_parameters(provider, [dataset])
Find the available parameters for a given provider
or for a specific dataset
from provider
.
Examples
# List all parameters from AMDA provider
list_parameters(:amda)
# List parameters from specific CDA dataset
list_parameters(:cda, "SOHO_ERNE-HED_L2-1MIN")
# output
5-element Vector{String}:
"est"
"PH"
"AH"
"PHC"
"AHC"
See also: list_datasets
Using Dynamic Inventory
The dynamic inventory allows you to browse available datasets interactively:
# Create a shorthand reference
const spz = speasy
# Access the AMDA data tree
amda_tree = spz.inventories.data_tree.amda
# Navigate to specific parameters
ace_imf = amda_tree.Parameters.ACE.MFI.ace_imf_all.imf
data = get_data(ace_imf, "2016-6-2", "2016-6-3");
SpeasyVariable{Float32, 2}: imf
Time Range: 2016-06-02T00:00:15 to 2016-06-02T23:59:59
Units: nT
Size: (5400, 3)
Memory Usage: 150.260 KiB
Metadata:
FILLVAL: Any[NaN]
FIELDNAM: b_gse
SI_CONVERSION: 1e-9>T
VALIDMAX: Any[3.4028234663852886e38]
TENSOR_ORDER: 0
TENSOR_FRAME: GSE
CATDESC: imf
VALIDMIN: Any[-3.4028234663852886e38]
DISPLAY_TYPE: time_series
UNITS: nT
VAR_NOTES:
DEPEND_0: AMDA_TIME
LABL_PTR_1: Any["bx", "by", "bz"]
FORMAT: F11.4
VAR_TYPE: data
DATA: N/A
Using Macro
You can also use macro @spz_str
to define multiple products:
products = spz"cda/OMNI_HRO_1MIN/flow_speed,E,Pressure"
Pressure_product = products[3]
Product: cda/OMNI_HRO_1MIN/Pressure
Data (String):
cda/OMNI_HRO_1MIN/Pressure
Transformation (#get_data):
get_data
Metadata (NoMetadata):
SpaceDataModel.NoMetadata()
Products are function-like objects, so you can call them with time intervals as arguments to get the data:
Pressure_product("2016-6-2", "2016-6-3")
SpeasyVariable{Float32, 2}: Pressure
Time Range: 2016-06-02T00:00:00 to 2016-06-02T23:59:00
Units: nPa
Size: (1440, 1)
Memory Usage: 30.887 KiB
Metadata:
FILLVAL: Any[99.98999786376953]
FIELDNAM: Flow pressure
VALIDMAX: Any[100.0]
SCALEMAX: Any[100.0]
CATDESC: Flow pressure (nPa)
VALIDMIN: Any[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: Any[0.0]
LABLAXIS: Flow pressure
Multiple Parameters
You can request multiple parameters at once and get them as a NamedTuple:
products = [
spz.inventories.tree.amda.Parameters.Wind.SWE.wnd_swe_kp.wnd_swe_vth,
spz.inventories.tree.amda.Parameters.Wind.SWE.wnd_swe_kp.wnd_swe_pdyn,
spz.inventories.tree.amda.Parameters.Wind.SWE.wnd_swe_kp.wnd_swe_n
]
data = get_data(NamedTuple, products, "2010-01-02", "2010-01-02T01")
(wnd_swe_vth = wnd_swe_vth [Time Range: 2010-01-02T00:00:34.450 to 2010-01-02T00:58:42.023, Units: km/s, Size: (36, 1)], wnd_swe_pdyn = wnd_swe_pdyn [Time Range: 2010-01-02T00:00:34.450 to 2010-01-02T00:58:42.023, Units: nPa, Size: (36, 1)], wnd_swe_n = wnd_swe_n [Time Range: 2010-01-02T00:00:34.450 to 2010-01-02T00:58:42.023, Units: cm-3, Size: (36, 1)])
data.wnd_swe_n
SpeasyVariable{Float32, 2}: wnd_swe_n
Time Range: 2010-01-02T00:00:34.450 to 2010-01-02T00:58:42.023
Units: cm-3
Size: (36, 1)
Memory Usage: 3.318 KiB
Metadata:
FILLVAL: Any[NaN]
FIELDNAM: density
SI_CONVERSION:
VALIDMAX: Any[3.4028234663852886e38]
TENSOR_ORDER: 0
TENSOR_FRAME:
CATDESC: wnd_swe_n
VALIDMIN: Any[-3.4028234663852886e38]
DISPLAY_TYPE: time_series
UNITS: cm-3
VAR_NOTES:
DEPEND_0: AMDA_TIME
FORMAT: F11.4
VAR_TYPE: data
DATA: N/A
LABLAXIS: density
Multiple Time Intervals
You can also request data for multiple time intervals:
products = [
"cda/OMNI_HRO_1MIN/flow_speed",
"cda/OMNI_HRO_1MIN/Pressure"
]
intervals = [
["2010-01-02", "2010-01-02T01"],
["2009-08-02", "2009-08-02T01"]
]
get_data(products, intervals)
2-element Vector{Vector{SpeasyVariable{Float32, 2}}}:
[flow_speed [Time Range: 2010-01-02T00:00:00 to 2010-01-02T00:59:00, Units: km/s, Size: (60, 1)], flow_speed [Time Range: 2009-08-02T00:00:00 to 2009-08-02T00:59:00, Units: km/s, Size: (60, 1)]]
[Pressure [Time Range: 2010-01-02T00:00:00 to 2010-01-02T00:59:00, Units: nPa, Size: (60, 1)], Pressure [Time Range: 2009-08-02T00:00:00 to 2009-08-02T00:59:00, Units: nPa, Size: (60, 1)]]
Working with SSC Data
For trajectory data from SSCWeb:
# Get spacecraft trajectory (default is GSE)
trajectory = get_data("ssc/wind", "2016-6-2", "2016-6-3")
# Specify coordinate system
trajectory_gsm = get_data("ssc/wind/gsm", "2016-6-2", "2016-6-3")
SpeasyVariable{Float64, 2}:
Time Range: 2016-06-02T00:00:00 to 2016-06-02T23:48:00
Units: km
Size: (120, 3)
Memory Usage: 5.602 KiB
Metadata:
UNITS: km
CoordinateSystem: GSM
Accessing Data Properties
times(data.wnd_swe_n) # timestamps
parent(data.wnd_swe_n) # data values
36×1 PyArray{Float32, 2}:
NaN
7.661206
7.0948887
7.0640645
6.8097296
7.281172
7.003752
7.084024
6.8727236
7.785167
⋮
8.654632
8.165966
7.710116
8.210449
7.5762434
7.8650913
5.9453
7.1250095
7.671092