This Jupyter notebook demonstrates using the cdasws Python package to retrieve data from two cdaweb datasets that have different timestamps and places the data on the same time grid (with optional spike removal). The data is returned in the SpacePy data model. The AC_H0_SWE and AC_H2_SWE datasets are used in this example. For more information on binning, see binning in cdaweb.
This notebook contains the following sections:
Install the prerequisite software the Python Package Index.
Execute some preliminary code that is necessary before the code that follows.
from cdasws.cdasws import CdasWs
import matplotlib.pyplot as plt
cdas = CdasWs()
The following code gets and displays the original, unbinned data.
dataset0 = 'AC_H0_SWE'
parameters = ['Np']
start = '1998-02-04T00:00:00Z'
stop = '1998-02-06T00:00:00Z'
status, data0 = cdas.get_data(dataset0, parameters, start, stop)
print(f'{dataset0}')
print(data0)
dataset1 = 'AC_H2_SWE'
status, data1 = cdas.get_data(dataset1, parameters, start, stop)
print()
print(f'{dataset1}')
print(data1)
AC_H0_SWE
<xarray.Dataset> Size: 32kB
Dimensions: (Epoch: 2700)
Coordinates:
* Epoch (Epoch) datetime64[ns] 22kB 1998-02-04T00:00:31 ... 1998-02-05T2...
Data variables:
Np (Epoch) float32 11kB nan nan nan nan ... 14.81 14.48 14.95 13.58
Attributes: (12/31)
TITLE: ['ACE> Solar Wind Parameters']
Project: ['ACE>Advanced Composition Explorer', 'ISTP>...
Discipline: ['Space Physics>Interplanetary Studies']
Source_name: ['AC>Advanced Composition Explorer']
Data_type: ['H0>64-sec Level 2 data']
Descriptor: ['SWEP>ACE Solar Wind Electron Proton Alpha ...
... ...
Rules_of_use: ['See the rules of use available from the AC...
Alt_logical_source: ['ACE_SWEPAM_Solar-Wind-Plasma-Level2-H0_64s...
spase_DatasetResourceID: ['spase://NASA/NumericalData/ACE/SWEPAM/L2/P...
DOI: ['https://doi.org/10.48322/tsfn-6v47']
CDAWEB_PARENTS: ['ac_h0_swe_00000000_v01', 'ac_h0_swe_199802...
PARENTS: ['ac_h0_swe_00000000_v01', 'ac_h0_swe_199802...
AC_H2_SWE
<xarray.Dataset> Size: 588B
Dimensions: (Epoch: 49)
Coordinates:
* Epoch (Epoch) datetime64[ns] 392B 1998-02-04 ... 1998-02-06
Data variables:
Np (Epoch) float32 196B nan nan nan nan nan ... 12.0 13.43 10.49 10.62
Attributes: (12/31)
TITLE: ['ACE> Solar Wind Parameters']
Project: ['ACE>Advanced Composition Explorer', 'ISTP>...
Discipline: ['Space Physics>Interplanetary Studies']
Source_name: ['AC>Advanced Composition Explorer']
Data_type: ['H2>1-hour Level 2 data']
Descriptor: ['SWEP>ACE Solar Wind Electron Proton Alpha ...
... ...
Rules_of_use: ['See the rules of use available from the AC...
Alt_logical_source: ['ACE_SWEPAM_Solar-Wind-Plasma-Level2_1hour_...
spase_DatasetResourceID: ['spase://NASA/NumericalData/ACE/SWEPAM/L2/P...
DOI: ['https://doi.org/10.48322/9w01-2555']
CDAWEB_PARENTS: ['ac_h2_swe_00000000_v01', 'ac_h2_swe_199802...
PARENTS: ['ac_h2_swe_00000000_v01', 'ac_h2_swe_199802...
The following code gets data after it has been binned with 60 second time intervals and any missing values created by interpolation.
binData = {
'interval': 60.0,
'interpolateMissingValues': True,
'sigmaMultiplier': 4
}
status, data0 = cdas.get_data(dataset0, parameters, start, stop, binData=binData)
print(f'{dataset0}')
print(data0)
status, data1 = cdas.get_data(dataset1, parameters, start, stop, binData=binData)
print()
print(f'{dataset1}')
print(data1)
AC_H0_SWE
<xarray.Dataset> Size: 91kB
Dimensions: (record0: 2700, Epoch_bin: 2880)
Coordinates:
* Epoch_bin (Epoch_bin) datetime64[ns] 23kB 1998-02-04T00:00:...
NP_BIN_DELTA_MINUS_VAR (Epoch_bin) float32 12kB nan nan nan ... nan nan nan
NP_BIN_DELTA_PLUS_VAR (Epoch_bin) float32 12kB nan nan nan ... nan nan nan
Dimensions without coordinates: record0
Data variables:
Epoch (record0) datetime64[ns] 22kB 1998-02-04T00:00:31...
Np (Epoch_bin) float32 12kB 16.33 16.33 ... 14.95 13.58
NP_NBIN (Epoch_bin) float32 12kB -0.0 -0.0 -0.0 ... 1.0 1.0
Attributes: (12/31)
TITLE: ['ACE> Solar Wind Parameters']
Project: ['ACE>Advanced Composition Explorer', 'ISTP>...
Discipline: ['Space Physics>Interplanetary Studies']
Source_name: ['AC>Advanced Composition Explorer']
Data_type: ['H0>64-sec Level 2 data']
Descriptor: ['SWEP>ACE Solar Wind Electron Proton Alpha ...
... ...
Rules_of_use: ['See the rules of use available from the AC...
Alt_logical_source: ['ACE_SWEPAM_Solar-Wind-Plasma-Level2-H0_64s...
spase_DatasetResourceID: ['spase://NASA/NumericalData/ACE/SWEPAM/L2/P...
DOI: ['https://doi.org/10.48322/tsfn-6v47']
CDAWEB_PARENTS: ['ac_h0_swe_00000000_v01', 'ac_h0_swe_199802...
PARENTS: ['ac_h0_swe_00000000_v01', 'ac_h0_swe_199802...
AC_H2_SWE
<xarray.Dataset> Size: 70kB
Dimensions: (record0: 49, Epoch_bin: 2880)
Coordinates:
* Epoch_bin (Epoch_bin) datetime64[ns] 23kB 1998-02-04T00:00:...
NP_BIN_DELTA_MINUS_VAR (Epoch_bin) float32 12kB nan nan nan ... nan nan nan
NP_BIN_DELTA_PLUS_VAR (Epoch_bin) float32 12kB nan nan nan ... nan nan nan
Dimensions without coordinates: record0
Data variables:
Epoch (record0) datetime64[ns] 392B 1998-02-04 ... 1998...
Np (Epoch_bin) float32 12kB 16.66 16.66 ... 10.49 10.49
NP_NBIN (Epoch_bin) float32 12kB -0.0 -0.0 ... -0.0 -0.0
Attributes: (12/31)
TITLE: ['ACE> Solar Wind Parameters']
Project: ['ACE>Advanced Composition Explorer', 'ISTP>...
Discipline: ['Space Physics>Interplanetary Studies']
Source_name: ['AC>Advanced Composition Explorer']
Data_type: ['H2>1-hour Level 2 data']
Descriptor: ['SWEP>ACE Solar Wind Electron Proton Alpha ...
... ...
Rules_of_use: ['See the rules of use available from the AC...
Alt_logical_source: ['ACE_SWEPAM_Solar-Wind-Plasma-Level2_1hour_...
spase_DatasetResourceID: ['spase://NASA/NumericalData/ACE/SWEPAM/L2/P...
DOI: ['https://doi.org/10.48322/9w01-2555']
CDAWEB_PARENTS: ['ac_h2_swe_00000000_v01', 'ac_h2_swe_199802...
PARENTS: ['ac_h2_swe_00000000_v01', 'ac_h2_swe_199802...
The following code compares the binned data from the two datasets by plotting the values.
plt.plot(data0['Epoch_bin'], data0['Np'])
plt.plot(data1['Epoch_bin'], data1['Np'])
plt.xlabel(data0['Epoch'].attrs['LABLAXIS'])
plt.xticks(rotation=45, ha='right')
plt.ylabel(data0['Np'].attrs['LABLAXIS'] + ' ' +
data0['Np'].attrs['UNITS'])
plt.legend([dataset0, dataset1])
plt.show()
View the cdasws API for additional functions. Additional notebook examples are also available.