{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Reading and Writing Files\n", "\n", "## HDF5\n", "\n", "Scipp supports writing variables, data arrays, and dataset to [HDF5](https://portal.hdfgroup.org/display/support/Documentation) files.\n", "Reading of HDF5 is supported *only* for these scipp-specific files.\n", "Other HDF5-based formats are not supported at this point.\n", "For reading the HDF5-based [NeXus](https://www.nexusformat.org/) files, see [scippneutron](https://scipp.github.io/scippneutron/).\n", "\n", "
\n", "\n", "**Warning**\n", " \n", "We do not recommend to use scipp HDF5 files for archiving or as the sole means of storing valuable data.\n", "The current scipp HDF5 schema is not a standard and will likely be subject to change due to the early development status of scipp.\n", "**Future versions of scipp may not be able to read older files.**\n", " \n", "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.\n", "Note that the scipp version is stored as an HDF5 attribute of the saved objects.\n", " \n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import scipp as sc\n", "\n", "x = sc.Variable(dims=['x'], values=np.arange(10))\n", "var = sc.Variable(dims=['x', 'y'], values=np.random.rand(9,3))\n", "a = sc.DataArray(data=var, coords={'x':x})\n", "\n", "a.to_hdf5(filename='test.hdf5')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "b = sc.io.open_hdf5(filename='test.hdf5')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "b" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## NeXus\n", "\n", "Scipp has no built-in support for loading [NeXus](https://www.nexusformat.org/) files.\n", "However, the `scippneutron` package can internally use [Mantid](https://www.mantidproject.org/Main_Page) to load such files, or any other Mantid-supported file type, see [scippneutron](https://scipp.github.io/scippneutron/) and in particular [scippneutron.load](https://scipp.github.io/scippneutron/generated/scippneutron.load.html#scippneutron.load)." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.10" } }, "nbformat": 4, "nbformat_minor": 4 }