The following code demonstrates how to access magnetic field measurements from the ACE mission dataset using the cdasws package in a Jupyter notebook.
from cdasws import CdasWs
import matplotlib.pyplot as plt
cdas = CdasWs()
data = cdas.get_data('AC_H1_MFI', ['Magnitude', 'BGSEc'],
'2009-06-01T00:00:00Z', '2009-06-01T00:10:00Z')[1]
print(data)
{'Epoch': VarCopy([datetime.datetime(2009, 6, 1, 0, 0), datetime.datetime(2009, 6, 1, 0, 4), datetime.datetime(2009, 6, 1, 0, 8)], dtype=object), 'Magnitude': VarCopy([3.495, 3.474, 3.477], dtype=float32), 'BGSEc': VarCopy([[-0.106, 2.521, -2.391], [-0.412, 2.402, -2.449], [-0.094, 2.309, -2.587]], dtype=float32), 'cartesian': VarCopy(['x_component', 'y_component', 'z_component'], dtype='<U11'), 'metavar0': VarCopy(['Bx GSE', 'By GSE', 'Bz GSE'], dtype='<U6')}
To display metadata for the Magnitude variable, do
print(data['Magnitude'].attrs)
{'FIELDNAM': 'B-field magnitude', 'VALIDMIN': 0.0, 'VALIDMAX': 500.0, 'SCALEMIN': 0.0, 'SCALEMAX': 10.0, 'UNITS': 'nT', 'FORMAT': 'F8.3', 'VAR_TYPE': 'data', 'DICT_KEY': 'magnetic_field>magnitude', 'FILLVAL': -1e+31, 'DEPEND_0': 'Epoch_bin', 'CATDESC': 'B-field magnitude', 'LABLAXIS': '<|B|>', 'DISPLAY_TYPE': 'time_series', 'DIM_SIZES': 0}
To plot the Magnitude values using the label values from the metadata, do
plt.plot(data['Epoch'], data['Magnitude'])
plt.xlabel(data['Epoch'].attrs['LABLAXIS'])
plt.ylabel(data['Magnitude'].attrs['LABLAXIS'] + ' ' +
data['Magnitude'].attrs['UNITS'])
plt.show()
To have uniformly spaced (with respect to time) values computed (with optional spike removal), add the binData keyword paramter like this
status, data = cdas.get_data('AC_H1_MFI', ['Magnitude', 'BGSEc'],
'2009-06-01T00:00:00Z', '2009-06-01T00:10:00Z',
binData={
'interval': 60.0,
'interpolateMissingValues': True,
'sigmaMultiplier': 4
})
print(data)
{'Epoch_bin': VarCopy([datetime.datetime(2009, 6, 1, 0, 0, 30), datetime.datetime(2009, 6, 1, 0, 1, 30), datetime.datetime(2009, 6, 1, 0, 2, 30), datetime.datetime(2009, 6, 1, 0, 3, 30), datetime.datetime(2009, 6, 1, 0, 4, 30), datetime.datetime(2009, 6, 1, 0, 5, 30), datetime.datetime(2009, 6, 1, 0, 6, 30), datetime.datetime(2009, 6, 1, 0, 7, 30), datetime.datetime(2009, 6, 1, 0, 8, 30), datetime.datetime(2009, 6, 1, 0, 9, 30)], dtype=object), 'Epoch': VarCopy([datetime.datetime(2009, 6, 1, 0, 0), datetime.datetime(2009, 6, 1, 0, 4), datetime.datetime(2009, 6, 1, 0, 8)], dtype=object), 'Magnitude': VarCopy([3.495 , 3.48975, 3.4845 , 3.47925, 3.474 , 3.47475, 3.4755 , 3.47625, 3.477 , 3.477 ], dtype=float32), 'BGSEc': VarCopy([[-0.106 , 2.521 , -2.391 ], [-0.1825 , 2.49125 , -2.4055 ], [-0.259 , 2.4615 , -2.42 ], [-0.3355 , 2.4317498, -2.4345 ], [-0.412 , 2.402 , -2.449 ], [-0.3325 , 2.3787498, -2.4835 ], [-0.253 , 2.3555 , -2.518 ], [-0.1735 , 2.33225 , -2.5524998], [-0.094 , 2.309 , -2.587 ], [-0.094 , 2.309 , -2.587 ]], dtype=float32), 'MAGNITUDE_NBIN': VarCopy([1., 0., 0., 0., 1., 0., 0., 0., 1., 0.], dtype=float32), 'MAGNITUDE_BIN_DELTA_MINUS_VAR': VarCopy([-1.e+31, -1.e+31, -1.e+31, -1.e+31, -1.e+31, -1.e+31, -1.e+31, -1.e+31, -1.e+31, -1.e+31], dtype=float32), 'MAGNITUDE_BIN_DELTA_PLUS_VAR': VarCopy([-1.e+31, -1.e+31, -1.e+31, -1.e+31, -1.e+31, -1.e+31, -1.e+31, -1.e+31, -1.e+31, -1.e+31], dtype=float32), 'BGSEC_NBIN': VarCopy([[ 1., 1., 1.], [-0., -0., -0.], [-0., -0., -0.], [-0., -0., -0.], [ 1., 1., 1.], [-0., -0., -0.], [-0., -0., -0.], [-0., -0., -0.], [ 1., 1., 1.], [-0., -0., -0.]], dtype=float32), 'BGSEC_BIN_DELTA_MINUS_VAR': VarCopy([[-1.e+31, -1.e+31, -1.e+31], [-1.e+31, -1.e+31, -1.e+31], [-1.e+31, -1.e+31, -1.e+31], [-1.e+31, -1.e+31, -1.e+31], [-1.e+31, -1.e+31, -1.e+31], [-1.e+31, -1.e+31, -1.e+31], [-1.e+31, -1.e+31, -1.e+31], [-1.e+31, -1.e+31, -1.e+31], [-1.e+31, -1.e+31, -1.e+31], [-1.e+31, -1.e+31, -1.e+31]], dtype=float32), 'BGSEC_BIN_DELTA_PLUS_VAR': VarCopy([[-1.e+31, -1.e+31, -1.e+31], [-1.e+31, -1.e+31, -1.e+31], [-1.e+31, -1.e+31, -1.e+31], [-1.e+31, -1.e+31, -1.e+31], [-1.e+31, -1.e+31, -1.e+31], [-1.e+31, -1.e+31, -1.e+31], [-1.e+31, -1.e+31, -1.e+31], [-1.e+31, -1.e+31, -1.e+31], [-1.e+31, -1.e+31, -1.e+31], [-1.e+31, -1.e+31, -1.e+31]], dtype=float32), 'cartesian_bin': VarCopy(['x_component', 'y_component', 'z_component'], dtype='<U11'), 'cartesian': VarCopy(['x_component', 'y_component', 'z_component'], dtype='<U11'), 'metavar0': VarCopy(['Bx GSE', 'By GSE', 'Bz GSE'], dtype='<U6'), 'metavar1': VarCopy(['# of Bx GSE', '# of By GSE', '# of Bz GSE'], dtype='<U11'), 'metavar2': VarCopy('# of ', dtype='<U5')}
To get data from a dataset with a digital object identifier do the following:
status, data = cdas.get_data('10.21978/P8PG8V', ['BT'], '1987-09-24T00:00:00Z', '1987-09-25T00:00:00Z')
print(data.attrs['Descriptor'])
print(data)
['MFI>3-axis fluxgate magnetometer averages'] {'Epoch': VarCopy([datetime.datetime(1987, 9, 24, 0, 30, 1, 567000), datetime.datetime(1987, 9, 24, 0, 30, 5, 567000), datetime.datetime(1987, 9, 24, 0, 30, 9, 567000), ..., datetime.datetime(1987, 9, 24, 23, 59, 51, 368000), datetime.datetime(1987, 9, 24, 23, 59, 55, 369000), datetime.datetime(1987, 9, 24, 23, 59, 59, 369000)], dtype=object), 'BT': VarCopy([89.8591, 89.7978, 89.7269, ..., 18.5909, 18.6276, 18.5359], dtype=float32)}
View the cdasws API for additional functions.