spectrochempy.read_omnic
- read_omnic(*paths, **kwargs)[source]
Open a Thermo Nicolet OMNIC file.
This is the explicit OMNIC reader in the public import API. Use
spectrochempy.readfor generic format autodetection andscp.omnic.read(...)orspectrochempy.read_omnicwhen the OMNIC format is already known.Open Omnic file or a list of
.spg,.spaor.srsfiles and set data/metadata in the current dataset.The collected metadata are: - names of spectra - acquisition dates (UTC) - units of spectra (absorbance, transmittance, reflectance, Log(1/R), Kubelka-Munk, Raman intensity, photoacoustics, volts) - units of xaxis (wavenumbers in \(cm^{-1}\), wavelengths in nm or micrometer, Raman shift in \(cm^{-1}\)) - spectra history (but only incorporated in the NDDataset if a single spa is read)
An error is generated when an SPG file contains spectra with inconsistent x-axis definitions, unless
allow_inconsistent_x=Trueis specified. In that case, a list containing oneNDDatasetper spectrum is returned.Non-merged multi-file reads may also return a list-like
ScpObjectListexposing helper methods for dataset selection. Seespectrochempy.readfor the complete description of the generic import convention and multi-object return behavior.- Parameters:
*paths (
str,Pathobject 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
mergeis set toFalse.**kwargs (keyword parameters, optional) – See Other Parameters.
- Returns:
object (
NDDatasetorScpObjectListofNDDataset) – The returned dataset(s). When several datasets are returned, the result is a list-likeScpObjectListwith helper attributes such as.names,.select_largest(),.select_by_name(),.filter_by_ndim(), and.filter_by_shape().- Other Parameters:
content (
bytesobject, 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.csv_delimiter (
str, optional, default:csv_delimiter) – Set the column delimiter in CSV file.description (
str, optional) – A custom description.directory (
Pathobject 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) – IfTrueand several filenames or adirectoryhave been provided as arguments, then a singleNDDatasetwith 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) –Protocolused 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.allow_inconsistent_x (
bool, optional, default:False) – Allow SPG files whose spectra have different x-axis definitions. When enabled, return oneNDDatasetper spectrum instead of merging the spectra. This option has no effect on SPA or SRS files.
See also
readGeneric reader inferring protocol from the filename extension.
spectrochempy.read_zipRead Zip archives (containing spectrochempy readable files)
spectrochempy.read_dirRead an entire directory.
spectrochempy.read_opusRead OPUS spectra.
spectrochempy.read_labspecRead Raman LABSPEC spectra (
.txt).spectrochempy.read_omnicRead Omnic spectra (
.spa,.spg,.srs).spectrochempy.read_socRead Surface Optics Corp. files (
.ddr,.hdr, or.sdr).spectrochempy.read_spcRead Galactic files (
.spc).spectrochempy.read_quaderaRead a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.
spectrochempy.read_csvRead CSV files (
.csv).spectrochempy.read_matlabRead Matlab files (
.mat,.dso).spectrochempy.read_wireRead Renishaw Wire files (
.wdf).spectrochempy.read_spgAlias of
read_omnic.spectrochempy.read_spaAlias of
read_omnic.spectrochempy.read_srsAlias of
read_omnic.
Examples
Reading a single OMNIC file (providing a windows type filename relative to the default
datadir)>>> scp.read_omnic('irdata\\nh4y-activation.spg') NDDataset: [float64] a.u. (shape: (y:55, x:5549))
Reading a single OMNIC file (providing a unix/python type filename relative to the default
datadir)Note that here read_omnic is called as a classmethod of the NDDataset class
>>> scp.read_omnic('irdata/nh4y-activation.spg') NDDataset: [float64] a.u. (shape: (y:55, x:5549))
Using the explicit namespace API
>>> scp.omnic.read('irdata/nh4y-activation.spg') NDDataset: [float64] a.u. (shape: (y:55, x:5549))
Single file specified with pathlib.Path object
>>> from pathlib import Path >>> folder = Path('irdata') >>> p = folder / 'nh4y-activation.spg' >>> scp.read_omnic(p) NDDataset: [float64] a.u. (shape: (y:55, x:5549))
Multiple files not merged (return a list-like multi-dataset result). Note that a directory is specified
>>> le = scp.read_omnic('irdata/nh4y-activation.spg', 'wodger.spg') >>> len(le) 2 >>> le[1] NDDataset: [float64] a.u. (shape: (y:55, x:5549))
Multiple files merged as the
mergekeyword is set to true>>> scp.read_omnic('irdata/nh4y-activation.spg', 'wodger.spg', merge=True) NDDataset: [float64] a.u. (shape: (y:57, x:5549))
Multiple files to merge : they are passed as a list instead of using the keyword
merge>>> scp.read_omnic(['irdata/nh4y-activation.spg', 'wodger.spg']) NDDataset: [float64] a.u. (shape: (y:57, x:5549))
Multiple files not merged : they are passed as a list but
mergeis set to false>>> l2 = scp.read_omnic(['irdata/nh4y-activation.spg', 'wodger.spg'], merge=False) >>> len(l2) 2 >>> names = l2.names >>> len(names) 2 >>> largest = l2.select_largest() >>> largest.ndim 2
Read without a filename. This has the effect of opening a dialog for file(s) selection
>>> nd = scp.read_omnic()
Read in a directory (assume that only OMNIC files are present in the directory (else we must use the generic
readfunction instead)>>> l3 = scp.read_omnic(directory='irdata/OMNIC/1-20') >>> len(l3) 3
Again we can use merge to stack all 4 spectra if they have compatible dimensions.
>>> scp.read_omnic(directory='irdata/OMNIC/1-20', merge=True) [NDDataset: [float64] a.u. (shape: (y:1, x:5549)), NDDataset: [float64] a.u. (shape: (y:4, x:5549))]
Examples using spectrochempy.read_omnic
Mask a saturated region and transform an IR dataset