hdpws HAPI Example Jupyter Notebook¶
This Jupyter notebook demonstrates using the hdpws Python package to find HAPI accessible data from the Space Physics Archive Search and Extract (SPASE) metadata documents at the Heliophysics Data Portal (HDP). It assumes some familarity with the SPASE data model. This notebook contains the following sections:
Prerequisites¶
Install the prerequisite software from Python Package Index (PyPI) software repository.
- pip install hdpws
Setup¶
Execute some preliminary code that is necessary before the code that follows.
from hdpws.hdpws import HdpWs
from hdpws import NAMESPACES as NS
from hdpws.resourcetype import ResourceType as rt
from hdpws.spase import HapiAccessURL
from IPython.core.display import HTML
hdp = HdpWs()
Get MeasurementTypes¶
The following code demonstrates how to get the list of available /Spase/MeasurementType values.
result = hdp.get_measurement_types()
print('HDP MeasurementTypes:')
for value in result['MeasurementType']:
print(f' {value}')
HDP MeasurementTypes: ActivityIndex Dopplergram Dust ElectricField EnergeticParticles Ephemeris ImageIntensity InstrumentStatus IonComposition Irradiance MagneticField Magnetogram NeutralAtomImages NeutralGas Profile Radiance Spectrum SPICE ThermalPlasma Waves Waves.Active Waves.Passive
Get ObservedRegions¶
The following code demonstrates how to get the list of available /Spase/ObservedRegion values.
result = hdp.get_observed_regions()
observed_regions = result['ObservedRegion']
print(f'{len(observed_regions)} HDP Observed Regions:')
for value in observed_regions[0:9]:
print(f' {value}')
print(' ...')
122 HDP Observed Regions: Asteroid Comet Earth Earth.Magnetosheath Earth.Magnetosphere Earth.Magnetosphere.Magnetotail Earth.Magnetosphere.Main Earth.Magnetosphere.Plasmasphere Earth.Magnetosphere.Polar ...
Get ObservatoryIDs¶
The following code demonstrates how to get the list of available /Spase/Observatory/ResourceID values.
result = hdp.get_observatory_ids()
observatory_ids = result['ObservatoryID']
print(f'{len(observatory_ids)} HDP ObservatoryIDs:')
for value in observatory_ids[0:9]:
print(f' {value}')
print(' ...')
2936 HDP ObservatoryIDs: spase://SMWG/Observatory/AE-D spase://SMWG/Observatory/Helios1 spase://SMWG/Observatory/DynamicsExplorer1 spase://SMWG/Observatory/SolarOrbiter spase://SMWG/Observatory/IMP8 spase://SMWG/Observatory/MarsExpress spase://SMWG/Observatory/GIRO spase://SMWG/Observatory/Interball-Tail spase://SMWG/Observatory/IRIS ...
Get NumericalData¶
The following code demonstrates how to find HAPI accessible SPASE NumericalData documents matching the specified search criteria.
query = {
'InstrumentID': 'spase://SMWG/Instrument/Wind/MFI',
'Cadence': '=PT3S',
'ObservedRegion': 'Heliosphere.NearEarth',
'MeasurementType': 'MagneticField',
'AccessRights': 'Open',
'Style': 'HAPI'
}
types = [rt.NUMERICAL_DATA]
time_range = ['2022-01-01', '2022-01-02']
result = hdp.get_spase_data(types, query, time_range)
if result['HttpStatus'] == 200:
for spase in result['Result'].findall('.//Spase',
namespaces=NS):
id = spase.find('.//ResourceID', namespaces=NS)
name = spase.find('.//Name', namespaces=NS)
description = spase.find('.//Description',
namespaces=NS)
print('Name: ', name.text)
print('ResourceID: ', id.text)
print('Description: ', description.text[:60], '...')
display(HTML('<a href="' + hdp.get_spase_url(id.text) +
'" target="_blank">' +
'HTML representation of SPASE</a>'))
hapi_access_url_element = \
spase.find('.//AccessURL[Style="HAPI"]', namespaces=NS)
if hapi_access_url_element is not None:
hapi_access_url = HapiAccessURL(hapi_access_url_element)
hapi_display_url = hapi_access_url.get_html_url()
hapi_html_link = "<a href=""" + \
hapi_display_url + \
""" target=""_blank"">HAPI access information</a>"""
display(HTML(hapi_html_link))
Name: Wind Spacecraft Homepage ResourceID: spase://NASA/NumericalData/Wind/MFI/PT03S Description: Wind MFI composite data in GSE and GSM coordinates. The file ...
Name: Wind Spacecraft Homepage ResourceID: spase://NASA/NumericalData/Wind/MFI/RTN/PT03S Description: Wind MFI composite data in RTN coordinates. The files contai ...