Skip to content

geotiff: extract attrs/metadata helpers to _attrs.py (#1883)#1893

Merged
brendancol merged 1 commit into
mainfrom
issue-1883
May 15, 2026
Merged

geotiff: extract attrs/metadata helpers to _attrs.py (#1883)#1893
brendancol merged 1 commit into
mainfrom
issue-1883

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

Step 5 of #1813's multi-PR refactor of xrspatial/geotiff/__init__.py. Pure code motion; no public API change.

Moved into a new xrspatial/geotiff/_attrs.py:

  • _populate_attrs_from_geo_info — single source of truth for every read backend's DataArray.attrs (called from 4 read paths plus windowed reads).
  • _resolve_nodata_attr — sentinel resolution from attrs (checks 'nodata', 'nodatavals', '_FillValue' in that order, with NaN handling).
  • _merge_friendly_extra_tags / _extract_rich_tags — write-side helpers that fold friendly attrs (image_description, extra_samples, colormap) into the extra_tags list passed to the writer.
  • _extent_to_window — geographic-extent → pixel-window math.

Plus the constants the helpers need: _TIFF_BYTE, _TIFF_ASCII, _TIFF_SHORT, _RESOLUTION_UNIT_IDS, _LEVEL_RANGES, _VALID_COMPRESSIONS.

_extent_to_window is consumed by xrspatial/accessor.py via from .geotiff import _extent_to_window; the re-import in __init__.py keeps that path resolving. The internal-only constants (_TIFF_*, _RESOLUTION_UNIT_IDS, _merge_friendly_extra_tags) are not re-imported into __init__.py because nothing inside it calls them after the move.

Diff stats

  • __init__.py: 4569 → 4271 (-298 lines).
  • New _attrs.py: 332 lines.

Test plan

Closes #1883. Refs #1813.

Step 5 of #1813's multi-PR refactor of __init__.py. Pure code motion;
no public API change.

Moved into a new xrspatial/geotiff/_attrs.py:

- _populate_attrs_from_geo_info: single source of truth for every
  read backend's DataArray.attrs (called 4x in __init__.py + every
  windowed-read path).
- _resolve_nodata_attr: nodata sentinel resolution from attrs
  (checks 'nodata', 'nodatavals', '_FillValue' in that order).
- _merge_friendly_extra_tags / _extract_rich_tags: write-side helpers
  that fold friendly attrs (image_description, extra_samples,
  colormap) into the extra_tags list passed to the writer.
- _extent_to_window: geographic extent to pixel-window math.

Plus the TIFF tag-id constants the helpers need (_TIFF_BYTE,
_TIFF_ASCII, _TIFF_SHORT, _RESOLUTION_UNIT_IDS) and the writer-side
constants used by to_geotiff (_LEVEL_RANGES, _VALID_COMPRESSIONS).

_extent_to_window is consumed by xrspatial/accessor.py via
``from .geotiff import _extent_to_window``; the re-import in
__init__.py keeps that path resolving.

Net __init__.py change: 4569 -> 4271 lines (-298). _attrs.py is 332
lines.

Verification: pixel-parity matrix from #1889 (192 cells), runtime
identity from #1890 (9 tests), attrs parity from #1548 (5 tests),
extra_tags filter (#1657), geotags, overview nodata inheritance
(#1739) -- 251/251 pass.

Refs #1813.
Copilot AI review requested due to automatic review settings May 15, 2026 03:24
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 15, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Step 5 of the geotiff refactor (#1813): extracts the attrs/metadata helpers and TIFF tag-id constants from xrspatial/geotiff/__init__.py into a new _attrs.py module. Pure code motion with re-imports preserving the public/private import surface.

Changes:

  • Created xrspatial/geotiff/_attrs.py containing _populate_attrs_from_geo_info, _resolve_nodata_attr, _merge_friendly_extra_tags, _extract_rich_tags, _extent_to_window, and constants (_LEVEL_RANGES, _VALID_COMPRESSIONS, _TIFF_*, _RESOLUTION_UNIT_IDS).
  • Removed those definitions from __init__.py and re-imported the names still referenced inline (or by xrspatial.accessor).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
xrspatial/geotiff/_attrs.py New module holding attrs lifecycle helpers and tag-id constants.
xrspatial/geotiff/init.py Drops the moved helpers/constants; re-imports the names still used inline or via from xrspatial.geotiff import ….

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@brendancol brendancol merged commit d0b4148 into main May 15, 2026
15 checks passed
@brendancol brendancol deleted the issue-1883 branch May 15, 2026 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

geotiff: extract attrs/metadata helpers into _attrs.py (#1813 step 5)

2 participants