What’s new in scipp
Contents
What’s new in scipp#
This page highlights feature additions and discusses major changes from recent releases. For a full list of changes see the Release Notes.
[1]:
import numpy as np
import scipp as sc
General#
String formatting#
New in 0.15
Added support for compact formatting of 0-D variables.
Example:
[2]:
var = sc.scalar(12.5, variance=4.0, unit='mm')
print(f'{var}')
print(f'{var:c}')
<scipp.Variable> () float64 [mm] [12.5] [4]
12(2) mm
Implicit conversion to boolean#
New in 0.15
Added support for implicit conversion of 0-D variables to bool.
Examples:
[3]:
if sc.scalar(1, unit='m') < sc.scalar(2, unit='m'):
print('ok')
var = sc.array(values=[1, 2, 3, 4, 5], dims=['x'], unit='m')
if sc.any(var == sc.scalar(3, unit='m')):
print('ok')
ok
ok
Keyword-argument syntax for rename_dims
#
New in 0.15
Added support for keyword arguments in rename_dims
to define dimensions, as also supported by rename
.
Example:
[4]:
var = sc.ones(dims=['x', 'y'], shape=(4, 3))
var.rename_dims(x='xnew', y='ynew')
[4]:
- (xnew: 4, ynew: 3)float64𝟙1.0, 1.0, ..., 1.0, 1.0
Values:
array([[1., 1., 1.], [1., 1., 1.], [1., 1., 1.], [1., 1., 1.]])
Unique dimensions and slicing of 1-D objects#
New in 0.9
The new dim
property checks whether an object is 1-D, and returns the only dimension label. An exception is raised if the object is not 1-D.
Example:
[5]:
x = sc.linspace(dim='x', start=0, stop=1, num=4)
x.dim
[5]:
'x'
New in 0.11
1-D objects can now be sliced without specifying a dimension.
Example:
[6]:
x[-1]
[6]:
- ()float64𝟙1.0
Values:
array(1.)
If an object is not 1-D then DimensionError
is raised:
[7]:
var2d = sc.concat([x, x], 'y')
var2d[0]
---------------------------------------------------------------------------
DimensionError Traceback (most recent call last)
Input In [7], in <cell line: 2>()
1 var2d = sc.concat([x, x], 'y')
----> 2 var2d[0]
DimensionError: Slicing with implicit dimension label is only possible for 1-D objects. Got Sizes[y:2, x:4, ] with ndim=2. Provide an explicit dimension label, e.g., var['y', 0] instead of var[0].
Slicing with stride#
New in 0.12
Positional slicing (slicing with integer indices, as opposed to slicing with a label matching a coordinate value) now supports strides.
Negative strides are currently not supported.
Examples:
[8]:
y = sc.arange('y', 10)
y[::2]
[8]:
- (y: 5)int64𝟙0, 2, 4, 6, 8
Values:
array([0, 2, 4, 6, 8])
[9]:
x = sc.linspace('x', 0.0, 1.0, num=5)
da = sc.DataArray(
sc.ones(dims=['x', 'y'], shape=[4, 10], unit='K'), coords={'x': x, 'y': y}
)
da['y', 1::2]
[9]:
- x: 4
- y: 5
- x(x [bin-edge])float64𝟙0.0, 0.25, 0.5, 0.75, 1.0
Values:
array([0. , 0.25, 0.5 , 0.75, 1. ]) - y(y)int64𝟙1, 3, 5, 7, 9
Values:
array([1, 3, 5, 7, 9])
- (x, y)float64K1.0, 1.0, ..., 1.0, 1.0
Values:
array([[1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.]])
Slicing a dimension with a bin-edge coordinate with a stride is ill-defined and not supported:
[10]:
da['x', ::2]
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
Input In [10], in <cell line: 1>()
----> 1 da['x', ::2]
IndexError: Object has bin-edges along dimension x so slicing with stride 2 != 1 is not valid.
Slicing: Advanced indexing support with integer array or boolean variable#
New in 0.13
Added support for indexing with an integer array.
Added support for indexing with a boolean variable.
The Slicing documentation provides details and examples.
Units#
Unified conversion of unit and dtype#
New in 0.11
Variables and data arrays have a new method, to
, for conversion of dtype, unit, or both. This can be used to replace uses of to_unit
and astype
.
Example:
[11]:
var = sc.arange(dim='x', start=0, stop=4, unit='m')
var
[11]:
- (x: 4)int64m0, 1, 2, 3
Values:
array([0, 1, 2, 3])
Use the unit
keyword argument to convert to a different unit:
[12]:
var.to(unit='mm')
[12]:
- (x: 4)int64mm0, 1000, 2000, 3000
Values:
array([ 0, 1000, 2000, 3000])
Use the dtype
keyword argument to convert to a different dtype:
[13]:
var.to(dtype='float64')
[13]:
- (x: 4)float64m0.0, 1.0, 2.0, 3.0
Values:
array([0., 1., 2., 3.])
If both unit
and dtype
are provided, the implementation attempts to apply the two conversions in optimal order to reduce or avoid the effect of rounding/truncation errors:
[14]:
var.to(dtype='float64', unit='km')
[14]:
- (x: 4)float64km0.0, 0.001, 0.002, 0.003
Values:
array([0. , 0.001, 0.002, 0.003])
Support for unit=None
#
New in 0.12
Previously scipp used unit=sc.units.dimensionless
(or the alias unit=sc.units.one
) for anything that does not have a unit, such as strings, booleans, or bins. To allow for distinction of actual physically dimensionless quantities from these cases, scipp now supports variables and, by extension, data arrays that have their unit set to None
.
This change is accompanied by a number of related changes:
Creation function use a default unit if not given explicitly. The default for numbers (floating point or integer) is
sc.units.dimensionless
. The default for everything else, includingbool
isNone
.Comparison operations, which return variables with
dtype=bool
, haveunit=None
.A new function
index
was added, to allow for creation of 0-D variable withunit=None
. This complementsscalar
, which uses the default unit (depending on thedtype
).
Examples:
[15]:
print(sc.array(dims=['x'], values=[1.1, 2.2, 3.3]))
print(sc.array(dims=['x'], values=[1, 2, 3]))
print(sc.array(dims=['x'], values=[False, True, False]))
print(sc.array(dims=['x'], values=['a', 'b', 'c']))
<scipp.Variable> (x: 3) float64 [dimensionless] [1.1, 2.2, 3.3]
<scipp.Variable> (x: 3) int64 [dimensionless] [1, 2, 3]
<scipp.Variable> (x: 3) bool <no unit> [False, True, False]
<scipp.Variable> (x: 3) string <no unit> ["a", "b", "c"]
[16]:
a = sc.array(dims=['x'], values=[1, 2, 3])
b = sc.array(dims=['x'], values=[1, 3, 3])
print(a == b)
print(a < b)
<scipp.Variable> (x: 3) bool <no unit> [True, False, True]
<scipp.Variable> (x: 3) bool <no unit> [False, True, False]
[17]:
(a == b).unit is None
[17]:
True
For some purposes we may use a coordinate with unique integer-valued identifiers. Since the identifiers to not have a physical meaning, we use unit=None
. Note that this has to be given explicitly since otherwise integers are treated as numbers, i.e., the unit would be dimensionless:
[18]:
da = sc.DataArray(
a, coords={'id': sc.array(dims=['x'], unit=None, values=[34, 21, 14])}
)
da
[18]:
- x: 3
- id(x)int6434, 21, 14
Values:
array([34, 21, 14])
- (x)int64𝟙1, 2, 3
Values:
array([1, 2, 3])
The index
function can now be used to conveniently lookup data by its identifier:
[19]:
da['id', sc.index(21)]
[19]:
- ()int64𝟙2
Values:
array(2)
- id()int6421
Values:
array(21)
Reduced effect of rounding errors when converting units#
New in 0.14
sc.to_unit
(and therefore also the to()
method) now avoid rounding errors when converting from a large unit to a small unit, if the conversion factor is integral.
Example:
[20]:
sc.scalar(1.0, unit='m').to(unit='nm')
[20]:
- ()float64nm1000000000.0
Values:
array(1.e+09)
Checking if coordinates are bin-edges#
New in 0.13
The coords
property (and also the attrs
, meta
, and masks
properties) now provide the is_edges
method to check if an entry is a bin-edge coordinate.
Example:
[21]:
import scipp as sc
x = sc.arange('x', 3)
da = sc.DataArray(x, coords={'x1': x, 'x2': sc.arange('x', 4)})
print(f"{da.coords.is_edges('x1') = }")
print(f"{da.coords.is_edges('x2') = }")
da.coords.is_edges('x1') = False
da.coords.is_edges('x2') = True
Coordinate transformations#
New in 0.15
Several improvements for transform_coords
:
Support a keyword-syntax for defining single-step transformations.
Now works with
lookup
(see below).Now works with callables other than functions, such as the output of
partial
(not with keyword arguments) or instances of classes defining__call__
.
Examples:
[22]:
da = sc.data.table_xyz(nrow=10)
da.transform_coords(xy=lambda x, y: x * y)
[22]:
- row: 10
- xy(row)float64m^20.431, 0.232, ..., 0.166, 0.229
Values:
array([0.43073058, 0.23187028, 0.79733511, 0.22603884, 0.21535264, 0.07792538, 0.17788141, 0.0709546 , 0.16588544, 0.22948474]) - z(row)float64m0.060, 0.684, ..., 0.003, 0.251
Values:
array([0.06013866, 0.68368891, 0.67123802, 0.61101798, 0.06013731, 0.97776927, 0.43895163, 0.53259502, 0.00313229, 0.25126711])
- (row)float64K1.086, 1.043, ..., 1.009, 1.047
Values:
array([1.08584904, 1.04252984, 1.0735819 , 1.09220432, 1.01534742, 1.09922592, 1.01823318, 1.09401129, 1.00868831, 1.04682107])
- x(row)float64m0.977, 0.380, ..., 0.964, 0.264
Values:
array([0.97669977, 0.38019574, 0.92324623, 0.26169242, 0.31909706, 0.11809123, 0.24176629, 0.31853393, 0.96407925, 0.2636498 ]) - y(row)float64m0.441, 0.610, ..., 0.172, 0.870
Values:
array([0.44100612, 0.60987081, 0.8636213 , 0.86375767, 0.67488131, 0.65987435, 0.7357577 , 0.22275366, 0.17206618, 0.87041497])
[23]:
from functools import partial
def linear(a, b, x):
return a * x + b
func = partial(linear, 0.5, sc.scalar(10.0, unit='m'))
da.transform_coords(fx=func)
[23]:
- row: 10
- fx(row)float64m10.488, 10.190, ..., 10.482, 10.132
Values:
array([10.48834988, 10.19009787, 10.46162312, 10.13084621, 10.15954853, 10.05904562, 10.12088315, 10.15926696, 10.48203962, 10.1318249 ]) - y(row)float64m0.441, 0.610, ..., 0.172, 0.870
Values:
array([0.44100612, 0.60987081, 0.8636213 , 0.86375767, 0.67488131, 0.65987435, 0.7357577 , 0.22275366, 0.17206618, 0.87041497]) - z(row)float64m0.060, 0.684, ..., 0.003, 0.251
Values:
array([0.06013866, 0.68368891, 0.67123802, 0.61101798, 0.06013731, 0.97776927, 0.43895163, 0.53259502, 0.00313229, 0.25126711])
- (row)float64K1.086, 1.043, ..., 1.009, 1.047
Values:
array([1.08584904, 1.04252984, 1.0735819 , 1.09220432, 1.01534742, 1.09922592, 1.01823318, 1.09401129, 1.00868831, 1.04682107])
- x(row)float64m0.977, 0.380, ..., 0.964, 0.264
Values:
array([0.97669977, 0.38019574, 0.92324623, 0.26169242, 0.31909706, 0.11809123, 0.24176629, 0.31853393, 0.96407925, 0.2636498 ])
Operations#
Creation functions#
New in 0.11
Creation functions for datetimes where added:
Added
epoch
,datetime
anddatetimes
.
[24]:
sc.datetime('now', unit='ms')
[24]:
- ()datetime64ms2022-08-24T05:52:00.000
Values:
array('2022-08-24T05:52:00.000', dtype='datetime64[ms]')
[25]:
times = sc.datetimes(
dims=['time'], values=['2022-01-11T10:24:03', '2022-01-11T10:24:03']
)
times
[25]:
- (time: 2)datetime64s2022-01-11T10:24:03, 2022-01-11T10:24:03
Values:
array(['2022-01-11T10:24:03', '2022-01-11T10:24:03'], dtype='datetime64[s]')
The new epoch
function is useful for obtaining the time since epoch, i.e., a time difference (dtype='int64'
) instead of a time point (dtype='datetime64'
):
[26]:
times - sc.epoch(unit=times.unit)
[26]:
- (time: 2)int64s1641896643, 1641896643
Values:
array([1641896643, 1641896643])
New in 0.12
zeros_like
, ones_like
, empty_like
, and full_like
can now be used with data arrays.
Example:
[27]:
x = sc.linspace('x', 0.0, 1.0, num=5)
da = sc.DataArray(sc.ones(dims=['x', 'y'], shape=[4, 6], unit='K'), coords={'x': x})
sc.zeros_like(da)
[27]:
- x: 4
- y: 6
- x(x [bin-edge])float64𝟙0.0, 0.25, 0.5, 0.75, 1.0
Values:
array([0. , 0.25, 0.5 , 0.75, 1. ])
- (x, y)float64K0.0, 0.0, ..., 0.0, 0.0
Values:
array([[0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0.]])
Utility methods and functions#
New in 0.12
Added
squeeze
method to remove length-1 dimensions from objects.Added
rename
method to rename dimensions and associated dimension-coordinates (or attributes). This complementsrename_dims
, which only changes dimension labels but does not rename coordinates.Added
midpoints
to compute bin-centers.
Example:
[28]:
x = sc.linspace('x', 0.0, 1.0, num=5)
da = sc.DataArray(sc.ones(dims=['x', 'y'], shape=[4, 6], unit='K'), coords={'x': x})
A length-1 x-dimension…
[29]:
da['x', 0:1]
[29]:
- x: 1
- y: 6
- x(x [bin-edge])float64𝟙0.0, 0.25
Values:
array([0. , 0.25])
- (x, y)float64K1.0, 1.0, ..., 1.0, 1.0
Values:
array([[1., 1., 1., 1., 1., 1.]])
… can be removed with squeeze
:
[30]:
da['x', 0:1].squeeze()
[30]:
- y: 6
- (y)float64K1.0, 1.0, ..., 1.0, 1.0
Values:
array([1., 1., 1., 1., 1., 1.])
- x(x)float64𝟙0.0, 0.25
Values:
array([0. , 0.25])
squeeze
returns a new object and leaves the original unchanged.
Renaming is most convenient using keyword arguments:
[31]:
da.rename(x='xnew')
[31]:
- xnew: 4
- y: 6
- xnew(xnew [bin-edge])float64𝟙0.0, 0.25, 0.5, 0.75, 1.0
Values:
array([0. , 0.25, 0.5 , 0.75, 1. ])
- (xnew, y)float64K1.0, 1.0, ..., 1.0, 1.0
Values:
array([[1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1.]])
rename
returns a new object and leaves the original unchanged.
midpoints
can be used to replace a bin-edge coordinate by bin centers:
[32]:
da.coords['x'] = sc.midpoints(da.coords['x'])
da
[32]:
- x: 4
- y: 6
- x(x)float64𝟙0.125, 0.375, 0.625, 0.875
Values:
array([0.125, 0.375, 0.625, 0.875])
- (x, y)float64K1.0, 1.0, ..., 1.0, 1.0
Values:
array([[1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1.]])
Binning and histogramming operations#
Reworked API for better user experience#
New in 0.15
Simpler interface for binning and histogramming operations:
sc.bin
moved tosc.binning.make_binned
.Most users should use
sc.bin
orsc.group
(see below for new interface).
sc.histogram
moved tosc.binning.make_histogrammed
.Most users should use
sc.hist
(see below for new interface).
bin
,group
,hist
, andrebin
are now available as methods (in addition to free functions).bin
andhist
can be provided with one of:Bin count.
Bin size.
Bin edges.
Examples, given a table:
[33]:
table = sc.data.table_xyz(nrow=100)
table.coords['label'] = (table.coords['x'] * 10).to(dtype='int32')
table
[33]:
- row: 100
- label(row)int32m9, 3, ..., 9, 0
Values:
array([9, 3, 9, 2, 3, 1, 2, 3, 9, 2, 4, 6, 8, 8, 6, 6, 7, 2, 1, 8, 0, 6, 6, 6, 0, 9, 4, 5, 0, 2, 8, 4, 7, 9, 1, 9, 1, 9, 0, 4, 8, 2, 8, 9, 8, 4, 3, 4, 0, 2, 5, 7, 4, 3, 9, 7, 4, 4, 7, 8, 2, 7, 8, 8, 0, 5, 6, 2, 4, 5, 9, 0, 2, 2, 3, 0, 3, 1, 8, 6, 0, 2, 6, 1, 9, 1, 7, 4, 3, 2, 8, 3, 0, 0, 4, 8, 3, 8, 9, 0], dtype=int32) - x(row)float64m0.977, 0.380, ..., 0.947, 0.067
Values:
array([0.97669977, 0.38019574, 0.92324623, 0.26169242, 0.31909706, 0.11809123, 0.24176629, 0.31853393, 0.96407925, 0.2636498 , 0.44100612, 0.60987081, 0.8636213 , 0.86375767, 0.67488131, 0.65987435, 0.7357577 , 0.22275366, 0.17206618, 0.87041497, 0.06013866, 0.68368891, 0.67123802, 0.61101798, 0.06013731, 0.97776927, 0.43895163, 0.53259502, 0.00313229, 0.25126711, 0.85849044, 0.42529835, 0.73581899, 0.92204322, 0.15347417, 0.99225923, 0.18233178, 0.9401129 , 0.08688306, 0.46821072, 0.8289892 , 0.28105226, 0.86909151, 0.97641657, 0.84171366, 0.4488736 , 0.37050843, 0.48266944, 0.09218155, 0.22668311, 0.53656624, 0.73323165, 0.44891079, 0.30550077, 0.9473596 , 0.75103384, 0.47204846, 0.45727588, 0.7463378 , 0.85539988, 0.29350156, 0.7333145 , 0.8088307 , 0.88708697, 0.02483321, 0.51254945, 0.61278568, 0.28034895, 0.45213173, 0.53122109, 0.98863456, 0.00597817, 0.20128829, 0.2568758 , 0.34074484, 0.05300196, 0.3264945 , 0.19835821, 0.82921491, 0.63712163, 0.08544074, 0.22016044, 0.68117601, 0.13441009, 0.95651369, 0.13652398, 0.79770214, 0.49829352, 0.30470773, 0.23420605, 0.89300817, 0.3775365 , 0.07634545, 0.03380685, 0.46161332, 0.87382396, 0.35060949, 0.82352055, 0.94719907, 0.06704071]) - y(row)float64m0.298, 0.619, ..., 0.942, 0.266
Values:
array([0.29784009, 0.61916102, 0.30175743, 0.17484645, 0.4955052 , 0.7605704 , 0.68726158, 0.24815478, 0.62204659, 0.31565569, 0.27721642, 0.92986521, 0.27959527, 0.94883502, 0.20201735, 0.56547841, 0.38030313, 0.80810673, 0.12755367, 0.95133955, 0.72882736, 0.175545 , 0.69275909, 0.09283302, 0.55640157, 0.10249413, 0.04369324, 0.39269051, 0.69105406, 0.72697743, 0.6690316 , 0.59155473, 0.87900055, 0.53765765, 0.0978224 , 0.14129582, 0.96228009, 0.7981039 , 0.00675377, 0.94581154, 0.65542259, 0.91068457, 0.15258466, 0.58863232, 0.5037656 , 0.17380898, 0.0628503 , 0.66454833, 0.03190526, 0.2381556 , 0.51542965, 0.60235782, 0.28295953, 0.84313 , 0.89470557, 0.72319123, 0.92654142, 0.05899723, 0.05014746, 0.12388012, 0.12208044, 0.53115015, 0.91313804, 0.18246727, 0.99149871, 0.87990489, 0.32295563, 0.19131571, 0.49686643, 0.31440532, 0.03030466, 0.09262352, 0.58902035, 0.63403838, 0.96634448, 0.01487968, 0.73315998, 0.63286286, 0.50168492, 0.12093655, 0.85794039, 0.70241087, 0.56861403, 0.98109921, 0.0903527 , 0.72707977, 0.4886337 , 0.28049914, 0.88533027, 0.80772818, 0.43944917, 0.64164812, 0.63103906, 0.00843672, 0.22165835, 0.21689278, 0.22026903, 0.74113721, 0.94155401, 0.2664373 ]) - z(row)float64m0.747, 0.002, ..., 0.314, 0.264
Values:
array([7.47273308e-01, 2.07107674e-03, 8.09356321e-01, 8.06808892e-01, 5.45326666e-02, 9.89362828e-02, 5.53226569e-01, 7.62910553e-01, 7.30931237e-01, 6.82471044e-01, 7.62591309e-01, 5.99412526e-01, 2.35477373e-01, 2.80612918e-02, 9.11675838e-01, 4.14080600e-01, 7.23464080e-01, 2.65950874e-01, 9.80369577e-01, 1.78090002e-01, 4.69184186e-02, 4.94115808e-01, 3.70529117e-01, 6.55574256e-01, 4.61285877e-05, 1.43014725e-01, 8.58975880e-01, 6.82809970e-01, 3.32033306e-01, 2.48161990e-02, 4.22029167e-02, 3.89582513e-01, 9.43011313e-01, 9.18612070e-01, 3.14726967e-01, 3.72220959e-01, 2.66749743e-01, 1.41873954e-01, 5.91518522e-01, 4.63079614e-01, 8.35330328e-01, 4.95433949e-01, 1.77145233e-02, 4.37894709e-01, 1.34038413e-01, 3.32400970e-01, 5.01302700e-01, 5.43368711e-01, 6.94848901e-01, 9.64195746e-01, 3.74901627e-01, 7.55347800e-01, 5.28479739e-01, 8.64631462e-01, 5.60848997e-01, 3.82137452e-01, 4.99961889e-01, 5.29737869e-01, 9.85621960e-01, 6.12813748e-02, 4.48468954e-02, 1.94324791e-01, 3.90880357e-03, 1.05811175e-01, 3.94437734e-01, 2.04830871e-01, 4.81965369e-01, 8.45400145e-01, 6.38468218e-01, 7.67432200e-01, 8.30547857e-01, 1.26939493e-01, 4.42671816e-02, 4.48197124e-01, 4.66555556e-01, 9.60267487e-01, 2.57805778e-01, 4.44110753e-01, 5.59008379e-01, 8.49988825e-01, 1.25328933e-01, 9.28501378e-01, 5.79709037e-01, 4.62533411e-01, 4.43393736e-01, 4.98910467e-02, 2.75026095e-01, 6.19929186e-01, 9.19012177e-01, 9.20682467e-01, 2.56063563e-01, 5.36146329e-01, 3.05924148e-01, 3.67851697e-01, 3.51097154e-01, 4.32807732e-01, 3.26208986e-03, 4.54868778e-01, 3.13958993e-01, 2.63649599e-01])
- (row)float64K1.057, 1.049, ..., 1.039, 1.053
Values:
array([1.0572413 , 1.04910187, 1.07196889, 1.04637864, 1.08511135, 1.07883327, 1.05410473, 1.09462853, 1.0646386 , 1.04214041, 1.02263323, 1.01624572, 1.03547522, 1.02456488, 1.04678623, 1.07764753, 1.00386747, 1.07820403, 1.01681343, 1.0588846 , 1.00044092, 1.08331491, 1.07175395, 1.01784325, 1.09188934, 1.03525373, 1.06123806, 1.02162412, 1.04985638, 1.06833087, 1.01977245, 1.03260294, 1.04336006, 1.05551015, 1.02912231, 1.04728736, 1.01041479, 1.04379077, 1.00211797, 1.01790313, 1.09130702, 1.02068456, 1.03641199, 1.0181115 , 1.05851357, 1.05882001, 1.0892991 , 1.07328981, 1.09436318, 1.01947839, 1.02410795, 1.08659535, 1.08700923, 1.01338181, 1.03628868, 1.00136035, 1.02336109, 1.03458256, 1.03085164, 1.01212304, 1.09532596, 1.03578161, 1.04725279, 1.06947597, 1.0815284 , 1.08894865, 1.05875947, 1.08840914, 1.05540028, 1.07955569, 1.02423292, 1.07494723, 1.02590595, 1.05768937, 1.09356846, 1.06142638, 1.0070585 , 1.08930236, 1.05196076, 1.00841121, 1.03741442, 1.07327263, 1.00929804, 1.06677877, 1.09963128, 1.01891984, 1.06376295, 1.09236163, 1.08124864, 1.02353567, 1.06599126, 1.08741107, 1.06795978, 1.01730203, 1.08231962, 1.08423843, 1.08752373, 1.01219293, 1.0387933 , 1.05254691])
Bin into 10 x and y bins:
[34]:
table.bin(x=10, y=10)
[34]:
- x: 10
- y: 10
- x(x [bin-edge])float64m0.003, 0.102, ..., 0.893, 0.992
Values:
array([0.00313229, 0.10204498, 0.20095768, 0.29987037, 0.39878306, 0.49769576, 0.59660845, 0.69552115, 0.79443384, 0.89334654, 0.99225923]) - y(y [bin-edge])float64m0.007, 0.105, ..., 0.893, 0.991
Values:
array([0.00675377, 0.10522827, 0.20370276, 0.30217725, 0.40065175, 0.49912624, 0.59760074, 0.69607523, 0.79454972, 0.89302422, 0.99149871])
- (x, y)DataArrayViewbinned data [len=5, len=0, ..., len=1, len=2]
Values:
[<scipp.DataArray> Dimensions: Sizes[row:5, ] Coordinates: label int32 [m] (row) [0, 0, ..., 0, 0] x float64 [m] (row) [0.0868831, 0.0921815, ..., 0.053002, 0.0338069] y float64 [m] (row) [0.00675377, 0.0319053, ..., 0.0148797, 0.00843672] z float64 [m] (row) [0.591519, 0.694849, ..., 0.960267, 0.367852] Data: float64 [K] (row) [1.00212, 1.09436, ..., 1.06143, 1.0173] , <scipp.DataArray> Dimensions: Sizes[row:0, ] Coordinates: label int32 [m] (row) [] x float64 [m] (row) [] y float64 [m] (row) [] z float64 [m] (row) [] Data: float64 [K] (row) [] , ..., <scipp.DataArray> Dimensions: Sizes[row:1, ] Coordinates: label int32 [m] (row) [9] x float64 [m] (row) [0.940113] y float64 [m] (row) [0.798104] z float64 [m] (row) [0.141874] Data: float64 [K] (row) [1.04379] , <scipp.DataArray> Dimensions: Sizes[row:2, ] Coordinates: label int32 [m] (row) [9, 9] x float64 [m] (row) [0.94736, 0.947199] y float64 [m] (row) [0.894706, 0.941554] z float64 [m] (row) [0.560849, 0.313959] Data: float64 [K] (row) [1.03629, 1.03879] ]
Bin based on bin size:
[35]:
table.bin(x=1 * sc.Unit('mm'))
[35]:
- x: 990
- x(x [bin-edge])float64m0.003, 0.004, ..., 0.992, 0.993
Values:
array([0.00313229, 0.00413229, 0.00513229, 0.00613229, 0.00713229, 0.00813229, 0.00913229, 0.01013229, 0.01113229, 0.01213229, 0.01313229, 0.01413229, 0.01513229, 0.01613229, 0.01713229, 0.01813229, 0.01913229, 0.02013229, 0.02113229, 0.02213229, 0.02313229, 0.02413229, 0.02513229, 0.02613229, 0.02713229, 0.02813229, 0.02913229, 0.03013229, 0.03113229, 0.03213229, 0.03313229, 0.03413229, 0.03513229, 0.03613229, 0.03713229, 0.03813229, 0.03913229, 0.04013229, 0.04113229, 0.04213229, 0.04313229, 0.04413229, 0.04513229, 0.04613229, 0.04713229, 0.04813229, 0.04913229, 0.05013229, 0.05113229, 0.05213229, 0.05313229, 0.05413229, 0.05513229, 0.05613229, 0.05713229, 0.05813229, 0.05913229, 0.06013229, 0.06113229, 0.06213229, 0.06313229, 0.06413229, 0.06513229, 0.06613229, 0.06713229, 0.06813229, 0.06913229, 0.07013229, 0.07113229, 0.07213229, 0.07313229, 0.07413229, 0.07513229, 0.07613229, 0.07713229, 0.07813229, 0.07913229, 0.08013229, 0.08113229, 0.08213229, 0.08313229, 0.08413229, 0.08513229, 0.08613229, 0.08713229, 0.08813229, 0.08913229, 0.09013229, 0.09113229, 0.09213229, 0.09313229, 0.09413229, 0.09513229, 0.09613229, 0.09713229, 0.09813229, 0.09913229, 0.10013229, 0.10113229, 0.10213229, 0.10313229, 0.10413229, 0.10513229, 0.10613229, 0.10713229, 0.10813229, 0.10913229, 0.11013229, 0.11113229, 0.11213229, 0.11313229, 0.11413229, 0.11513229, 0.11613229, 0.11713229, 0.11813229, 0.11913229, 0.12013229, 0.12113229, 0.12213229, 0.12313229, 0.12413229, 0.12513229, 0.12613229, 0.12713229, 0.12813229, 0.12913229, 0.13013229, 0.13113229, 0.13213229, 0.13313229, 0.13413229, 0.13513229, 0.13613229, 0.13713229, 0.13813229, 0.13913229, 0.14013229, 0.14113229, 0.14213229, 0.14313229, 0.14413229, 0.14513229, 0.14613229, 0.14713229, 0.14813229, 0.14913229, 0.15013229, 0.15113229, 0.15213229, 0.15313229, 0.15413229, 0.15513229, 0.15613229, 0.15713229, 0.15813229, 0.15913229, 0.16013229, 0.16113229, 0.16213229, 0.16313229, 0.16413229, 0.16513229, 0.16613229, 0.16713229, 0.16813229, 0.16913229, 0.17013229, 0.17113229, 0.17213229, 0.17313229, 0.17413229, 0.17513229, 0.17613229, 0.17713229, 0.17813229, 0.17913229, 0.18013229, 0.18113229, 0.18213229, 0.18313229, 0.18413229, 0.18513229, 0.18613229, 0.18713229, 0.18813229, 0.18913229, 0.19013229, 0.19113229, 0.19213229, 0.19313229, 0.19413229, 0.19513229, 0.19613229, 0.19713229, 0.19813229, 0.19913229, 0.20013229, 0.20113229, 0.20213229, 0.20313229, 0.20413229, 0.20513229, 0.20613229, 0.20713229, 0.20813229, 0.20913229, 0.21013229, 0.21113229, 0.21213229, 0.21313229, 0.21413229, 0.21513229, 0.21613229, 0.21713229, 0.21813229, 0.21913229, 0.22013229, 0.22113229, 0.22213229, 0.22313229, 0.22413229, 0.22513229, 0.22613229, 0.22713229, 0.22813229, 0.22913229, 0.23013229, 0.23113229, 0.23213229, 0.23313229, 0.23413229, 0.23513229, 0.23613229, 0.23713229, 0.23813229, 0.23913229, 0.24013229, 0.24113229, 0.24213229, 0.24313229, 0.24413229, 0.24513229, 0.24613229, 0.24713229, 0.24813229, 0.24913229, 0.25013229, 0.25113229, 0.25213229, 0.25313229, 0.25413229, 0.25513229, 0.25613229, 0.25713229, 0.25813229, 0.25913229, 0.26013229, 0.26113229, 0.26213229, 0.26313229, 0.26413229, 0.26513229, 0.26613229, 0.26713229, 0.26813229, 0.26913229, 0.27013229, 0.27113229, 0.27213229, 0.27313229, 0.27413229, 0.27513229, 0.27613229, 0.27713229, 0.27813229, 0.27913229, 0.28013229, 0.28113229, 0.28213229, 0.28313229, 0.28413229, 0.28513229, 0.28613229, 0.28713229, 0.28813229, 0.28913229, 0.29013229, 0.29113229, 0.29213229, 0.29313229, 0.29413229, 0.29513229, 0.29613229, 0.29713229, 0.29813229, 0.29913229, 0.30013229, 0.30113229, 0.30213229, 0.30313229, 0.30413229, 0.30513229, 0.30613229, 0.30713229, 0.30813229, 0.30913229, 0.31013229, 0.31113229, 0.31213229, 0.31313229, 0.31413229, 0.31513229, 0.31613229, 0.31713229, 0.31813229, 0.31913229, 0.32013229, 0.32113229, 0.32213229, 0.32313229, 0.32413229, 0.32513229, 0.32613229, 0.32713229, 0.32813229, 0.32913229, 0.33013229, 0.33113229, 0.33213229, 0.33313229, 0.33413229, 0.33513229, 0.33613229, 0.33713229, 0.33813229, 0.33913229, 0.34013229, 0.34113229, 0.34213229, 0.34313229, 0.34413229, 0.34513229, 0.34613229, 0.34713229, 0.34813229, 0.34913229, 0.35013229, 0.35113229, 0.35213229, 0.35313229, 0.35413229, 0.35513229, 0.35613229, 0.35713229, 0.35813229, 0.35913229, 0.36013229, 0.36113229, 0.36213229, 0.36313229, 0.36413229, 0.36513229, 0.36613229, 0.36713229, 0.36813229, 0.36913229, 0.37013229, 0.37113229, 0.37213229, 0.37313229, 0.37413229, 0.37513229, 0.37613229, 0.37713229, 0.37813229, 0.37913229, 0.38013229, 0.38113229, 0.38213229, 0.38313229, 0.38413229, 0.38513229, 0.38613229, 0.38713229, 0.38813229, 0.38913229, 0.39013229, 0.39113229, 0.39213229, 0.39313229, 0.39413229, 0.39513229, 0.39613229, 0.39713229, 0.39813229, 0.39913229, 0.40013229, 0.40113229, 0.40213229, 0.40313229, 0.40413229, 0.40513229, 0.40613229, 0.40713229, 0.40813229, 0.40913229, 0.41013229, 0.41113229, 0.41213229, 0.41313229, 0.41413229, 0.41513229, 0.41613229, 0.41713229, 0.41813229, 0.41913229, 0.42013229, 0.42113229, 0.42213229, 0.42313229, 0.42413229, 0.42513229, 0.42613229, 0.42713229, 0.42813229, 0.42913229, 0.43013229, 0.43113229, 0.43213229, 0.43313229, 0.43413229, 0.43513229, 0.43613229, 0.43713229, 0.43813229, 0.43913229, 0.44013229, 0.44113229, 0.44213229, 0.44313229, 0.44413229, 0.44513229, 0.44613229, 0.44713229, 0.44813229, 0.44913229, 0.45013229, 0.45113229, 0.45213229, 0.45313229, 0.45413229, 0.45513229, 0.45613229, 0.45713229, 0.45813229, 0.45913229, 0.46013229, 0.46113229, 0.46213229, 0.46313229, 0.46413229, 0.46513229, 0.46613229, 0.46713229, 0.46813229, 0.46913229, 0.47013229, 0.47113229, 0.47213229, 0.47313229, 0.47413229, 0.47513229, 0.47613229, 0.47713229, 0.47813229, 0.47913229, 0.48013229, 0.48113229, 0.48213229, 0.48313229, 0.48413229, 0.48513229, 0.48613229, 0.48713229, 0.48813229, 0.48913229, 0.49013229, 0.49113229, 0.49213229, 0.49313229, 0.49413229, 0.49513229, 0.49613229, 0.49713229, 0.49813229, 0.49913229, 0.50013229, 0.50113229, 0.50213229, 0.50313229, 0.50413229, 0.50513229, 0.50613229, 0.50713229, 0.50813229, 0.50913229, 0.51013229, 0.51113229, 0.51213229, 0.51313229, 0.51413229, 0.51513229, 0.51613229, 0.51713229, 0.51813229, 0.51913229, 0.52013229, 0.52113229, 0.52213229, 0.52313229, 0.52413229, 0.52513229, 0.52613229, 0.52713229, 0.52813229, 0.52913229, 0.53013229, 0.53113229, 0.53213229, 0.53313229, 0.53413229, 0.53513229, 0.53613229, 0.53713229, 0.53813229, 0.53913229, 0.54013229, 0.54113229, 0.54213229, 0.54313229, 0.54413229, 0.54513229, 0.54613229, 0.54713229, 0.54813229, 0.54913229, 0.55013229, 0.55113229, 0.55213229, 0.55313229, 0.55413229, 0.55513229, 0.55613229, 0.55713229, 0.55813229, 0.55913229, 0.56013229, 0.56113229, 0.56213229, 0.56313229, 0.56413229, 0.56513229, 0.56613229, 0.56713229, 0.56813229, 0.56913229, 0.57013229, 0.57113229, 0.57213229, 0.57313229, 0.57413229, 0.57513229, 0.57613229, 0.57713229, 0.57813229, 0.57913229, 0.58013229, 0.58113229, 0.58213229, 0.58313229, 0.58413229, 0.58513229, 0.58613229, 0.58713229, 0.58813229, 0.58913229, 0.59013229, 0.59113229, 0.59213229, 0.59313229, 0.59413229, 0.59513229, 0.59613229, 0.59713229, 0.59813229, 0.59913229, 0.60013229, 0.60113229, 0.60213229, 0.60313229, 0.60413229, 0.60513229, 0.60613229, 0.60713229, 0.60813229, 0.60913229, 0.61013229, 0.61113229, 0.61213229, 0.61313229, 0.61413229, 0.61513229, 0.61613229, 0.61713229, 0.61813229, 0.61913229, 0.62013229, 0.62113229, 0.62213229, 0.62313229, 0.62413229, 0.62513229, 0.62613229, 0.62713229, 0.62813229, 0.62913229, 0.63013229, 0.63113229, 0.63213229, 0.63313229, 0.63413229, 0.63513229, 0.63613229, 0.63713229, 0.63813229, 0.63913229, 0.64013229, 0.64113229, 0.64213229, 0.64313229, 0.64413229, 0.64513229, 0.64613229, 0.64713229, 0.64813229, 0.64913229, 0.65013229, 0.65113229, 0.65213229, 0.65313229, 0.65413229, 0.65513229, 0.65613229, 0.65713229, 0.65813229, 0.65913229, 0.66013229, 0.66113229, 0.66213229, 0.66313229, 0.66413229, 0.66513229, 0.66613229, 0.66713229, 0.66813229, 0.66913229, 0.67013229, 0.67113229, 0.67213229, 0.67313229, 0.67413229, 0.67513229, 0.67613229, 0.67713229, 0.67813229, 0.67913229, 0.68013229, 0.68113229, 0.68213229, 0.68313229, 0.68413229, 0.68513229, 0.68613229, 0.68713229, 0.68813229, 0.68913229, 0.69013229, 0.69113229, 0.69213229, 0.69313229, 0.69413229, 0.69513229, 0.69613229, 0.69713229, 0.69813229, 0.69913229, 0.70013229, 0.70113229, 0.70213229, 0.70313229, 0.70413229, 0.70513229, 0.70613229, 0.70713229, 0.70813229, 0.70913229, 0.71013229, 0.71113229, 0.71213229, 0.71313229, 0.71413229, 0.71513229, 0.71613229, 0.71713229, 0.71813229, 0.71913229, 0.72013229, 0.72113229, 0.72213229, 0.72313229, 0.72413229, 0.72513229, 0.72613229, 0.72713229, 0.72813229, 0.72913229, 0.73013229, 0.73113229, 0.73213229, 0.73313229, 0.73413229, 0.73513229, 0.73613229, 0.73713229, 0.73813229, 0.73913229, 0.74013229, 0.74113229, 0.74213229, 0.74313229, 0.74413229, 0.74513229, 0.74613229, 0.74713229, 0.74813229, 0.74913229, 0.75013229, 0.75113229, 0.75213229, 0.75313229, 0.75413229, 0.75513229, 0.75613229, 0.75713229, 0.75813229, 0.75913229, 0.76013229, 0.76113229, 0.76213229, 0.76313229, 0.76413229, 0.76513229, 0.76613229, 0.76713229, 0.76813229, 0.76913229, 0.77013229, 0.77113229, 0.77213229, 0.77313229, 0.77413229, 0.77513229, 0.77613229, 0.77713229, 0.77813229, 0.77913229, 0.78013229, 0.78113229, 0.78213229, 0.78313229, 0.78413229, 0.78513229, 0.78613229, 0.78713229, 0.78813229, 0.78913229, 0.79013229, 0.79113229, 0.79213229, 0.79313229, 0.79413229, 0.79513229, 0.79613229, 0.79713229, 0.79813229, 0.79913229, 0.80013229, 0.80113229, 0.80213229, 0.80313229, 0.80413229, 0.80513229, 0.80613229, 0.80713229, 0.80813229, 0.80913229, 0.81013229, 0.81113229, 0.81213229, 0.81313229, 0.81413229, 0.81513229, 0.81613229, 0.81713229, 0.81813229, 0.81913229, 0.82013229, 0.82113229, 0.82213229, 0.82313229, 0.82413229, 0.82513229, 0.82613229, 0.82713229, 0.82813229, 0.82913229, 0.83013229, 0.83113229, 0.83213229, 0.83313229, 0.83413229, 0.83513229, 0.83613229, 0.83713229, 0.83813229, 0.83913229, 0.84013229, 0.84113229, 0.84213229, 0.84313229, 0.84413229, 0.84513229, 0.84613229, 0.84713229, 0.84813229, 0.84913229, 0.85013229, 0.85113229, 0.85213229, 0.85313229, 0.85413229, 0.85513229, 0.85613229, 0.85713229, 0.85813229, 0.85913229, 0.86013229, 0.86113229, 0.86213229, 0.86313229, 0.86413229, 0.86513229, 0.86613229, 0.86713229, 0.86813229, 0.86913229, 0.87013229, 0.87113229, 0.87213229, 0.87313229, 0.87413229, 0.87513229, 0.87613229, 0.87713229, 0.87813229, 0.87913229, 0.88013229, 0.88113229, 0.88213229, 0.88313229, 0.88413229, 0.88513229, 0.88613229, 0.88713229, 0.88813229, 0.88913229, 0.89013229, 0.89113229, 0.89213229, 0.89313229, 0.89413229, 0.89513229, 0.89613229, 0.89713229, 0.89813229, 0.89913229, 0.90013229, 0.90113229, 0.90213229, 0.90313229, 0.90413229, 0.90513229, 0.90613229, 0.90713229, 0.90813229, 0.90913229, 0.91013229, 0.91113229, 0.91213229, 0.91313229, 0.91413229, 0.91513229, 0.91613229, 0.91713229, 0.91813229, 0.91913229, 0.92013229, 0.92113229, 0.92213229, 0.92313229, 0.92413229, 0.92513229, 0.92613229, 0.92713229, 0.92813229, 0.92913229, 0.93013229, 0.93113229, 0.93213229, 0.93313229, 0.93413229, 0.93513229, 0.93613229, 0.93713229, 0.93813229, 0.93913229, 0.94013229, 0.94113229, 0.94213229, 0.94313229, 0.94413229, 0.94513229, 0.94613229, 0.94713229, 0.94813229, 0.94913229, 0.95013229, 0.95113229, 0.95213229, 0.95313229, 0.95413229, 0.95513229, 0.95613229, 0.95713229, 0.95813229, 0.95913229, 0.96013229, 0.96113229, 0.96213229, 0.96313229, 0.96413229, 0.96513229, 0.96613229, 0.96713229, 0.96813229, 0.96913229, 0.97013229, 0.97113229, 0.97213229, 0.97313229, 0.97413229, 0.97513229, 0.97613229, 0.97713229, 0.97813229, 0.97913229, 0.98013229, 0.98113229, 0.98213229, 0.98313229, 0.98413229, 0.98513229, 0.98613229, 0.98713229, 0.98813229, 0.98913229, 0.99013229, 0.99113229, 0.99213229, 0.99313229])
- (x)DataArrayViewbinned data [len=1, len=0, ..., len=0, len=1]
Values:
[<scipp.DataArray> Dimensions: Sizes[row:1, ] Coordinates: label int32 [m] (row) [0] x float64 [m] (row) [0.00313229] y float64 [m] (row) [0.691054] z float64 [m] (row) [0.332033] Data: float64 [K] (row) [1.04986] , <scipp.DataArray> Dimensions: Sizes[row:0, ] Coordinates: label int32 [m] (row) [] x float64 [m] (row) [] y float64 [m] (row) [] z float64 [m] (row) [] Data: float64 [K] (row) [] , ..., <scipp.DataArray> Dimensions: Sizes[row:0, ] Coordinates: label int32 [m] (row) [] x float64 [m] (row) [] y float64 [m] (row) [] z float64 [m] (row) [] Data: float64 [K] (row) [] , <scipp.DataArray> Dimensions: Sizes[row:1, ] Coordinates: label int32 [m] (row) [9] x float64 [m] (row) [0.992259] y float64 [m] (row) [0.141296] z float64 [m] (row) [0.372221] Data: float64 [K] (row) [1.04729] ]
Group by label and bin by y:
[36]:
table.group('label').bin(y=20)
[36]:
- label: 10
- y: 20
- label(label)int32m0, 1, ..., 8, 9
Values:
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int32) - y(y [bin-edge])float64m0.007, 0.056, ..., 0.942, 0.991
Values:
array([0.00675377, 0.05599102, 0.10522827, 0.15446551, 0.20370276, 0.25294001, 0.30217725, 0.3514145 , 0.40065175, 0.44988899, 0.49912624, 0.54836349, 0.59760074, 0.64683798, 0.69607523, 0.74531248, 0.79454972, 0.84378697, 0.89302422, 0.94226146, 0.99149871])
- (label, y)DataArrayViewbinned data [len=4, len=1, ..., len=2, len=0]
Values:
[<scipp.DataArray> Dimensions: Sizes[row:4, ] Coordinates: x float64 [m] (row) [0.0868831, 0.0921815, 0.053002, 0.0338069] y float64 [m] (row) [0.00675377, 0.0319053, 0.0148797, 0.00843672] z float64 [m] (row) [0.591519, 0.694849, 0.960267, 0.367852] Data: float64 [K] (row) [1.00212, 1.09436, 1.06143, 1.0173] , <scipp.DataArray> Dimensions: Sizes[row:1, ] Coordinates: x float64 [m] (row) [0.00597817] y float64 [m] (row) [0.0926235] z float64 [m] (row) [0.126939] Data: float64 [K] (row) [1.07495] , ..., <scipp.DataArray> Dimensions: Sizes[row:2, ] Coordinates: x float64 [m] (row) [0.94736, 0.947199] y float64 [m] (row) [0.894706, 0.941554] z float64 [m] (row) [0.560849, 0.313959] Data: float64 [K] (row) [1.03629, 1.03879] , <scipp.DataArray> Dimensions: Sizes[row:0, ] Coordinates: x float64 [m] (row) [] y float64 [m] (row) [] z float64 [m] (row) [] Data: float64 [K] (row) [] ]
For more examples see the documentation of the functions.
Multi-dimensional histogramming#
New in 0.15
Added support for multi-dimensional histogramming with hist
. This is partially based on bin
, i.e., performance may be sub-optimal.
Example:
[37]:
table.hist(x=10, y=20)
[37]:
- x: 10
- y: 20
- x(x [bin-edge])float64m0.003, 0.102, ..., 0.893, 0.992
Values:
array([0.00313229, 0.10204498, 0.20095768, 0.29987037, 0.39878306, 0.49769576, 0.59660845, 0.69552115, 0.79443384, 0.89334654, 0.99225923]) - y(y [bin-edge])float64m0.007, 0.056, ..., 0.942, 0.991
Values:
array([0.00675377, 0.05599102, 0.10522827, 0.15446551, 0.20370276, 0.25294001, 0.30217725, 0.3514145 , 0.40065175, 0.44988899, 0.49912624, 0.54836349, 0.59760074, 0.64683798, 0.69607523, 0.74531248, 0.79454972, 0.84378697, 0.89302422, 0.94226146, 0.99149871])
- (x, y)float64K4.175, 1.075, ..., 2.075, 0.0
Values:
array([[4.17520956, 1.07494723, 0. , 0. , 0. , 1.05254691, 0. , 0. , 0. , 0. , 0. , 1.09188934, 1.06795978, 1.04985638, 1.00044092, 0. , 0. , 1.03741442, 0. , 1.0815284 ], [0. , 1.02912231, 1.01681343, 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 1.08930236, 0. , 1.01891984, 1.07883327, 0. , 0. , 0. , 2.07719356], [0. , 0. , 1.09532596, 2.13478778, 1.01947839, 0. , 1.04214041, 0. , 0. , 0. , 0. , 1.02590595, 1.05768937, 1.05410473, 2.1416035 , 0. , 2.10173969, 0. , 1.02068456, 0. ], [0. , 1.0892991 , 0. , 0. , 2.18215226, 0. , 0. , 0. , 0. , 1.08511135, 0. , 0. , 2.13651294, 0. , 1.0070585 , 0. , 1.01338181, 1.08124864, 0. , 1.09356846], [1.06123806, 1.03458256, 0. , 1.05882001, 1.08231962, 2.10964246, 0. , 0. , 0. , 1.05540028, 0. , 1.03260294, 0. , 1.07328981, 0. , 0. , 0. , 0. , 1.02336109, 1.01790313], [0. , 0. , 0. , 0. , 0. , 1.09236163, 1.07955569, 1.02162412, 0. , 0. , 1.02410795, 0. , 0. , 0. , 0. , 0. , 0. , 1.08894865, 0. , 0. ], [0. , 1.01784325, 1.00841121, 2.13010114, 0. , 0. , 1.05875947, 0. , 0. , 0. , 0. , 2.08694556, 0. , 1.07175395, 0. , 0. , 0. , 0. , 1.01624572, 0. ], [1.03085164, 0. , 0. , 0. , 0. , 0. , 0. , 1.00386747, 0. , 0. , 1.03578161, 0. , 1.08659535, 0. , 1.00136035, 0. , 0. , 1.04336006, 0. , 0. ], [0. , 0. , 2.04853503, 1.06947597, 1.08423843, 1.03547522, 0. , 0. , 1.06599126, 1.06376295, 2.11047433, 0. , 0. , 2.11107947, 1.01219293, 0. , 0. , 0. , 1.04725279, 2.08344949], [1.02423292, 2.13488502, 1.04728736, 0. , 0. , 2.12921019, 0. , 0. , 0. , 0. , 1.05551015, 1.0181115 , 1.0646386 , 0. , 0. , 0. , 1.04379077, 0. , 2.07508198, 0. ]])
nanhist
#
New in 0.15
Added nanhist
, to skip NaN values when computing a histogram. This is based on bin
, i.e., performance may be sub-optimal.
Binned data#
Interpolation using lookup
#
New in 0.15
lookup
is extended and improved, to facilitate “event filtering” operations:
Support for non-histogram data arrays as input functions. In this case two lookup modes,
previous
andnearest
are provided. This makes this similar toscipy.interpolate.interp1d
.Custom fill values are now supported. This is used for out-of-range as well as for masked values.
Works with
transform_coords
.
Example:
Given a function func
and a data array:
[38]:
x = sc.linspace('x', 0, 1, num=51, unit='m')
func = sc.DataArray(x * x, coords={'x': x}) # approximating f(x) = x**2
table = sc.data.table_xyz(nrow=100)
da = table.bin(y=2, x=10) # note x=10, unlike in func above
We can compute a new coordinate x2
, for both the bin coordinate and the event coordinate:
[39]:
da = da.transform_coords(x2=sc.lookup(func, mode='nearest'))
da
[39]:
- y: 2
- x2: 10
- x2(x2 [bin-edge])float64m^20.0, 0.010, ..., 0.81, 1.0
Values:
array([0. , 0.01, 0.04, 0.09, 0.16, 0.25, 0.36, 0.49, 0.64, 0.81, 1. ]) - y(y [bin-edge])float64m0.007, 0.499, 0.991
Values:
array([0.00675377, 0.49912624, 0.99149871])
- (y, x2)DataArrayViewbinned data [len=6, len=2, ..., len=8, len=6]
Values:
[<scipp.DataArray> Dimensions: Sizes[row:6, ] Coordinates: x2 float64 [m^2] (row) [0.0064, 0.01, ..., 0.0016, 0.0036] y float64 [m] (row) [0.00675377, 0.0319053, ..., 0.00843672, 0.266437] z float64 [m] (row) [0.591519, 0.694849, ..., 0.367852, 0.26365] Data: float64 [K] (row) [1.00212, 1.09436, ..., 1.0173, 1.05255] Attributes: x float64 [m] (row) [0.0868831, 0.0921815, ..., 0.0338069, 0.0670407] , <scipp.DataArray> Dimensions: Sizes[row:2, ] Coordinates: x2 float64 [m^2] (row) [0.0324, 0.0256] y float64 [m] (row) [0.127554, 0.0978224] z float64 [m] (row) [0.98037, 0.314727] Data: float64 [K] (row) [1.01681, 1.02912] Attributes: x float64 [m] (row) [0.172066, 0.153474] , ..., <scipp.DataArray> Dimensions: Sizes[row:8, ] Coordinates: x2 float64 [m^2] (row) [0.7396, 0.7744, ..., 0.6724, 0.6724] y float64 [m] (row) [0.948835, 0.95134, ..., 0.501685, 0.741137] z float64 [m] (row) [0.0280613, 0.17809, ..., 0.559008, 0.454869] Data: float64 [K] (row) [1.02456, 1.05888, ..., 1.05196, 1.01219] Attributes: x float64 [m] (row) [0.863758, 0.870415, ..., 0.829215, 0.823521] , <scipp.DataArray> Dimensions: Sizes[row:6, ] Coordinates: x2 float64 [m^2] (row) [0.9216, 0.8464, ..., 0.8836, 0.8836] y float64 [m] (row) [0.622047, 0.537658, ..., 0.894706, 0.941554] z float64 [m] (row) [0.730931, 0.918612, ..., 0.560849, 0.313959] Data: float64 [K] (row) [1.06464, 1.05551, ..., 1.03629, 1.03879] Attributes: x float64 [m] (row) [0.964079, 0.922043, ..., 0.94736, 0.947199] ]
- x(x2 [bin-edge])float64m0.003, 0.102, ..., 0.893, 0.992
Values:
array([0.00313229, 0.10204498, 0.20095768, 0.29987037, 0.39878306, 0.49769576, 0.59660845, 0.69552115, 0.79443384, 0.89334654, 0.99225923])
[40]:
sc.show(da)
Reduction operations#
More operations supported by data arrays and datasets#
New in 0.14
DataArray
andDataset
now support more reduction operations, includingsum
,nansum
,mean
,nanmean
,max
,min
,nanmax
,nanmin
,all
, andany
.All of the above are now also supported for the
bins
property.groupby
now also supports all of these operations. Exception:nanmean
.Event-based masks are now supported in all reduction operations.
Example:
[41]:
da = sc.data.binned_x(nevent=100, nbin=3)
da
[41]:
- x: 3
- x(x [bin-edge])float64m0.003, 0.333, 0.663, 0.992
Values:
array([0.00313229, 0.33284127, 0.66255025, 0.99225923])
- (x)DataArrayViewbinned data [len=37, len=26, len=37]
Values:
[<scipp.DataArray> Dimensions: Sizes[row:37, ] Coordinates: x float64 [m] (row) [0.261692, 0.319097, ..., 0.0338069, 0.0670407] y float64 [m] (row) [0.174846, 0.495505, ..., 0.00843672, 0.266437] z float64 [m] (row) [0.806809, 0.0545327, ..., 0.367852, 0.26365] Data: float64 [K] (row) [1.04638, 1.08511, ..., 1.0173, 1.05255] , <scipp.DataArray> Dimensions: Sizes[row:26, ] Coordinates: x float64 [m] (row) [0.380196, 0.441006, ..., 0.461613, 0.350609] y float64 [m] (row) [0.619161, 0.277216, ..., 0.221658, 0.220269] z float64 [m] (row) [0.00207108, 0.762591, ..., 0.351097, 0.00326209] Data: float64 [K] (row) [1.0491, 1.02263, ..., 1.08232, 1.08752] , <scipp.DataArray> Dimensions: Sizes[row:37, ] Coordinates: x float64 [m] (row) [0.9767, 0.923246, ..., 0.823521, 0.947199] y float64 [m] (row) [0.29784, 0.301757, ..., 0.741137, 0.941554] z float64 [m] (row) [0.747273, 0.809356, ..., 0.454869, 0.313959] Data: float64 [K] (row) [1.05724, 1.07197, ..., 1.01219, 1.03879] ]
The maximum value in each bin:
[42]:
da.bins.max()
[42]:
- x: 3
- x(x [bin-edge])float64m0.003, 0.333, 0.663, 0.992
Values:
array([0.00313229, 0.33284127, 0.66255025, 0.99225923])
- (x)float64K1.095, 1.094, 1.100
Values:
array([1.09532596, 1.09356846, 1.09963128])
The maximum value in each bin of a binned variable, here a coordinate:
[43]:
da.bins.coords['x'].bins.max()
[43]:
- (x: 3)float64m0.326, 0.660, 0.992
Values:
array([0.3264945 , 0.65987435, 0.99225923])
Shape operations#
fold
supports size -1#
New in 0.12
fold
now accepts up to one size (or shape) entry with value -1
. This indicates that the size should be computed automatically based on the input size and other provided sizes.
Example:
[44]:
var = sc.arange('xyz', 2448)
var.fold('xyz', sizes={'x': 4, 'y': 4, 'z': -1})
[44]:
- (x: 4, y: 4, z: 153)int64𝟙0, 1, ..., 2446, 2447
Values:
array([[[ 0, 1, 2, ..., 150, 151, 152], [ 153, 154, 155, ..., 303, 304, 305], [ 306, 307, 308, ..., 456, 457, 458], [ 459, 460, 461, ..., 609, 610, 611]], [[ 612, 613, 614, ..., 762, 763, 764], [ 765, 766, 767, ..., 915, 916, 917], [ 918, 919, 920, ..., 1068, 1069, 1070], [1071, 1072, 1073, ..., 1221, 1222, 1223]], [[1224, 1225, 1226, ..., 1374, 1375, 1376], [1377, 1378, 1379, ..., 1527, 1528, 1529], [1530, 1531, 1532, ..., 1680, 1681, 1682], [1683, 1684, 1685, ..., 1833, 1834, 1835]], [[1836, 1837, 1838, ..., 1986, 1987, 1988], [1989, 1990, 1991, ..., 2139, 2140, 2141], [2142, 2143, 2144, ..., 2292, 2293, 2294], [2295, 2296, 2297, ..., 2445, 2446, 2447]]])
broadcast
supports DataArray
#
New in 0.13
broadcast
now also supports data arrays.
flatten
drops mismatching bin edges#
New in 0.15
flatten
now drops mismatching bin edges instead of raising an exception.
Example:
[45]:
hist = sc.data.table_xyz(nrow=100).hist(y=2, x=4)
hist.flatten(to='yx')
[45]:
- yx: 8
- (yx)float64K9.368, 16.031, ..., 9.454, 15.623
Values:
array([ 9.36811784, 16.03081984, 9.412524 , 14.73394598, 16.84836126, 13.62563212, 9.45373887, 15.62294235])
Above the x
edges cannot be joined together so the coordinate is dropped in the result. Note the similar behavior of integer-array indexing, for the same reason:
[46]:
hist['x', [0, 2, 3]] # drops x edges
[46]:
- y: 2
- x: 3
- y(y [bin-edge])float64m0.007, 0.499, 0.991
Values:
array([0.00675377, 0.49912624, 0.99149871])
- (y, x)float64K9.368, 9.413, ..., 9.454, 15.623
Values:
array([[ 9.36811784, 9.412524 , 14.73394598], [16.84836126, 9.45373887, 15.62294235]])
Vectors and matrices#
General#
New in 0.11
scipp.spatial
has been restructured and extended:
New data types for spatial transforms were added:
vector3
(renamed fromvector3_float64
)rotation3
(3-D rotation defined using quaternion coeffiecients)translation3
(translation in 3-D)linear_transform3
(previouslymatrix_3_float64
, 3-D linear transform with, e.g., rotation and scaling)affine_transform3
(affine transform in 3-D, combination of a linear transform and a translation, defined using 4x4 matrix)
The scipp.spatial submodule was extended with a number of new creation functions, in particular for the new dtypes.
matrix
andmatrices
for creating “matrices” have been deprecated. Usescipp.spatial.linear_transform
andscipp.spatial.linear_transforms
instead.
Note that the scipp.spatial
subpackage must be imported explicitly:
[47]:
from scipp import spatial
linear = spatial.linear_transform(value=[[1, 0, 0], [0, 2, 0], [0, 0, 3]])
linear
[47]:
- ()linear_transform3𝟙[[1. 0. 0.] [0. 2. 0.] [0. 0. 3.]]
Values:
array([[1., 0., 0.], [0., 2., 0.], [0., 0., 3.]])
[48]:
trans = spatial.translation(value=[1, 2, 3], unit='m')
trans
[48]:
- ()translation3m[1. 2. 3.]
Values:
array([1., 2., 3.])
Multiplication can be used to combine the various transforms:
[49]:
linear * trans
[49]:
- ()affine_transform3m[[1. 0. 0. 1.] [0. 2. 0. 4.] [0. 0. 3. 9.] [0. 0. 0. 1.]]
Values:
array([[1., 0., 0., 1.], [0., 2., 0., 4.], [0., 0., 3., 9.], [0., 0., 0., 1.]])
Note that in the case of affine_transform3
the unit refers to the translation part. A unit for the linear part is currently not supported.
SciPy compatibility layer#
New in 0.11
A number of subpackages providing wrappers for a subset of functions from the corresponding packages in SciPy was added:
scipp.integrate providing
simpson
andtrapezoid
.scipp.interpolate providing
interp1d
.scipp.optimize providing
curve_fit
.scipp.signal providing
butter
andsosfiltfilt
.
Please refer to the function documentation for working examples.
New in 0.14
scipp.ndimage providing
gaussian_filter
,median_filter
, and more.
Python ecosystem compatibility#
New in 0.15
Added scipp.compat.to_xarray
Example:
[50]:
da = sc.data.data_xy()
sc.compat.to_xarray(da)
[50]:
<xarray.DataArray (x: 100, y: 100)> array([[0.97669977, 0.38019574, 0.92324623, ..., 0.82352055, 0.94719907, 0.06704071], [0.29784009, 0.61916102, 0.30175743, ..., 0.74113721, 0.94155401, 0.2664373 ], [0.74727331, 0.00207108, 0.80935632, ..., 0.45486878, 0.31395899, 0.2636496 ], ..., [0.96361756, 0.24277487, 0.13245066, ..., 0.040788 , 0.68996056, 0.57886072], [0.86150017, 0.23153692, 0.46282186, ..., 0.56816586, 0.67814736, 0.31450947], [0.76446616, 0.39851845, 0.00798981, ..., 0.79800865, 0.17579735, 0.58481827]]) Coordinates: * y (y) float64 0.0 0.05051 0.101 0.1515 ... 4.848 4.899 4.949 5.0 * x (x) float64 0.0 0.0101 0.0202 0.0303 ... 0.9697 0.9798 0.9899 1.0 Attributes: units: dimensionless
Performance#
New in 0.12
sc.bin()
is now faster when binning or grouping into thousands of bins or more.
New in 0.14
Fixed slow import times of scipp
.