fourierror.data_array#
A scipp.DataArray subclass that carries a CovDataArray.
- class fourierror.data_array.CovDataArray(data, coords=None, masks=None, name='', covariance=None)#
Bases:
DataArrayA
scipp.DataArraywhose data carries a full covariance matrix.- Parameters:
data (
Variable) – The data. ACovVariablesupplies its own covariance; a plainVariableis taken as uncorrelated unlesscovarianceis given.coords (
Mapping[str,Variable] |None) – As forscipp.DataArray.masks (
Mapping[str,Variable] |None) – As forscipp.DataArray.name (
str) – As forscipp.DataArray.covariance (
Any) – Covariance matrix, overriding one carried bydata.
Examples
>>> import numpy as np >>> import scipp as sc >>> from fourierror.variable import covariance_array >>> cv = covariance_array( ... dims=['x'], values=[1.0, 2.0], covariance=[[0.04, 0.02], [0.02, 0.09]] ... ) >>> da = CovDataArray(data=cv, coords={'x': sc.arange('x', 2.0)}) >>> type(da.data).__name__ 'CovVariable' >>> round(float(da.sum('x').data.variance), 12) 0.17
Notes
.datarebuilds theCovVariableon each access, which copies theN x Ncovariance. Bind it to a local name in hot loops.- classmethod from_data_array(da, covariance=None)#
Build from a plain
DataArray, assuming no correlation by default.- Return type:
- to_data_array()#
Drop the correlations, returning a plain
DataArray.The variances of the result are the diagonal of the covariance, so marginal uncertainties are preserved.
- Return type:
- property data: CovVariable#
The data, as a
CovVariable.- Setter accepts:
- property covariance: Variable#
The full covariance matrix of the data, i.e.
self.data.covariance.A copy, for the same reason as
CovVariable.covariance: writing through the accessor would otherwise mutate internal state and leave the C++-side variances stale, with no error.- Setter accepts:
Any
- __add__(other)#
Return
self + other, propagating the covariance.- Return type:
- __radd__(other)#
Return
other + self, propagating the covariance.- Return type:
- __sub__(other)#
Return
self - other, propagating the covariance.- Return type:
- __rsub__(other)#
Return
other - self, propagating the covariance.- Return type:
- __mul__(other)#
Return
self * other, propagating the covariance.- Return type:
- __rmul__(other)#
Return
other * self, propagating the covariance.- Return type:
- __truediv__(other)#
Return
self / other, propagating the covariance.- Return type:
- __rtruediv__(other)#
Return
other / self, propagating the covariance.- Return type:
- __neg__()#
Return
-self; the covariance is unchanged.- Return type:
- __abs__()#
Return
abs(self), propagating the covariance.- Return type:
- __pow__(other)#
Return
self ** otherfor an exact exponent, propagating the covariance.- Return type:
- sum(dim=None)#
Sum over
dim(all dims ifNone), including off-diagonal terms.- Parameters:
dim (
Any) – Dimension, or dimensions, to sum over.- Return type:
- Returns:
The sum, with the covariance of the summed elements.
- mean(dim=None)#
Mean over
dim(all dims ifNone), including off-diagonal terms.- Parameters:
dim (
Any) – Dimension, or dimensions, to average over.- Return type:
- Returns:
The mean, with the covariance of the averaged elements.
- __getitem__(key)#
Slice, selecting the same elements on both covariance axes.
The selected positions are found by slicing a probe array of flat indices with the same key, so positional, label-based and boolean indexing all stay consistent with the base class.
- Return type:
- transpose(dims=None)#
Transpose to
dims, reordering both axes of the covariance.- Parameters:
dims (
Sequence[str] |None) – The new dimension order; reversed ifNone.- Return type:
- to(**kwargs)#
Convert unit and/or dtype, scaling the covariance accordingly.
- Parameters:
**kwargs (
Any) – Passed toscipp.DataArray.to.- Return type:
- copy(deep=True)#
Return a copy of the data array and its covariance.
- Parameters:
deep (
bool) – Whether to copy the underlying buffers.- Return type:
- fourierror.data_array.covariance_data_array(self, data, coords=None, masks=None, name='', covariance=None)#
Create the data array; see the class docstring for the parameters.
- Return type:
None