@@ -59,6 +59,26 @@ def _mse(errors: da.Array) -> da.Array:
5959 )
6060
6161
62+ def _set_coordinate_attr (x : DataArray ):
63+ """Sets the coordinate attribute, if applicable."""
64+ if x .coords .keys ():
65+ x .attrs ["coordinates" ] = " " .join (map (str , x .coords .keys ()))
66+
67+
68+ def _set_standard_name_attr (x : DataArray ):
69+ """Sets the standard name attribute, if applicable"""
70+ if "standard_name" in x .attrs :
71+ standard_name = x .attrs ["standard_name" ]
72+ x .attrs ["standard_name" ] = f"{ standard_name } standard_error"
73+
74+
75+ def _set_title_attr (x : DataArray ):
76+ """Sets the title attribute, if applicable."""
77+ if "title" in x .attrs :
78+ title = x .attrs ["title" ]
79+ x .attrs ["title" ] = f"standard uncertainty of { title } "
80+
81+
6282class CollectOp (Operator ):
6383 """The collect operator."""
6484
@@ -118,8 +138,6 @@ def add_uncertainty(self, target, source, v, x, filtered: bool = False):
118138 dims = x .dims ,
119139 attrs = x .attrs ,
120140 )
121- for attr in config [v ].get ("attrs_pop" , []):
122- target [v_unc ].attrs .pop (attr , None )
123141 if "actual_range" in target [v_unc ].attrs :
124142 target [v_unc ].attrs ["actual_range" ] = np .array (
125143 [
@@ -128,20 +146,16 @@ def add_uncertainty(self, target, source, v, x, filtered: bool = False):
128146 ],
129147 dtype = x_unc .dtype ,
130148 )
131- if "standard_name" in target [v_unc ].attrs :
132- standard_name = target [v_unc ].attrs ["standard_name" ]
149+ if filtered :
133150 target [v_unc ].attrs [
134- "standard_name"
135- ] = f"{ standard_name } standard_error"
136- if "title" in target [v_unc ].attrs :
137- title = target [v_unc ].attrs ["title" ]
138- target [v_unc ].attrs ["title" ] = f"standard uncertainty of { title } "
151+ "comment"
152+ ] = "filtered variant of standard uncertainty"
153+ _set_coordinate_attr (target [v_unc ])
154+ _set_standard_name_attr (target [v_unc ])
155+ _set_title_attr (target [v_unc ])
156+ for attr in config [v ].get ("attrs_pop" , []):
157+ target [v_unc ].attrs .pop (attr , None )
139158 target [v_unc ].attrs .update (config [v ].get ("attrs" , {}))
140- if filtered :
141- target [v_unc ].attrs ["comment" ] = (
142- "filtered variant of standard uncertainty using a lateral "
143- "low-pass filter"
144- )
145159 if get_logger ().is_enabled (Logging .DEBUG ):
146160 get_logger ().debug (f"min: { da .nanmin (x_unc ).compute () :.3f} " )
147161 get_logger ().debug (f"max: { da .nanmax (x_unc ).compute () :.3f} " )
0 commit comments