đ Using HAPI#
Abstract: An overview of using HAPI to access Swarm data, and using hapiclient within the VRE. HAPI has been added to the VirES server as an alternative interface to the main VirES API. The Heliophysics Application Programming Interface (HAPI) is a community specification of a unified interface for accessing data time-series. VirES for Swarm acts as a HAPI server and allows access to selected datasets via the HAPI interface. This enables more interoperability with other analysis tools.
Learn more about HAPI
Information about the datasets through VirES+HAPI and more details:
https://vires.services/hapi/Overview of HAPI and other servers and clients:
https://hapi-server.org/
Only a few Swarm datasets are currently available through HAPI, but more will be available soon. HAPI is a more limited interface than the full VirES API so there is no access to special VirES features like magnetic model handling, resampling, and filtering.
Data is available at simple endpoints following /hapi/ and the interface is open so there is no authentication needed. For example:
!curl 'https://vires.services/hapi/data?dataset=SW_OPER_MAGA_LR_1B¶meters=Latitude,B_NEC&start=2013-11-25T11:02:52Z&stop=2013-11-25T11:03:02Z&format=csv'
2013-11-25T11:02:52.000Z,72.3503959,6308.4278,2347.3389,45294.474
2013-11-25T11:02:53.000Z,72.4134062,6282.6502,2344.2379,45301.376000000004
2013-11-25T11:02:54.000Z,72.4764122,6258.4517000000005,2341.4577,45309.2437
2013-11-25T11:02:55.000Z,72.5394137,6234.4708,2338.4647,45317.095700000005
2013-11-25T11:02:56.000Z,72.6024106,6210.6011,2335.447,45324.9253
2013-11-25T11:02:57.000Z,72.66540309999999,6187.0505,2331.8862,45332.634300000005
2013-11-25T11:02:58.000Z,72.7283908,6162.9089,2329.6645000000003,45340.3939
2013-11-25T11:02:59.000Z,72.79137399999999,6138.7093,2326.965,45348.1033
2013-11-25T11:03:00.000Z,72.8543524,6115.4042,2322.3379,45355.7506
2013-11-25T11:03:01.000Z,72.917326,6091.4546,2319.8754,45363.3795
Quickstart with hapiclient#
hapiclient is a Python client that interfaces with HAPI servers. It can be used like:
from hapiclient import hapi
server = 'https://vires.services/hapi';
dataset = 'SW_OPER_MAGA_LR_1B';
parameters = 'Latitude,B_NEC';
start = '2013-11-25T11:02:52Z';
stop = '2013-11-25T11:03:02Z';
data, meta = hapi(server, dataset, parameters, start, stop)
Data and metadata are returned separately as a NumPy Structured Array and dictionary.
data["Timestamp"]
array([b'2013-11-25T11:02:52.000Z', b'2013-11-25T11:02:53.000Z',
b'2013-11-25T11:02:54.000Z', b'2013-11-25T11:02:55.000Z',
b'2013-11-25T11:02:56.000Z', b'2013-11-25T11:02:57.000Z',
b'2013-11-25T11:02:58.000Z', b'2013-11-25T11:02:59.000Z',
b'2013-11-25T11:03:00.000Z', b'2013-11-25T11:03:01.000Z'],
dtype='|S24')
data["B_NEC"]
array([[ 6308.4278, 2347.3389, 45294.474 ],
[ 6282.6502, 2344.2379, 45301.376 ],
[ 6258.4517, 2341.4577, 45309.2437],
[ 6234.4708, 2338.4647, 45317.0957],
[ 6210.6011, 2335.447 , 45324.9253],
[ 6187.0505, 2331.8862, 45332.6343],
[ 6162.9089, 2329.6645, 45340.3939],
[ 6138.7093, 2326.965 , 45348.1033],
[ 6115.4042, 2322.3379, 45355.7506],
[ 6091.4546, 2319.8754, 45363.3795]])
For more help, see:
Demonstration notebooks:
hapi-server/client-python-notebooksTool which generates code snippets and more:
https://hapi-server.org/servers