@@ -276,6 +276,55 @@ def is_systematic(self) -> bool:
276276
277277 return all (e [1 ].is_systematic is True for e in self .err_corr )
278278
279+ def err_corr_dict (self ) -> dict :
280+ """
281+ Error-correlation dictionary for uncertainty effect.
282+
283+ :return: dictionary with error-correlation for each dimension
284+ """
285+
286+ # initialise error-correlation dictionary
287+ err_corr_dict = {}
288+
289+ # populate with error-correlation matrices built be each error-correlation
290+ # parameterisation object
291+ for dim_err_corr in self .err_corr :
292+ if np .all (
293+ [
294+ dim in self ._obj [self ._unc_var_name ][self ._sli ].dims
295+ for dim in dim_err_corr [1 ].dims
296+ ]
297+ ):
298+ if dim_err_corr [1 ].form in ["random" , "systematic" ]:
299+ err_corr_dict [dim_err_corr [0 ]] = dim_err_corr [1 ].form
300+
301+ elif dim_err_corr [1 ].form == "err_corr_matrix" :
302+ err_corr_dict [dim_err_corr [0 ]] = self ._obj [
303+ dim_err_corr [1 ].params [0 ]
304+ ].values
305+
306+ else :
307+ raise NotImplementedError (
308+ "this correlation form is not implemented for err_corr_dict()"
309+ )
310+ return err_corr_dict
311+
312+ def err_corr_dict_numdim (self ) -> dict :
313+ """
314+ Error-correlation dictionary for uncertainty effect, where the keys are the dimension index rather than dimension name.
315+
316+ :return: dictionary with error-correlation for each dimension
317+ """
318+ # initialise error-correlation dictionary
319+ err_corr_dict = self .err_corr_dict ()
320+ err_corr_dict_numdim = {}
321+
322+ for idim , dim in enumerate (self ._obj .dims ):
323+ if dim in err_corr_dict .keys ():
324+ err_corr_dict_numdim [str (idim )] = err_corr_dict [dim ]
325+
326+ return err_corr_dict_numdim
327+
279328 def err_corr_matrix (self ) -> xr .DataArray :
280329 """
281330 Error-correlation matrix for uncertainty effect.
@@ -291,7 +340,12 @@ def err_corr_matrix(self) -> xr.DataArray:
291340 # populate with error-correlation matrices built be each error-correlation
292341 # parameterisation object
293342 for dim_err_corr in self .err_corr :
294- if np .all ([dim in self ._obj [self ._unc_var_name ][self ._sli ].dims for dim in dim_err_corr [1 ].dims ]):
343+ if np .all (
344+ [
345+ dim in self ._obj [self ._unc_var_name ][self ._sli ].dims
346+ for dim in dim_err_corr [1 ].dims
347+ ]
348+ ):
295349 err_corr_matrix .values = err_corr_matrix .values .dot (
296350 dim_err_corr [1 ].build_matrix (self ._sli )
297351 )
@@ -583,7 +637,8 @@ def structured_err_cov_matrix(self):
583637
584638 covs_sum = np .zeros (structured_err_cov_matrix .shape )
585639 for unc in self :
586- covs_sum += unc [self ._sli ].err_cov_matrix ().values
640+ if unc .is_structured :
641+ covs_sum += unc [self ._sli ].err_cov_matrix ().values
587642
588643 structured_err_cov_matrix .values = covs_sum
589644
0 commit comments