Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ec4ebbd
init endpoint files
akash5100 Jul 3, 2022
f2312e4
Parameterized the tests
akash5100 Jul 4, 2022
e08ec9e
test and base class for getJP2Header endpoint
akash5100 Jul 4, 2022
a8760e9
Add JPX endpoint
akash5100 Jul 4, 2022
c30d46c
Add getStatus endpoint
akash5100 Jul 4, 2022
58fb40d
Add closest to midpoint endpoint
akash5100 Jul 4, 2022
62f315b
replace time with datetime module to create timestamps
akash5100 Jul 5, 2022
94acba8
Replace Field with Optional
akash5100 Jul 5, 2022
0bfb6f4
revert the test
akash5100 Jul 5, 2022
b555d31
Remove test for unknown/invalid args
akash5100 Jul 5, 2022
ddf4390
Split Parameterized to multiple tests
akash5100 Jul 5, 2022
feb01bd
Split Parameterized to multiple tests
akash5100 Jul 5, 2022
61266b4
Revert changes to avoid merge conflict
akash5100 Jul 6, 2022
f8f4e0d
Fix repeating convert_date_to_isoformat function
akash5100 Jul 6, 2022
94be257
fix failing test
akash5100 Jul 6, 2022
df99124
enable reuse
nabobalis Jul 7, 2022
922c64e
init endpoint files
akash5100 Jul 3, 2022
98408fa
test and base class for getJP2Header endpoint
akash5100 Jul 4, 2022
b31f8f3
Add JPX endpoint
akash5100 Jul 4, 2022
c4d40eb
Add getStatus endpoint
akash5100 Jul 4, 2022
5e82f16
Add closest to midpoint endpoint
akash5100 Jul 4, 2022
c6eb20a
replace time with datetime module to create timestamps
akash5100 Jul 5, 2022
93ad96e
Replace Field with Optional
akash5100 Jul 5, 2022
a0793de
Remove test for unknown/invalid args
akash5100 Jul 5, 2022
021d4eb
Split Parameterized to multiple tests
akash5100 Jul 5, 2022
9ea7720
Split Parameterized to multiple tests
akash5100 Jul 5, 2022
d23e1fa
Revert changes to avoid merge conflict
akash5100 Jul 6, 2022
e0b6ab7
Fix repeating convert_date_to_isoformat function
akash5100 Jul 6, 2022
5c025c2
fix failing test
akash5100 Jul 6, 2022
6311073
enable reuse
nabobalis Jul 7, 2022
07dcf57
Merge branch 'main' into jpeg2000_endpoints
akash5100 Jul 8, 2022
81ed5d1
Remove test for unknown paramters
akash5100 Jul 8, 2022
a0e9a81
Merge branch 'jpeg2000_endpoints' of github.com:akash5100/python-api …
akash5100 Jul 8, 2022
1058cd1
Update hvpy/api_groups/jpeg2000/get_jpx.py
akash5100 Jul 8, 2022
c7d1bbd
Update hvpy/api_groups/jpeg2000/get_jpx_closest_to_mid_point.py
akash5100 Jul 8, 2022
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
29 changes: 29 additions & 0 deletions hvpy/api_groups/jpeg2000/get_jp2_header.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from typing import Optional

from hvpy.io import HvpyParameters, OutputType


class getJP2HeaderInputParameters(HvpyParameters):
"""
Handles the input parameters of the getJP2Header API.

Attributes
----------
id : int
Unique JP2 image identifier.
callback : str, optional
Wrap the response object in a function call of your choosing.

References
----------
* `<https://api.helioviewer.org/docs/v2/api/api_groups/jpeg2000.html#getjp2header>`__
"""

id: int
callback: Optional[str] = None

def get_output_type(self) -> OutputType:
"""
Returns the output type of the API call.
"""
return OutputType.STRING
9 changes: 2 additions & 7 deletions hvpy/api_groups/jpeg2000/get_jp2_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pydantic import Field, validator

from hvpy.io import HvpyParameters, OutputType
from hvpy.utils import convert_date_to_isoformat


