Skip to content

Conversation

HGWright
Copy link
Contributor

@HGWright HGWright commented Oct 24, 2024

🚀 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:

  • benchmark_this Request that this pull request be benchmarked to check if it introduces performance shifts

Comment on lines 1430 to 1462
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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
)

Copy link
Contributor

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)

Copy link
Contributor

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.

@HGWright HGWright marked this pull request as ready for review October 25, 2024 16:22
@HGWright HGWright changed the title DRAFT Bounds on derived coords Bounds on derived coords Oct 25, 2024
@HGWright
Copy link
Contributor Author

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 Future: flag as a different method of loading, this means that we can keep the existing Iris behaviour. We can also avoid making this save to the best version of CF until a later date to avoid this code going stale. (This will be written up and spec'd out in an issue.)

@trexfeathers
Copy link
Contributor

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 Future: flag as a different method of loading, this means that we can keep the existing Iris behaviour. We can also avoid making this save to the best version of CF until a later date to avoid this code going stale. (This will be written up and spec'd out in an issue.)

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.

@trexfeathers
Copy link
Contributor

My understanding of our goal

... after my most recent conversation with @HGWright

Ref: CF Conventions 7.1.4. Boundaries and Formula Terms

FUTURE OFF 1 FUTURE ON
Primary method 2
Secondary method 3
hybrid_height.nc 4

Footnotes

  1. the current situation

  2. "If a parametric coordinate variable with a formula_terms attribute (section 4.3.2) also has a bounds attribute, its boundary variable must have a formula_terms attribute too. In this case the same terms would appear in both (as specified in Appendix D), since the transformation from the parametric coordinate values to physical space is realized through the same formula. For any term that depends on the vertical dimension, however, the variable names appearing in the formula terms would differ from those found in the formula_terms attribute of the coordinate variable itself because the boundary variables for formula terms are two-dimensional while the formula terms themselves are one-dimensional."

  3. "Whenever a formula_terms attribute is attached to a boundary variable, the formula terms may additionally be identified using a second method: variables appearing in the vertical coordinates' formula_terms may be declared to be coordinate, scalar coordinate or auxiliary coordinate variables, and those coordinates may have bounds attributes that identify their boundary variables. In that case, the bounds attribute of a formula terms variable must be consistent with the formula_terms attribute of the boundary variable. Software digesting legacy datasets (constructed prior to version 1.7 of this standard) may have to rely in some cases on the first method of identifying the formula term variables and in other cases, on the second. Starting from version 1.7, however, the first method will be sufficient."

  4. hybrid_height.nc in iris-sample-data is acknowledged to be incorrect CF, but has been the Iris status quo for years. Iris internals/tests expect this format, and we must assume some users might also depend on this, hence why dropping support for this invalid format must be protected behind a FUTURE flag.

@pp-mo pp-mo linked an issue Feb 20, 2025 that may be closed by this pull request
scitools-ci bot and others added 17 commits February 28, 2025 16:48
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>
fnattino and others added 22 commits February 28, 2025 17:07
* 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>
* 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>
@github-actions github-actions bot added the benchmark_this Request that this pull request be benchmarked to check if it introduces performance shifts label Feb 28, 2025
@HGWright
Copy link
Contributor Author

I have messed up the PR trying to revive this. Closing and moving changes to a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
benchmark_this Request that this pull request be benchmarked to check if it introduces performance shifts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bounds of derived variable are not read correctly
9 participants