def _read_dir(*args, **kwargs): _, directory = args directory = readdirname(directory) files = get_filename(directory, **kwargs) datasets = [] for key in files.keys(): if key: importer = Importer() nd = importer(files[key], **kwargs) if not isinstance(nd, list): nd = [nd] datasets.extend(nd) return datasets
def read_dir(directory=None, **kwargs): """ Read an entire directory. Open a list of readable files in a and store data/metadata in a dataset or a list of datasets according to the following rules : * 2D spectroscopic data (e.g. valid *.spg files or matlab arrays, etc...) from distinct files are stored in distinct NDdatasets. * 1D spectroscopic data (e.g., *.spa files) in a given directory are grouped into single NDDataset, providing their unique dimension are compatible. If not, an error is generated. Parameters ---------- directory : str or pathlib Folder where are located the files to read. Returns -------- read_dir |NDDataset| or list of |NDDataset|. Depending on the python version, the order of the datasets in the list may change. See Also -------- read_topspin : Read TopSpin Bruker NMR spectra. read_omnic : Read Omnic spectra. read_opus : Read OPUS 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 -------- >>> import spectrochempy as scp >>> scp.preferences.csv_delimiter = ',' >>> A = scp.read_dir('irdata') >>> len(A) 4 >>> B = scp.NDDataset.read_dir() """ kwargs['listdir'] = True importer = Importer() return importer(directory, **kwargs)
def read_labspec(*paths, **kwargs): """ Read a single Raman spectrum or a series of Raman spectra. Files to open are *.txt file created by Labspec software. Non-labspec .txt files are ignored (return None) 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 |NDDataset| or list of |NDDataset| or None. 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_opus : Read OPUS 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 -------- >>> A = scp.read_labspec('ramandata/Activation.txt') """ kwargs["filetypes"] = ["LABSPEC exported files (*.txt)"] kwargs["protocol"] = ["labspec", "txt"] importer = Importer() return importer(*paths, **kwargs)
def read_jcamp(*paths, **kwargs): """ Open Infrared JCAMP-DX files with extension ``.jdx`` or ``.dx``. Limited to AFFN encoding (see R. S. McDonald and Paul A. Wilks, JCAMP-DX: A Standard Form for Exchange of Infrared Spectra in Computer Readable Form, Appl. Spec., 1988, 1, 151–162. doi:10.1366/0003702884428734.) 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 : dict See other parameters. Returns -------- read_jcamp |NDDataset| or list of |NDDataset|. 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 exemples 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_opus : Read OPUS 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. """ kwargs['filetypes'] = ['JCAMP-DX files (*.jdx *.dx)'] kwargs['protocol'] = ['jcamp'] importer = Importer() return importer(*paths, **kwargs)
def read_srs(*paths, **kwargs): """ Open a Thermo Nicolet file or a list of files with extension ``.srs``. Open Omnic file or a list of files with extension ``.srs`` and set data/metadata in the current dataset. 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 -------- NDDataset The dataset or a list of dataset corresponding to a (set of) series or backgroun files. Other Parameters ----------------- return_bg : bool, optional Default value is False. When set to 'True' returns the series background 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_opus : Read OPUS spectra. read_labspec : Read Raman LABSPEC spectra. read_spg : Read Omnic *.spg grouped spectra. read_spa : Read Omnic *.Spa single spectra. read_csv : Read CSV files. read_zip : Read Zip files. read_matlab : Read Matlab files. Notes ----- This method is an alias of ``read_omnic``, except that the type of file is constrained to *.srs. Examples --------- >>> scp.read_srs('irdata/omnic_series/rapid_scan_reprocessed.srs') NDDataset: [float64] a.u. (shape: (y:643, x:3734)) """ kwargs["filetypes"] = ["OMNIC series (*.srs)"] kwargs["protocol"] = ["srs"] importer = Importer() return importer(*paths, **kwargs)
def read_sdr(*paths, **kwargs): """ Open a Surface Optics Corps. file or a list of files with extension ``.sdr``. Open Surface Optics Corps. file or a list of files with extension ``.sdr`` and set data/metadata in the current dataset. 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_ddr The dataset or a list of dataset corresponding to the (set of) file(s). Other Parameters ----------------- return_ifg : str or None, optional Default value is None. When set to 'sample' returns the sample interferogram of the spa file if present or None if absent. When set to 'background' returns the backgroung interferogram of the spa file if present or None if absent. 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. Examples --------- """ kwargs["filetypes"] = ["Surface Optics Corp. (*.sdr)"] kwargs["protocol"] = ["sdr"] importer = Importer() return importer(*paths, **kwargs)
def read_omnic(*paths, **kwargs): """ Open a Thermo Nicolet OMNIC file. Open Omnic file or a list of files with extension ``.spg`` , ``.spa`` or ``.srs`` 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, 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 -------- out The dataset or a list of dataset corresponding to a (set of) .spg, .spa or .srs file(s). Other Parameters ----------------- 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_dir : Read a set of data from a directory. read_spg : Read Omnic files .spg. read_spa : Read Omnic files .spa. read_srs : Read Omnic files .srs. read_opus : Read Bruker OPUS files. read_topspin : Read TopSpin NMR files. read_csv : Read .csv. read_matlab : Read MATLAB files .mat. read_zip : Read zipped group of files. 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.NDDataset.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)) """ kwargs["filetypes"] = ["OMNIC files (*.spa *.spg)", "OMNIC series (*.srs)"] kwargs["protocol"] = ["omnic", "spa", "spg", "srs"] importer = Importer() return importer(*paths, **kwargs)
def read_opus(*paths, **kwargs): """ 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)) """ kwargs["filetypes"] = ["Bruker OPUS files (*.[0-9]*)"] kwargs["protocol"] = ["opus"] importer = Importer() return importer(*paths, **kwargs)
def read_topspin(*paths, **kwargs): """ Open Bruker TOPSPIN (NMR) dataset. Parameters ---------- *paths : str, optional Paths of the Bruker directories to read. **kwargs Optional keyword parameters (see Other Parameters). Returns -------- read_topspin |NDDataset| or list of |NDDataset|. Other Parameters ---------------- expno : int, optional experiment number. procno : int processing number. 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. origin : {'omnic', 'tga'}, optional 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 Set the column delimiter in CSV file. By default it is the one set in SpectroChemPy ``Preferences``. 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_topspin : Read TopSpin Bruker NMR spectra. read_omnic : Read Omnic spectra. read_opus : Read OPUS 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. """ kwargs["filetypes"] = [ "Bruker TOPSPIN fid's or processed data files (fid ser 1[r|i] 2[r|i]* 3[r|i]*)", "Compressed TOPSPIN data directories (*.zip)", ] kwargs["protocol"] = ["topspin"] importer = Importer() return importer(*paths, **kwargs)
def read_zip(*paths, **kwargs): """ Open a zipped list of data files. 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 : dict See other parameters. Returns -------- read_zip |NDDataset| or list of |NDDataset|. 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. origin : {'omnic', 'tga'}, optional 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 Set the column delimiter in CSV file. By default it is the one set in SpectroChemPy ``Preferences``. 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 exemples 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_topspin : Read TopSpin Bruker NMR spectra. read_omnic : Read Omnic spectra. read_opus : Read OPUS 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 -------- >>> import spectrochempy as scp >>> A = scp.read_zip('agirdata/P350/FTIR/FTIR.zip', only=50, origin='omnic') >>> print(A) NDDataset: [float64] a.u. (shape: (y:50, x:2843)) """ kwargs['filetypes'] = ['Compressed files (*.zip)'] # TODO: allows other type of compressed files kwargs['protocol'] = ['zip'] importer = Importer() return importer(*paths, **kwargs)
def read_quadera(*paths, **kwargs): """ Read a Pfeiffer Vacuum's QUADERA® mass spectrometer software file with extension ``.asc`` and return its content as dataset. 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 : dict See other parameters. Returns -------- read_quadera |NDDataset| or list of |NDDataset|. Other Parameters ---------------- timestamp: bool, optional returns the acquisition timestamp as Coord (Default=True). If set to false, returns the time relative to the acquisition time of the data protocol : {'scp', 'omnic', 'opus', 'topspin', 'matlab', 'jcamp', 'csv', 'excel', 'asc'}, 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) 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 exemples 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) Examples --------- >>> import spectrochempy as scp >>> scp.read_quadera('msdata/ion_currents.asc') NDDataset: [float64] A (shape: (y:16975, x:10)) Notes: ------ Currently the acquisition time is that of the first channel as the timeshift of other channels are typically within few seconds, and the data of other channels are NOT interpolated Todo: check with users wether data interpolation should be made See Also -------- read : Read generic files. read_topspin : Read TopSpin Bruker NMR spectra. read_omnic : Read Omnic spectra. read_opus : Read OPUS 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. """ kwargs['filetypes'] = ['Quadera files (*.asc)'] kwargs['protocol'] = ['asc'] importer = Importer() return importer(*paths, **kwargs)
def read_matlab(*paths, **kwargs): """ Read a matlab file with extension ``.mat`` and return its content as a list. The array of numbers (i.e. matlab matrices) and Eigenvector's DataSet Object (DSO, see `DSO <https://www.eigenvector.com/software/dataset.htm>`_ ) are returned as NDDatasets. The content not recognized by SpectroChemPy is returned as a tuple (name, object). 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_matlab |NDDataset| or list of |NDDataset|. 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) 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) Examples --------- >>> scp.read_matlab('matlabdata/dso.mat') NDDataset: [float64] unitless (shape: (y:20, x:426)) See ``read_omnic`` for more examples of use See Also -------- read : Read generic files. read_topspin : Read TopSpin Bruker NMR spectra. read_omnic : Read Omnic spectra. read_opus : Read OPUS 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. """ kwargs["filetypes"] = ["MATLAB files (*.mat *.dso)"] kwargs["protocol"] = ["matlab", "mat", "dso"] importer = Importer() return importer(*paths, **kwargs)
def read_carroucell(directory=None, **kwargs): """ Open .spa files in a directory after a carroucell experiment. The files for a given sample are grouped in NDDatasets (sorted by acquisition date). The NDDatasets are returned in a list sorted by sample number. When the file containing the temperature data is present, the temperature is read and assigned as a label to each spectrum. Parameters ---------- directory : str, optional If not specified, opens a dialog box. **kwargs Optional keyword parameters. See Other Parameters. Other Parameters ---------------- spectra : arraylike of 2 int (min, max), optional, default=None The first and last spectrum to be loaded as determined by their number. If None all spectra are loaded. discardbg : bool, optional, default=True If True : do not load background (sample #9). delta_clocks : int, optional, default=0 Difference in seconds between the clocks used for spectra and temperature acquisition. Defined as t(thermocouple clock) - t(spectrometer clock). Returns -------- nddataset |NDDataset| or list of |NDDataset|. See Also -------- read_topspin : Read TopSpin Bruker NMR spectra. read_omnic : Read Omnic spectra. read_opus : Read OPUS 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. Notes ------ All files are expected to be present in the same directory and their filenames are expected to be in the format : X_samplename_YYY.spa and for the background files : X_BCKG_YYYBG.spa where X is the sample holder number and YYY the spectrum number. Examples -------- >>> scp.read_carroucell("irdata/carroucell_samp") no temperature file [NDDataset: [float64] a.u. (shape: (y:6, x:11098)), NDDataset: ... """ kwargs["filetypes"] = ["Carroucell files (*.spa)"] kwargs["protocol"] = ["carroucell"] importer = Importer() return importer(directory, **kwargs)
def read_csv(*paths, **kwargs): """ Open a *.csv file or a list of *.csv files. This is limited to 1D array - csv file must have two columns [index, data] without header. 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_csv |NDDataset| or list of |NDDataset|. Other Parameters ---------------- 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. origin : {'omnic', 'tga'}, optional 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 Set the column delimiter in CSV file. By default it is the one set in SpectroChemPy ``Preferences``. 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_topspin : Read TopSpin Bruker NMR spectra. read_omnic : Read Omnic spectra. read_opus : Read OPUS spectra. read_spg : Read Omnic *.spg grouped spectra. read_spa : Read Omnic *.Spa single spectra. read_srs : Read Omnic series. read_zip : Read Zip files. read_matlab : Read Matlab files. read : Generic file reading. Examples --------- >>> scp.read_csv('agirdata/P350/TGA/tg.csv') NDDataset: [float64] unitless (shape: (y:1, x:3247)) Additional information can be stored in the dataset if the origin is given (known origin for now : tga or omnic) # TODO: define some template to allow adding new origins >>> scp.read_csv('agirdata/P350/TGA/tg.csv', origin='tga') NDDataset: [float64] wt.% (shape: (y:1, x:3247)) Sometimes the delimiteur needs to be adjusted >>> prefs = scp.preferences >>> scp.read_csv('irdata/IR.CSV', directory=prefs.datadir, origin='omnic', csv_delimiter=',') NDDataset: [float64] a.u. (shape: (y:1, x:3736)) """ kwargs["filetypes"] = ["CSV files (*.csv)"] kwargs["protocol"] = ["csv"] importer = Importer() return importer(*paths, **kwargs)
def _read_fk(*args, **kwargs): return Importer._read_fake(*args, **kwargs)
def read_fake(*paths, **kwargs): kwargs["filetypes"] = ["FAKE files (*fk, *.fk1, .fk2)"] kwargs["protocol"] = ["fake", ".fk", "fk1", "fk2"] importer = Importer() return importer(*paths, **kwargs)