Parsing API Reference¶
Import: from ecgdatakit import FileParser, parse_batch
Auto-detect format and parse any supported ECG file |
|
Base class for all ECG format parsers |
|
Parse multiple ECG files in parallel |
FileParser¶
- class ecgdatakit.parsing.parser.FileParser[source]¶
Bases:
objectAuto-discovers parsers and dispatches files to the right one.
- static supported_formats()[source]¶
Return a description of every supported ECG format.
Can be called without instantiation:
FileParser.supported_formats()
Each entry contains:
name– short format name (e.g."HL7 aECG")description– one-line descriptionextensions– list of typical file extensions
- parse(file_path, auto_scale=True, units='mV')[source]¶
Parse an ECG file, auto-detecting the format.
- Parameters:
auto_scale (
bool) – WhenTrue(default), leads with scaling metadata are automatically converted to physical units (see units). Leads without sufficient metadata are left as raw ADC values and a warning is emitted. Set toFalseto always receive raw ADC samples.units (
str) – Target voltage unit when auto_scale isTrue. Accepted values:"uV"(microvolts),"mV"(millivolts, default),"V"(volts). Ignored when auto_scale isFalse.
- Raises:
ValueError – If no parser can handle the file or units is not recognised.
- Return type:
Parser¶
parse_batch¶
Examples¶
Basic usage¶
from ecgdatakit import FileParser
fp = FileParser()
record = fp.parse("ecg_file.xml")
Auto-scaling¶
auto_scale controls whether leads are automatically converted from raw ADC integers to millivolts.
When True (default), leads with scaling metadata (resolution, offset, units) are converted to mV automatically.
Leads without sufficient metadata are left as raw ADC values and a warning is emitted:
UserWarning: Leads ['Ch1', 'Ch2'] contain raw ADC samples — no scaling
metadata available. Pass auto_scale=False to get raw values.
# Default — leads with scaling metadata are converted to mV
record = fp.parse("ecg_file.xml")
# Raw ADC values, no conversion
record = fp.parse("ecg_file.xml", auto_scale=False)
Set to False to always receive raw ADC samples. See Signal Scaling for details on which formats provide scaling metadata and how to convert manually.
Listing supported formats¶
for fmt in FileParser.supported_formats():
print(fmt["name"], fmt["extensions"])
Batch parsing¶
from ecgdatakit import parse_batch
records = list(parse_batch(file_list, max_workers=4))