scipp.DataArray#

class scipp.DataArray#

Named variable with associated coords, masks, and attributes.

__init__(self, data: Variable, coords: Mapping[str, Variable] | Iterable[tuple[str, Variable]] = {}, masks: Mapping[str, Variable] | Iterable[tuple[str, Variable]] = {}, attrs: Mapping[str, Variable] | Iterable[tuple[str, Variable]] = {}, name: str = '') None#

DataArray initializer.

Parameters:
  • data – Data and optionally variances.

  • coords – Coordinates referenced by dimension.

  • masks – Masks referenced by name.

  • attrs – Attributes referenced by dimension.

  • name – Name of the data array.

Methods

__init__(self, data[, coords, masks, attrs, ...])

DataArray initializer.

all([dim])

Logical AND over input values.

any([dim])

Logical OR over input values.

assign_attrs([attrs])

Return new object with updated or inserted attrs.

assign_coords([coords])

Return new object with updated or inserted coordinate.

assign_masks([masks])

Return new object with updated or inserted masks.

astype(self, type, *[, copy])

Converts a Variable or DataArray to a different dtype.

bin([arg_dict, dim])

Create binned data by binning input along all dimensions given by edges.

broadcast(*[, dims, shape, sizes])

Broadcast a Variable or a DataArray.

ceil(*[, out])

Round up to the nearest integer of all values passed in x.

copy(self[, deep])

Return a (by default deep) copy.

deprecated_drop_attrs(*args, **kwargs)

Overloaded function.

drop_attrs(*args)

Drop attrs.

drop_coords(*args, **kwargs)

Overloaded function.

drop_masks(*args, **kwargs)

Overloaded function.

flatten([dims, to])

Flatten multiple dimensions into a single dimension.

floor(*[, out])

Round down to the nearest integer of all values passed in x.

fold(dim, *[, dims, shape, sizes])

Fold a single dimension of a variable or data array into multiple dims.

group(*args[, dim])

Create binned data by grouping input by one or more coordinates.

groupby(group, *[, bins])

Group dataset or data array based on values of specified labels.

hist([arg_dict, dim])

Compute a histogram.

max([dim])

Maximum of elements in the input.

mean([dim])

Arithmetic mean of elements in the input.

median([dim])

Compute the median of the input values.

min([dim])

Minimum of elements in the input.

nanhist([arg_dict, dim])

Compute a histogram, skipping NaN values.

nanmax([dim])

Maximum of elements in the input ignoring NaN's.

nanmean([dim])

Arithmetic mean of elements in the input ignoring NaN's.

nanmedian([dim])

Compute the median of the input values ignoring NaN's.

nanmin([dim])

Minimum of elements in the input ignoring NaN's.

nanstd([dim])

Compute the standard deviation of the input values ignoring NaN's.

nansum([dim])

Sum of elements in the input ignoring NaN's.

nanvar([dim])

Compute the variance of the input values ignoring NaN's.

plot(**kwargs)

Wrapper function to plot data.

rebin([arg_dict])

Rebin a data array or dataset.

rename([dims_dict])

Rename the dimensions, coordinates, and attributes.

rename_dims([dims_dict])

Rename dimensions.

round(*[, out])

Round to the nearest integer of all values passed in x.

save_hdf5(filename)

Write an object out to file in HDF5 format.

squeeze([dim])

Remove dimensions of length 1.

std([dim])

Compute the standard deviation of the input values.

sum([dim])

Sum of elements in the input.

to(*[, unit, dtype, copy])

Converts a Variable or DataArray to a different dtype and/or a different unit.

transform_coords([targets, graph, ...])

Compute new coords based on transformations of input coords.

transpose([dims])

Transpose dimensions of the input.

underlying_size(self)

Return the size of the object in bytes.

var([dim])

Compute the variance of the input values.

Attributes

attrs

Dict of attrs.

bins

Returns helper scipp.Bins allowing bin-wise operations to be performed or None if not binned data.

coords

Dict of coords.

data

Underlying data item.

deprecated_attrs

