Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions hvpy/api_groups/official_clients/get_data_sources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from typing import Optional

from hvpy.io import HvpyParameters, OutputType


class getDataSourcesInputParameters(HvpyParameters):
"""
Handles the input parameters of the getDataSources API.

Attributes
----------
{Shared}
verbose : bool, optional
Output the hierarchical list of available datasources in a format that is compatible with the JHelioviewer desktop client, default is False.
enable : str, optional
Comma-separated list of observatories to enable.
callback : str, optional
Wrap the response object in a function call of your choosing.

References
----------
* `<https://api.helioviewer.org/docs/v2/api/api_groups/official_clients.html#getdatasources>`__
{Shared}
"""

verbose: Optional[bool] = False
enable: Optional[str] = None
callback: Optional[str] = None

def get_output_type(self) -> OutputType:
"""
Returns the output type of the API call.
"""
if self.callback:
return OutputType.STRING
else:
return OutputType.JSON
17 changes: 17 additions & 0 deletions hvpy/api_groups/official_clients/tests/test_get_data_sources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from hvpy import getDataSources


def test_json_response():
response = getDataSources()
assert isinstance(response, dict)


def test_str_response():
response = getDataSources(callback="callback")
assert isinstance(response, str)
assert response.startswith("callback(")


def test_enable_parameter():
response = getDataSources(verbose=False, enable="[Yohkoh,STEREO_A,STEREO_B]")
assert isinstance(response, dict)
37 changes: 36 additions & 1 deletion hvpy/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
from hvpy.parameters import *
from hvpy.utils import add_shared_docstring

__all__ = ["getJP2Image", "getJP2Header", "getJPXClosestToMidPoint", "getJPX", "getStatus", "getClosestImage"]
__all__ = [
"getJP2Image",
"getJP2Header",
"getJPXClosestToMidPoint",
"getJPX",
"getStatus",
"getClosestImage",
"getDataSources",
]


@add_shared_docstring(getJP2ImageInputParameters)
Expand Down Expand Up @@ -174,3 +182,30 @@ def getClosestImage(
"""
params = getClosestImageInputParameters(date=date, sourceId=sourceId, callback=callback)
return execute_api_call(input_parameters=params)


@add_shared_docstring(getDataSourcesInputParameters)
def getDataSources(
verbose: Optional[bool] = False,
enable: Optional[str] = None,
callback: Optional[str] = None,
) -> Union[bytes, str, Dict[str, Any]]:
"""
Return a hierarchial list of the available datasources.

Parameters
----------
{Insert}
Examples
--------
>>> from hvpy import getDataSources
>>> getDataSources()
{'SDO': {'HMI': {'continuum': {'sourceId': 18, 'nickname': 'HMI Int', 'layeringOrder': 1, 'start': '2010-12-06 06:53:41', 'end': '2022-07-11 23:59:54',
'uiLabels': [{'label': 'Observatory', 'name': 'SDO'}, {'label': 'Instrument', 'name': 'HMI'}, {'label': 'Measurement', 'name': 'continuum'}]}, ...}
"""
params = getDataSourcesInputParameters(
verbose=verbose,
enable=enable,
callback=callback,
)
return execute_api_call(input_parameters=params)
2 changes: 2 additions & 0 deletions hvpy/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from hvpy.api_groups.jpeg2000.get_jpx_closest_to_mid_point import getJPXClosestToMidPointInputParameters
from hvpy.api_groups.jpeg2000.get_status import getStatusInputParameters
from hvpy.api_groups.official_clients.get_closest_image import getClosestImageInputParameters
from hvpy.api_groups.official_clients.get_data_sources import getDataSourcesInputParameters

__all__ = [
"getJP2ImageInputParameters",
Expand All @@ -12,4 +13,5 @@
"getJPXInputParameters",
"getStatusInputParameters",
"getClosestImageInputParameters",
"getDataSourcesInputParameters",
]