-
Notifications
You must be signed in to change notification settings - Fork 0
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
Hv check test suite #120
Merged
Merged
Hv check test suite #120
Changes from 40 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
3a7d87a
fix: added comments in the tests
HansVRP cfebc1f
test feature extration unit test
HansVRP d8d45c8
test feature extraction unit test
HansVRP dd5e7da
fix: add abstract methods to dummyclass
HansVRP 7b62eae
fix: add espg setter to feature extractor
HansVRP 8762aa1
fix: lat lon assert
HansVRP d75f11c
fix: mockarray for excecute test
HansVRP 2237b92
fix: work on mocks
HansVRP 43b6559
fix: work on mocks
HansVRP ecf11d3
fix: work on mocks
HansVRP 8ffdabe
fix: work on mocks
HansVRP 21ab48c
fix: work on mocks
HansVRP 8f60edf
fix: work on mocks
HansVRP 3eb1635
fix: work on mocks
HansVRP a5605f2
fix: work on mocks
HansVRP 34be739
fix: work on mocks
HansVRP 7246d9e
fix: work on mocks
HansVRP 428f1a3
fix: work on mocks
HansVRP f23230c
fix: work on mocks
HansVRP 2fadb34
fix: work on mocks
HansVRP 478a692
fix: work on mocks
HansVRP 66d21c4
fix: work on mocks
HansVRP 7ccfddb
fix: work on mocks
HansVRP 9d76a18
fix: include test_unit_patch
HansVRP 65cd4f7
fix: improve readibility and avoid random
HansVRP b621528
fix: improve readibility and avoid random
HansVRP ee42242
pass through precommit
HansVRP e59d8fb
disable integration tests
HansVRP 8276b11
Merge branch 'main' into hv_check_test_suite
HansVRP 4cbffc6
fix: resolve merge conflict
HansVRP 441dec5
fix: resolve merge conflict
HansVRP 973d959
fix: avoid mocking pyproj
HansVRP 647ed52
fix: add assert on pyproj
HansVRP 60cc32a
fix: remove random from test and remove mock pyproj
HansVRP ee46130
clean up darker
HansVRP 76fab68
fix: skip excecute test
HansVRP 6cb75c2
fix: skip excecute test
HansVRP 41d408b
Merge branch 'main' into hv_check_test_suite
HansVRP c4da77f
remove comment
HansVRP 7b13472
resolve merge conflict
HansVRP c5d1394
fix; remove .nc
HansVRP 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 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
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
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
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,103 @@ | ||
from unittest.mock import MagicMock | ||
|
||
import numpy as np | ||
import pytest | ||
import xarray as xr | ||
|
||
from openeo_gfmap.features import PatchFeatureExtractor | ||
|
||
LAT_HARMONIZED_NAME = "GEO-LAT" | ||
LON_HARMONIZED_NAME = "GEO-LON" | ||
EPSG_HARMONIZED_NAME = "GEO-EPSG" | ||
|
||
|
||
# Mock class for the patch feature extractor | ||
class DummyPatchFeatureExtractor(PatchFeatureExtractor): | ||
def output_labels(self): | ||
return ["label1", "label2"] | ||
|
||
def execute(self, inarr: xr.DataArray) -> xr.DataArray: | ||
return inarr # Simplified for testing purposes | ||
|
||
|
||
@pytest.fixture | ||
def mock_feature_extractor(): | ||
return DummyPatchFeatureExtractor() | ||
|
||
|
||
@pytest.fixture | ||
def mock_data_array(): | ||
return xr.DataArray(np.array([[1, 2], [3, 4]]), dims=["y", "x"]) | ||
|
||
|
||
def test_get_latlons_epsg_none(mock_feature_extractor, mock_data_array): | ||
mock_feature_extractor._epsg = None | ||
with pytest.raises(Exception): | ||
mock_feature_extractor.get_latlons(mock_data_array) | ||
|
||
|
||
def test_get_latlons_epsg_4326(mock_feature_extractor, mock_data_array): | ||
mock_feature_extractor._epsg = 4326 | ||
result = mock_feature_extractor.get_latlons(mock_data_array) | ||
assert LAT_HARMONIZED_NAME in result.coords["bands"].values | ||
assert LON_HARMONIZED_NAME in result.coords["bands"].values | ||
|
||
|
||
def test_get_latlons_reproject(mock_feature_extractor, mock_data_array): | ||
mock_feature_extractor._epsg = ( | ||
3857 # Set the EPSG code to the desired projection (e.g., Web Mercator) | ||
) | ||
|
||
# Create mock coordinates matching the 'x' and 'y' dimensions | ||
x_coords = mock_data_array.coords["x"].values | ||
y_coords = mock_data_array.coords["y"].values | ||
|
||
xx, yy = np.meshgrid(x_coords, y_coords) | ||
result = mock_feature_extractor.get_latlons(mock_data_array) | ||
|
||
# Assert the expected behavior (add your specific assertions here) | ||
assert result is not None | ||
assert result[0].shape == xx.shape | ||
assert result[1].shape == yy.shape | ||
|
||
|
||
# test rescaling | ||
def test_rescale_s1_backscatter_valid(mock_feature_extractor, mock_data_array): | ||
s1_bands = ["S1-SIGMA0-VV", "S1-SIGMA0-VH"] | ||
data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]], dtype=np.uint16) | ||
mock_data_array = xr.DataArray( | ||
data, dims=["bands", "y", "x"], coords={"bands": s1_bands} | ||
) | ||
|
||
result = mock_feature_extractor._rescale_s1_backscatter(mock_data_array) | ||
assert result.dtype == np.uint16 | ||
|
||
|
||
# TODO | ||
@pytest.mark.skip( | ||
reason="Skipping test for since underlying excecutor needs to be changed" | ||
) | ||
def test_execute(): | ||
# Create an instance of the extractor | ||
extractor = DummyPatchFeatureExtractor() | ||
extractor._parameters = {"rescale_s1": True} | ||
|
||
# Mock the cube | ||
data = np.ones((1, 2, 2, 2)) | ||
mock_cube = MagicMock() | ||
mock_cube.get_array.return_value = xr.DataArray(data, dims=["bands", "t", "y", "x"]) | ||
|
||
# Mock the methods | ||
extractor._common_preparations = MagicMock(return_value=mock_cube.get_array()) | ||
extractor._rescale_s1_backscatter = MagicMock(return_value=mock_cube.get_array()) | ||
|
||
# Execute the method | ||
result = extractor._execute(mock_cube, {}) | ||
|
||
# Ensure the result is correctly transposed to have dimensions ["bands", "y", "x"] | ||
expected_dims = ["bands", "t", "y", "x"] | ||
assert result.get_array().dims == expected_dims | ||
|
||
# Check that the mock methods were called | ||
extractor._common_preparations.assert_called() | ||
extractor._rescale_s1_backscatter.assert_called() |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this file be commited?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably not