|
8 | 8 | import pystac |
9 | 9 | import pytest |
10 | 10 |
|
| 11 | +from openeo.api.process import Parameter |
11 | 12 | from openeo.metadata import ( |
12 | 13 | _PYSTAC_1_9_EXTENSION_INTERFACE, |
13 | 14 | Band, |
@@ -1279,6 +1280,35 @@ def test_metadata_resample_spatial(cube_metadata, kwargs, expected_x, expected_y |
1279 | 1280 | assert metadata.band_dimension == cube_metadata.band_dimension |
1280 | 1281 |
|
1281 | 1282 |
|
| 1283 | +@pytest.mark.parametrize("cube_metadata", [CUBE_METADATA_XYTB, CUBE_METADATA_TBXY]) |
| 1284 | +def test_metadata_resample_spatial_parameter_resolution_only(cube_metadata): |
| 1285 | + """When resolution is a Parameter, step should remain unchanged and crs should stay as-is.""" |
| 1286 | + param = Parameter.number("res", description="The spatial resolution.") |
| 1287 | + metadata = cube_metadata.resample_spatial(resolution=param) |
| 1288 | + assert isinstance(metadata, CubeMetadata) |
| 1289 | + # step must not change because the resolution is unknown at build time |
| 1290 | + assert metadata.spatial_dimensions == [ |
| 1291 | + SpatialDimension(name="x", extent=[2, 7], crs=4326, step=0.1), |
| 1292 | + SpatialDimension(name="y", extent=[49, 52], crs=4326, step=0.1), |
| 1293 | + ] |
| 1294 | + assert metadata.temporal_dimension == cube_metadata.temporal_dimension |
| 1295 | + assert metadata.band_dimension == cube_metadata.band_dimension |
| 1296 | + |
| 1297 | + |
| 1298 | +@pytest.mark.parametrize("cube_metadata", [CUBE_METADATA_XYTB, CUBE_METADATA_TBXY]) |
| 1299 | +def test_metadata_resample_spatial_parameter_resolution_with_projection(cube_metadata): |
| 1300 | + """When resolution is a Parameter but projection is concrete, crs should be updated.""" |
| 1301 | + param = Parameter.number("res", description="The spatial resolution.") |
| 1302 | + metadata = cube_metadata.resample_spatial(resolution=param, projection=32631) |
| 1303 | + assert isinstance(metadata, CubeMetadata) |
| 1304 | + assert metadata.spatial_dimensions == [ |
| 1305 | + SpatialDimension(name="x", extent=[2, 7], crs=32631, step=0.1), |
| 1306 | + SpatialDimension(name="y", extent=[49, 52], crs=32631, step=0.1), |
| 1307 | + ] |
| 1308 | + assert metadata.temporal_dimension == cube_metadata.temporal_dimension |
| 1309 | + assert metadata.band_dimension == cube_metadata.band_dimension |
| 1310 | + |
| 1311 | + |
1282 | 1312 | @pytest.mark.parametrize("cube_metadata", [CUBE_METADATA_XYTB, CUBE_METADATA_TBXY]) |
1283 | 1313 | def test_metadata_resample_cube_spatial(cube_metadata): |
1284 | 1314 | metadata1 = cube_metadata.resample_spatial(resolution=(11, 22), projection=32631) |
|
0 commit comments