hapiclient & hapiplot#

The Heliophysics Data Application Programmer’s Interface (HAPI) specification is a time series download and streaming format specification. There are several independent HAPI servers that enable a unified interface to data provided on those servers. See http://hapi-server.org/ for more information.

You can access data in Python with hapiclient and quickly plot such data with hapiplot:

from hapiclient import hapi
from hapiplot import hapiplot
# Get Dst index from CDAWeb HAPI server

# See http://hapi-server.org/servers/ for a list of
# other HAPI servers and datasets.
server     = 'https://cdaweb.gsfc.nasa.gov/hapi'
dataset    = 'OMNI2_H0_MRG1HR'
start      = '2003-09-01T00:00:00'
stop       = '2003-12-01T00:00:00'
parameters = 'DST1800'
opts       = {'logging': True}

# Get data
data, meta = hapi(server, dataset, parameters, start, stop, **opts)
hapi(): Running hapi.py version 0.2.5
hapi(): file directory = /tmp/hapi-data/cdaweb.gsfc.nasa.gov_hapi
hapi(): Reading /tmp/hapi-data/cdaweb.gsfc.nasa.gov_hapi
hapi(): Writing OMNI2_H0_MRG1HR___.json 
hapi(): Writing OMNI2_H0_MRG1HR___.pkl 
hapi(): Reading https://cdaweb.gsfc.nasa.gov/hapi/capabilities
hapi(): Writing https://cdaweb.gsfc.nasa.gov/hapi/data?id=OMNI2_H0_MRG1HR&parameters=DST1800&time.min=2003-09-01T00:00:00Z&time.max=2003-12-01T00:00:00Z&format=binary to OMNI2_H0_MRG1HR_DST1800_20030901T000000_20031201T000000.bin
hapi(): Reading and parsing OMNI2_H0_MRG1HR_DST1800_20030901T000000_20031201T000000.bin
hapi(): Writing /tmp/hapi-data/cdaweb.gsfc.nasa.gov_hapi/OMNI2_H0_MRG1HR_DST1800_20030901T000000_20031201T000000.pkl
hapi(): Writing /tmp/hapi-data/cdaweb.gsfc.nasa.gov_hapi/OMNI2_H0_MRG1HR_DST1800_20030901T000000_20031201T000000.npy
print(meta)
{'HAPI': '2.0', 'status': {'code': 1200, 'message': 'OK'}, 'parameters': [{'name': 'Time', 'type': 'isotime', 'units': 'UTC', 'length': 24, 'fill': None}, {'name': 'DST1800', 'type': 'integer', 'units': 'nT', 'fill': '99999', 'description': 'Dst - 1-hour Dst index (1963/001-2014/366), Provisional Dst (2017/001-2021/365), Quick-look Dst (2022/001-2021/296), from WDC Kyoto'}], 'startDate': '1970-01-01T00:00:00Z', 'stopDate': '2022-11-02T18:00:00Z', 'resourceURL': 'https://cdaweb.gsfc.nasa.gov/misc/NotesO.html#OMNI2_H0_MRG1HR', 'contact': 'J.H. King, N. Papitashvili @ ADNET, NASA GSFC', 'x_server': 'https://cdaweb.gsfc.nasa.gov/hapi', 'x_dataset': 'OMNI2_H0_MRG1HR', 'x_parameters': 'DST1800', 'x_time.min': '2003-09-01T00:00:00Z', 'x_time.max': '2003-12-01T00:00:00Z', 'x_requestDate': '2022-11-10T14:31:52', 'x_cacheDir': '/tmp/hapi-data/cdaweb.gsfc.nasa.gov_hapi', 'x_downloadTime': 0.6396651268005371, 'x_readTime': 0.0008366107940673828, 'x_metaFileParsed': '/tmp/hapi-data/cdaweb.gsfc.nasa.gov_hapi/OMNI2_H0_MRG1HR___.pkl', 'x_dataFileParsed': '/tmp/hapi-data/cdaweb.gsfc.nasa.gov_hapi/OMNI2_H0_MRG1HR_DST1800_20030901T000000_20031201T000000.npy', 'x_metaFile': '/tmp/hapi-data/cdaweb.gsfc.nasa.gov_hapi/OMNI2_H0_MRG1HR___.json', 'x_dataFile': '/tmp/hapi-data/cdaweb.gsfc.nasa.gov_hapi/OMNI2_H0_MRG1HR_DST1800_20030901T000000_20031201T000000.bin', 'x_totalTime': 0.8663744926452637}
print(data)
[(b'2003-09-01T00:30:00.000Z',   0) (b'2003-09-01T01:30:00.000Z',   4)
 (b'2003-09-01T02:30:00.000Z',   8) ... (b'2003-11-30T21:30:00.000Z', -38)
 (b'2003-11-30T22:30:00.000Z', -33) (b'2003-11-30T23:30:00.000Z', -27)]
# Plot all parameters
hapiplot(data, meta)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In [5], line 2
      1 # Plot all parameters
----> 2 hapiplot(data, meta)

File /usr/share/miniconda/envs/pyhc/lib/python3.10/site-packages/hapiplot/hapiplot.py:637, in hapiplot(*args, **kwargs)
    634         tsopts['nodata'] = True
    636     with rc_context(rc=opts['rcParams']):
--> 637         fig = timeseries(Time, y, **tsopts)
    639     meta["parameters"][i]['hapiplot']['figure'] = fig
    642 if opts['saveimage']:

File /usr/share/miniconda/envs/pyhc/lib/python3.10/site-packages/hapiplot/plot/timeseries.py:123, in timeseries(t, y, **kwargs)
    121 else:
    122     fig, ax = plt.subplots()
--> 123     fig.canvas.set_window_title(opts['title'])
    125 if len(y.shape) > 1:
    126     all_nan = np.full((y.shape[1]), False)

AttributeError: 'FigureCanvasAgg' object has no attribute 'set_window_title'
../_images/hapi_6_1.png