Skip to content

Commit 60569dd

Browse files
committed
geotiff: document attrs tier classification in _attrs.py (#1984)
Extends the module docstring with the three-tier attrs contract from issue #1984: - Canonical keys (crs, crs_wkt, transform, nodata, raster_type, extra_tags, gdal_metadata, gdal_metadata_xml, x_resolution, y_resolution, resolution_unit, _xrspatial_geotiff_contract) are owned by xrspatial and survive round-trip. - Compatibility aliases (nodatavals, _FillValue) are read for ecosystem interop but writers never emit them when the canonical key is set. - Best-effort pass-through keys (GeoKey-derived fields, image_description, extra_samples, colormap variants) are preserved when the writer can reconstruct them from canonical state. Docstring-only change. The contract version key is mentioned for reference; it is populated by a later PR in the series.
1 parent 0570518 commit 60569dd

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

xrspatial/geotiff/_attrs.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,62 @@
1414
entries.
1515
1616
Extracted in step 5 of issue #1813.
17+
18+
Attrs contract (issue #1984)
19+
----------------------------
20+
21+
The keys written into ``DataArray.attrs`` by the read paths fall into
22+
three tiers. Writers honour the same split: canonical keys are emitted,
23+
compatibility aliases are read but never written when the canonical key
24+
is present, and pass-through keys are kept when the writer can
25+
reconstruct them from canonical state.
26+
27+
The contract version is recorded in ``attrs['_xrspatial_geotiff_contract']``
28+
(currently ``1``). Consumers can branch on this integer if the tier
29+
split changes in a future release.
30+
31+
Canonical (xrspatial owns these; round-trip stable):
32+
33+
- ``crs``: EPSG integer code for the horizontal CRS.
34+
- ``crs_wkt``: PROJ WKT string for the horizontal CRS. Always emitted.
35+
- ``transform``: tuple of ``(origin_x, origin_y, pixel_width, pixel_height)``.
36+
- ``nodata``: declared file sentinel as stored in the GDAL_NODATA tag. The
37+
declared-vs-masked split is tracked in issue #1988; the canonical
38+
semantics here describe the intended behaviour once #1988 lands.
39+
- ``raster_type``: ``'area'`` (implicit / RasterPixelIsArea) or ``'point'``
40+
(explicit / RasterPixelIsPoint).
41+
- ``extra_tags``: list of ``(tag_id, type_id, count, value)`` tuples for
42+
TIFF tags outside the structured set.
43+
- ``gdal_metadata``: dict parsed from the GDAL_METADATA XML tag.
44+
- ``gdal_metadata_xml``: raw GDAL_METADATA XML string.
45+
- ``x_resolution``, ``y_resolution``, ``resolution_unit``: TIFF
46+
XResolution / YResolution / ResolutionUnit values.
47+
- ``_xrspatial_geotiff_contract``: integer version of this contract.
48+
49+
Compatibility alias (read for ecosystem interop; writers must not emit
50+
when the canonical key is present):
51+
52+
- ``nodatavals``: rioxarray per-band tuple form of ``nodata``.
53+
- ``_FillValue``: CF-convention name for ``nodata``.
54+
55+
Best-effort pass-through (preserved when the writer can reconstruct
56+
from canonical state, otherwise dropped on round-trip):
57+
58+
- ``crs_name``: human-readable CRS name from the GeoKey directory.
59+
- ``geog_citation``: GeographicTypeGeoKey citation string.
60+
- ``datum_code``: GeogGeodeticDatumGeoKey value.
61+
- ``angular_units``: GeogAngularUnitsGeoKey value.
62+
- ``linear_units``: ProjLinearUnitsGeoKey value.
63+
- ``semi_major_axis``: GeogSemiMajorAxisGeoKey value.
64+
- ``inv_flattening``: GeogInvFlatteningGeoKey value.
65+
- ``projection_code``: ProjectedCSTypeGeoKey value.
66+
- ``vertical_crs``: VerticalCSTypeGeoKey value.
67+
- ``vertical_citation``: VerticalCitationGeoKey value.
68+
- ``vertical_units``: VerticalUnitsGeoKey value.
69+
- ``image_description``: TIFF ImageDescription tag.
70+
- ``extra_samples``: TIFF ExtraSamples tag.
71+
- ``colormap``, ``colormap_rgba``, ``cmap``: palette data attached to
72+
single-band paletted images.
1773
"""
1874
from __future__ import annotations
1975

0 commit comments

Comments
 (0)