Dict of attrs.

deprecated_meta

Dict of coords and attrs.

dim

The only dimension label for 1-dimensional data, raising an exception if the data is not 1-dimensional.

dims

Dimension labels of the data (read-only).

dtype

Data type contained in the variable.

masks

Dict of masks.

meta

Dict of coords and attrs.

name

The name of the held data.

ndim

Number of dimensions of the data (read-only).

shape

Shape of the data (read-only).

size

Number of elements in the data (read-only).

sizes

dict mapping dimension labels to dimension sizes (read-only).

unit

Physical unit of the data.

value

The only value for 0-dimensional data, raising an exception if the data is not 0-dimensional.

values

Array of values of the data.

variance

The only variance for 0-dimensional data, raising an exception if the data is not 0-dimensional.

variances

Array of variances of the data.

__getitem__(*args, **kwargs)#

Overloaded function.

  1. __getitem__(self: scipp._scipp.core.DataArray, arg0: int) -> scipp._scipp.core.DataArray

  2. __getitem__(self: scipp._scipp.core.DataArray, arg0: slice) -> scipp._scipp.core.DataArray

  3. __getitem__(self: scipp._scipp.core.DataArray, arg0: scipp._scipp.core.Variable) -> scipp._scipp.core.DataArray

  4. __getitem__(self: scipp._scipp.core.DataArray, arg0: tuple[str, scipp._scipp.core.Variable]) -> scipp._scipp.core.DataArray

  5. __getitem__(self: scipp._scipp.core.DataArray, arg0: tuple[str, int]) -> scipp._scipp.core.DataArray

  6. __getitem__(self: scipp._scipp.core.DataArray, arg0: tuple[str, slice]) -> scipp._scipp.core.DataArray

  7. __getitem__(self: scipp._scipp.core.DataArray, arg0: ellipsis) -> scipp._scipp.core.DataArray

  8. __getitem__(self: scipp._scipp.core.DataArray, arg0: list[int]) -> scipp._scipp.core.DataArray

  9. __getitem__(self: scipp._scipp.core.DataArray, arg0: tuple[str, list[int]]) -> scipp._scipp.core.DataArray

all(dim=None)#

Logical AND over input values.

Seealso:

Details in scipp.all()

Return type:

TypeVar(VariableLikeType, Variable, DataArray, Dataset, DataGroup[Any])

any(dim=None)#

Logical OR over input values.

Seealso:

Details in scipp.any()

Return type:

TypeVar(VariableLikeType, Variable, DataArray, Dataset, DataGroup[Any])

assign_attrs(attrs=None, /, **attrs_kwargs)#

Return new object with updated or inserted attrs.

Parameters:
Returns:

DataArrayscipp.DataArray with updated attributes.

assign_coords(coords=None, /, **coords_kwargs)#

Return new object with updated or inserted coordinate.

Parameters:
Returns:

TypeVar(_T, Dataset, DataArray)scipp.DataArray or scipp.Dataset with updated coordinates.

assign_masks(masks=None, /, **masks_kwargs)#

Return new object with updated or inserted masks.

Parameters:
Returns:

DataArrayscipp.DataArray with updated masks.

astype(self: scipp._scipp.core.DataArray, type: object, *, copy: bool = True) scipp._scipp.core.DataArray#

Converts a Variable or DataArray to a different dtype.

If the dtype is unchanged and copy is False, the object is returned without making a deep copy.

Parameters:
  • type – Target dtype.

  • copy – If False, return the input object if possible. If True, the function always returns a new object.

Raises:

If the data cannot be converted to the requested dtype.

Returns:

New variable or data array with specified dtype.

Return type:

Union[scipp.Variable, scipp.DataArray]

property attrs: Coords#

Dict of attrs.

Deprecated since version 23.9.0: Use coords with unset alignment flag instead, or store attributes in higher-level data structures.

bin(arg_dict=None, /, *, dim=None, **kwargs)#

Create binned data by binning input along all dimensions given by edges.

Seealso:

Details in scipp.bin()

