From bc236b5c9465e9d7af39b56be564bdb29670dd47 Mon Sep 17 00:00:00 2001 From: Ziga Luksic Date: Tue, 29 Aug 2023 13:27:59 +0200 Subject: [PATCH 1/3] add test --- tests/core/test_eodata_io.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/core/test_eodata_io.py b/tests/core/test_eodata_io.py index d00f40af..9b0cdaaa 100644 --- a/tests/core/test_eodata_io.py +++ b/tests/core/test_eodata_io.py @@ -242,6 +242,15 @@ def test_save_timestamps(eopatch, fs_loader, save_timestamps, features, should_s assert temp_fs.exists("/timestamps.json.gz") == should_save +def test_auto_save_load_timestamps(eopatch): + """Saving and loading with default values should process timestamps.""" + test_patch = EOPatch(bbox=eopatch.bbox, timestamps=eopatch.timestamps) # no temporal stuff + with TempFS() as temp_fs: + test_patch.save("/", filesystem=temp_fs) + assert temp_fs.exists("/timestamps.json.gz") + assert EOPatch.load("/", filesystem=temp_fs).timestamps is not None + + @mock_s3 @pytest.mark.parametrize("fs_loader", FS_LOADERS) @pytest.mark.parametrize( From 90b34a0b07af61b152efd3691a524fa78db366f8 Mon Sep 17 00:00:00 2001 From: Ziga Luksic Date: Tue, 29 Aug 2023 13:28:06 +0200 Subject: [PATCH 2/3] implement --- eolearn/core/eodata_io.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/eolearn/core/eodata_io.py b/eolearn/core/eodata_io.py index 6f8e95b9..bcc0408f 100644 --- a/eolearn/core/eodata_io.py +++ b/eolearn/core/eodata_io.py @@ -132,7 +132,9 @@ def save_eopatch( _check_collisions(overwrite_permission, eopatch_features, file_information) if save_timestamps == "auto": - save_timestamps = any(ftype.is_temporal() for ftype, _ in eopatch_features) and temporal_selection is None + save_timestamps = ( + features is ... or any(ftype.is_temporal() for ftype, _ in eopatch_features) + ) and temporal_selection is None # Data must be collected before any tinkering with files due to lazy-loading data_for_saving = list( @@ -306,7 +308,9 @@ def load_eopatch_content( if file_information.bbox is not None: bbox = FeatureIOBBox(file_information.bbox, filesystem).load() - auto_load = load_timestamps == "auto" and any(ftype.is_temporal() for ftype, _ in features_dict) + auto_load = load_timestamps == "auto" and ( + features is ... or any(ftype.is_temporal() for ftype, _ in features_dict) + ) timestamps = None if load_timestamps is True or auto_load: From eed247cea1cefecad71196f227fac44bb46a248b Mon Sep 17 00:00:00 2001 From: Ziga Luksic Date: Tue, 29 Aug 2023 13:28:11 +0200 Subject: [PATCH 3/3] fix docs --- eolearn/core/core_tasks.py | 8 ++++---- eolearn/core/eodata.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/eolearn/core/core_tasks.py b/eolearn/core/core_tasks.py index 7ab11e15..08da4aa9 100644 --- a/eolearn/core/core_tasks.py +++ b/eolearn/core/core_tasks.py @@ -118,8 +118,8 @@ def __init__( :param overwrite_permission: A level of permission for overwriting an existing EOPatch :param compress_level: A level of data compression and can be specified with an integer from 0 (no compression) to 9 (highest compression). - :save_timestamps: Whether to save the timestamps of the EOPatch. By default they are saved whenever temporal - features are being saved. + :save_timestamps: Whether to save the timestamps of the EOPatch. With the `"auto"` setting timestamps are saved + if `features=...` or if other temporal features are being saved. :param use_zarr: Saves numpy-array based features into Zarr files. Requires ZARR extra dependencies. :param temporal_selection: Writes all of the data to the chosen temporal indices of preexisting arrays. Can be used for saving data in multiple steps for memory optimization. When set to `"infer"` it will match the @@ -185,8 +185,8 @@ def __init__( default configuration will be taken. :param features: A collection of features to be loaded. By default, all features will be loaded. :param lazy_loading: If `True` features will be lazy loaded. - :load_timestamps: Whether to load the timestamps of the EOPatch. By default they are loaded whenever temporal - features are being loaded. + :load_timestamps: Whether to load the timestamps of the EOPatch. With the `"auto"` setting timestamps are loaded + if `features=...` or if other temporal features are being loaded. :param temporal_selection: Only loads data corresponding to the chosen indices. Can also be a callable that, given a list of timestamps, returns a list of booleans declaring which temporal slices to load. """ diff --git a/eolearn/core/eodata.py b/eolearn/core/eodata.py index 5b158e98..fb8819b7 100644 --- a/eolearn/core/eodata.py +++ b/eolearn/core/eodata.py @@ -621,8 +621,8 @@ def save( to 9 (highest compression). :param filesystem: An existing filesystem object. If not given it will be initialized according to the `path` parameter. - :save_timestamps: Whether to save the timestamps of the EOPatch. By default they are saved whenever temporal - features are being saved. + :save_timestamps: Whether to save the timestamps of the EOPatch. With the `"auto"` setting timestamps are saved + if `features=...` or if other temporal features are being saved. :param use_zarr: Saves numpy-array based features into Zarr files. Requires ZARR extra dependencies. :param temporal_selection: Writes all of the data to the chosen temporal indices of preexisting arrays. Can be used for saving data in multiple steps for memory optimization. When set to `"infer"` it will match the @@ -661,8 +661,8 @@ def load( :param lazy_loading: If `True` features will be lazy loaded. :param filesystem: An existing filesystem object. If not given it will be initialized according to the `path` parameter. - :load_timestamps: Whether to load the timestamps of the EOPatch. By default they are loaded whenever temporal - features are being loaded. + :load_timestamps: Whether to load the timestamps of the EOPatch. With the `"auto"` setting timestamps are loaded + if `features=...` or if other temporal features are being loaded. :param temporal_selection: Only loads data corresponding to the chosen indices. Can also be a callable that, given a list of timestamps, returns a list of booleans declaring which temporal slices to load. :return: Loaded EOPatch