Harden code, tests, and documentation for robustness and compliance - #96
Merged
Conversation
- Refactor `.values` calls in `grid.py` to maintain Dask laziness for mask handling. - Implement `Regridder.clear_cache()` and `clear_instance_cache()` for improved memory management. - Add `__del__` to `Regridder` to ensure automatic cleanup of worker-local caches. - Improve ESMF error handling by translating cryptic codes into descriptive messages. - Harden `_apply_weights_core` to handle empty or NaN-only input arrays gracefully. - Add comprehensive new tests for hardening verification, Aero Protocol compliance, and cache isolation. - Format codebase with `ruff`.
…33388927676 Harden tests and code
- Resolved formatting issues in test files and core logic. - Added missing NumPy-style docstrings and type hints to CLI and internal functions. - Verified that all unit tests pass with both Eager and Lazy backends. - Ensured compliance with the Aero Protocol for backend-agnostic computation. - Verified that pre-commit hooks (ruff, ruff-format) pass completely.
…186392 Fix linting and CI issues for PR NOAA-EMC#94
Moved approximately 70 fragmented test files into 11 categorical files: - test_backends.py - test_diagnostics.py - test_grids.py - test_integration.py - test_misc.py - test_optimization.py - test_protocol.py - test_regridder.py - test_unstructured.py - test_utils.py - test_viz.py Each file contains migrated test functions and classes, with name conflicts resolved by appending suffixes. Shared fixtures like dask_client and sample_input were preserved. All original test_aero_*.py and other redundant test files were removed to improve repository structure and maintainability.
…8799792 Consolidate and logically name test suite
- Add Architecture overview with Mermaid diagram to index.md - Create Scientific Hygiene guide (Aero Protocol, NaN handling, diagnostics) - Document xarray accessors in new accessors.md - Complete missing grid generation utilities in utils.md - Update navigation and examples README - Fix SyntaxError and missing import in tests/test_utils.py
Harden Documentation and Scientific Guides
- Replace star imports with explicit imports in `tests/test_utils.py`. - Fix bare except in `tests/test_utils.py`. - Remove redundant empty test files that only contained star imports and no tests. - Consolidate ESMF check logic in `tests/test_utils.py`. - Ensure compliance with `ruff` linting rules.
…35715884 Fix linting issues in tests
- Update `.regrid.to()` to support passing a pre-computed `Regridder` instance, avoiding redundant weight generation. - Add `.regrid.get_regridder()` to both DataArray and Dataset accessors to allow users to extract and reuse regridders. - Add `.regrid.plot_diagnostics()` to accessors for rapid quality control. - Ensure all new methods follow the Aero Protocol (backend-agnostic, strictly typed, NumPy docstrings). - Add comprehensive tests in `tests/test_accessors.py` covering NumPy and Dask backends.
…8936950334624906 Optimize xarray accessors for weight reuse and diagnostics
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.
This pull request adds significant new functionality and tests to the
xregridaccessors forxarray.DataArrayandxarray.Dataset, making them more flexible and user-friendly. The main changes include allowing the accessors'.to()method to accept either a target grid or a pre-computedRegridder, adding convenience methods for regridder creation and diagnostics plotting, and introducing comprehensive tests for these features.Enhancements to accessor functionality:
.to()method for bothDataArrayandDatasetaccessors now accepts either a target grid (xr.Dataset) or an existingRegridderinstance, enabling more efficient and flexible regridding workflows. [1] [2].get_regridder()convenience methods to both accessors, allowing users to easily create and reuse aRegridderinstance. [1] [2].plot_diagnostics()methods to both accessors, providing a simple interface for visualizing regridding diagnostics directly from aDataArrayorDataset. [1] [2]Testing improvements:
tests/test_accessors.pyto verify the new accessor behaviors, including support for both eager (NumPy) and lazy (Dask) arrays, regridding with aRegridderinstance, and smoke tests for the diagnostics plotting methods.Type hint improvements:
Union[xr.Dataset, Regridder]for thetarget_gridparameter, reflecting the expanded input options.These changes make the regridding API more flexible and user-friendly, and the new tests ensure robustness and correct behavior.