-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add filter_temporal process (#76)
* partial fix of sggregate_temporal * Revert "partial fix of sggregate_temporal" This reverts commit bfd7a7e. * implemented filter_temporal * added filter_temporal test * added filter_temporal test * added filter_temporal test * fixed little things * removed unused import * merge main * add spec for filter_temporal * add test with open interval --------- Co-authored-by: Lukas Weidenholzer <[email protected]>
- Loading branch information
1 parent
f782ec8
commit e5b84d8
Showing
3 changed files
with
96 additions
and
8 deletions.
There are no files selected for viewing
49 changes: 42 additions & 7 deletions
49
openeo_processes_dask/process_implementations/cubes/_filter.py
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,53 @@ | ||
import numpy as np | ||
import pytest | ||
import xarray as xr | ||
from openeo_pg_parser_networkx.pg_schema import TemporalInterval | ||
|
||
from openeo_processes_dask.process_implementations.cubes._filter import filter_temporal | ||
from openeo_processes_dask.process_implementations.exceptions import ( | ||
DimensionNotAvailable, | ||
) | ||
from tests.general_checks import general_output_checks | ||
from tests.mockdata import create_fake_rastercube | ||
|
||
|
||
@pytest.mark.parametrize("size", [(30, 30, 30, 1)]) | ||
@pytest.mark.parametrize("dtype", [np.uint8]) | ||
def test_filter_temporal(temporal_interval, bounding_box, random_raster_data): | ||
input_cube = create_fake_rastercube( | ||
data=random_raster_data, | ||
spatial_extent=bounding_box, | ||
temporal_extent=temporal_interval, | ||
bands=["B02"], | ||
backend="dask", | ||
) | ||
|
||
temporal_interval_part = TemporalInterval.parse_obj( | ||
["2018-05-15T00:00:00", "2018-06-01T00:00:00"] | ||
) | ||
output_cube = filter_temporal(data=input_cube, extent=temporal_interval_part) | ||
|
||
general_output_checks( | ||
input_cube=input_cube, | ||
output_cube=output_cube, | ||
verify_attrs=False, | ||
verify_crs=True, | ||
) | ||
|
||
xr.testing.assert_equal( | ||
output_cube, | ||
input_cube.loc[dict(t=slice("2018-05-15T00:00:00", "2018-05-31T23:59:59"))], | ||
) | ||
|
||
with pytest.raises(DimensionNotAvailable): | ||
filter_temporal( | ||
data=input_cube, extent=temporal_interval_part, dimension="immissing" | ||
) | ||
|
||
temporal_interval_open = TemporalInterval.parse_obj([None, "2018-05-03T00:00:00"]) | ||
output_cube = filter_temporal(data=input_cube, extent=temporal_interval_open) | ||
|
||
xr.testing.assert_equal( | ||
output_cube, | ||
input_cube.loc[dict(t=slice("2018-05-01T00:00:00", "2018-05-02T23:59:59"))], | ||
) |