You're reading the documentation for a development version. For the latest released version, please have a look at v0.5.
cwepr.io.txt_file module
Importer for simple text and CSV files.
Despite its obvious limitations (normally no metadata, limited resolution, large files) text or CSV files are an often-encountered exchange format and can serve as an easy way to import data from otherwise not supported file formats, as nearly every software to record data allows to export these data as simple text or CSV files.
You may have a look as well at the importers provided by the ASpecD package
for similar situations, particularly aspecd.io.TxtImporter
.
- class cwepr.io.txt_file.TxtImporter(source='')
Bases:
TxtImporter
Importer for text files with various delimiters and separators.
Automatically detects the extension of a file. Therefore, the importer should be given explicitly in the recipe if it is different from “.txt”.
Due to the inherent lacking of metadata in text files despite their widespread use, the importer adds three values as metadata in order to get the axis label for the magnetic field axis correctly:
Unit of the first axis: mT
Quantity of the fist axis: magnetic field
Quantity of the second axis: intensity
- parameters
Parameters controlling the import
- skiprows
int
Number of rows to skip in text file (e.g., header lines)
- delimiter
str
The string used to separate values.
Default: None (meaning: whitespace)
- comments
str
|list
Characters or list of characters indicating the start of a comment.
Default: #
- separator
str
Character used as decimal separator.
Default: None (meaning: dot)
- Type:
- skiprows
Examples
For convenience, a series of examples in recipe style (for details of the recipe-driven data analysis, see
aspecd.tasks
) is given below for how to make use of this class. The examples focus each on a single aspect.The most general and simple case, using only default values:
datasets: - eprdata.txt
However, you can control the import in quite some detail, with respect to delimiter, decimal separator, rows to skip from the top, and comment character. A full example setting each of these parameters may look as follows:
datasets: - source: eprdata.txt importer_parameters: delimiter: '\t' separator: ',' skiprows: 3 comments: '%'
Here, the delimiter between columns is the tabulator, the decimal separator the comma, the first three lines are skipped by default as well as every line starting with a percent character, as this is interpreted as comment.
A frequent use case is importing simulations that were carried out with EasySpin. A MATLAB excerpt for saving the simulated spectrum might look as follows:
[B_sim_iso, Spc_sim_iso] = garlic(Sys, Exp); data = [B_sim_iso', Spc_sim_iso']; writematrix(data, 'Simulated-spectrum')
Read in the simulated spectrum with:
datasets: - source: Simulated-spectrum.txt id: simulation importer: TxtImporter importer_parameters: delimiter: ','
Changed in version 0.5: Renamed from CsvImporter to TxtImporter and generalised handling of text files. Now inherits from
aspecd.io.TxtImporter
.
- class cwepr.io.txt_file.CsvImporter(source='')
Bases:
TxtImporter
Simple importer for csv files containing EPR data.
The delimiter defaults to the comma, as the name implies, but you can set the delimiter as well as other parameters explicitly. See
TxtImporter
for details.Due to the inherent lacking of metadata in text files despite their widespread use, the importer adds three values as metadata in order to get the axis label for the magnetic field axis correctly:
Unit of the first axis: mT
Quantity of the fist axis: magnetic field
Quantity of the second axis: intensity
Changed in version 0.5: Renamed from CsvImporter to TxtImporter and generalised handling of text files. Now inherits from
TxtImporter
.