5.3.1.7.2.4.2. cli.cmd_etl.etl.convert.Converter
- class cli.cmd_etl.etl.convert.Converter(data_path: Path, recursive: bool, conversion_settings: ConversionSettings)
Bases:
objectHigh-level converter that discovers files and transforms them.
The converter accepts either a single file path or a directory. When a directory is provided, it can optionally traverse subdirectories to find files that match the configured input format. Each discovered file is read and written in the configured output format. Errors (e.g., missing paths, permission issues) are reported and cause the process to exit with a non-zero status.
- convert() None
Discover and convert all matching files.
Behavior:
Verifies that the provided data path exists.
If it’s a file, converts exactly that file.
If it’s a directory, collects all files with the expected input suffix. When ‘recursive’ is True, includes subdirectories.
For each discovered file, delegates to ‘_convert’.
Exits:
Prints an error and exits with status 1 if the path does not exist or an OS-related error occurs (including permission issues).
- read_gamry(file_path: Path) DataFrame | None
Read a Gamry .DTA file and return its content as a DataFrame.
The method detects the start of the tabular section by scanning for the line containing the literal ‘TABLE’. All lines before (and including) that line are skipped. The data is then parsed via pandas.read_csv with:
Tab as field separator.
Two-row header (MultiIndex), where the second header row is dropped.
Comma as decimal separator.
Optional ‘skip_footer’ lines ignored at the end (if provided).
The resulting DataFrame is post-processed by:
Dropping the second header level.
Dropping the first column ‘Pt’, which is considered an index/counter.
- Parameters:
file_path – Path to the .dta file.
- Returns:
A pandas DataFrame with cleaned columns and without the ‘Pt’ column. Returns None if the ‘TABLE’ marker cannot be found.
Notes
‘skip_footer’ is read from ‘conversion_settings.additional’. If not set or falsy, it defaults to 0.
- read_graphtec(file_path: Path) DataFrame | None
Read a Graphtec CSV export and return a cleaned DataFrame.
The reader expects a CSV with a two-row column header and a 32-line preamble. It flattens the header, removes the leading non-data/index column, combines the “Date&Time” and “ms” columns into a single pandas datetime, and drops the original “ms” column.
- Parameters:
file_path (Path) – Path to the Graphtec CSV file.
- Returns:
DataFrame where:
”Date&Time” is datetime64[ns] (date/time plus milliseconds).
Measurement channels remain as subsequent columns.
The “ms” column is removed.
Returns None if upstream logic intends to signal no data.
- Return type:
pd.DataFrame or None
- Raises:
FileNotFoundError – If the file does not exist.
pandas.errors.ParserError – If the CSV cannot be parsed.
KeyError – If required columns (“Date&Time”, “ms”) are missing.
Notes
The header offset is fixed at 32 lines; adjust if your export differs.
Columns are assumed to include “Date&Time” and “ms”.