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.281, 0.147, ..., 0.980, 0.459
      Values:
      array([[0.2814966 , 0.14718815, 0.86004459], [0.63935844, 0.74067307, 0.1946895 ], [0.05722854, 0.20758956, 0.79890307], [0.40736814, 0.94875488, 0.99569992], [0.27305599, 0.98908999, 0.68110141], [0.67588015, 0.87703071, 0.96492915], [0.6526303 , 0.84626007, 0.59259751], [0.92824262, 0.64362823, 0.39218213], [0.05090469, 0.97965768, 0.45912261]])

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.