Support TIFF predictor=3 on the CPU write path (#1313)#1314
Merged
brendancol merged 1 commit intomainfrom Apr 29, 2026
Merged
Conversation
to_geotiff and the streaming writer now accept predictor as bool or int. False/0/1 means none, True/2 keeps horizontal differencing, and 3 selects the floating-point predictor. The encoder (fp_predictor_encode) already existed in _compression.py but was not reachable from the writer. Predictor 3 is rejected for non-float dtypes. Predictor=True still emits TIFF predictor 2, so existing callers are unaffected.
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.
Summary
to_geotiff,write_geotiff_gpu, the VRT writer, and the dask streaming writer now acceptpredictorasboolorint. Passing3selects the floating-point predictor (TIFF Technical Note 3), which typically gives better deflate/zstd ratios on float rasters than horizontal differencing.fp_predictor_encode(already in_compression.py) into_writer.py's strip, tile, streaming, and_compress_blockpaths. Adds anormalize_predictorhelper that rejects predictor=3 on integer dtypes and preserves the legacy bool semantics:False/Truestill mean "no predictor" / "horizontal differencing"._fp_predictor_encode_kernelwaiting to be reached.Closes #1313.
Test plan
xrspatial/geotiff/tests/test_predictor_fp_write_1313.py: round-trip float32 and float64 under deflate and zstd (tiled and stripped), multi-band float32, dask streaming, integer-dtype rejection, legacypredictor=True/Falseunchanged,compression='none'suppresses the predictor, and a smooth-float file with predictor=3 is smaller than the same file with predictor=2.xrspatial/geotiff/tests/suite: 469 passed, 4 skipped, no regressions. (Three pre-existing matplotlibTestPalettefailures exist onmainand were deselected.)_read_predictor_tagtest helper reads the TIFF Predictor tag (id 317) directly from each written file to verify the on-disk tag matches what was requested.