class getJP2ImageInputParameters(HvpyParameters):
Expand Down Expand Up @@ -31,13 +32,7 @@ class getJP2ImageInputParameters(HvpyParameters):
sourceId: int
jpip: bool = False
Json: bool = Field(False, alias="json")

@validator("date")
def convert_date_to_isoformat(cls, v) -> str:
"""
Converts the date from a datetime object to a string in the ISO format.
"""
return v.isoformat() + "Z"
_date_validator = validator("date", allow_reuse=True)(convert_date_to_isoformat)

def get_output_type(self) -> OutputType:
"""
Expand Down
54 changes: 54 additions & 0 deletions hvpy/api_groups/jpeg2000/get_jpx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from typing import Optional
from datetime import datetime

from pydantic import validator

from hvpy.io import HvpyParameters, OutputType
from hvpy.utils import convert_date_to_isoformat


class getJPXInputParameters(HvpyParameters):
"""
Handles the input parameters of the getJPX API.

Attributes
----------
startTime : datetime
Date/Time for the beginning of the JPX movie data.
endTime : datetime
Date/Time for the end of the JPX movie data.
sourceId : int
Unique image datasource identifier.
linked : bool, optional
Generate a linked JPX file containing image pointers instead of data for each individual frame in the series.
verbose : bool, optional
If set to true, the JSON response will include timestamps for each frame in the resulting movie and any warning messages associated with the request, in addition to the JPX movie file URI.
jpip : bool, optional
Optionally return a JPIP URI string instead of the binary data of the movie itself, or instead of an HTTP URI in the JSON response (if verbose is set to true).
cadence : int, optional
The desired amount of time (in seconds) between each frame in the movie.

References
----------
* `<https://api.helioviewer.org/docs/v2/api/api_groups/jpeg2000.html#getjpx>`__
"""

startTime: datetime
endTime: datetime
sourceId: int
linked: bool = True
verbose: bool = False
jpip: bool = False
cadence: Optional[int] = None
_date_validator = validator("startTime", "endTime", allow_reuse=True)(convert_date_to_isoformat)

def get_output_type(self) -> OutputType:
"""
Returns the output type of the API call.
"""
if not self.jpip and not self.verbose:
return OutputType.RAW
elif self.jpip and not self.verbose:
return OutputType.STRING
else:
return OutputType.JSON
51 changes: 51 additions & 0 deletions hvpy/api_groups/jpeg2000/get_jpx_closest_to_mid_point.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from typing import List
from datetime import datetime

from pydantic import validator

from hvpy.io import HvpyParameters, OutputType
from hvpy.utils import convert_date_to_unix


class getJPXClosestToMidPointInputParameters(HvpyParameters):
"""
Handles the input parameters of the getJPXClosestToMidPoint API.

Attributes
----------
startTimes : datetime
Comma separated timestamps for the beginning of the JPX movie data.
endTimes : datetime
Comma separated timestamps for the end of the JPX movie data.
sourceId : int
Unique image datasource identifier.
linked : bool, optional
Generate a linked JPX file containing image pointers instead of data for each individual frame in the series.
verbose : bool, optional
If set to true, the JSON response will include timestamps for each frame in the resulting movie and any warning messages associated with the request, in addition to the JPX movie file URI.
jpip : bool, optional
Optionally return a JPIP URI string instead of the binary data of the movie itself, or instead of an HTTP URI in the JSON response (if verbose is set to true).

References
----------
* `<https://api.helioviewer.org/docs/v2/api/api_groups/jpeg2000.html#getjpxclosesttomidpoint>`__
"""

startTimes: List[datetime]
endTimes: List[datetime]
sourceId: int
linked: bool = True
verbose: bool = False
jpip: bool = False
_date_validator = validator("startTimes", "endTimes", allow_reuse=True)(convert_date_to_unix)

def get_output_type(self) -> OutputType:
"""
Returns the output type of the API call.
"""
if not self.jpip and not self.verbose:
return OutputType.RAW
elif self.jpip and not self.verbose:
return OutputType.STRING
else:
return OutputType.JSON
18 changes: 18 additions & 0 deletions hvpy/api_groups/jpeg2000/get_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from hvpy.io import HvpyParameters, OutputType


class getStatusInputParameters(HvpyParameters):
"""
Returns information about how far behind the latest available JPEG2000
images.

