|
2 | 2 | User Guide |
3 | 3 | ********** |
4 | 4 |
|
5 | | -This user guide provides a walkthrough of the major features in the ``hvpy`` package. |
| 5 | +This guide provides a walkthrough of the major features in the ``hvpy`` package. |
| 6 | +``hvpy`` is a python wrapper for the `Helioviewer API <https://api.helioviewer.org/docs/v2/>`__, which is the same API that powers `helioviewer.org <https://helioviewer.org>`__. |
| 7 | + |
| 8 | +Basic Usage |
| 9 | +----------- |
| 10 | +Each API endpoint has a function in ``hvpy`` that shares the same name and has the same input parameters. |
| 11 | +For example if you are looking at `getJP2Image <https://api.helioviewer.org/docs/v2/api/api_groups/jpeg2000.html#getjp2image>`__ in the Helioviewer documentation, you would execute this in ``hvpy`` with the following command: |
| 12 | + |
| 13 | +.. code-block:: Python |
| 14 | +
|
| 15 | + import hvpy |
| 16 | + from hvpy.datasource import DataSource |
| 17 | + from datetime import datetime |
| 18 | +
|
| 19 | + jp2 = hvpy.getJP2Image(datetime.now(), DataSource.AIA_94.value) |
| 20 | +
|
| 21 | +Managing Return Types |
| 22 | +--------------------- |
| 23 | +``hvpy`` will attempt to coerce the result into a Python datatype for you. |
| 24 | +In general, there are 3 types of results you can expect from the API: |
| 25 | + |
| 26 | +1. Raw Data |
| 27 | +2. Strings |
| 28 | +3. JSON |
| 29 | + |
| 30 | +In ``hvpy`` these return types map to: |
| 31 | + |
| 32 | +1. `bytearray` |
| 33 | +2. `str` |
| 34 | +3. `dict` |
| 35 | + |
| 36 | +Sometimes the return type will change dependending on the input parameters you specify. |
| 37 | +Make sure to review your input parameters carefully. |
| 38 | +The descriptions in both our :ref:`api-reference` and the `API Docs <https://api.helioviewer.org/docs/v2/>`__ will say whether certain parameters change the output type. |
| 39 | + |
| 40 | +Helper Functions |
| 41 | +---------------- |
| 42 | +``hvpy`` provides a few helper functions for certain actions that generally require multiple API reqeusts. |
| 43 | +There are also helper functions for actions that may require more work than a simple API call. |
| 44 | + |
| 45 | +Helper Flows |
| 46 | +^^^^^^^^^^^^ |
| 47 | +For example, creating a movie requires calling `hvpy.queueMovie` followed by `hvpy.getMovieStatus` to see if the movie is done. |
| 48 | +Then you would call `hvpy.downloadMovie` to get the result. |
| 49 | +``hvpy`` provides some helper functions to perform these flows for you. |
| 50 | + |
| 51 | +Datasource & Event Selection |
| 52 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 53 | +Some API requests accept a list of datasources and events. |
| 54 | +These are in a very specific format. |
| 55 | +For example layering an SDO/AIA 94 and an SDO/AIA 304 image might look like "[13,1,50],[8,1,50]". |
| 56 | +Since ``hvpy`` provides a one to one mapping, you would have to understand and create this string yourself. |
| 57 | +To do this, you would have to go figure out how helioviewer likes its layer strings, and find the IDs for each source. |
| 58 | + |
| 59 | +``hvpy`` makes this easy by providing a function for you. |
| 60 | +`hvpy.utils.create_layers` will create this string for you. |
| 61 | +You simply specify a tuple with the source enum you want, and the opacity it should have the end result. |
| 62 | + |
| 63 | +.. code-block:: Python |
| 64 | +
|
| 65 | + from hvpy.utils import create_layers |
| 66 | + from hvpy.datasource import DataSource |
| 67 | +
|
| 68 | + layer_string = create_layers([(DataSource.AIA_304, 50), (DataSource.AIA_94, 50)]) |
| 69 | + print(layer_string) |
| 70 | + "[13,1,50],[8,1,50]" |
| 71 | +
|
| 72 | +There is a similar function for choosing events that you want to have displayed in `hvpy.utils.create_events` |
| 73 | + |
| 74 | +Miscellaneous Helpers |
| 75 | +^^^^^^^^^^^^^^^^^^^^^ |
| 76 | +``hvpy`` also provides some miscellaneous helper functions. |
| 77 | +For example, since many API endpoints return raw data like images or videos, we've implemented a simple `hvpy.utils.save_file` to save this binary data to disk. |
0 commit comments