-
Notifications
You must be signed in to change notification settings - Fork 4
JPEG2000 endpoints #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dgarciabriseno
merged 35 commits into
Helioviewer-Project:main
from
akash5100:jpeg2000_endpoints
Jul 8, 2022
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
ec4ebbd
init endpoint files
akash5100 f2312e4
Parameterized the tests
akash5100 e08ec9e
test and base class for getJP2Header endpoint
akash5100 a8760e9
Add JPX endpoint
akash5100 c30d46c
Add getStatus endpoint
akash5100 58fb40d
Add closest to midpoint endpoint
akash5100 62f315b
replace time with datetime module to create timestamps
akash5100 94acba8
Replace Field with Optional
akash5100 0bfb6f4
revert the test
akash5100 b555d31
Remove test for unknown/invalid args
akash5100 ddf4390
Split Parameterized to multiple tests
akash5100 feb01bd
Split Parameterized to multiple tests
akash5100 61266b4
Revert changes to avoid merge conflict
akash5100 f8f4e0d
Fix repeating convert_date_to_isoformat function
akash5100 94be257
fix failing test
akash5100 df99124
enable reuse
nabobalis 922c64e
init endpoint files
akash5100 98408fa
test and base class for getJP2Header endpoint
akash5100 b31f8f3
Add JPX endpoint
akash5100 c4d40eb
Add getStatus endpoint
akash5100 5e82f16
Add closest to midpoint endpoint
akash5100 c6eb20a
replace time with datetime module to create timestamps
akash5100 93ad96e
Replace Field with Optional
akash5100 a0793de
Remove test for unknown/invalid args
akash5100 021d4eb
Split Parameterized to multiple tests
akash5100 9ea7720
Split Parameterized to multiple tests
akash5100 d23e1fa
Revert changes to avoid merge conflict
akash5100 e0b6ab7
Fix repeating convert_date_to_isoformat function
akash5100 5c025c2
fix failing test
akash5100 6311073
enable reuse
nabobalis 07dcf57
Merge branch 'main' into jpeg2000_endpoints
akash5100 81ed5d1
Remove test for unknown paramters
akash5100 a0e9a81
Merge branch 'jpeg2000_endpoints' of github.com:akash5100/python-api …
akash5100 1058cd1
Update hvpy/api_groups/jpeg2000/get_jpx.py
akash5100 c7d1bbd
Update hvpy/api_groups/jpeg2000/get_jpx_closest_to_mid_point.py
akash5100 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/" |
59 changes: 59 additions & 0 deletions
59
hvpy/api_groups/jpeg2000/tests/test_get_jpx_closest_to_mid_point.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.