-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #690 track
resample_spatial
in cube metadata
- Loading branch information
Showing
7 changed files
with
157 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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 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
Empty file.
This file contains 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,16 @@ | ||
from typing import Tuple, Union | ||
|
||
|
||
def normalize_resample_resolution( | ||
resolution: Union[int, float, Tuple[float, float], Tuple[int, int]] | ||
) -> Tuple[Union[int, float], Union[int, float]]: | ||
"""Normalize a resolution value, as used in the `resample_spatial` process to a two-element tuple.""" | ||
if isinstance(resolution, (int, float)): | ||
return (resolution, resolution) | ||
elif ( | ||
isinstance(resolution, (list, tuple)) | ||
and len(resolution) == 2 | ||
and all(isinstance(r, (int, float)) for r in resolution) | ||
): | ||
return tuple(resolution) | ||
raise ValueError(f"Invalid resolution {resolution!r}") |
This file contains 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 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 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 @@ | ||
import pytest | ||
|
||
from openeo.utils.normalize import normalize_resample_resolution | ||
|
||
|
||
@pytest.mark.parametrize( | ||
["resolution", "expected"], | ||
[ | ||
(1, (1, 1)), | ||
(1.23, (1.23, 1.23)), | ||
([1, 2], (1, 2)), | ||
((1.23, 2.34), (1.23, 2.34)), | ||
], | ||
) | ||
def test_normalize_resample_resolution(resolution, expected): | ||
assert normalize_resample_resolution(resolution) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"resolution", | ||
[ | ||
"0123", | ||
[1, 2, 3], | ||
{"x": 2, "y": 5}, | ||
], | ||
) | ||
def test_normalize_resample_resolution(resolution): | ||
with pytest.raises(ValueError, match="Invalid resolution"): | ||
normalize_resample_resolution(resolution) |