Repository navigation
Conversation
Compare large (GeoTIFF/netCDF) job result rasters block by block, reading files lazily, to bound memory usage and avoid out-of-memory failures, as encountered in the APEx benchmarks (#871). - Load netCDF lazily (`xarray.open_dataset`) and close opened files after comparison (re-open per variable to release HDF5 chunk caches). - Iterate over blocks of at most `_COMPARE_BLOCK_SIZE` elements, splitting non-spatial dimensions (time, bands) first, then y. - Accumulate per (x, y) slice difference statistics (counts, min/max, mean/var, bbox, coarsened ascii art) incrementally. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #871
Problem
assert_job_results_allcloseloads both rasters fully into memory and builds several full-size float64 intermediates (threshold, diff, masks, ...). In the APEx benchmarks (openeo-apex-benchmarks-cdse#217) this caused:ramona_benin:MemoryError: Unable to allocate 17.3 GiB for an array with shape (1, 68355, 33904)in_compare_xarray_dataarraysentinel1_sar_slc_preprocessing: process killed by the OOM killer (exit 137)Approach
No new dependencies (e.g. dask/cubed): compare block by block with plain xarray/numpy, accumulating statistics incrementally.
_iter_blocks: yields aligned blocks of at most_COMPARE_BLOCK_SIZE(2**20) elements, each loaded once. Non-spatial dims (time, bands) are split first, theny,xis never split. Splitting onyonly was ~4x slower on netCDF files that are chunked per band/time (as written by the openEO back-end), because of partial HDF5 chunk reads._compare_xarray_dataarray: nodata mismatch counts, bad pixel counts and thexarray.testing.assert_allclosecheck are done per block._compare_xarray_dataarray_xy: per (x, y) slice statistics are accumulated in_XYDiffStats(counts, min/max, mean/variance via Chan's parallel algorithm, diff bbox and a coarsened grid for the ascii art).xarray.open_datasetinstead ofload_dataset). Opened files are closed after comparison (_opened_xarraycontext manager) and re-opened per variable, to release the HDF5 chunk cache (otherwise RSS grew ~134 MB per variable).Output for small arrays (single block) is unchanged. I verified this with a snapshot of all comparison messages for a set of mismatch scenarios, identical for block sizes 1, 7, 50, 100, 1000 and the default. With multiple blocks, the only difference is that the xarray "Left and right DataArray objects are not close" message shows the first differing block, rather than the full array.
Measurements
Limitations
xarray.testing.assert_allclose(existing behavior).Tests
New tests in
tests/testing/test_results.py: block-wise vs single-block equivalence (several block sizes, pixel tolerances, dimension orders), tracemalloc peak memory bounds for in-memory, GeoTIFF and netCDF inputs (including a check that the files get closed), and_iter_blockssplit order.This PR was drafted with the help of GitHub Copilot CLI (Claude).