scipp.rebin#
- scipp.rebin(x, arg_dict=None, /, **kwargs)#
Rebin a data array or dataset.
The coordinate of the input for the dimension to be rebinned must contain bin edges, i.e., the data must be histogrammed.
If the input has masks that contain the dimension being rebinned then those masks are applied to the data before rebinning. That is, masked values are treated as zero.
- Parameters:
x (
Variable
|DataArray
|Dataset
|DataGroup
[Any
]) – Data to rebin.arg_dict (
Optional
[dict
[str
,SupportsIndex
|Variable
]], default:None
) – Dictionary mapping dimension labels to binning parameters.**kwargs (
SupportsIndex
|Variable
) – Mapping of dimension label to corresponding binning parameters.
- Returns:
Variable
|DataArray
|Dataset
|DataGroup
[Any
] – Data rebinned according to the new bin edges.
See also
scipp.bin
For changing the binning of binned (as opposed to dense, histogrammed) data.
scipp.hist
For histogramming data.
Examples
Rebin a data array along one of its dimensions, specifying (1) number of bins, (2) bin width, or (3) actual binning:
>>> from numpy.random import default_rng >>> rng = default_rng(seed=1234) >>> x = sc.array(dims=['row'], unit='m', values=rng.random(100)) >>> y = sc.array(dims=['row'], unit='m', values=rng.random(100)) >>> data = sc.ones(dims=['row'], unit='K', shape=[100]) >>> table = sc.DataArray(data=data, coords={'x': x, 'y': y}) >>> da = table.hist(x=100, y=100) >>> da.rebin(x=2).sizes {'x': 2, 'y': 100}
>>> da.rebin(x=sc.scalar(0.2, unit='m')).sizes {'x': 5, 'y': 100}
>>> da.rebin(x=sc.linspace('x', 0.2, 0.8, num=10, unit='m')).sizes {'x': 9, 'y': 100}
Rebin a data array along two of its dimensions:
>>> da = table.hist(x=100, y=100) >>> da.rebin(x=4, y=6).sizes {'x': 4, 'y': 6}