diff --git a/features/eolearn/tests/conftest.py b/features/eolearn/tests/conftest.py index d2c2c5776..e319f4dbb 100644 --- a/features/eolearn/tests/conftest.py +++ b/features/eolearn/tests/conftest.py @@ -8,6 +8,8 @@ from eolearn.core import EOPatch +pytest.register_assert_rewrite("sentinelhub.testing_utils") # makes asserts in helper functions work with pytest + EXAMPLE_DATA_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", "example_data") EXAMPLE_EOPATCH_PATH = os.path.join(EXAMPLE_DATA_PATH, "TestEOPatch") diff --git a/features/eolearn/tests/test_blob.py b/features/eolearn/tests/test_blob.py index 7e294fe0e..af3feee15 100644 --- a/features/eolearn/tests/test_blob.py +++ b/features/eolearn/tests/test_blob.py @@ -11,51 +11,50 @@ import copy import sys -import numpy as np import pytest -from numpy.testing import assert_array_equal from pytest import approx from skimage.feature import blob_dog +from sentinelhub.testing_utils import test_numpy_data + from eolearn.core import FeatureType -from eolearn.core.eodata_io import FeatureIO from eolearn.features import BlobTask, DoGBlobTask, DoHBlobTask, LoGBlobTask FEATURE = (FeatureType.DATA, "NDVI", "blob") +BLOB_FEATURE = (FeatureType.DATA, "blob") -def test_blob_feature(small_ndvi_eopatch): +def test_dog_blob_task(small_ndvi_eopatch): eopatch = small_ndvi_eopatch BlobTask(FEATURE, blob_dog, sigma_ratio=1.6, min_sigma=1, max_sigma=30, overlap=0.5, threshold=0)(eopatch) DoGBlobTask((FeatureType.DATA, "NDVI", "blob_dog"), threshold=0)(eopatch) - assert eopatch.data["blob"] == approx( - eopatch.data["blob_dog"] - ), "DoG derived class result not equal to base class result" + assert eopatch[BLOB_FEATURE] == approx(eopatch.data["blob_dog"]) BLOB_TESTS = [ - [DoGBlobTask(FEATURE, threshold=0), 0.0, 37.9625, 0.0854, 0.0], + (DoGBlobTask(FEATURE, threshold=0), {"exp_min": 0.0, "exp_max": 37.9625, "exp_mean": 0.08545, "exp_median": 0.0}), ] if sys.version_info >= (3, 8): # For Python 3.7 scikit-image returns less accurate result for this test - BLOB_TESTS.append([DoHBlobTask(FEATURE, num_sigma=5, threshold=0), 0.0, 21.9203, 0.05807, 0.0]) - BLOB_TESTS.append([LoGBlobTask(FEATURE, log_scale=True, threshold=0), 0, 42.4264, 0.0977, 0.0]) - - -@pytest.mark.parametrize("task, expected_min, expected_max, expected_mean, expected_median", BLOB_TESTS) -def test_blob(small_ndvi_eopatch, task, expected_min, expected_max, expected_mean, expected_median): + BLOB_TESTS.extend( + [ + ( + DoHBlobTask(FEATURE, num_sigma=5, threshold=0), + {"exp_min": 0.0, "exp_max": 21.9203, "exp_mean": 0.05807, "exp_median": 0.0}, + ), + ( + LoGBlobTask(FEATURE, log_scale=True, threshold=0), + {"exp_min": 0, "exp_max": 42.4264, "exp_mean": 0.09767, "exp_median": 0.0}, + ), + ] + ) + + +@pytest.mark.parametrize("task, expected_statistics", BLOB_TESTS) +def test_blob_task(small_ndvi_eopatch, task, expected_statistics): eopatch = copy.deepcopy(small_ndvi_eopatch) task.execute(eopatch) - # Test that no other features were modified - for feature, value in small_ndvi_eopatch.data.items(): - if isinstance(value, FeatureIO): - value = value.load() - assert_array_equal(value, eopatch.data[feature], err_msg=f"EOPatch data feature '{feature}' has changed") - - delta = 1e-4 + test_numpy_data(eopatch[BLOB_FEATURE], exp_shape=(10, 20, 20, 1), **expected_statistics, delta=1e-4) - blob = eopatch.data[FEATURE[-1]] - assert np.min(blob) == approx(expected_min, abs=delta) - assert np.max(blob) == approx(expected_max, abs=delta) - assert np.mean(blob) == approx(expected_mean, abs=delta) - assert np.median(blob) == approx(expected_median, abs=delta) + del eopatch[BLOB_FEATURE] + assert small_ndvi_eopatch == eopatch, "Other features of the EOPatch were affected." diff --git a/features/eolearn/tests/test_haralick.py b/features/eolearn/tests/test_haralick.py index b03cdfce7..de1515ed7 100644 --- a/features/eolearn/tests/test_haralick.py +++ b/features/eolearn/tests/test_haralick.py @@ -10,56 +10,38 @@ import numpy as np import pytest -from numpy.testing import assert_array_equal -from pytest import approx + +from sentinelhub.testing_utils import test_numpy_data from eolearn.core import FeatureType -from eolearn.core.eodata_io import FeatureIO from eolearn.features import HaralickTask FEATURE = (FeatureType.DATA, "NDVI", "haralick") +OUTPUT_FEATURE = (FeatureType.DATA, "haralick") @pytest.mark.parametrize( - "task, expected_min, expected_max, expected_mean, expected_median", + "task, expected_statistics", ( [ HaralickTask(FEATURE, texture_feature="contrast", angle=0, levels=255, window_size=3), - 3.5, - 9079.0, - 965.8295, - 628.5833, + {"exp_min": 3.5, "exp_max": 9079.0, "exp_mean": 965.8295, "exp_median": 628.5833}, ], [ HaralickTask(FEATURE, texture_feature="sum_of_square_variance", angle=np.pi / 2, levels=8, window_size=5), - 0.96899, - 48.7815, - 23.0229, - 23.8987, + {"exp_min": 0.96899, "exp_max": 48.7815, "exp_mean": 23.0229, "exp_median": 23.8987}, ], [ HaralickTask(FEATURE, texture_feature="sum_entropy", angle=-np.pi / 2, levels=8, window_size=7), - 0, - 1.7463, - 0.5657, - 0.5055, + {"exp_min": 0, "exp_max": 1.7463, "exp_mean": 0.5657, "exp_median": 0.50558}, ], ), ) -def test_haralick(small_ndvi_eopatch, task, expected_min, expected_max, expected_mean, expected_median): +def test_haralick(small_ndvi_eopatch, task, expected_statistics): eopatch = copy.deepcopy(small_ndvi_eopatch) task.execute(eopatch) - # Test that no other features were modified - for feature, value in small_ndvi_eopatch.data.items(): - if isinstance(value, FeatureIO): - value = value.load() - assert_array_equal(value, eopatch.data[feature], err_msg=f"EOPatch data feature '{feature}' has changed") - - delta = 1e-4 + test_numpy_data(eopatch[OUTPUT_FEATURE], exp_shape=(10, 20, 20, 1), **expected_statistics, delta=1e-4) - haralick = eopatch.data["haralick"] - assert np.min(haralick) == approx(expected_min, abs=delta) - assert np.max(haralick) == approx(expected_max, abs=delta) - assert np.mean(haralick) == approx(expected_mean, abs=delta) - assert np.median(haralick) == approx(expected_median, abs=delta) + del eopatch[OUTPUT_FEATURE] + assert small_ndvi_eopatch == eopatch, "Other features of the EOPatch were affected." diff --git a/features/eolearn/tests/test_hog.py b/features/eolearn/tests/test_hog.py index 7b80fe36c..2f215b9f6 100644 --- a/features/eolearn/tests/test_hog.py +++ b/features/eolearn/tests/test_hog.py @@ -8,12 +8,9 @@ """ import copy -import numpy as np -from numpy.testing import assert_array_equal -from pytest import approx +from sentinelhub.testing_utils import test_numpy_data from eolearn.core import FeatureType -from eolearn.core.eodata_io import FeatureIO from eolearn.features import HOGTask @@ -30,19 +27,12 @@ def test_hog(small_ndvi_eopatch): eopatch = copy.deepcopy(small_ndvi_eopatch) task.execute(eopatch) - # Test that no other features were modified - for feature, value in small_ndvi_eopatch.data.items(): - if isinstance(value, FeatureIO): - value = value.load() - assert_array_equal(value, eopatch.data[feature], err_msg=f"EOPatch data feature '{feature}' has changed") - - delta = 1e-4 - for feature, expected_min, expected_max, expected_mean, expected_median in [ - ("hog", 0.0, 0.5567, 0.0931, 0.0), - ("hog_visu", 0.0, 0.3241, 0.0105, 0.0), + for feature_name, expected_statistics in [ + ("hog", {"exp_min": 0.0, "exp_max": 0.5567, "exp_mean": 0.09309, "exp_median": 0.0}), + ("hog_visu", {"exp_min": 0.0, "exp_max": 0.3241, "exp_mean": 0.010537, "exp_median": 0.0}), ]: - hog = eopatch.data[feature] - assert np.min(hog) == approx(expected_min, abs=delta) - assert np.max(hog) == approx(expected_max, abs=delta) - assert np.mean(hog) == approx(expected_mean, abs=delta) - assert np.median(hog) == approx(expected_median, abs=delta) + test_numpy_data(eopatch.data[feature_name], **expected_statistics, delta=1e-4) + + del eopatch[(FeatureType.DATA, "hog")] + del eopatch[(FeatureType.DATA, "hog_visu")] + assert small_ndvi_eopatch == eopatch, "Other features of the EOPatch were affected." diff --git a/features/eolearn/tests/test_interpolation.py b/features/eolearn/tests/test_interpolation.py index f33ad509e..17f032803 100644 --- a/features/eolearn/tests/test_interpolation.py +++ b/features/eolearn/tests/test_interpolation.py @@ -11,11 +11,12 @@ """ import dataclasses from datetime import datetime -from typing import Optional +from typing import Dict, Optional import numpy as np import pytest -from pytest import approx + +from sentinelhub.testing_utils import test_numpy_data from eolearn.core import EOPatch, EOTask, FeatureType from eolearn.features import ( @@ -53,10 +54,7 @@ class InterpolationTestCase: name: str task: EOTask result_len: int - img_min: float - img_max: float - img_mean: float - img_median: float + expected_statistics: Dict[str, float] nan_replace: Optional[float] = None def execute(self, eopatch): @@ -82,10 +80,7 @@ def execute(self, eopatch): unknown_value=10, ), result_len=68, - img_min=0.0, - img_max=0.82836, - img_mean=0.51187, - img_median=0.57889, + expected_statistics=dict(exp_min=0.0, exp_max=0.82836, exp_mean=0.51187, exp_median=0.57889), ), InterpolationTestCase( "linear-p", @@ -97,10 +92,7 @@ def execute(self, eopatch): interpolate_pixel_wise=True, ), result_len=68, - img_min=0.0, - img_max=0.82836, - img_mean=0.51187, - img_median=0.57889, + expected_statistics=dict(exp_min=0.0, exp_max=0.82836, exp_mean=0.51187, exp_median=0.57889), ), InterpolationTestCase( "linear_change_timescale", @@ -112,10 +104,7 @@ def execute(self, eopatch): scale_time=1, ), result_len=68, - img_min=0.0, - img_max=0.82836, - img_mean=0.51187, - img_median=0.57889, + expected_statistics=dict(exp_min=0.0, exp_max=0.82836, exp_mean=0.51187, exp_median=0.57889), ), InterpolationTestCase( "cubic", @@ -128,10 +117,7 @@ def execute(self, eopatch): bounds_error=False, ), result_len=69, - img_min=0.0, - img_max=5.0, - img_mean=1.3532, - img_median=0.638732, + expected_statistics=dict(exp_min=0.0, exp_max=5.0, exp_mean=1.3532, exp_median=0.638732), ), InterpolationTestCase( "spline", @@ -145,10 +131,7 @@ def execute(self, eopatch): unknown_value=0, ), result_len=147, - img_min=-0.17814, - img_max=1.0, - img_mean=0.49738, - img_median=0.556853, + expected_statistics=dict(exp_min=-0.1781458, exp_max=1.0, exp_mean=0.49738, exp_median=0.556853), ), InterpolationTestCase( "bspline", @@ -160,10 +143,7 @@ def execute(self, eopatch): spline_degree=5, ), result_len=1, - img_min=-0.0163, - img_max=0.62323, - img_mean=0.319117, - img_median=0.32588, + expected_statistics=dict(exp_min=-0.0162962, exp_max=0.62323, exp_mean=0.319117, exp_median=0.3258836), ), InterpolationTestCase( "bspline-p", @@ -176,10 +156,7 @@ def execute(self, eopatch): interpolate_pixel_wise=True, ), result_len=1, - img_min=-0.0163, - img_max=0.62323, - img_mean=0.319117, - img_median=0.32588, + expected_statistics=dict(exp_min=-0.0162962, exp_max=0.62323, exp_mean=0.319117, exp_median=0.3258836), ), InterpolationTestCase( "akima", @@ -187,10 +164,7 @@ def execute(self, eopatch): (FeatureType.DATA, "NDVI"), unknown_value=0, mask_feature=(FeatureType.MASK, "IS_VALID") ), result_len=68, - img_min=-0.091035, - img_max=0.8283603, - img_mean=0.51427454, - img_median=0.59095883, + expected_statistics=dict(exp_min=-0.091035, exp_max=0.8283603, exp_mean=0.51427454, exp_median=0.59095883), ), InterpolationTestCase( "kriging interpolation", @@ -198,10 +172,7 @@ def execute(self, eopatch): (FeatureType.DATA, "NDVI"), result_interval=(-10, 10), resample_range=("2017-01-01", "2018-01-01", 10) ), result_len=37, - img_min=-0.18389, - img_max=0.5995388, - img_mean=0.35485545, - img_median=0.37279952, + expected_statistics=dict(exp_min=-0.183885, exp_max=0.5995388, exp_mean=0.35485545, exp_median=0.37279952), ), InterpolationTestCase( "nearest resample", @@ -209,10 +180,7 @@ def execute(self, eopatch): (FeatureType.DATA, "NDVI"), result_interval=(0.0, 1.0), resample_range=("2016-01-01", "2018-01-01", 5) ), result_len=147, - img_min=-0.2, - img_max=0.8283603, - img_mean=0.32318678, - img_median=0.2794411, + expected_statistics=dict(exp_min=-0.2, exp_max=0.8283603, exp_mean=0.32318678, exp_median=0.2794411), nan_replace=-0.2, ), InterpolationTestCase( @@ -221,10 +189,7 @@ def execute(self, eopatch): (FeatureType.DATA, "NDVI"), result_interval=(0.0, 1.0), resample_range=("2016-01-01", "2018-01-01", 5) ), result_len=147, - img_min=-0.2, - img_max=0.82643485, - img_mean=0.32218185, - img_median=0.29093677, + expected_statistics=dict(exp_min=-0.2, exp_max=0.82643485, exp_mean=0.32218185, exp_median=0.29093677), nan_replace=-0.2, ), InterpolationTestCase( @@ -236,10 +201,7 @@ def execute(self, eopatch): unknown_value=5, ), result_len=69, - img_min=-0.2, - img_max=5.0, - img_mean=1.209852, - img_median=0.40995836, + expected_statistics=dict(exp_min=-0.2, exp_max=5.0, exp_mean=1.209852, exp_median=0.40995836), nan_replace=-0.2, ), InterpolationTestCase( @@ -252,10 +214,7 @@ def execute(self, eopatch): resample_range=("2015-09-01", "2016-01-01", "2016-07-01", "2017-01-01", "2017-07-01"), ), result_len=5, - img_min=-0.0252167, - img_max=0.816656, - img_mean=0.49966, - img_median=0.533415, + expected_statistics=dict(exp_min=-0.0252167, exp_max=0.816656, exp_mean=0.49966, exp_median=0.533415), ), InterpolationTestCase( "linear with bands and multiple masks", @@ -270,10 +229,7 @@ def execute(self, eopatch): ], ), result_len=68, - img_min=0.0003, - img_max=10.0, - img_mean=0.132176, - img_median=0.086, + expected_statistics=dict(exp_min=0.0003, exp_max=10.0, exp_mean=0.132176, exp_median=0.086), ), ] @@ -295,10 +251,7 @@ def execute(self, eopatch): ], ), result_len=69, - img_min=0.0, - img_max=5.0, - img_mean=1.3592644, - img_median=0.6174331, + expected_statistics=dict(exp_min=0.0, exp_max=5.0, exp_mean=1.3592644, exp_median=0.6174331), ), InterpolationTestCase( "cubic_copy_fail", @@ -316,17 +269,15 @@ def execute(self, eopatch): ], ), result_len=69, - img_min=0.0, - img_max=5.0, - img_mean=1.3592644, - img_median=0.6174331, + expected_statistics=dict(exp_min=0.0, exp_max=5.0, exp_mean=1.3592644, exp_median=0.6174331), ), ] @pytest.mark.parametrize("test_case", INTERPOLATION_TEST_CASES) -def test_interpolation(test_case, test_patch): +def test_interpolation(test_case: InterpolationTestCase, test_patch): eopatch = test_case.execute(test_patch) + delta = 1e-4 if isinstance(test_case.task, KrigingInterpolationTask) else 1e-5 # Check types and shapes assert isinstance(eopatch.timestamp, list), "Expected a list of timestamps" @@ -335,14 +286,9 @@ def test_interpolation(test_case, test_patch): assert eopatch.data["NDVI"].shape == (test_case.result_len, 20, 20, 1) # Check results - delta = 1e-5 # Can't be higher accuracy because of Kriging interpolation feature_type, feature_name, _ = test_case.task.renamed_feature data = eopatch[feature_type, feature_name] - - assert np.min(data) == approx(test_case.img_min, abs=delta) - assert np.max(data) == approx(test_case.img_max, abs=delta) - assert np.mean(data) == approx(test_case.img_mean, abs=delta) - assert np.median(data) == approx(test_case.img_median, abs=delta) + test_numpy_data(data, **test_case.expected_statistics, delta=delta) @pytest.mark.parametrize("test_case", COPY_FEATURE_CASES) @@ -359,4 +305,4 @@ def test_copied_fields(test_case, test_patch): (FeatureType.MASK_TIMELESS, "LULC"), ] for feature in copied_features: - assert feature in eopatch.get_feature_list(), f"Expected feature `{feature}` is not present in EOPatch" + assert feature in eopatch, f"Expected feature `{feature}` is not present in EOPatch" diff --git a/features/eolearn/tests/test_local_binary_pattern.py b/features/eolearn/tests/test_local_binary_pattern.py index a8b587893..4915d8ee2 100644 --- a/features/eolearn/tests/test_local_binary_pattern.py +++ b/features/eolearn/tests/test_local_binary_pattern.py @@ -9,34 +9,31 @@ import copy -import numpy as np import pytest -from numpy.testing import assert_array_equal -from pytest import approx + +from sentinelhub.testing_utils import test_numpy_data from eolearn.core import FeatureType -from eolearn.core.eodata_io import FeatureIO from eolearn.features import LocalBinaryPatternTask +LBP_FEATURE = (FeatureType.DATA, "NDVI", "lbp") +OUTPUT_FEATURE = (FeatureType.DATA, "lbp") + @pytest.mark.parametrize( - "task, expected_min, expected_max, expected_mean, expected_median", - ([LocalBinaryPatternTask((FeatureType.DATA, "NDVI", "lbp"), nb_points=24, radius=3), 0.0, 25.0, 15.8313, 21.0],), + "task, expected_statistics", + ( + [ + LocalBinaryPatternTask(LBP_FEATURE, nb_points=24, radius=3), + {"exp_min": 0.0, "exp_max": 25.0, "exp_mean": 15.8313, "exp_median": 21.0}, + ], + ), ) -def test_local_binary_pattern(small_ndvi_eopatch, task, expected_min, expected_max, expected_mean, expected_median): +def test_local_binary_pattern(small_ndvi_eopatch, task, expected_statistics): eopatch = copy.deepcopy(small_ndvi_eopatch) task.execute(eopatch) - # Test that no other features were modified - for feature, value in small_ndvi_eopatch.data.items(): - if isinstance(value, FeatureIO): - value = value.load() - assert_array_equal(value, eopatch.data[feature], err_msg=f"EOPatch data feature '{feature}' has changed") - - delta = 1e-4 + test_numpy_data(eopatch[OUTPUT_FEATURE], exp_shape=(10, 20, 20, 1), **expected_statistics, delta=1e-4) - haralick = eopatch.data["lbp"] - assert np.min(haralick) == approx(expected_min, abs=delta) - assert np.max(haralick) == approx(expected_max, abs=delta) - assert np.mean(haralick) == approx(expected_mean, abs=delta) - assert np.median(haralick) == approx(expected_median, abs=delta) + del eopatch[OUTPUT_FEATURE] + assert small_ndvi_eopatch == eopatch, "Other features of the EOPatch were affected." diff --git a/features/eolearn/tests/test_radiometric_normalization.py b/features/eolearn/tests/test_radiometric_normalization.py index 00047b24b..af2ebbf52 100644 --- a/features/eolearn/tests/test_radiometric_normalization.py +++ b/features/eolearn/tests/test_radiometric_normalization.py @@ -11,11 +11,10 @@ import numpy as np import pytest -from numpy.testing import assert_array_equal -from pytest import approx + +from sentinelhub.testing_utils import test_numpy_data from eolearn.core import FeatureType -from eolearn.core.eodata_io import FeatureIO from eolearn.features import ( BlueCompositingTask, HistogramMatchingTask, @@ -47,7 +46,7 @@ def eopatch_fixture(example_eopatch): @pytest.mark.parametrize( - "task, test_feature, expected_min, expected_max, expected_mean, expected_median", + "task, test_feature, expected_statistics", ( [ MaskFeatureTask( @@ -56,20 +55,14 @@ def eopatch_fixture(example_eopatch): mask_values=[0, 1, 2, 3, 8, 9, 10, 11], ), DATA_TEST_FEATURE, - 0.0002, - 1.4244, - 0.21167801, - 0.142, + {"exp_min": 0.0002, "exp_max": 1.4244, "exp_mean": 0.21167801, "exp_median": 0.1422}, ], [ ReferenceScenesTask( (FeatureType.DATA, "BANDS-S2-L1C", "TEST"), (FeatureType.SCALAR, "CLOUD_COVERAGE"), max_scene_number=5 ), DATA_TEST_FEATURE, - 0.0005, - 0.5318, - 0.16823094, - 0.1404, + {"exp_min": 0.0005, "exp_max": 0.5318, "exp_mean": 0.16823094, "exp_median": 0.1404}, ], [ BlueCompositingTask( @@ -79,10 +72,7 @@ def eopatch_fixture(example_eopatch): interpolation="geoville", ), DATA_TIMELESS_TEST_FEATURE, - 0.0005, - 0.5075, - 0.11658352, - 0.0833, + {"exp_min": 0.0005, "exp_max": 0.5075, "exp_mean": 0.11658352, "exp_median": 0.0833}, ], [ HOTCompositingTask( @@ -93,10 +83,7 @@ def eopatch_fixture(example_eopatch): interpolation="geoville", ), DATA_TIMELESS_TEST_FEATURE, - 0.0005, - 0.5075, - 0.117758796, - 0.0846, + {"exp_min": 0.0005, "exp_max": 0.5075, "exp_mean": 0.117758796, "exp_median": 0.0846}, ], [ MaxNDVICompositingTask( @@ -107,10 +94,7 @@ def eopatch_fixture(example_eopatch): interpolation="geoville", ), DATA_TIMELESS_TEST_FEATURE, - 0.0005, - 0.5075, - 0.13430128, - 0.0941, + {"exp_min": 0.0005, "exp_max": 0.5075, "exp_mean": 0.13430128, "exp_median": 0.0941}, ], [ MaxNDWICompositingTask( @@ -121,10 +105,7 @@ def eopatch_fixture(example_eopatch): interpolation="geoville", ), DATA_TIMELESS_TEST_FEATURE, - 0.0005, - 0.5318, - 0.2580135, - 0.2888, + {"exp_min": 0.0005, "exp_max": 0.5318, "exp_mean": 0.2580135, "exp_median": 0.2888}, ], [ MaxRatioCompositingTask( @@ -136,39 +117,25 @@ def eopatch_fixture(example_eopatch): interpolation="geoville", ), DATA_TIMELESS_TEST_FEATURE, - 0.0006, - 0.5075, - 0.13513365, - 0.0958, + {"exp_min": 0.0006, "exp_max": 0.5075, "exp_mean": 0.13513365, "exp_median": 0.0958}, ], [ HistogramMatchingTask( (FeatureType.DATA, "BANDS-S2-L1C", "TEST"), (FeatureType.DATA_TIMELESS, "REFERENCE_COMPOSITE") ), DATA_TEST_FEATURE, - -0.049050678, - 0.68174845, - 0.1165936, - 0.08370649, + {"exp_min": -0.049050678, "exp_max": 0.68174845, "exp_mean": 0.1165936, "exp_median": 0.08370649}, ], ), ) -def test_haralick(eopatch, task, test_feature, expected_min, expected_max, expected_mean, expected_median): +def test_radiometric_normalization(eopatch, task, test_feature, expected_statistics): initial_patch = copy.deepcopy(eopatch) eopatch = task.execute(eopatch) - # Test that no other features were modified - for feature, value in initial_patch.data.items(): - if isinstance(value, FeatureIO): - value = value.load() - assert_array_equal(value, eopatch.data[feature], err_msg=f"EOPatch data feature '{feature}' has changed") - assert isinstance(eopatch.timestamp, list), "Expected a list of timestamps" assert isinstance(eopatch.timestamp[0], datetime), "Expected timestamps of type datetime.datetime" - delta = 1e-3 - result = eopatch[test_feature] - assert np.nanmin(result) == approx(expected_min, abs=delta) - assert np.nanmax(result) == approx(expected_max, abs=delta) - assert np.nanmean(result) == approx(expected_mean, abs=delta) - assert np.nanmedian(result) == approx(expected_median, abs=delta) + test_numpy_data(eopatch[test_feature], **expected_statistics, delta=1e-3) + + del eopatch[test_feature] + assert initial_patch == eopatch, "Other features of the EOPatch were affected."