References
----------
* `<https://api.helioviewer.org/docs/v2/api/api_groups/jpeg2000.html#getstatus>`__
"""

def get_output_type(self) -> OutputType:
"""
Returns the output type of the API call.
"""
return OutputType.JSON
28 changes: 28 additions & 0 deletions hvpy/api_groups/jpeg2000/tests/test_get_jp2_header.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pytest
from pydantic import ValidationError

from hvpy.api_groups.jpeg2000.get_jp2_header import getJP2HeaderInputParameters
from hvpy.core import execute_api_call


def test_getJP2HeaderInputParameters():
params = getJP2HeaderInputParameters(id=9838343)
response = execute_api_call(input_parameters=params)
assert isinstance(response, str)
assert response.startswith("<?xml")
assert response.endswith("</meta>")

params = getJP2HeaderInputParameters(id=9838343, callback="my_callback")
response = execute_api_call(input_parameters=params)
assert isinstance(response, str)
assert response.startswith("my_callback(")


def test_error_handling():
with pytest.raises(ValidationError, match="getJP2HeaderInputParameters\nid\n field required"):
getJP2HeaderInputParameters(callback="my_callback")


def test_url_property():
params = getJP2HeaderInputParameters(id=9838343)
assert params.url == "https://api.helioviewer.org/v2/getJP2Header/"
3 changes: 1 addition & 2 deletions hvpy/api_groups/jpeg2000/tests/test_get_jp2_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def test_error_handling():


def test_url_property():
date_obj = datetime(2022, 1, 1, 23, 59, 59)
params = {"date": date_obj, "sourceId": 14, "jpip": True, "json": True}
params = {"date": datetime(2022, 1, 1, 23, 59, 59), "sourceId": 14, "jpip": True, "json": True}
params = getJP2ImageInputParameters(**params)
assert params.url == "https://api.helioviewer.org/v2/getJP2Image/"
82 changes: 82 additions & 0 deletions hvpy/api_groups/jpeg2000/tests/test_get_jpx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from datetime import datetime

import pytest
from pydantic import ValidationError

from hvpy.api_groups.jpeg2000.get_jpx import getJPXInputParameters
from hvpy.core import execute_api_call


def test_raw_response():
params = getJPXInputParameters(
startTime=datetime(2014, 1, 1, 0, 0, 0),
endTime=datetime(2014, 1, 1, 0, 45, 0),
sourceId=14,
linked=False,
verbose=False,
jpip=False,
cadence=None,
)
response = execute_api_call(params)
assert isinstance(response, bytes)


def test_str_response():
params = getJPXInputParameters(
startTime=datetime(2014, 1, 1, 0, 0, 0),
endTime=datetime(2014, 1, 1, 0, 45, 0),
sourceId=14,
linked=False,
verbose=False,
jpip=True,
cadence=None,
)
response = execute_api_call(params)
assert isinstance(response, str)
assert response.startswith("jpip://")


def test_json_response():
params = getJPXInputParameters(
startTime=datetime(2014, 1, 1, 0, 0, 0),
endTime=datetime(2014, 1, 1, 0, 45, 0),
sourceId=14,
linked=False,
verbose=True,
jpip=True,
cadence=None,
)
response = execute_api_call(params)
assert isinstance(response, dict)
assert response["uri"].startswith("jpip://")

params = getJPXInputParameters(
startTime=datetime(2014, 1, 1, 0, 0, 0),
endTime=datetime(2014, 1, 1, 0, 45, 0),
sourceId=14,
linked=False,
verbose=True,
jpip=False,
cadence=None,
)
response = execute_api_call(params)
assert isinstance(response, dict)
assert response["uri"].startswith("https://")


def test_error_handling():
with pytest.raises(ValidationError, match="getJPXInputParameters\nstartTime\n field required"):
getJPXInputParameters(endTime=datetime(2014, 1, 1, 0, 45, 0), sourceId=14)

with pytest.raises(ValidationError, match="getJPXInputParameters\nendTime\n field required"):
getJPXInputParameters(startTime=datetime(2014, 1, 1, 0, 0, 0), sourceId=14)

with pytest.raises(ValidationError, match="getJPXInputParameters\nsourceId\n field required"):
getJPXInputParameters(startTime=datetime(2014, 1, 1, 0, 0, 0), endTime=datetime(2014, 1, 1, 0, 45, 0))


def test_url_property():
params = getJPXInputParameters(
startTime=datetime(2014, 1, 1, 0, 0, 0), endTime=datetime(2014, 1, 1, 0, 45, 0), sourceId=14
)
assert params.url == "https://api.helioviewer.org/v2/getJPX/"
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from datetime import datetime

import pytest
from pydantic import ValidationError

from hvpy.api_groups.jpeg2000.get_jpx_closest_to_mid_point import getJPXClosestToMidPointInputParameters
from hvpy.core import execute_api_call

startTimes = [datetime(2014, 1, 1, 0, 0, 0), datetime(2014, 1, 1, 2, 3, 3), datetime(2014, 1, 1, 4, 5, 5)]
endTimes = [datetime(2014, 1, 1, 0, 45, 0), datetime(2014, 1, 1, 2, 33, 3), datetime(2014, 1, 1, 4, 54, 5)]


def test_raw_response():
params = getJPXClosestToMidPointInputParameters(
startTimes=startTimes, endTimes=endTimes, sourceId=14, linked=False, verbose=False, jpip=False
)
response = execute_api_call(input_parameters=params)
assert isinstance(response, bytes)


def test_str_response():
params = getJPXClosestToMidPointInputParameters(
startTimes=startTimes, endTimes=endTimes, sourceId=14, linked=False, verbose=False, jpip=True
)
response = execute_api_call(input_parameters=params)
assert isinstance(response, str)
assert response.startswith("jpip://")


def test_json_response():
params = getJPXClosestToMidPointInputParameters(
startTimes=startTimes, endTimes=endTimes, sourceId=14, linked=False, verbose=True, jpip=True
)
response = execute_api_call(input_parameters=params)
assert isinstance(response, dict)
assert response["uri"].startswith("jpip://")

params = getJPXClosestToMidPointInputParameters(
startTimes=startTimes, endTimes=endTimes, sourceId=14, linked=False, verbose=True, jpip=False
)
response = execute_api_call(input_parameters=params)
assert isinstance(response, dict)
assert response["uri"].startswith("https://")


def test_error_handling():
with pytest.raises(ValidationError, match="getJPXClosestToMidPointInputParameters\nstartTimes\n field required"):
getJPXClosestToMidPointInputParameters(endTimes=endTimes, sourceId=14)

with pytest.raises(ValidationError, match="getJPXClosestToMidPointInputParameters\nendTimes\n field required"):
getJPXClosestToMidPointInputParameters(startTimes=startTimes, sourceId=14)

with pytest.raises(ValidationError, match="getJPXClosestToMidPointInputParameters\nsourceId\n field required"):
getJPXClosestToMidPointInputParameters(startTimes=startTimes, endTimes=endTimes)


def test_url_property():
params = getJPXClosestToMidPointInputParameters(startTimes=startTimes, endTimes=endTimes, sourceId=14)
assert params.url == "https://api.helioviewer.org/v2/getJPXClosestToMidPoint/"
13 changes: 13 additions & 0 deletions hvpy/api_groups/jpeg2000/tests/test_get_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from hvpy.api_groups.jpeg2000.get_status import getStatusInputParameters
from hvpy.core import execute_api_call


def test_getStatusInputParameters():
params = getStatusInputParameters()
response = execute_api_call(input_parameters=params)
assert isinstance(response, dict)


def test_url_property():
params = getStatusInputParameters()
assert params.url == "https://api.helioviewer.org/v2/getStatus/"
2 changes: 1 addition & 1 deletion hvpy/io.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum, auto
from typing import Any, Dict

from pydantic.main import BaseModel
from pydantic import BaseModel

__all__ = ["HvpyParameters", "OutputType"]

Expand Down
Loading