-
Notifications
You must be signed in to change notification settings - Fork 284
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
base: main
Are you sure you want to change the base?
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.
🚀 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: