Reading and Writing Files#

HDF5#

Scipp supports writing variables, data arrays, and dataset to HDF5 files. Reading of HDF5 is supported only for these scipp-specific files. Other HDF5-based formats are not supported at this point. For reading the HDF5-based NeXus files, see scippneutron.

Warning

We do not recommend to use Scipp HDF5 files for archiving or as the sole means of storing valuable data. The current Scipp HDF5 schema is not a standard and will likely be subject to change due to the early development status of scipp. Future versions of Scipp may not be able to read older files.

That being said, the file format is quite simple and based on the HDF5 standard so it would still be possible to recover data from such files in such a case. Note that the Scipp version is stored as an HDF5 attribute of the saved objects.

[1]:
import numpy as np
import scipp as sc

x = sc.Variable(dims=['x'], values=np.arange(10))
var = sc.Variable(dims=['x', 'y'], values=np.random.rand(9,3))
a = sc.DataArray(data=var, coords={'x':x})

a.to_hdf5(filename='test.hdf5')
[2]:
b = sc.io.open_hdf5(filename='test.hdf5')
[3]:
b
[3]:
Show/Hide data repr Show/Hide attributes
scipp.DataArray (1.29 KB)
    • x: 9
    • y: 3
    • x
      (x [bin-edge])
      int64
      𝟙
      0, 1, ..., 8, 9
      Values:
      array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
    • (x, y)
      float64
      𝟙
      0.297, 0.264, ..., 0.556, 0.140
      Values:
      array([[0.29670205, 0.26435471, 0.23030373], [0.20146128, 0.48771275, 0.06188159], [0.89043768, 0.78149186, 0.70676164], [0.09002005, 0.70588558, 0.09907501], [0.1678411 , 0.12730924, 0.77604627], [0.00694063, 0.28185784, 0.79099092], [0.75711042, 0.88803817, 0.69604086], [0.80984849, 0.63338915, 0.56642657], [0.6193196 , 0.55577506, 0.1395241 ]])

NeXus#

Scipp has no built-in support for loading NeXus files. However, the scippneutron package can internally use Mantid to load such files, or any other Mantid-supported file type, see scippneutron and in particular scippneutron.load.