This Jupyter notebook demonstrates using the cdasws Python package to access a CDAWlib plot of data from cdaweb. This notebook contains the following sections:
Notes:
Install the prerequisite software from the Python Package Index if it is not already installed.
#%pip install -U cdasws
#%pip install -U matplotlib
Execute some preliminary code that is necessary before the code that follows.
from cdasws import CdasWs
from cdasws.datarequest import GraphOptions, ImageFormat, Overplot, TextFormat
import matplotlib.pyplot as plt
from matplotlib import image as mpimg
from PIL import Image
import urllib
cdas = CdasWs()
status, result = cdas.get_graph('AC_H1_MFI', ['Magnitude'],
'2009-06-01T00:00:00Z', '2009-06-02T00:10:00Z')
The following code demonstrates how to display the CDAWlib plot.
if status == 200:
graph = urllib.request.urlopen(result['FileDescription'][0]['Name'])
img = Image.open(graph)
plt.imshow(img)
plt.show()
else:
print('Error getting graph: ', status)
The above example was intentionally simple and accepted default values where possible. The following code demonstrates some of the additional options.
result = cdas.get_graph('AC_H1_MFI', ['Magnitude', 'BGSEc'],
'2009-06-01T00:00:00Z', '2009-06-02T00:10:00Z',
GraphOptions(coarse_noise_filter=True,
#x_axis_width_factor=4,
y_axis_height_factor=2,
combine=True,
overplot=Overplot.VECTOR_COMPONENTS),
[ImageFormat.PDF])[1]
print(result['FileDescription'][0]['Name'])
https://cdaweb.gsfc.nasa.gov/tmp/wsYdtNnS/AC_H1_MFI__000.pdf
The cdasws
package has many additional capabilities such as the following:
View the cdasws API for additional functions. Additional notebook examples are also available.