Package: hapiclient
HAPI Client for PythonBasic usage examples for various HAPI servers are given inhapi_demo.pyand the Examples section of a Jupyter Notebook hosted on Google Colab:.Installationpipinstallhapiclient--upgrade# orpipinstall'git+https://github.com/hapi-server/client-python'--upgradeThe optionalhapiplot packageprovides basic preview plotting capabilities of data from a HAPI server. ThePlotting sectionof thehapiclientJupyter Notebook shows how to plot the output ofhapiclientusing many other plotting libraries.To installhapiplot, usepipinstallhapiplot--upgrade# orpipinstall'git+https://github.com/hapi-server/plot-python'--upgradeSee theAppendixfor a fail-safe installation method.Basic Example# Get Dst index from CDAWeb HAPI serverfromhapiclientimporthapi# 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 datadata,meta=hapi(server,dataset,parameters,start,stop,**opts)print(meta)print(data)# Plot all parametersfromhapiplotimporthapiplothapiplot(data,meta)DocumentationBasic usage examples for various HAPI servers are given inhapi_demo.pyand theExamples sectionof a Jupyter Notebook hosted on Google Colab.Seehttp://hapi-server.org/servers/for a list of HAPI servers and datasets.All of the features are extensively demonstrated inhapi_demo.ipynb, a Jupyter Notebook that can be viewed an executed on Google Colab.Metadata ModelSee also the examples in theMetadata Model sectionof thehapiclientJupyter Notebook.The HAPI client metadata model is intentionally minimal and closely follows that of theHAPI metadata model. We expect that another library will be developed that allows high-level search and grouping of information from HAPI servers. See alsoissue #106.Data Model and Time FormatSee also the examples in theData Model sectionof thehapiclientJupyter Notebook. The examples includeFast and well-tested conversion from ISO 8601 timestamp strings to PythondatetimeobjectsPutting the content ofdatain a PandasDataFrameobjectCreating an Astropy NDArrayA request for data of the formdata, meta = hapi(server, dataset, parameters, start, stop)returns theNumpy N-D arraydataand a Python dictionarymetafrom a HAPI-compliant data serverserver. The structure ofdataandmetamirrors the structure of a response from a HAPI server.The HAPI client data model is intentionally basic. There is an ongoing discussion of a data model for Heliophysics data among thePyHC community. When this data model is complete, a function that convertsdataandmetato that data model will be included in thehapiclientpackage.Developmentgitclonehttps://github.com/hapi-server/client-pythoncdclient-python;pipinstall-e.or, create an isolated Anaconda installation (downloads and installs latest Miniconda3) usingmakeinstallPYTHON=python3.6# Execute command displayed to activate isolated environmentThe commandpip install -e .creates symlinks so that the local package is
used instead of an installed package. You may need to executepip uninstall hapiclientto ensure the local package is used. To check the version installed, usepip list | grep hapiclient.To run tests before a commit, executemakerepository-testTo run an individual unit test in a Python session, use, e.g.,fromhapiclient.test.test_hapiimporttest_reader_shorttest_reader_short()ContactSubmit bug reports and feature requests on therepository issue
tracker.AppendixFail-safe installationPython command line:importosprint(os.popen("pip install hapiclient").read())The above executes and displays the output of the operating system
commandpip install hapiclientusing the shell environment
associated with that installation of Python.This method addresses a problem that is sometimes encountered when
attempting to usepippackages in Anaconda. To use apippackage
in Anaconda, one must use the version ofpipinstalled with Anaconda
(it is usually under a subdirectory with the nameanaconda/) as
opposed to the one installed with the operating system. To see the
location ofpipused in a given Python session, enterprint(os.popen("which pip").read()).