Skip to content

Commit bcba035

Browse files
committed
Sync compression docstrings against actual codec map (#1562)
_writer.write listed three codecs ('none', 'deflate', 'lzw') while _compression_tag accepts nine. to_geotiff listed six and omitted 'lz4', 'jpeg2000'/'j2k', and 'lerc'. Update both docstrings to match _VALID_COMPRESSIONS / _compression_tag. Also fill in the missing parameter docs on _writer.write that grew silently as features landed: compression_level, overview_resampling, crs_wkt, raster_type, x_resolution, y_resolution, resolution_unit, gdal_metadata_xml, extra_tags, bigtiff, max_z_error. Docs-only change.
1 parent deef216 commit bcba035

2 files changed

Lines changed: 42 additions & 5 deletions

File tree

xrspatial/geotiff/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -810,10 +810,14 @@ def to_geotiff(data: xr.DataArray | np.ndarray, path, *,
810810
nodata : float, int, or None
811811
NoData value.
812812
compression : str
813-
'none', 'deflate', 'lzw', 'jpeg', 'packbits', or 'zstd'.
814-
JPEG is lossy and only supports uint8 data (1 or 3 bands).
815-
With ``gpu=True``, JPEG uses nvJPEG for GPU-accelerated
816-
encode/decode when available, falling back to Pillow on CPU.
813+
Codec name. One of ``'none'``, ``'deflate'``, ``'lzw'``,
814+
``'jpeg'``, ``'packbits'``, ``'zstd'``, ``'lz4'``,
815+
``'jpeg2000'`` (alias ``'j2k'``), or ``'lerc'``.
816+
``'jpeg'`` is currently rejected on write because the encoder
817+
omits the JPEGTables tag and produced files do not round-trip
818+
through libtiff / GDAL / rasterio. Use ``'deflate'``, ``'zstd'``,
819+
or ``'lzw'`` instead. ``'lerc'`` accepts ``max_z_error`` for
820+
lossy compression with a bounded per-pixel error.
817821
compression_level : int or None
818822
Compression effort level. None uses each codec's default (6 for
819823
deflate/zstd). Valid ranges: deflate 1-9, zstd 1-22, lz4 0-16.

xrspatial/geotiff/_writer.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,10 +998,19 @@ def write(data: np.ndarray, path: str, *,
998998
Pixel-to-coordinate mapping.
999999
crs_epsg : int or None
10001000
EPSG code.
1001+
crs_wkt : str or None
1002+
WKT string. Used only when ``crs_epsg`` is None.
10011003
nodata : float, int, or None
10021004
NoData value.
10031005
compression : str
1004-
'none', 'deflate', or 'lzw'.
1006+
Codec name. One of ``'none'``, ``'deflate'``, ``'lzw'``,
1007+
``'jpeg'``, ``'packbits'``, ``'zstd'``, ``'lz4'``,
1008+
``'jpeg2000'`` (alias ``'j2k'``), or ``'lerc'``.
1009+
compression_level : int or None
1010+
Effort level forwarded to the codec. None uses each codec's
1011+
default. Valid ranges: deflate 1-9, zstd 1-22, lz4 0-16.
1012+
Codecs without a level concept (lzw, packbits, jpeg) accept any
1013+
value and ignore it.
10051014
tiled : bool
10061015
Use tiled layout (vs strips).
10071016
tile_size : int
@@ -1015,6 +1024,30 @@ def write(data: np.ndarray, path: str, *,
10151024
overview_levels : list of int or None
10161025
Overview decimation factors (e.g. [2, 4, 8]).
10171026
Only used if cog=True. If None and cog=True, auto-generate.
1027+
overview_resampling : str
1028+
Resampling method for overviews: ``'mean'`` (default),
1029+
``'nearest'``, ``'min'``, ``'max'``, ``'median'``, ``'mode'``,
1030+
or ``'cubic'``.
1031+
raster_type : int
1032+
TIFF ``GTRasterTypeGeoKey`` value. ``1`` (default) = PixelIsArea,
1033+
``2`` = PixelIsPoint.
1034+
x_resolution, y_resolution : float or None
1035+
Pixels per ``resolution_unit`` along each axis. Written into the
1036+
TIFF XResolution / YResolution tags.
1037+
resolution_unit : int or None
1038+
TIFF ResolutionUnit tag. ``1`` = none, ``2`` = inch, ``3`` = cm.
1039+
gdal_metadata_xml : str or None
1040+
Raw XML payload written to the ``GDAL_METADATA`` tag. Used to
1041+
round-trip arbitrary GDAL-style metadata.
1042+
extra_tags : list or None
1043+
Additional TIFF tags to emit, as a list of
1044+
``(tag_id, type_id, count, value)`` tuples.
1045+
bigtiff : bool or None
1046+
Force BigTIFF (64-bit offsets). None auto-promotes when the
1047+
estimated file size would exceed the classic-TIFF 4 GB limit.
1048+
max_z_error : float
1049+
Per-pixel error budget for LERC compression. ``0.0`` (default)
1050+
is lossless. Only valid with ``compression='lerc'``.
10181051
"""
10191052
comp_tag = _compression_tag(compression)
10201053
pred_int = normalize_predictor(predictor, data.dtype, comp_tag)

0 commit comments

Comments
 (0)