silx.io: Input-output¶
Top-level functions¶
-
silx.io.open(filename)[source]¶ Open a file as an h5py-like object.
Format supported: - h5 files, if h5py module is installed - SPEC files exposed as a NeXus layout - raster files exposed as a NeXus layout (if fabio is installed) - Numpy files (‘npy’ and ‘npz’ files)
The filename can be trailled an HDF5 path using the separator ::. In this case the object returned is a proxy to the target node, implementing the close function and supporting with context.
The file is opened in read-only mode.
Parameters: filename (str) – A filename which can containt an HDF5 path by using :: separator. Raises: IOError if the file can’t be loaded or path can’t be found Return type: h5py-like node
-
silx.io.save1D(fname, x, y, xlabel=None, ylabels=None, filetype=None, fmt='%.7g', csvdelim=';', newline='\n', header='', footer='', comments='#', autoheader=False)[source]¶ Saves any number of curves to various formats: Specfile, CSV, txt or npy. All curves must have the same number of points and share the same
xvalues.Parameters: - fname – Output file path, or file handle open in write mode.
If
fnameis a path, file is opened inwmode. Existing file with a same name will be overwritten. - x – 1D-Array (or list) of abscissa values.
- y – 2D-array (or list of lists) of ordinates values. First index
is the curve index, second index is the sample index. The length
of the second dimension (number of samples) must be equal to
len(x).ycan be a 1D-array in case there is only one curve to be saved. - filetype – Filetype:
"spec", "csv", "txt", "ndarray". IfNone, filetype is detected from file name extension (.dat, .csv, .txt, .npy). - xlabel – Abscissa label
- ylabels – List of y labels
- fmt – Format string for data. You can specify a short format
string that defines a single format for both
xandyvalues, or a list of two different format strings (e.g.["%d", "%.7g"]). Default is"%.7g". This parameter does not apply to the npy format. - csvdelim – String or character separating columns in txt and CSV formats. The user is responsible for ensuring that this delimiter is not used in data labels when writing a CSV file.
- newline – String or character separating lines/records in txt
format (default is line break character
\n). - header – String that will be written at the beginning of the file in txt format.
- footer – String that will be written at the end of the file in txt format.
- comments – String that will be prepended to the
headerandfooterstrings, to mark them as comments. Default:#. - autoheader – In CSV or txt,
Truecauses the first header line to be written as a standard CSV header line with column labels separated by the specified CSV delimiter.
When saving to Specfile format, each curve is saved as a separate scan with two data columns (
xandy).CSV and txt formats are similar, except that the txt format allows user defined header and footer text blocks, whereas the CSV format has only a single header line with columns labels separated by field delimiters and no footer. The txt format also allows defining a record separator different from a line break.
The npy format is written with
numpy.saveand can be read back withnumpy.load. Ifxlabelandylabelsare undefined, data is saved as a regular 2Dnumpy.ndarray(contatenation ofxandy). If bothxlabelandylabelsare defined, the data is saved as anumpy.recarrayafter being transposed and having labels assigned to columns.- fname – Output file path, or file handle open in write mode.
If
-
silx.io.is_dataset(obj)[source]¶ True if the object is a h5py.Dataset-like object.
Parameters: obj – An object
-
silx.io.is_group(obj)[source]¶ True if the object is a h5py.Group-like object.
Parameters: obj – An object