Data¶
ECGDataset¶
ECGDataset
dataclass
¶
ECGDataset(data: ndarray, lead_names: List[str], fs: float, source_path: Path, label: str, file_names: List[str] = list())
Container for a collection of ECG recordings loaded from a folder.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
ndarray
|
Shape (n_samples, n_leads, n_timepoints). |
lead_names |
List[str]
|
Ordered list of lead names. |
fs |
float
|
Sampling frequency in Hz. |
source_path |
Path
|
Folder the data was loaded from. |
label |
str
|
Human-readable label used in plots/reports (defaults to folder name). |
file_names |
List[str]
|
Original filenames in load order. |
select_leads
¶
Return a new ECGDataset restricted to the requested leads.
Source code in ecgen_eval/data/dataset.py
sample
¶
Return a new ECGDataset with n randomly selected recordings.
Source code in ecgen_eval/data/dataset.py
LEADS_12
module-attribute
¶
Loaders¶
load_ecg_npy
¶
load_ecg_npy(path: Union[str, Path], fs: float = 500.0, label: Optional[str] = None, lead_names: Optional[List[str]] = None, max_samples: Optional[int] = None) -> ECGDataset
Load a NumPy array of ECGs saved with np.save / np.savez.
The array must have shape (N, L, T) — samples × leads × timepoints.
This is the native output format of ECGEN-FM, ECGEN-VAE, and Pulse2Pulse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Path to a |
required |
fs
|
float
|
Sampling frequency in Hz. Default: 500. |
500.0
|
label
|
str
|
Display label. Defaults to stem of the file. |
None
|
lead_names
|
list of str
|
Lead name list. Auto-assigned from L if 8 or 12 leads. |
None
|
max_samples
|
int
|
Cap number of recordings loaded. |
None
|
Returns:
| Type | Description |
|---|---|
ECGDataset
|
|
Source code in ecgen_eval/data/loader.py
load_ecg_wfdb
¶
load_ecg_wfdb(record_dir: Union[str, Path], fs: float = 500.0, label: Optional[str] = None, lead_names: Optional[List[str]] = None, max_samples: Optional[int] = None, resample_to: Optional[float] = None) -> ECGDataset
Load WFDB ECG records from a directory (e.g. PTB-XL).
Requires the wfdb package (pip install wfdb).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record_dir
|
str or Path
|
Directory containing |
required |
fs
|
float
|
Expected sampling frequency. Used for metadata only unless resample_to is set. |
500.0
|
label
|
str
|
Display label. Defaults to directory name. |
None
|
lead_names
|
list of str
|
Override lead names (e.g. to match a specific lead ordering). |
None
|
max_samples
|
int
|
Cap on number of records loaded. |
None
|
resample_to
|
float
|
If provided, resample each record to this sampling rate using scipy. |
None
|
Returns:
| Type | Description |
|---|---|
ECGDataset
|
|
Source code in ecgen_eval/data/loader.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
load_ecg_folder
¶
load_ecg_folder(folder: Union[str, Path], fs: float = 500.0, label: Optional[str] = None, n_leads: Optional[int] = None, n_timepoints: Optional[int] = None, lead_names: Optional[List[str]] = None, max_samples: Optional[int] = None) -> ECGDataset
Load ECGs from folder or a single file, auto-detecting the format.
Supported: .npy / .npz (NumPy), .hea / WFDB records, and .csv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder
|
str or Path
|
Directory or a single file path. |
required |
fs
|
float
|
Sampling frequency in Hz (default 500 Hz). |
500.0
|
label
|
str
|
Display label for plots. Defaults to the folder/file name. |
None
|
n_leads
|
int
|
Expected number of leads (8 or 12). Auto-detected if None. (CSV only) |
None
|
n_timepoints
|
int
|
Expected number of timepoints per lead. Auto-detected if None. (CSV only) |
None
|
lead_names
|
list of str
|
Explicit lead name list. Auto-detected or default-assigned if None. |
None
|
max_samples
|
int
|
Cap the number of loaded recordings (useful for quick tests). |
None
|
Returns:
| Type | Description |
|---|---|
ECGDataset
|
|