-
Notifications
You must be signed in to change notification settings - Fork 296
Bounds on derived coords #6190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bounds on derived coords #6190
Conversation
lib/iris/fileformats/cf.py
Outdated
if cf_root not in self.cf_group.bounds: | ||
# Check if cf_root has a bounds attribute. | ||
if cf_root in self.cf_group.coordinates: | ||
# Need to generalise this for if it's a dim or aux coord. | ||
bounds_name = getattr( | ||
self.cf_group.coordinates[cf_root], "bounds", None | ||
) | ||
if bounds_name is not None: | ||
form_terms = getattr( | ||
self.cf_group.coordinates[cf_root], "formula_terms" | ||
) | ||
form_terms = form_terms.replace(":", "") | ||
form_terms = form_terms.split(" ") | ||
example_dict = {"a": "A", "b": "B", "ps": "PS", "p0": "P0"} | ||
for cf_vari in formula_terms.values(): | ||
for ( | ||
cf_roots, | ||
cf_terms, | ||
) in cf_vari.cf_terms_by_root.items(): | ||
if cf_terms == cf_term: | ||
if ( | ||
cf_roots in self.cf_group.bounds | ||
and cf_roots == bounds_name | ||
): | ||
if cf_terms in form_terms: | ||
to_attach_to = example_dict[cf_terms] | ||
attach_from = cf_vari.cf_name | ||
if ( | ||
to_attach_to.lower() | ||
!= attach_from.lower() | ||
): | ||
cf_var.bounds = cf_vari | ||
print(cf_vari.bounds) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if cf_root not in self.cf_group.bounds: | |
# Check if cf_root has a bounds attribute. | |
if cf_root in self.cf_group.coordinates: | |
# Need to generalise this for if it's a dim or aux coord. | |
bounds_name = getattr( | |
self.cf_group.coordinates[cf_root], "bounds", None | |
) | |
if bounds_name is not None: | |
form_terms = getattr( | |
self.cf_group.coordinates[cf_root], "formula_terms" | |
) | |
form_terms = form_terms.replace(":", "") | |
form_terms = form_terms.split(" ") | |
example_dict = {"a": "A", "b": "B", "ps": "PS", "p0": "P0"} | |
for cf_vari in formula_terms.values(): | |
for ( | |
cf_roots, | |
cf_terms, | |
) in cf_vari.cf_terms_by_root.items(): | |
if cf_terms == cf_term: | |
if ( | |
cf_roots in self.cf_group.bounds | |
and cf_roots == bounds_name | |
): | |
if cf_terms in form_terms: | |
to_attach_to = example_dict[cf_terms] | |
attach_from = cf_vari.cf_name | |
if ( | |
to_attach_to.lower() | |
!= attach_from.lower() | |
): | |
cf_var.bounds = cf_vari | |
print(cf_vari.bounds) | |
bounds_name = None | |
cf_root_coord = self.cf_group.coordinates.get(cf_root, None) | |
with contextlib.suppress(AttributeError): | |
# Copes with cf_root_coord not existing, OR not having | |
# `bounds` attribute. | |
bounds_name = _getncattr(cf_root_coord, "bounds") | |
if bounds_name is not None: | |
# This will error if more or less than 1 variable is found. | |
# TODO: does this ever need to be more permissive? | |
(bounds_var,) = [ | |
f for f in formula_terms.values() | |
if f.cf_terms_by_root.get(bounds_name) == cf_term | |
] | |
self.cf_group[cf_var.cf_name].bounds = bounds_var.cf_name | |
# TODO: get bounds_var into the appropriate 'cf_group' for | |
# discovery during helpers.get_cf_bounds_var(). | |
self.cf_group[bounds_var.cf_name] = CFBoundaryVariable( | |
bounds_var.cf_name, bounds_var.cf_data | |
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might also work:
-cf_root_coord = self.cf_group.coordinates.get(cf_root, None)
+cf_root_coord = self.cf_group.coordinates.get(cf_root)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that I did not exclude variables that are duplicated between the original formula terms and the bounds formula terms. E.g. ps
and p0
in #3678.
This needs doing.
After a long and productive discussion with @trexfeathers and @pp-mo (thanks guys). We have decided that for the upcoming 3.12 release we will put this behind a |
Something else from that discussion, which affects the work in this PR: we need to think about how to handle a case where both approaches to recording bounds have been used, but they produce conflicting information. |
My understanding of our goal... after my most recent conversation with @HGWright Ref: CF Conventions 7.1.4. Boundaries and Formula Terms
Footnotes
|
Co-authored-by: Lockfile bot <noreply@github.com>
* added in a vertical rule for surface fields * added in PR # to whatsnew * added flags * tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixed whatsnew * improved paramaterisation * added doc improvements * fixed underscore * doc changes * Fixed spacing error --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Specify meta in da.map_blocks * Improve tests * Add more tests * Add whatsnew * Specify dtype in map_complete_blocks and undo change to lazy_elementwise --------- Co-authored-by: Patrick Peglar <patrick.peglar@metoffice.gov.uk>
* Update CF standard names table. * ADDED WHATSNEW
updates: - [github.com/astral-sh/ruff-pre-commit: v0.7.0 → v0.7.1](astral-sh/ruff-pre-commit@v0.7.0...v0.7.1) - [github.com/asottile/blacken-docs: 1.19.0 → 1.19.1](adamchainz/blacken-docs@1.19.0...1.19.1) - [github.com/pre-commit/mirrors-mypy: v1.12.1 → v1.13.0](pre-commit/mirrors-mypy@v1.12.1...v1.13.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Bumps [scitools/workflows](https://github.com/scitools/workflows) from 2024.10.2 to 2024.10.3. - [Release notes](https://github.com/scitools/workflows/releases) - [Commits](SciTools/workflows@2024.10.2...2024.10.3) --- updated-dependencies: - dependency-name: scitools/workflows dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Use the new re-entrant do-nothing script. * Proper import error handling. * Always use git add. * More automation around CF standard names. * Missing bracket. * Less nebulous language. * Encourage copy-pasting from previous releases. * Clearer wording about release branches. * Clearer RTD versioning. * More precise installation tests. * Clearer rc branch naming. * Draw attention to deviation from conda-forge guidance. * Wait for CI to finish. * Include conda search command. * Comment on discussion. * Viva Engage. * Use a git command for recreating files. * Better SHA256 validation. * Add missing conda deactivate command. * Correct URL for watching conda-forge process. * Correct use of self.git_tag. * More guidance about when to change RC feedstock files. * Better advice for waiting for conda testing. * Raise correct message if `nothing` is not installed. Co-authored-by: Elias <110238618+ESadek-MO@users.noreply.github.com> * Line breaks in CF standard names instructions. Co-authored-by: Elias <110238618+ESadek-MO@users.noreply.github.com> * Don't use override-channels * Shout louder about NOT targeting the main branch. * More specificity in creating PRs, extra check for conda-forge RCs. * Corrected sha256 check. * What's New entry. --------- Co-authored-by: Elias <110238618+ESadek-MO@users.noreply.github.com>
* added conversion translation section, and fixed mocker reference * mocker is a fixture * which can, not which and * clarified mocker is the fixture, not .patch
updates: - [github.com/astral-sh/ruff-pre-commit: v0.7.1 → v0.7.2](astral-sh/ruff-pre-commit@v0.7.1...v0.7.2) - [github.com/aio-libs/sort-all: v1.2.0 → v1.3.0](aio-libs/sort-all@v1.2.0...v1.3.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Bumps [scitools/workflows](https://github.com/scitools/workflows) from 2024.10.3 to 2024.11.2. - [Release notes](https://github.com/scitools/workflows/releases) - [Commits](SciTools/workflows@2024.10.3...2024.11.2) --- updated-dependencies: - dependency-name: scitools/workflows dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* removed mentions of RC from whatsnew 3.11 * corrected date in whatsnew 3.11
Bumps [scitools/workflows](https://github.com/scitools/workflows) from 2024.11.2 to 2024.11.3. - [Release notes](https://github.com/scitools/workflows/releases) - [Commits](SciTools/workflows@2024.11.2...2024.11.3) --- updated-dependencies: - dependency-name: scitools/workflows dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* add lazy median * add tests * add what's new entry * move tests to pytest --------- Co-authored-by: Elias <110238618+ESadek-MO@users.noreply.github.com>
Co-authored-by: Lockfile bot <noreply@github.com>
updates: - [github.com/astral-sh/ruff-pre-commit: v0.9.1 → v0.9.2](astral-sh/ruff-pre-commit@v0.9.1...v0.9.2) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This reverts commit 752dfb8.
* lazy interpolation using map_complete_blocks * pre-commit fixes * replace test on interpolation with lazy data * Update lib/iris/analysis/_interpolation.py Co-authored-by: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> * Update lib/iris/analysis/_interpolation.py Co-authored-by: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> * resume local import * add entry to latest.rst * add author name to list * drop duplicated method * new signature of map_complete_blocks * update docstrings on lazy data * update userguide with lazy interpolator * the unstructured NN regridder does not support lazy data * remove caching an interpolator * update what's new entry * remove links to docs section about caching interpolators --------- Co-authored-by: Martin Yeo <40734014+trexfeathers@users.noreply.github.com>
Bumps [scitools/workflows](https://github.com/scitools/workflows) from 2025.01.3 to 2025.01.4. - [Release notes](https://github.com/scitools/workflows/releases) - [Commits](SciTools/workflows@2025.01.3...2025.01.4) --- updated-dependencies: - dependency-name: scitools/workflows dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Patrick Peglar <patrick.peglar@metoffice.gov.uk>
Bumps [scitools/workflows](https://github.com/scitools/workflows) from 2025.01.4 to 2025.01.5. - [Release notes](https://github.com/scitools/workflows/releases) - [Commits](SciTools/workflows@2025.01.4...2025.01.5) --- updated-dependencies: - dependency-name: scitools/workflows dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Lockfile bot <noreply@github.com> Co-authored-by: Martin Yeo <40734014+trexfeathers@users.noreply.github.com>
…ols#6288) * Use cube chunks for smart weights * Fix docstring for area_weights * Remove unused code * Added whatsnew
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/astral-sh/ruff-pre-commit: v0.9.2 → v0.9.4](astral-sh/ruff-pre-commit@v0.9.2...v0.9.4) - [github.com/codespell-project/codespell: v2.3.0 → v2.4.1](codespell-project/codespell@v2.3.0...v2.4.1) * Odd fixes for link + spelling failures. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Patrick Peglar <patrick.peglar@metoffice.gov.uk>
* Read list of variables only once * Add whatsnew * Improve whatsnew * Add benchmark for files with many cubes
Co-authored-by: Lockfile bot <noreply@github.com> merge-commit
Bumps [scitools/workflows](https://github.com/scitools/workflows) from 2025.01.5 to 2025.02.0. - [Release notes](https://github.com/scitools/workflows/releases) - [Commits](SciTools/workflows@2025.01.5...2025.02.0) --- updated-dependencies: - dependency-name: scitools/workflows dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
updates: - [github.com/astral-sh/ruff-pre-commit: v0.9.4 → v0.9.6](astral-sh/ruff-pre-commit@v0.9.4...v0.9.6) - [github.com/pre-commit/mirrors-mypy: v1.14.1 → v1.15.0](pre-commit/mirrors-mypy@v1.14.1...v1.15.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Bumps [scitools/workflows](https://github.com/scitools/workflows) from 2025.02.0 to 2025.02.1. - [Release notes](https://github.com/scitools/workflows/releases) - [Commits](SciTools/workflows@2025.02.0...2025.02.1) --- updated-dependencies: - dependency-name: scitools/workflows dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
… files with multiple variables (SciTools#6252) * Cache Dask arrays to speed up loading files with multiple variables * Add benchmark for files with many cubes * Add whatsnew * Add test * Add license header * Use a global to set the cache size * Update whatsnew
updates: - [github.com/PyCQA/flake8: 7.1.1 → 7.1.2](PyCQA/flake8@7.1.1...7.1.2) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
I have messed up the PR trying to revive this. Closing and moving changes to a new PR. |
🚀 Pull Request
Description
This PR does the loading agreed in #3678 (from this comment)
Consult Iris pull request check list
Add any of the below labels to trigger actions on this PR: