Skip to content

Support TIFF predictor=3 on the CPU write path (#1313)#1314

Merged
brendancol merged 1 commit intomainfrom
issue-1313
Apr 29, 2026
Merged

Support TIFF predictor=3 on the CPU write path (#1313)#1314
brendancol merged 1 commit intomainfrom
issue-1313

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

  • to_geotiff, write_geotiff_gpu, the VRT writer, and the dask streaming writer now accept predictor as bool or int. Passing 3 selects the floating-point predictor (TIFF Technical Note 3), which typically gives better deflate/zstd ratios on float rasters than horizontal differencing.
  • Wires fp_predictor_encode (already in _compression.py) into _writer.py's strip, tile, streaming, and _compress_block paths. Adds a normalize_predictor helper that rejects predictor=3 on integer dtypes and preserves the legacy bool semantics: False/True still mean "no predictor" / "horizontal differencing".
  • Threads the int through to the GPU writer, which already had a _fp_predictor_encode_kernel waiting to be reached.

Closes #1313.

Test plan

  • New tests in 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, legacy predictor=True/False unchanged, compression='none' suppresses the predictor, and a smooth-float file with predictor=3 is smaller than the same file with predictor=2.
  • Full xrspatial/geotiff/tests/ suite: 469 passed, 4 skipped, no regressions. (Three pre-existing matplotlib TestPalette failures exist on main and were deselected.)
  • On a 512×512 smooth float32 raster, deflate output: predictor=3 590 KB vs predictor=2 787 KB (~25% smaller), confirming the encoder is wired correctly.
  • _read_predictor_tag test helper reads the TIFF Predictor tag (id 317) directly from each written file to verify the on-disk tag matches what was requested.

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.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label Apr 29, 2026
@brendancol brendancol merged commit 7cdb13a into main Apr 29, 2026
11 checks passed
@brendancol brendancol deleted the issue-1313 branch May 4, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

to_geotiff: support predictor=3 (floating-point predictor) on CPU write path

1 participant