Skip to content

Metadata conversion refactor#4

Open
ianhi wants to merge 7 commits intomainfrom
metadata-conversion-refactor
Open

Metadata conversion refactor#4
ianhi wants to merge 7 commits intomainfrom
metadata-conversion-refactor

Conversation

@ianhi
Copy link
Copy Markdown
Owner

@ianhi ianhi commented Nov 13, 2025

working to more methodically convert all ome-metadata to equiv xarray object

ianhi and others added 3 commits November 13, 2025 16:57
Major redesign of how OME-NGFF metadata is stored in xarray objects.
Metadata that can be represented in xarray's data model (coordinates,
dimension names) is now stored there, not duplicated in attrs.

Design Principles:
- Coordinates represent data: scale/translation transforms → coord arrays,
  channel labels → channel coordinate values
- Attrs for non-representable metadata only: axis types, colors, windows,
  version info
- Full metadata dict preserved for perfect round-tripping
- No backward compatibility cruft (no users yet)

New Module: xarray_ome/metadata.py
- metadata_to_xarray_attrs(): OME-NGFF → xarray attrs (non-coord metadata)
- xarray_to_metadata(): xarray → OME-NGFF dict (for writing)
- Comprehensive docstrings explaining what goes where
- Designed for bidirectional conversion

Tests: tests/test_metadata_conversion.py (18 new tests)
- Test basic metadata extraction
- Test axes types, units, orientations
- Test multiscale info, channel colors/windows
- Test round-trip fidelity (metadata → xarray → metadata)
- Test preservation of unknown/future fields
- Test both string and numeric channel coordinates

Changes to reader.py:
- Remove _break_out_metadata() (replaced by new module)
- Simplify _ngff_image_to_dataset() - no backward compat attrs
- Use metadata_to_xarray_attrs() for clean separation
- Keep only ome_scale/ome_translation for efficient round-trip

Changes to writer.py:
- Import xarray_to_metadata (prepared for future use)
- Writer currently relies on ngff-zarr defaults (works correctly)
- Full metadata reconstruction will be added when needed

Changes to docs/api.md:
- Updated metadata attributes documentation
- Reorganized into "Common Attributes" and "Dataset-Only Attributes"
- Added all new attribute names with examples

All 60 tests pass (42 original + 18 new metadata tests).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Document the zarr backend fallback feature as a TODO for now, as it
needs more work to properly handle the interaction between backend
detection and reader error handling.

Changes:
- Add TODO.md with detailed notes on zarr fallback implementation
- Update reader.py to check store type before attempting to parse
- Improve error messages to distinguish between:
  - Regular zarr files (not OME-NGFF)
  - HCS plate structures (not yet supported)
  - Failed metadata parsing
- Backend already has fallback logic, but needs refactoring to work
  properly with reader's validation

The fallback feature is partially implemented but not yet working end-to-end.
Documented for future completion.

All 60 tests still pass.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Create detailed reference documenting how each OME-NGFF metadata
component is mapped to xarray structures (coordinates, dimensions,
or attributes).

Content:
- Design philosophy: metadata that CAN be in xarray coords/dims goes
  there, not duplicated in attrs
- Complete mapping tables for axes, coordinateTransformations,
  multiscales, omero, labels, and plate/well sections
- Direct links to OME-NGFF v0.5 spec sections for each metadata type
- Code examples showing both OME-NGFF and xarray representations
- Complete attribute reference for DataTree and Dataset objects
- Round-trip fidelity documentation
- Implementation details with function references

Added metadata_mapping page to docs/index.md toctree between usage
and examples.

This documentation provides a comprehensive reference for
understanding the bidirectional metadata conversion implemented in
the metadata.py module.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ianhi ianhi closed this Nov 13, 2025
@ianhi ianhi reopened this Nov 13, 2025
ianhi and others added 4 commits November 13, 2025 17:14
Set up automated testing, linting, and documentation building with uv
package manager for fast, reliable CI/CD.

Workflow Jobs:

1. Test Matrix:
   - Runs on: Ubuntu, macOS, Windows
   - Python versions: 3.11, 3.12, 3.13
   - Uses uv for dependency installation
   - Runs pytest with coverage reporting
   - Uploads coverage to Codecov (Ubuntu + Python 3.11 only)

2. Lint:
   - Runs ruff linting and formatting checks
   - Runs mypy type checking
   - Ensures code quality standards

3. Docs:
   - Builds Sphinx documentation with warnings as errors
   - Uploads HTML documentation as artifact
   - Validates documentation builds successfully

Benefits of using uv:
- Fast dependency resolution and installation
- Consistent environments across local dev and CI
- Native Python version management
- Works seamlessly with pyproject.toml

The workflow triggers on:
- Push to main and active feature branches
- Pull requests to main

Also fixed broken link in metadata_mapping.md documentation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Reduce CI complexity by testing only on Ubuntu across Python 3.11-3.13.
This speeds up CI runs while maintaining Python version compatibility
testing. Cross-platform testing can be added later if needed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Simplified workflow to only run tests since:
- Linting is handled by pre-commit.ci
- Documentation builds are handled by Read the Docs

This keeps CI focused on testing across Python versions (3.11-3.13)
with coverage reporting.

Final CI setup:
- Test matrix: Ubuntu with Python 3.11, 3.12, 3.13
- Coverage upload to Codecov for Python 3.11

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

1 participant