🌞 Using HAPI

🌞 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

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&parameters=Latitude,B_NEC&start=2013-11-25T11:02:52Z&stop=2013-11-25T11:03:02Z&format=csv'
2013-11-25T11:02:52.000Z,72.3503976,6308.470200000001,2347.2374,45294.5919

2013-11-25T11:02:53.000Z,72.4134067,6282.7241,2343.9951,45301.5368

2013-11-25T11:02:54.000Z,72.4764126,6258.5256,2341.2154,45309.4043

2013-11-25T11:02:55.000Z,72.5394141,6234.5447,2338.223,45317.2562

2013-11-25T11:02:56.000Z,72.6024111,6210.675200000001,2335.2058,45325.0857

2013-11-25T11:02:57.000Z,72.6654035,6187.1245,2331.6455,45332.7946

2013-11-25T11:02:58.000Z,72.7283913,6162.983,2329.4243,45340.554000000004

2013-11-25T11:02:59.000Z,72.7913744,6138.783600000001,2326.7253,45348.2633

2013-11-25T11:03:00.000Z,72.8543528,6115.4785,2322.0985,45355.910500000005

2013-11-25T11:03:01.000Z,72.9173265,6091.529,2319.6365,45363.539300000004

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.4702,  2347.2374, 45294.5919],
       [ 6282.7241,  2343.9951, 45301.5368],
       [ 6258.5256,  2341.2154, 45309.4043],
       [ 6234.5447,  2338.223 , 45317.2562],
       [ 6210.6752,  2335.2058, 45325.0857],
       [ 6187.1245,  2331.6455, 45332.7946],
       [ 6162.983 ,  2329.4243, 45340.554 ],
       [ 6138.7836,  2326.7253, 45348.2633],
       [ 6115.4785,  2322.0985, 45355.9105],
       [ 6091.529 ,  2319.6365, 45363.5393]])

For more help, see: