Skip to content

Commit f736c4b

Browse files
committed
Distinguish local+global attributes in netcdf loads.
1 parent 8b751c5 commit f736c4b

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/iris/fileformats/_nc_load_rules/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ def build_cube_metadata(engine):
433433
# Set the cube global attributes.
434434
for attr_name, attr_value in cf_var.cf_group.global_attributes.items():
435435
try:
436-
cube.attributes[str(attr_name)] = attr_value
436+
cube.attributes.globals[str(attr_name)] = attr_value
437437
except ValueError as e:
438438
msg = "Skipping global attribute {!r}: {}"
439439
warnings.warn(msg.format(attr_name, str(e)))

lib/iris/fileformats/netcdf/loader.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,13 @@ def attribute_predicate(item):
159159
return item[0] not in _CF_ATTRS
160160

161161
tmpvar = filter(attribute_predicate, cf_var.cf_attrs_unused())
162+
attrs_dict = iris_object.attributes
163+
if hasattr(attrs_dict, "locals"):
164+
# Treat cube attributes (i.e. a CubeAttrsDict) as a special case.
165+
# These attrs are "local" (i.e. on the variable), so record them as such.
166+
attrs_dict = attrs_dict.locals
162167
for attr_name, attr_value in tmpvar:
163-
_set_attributes(iris_object.attributes, attr_name, attr_value)
168+
_set_attributes(attrs_dict, attr_name, attr_value)
164169

165170

166171
def _get_actual_dtype(cf_var):

0 commit comments

Comments
 (0)