Skip to content

Guard NBITS=16 against GDAL Float16 / rasterio incompatibility#690

Merged
mirzaees merged 2 commits intoisce-framework:mainfrom
scottstanie:fix-rasterio-gdal-float16
Mar 16, 2026
Merged

Guard NBITS=16 against GDAL Float16 / rasterio incompatibility#690
mirzaees merged 2 commits intoisce-framework:mainfrom
scottstanie:fix-rasterio-gdal-float16

Conversation

@scottstanie
Copy link
Copy Markdown
Member

GDAL 3.11+ interprets NBITS=16 on float32 GeoTIFFs as native Float16 (datatype code 15). Rasterio builds that lack a mapping for code 15 then raise KeyError: 15 on open.

Add _can_use_nbits16() that checks for this mismatch and gates all NBITS=16 usage behind it. On old GDAL the behavior is unchanged; on new GDAL the option is skipped until rasterio adds Float16 support.

Fixes issue raise in #687, specifically: #687 (comment)

Change Summary

Related issue number

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review

GDAL 3.11+ interprets NBITS=16 on float32 GeoTIFFs as native Float16
(datatype code 15). Rasterio builds that lack a mapping for code 15
then raise `KeyError: 15` on open.

Add `_can_use_nbits16()` that checks for this mismatch and gates all
NBITS=16 usage behind it. On old GDAL the behavior is unchanged; on
new GDAL the option is skipped until rasterio adds Float16 support.

Fixes isce-framework#687

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@scottstanie
Copy link
Copy Markdown
Member Author

Just confirming that my environment upgraded to rasterio 1.4.4, I got the same

...
  File "/Users/staniewi/repos/dolphin/src/dolphin/workflows/single.py", line 424, in run_wrapped_phase_single
    io.repack_rasters(phase_linked_crlb_files, use_16_bits=True)
    ...
  File "/Users/staniewi/miniforge3/envs/mapping-312/lib/python3.12/site-packages/rasterio/__init__.py", line 366, in open
    dataset = writer(
              ^^^^^^^
  File "rasterio/_io.pyx", line 1636, in rasterio._io.DatasetWriterBase.__init__
  File "rasterio/_base.pyx", line 967, in rasterio._base.DatasetBase.meta.__get__
  File "rasterio/_base.pyx", line 506, in rasterio._base.DatasetBase.dtypes.__get__
  File "rasterio/_base.pyx", line 176, in rasterio._base._band_dtype
KeyError: 15

but then tried this fix and it ran through

The original commit only guarded the write path
@mirzaees mirzaees self-requested a review March 16, 2026 15:30
@mirzaees mirzaees merged commit a497eb3 into isce-framework:main Mar 16, 2026
5 checks passed
@scottstanie scottstanie deleted the fix-rasterio-gdal-float16 branch March 16, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants