spectrochempy.read_opus

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

Open Bruker OPUS file(s).

This is the explicit OPUS reader in the public import API. Use spectrochempy.read for generic format autodetection and scp.opus.read(...) or spectrochempy.read_opus when the OPUS format is already known.

Eventually group them in a single dataset. Returns an error if dimensions are incompatibles.

Non-merged multi-file reads may return a list-like ScpObjectList exposing helper methods for dataset selection. See spectrochempy.read for the complete description of the generic import convention and multi-object return behavior.

Parameters:
  • *paths (str, Path object objects or valid urls, 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., ( filename1, filename2, …, kwargs )

    If the list of filenames are enclosed into brackets:

    • e.g., ( [filename1, filename2, …], kwargs )

    The returned datasets are merged to form a single dataset, except if merge is set to False.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

  • type (str, optional) – The type of data to be read. Possible values are:

    • “AB”: Absorbance (default if present in the file)

    • “TR”: Transmittance

    • “KM”: Kubelka-Munk

    • “RAM”: Raman

    • “EMI”: Emission

    • “RFL”: Reflectance

    • “LRF”: log(Reflectance)

    • “ATR”: ATR

    • “PAS”: Photoacoustic

    • “RF”: Single-channel reference spectra

    • “SM”: Single-channel sample spectra

    • “IGRF”: Reference interferogram

    • “IGSM”: Sample interferogram

    • “PHRF”: Reference phase

    • “PHSM”: Sample phase

    • “TRACE”: Trace (intensity over time) for time-resolved files

    • “GCIG”: GC file (series of interferograms)

    • “GCSC”: GC file (series of spectra)

    An error is raised if the specified type is not present in the file.

Returns:

object (NDDataset or ScpObjectList of NDDataset) – The returned dataset(s). When several datasets are returned, the result is a list-like ScpObjectList with helper attributes such as .names, .select_largest(), .select_by_name(), .filter_by_ndim(), and .filter_by_shape().

Other Parameters:
  • 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 web application to handle drag and drop of files into a Browser.

  • csv_delimiter (str, optional, default: csv_delimiter) – Set the column delimiter in CSV file.

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

  • directory (Path object objects or valid urls, optional) – From where to read the files.

  • download_only (bool, optional, default: False) – Used only when url are specified. If True, only downloading and saving of the files is performed, with no attempt to read their content.

  • merge (bool, optional, default: False) – If True and several filenames or a directory have been provided as arguments, then a single NDDataset with merged dataset (stacked along the first dimension) is returned. In the case not all datasets have compatible dimensions or types/origins, then several NDDatasets can be returned for different groups of compatible datasets.

  • origin (str, optional) – If provided it may be used to define the type of experiment: e.g., ‘ir’, ‘raman’,.. or the origin of the data, e.g., ‘omnic’, ‘opus’, … It is often provided by the reader automatically, but can be set manually.

    It is used, for instance, when reading a directory with different types of files and merging compatible datasets into separate groups by origin.

    It is also used when reading with the CSV protocol. In order to properly interpret CSV file it can be necessary to set the origin of the spectra. Up to now only 'omnic' and 'tga' have been implemented.

  • pattern (str, optional) – A pattern to filter the files to read.

    Added in version 0.7.2.

  • protocol (str, optional) – Protocol used for reading, for example 'scp', 'omnic', 'opus', 'matlab', 'jcamp', 'csv', or 'excel'. If not provided, the correct protocol is inferred whenever possible from the filename extension.

  • read_only (bool, optional, default: True) – Used only when url are specified. If True, saving of the files is performed in the current directory, or in the directory specified by the directory parameter.

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

  • replace_existing (bool, optional, default: False) – Used only when url are specified. By default, existing files are not replaced so not downloaded.

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

See also

read

Generic reader inferring protocol from the filename extension.

spectrochempy.read_zip

Read Zip archives (containing spectrochempy readable files)

spectrochempy.read_dir

Read an entire directory.

spectrochempy.read_labspec

Read Raman LABSPEC spectra (.txt).

spectrochempy.read_omnic

Read Omnic spectra (.spa, .spg, .srs).

spectrochempy.read_soc

Read Surface Optics Corp. files (.ddr, .hdr, or .sdr).

spectrochempy.read_spc

Read Galactic files (.spc).

spectrochempy.read_quadera

Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.

spectrochempy.read_csv

Read CSV files (.csv).

spectrochempy.read_matlab

Read Matlab files (.mat, .dso).

spectrochempy.read_wire

Read Renishaw Wire files (.wdf).

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 )

>>> scp.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))

Using the explicit namespace API

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

Multiple files not merged (return a list-like multi-dataset result). 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
>>> names = le.names
>>> len(names)
3
>>> largest = le.select_largest()
>>> largest.ndim
2

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)
2

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

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

Bruker OPUS files often contain several types of data (AB, RF, IGSM …). In some cases, the type of data can be inferred from the file content. For instance, if the file contains a single background spectrum, it is inferred as a reference spectrum. In the following example, the file background.0 is correctly inferred as a reference spectrum.

>>> B = scp.read_opus('irdata/OPUS/background.0')
>>> B
NDDataset: [float64] a.u. (shape: (y:1, x:4096))

If the type of data can not be inferred, an error is raised. In the following example, if the file test.0000 contains only sample spectra (SM), the type of data must be specified.

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

Examples using spectrochempy.read_opus

Loading Bruker OPUS files

Loading Bruker OPUS files