fix: Write the predictor into COGs from write_cog - #74
Merged
kylebarron merged 1 commit intoOct 1, 2026
Merged
Conversation
write_cog set the predictor on the in-memory dataset only, not on the COG copy, so every fixture generated with a predictor actually used none. Pass it to the COG copy. This regenerates the four fixtures that ask for predictor 2. Their pixels are unchanged at every level; their info files now report PREDICTOR: 2. A test checks that they carry the predictor on every IFD.
james-willis
marked this pull request as ready for review
October 1, 2026 21:08
This was referenced Oct 1, 2026
kylebarron
added a commit
that referenced
this pull request
Oct 1, 2026
GDAL only logs a warning when it ignores a creation option, and the generators never show rasterio's log, so write_cog could silently write a fixture without an option it was asked for, as happened with the predictor in #74. - Raise a ValueError when a predictor is combined with a codec other than DEFLATE, LZW or ZSTD. GDAL drops it for the others; for LZMA it doesn't even warn, although its own check says LZMA takes a predictor. - Keep a `nodata` value passed with the default nodata_type instead of overwriting it with 0. - Apply `scale` and `offset` independently instead of only when both are given. - Drop `tiled` and `copy_src_overviews`, which the COG driver doesn't support, so they only produced warnings on every write. No fixture changes: every existing call either passes a supported codec, nodata=0, or both scale and offset. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
kylebarron
added a commit
that referenced
this pull request
Oct 1, 2026
Follow-up to #74, which made write_cog actually write the predictor: - uint16_1band_lzw_block128_predictor2: its arange data never carried from the low byte into the high byte within a tile row, so a reader that undoes predictor 2 byte by byte, or without wrapping, still read it correctly. Each row is now a triangle wave stepping by 1000 per pixel. The fixture is also 256x256 with the 128x128 tiles its name says, instead of 128x128 with 64x64 tiles. - uint16_1band_scale_offset: drop the predictor, which #74 turned on, so a reader without predictor support doesn't fail this fixture's scale/offset test. The file is back to its pre-#74 bytes. Also fix its docstrings, which said LZW and 512x512. - Add uint8_rgb_deflate_block64_predictor2: every predictor fixture was single band, so a reader that differences adjacent samples instead of adjacent pixels passed them all. - Add float32_1band_deflate_block64_predictor3: write_cog can write predictor 3 now, but no fixture had it. tests/test_predictor.py now checks every generated fixture: it carries a predictor exactly when its name says so, ignoring GDAL's mask IFDs, which never have one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kylebarron
added a commit
that referenced
this pull request
Oct 1, 2026
Follow-up to #74, which made write_cog actually write the predictor: - uint16_1band_lzw_block128_predictor2: its arange data never carried from the low byte into the high byte within a tile row, so a reader that undoes predictor 2 byte by byte, or without wrapping, still read it correctly. Each row is now a triangle wave stepping by 1000 per pixel. The fixture is also 256x256 with the 128x128 tiles its name says, instead of 128x128 with 64x64 tiles. - uint16_1band_scale_offset: drop the predictor, which #74 turned on, so a reader without predictor support doesn't fail this fixture's scale/offset test. The file is back to its pre-#74 bytes. Also fix its docstrings, which said LZW and 512x512. - Add uint8_rgb_deflate_block64_predictor2: every predictor fixture was single band, so a reader that differences adjacent samples instead of adjacent pixels passed them all. - Add float32_1band_deflate_block64_predictor3: write_cog can write predictor 3 now, but no fixture had it. tests/test_predictor.py now checks every generated fixture: it carries a predictor exactly when its name says so, ignoring GDAL's mask IFDs, which never have one. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.
write_cogsetpredictoron the in-memory GTiff dataset but not on the COG copy, so every fixture generated with a predictor actually used none:tifffilereportsPREDICTOR.NONEon every IFD of them. Found while making the big endian fixtures in #73.This passes the predictor to the COG copy instead (on the in-memory dataset it had no effect on the output) and regenerates the four fixtures that ask for predictor 2:
uint16_1band_lzw_block128_predictor2uint16_1band_scale_offsetuint8_1band_deflate_block128_unaligned_predictor2uint8_1band_lzw_block64_predictor2Their pixels are unchanged: every level of each regenerated file reads back identical to the committed version with rasterio. The only change in the
_info.mdfiles is a newPREDICTOR: 2line.Tests
tests/test_predictor.pychecks that those four fixtures carry predictor 2 on every IFD. It fails on main (4 failed) and passes here.pixi run checkandpixi run testpass.Downstream
deck.gl-raster's
integration-rasterio.test.tspasses (17/17) against the regenerated fixtures, both on deck.gl-raster main and with developmentseed/deck.gl-raster#687, so its predictor 2 decoding now gets real coverage and holds up.#73's
rewrite_big_endianpasses the predictor explicitly because of this bug. It's still correct after this merges; whichever lands second, I can simplify it to take the predictor from the source.