Add max_z_error parameter for lossy LERC compression#1513
Merged
brendancol merged 1 commit intoxarray-contrib:mainfrom May 7, 2026
Merged
Add max_z_error parameter for lossy LERC compression#1513brendancol merged 1 commit intoxarray-contrib:mainfrom
brendancol merged 1 commit intoxarray-contrib:mainfrom
Conversation
LERC takes a maxZErr argument: 0.0 is lossless, larger values let the encoder approximate within that bound. The codec wrapper already accepted it, but every writer above it hard-coded 0.0. to_geotiff now takes max_z_error and threads it through the eager write, the dask streaming write, the VRT path, the COG/overview path, and every helper that calls lerc_compress. Validation runs up front in to_geotiff: - max_z_error < 0 raises ValueError. - max_z_error != 0 with any codec other than 'lerc' raises ValueError. - max_z_error != 0 on the GPU writer raises ValueError (nvCOMP has no LERC backend). Closes xarray-contrib#1510.
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.
Closes #1510.
LERC takes a
maxZErrargument: 0.0 is lossless, larger values let the encoder approximate within that bound. The codec wrapper in_compression.pyalready accepted it, but every writer above it hard-coded 0.0, so there was no way to ask for a lossy LERC write from the public API.to_geotiffnow takesmax_z_error: float = 0.0and threads it through the eager write, the dask streaming write, the VRT path, the COG/overview path, and every helper that callslerc_compress.Validation runs up front in
to_geotiff:max_z_error < 0raisesValueError.max_z_error != 0with any codec other than'lerc'raisesValueError, so a non-zero budget never gets silently dropped.max_z_error != 0on the GPU writer raisesValueError. nvCOMP has no LERC backend.Tests in a new
test_lerc_max_z_error.pycover: bit-exact lossless round-trip at 0.0; 0.05 on a smooth float32 surface yields a strictly smaller file withabs(decoded - original) <= 0.05everywhere; dask streaming with a non-zero budget; negative values and non-LERC codecs raisingValueError; andmax_z_error=0.0with zstd still working (the default must not break other codecs).Test plan
pytest xrspatial/geotiff/tests/test_lerc_max_z_error.py -v(6 passed)pytest xrspatial/geotiff/tests/test_lerc.py -v(13 passed)pytest xrspatial/geotiff/tests/(673 passed, 4 skipped). Three matplotlibTestPaletterecursion errors reproduce onorigin/mainand are unrelated.