scipp.DataGroup#
- class scipp.DataGroup(*args, **kwargs)#
A dict-like group of data. Additionally provides dims and shape properties.
DataGroup acts like a Python dict but additionally supports Scipp functionality such as positional- and label-based indexing and Scipp operations by mapping them to the values in the dict. This may happen recursively to support tree-like data structures.
Added in version 23.01.0.
- __init__(*args, **kwargs)#
Methods
__init__(*args, **kwargs)all([dim])any([dim])apply(func, *args, **kwargs)Call func on all values and return new DataGroup containing the results.
astype(type, *[, copy])bin([arg_dict])broadcast(*[, dims, shape, sizes])ceil()clear()copy([deep])flatten([dims, to])floor()fold(dim, *[, dims, shape, sizes])get(k[,d])group(*args)groupby(group, *[, bins])hist([arg_dict])items()keys()max([dim])mean([dim])median([dim])min([dim])nanhist([arg_dict])nanmax([dim])nanmean([dim])nanmedian([dim])nanmin([dim])nanstd([dim])nansum([dim])nanvar([dim])plot(*args, **kwargs)pop(k[,d])If key is not found, d is returned if given, otherwise KeyError is raised.
popitem()as a 2-tuple; but raise KeyError if D is empty.
rebin([arg_dict])rename([dims_dict])rename_dims([dims_dict])round(*[, decimals])save_hdf5(filename)Write an object out to file in HDF5 format.
setdefault(k[,d])squeeze([dim])std([dim])sum([dim])to(*[, unit, dtype, copy])transform_coords([targets, graph, ...])transpose([dims])underlying_size()update([E, ]**F)If E present and has a .keys() method, does: for k in E.keys(): D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
values()var([dim])Attributes
binsUnion of dims of all items.
Number of dimensions, i.e., len(self.dims).
Union of shape of all items.
Dict combining dims and shape, i.e., mapping dim labels to their size.
- __getitem__(name)#
Return item of given name or index all items.
When
nameis a string, return the item of the given name. Otherwise, this returns a new DataGroup, with items created by indexing the items in this DataGroup. This may perform, e.g., Scipp’s positional indexing, label-based indexing, or advanced indexing on items that are scipp.Variable or scipp.DataArray.Label-based indexing is only possible when all items have a coordinate for the indexed dimension.
Advanced indexing comprises integer-array indexing and boolean-variable indexing. Unlike positional indexing, integer-array indexing works even when the item shapes are inconsistent for the indexed dimensions, provided that all items contain the maximal index in the integer array. Boolean-variable indexing is only possible when the shape of all items is compatible with the boolean variable.
A dict index maps dimension names to indices, e.g.,
dg[{'x': 0, 'y': 1}]. It is forwarded to each item, restricted to the dims that the item has. All indices are thus resolved against the unsliced item, so the result does not depend on the order of the dict keys.- Return type:
- apply(func, *args, **kwargs)#
Call func on all values and return new DataGroup containing the results.
- save_hdf5(filename)#
Write an object out to file in HDF5 format.
Supported types include
Variable,DataArray,Dataset, andDataGroup. Nested structures are supported.- Parameters:
- Return type:
See also
scipp.io.load_hdf5Load data from HDF5 files.
Examples
Save and load a Variable:
>>> import scipp as sc >>> import tempfile >>> var = sc.array(dims=['x'], values=[1.0, 2.0, 3.0], unit='m') >>> with tempfile.NamedTemporaryFile(suffix='.h5') as f: ... sc.io.save_hdf5(var, f.name) ... loaded = sc.io.load_hdf5(f.name) >>> loaded <scipp.Variable> (x: 3) float64 [m] [1, 2, 3]
Save and load a DataArray with coordinates:
>>> da = sc.DataArray( ... sc.array(dims=['x'], values=[10, 20, 30], unit='counts'), ... coords={'x': sc.array(dims=['x'], values=[0.1, 0.2, 0.3], unit='m')} ... ) >>> with tempfile.NamedTemporaryFile(suffix='.h5') as f: ... sc.io.save_hdf5(da, f.name) ... loaded = sc.io.load_hdf5(f.name) >>> loaded <scipp.DataArray> Dimensions: Sizes[x:3, ] Coordinates: * x float64 [m] (x) [0.1, 0.2, 0.3] Data: int64 [counts] (x) [10, 20, 30]
- property shape: tuple[int | None, ...]#
Union of shape of all items. Non-Scipp items are handled as shape=().
- property sizes: dict[str, int | None]#
Dict combining dims and shape, i.e., mapping dim labels to their size.
- values()#
- Return type:
ValuesView[TypeVar(_V)]