geotiff: extract attrs/metadata helpers to _attrs.py (#1883)#1893
Merged
Conversation
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.
Contributor
There was a problem hiding this comment.
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.pycontaining_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__.pyand re-imported the names still referenced inline (or byxrspatial.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.
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.
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'sDataArray.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 theextra_tagslist 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_windowis consumed byxrspatial/accessor.pyviafrom .geotiff import _extent_to_window; the re-import in__init__.pykeeps that path resolving. The internal-only constants (_TIFF_*,_RESOLUTION_UNIT_IDS,_merge_friendly_extra_tags) are not re-imported into__init__.pybecause nothing inside it calls them after the move.Diff stats
__init__.py: 4569 → 4271 (-298 lines)._attrs.py: 332 lines.Test plan
from xrspatial.geotiff import _populate_attrs_from_geo_info, _resolve_nodata_attr, _extract_rich_tags, _extent_to_window, _LEVEL_RANGES, _VALID_COMPRESSIONS— re-export works.xrspatial.accessor._extent_to_windowimport path still resolves.Closes #1883. Refs #1813.