7. IO
sed.io module easy access APIs
- sed.io.load_h5(faddr, mode='r')
Read xarray data from formatted hdf5 file
- Parameters:
faddr (str) – complete file name (including path)
mode (str, optional) – hdf5 read/write mode. Defaults to “r”.
- Raises:
ValueError – Raised if data or axes are not found in the file.
- Returns:
output xarra data
- Return type:
xr.DataArray
- sed.io.to_h5(data, faddr, mode='w')
Save xarray formatted data to hdf5
- Parameters:
data (xr.DataArray) – input data
faddr (str) – complete file name (including path)
mode (str, optional) – hdf5 read/write mode. Defaults to “w”.
- Raises:
Warning – subfunction warns if elements have been converted into strings for saving.
- sed.io.load_tiff(faddr, coords=None, dims=None, attrs=None)
Loads a tiff stack to an xarray.
The .tiff format does not retain information on the axes, so these need to be manually added with the axes argument. Otherwise, this returns the data only as np.ndarray.
- Parameters:
faddr (Union[str, Path]) – Path to file to load.
coords (dict, optional) – The axes describing the data, following the tiff stack order. Defaults to None.
dims (Sequence, optional) – the order of the coordinates provided, considering the data is ordered as TZCYXS. If None (default) it infers the order from the order of the coords dictionary.
attrs (dict, optional) – dictionary to add as attributes to the xarray.DataArray. Defaults to None.
- Returns:
an xarray representing the data loaded from the .tiff file
- Return type:
xr.DataArray
- sed.io.to_tiff(data, faddr, alias_dict=None)
Save an array as a .tiff stack compatible with ImageJ
- Parameters:
data (Union[xr.DataArray, np.ndarray]) – data to be saved. If a np.ndarray, the order is retained. If it is an xarray.DataArray, the order is inferred from axis_dict instead. ImageJ likes tiff files with axis order as TZCYXS. Therefore, best axis order in input should be: Time, Energy, posY, posX. The channels ‘C’ and ‘S’ are automatically added and can be ignored.
faddr (Union[Path, str]) – full path and name of file to save.
alias_dict (dict, optional) – name pairs for correct axis ordering. Keys should be any of T,Z,C,Y,X,S. The Corresponding value should be a dimension of the xarray or the dimension number if a numpy array. This is used to sort the data in the correct order for imagej standards. If None it tries to guess the order from the name of the axes or assumes T,Z,C,Y,X,S order for numpy arrays. Defaults to None.
- Raises:
AttributeError – if more than one axis corresponds to a single dimension
NotImplementedError – if data is not 2,3 or 4 dimensional
TypeError – if data is not a np.ndarray or an xarray.DataArray
- sed.io.to_nexus(data, faddr, reader, definition, input_files, **kwds)
Saves the x-array provided to a NeXus file at faddr, using the provided reader, NeXus definition and configuration file.
- Parameters:
data (xr.DataArray) – The data to save, containing metadata definitions in data._attrs[“metadata”].
faddr (str) – The file path to save to.
reader (str) – The name of the NeXus reader to use.
definition (str) – The NeXus definiton to use.
config_file (str) – The file path to the configuration file to use.
**kwds – Keyword arguments for
nexusutils.dataconverter.convert.input_files (
typing.Union[str,typing.Sequence[str]]) –