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: DataArray

A scipp.DataArray whose data carries a full covariance matrix.

Parameters:
  • data (Variable) – The data. A CovVariable supplies its own covariance; a plain Variable is taken as uncorrelated unless covariance is given.

  • coords (Mapping[str, Variable] | None) – As for scipp.DataArray.

  • masks (Mapping[str, Variable] | None) – As for scipp.DataArray.

  • name (str) – As for scipp.DataArray.

  • covariance (Any) – Covariance matrix, overriding one carried by data.

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

.data rebuilds the CovVariable on each access, which copies the N x N covariance. 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:

CovDataArray

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:

DataArray

property data: CovVariable#

The data, as a CovVariable.

Setter accepts:

Variable

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

property correlation: Variable#

The correlation matrix of the data.

__add__(other)#

Return self + other, propagating the covariance.

Return type:

CovDataArray

__radd__(other)#

Return other + self, propagating the covariance.

Return type:

CovDataArray

__sub__(other)#

Return self - other, propagating the covariance.

Return type:

CovDataArray

__rsub__(other)#

Return other - self, propagating the covariance.

Return type:

CovDataArray

__mul__(other)#

Return self * other, propagating the covariance.

Return type:

CovDataArray

__rmul__(other)#

Return other * self, propagating the covariance.

Return type:

CovDataArray

__truediv__(other)#

Return self / other, propagating the covariance.

Return type:

CovDataArray

__rtruediv__(other)#

Return other / self, propagating the covariance.

Return type:

CovDataArray

__neg__()#

Return -self; the covariance is unchanged.

Return type:

CovDataArray

__abs__()#

Return abs(self), propagating the covariance.

Return type:

CovDataArray

__pow__(other)#

Return self ** other for an exact exponent, propagating the covariance.

Return type:

CovDataArray

sum(dim=None)#

Sum over dim (all dims if None), including off-diagonal terms.

Parameters:

dim (Any) – Dimension, or dimensions, to sum over.

Return type:

CovDataArray

Returns:

The sum, with the covariance of the summed elements.

mean(dim=None)#

Mean over dim (all dims if None), including off-diagonal terms.

Parameters:

dim (Any) – Dimension, or dimensions, to average over.

Return type:

CovDataArray

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:

CovDataArray

transpose(dims=None)#

Transpose to dims, reordering both axes of the covariance.

Parameters:

dims (Sequence[str] | None) – The new dimension order; reversed if None.

Return type:

CovDataArray

to(**kwargs)#

Convert unit and/or dtype, scaling the covariance accordingly.

Parameters:

**kwargs (Any) – Passed to scipp.DataArray.to.

Return type:

CovDataArray

copy(deep=True)#

Return a copy of the data array and its covariance.

Parameters:

deep (bool) – Whether to copy the underlying buffers.

Return type:

CovDataArray

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