scipp.io.hdf5.save_hdf5#
- scipp.io.hdf5.save_hdf5(obj, 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]