Skip to content

Commit fe1de96

Browse files
Refactor bounds calculation to ensure consistency with dataset coordinates
1 parent 411bbd7 commit fe1de96

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

src/eopf_geozarr/s2_optimization/s2_multiscale.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,21 @@ def add_multiscales_metadata_to_parent(
378378
log.info("No CRS found, skipping multiscales metadata", base_path=group.path)
379379
return None
380380

381-
native_bounds = None
382-
try:
383-
native_bounds = first_dataset.rio.bounds()
384-
except (AttributeError, TypeError):
385-
x_coords = first_dataset.x.values
386-
y_coords = first_dataset.y.values
387-
native_bounds = (x_coords.min(), y_coords.min(), x_coords.max(), y_coords.max())
381+
# Calculate bounds directly from coordinates for consistency with the data arrays
382+
if "x" not in first_dataset.coords or "y" not in first_dataset.coords:
383+
log.error(
384+
"Missing x/y coordinates in dataset, cannot determine bounds", base_path=group.path
385+
)
386+
return None
387+
388+
x_coords = first_dataset.x.values
389+
y_coords = first_dataset.y.values
390+
native_bounds = (
391+
float(x_coords.min()),
392+
float(y_coords.min()),
393+
float(x_coords.max()),
394+
float(y_coords.max()),
395+
)
388396

389397
# Create overview_levels structure following the multiscales v1.0 specification
390398
overview_levels: list[OverviewLevelJSON] = []

0 commit comments

Comments
 (0)