This Jupyter notebook demonstrates using the cdasws Python package to access NetCDF data from cdaweb with the data returned in the xarray.Dataset. This notebook contains the following sections:
Notes:
Install the prerequisite software from the Python Package Index if it is not already installed.
%pip install xarray cdflib cdasws -q
Note: you may need to restart the kernel to use updated packages.
Execute some preliminary code that is necessary before the code that follows.
from cdasws.cdasws import CdasWs
from cdasws.datarepresentation import DataRepresentation as dr
import matplotlib.pyplot as plt
cdas = CdasWs()
The following code demonstrates how to get the available observatory groups.
obs_groups = cdas.get_observatory_groups()
for index, obs_group in enumerate(obs_groups):
obs_group_name = obs_group['Name']
if 'ICON' in obs_group_name:
print(obs_group_name)
ICON
The following code demontrates how to get a list of datasets.
datasets = cdas.get_datasets(observatoryGroup='ICON')
for index, dataset in enumerate(datasets):
print(dataset['Id'], dataset['Label'])
ICON_L2-1_MIGHTI-A_LOS-WIND-GREEN Michelson Interferometer for Global High-resolution Thermospheric Imaging (MIGHTI) Sensor A: Line-of-sight Wind Profiles - T. J. Immel (UC Berkeley>SSL) ICON_L2-1_MIGHTI-A_LOS-WIND-RED Michelson Interferometer for Global High-resolution Thermospheric Imaging (MIGHTI) Sensor A: Line-of-sight Wind Profiles - T. J. Immel (UC Berkeley>SSL) ICON_L2-1_MIGHTI-B_LOS-WIND-GREEN Michelson Interferometer for Global High-resolution Thermospheric Imaging (MIGHTI) Sensor B - Line-of-sight Wind Profiles - T. J. Immel (UC Berkeley>SSL) ICON_L2-1_MIGHTI-B_LOS-WIND-RED Michelson Interferometer for Global High-resolution Thermospheric Imaging (MIGHTI) Sensor B - Line-of-sight Wind Profiles - T. J. Immel (UC Berkeley>SSL) ICON_L2-2_MIGHTI_VECTOR-WIND-GREEN MIGHTI - Cardinal Vector Winds - T. J. Immel (UC Berkeley>SSL) ICON_L2-2_MIGHTI_VECTOR-WIND-RED MIGHTI - Cardinal Vector Winds - T. J. Immel (UC Berkeley>SSL) ICON_L2-3_MIGHTI-A_TEMPERATURE ICON MIGHTI-A Level 2.3 Retrieved Temperature File - T. J. Immel (UC Berkeley>SSL) ICON_L2-3_MIGHTI-B_TEMPERATURE ICON MIGHTI-B Level 2.3 Retrieved Temperature File - T. J. Immel (UC Berkeley>SSL) ICON_L2-4_FUV_DAY ICON FUV Daytime: column density ratio of thermospheric atomic oxygen to molecular nitrogen. - T. J. Immel (UC Berkeley>SSL) ICON_L2-4_FUV_DAY-LIMB ICON FUV Daytime Limb - T. J. Immel (UC Berkeley > SSL) ICON_L2-5_FUV_NIGHT FUV Short Wavelength Channel - 135.6 Altitude Profiles (night) - T. J. Immel (UC Berkeley>SSL) ICON_L2-6_EUV ICON EUV derived ionospheric data products - T. J. Immel (UC Berkeley>SSL) ICON_L2-7_IVM-A ICON Ion Velocity Meter (IVM) Thermal Plasma Measurements - T. J. Immel (UC Berkeley>SSL) ICON_L2-7_IVM-B ICON IVM Thermal Plasma Measurements B - T. J. Immel (UC Berkeley>SSL)
The following code demonstrates how to get a dataset's variables.
ds_id = 'ICON_L2-4_FUV_DAY'
var_names = []
variables = cdas.get_variables(ds_id)
for variable in variables:
var_name = variable['Name']
var_names.append(var_name)
print(var_name, variable['LongDescription'])
ICON_L24_1356_Emission Disk short wave emission ICON_L24_Ap Ap used in retreival ICON_L24_Disk_LOS_Zen_Angle Retrieved disk LOS zenith angle ICON_L24_Disk_Latitude Retrieved disk latitude ICON_L24_Disk_Longitude Retrieved disk longitude ICON_L24_Disk_ON2 Retrieved disk column O/N2 ICON_L24_Disk_SZA Retrieved disk SZA ICON_L24_Disk_Sigma_ON2 Retrieved disk column O/N2 uncertainty ICON_L24_LBH_Emission Disk long wave emission
The following code demonstrates how to get NetCDF data from the ICON_L2-4_FUV_DAY dataset.
data = cdas.get_data(ds_id, var_names,
'2022-11-24T23:00:00Z', '2022-11-24T23:05:00Z',
dataRepresentation = dr.XARRAY)[1]
print(data)
<xarray.Dataset> Size: 57kB
Dimensions: (Epoch_cdf: 24, record0: 6951)
Coordinates:
* Epoch_cdf (Epoch_cdf) datetime64[ns] 192B 2022-11-24T2...
Dimensions without coordinates: record0
Data variables:
time_base datetime64[ns] 8B 1970-01-01
ICON_L24_1356_Emission (Epoch_cdf) float32 96B 3.877e+03 ... 3.661e+03
ICON_L24_Ap (Epoch_cdf) float32 96B 9.0 9.0 9.0 ... 9.0 9.0
ICON_L24_Disk_LOS_Zen_Angle (Epoch_cdf) float32 96B 119.9 119.9 ... 119.9
ICON_L24_Disk_Latitude (Epoch_cdf) float32 96B -19.67 ... -18.34
ICON_L24_Disk_Longitude (Epoch_cdf) float32 96B 200.5 201.3 ... 217.8
ICON_L24_Disk_ON2 (Epoch_cdf) float32 96B 0.6418 0.672 ... 0.6956
ICON_L24_Disk_SZA (Epoch_cdf) float32 96B 8.413 9.165 ... 25.87
ICON_L24_Disk_Sigma_ON2 (Epoch_cdf) float32 96B 0.03897 ... 0.05703
ICON_L24_LBH_Emission (Epoch_cdf) float32 96B 1.015e+03 ... 900.1
Epoch (record0) int64 56kB 1669248003023 ... 16693...
Attributes: (12/40)
Acknowledgement: ['This is a data product from the NASA Ionos...
ADID_ref: ['NASA Contract>NNG12FA45C']
Calibration_file: [' ']
Conventions: ['SPDF ISTP/IACG Modified for NetCDF']
Data_level: ['L2.4']
Data_type: ['DP24>Data Product 2.4: FUV Daytime']
... ...
Nco: ['netCDF Operators version 4.8.1 (Homepage =...
Nc_kind: ['netCDF-4']
Nc_dimensions_g: ['Epoch=UNLIMITED', 'Covariance Matrix 2nd D...
Nc_strings_g: ['Acknowledgement ADID_Ref Calibration_File ...
spase_DatasetResourceID: ['spase://NASA/NumericalData/ICON/FUV/L2/Day...
DOI: ['https://doi.org/10.48322/w3qs-ed95']
The following code displays metadata for the ICON_L24_Disk_SZA variable, do
print(data.ICON_L24_Disk_SZA)
<xarray.DataArray 'ICON_L24_Disk_SZA' (Epoch_cdf: 24)> Size: 96B
array([ 8.413165, 9.165311, 9.919736, 10.674797, 11.431073, 12.187651,
12.945468, 13.703261, 14.462048, 15.220608, 15.980153, 16.739532,
17.499659, 18.259481, 19.019903, 19.780228, 20.540913, 21.30163 ,
22.062748, 22.823668, 23.585054, 24.345064, 25.106302, 25.867178],
dtype=float32)
Coordinates:
* Epoch_cdf (Epoch_cdf) datetime64[ns] 192B 2022-11-24T23:00:10.767000 ......
Attributes: (12/19)
FIELDNAM: Retrieved disk SZA
NC_DIMENSIONS_V: Epoch
NC_DEFLATE: 6
NC_SHUFFLE: true
NC_STORAGE: chunked
NC_CHUNKSIZES: 7013
... ...
VAR_NOTES: Solar zenith angle corresponding to disk retrieval
VAR_TYPE: data
NC_STRINGS_V: CatDesc Depend_0 Display_Type FieldNam Long_Name Units ...
DIM_SIZES: 0
standard_name: Retrieved disk SZA
units: Degrees
The following code plots the ICON_L24_Disk_SZA variable's values using the label values from the metadata.
data['ICON_L24_Disk_SZA'].plot()
[<matplotlib.lines.Line2D at 0x7fe2861c83a0>]
View the cdasws API for additional functions. Additional notebook examples are also available.