Skip to content

Commit 6561261

Browse files
committed
adding error correlation dictionaries per dimension as output (to be used in punpy for generating MC samples without the need to first calculate the full covariance matrix, which can be too memory intensive)
1 parent e809750 commit 6561261

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

obsarray/unc_accessor.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,47 @@ 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([dim in self._obj[self._unc_var_name][self._sli].dims for dim in dim_err_corr[1].dims]):
293+
if dim_err_corr[1].form in ["random","systematic"]:
294+
err_corr_dict[dim_err_corr[0]]=dim_err_corr[1].form
295+
296+
elif dim_err_corr[1].form == "err_corr_matrix":
297+
err_corr_dict[dim_err_corr[0]]=self._obj[dim_err_corr[1].params[0]].values
298+
299+
else:
300+
raise NotImplementedError("this correlation form is not implemented for err_corr_dict()")
301+
return err_corr_dict
302+
303+
def err_corr_dict_numdim(self) -> dict:
304+
"""
305+
Error-correlation dictionary for uncertainty effect, where the keys are the dimension index rather than dimension name.
306+
307+
:return: dictionary with error-correlation for each dimension
308+
"""
309+
# initialise error-correlation dictionary
310+
err_corr_dict = self.err_corr_dict()
311+
err_corr_dict_numdim = {}
312+
313+
for idim,dim in enumerate(self._obj.dims):
314+
if dim in err_corr_dict.keys():
315+
err_corr_dict_numdim[str(idim)]=err_corr_dict[dim]
316+
317+
return err_corr_dict_numdim
318+
319+
279320
def err_corr_matrix(self) -> xr.DataArray:
280321
"""
281322
Error-correlation matrix for uncertainty effect.

0 commit comments

Comments
 (0)