spectrochempy.read_opus

read_opus(*paths, **kwargs)[source]

Open Bruker OPUS file(s).

Eventually group them in a single dataset. Only Absorbance spectra are extracted (“AB” field). Returns an error if dimensions are incompatibles.

Parameters
  • *paths (str, pathlib.Path object, list of str, or list of pathlib.Path objects, optional) – The data source(s) can be specified by the name or a list of name for the file(s) to be loaded:

    e.g.,( file1, file2, …, **kwargs )

    If the list of filenames are enclosed into brackets:

    e.g., ( [ file1, file2, … ], **kwargs )

    The returned datasets are merged to form a single dataset, except if merge is set to False. If a source is not provided (i.e. no filename, nor content), a dialog box will be opened to select files.

  • **kwargs – Optional keyword parameters (see Other Parameters).

Returns

read_opus – The dataset or a list of dataset corresponding to a (set of) OPUS file(s).

Other Parameters
  • protocol ({‘scp’, ‘omnic’, ‘opus’, ‘topspin’, ‘matlab’, ‘jcamp’, ‘csv’, ‘excel’}, optional) – Protocol used for reading. If not provided, the correct protocol is inferred (whnever it is possible) from the file name extension.

  • directory (str, optional) – From where to read the specified filename. If not specified, read in the default datadir specified in SpectroChemPy Preferences.

  • merge (bool, optional) – Default value is False. If True, and several filenames have been provided as arguments, then a single dataset with merged (stacked along the first dimension) is returned (default=False).

  • sortbydate (bool, optional) – Sort multiple spectra by acquisition date (default=True).

  • description (str, optional) – A Custom description.

  • content (bytes object, optional) – Instead of passing a filename for further reading, a bytes content can be directly provided as bytes objects. The most convenient way is to use a dictionary. This feature is particularly useful for a GUI Dash application to handle drag and drop of files into a Browser. For examples on how to use this feature, one can look in the tests/tests_readers directory.

  • listdir (bool, optional) – If True and filename is None, all files present in the provided directory are returned (and merged if merge is True. It is assumed that all the files correspond to current reading protocol (default=True).

  • recursive (bool, optional) – Read also in subfolders. (default=False).

See also

read

Generic read method.

read_topspin

Read TopSpin Bruker NMR spectra.

read_omnic

Read Omnic spectra.

read_labspec

Read Raman LABSPEC spectra.

read_spg

Read Omnic *.spg grouped spectra.

read_spa

Read Omnic *.Spa single spectra.

read_srs

Read Omnic series.

read_csv

Read CSV files.

read_zip

Read Zip files.

read_matlab

Read Matlab files.

Examples

Reading a single OPUS file (providing a windows type filename relative to the default Datadir)

>>> scp.read_opus('irdata\\OPUS\\test.0000')
NDDataset: [float64] a.u. (shape: (y:1, x:2567))

Reading a single OPUS file (providing a unix/python type filename relative to the default Datadir) Note that here read_opus is called as a classmethod of the NDDataset class

>>> scp.NDDataset.read_opus('irdata/OPUS/test.0000')
NDDataset: [float64] a.u. (shape: (y:1, x:2567))

Single file specified with pathlib.Path object

>>> from pathlib import Path
>>> folder = Path('irdata/OPUS')
>>> p = folder / 'test.0000'
>>> scp.read_opus(p)
NDDataset: [float64] a.u. (shape: (y:1, x:2567))

Multiple files not merged (return a list of datasets). Note that a directory is specified

>>> le = scp.read_opus('test.0000', 'test.0001', 'test.0002', directory='irdata/OPUS')
>>> len(le)
3
>>> le[0]
NDDataset: [float64] a.u. (shape: (y:1, x:2567))

Multiple files merged as the merge keyword is set to true

>>> scp.read_opus('test.0000', 'test.0001', 'test.0002', directory='irdata/OPUS', merge=True)
NDDataset: [float64] a.u. (shape: (y:3, x:2567))

Multiple files to merge : they are passed as a list instead of using the keyword merge

>>> scp.read_opus(['test.0000', 'test.0001', 'test.0002'], directory='irdata/OPUS')
NDDataset: [float64] a.u. (shape: (y:3, x:2567))

Multiple files not merged : they are passed as a list but merge is set to false

>>> le = scp.read_opus(['test.0000', 'test.0001', 'test.0002'], directory='irdata/OPUS', merge=False)
>>> len(le)
3

Read without a filename. This has the effect of opening a dialog for file(s) selection

>>> nd = scp.read_opus()

Read in a directory (assume that only OPUS files are present in the directory (else we must use the generic read function instead)

>>> le = scp.read_opus(directory='irdata/OPUS')
>>> len(le)
4

Again we can use merge to stack all 4 spectra if thet have compatible dimensions.

>>> scp.read_opus(directory='irdata/OPUS', merge=True)
NDDataset: [float64] a.u. (shape: (y:4, x:2567))