-
Notifications
You must be signed in to change notification settings - Fork 296
PI-3473: Netcdf loading ancillary variables #3556
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
Changes from all commits
6842a50
5cfec8f
26a32a3
242a62f
479b2cf
738093f
365d0e9
c683f2e
5c50c56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
* Added support for the `black <https://black.readthedocs.io/en/stable/>`_ code formatter. | ||
This is now automatically checked on GitHub PRs, replacing the older, unittest-based | ||
"iris.tests.test_coding_standards.TestCodeFormat". | ||
Black provides automatic code format correction for most IDEs. | ||
See the new developer guide section on this : | ||
https://scitools-docs.github.io/iris/master/developers_guide/code_format.html. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -459,7 +459,10 @@ def __setstate__(self, state): | |
|
||
def _assert_case_specific_facts(engine, cf, cf_group): | ||
# Initialise pyke engine "provides" hooks. | ||
# These are used to patch non-processed element attributes after rules activation. | ||
engine.provides["coordinates"] = [] | ||
engine.provides["cell_measures"] = [] | ||
engine.provides["ancillary_variables"] = [] | ||
|
||
# Assert facts for CF coordinates. | ||
for cf_name in cf_group.coordinates.keys(): | ||
|
@@ -479,6 +482,12 @@ def _assert_case_specific_facts(engine, cf, cf_group): | |
_PYKE_FACT_BASE, "cell_measure", (cf_name,) | ||
) | ||
|
||
# Assert facts for CF ancillary variables. | ||
for cf_name in cf_group.ancillary_variables.keys(): | ||
engine.add_case_specific_fact( | ||
_PYKE_FACT_BASE, "ancillary_variable", (cf_name,) | ||
) | ||
|
||
# Assert facts for CF grid_mappings. | ||
for cf_name in cf_group.grid_mappings.keys(): | ||
engine.add_case_specific_fact( | ||
|
@@ -597,31 +606,38 @@ def _load_cube(engine, cf, cf_var, filename): | |
# Run pyke inference engine with forward chaining rules. | ||
engine.activate(_PYKE_RULE_BASE) | ||
|
||
# Populate coordinate attributes with the untouched attributes from the | ||
# associated CF-netCDF variable. | ||
coordinates = engine.provides.get("coordinates", []) | ||
|
||
# Having run the rules, now populate the attributes of all the cf elements with the | ||
# "unused" attributes from the associated CF-netCDF variable. | ||
# That is, all those that aren't CF reserved terms. | ||
def attribute_predicate(item): | ||
return item[0] not in _CF_ATTRS | ||
|
||
for coord, cf_var_name in coordinates: | ||
tmpvar = filter( | ||
attribute_predicate, cf.cf_group[cf_var_name].cf_attrs_unused() | ||
) | ||
def add_unused_attributes(iris_object, cf_var): | ||
tmpvar = filter(attribute_predicate, cf_var.cf_attrs_unused()) | ||
for attr_name, attr_value in tmpvar: | ||
_set_attributes(coord.attributes, attr_name, attr_value) | ||
_set_attributes(iris_object.attributes, attr_name, attr_value) | ||
|
||
def fix_attributes_all_elements(role_name): | ||
elements_and_names = engine.provides.get(role_name, []) | ||
|
||
for iris_object, cf_var_name in elements_and_names: | ||
add_unused_attributes(iris_object, cf.cf_group[cf_var_name]) | ||
|
||
# Populate the attributes of all coordinates, cell-measures and ancillary-vars. | ||
fix_attributes_all_elements("coordinates") | ||
fix_attributes_all_elements("ancillary_variables") | ||
fix_attributes_all_elements("cell_measures") | ||
|
||
tmpvar = filter(attribute_predicate, cf_var.cf_attrs_unused()) | ||
# Attach untouched attributes of the associated CF-netCDF data variable to | ||
# the cube. | ||
for attr_name, attr_value in tmpvar: | ||
_set_attributes(cube.attributes, attr_name, attr_value) | ||
# Also populate attributes of the top-level cube itself. | ||
add_unused_attributes(cube, cf_var) | ||
|
||
# Work out reference names for all the coords. | ||
names = { | ||
coord.var_name: coord.standard_name or coord.var_name or "unknown" | ||
for coord in cube.coords() | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should there still be whitespace here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I suppose so. |
||
# Add all the cube cell methods. | ||
cube.cell_methods = [ | ||
iris.coords.CellMethod( | ||
method=method.method, | ||
|
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.
For consistency, should this have a comment similar to this line?
iris/lib/iris/fileformats/_pyke_rules/fc_rules_cf.krb
Lines 2018 to 2019 in 1178de7
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.
Ok, but "consistency" is a bit of a lost cause in this code IMHO. Not least because we have far too much code duplication code, as here !
( N.B. We do still hope to replace all of this with Python code #3415 )