scipp.Bins#

class scipp.Bins(obj)#

Proxy for access to bin contents and operations on bins of a variable.

This class is returned from the bins property of variables and should generally not be created directly.

Bins is generic over the parent type, not the event type. That is, Variable.bins always returns Bins[Variable] regardless of whether the event list is a variable or data array.

__init__(obj)#

Methods

__init__(obj)

all()

Logical AND of events in each bin ignoring NaN's.

any()

Logical OR of events in each bin ignoring NaN's.

concat([dim])

Concatenate bins element-wise by concatenating bin contents along their internal bin dimension.

concatenate(other, *[, out])

Concatenate bins element-wise by concatenating bin contents along their internal bin dimension.

drop_coords(coords)

Drop coords from bin content

drop_masks(masks)

Drop masks from bin content

max()

Maximum of events in each bin.

mean()

Arithmetic mean of events in each bin.

min()

Minimum of events in each bin.

nanmax()

Maximum of events in each bin ignoring NaN's.

nanmean()

Arithmetic mean of events in each bin ignoring NaN's.

nanmin()

Minimum of events in each bin ignoring NaN's.

nansum()

Sum of events in each bin ignoring NaN's.

size()

Number of events or elements in a bin.

sum()

Sum of events in each bin.

Attributes

aligned

Alignment flag for coordinates of bin elements.

attrs

Attrs of the bins

constituents

Constituents of binned data, as supported by sc.bins().

coords

Coords of the bins

data

Data of the bins

deprecated_attrs

deprecated_meta

dtype

Data type of the bin elements.

masks

Masks of the bins

meta

Coords and attrs of the bins

unit

Unit of the bin elements

__getitem__(key)#

Extract events from bins based on labels or label ranges and return a copy.

This is similar to regular label-based indexing, but considers the event-coords, i.e., the coord values of individual bin entries. Unlike normal label-based indexing this returns a copy, as a subset of events is extracted.

Return type:

DataArray

property aligned: bool#

Alignment flag for coordinates of bin elements.

all()#

Logical AND of events in each bin ignoring NaN’s.

Returns:

TypeVar(_O, Variable, DataArray, Dataset) – The AND of each of the input bins without NaN’s.

See also

scipp.all

For performing an AND of non-bin data or across bins.

any()#

Logical OR of events in each bin ignoring NaN’s.

Returns:

TypeVar(_O, Variable, DataArray, Dataset) – The OR of each of the input bins without NaN’s.

See also

scipp.all

For performing an OR of non-bin data or across bins.

property attrs: MetaDataMap#

Attrs of the bins

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

concat(dim=None)#

Concatenate bins element-wise by concatenating bin contents along their internal bin dimension.

This is a reduction operation similar to scipp.sum() but operates on binned data. Elements (bins) are concatenated along their internal dimension.

Parameters:

dim (Union[str, Sequence[str], None], default: None) – Reduction dimension.

Returns:

TypeVar(_O, Variable, DataArray, Dataset) – All bins along dim concatenated into a single bin.

concatenate(other, *, out=None)#

Concatenate bins element-wise by concatenating bin contents along their internal bin dimension.

The bins to concatenate are obtained element-wise from self and other.

Parameters:
Returns:

Variable | DataArray – The bins of the two inputs merged.

Raises:

scipp.DTypeError – If other is not binned data.

property constituents: Constituents#

Constituents of binned data, as supported by sc.bins().

property coords: MetaDataMap#

Coords of the bins

property data: Variable#

Data of the bins

drop_coords(coords)#

Drop coords from bin content

Return type:

TypeVar(_O, Variable, DataArray, Dataset)

drop_masks(masks)#

Drop masks from bin content

Return type:

TypeVar(_O, Variable, DataArray, Dataset)

property dtype: DType#

Data type of the bin elements.

property masks: MetaDataMap#

Masks of the bins

max()#

Maximum of events in each bin.

Returns:

TypeVar(_O, Variable, DataArray, Dataset) – The maximum of each of the input bins.

See also

scipp.max

For calculating the maximum of non-bin data or across bins.

mean()#

Arithmetic mean of events in each bin.

Returns:

TypeVar(_O, Variable, DataArray, Dataset) – The mean of each of the input bins.

See also

scipp.mean

For calculating the mean of non-bin data or across bins.

property meta: MetaDataMap#

Coords and attrs of the bins

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

min()#

Minimum of events in each bin.

Returns:

TypeVar(_O, Variable, DataArray, Dataset) – The minimum of each of the input bins.

See also

scipp.min

For calculating the minimum of non-bin data or across bins.

nanmax()#

Maximum of events in each bin ignoring NaN’s.

Returns:

TypeVar(_O, Variable, DataArray, Dataset) – The maximum of each of the input bins without NaN’s.

See also

scipp.nanmax

For calculating the maximum of non-bin data or across bins.

nanmean()#

Arithmetic mean of events in each bin ignoring NaN’s.

Returns:

TypeVar(_O, Variable, DataArray, Dataset) – The mean of each of the input bins without NaN’s.

See also

scipp.nanmean

For calculating the mean of non-bin data or across bins.

nanmin()#

Minimum of events in each bin ignoring NaN’s.

Returns:

TypeVar(_O, Variable, DataArray, Dataset) – The minimum of each of the input bins without NaN’s.

See also

scipp.nanmin

For calculating the minimum of non-bin data or across bins.

nansum()#

Sum of events in each bin ignoring NaN’s.

Returns:

TypeVar(_O, Variable, DataArray, Dataset) – The sum of each of the input bins without NaN’s.

See also

scipp.nansum

For summing non-bin data or summing bins.

size()#

Number of events or elements in a bin.

Returns:

Variable – The number of elements in each of the input bins.

sum()#

Sum of events in each bin.

Returns:

TypeVar(_O, Variable, DataArray, Dataset) – The sum of each of the input bins.

See also

scipp.sum

For summing non-bin data or summing bins.

property unit: Unit | None#

Unit of the bin elements