Return type:

DataArray | DataGroup[Any]

property bins: Bins[_O] | None#

Returns helper scipp.Bins allowing bin-wise operations to be performed or None if not binned data.

broadcast(*, dims=None, shape=None, sizes=None)#

Broadcast a Variable or a DataArray.

Seealso:

Details in scipp.broadcast()

Return type:

TypeVar(VariableLikeType, Variable, DataArray, Dataset, DataGroup[Any])

ceil(*, out=None)#

Round up to the nearest integer of all values passed in x.

Seealso:

Details in scipp.ceil()

Return type:

VariableLike

property coords#

Dict of coords.

copy(self: scipp._scipp.core.DataArray, deep: bool = True) scipp._scipp.core.DataArray#

Return a (by default deep) copy.

If deep=True (the default), a deep copy is made. Otherwise, a shallow copy is made, and the returned data (and meta data) values are new views of the data and meta data values of this object.

property data#

Underlying data item.

property deprecated_attrs#

Dict of attrs.

deprecated_drop_attrs(*args, **kwargs)#

Overloaded function.

  1. deprecated_drop_attrs(self: scipp._scipp.core.DataArray, arg0: str) -> scipp._scipp.core.DataArray

  2. deprecated_drop_attrs(self: scipp._scipp.core.DataArray, arg0: list[str]) -> scipp._scipp.core.DataArray

property deprecated_meta#

Dict of coords and attrs.

property dim#

The only dimension label for 1-dimensional data, raising an exception if the data is not 1-dimensional.

property dims#

Dimension labels of the data (read-only).

drop_attrs(*args)#

Drop attrs. :rtype: DataArray

Deprecated since version 23.9.0: Use coords with unset alignment flag instead, or store attributes in higher-level data structures.

drop_coords(*args, **kwargs)#

Overloaded function.

  1. drop_coords(self: scipp._scipp.core.DataArray, arg0: str) -> scipp._scipp.core.DataArray

  2. drop_coords(self: scipp._scipp.core.DataArray, arg0: list[str]) -> scipp._scipp.core.DataArray

drop_masks(*args, **kwargs)#

Overloaded function.

  1. drop_masks(self: scipp._scipp.core.DataArray, arg0: str) -> scipp._scipp.core.DataArray

  2. drop_masks(self: scipp._scipp.core.DataArray, arg0: list[str]) -> scipp._scipp.core.DataArray

property dtype#

Data type contained in the variable.

flatten(dims=None, to=None)#

Flatten multiple dimensions into a single dimension.

Seealso:

Details in scipp.flatten()

Return type:

TypeVar(VariableLikeType, Variable, DataArray, Dataset, DataGroup[Any])

floor(*, out=None)#

Round down to the nearest integer of all values passed in x.

Seealso:

Details in scipp.floor()

Return type:

VariableLike

fold(dim, *, dims=None, shape=None, sizes=None)#

Fold a single dimension of a variable or data array into multiple dims.

Seealso:

Details in scipp.fold()

Return type:

TypeVar(VariableLikeType, Variable, DataArray, Dataset, DataGroup[Any])

group(*args, dim=None)#

Create binned data by grouping input by one or more coordinates.

Seealso:

Details in scipp.group()

Return type:

DataArray | DataGroup[Any]

groupby(group, *, bins=None)#

Group dataset or data array based on values of specified labels.

Seealso:

Details in scipp.groupby()

Return type:

GroupByDataArray | GroupByDataset

hist(arg_dict=None, /, *, dim=None, **kwargs)#

Compute a histogram.

Seealso:

Details in scipp.hist()

Return type:

Variable | DataArray | Dataset | DataGroup[Any]

property masks#

Dict of masks.

max(dim=None)#

Maximum of elements in the input.

Seealso:

Details in scipp.max()

Return type:

TypeVar(VariableLikeType, Variable, DataArray, Dataset, DataGroup[Any])

mean(dim=None)#

Arithmetic mean of elements in the input.

Seealso:

Details in scipp.mean()

Return type:

