spectrochempy.read_omnic
- read_omnic(*paths, **kwargs)[source][source]
Open a Thermo Nicolet OMNIC file.
Open Omnic file or a list of
.spg
,.spa
or.srs
files 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 if attempt is made to inconsistent datasets: units of spectra and xaxis, limits and number of points of the xaxis.
- 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 toFalse
.If a source is not provided (i.e., no
paths
, norcontent
), a dialog box will be opened to select files.**kwargs (keyword parameters, optional) – See Other Parameters.
- Returns:
object (
NDDataset
or list ofNDDataset
) – The returned dataset(s).- Other Parameters:
protocol (
str
, optional) –Protocol
used for reading. It can be one of {'scp'
,'omnic'
,'opus'
,'topspin'
,'matlab'
,'jcamp'
,'csv'
,'excel'
}. If not provided, the correct protocol is inferred (whenever it is possible) from the filename extension.directory (
Path
object objects or valid urls, optional) – From where to read the files.merge (
bool
, optional, default:False
) – IfTrue
and several filenames or adirectory
have been provided as arguments, then a singleNDDataset
with merged (stacked along the first dimension) is returned.sortbydate (
bool
, optional, default:True
) – Sort multiple filename by acquisition date.description (
str
, optional) – A Custom description.origin (one of {
'omnic'
,'tga'
}, optional) – 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.csv_delimiter (
str
, optional, default:csv_delimiter
) – Set the column delimiter in CSV file.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.iterdir (
bool
, optional, default:True
) – IfTrue
and no filename was provided, all files present in the provideddirectory
are returned (and merged ifmerge
isTrue
. It is assumed that all the files correspond to current reading protocol.Changed in version 0.6.2:
iterdir
replace the deprecatedlistdir
argument.
See also
read_spg
Read grouped Omnic spectra.
read_spa
Read single Omnic spectra.
read_srs
Read series Omnic spectra.
read
Generic reader inferring protocol from the filename extension.
read_zip
Read Zip archives (containing spectrochempy readable files)
read_dir
Read an entire directory.
read_opus
Read OPUS spectra.
read_labspec
Read Raman LABSPEC spectra (
.txt
).read_soc
Read Surface Optics Corps. files (
.ddr
,.hdr
or.sdr
).read_galactic
Read Galactic files (
.spc
).read_quadera
Read a Pfeiffer Vacuum’s QUADERA mass spectrometer software file.
read_topspin
Read TopSpin Bruker NMR spectra.
read_csv
Read CSV files (
.csv
).read_jcamp
Read Infrared JCAMP-DX files (
.jdx
,.dx
).read_matlab
Read Matlab files (
.mat
,.dso
).read_carroucell
Read files in a directory after a carroucell experiment.
read_wire
Read REnishaw Wire files (
.wdf
).
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))
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))
The directory can also be specified independently, either as a string or a pathlib object
>>> scp.read_omnic('nh4y-activation.spg', directory=folder) NDDataset: [float64] a.u. (shape: (y:55, x:5549))
Multiple files not merged (return a list of datasets)
>>> 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
merge
keyword 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 (note the brakets) 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
merge
is set to false>>> l2 = scp.read_omnic(['irdata/nh4y-activation.spg', 'wodger.spg'], merge=False) >>> len(l2) 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 OPUS files are present in the directory (else we must use the generic
read
function instead)>>> l3 = scp.read_omnic(directory='irdata/subdir/1-20') >>> len(l3) 3
Again we can use merge to stack all 4 spectra if thet have compatible dimensions.
>>> scp.read_omnic(directory='irdata/subdir', merge=True) NDDataset: [float64] a.u. (shape: (y:4, x:5549))
An example, where bytes contents are passed directly to the read_omnic method.
>>> datadir = scp.preferences.datadir >>> filename1 = datadir / 'irdata' / 'subdir' / '7_CZ0-100 Pd_101.SPA' >>> content1 = filename1.read_bytes() >>> filename2 = datadir / 'wodger.spg' >>> content2 = filename2.read_bytes() >>> listnd = scp.read_omnic({filename1.name: content1, filename2.name: content2}) >>> len(listnd) 2 >>> scp.read_omnic({filename1.name: content1, filename2.name: content2}, merge=True) NDDataset: [float64] a.u. (shape: (y:3, x:5549))