Skip to content

Commit 6995960

Browse files
authored
Do not realign when changing resolution (#405)
* avoid extent realignment when changing resolution Open-EO/openeo-geopyspark-driver#1193 * avoid extent realignment when changing resolution Open-EO/openeo-geopyspark-driver#1193 * avoid extent realignment when changing resolution Open-EO/openeo-geopyspark-driver#1193
1 parent f8ba67d commit 6995960

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

openeo_driver/ProcessGraphDeserializer.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,16 +579,18 @@ def _align_extent(extent,collection_id,env,target_resolution=None):
579579

580580
x = metadata.get('cube:dimensions', {}).get('x', {})
581581
y = metadata.get('cube:dimensions', {}).get('y', {})
582-
if (target_resolution == None and collection_resolution != None ):
583-
target_resolution = collection_resolution
584-
elif target_resolution == None:
582+
583+
if (target_resolution == None and collection_resolution == None):
585584
return extent
586585

586+
587587
if ( crs == 4326
588588
and extent.get('crs','') == "EPSG:4326"
589589
and "extent" in x and "extent" in y
590+
and (target_resolution == None or target_resolution == collection_resolution)
590591
):
591-
592+
#only align to collection resolution
593+
target_resolution = collection_resolution
592594
def align(v, dimension, rounding, resolution):
593595
range = dimension.get('extent', [])
594596
if v < range[0]:

tests/test_dry_run.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,41 @@ def test_auto_align(dry_run_env, dry_run_tracer):
11481148
} == load_params.global_extent
11491149

11501150

1151+
def test_no_auto_align_when_resampling(dry_run_env, dry_run_tracer):
1152+
polygon = {"type": "Polygon", "coordinates": [[(0.1, 0.1), (3, 5), (8, 2), (0.1, 0.1)]]}
1153+
cube = DataCube(PGNode("load_collection", id="ESA_WORLDCOVER_10M_2020_V1"), connection=None)
1154+
cube = cube.filter_spatial(geometries=polygon)
1155+
cube = cube.resample_spatial(resolution = 0.001)
1156+
1157+
pg = cube.flat_graph()
1158+
res = evaluate(pg, env=dry_run_env)
1159+
1160+
source_constraints = dry_run_tracer.get_source_constraints(merge=True)
1161+
assert len(source_constraints) == 1
1162+
src, constraints = source_constraints[0]
1163+
assert src == ("load_collection", ("ESA_WORLDCOVER_10M_2020_V1", ()))
1164+
(geometries,) = dry_run_tracer.get_geometries(operation="filter_spatial")
1165+
assert constraints == {
1166+
'resample': {'method': 'near',
1167+
'resolution': (0.001, 0.001),
1168+
'target_crs': None},
1169+
"spatial_extent": {"crs": "EPSG:4326", "east": 8.0, "north": 5.0, "south": 0.1, "west": 0.1},
1170+
"filter_spatial": {"geometries": DummyVectorCube.from_geometry(shapely.geometry.shape(polygon))},
1171+
"weak_spatial_extent": {"west": 0.1, "south": 0.1, "east": 8.0, "north": 5.0, "crs": "EPSG:4326"},
1172+
}
1173+
assert isinstance(geometries, DummyVectorCube)
1174+
assert shapely.geometry.mapping(geometries.to_multipolygon()) == {
1175+
"type": "Polygon",
1176+
"coordinates": (((0.1, 0.1), (3.0, 5.0), (8.0, 2.0), (0.1, 0.1)),),
1177+
}
1178+
# source_constraints = dry_run_tracer.get_source_constraints()
1179+
dry_run_env = dry_run_env.push({ENV_SOURCE_CONSTRAINTS: source_constraints})
1180+
load_params = _extract_load_parameters(
1181+
dry_run_env, source_id=("load_collection", ("ESA_WORLDCOVER_10M_2020_V1", ()))
1182+
)
1183+
assert {'crs': 'EPSG:4326', 'east': 8.0, 'north': 5.0, 'south': 0.1, 'west': 0.1} == load_params.global_extent
1184+
1185+
11511186
def test_global_bounds_from_weak_spatial_extent(dry_run_env, dry_run_tracer):
11521187
# The global extent is the union from the spatial extent and the weak spatial extent.
11531188
bbox = {"west": 1, "south": 1, "east": 3, "north": 3, "crs": "EPSG:4326"}

0 commit comments

Comments
 (0)