TypeVar(VariableLikeType, Variable, DataArray, Dataset, DataGroup[Any])

median(dim=None)#

Compute the median of the input values.

Seealso:

Details in scipp.median()

Return type:

TypeVar(VariableLikeType, Variable, DataArray, Dataset, DataGroup[Any])

property meta: Coords#

Dict of coords and attrs.

Deprecated since version 23.9.0: Use coords with unset alignment flag instead, or store attributes in higher-level data structures.

min(dim=None)#

Minimum of elements in the input.

Seealso:

Details in scipp.min()

Return type:

TypeVar(VariableLikeType, Variable, DataArray, Dataset, DataGroup[Any])

property name#

The name of the held data.

nanhist(arg_dict=None, /, *, dim=None, **kwargs)#

Compute a histogram, skipping NaN values.

Seealso:

Details in scipp.nanhist()

Return type:

Variable | DataArray | Dataset | DataGroup[Any]

nanmax(dim=None)#

Maximum of elements in the input ignoring NaN’s.

Seealso:

Details in scipp.nanmax()

Return type:

TypeVar(VariableLikeType, Variable, DataArray, Dataset, DataGroup[Any])

nanmean(dim=None)#

Arithmetic mean of elements in the input ignoring NaN’s.

Seealso:

Details in scipp.nanmean()

Return type:

TypeVar(VariableLikeType, Variable, DataArray, Dataset, DataGroup[Any])

nanmedian(dim=None)#

Compute the median of the input values ignoring NaN’s.

Seealso:

Details in scipp.nanmedian()

Return type:

TypeVar(VariableLikeType, Variable, DataArray, Dataset, DataGroup[Any])

nanmin(dim=None)#

Minimum of elements in the input ignoring NaN’s.

Seealso:

Details in scipp.nanmin()

Return type:

TypeVar(VariableLikeType, Variable, DataArray, Dataset, DataGroup[Any])

nanstd(dim=None, *, ddof)#

Compute the standard deviation of the input values ignoring NaN’s.

Seealso:

Details in scipp.nanstd()

Return type:

TypeVar(VariableLikeType, Variable, DataArray, Dataset, DataGroup[Any])

nansum(dim=None)#

Sum of elements in the input ignoring NaN’s.

Seealso:

Details in scipp.nansum()

Return type:

TypeVar(VariableLikeType, Variable, DataArray, Dataset, DataGroup[Any])

nanvar(dim=None, *, ddof)#

Compute the variance of the input values ignoring NaN’s.

Seealso:

Details in scipp.nanvar()

Return type:

TypeVar(VariableLikeType, Variable, DataArray, Dataset, DataGroup[Any])

property ndim#

Number of dimensions of the data (read-only).

plot(**kwargs)#

Wrapper function to plot data. See https://scipp.github.io/plopp/ for details.

Return type:

Any

rebin(arg_dict=None, /, **kwargs)#

Rebin a data array or dataset.

Seealso:

Details in scipp.rebin()

Return type:

Variable | DataArray | Dataset | DataGroup[Any]

rename(dims_dict=None, /, **names)#

Rename the dimensions, coordinates, and attributes.

The renaming can be defined:

  • using a dict mapping the old to new names, e.g. rename({'x': 'a', 'y': 'b'})

  • using keyword arguments, e.g. rename(x='a', y='b')

In both cases, x is renamed to a and y to b.

Names not specified in either input are unchanged.

Parameters:
  • dims_dict (Optional[dict[str, str]], default: None) – Dictionary mapping old to new names.

  • names (str) – Mapping of old to new names as keyword arguments.

Returns:

DataArray – A new data array with renamed dimensions, coordinates, and attributes. Buffers are shared with the input.

See also

scipp.DataArray.rename_dims

Only rename dimensions, not coordinates and attributes.

rename_dims(dims_dict=None, /, **names)#

Rename dimensions.

The renaming can be defined:

  • using a dict mapping the old to new names, e.g. rename_dims({'x': 'a', 'y': 'b'})

  • using keyword arguments, e.g. rename_dims(x='a', y='b')

