fix: Make write_cog refuse or apply every option it is given - #75
Merged
Merged
Conversation
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
commented
Oct 1, 2026
| "driver": "COG", | ||
| "interleave": interleave, | ||
| "compress": "DEFLATE", | ||
| "tiled": True, |
Member
Author
There was a problem hiding this comment.
is this automatic in the cog_profile?
Member
Author
There was a problem hiding this comment.
Note
This reply was written by Claude (Claude Code), not by @kylebarron.
Yes. The COG driver always tiles: it writes the file with TILED=YES and takes the tile size from BLOCKSIZE (cogdriver.cpp#L1204-L1208). TILED isn't one of its own creation options, so passing it only logged driver COG does not support creation option TILED.
The same lines set COPY_SRC_OVERVIEWS=YES, so dropping copy_src_overviews=True is a no-op too. Without either option, pixi run check still regenerates every fixture byte for byte.
🤖 Written by Claude Code
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.
Note
This PR was written by Claude (Claude Code), not by @kylebarron.
Follow-up to #74. Reviewing #74 turned up other ways
write_cogcan write a fixture without an option it was given. GDAL only logs a warning when it ignores a creation option, and the generators never show rasterio's log, so these failures are silent.Changes
ValueError. GDAL only writes a predictor for DEFLATE, LZW and ZSTD. JPEG, WEBP, LERC and PACKBITS drop it with a logged warning. LZMA drops it with no warning at all: GDAL's option check lists LZMA as taking a predictor (gtiffdataset_write.cpp), butGTIFFSupportsPredictor, which writes the tag, leaves it out. GDALmasteris the same.nodatais respected. With the defaultnodata_type="nodata", anodatayou passed was overwritten with 0. Now 0 is only the default.scaleandoffsetapply independently. Before, they were only applied when both were given.tiled=Trueandcopy_src_overviews=True. The COG driver doesn't support either, so they only logged a warning on every write.Not changed: raising on every GDAL warning
The #74 review suggested making
write_cograise whenever GDAL logsCPLE_NotSupported. That doesn't work cleanly. GDAL also logs'64' is an unexpected value for BLOCKSIZE creation option that should be >= 128for every fixture with 64×64 tiles, even though it writes those tiles. A blanket check would need exceptions keyed on message text.Instead,
test_no_ignored_creation_optionsasserts that a plainwrite_cogcall logs no warnings, which would have caught the two dead options. I also ran every generator with rasterio's log captured. With this change, the BLOCKSIZE warning is the only one left.Tests
tests/test_write_cog.pycallswrite_cogdirectly intotmp_pathand checks:ValueErrorfor JPEG, LERC, LZMA, PACKBITS and WEBPnodata,scaleandoffset9 of its 16 cases fail on
main. To let tests import the generators,pyproject.tomlgainspythonpath = ["."]. #73 adds the identical lines, so that part merges cleanly.No fixture changes:
pixi run checkregenerates every fixture byte for byte.pixi run testpasses.Merging with #73
#73 adds
rewrite_big_endiandirectly below thecopy(...)call this PR edits, so whichever lands second will likely get a one-line conflict.🤖 Written by Claude Code