CDFDatasets

DOI version

CDFDatasets.jl is a Julia package for reading CDF (Common Data Format) files, commonly used in space physics and other scientific domains. See CDF reader benchmarks for comparison with other CDF readers.

Installation

using Pkg
Pkg.add("CDFDatasets")

Quickstart

Here's a quick example using OMNI solar wind data:

using CDFDatasets

# Open a CDF dataset
omni_file = joinpath(pkgdir(CDFDatasets), "data/omni_coho1hr_merged_mag_plasma_20200501_v01.cdf")
ds = cdfopen(omni_file)
Dataset: /home/runner/work/CDFDatasets.jl/CDFDatasets.jl/data/omni_coho1hr_merged_mag_plasma_20200501_v01.cdf
Group: omni_coho1hr_merged_mag_plasma

Data variables
  heliographicLatitude (744) dims=Epoch [HelioGraphic Inertial (HGI) latitude; deg]
  heliographicLongitude (744) dims=Epoch [HGI longitude; deg]
  BR (744) dims=Epoch [BR in RTN (Radial-Tangential-Normal) coordinate system; nT]
  BT (744) dims=Epoch [BT in RTN coordinate system; nT]
  BN (744) dims=Epoch [BN in RTN coordinate system; nT]
  ABS_B (744) dims=Epoch [Field Magnitude Average |B  1/N SUM |B|; nT]
  V (744) dims=Epoch [Bulk Flow Speed; km/s]
  elevAngle (744) dims=Epoch [Proton flow elevation angle / latitude (RTN); Deg]
  azimuthAngle (744) dims=Epoch [Proton flow azimuth angle / longitude (RTN); Deg]
  N (744) dims=Epoch [Ion Density; N/cm3]
  T (744) dims=Epoch [Temperature; Deg K]
Support variables: Epoch
Global attributes
  28 attributes: Project, Discipline, Source_name, Data_type, Descriptor, Data_version, TITLE, TEXT, ...

Explore the dataset

julia> println("Variables: ", keys(ds))Variables: ["Epoch", "heliographicLatitude", "heliographicLongitude", "BR", "BT", "BN", "ABS_B", "V", "elevAngle", "azimuthAngle", "N", "T"]
julia> println("Attributes: ", keys(ds.attrib))Attributes: ["Project", "Discipline", "Source_name", "Data_type", "Descriptor", "Data_version", "TITLE", "TEXT", "MODS", "PI_name", "PI_affiliation", "Generation_date", "Acknowledgement", "ADID_ref", "Rules_of_use", "Instrument_type", "Generated_by", "Time_resolution", "Logical_file_id", "Logical_source", "Logical_source_description", "LINK_TEXT", "LINK_TITLE", "HTTP_LINK", "alt_logical_source", "Mission_group", "spase_DatasetResourceID", "DOI"]
julia> ds.attrib["Descriptor"]1-element Vector{String}: "merged magnetic field and plasma data from cohoweb"

Access variables

julia> ds["Epoch"]Epoch (744) dims=? [Epoch Time; DD-MMM-YYYY_hr:mm]
julia> ds["Epoch"][[1,end]]2-element Vector{Epoch}: 2020-05-01T00:00:00 2020-05-31T23:00:00
julia> ds["BR"]BR (744) dims=Epoch [BR in RTN (Radial-Tangential-Normal) coordinate system; nT]
julia> ds["BR"].attribCommonDataFormat.LazyAttrib{CommonDataFormat.CDFDataset{Int64}, Int32, Union{String, Vector}}("FIELDNAM" => "BR (RTN)", "CATDESC" => "BR in RTN (Radial-Tangential-Normal) coordinate system", "VALIDMIN" => Float32[-1000.0], "VALIDMAX" => Float32[1000.0], "UNITS" => "nT", "FORMAT" => "f6.1", "FILLVAL" => Float32[-1.0f31], "VAR_TYPE" => "data", "DISPLAY_TYPE" => "time_series", "DEPEND_0" => "Epoch"…)
# Calculate magnetic field magnitude
br = ds["BR"]
bt = ds["BT"]
bn = ds["BN"]
b_mag = sqrt.(br.^2 + bt.^2 + bn.^2) |> collect
744-element Vector{Float32}:
 3.544009
 2.9342802
 3.442383
 3.8961518
 0.64031243
 5.3721504
 5.4990907
 5.9514704
 4.3301272
 4.634652
 ⋮
 3.3301651
 2.9949956
 3.226453
 3.0380914
 3.828838
 3.3301651
 3.3674917
 3.749667
 3.8026307

API Reference

CDFDatasets.CDFDataset — Method
CDFDataset(file; checks = (;), master = nothing, varattrib = nothing)

Load the CDF dataset at the file path. Global attributes are entry vectors.

source
CDFDatasets.cdfopen — Method
cdfopen(file; kw...) :: CDFDataset
cdfopen(files, [t0, t1]; kw...) :: CDFDataset

Opens CDF file(s) as a CDFDataset, and restricts variables with a time coordinate to [t0, t1) when provided.

source
CDFDatasets.depend — Method
depend(var, i) :: Union{CDFVariable, Nothing}

Coordinate variable backing dimension i of var, or nothing when the dimension has no DEPEND.

source
CDFDatasets.variable — Method
variable(ds, name; metadata, fillval, validmin, validmax) :: CDFVariable

Variable name of ds, also ds[name]. The keywords override the dataset's checks and the attributes (README: Missing values).

source
SpaceDataModel.dims — Method
SpaceDataModel.dims(var::CDFVariable, i)

Coordinate of dimension i: its DEPEND, lazily and sliced like var, else nothing (also when the DEPEND does not fit). A non-record-varying coordinate loses its length-1 record dimension; a record-varying one keeps its records.

source