In both cases, x is renamed to a and y to b.

Dimensions not specified in either input are unchanged.

This function only renames dimensions. See the rename method to also rename coordinates and attributes.

Parameters:
  • dims_dict (Optional[dict[str, str]], default: None) – Dictionary mapping old to new names.

  • names (str) – Mapping of old to new names as keyword arguments.

Returns:

TypeVar(_T, Variable, DataArray, Dataset) – A new object with renamed dimensions.

round(*, out=None)#

Round to the nearest integer of all values passed in x.

Seealso:

Details in scipp.round()

Return type:

TypeVar(VariableLikeType, Variable, DataArray, Dataset, DataGroup[Any])

save_hdf5(filename)#

Write an object out to file in HDF5 format.

Return type:

None

property shape#

Shape of the data (read-only).

property size#

Number of elements in the data (read-only).

property sizes#

dict mapping dimension labels to dimension sizes (read-only).

squeeze(dim=None)#

Remove dimensions of length 1.

Seealso:

Details in scipp.squeeze()

Return type:

TypeVar(VariableLikeType, Variable, DataArray, Dataset, DataGroup[Any])

std(dim=None, *, ddof)#

Compute the standard deviation of the input values.

Seealso:

Details in scipp.std()

Return type:

TypeVar(VariableLikeType, Variable, DataArray, Dataset, DataGroup[Any])

sum(dim=None)#

Sum of elements in the input.

Seealso:

Details in scipp.sum()

Return type:

TypeVar(VariableLikeType, Variable, DataArray, Dataset, DataGroup[Any])

to(*, unit=None, dtype=None, copy=True)#

Converts a Variable or DataArray to a different dtype and/or a different unit.

If the dtype and unit are both unchanged and copy is False, the object is returned without making a deep copy.

This method will choose whether to do the dtype or units translation first, by using the following rules in order:

  • If either the input or output dtype is float64, the unit translation will be done on the float64 type

  • If either the input or output dtype is float32, the unit translation will be done on the float32 type

  • If both the input and output dtypes are integer types, the unit translation will be done on the larger type

  • In other cases, the dtype is converted first and then the unit translation is done

Parameters:
  • unit (Union[Unit, str, None], default: None) – Target unit. If None, the unit is unchanged.

  • dtype (Optional[Any], default: None) – Target dtype. If None, the dtype is unchanged.

  • copy (bool, default: True) – If False, return the input object if possible. If True, the function always returns a new object.

Returns:

Same as input – New object with specified dtype and unit.

Raises:
transform_coords(targets=None, /, graph=None, *, rename_dims=True, keep_aliases=True, keep_intermediate=True, keep_inputs=True, quiet=False, **kwargs)#

Compute new coords based on transformations of input coords.

Seealso:

Details in scipp.transform_coords()

Return type:

DataArray | Dataset

transpose(dims=None)#

Transpose dimensions of the input.

Seealso:

Details in scipp.transpose()

Return type:

TypeVar(VariableLikeType, Variable, DataArray, Dataset, DataGroup[Any])

underlying_size(self: scipp._scipp.core.DataArray) int#

Return the size of the object in bytes.

The size includes the object itself and all arrays contained in it. But arrays may be counted multiple times if components share buffers, e.g. multiple coordinates referencing the same memory. Conversely, the size may be underestimated. Especially, but not only, with dtype=PyObject.

This function includes all memory of the underlying buffers. Use __sizeof__ to get the size of the current slice only.

property unit#

Physical unit of the data.

property value#

The only value for 0-dimensional data, raising an exception if the data is not 0-dimensional.

property values#

Array of values of the data.

var(dim=None, *, ddof)#

Compute the variance of the input values.

Seealso:

Details in scipp.var()

Return type:

TypeVar(VariableLikeType, Variable, DataArray, Dataset, DataGroup[Any])

property variance#

The only variance for 0-dimensional data, raising an exception if the data is not 0-dimensional.

property variances#

Array of variances of the data.