Validation¶
Every record is checked before it is split, producing the original version
(all records, plus is_valid and quality_issues) and clean (valid only).
Engine¶
engine
¶
Validation pipeline orchestrator.
Validates all ECG records in a dataset using configurable quality checks and produces both original (all records + flags) and clean (valid only) DataFrames.
ValidationResult
dataclass
¶
ValidationResult(original_df: DataFrame, clean_df: DataFrame, record_validations: list[RecordValidation], summary: dict[str, int], total_records: int, valid_records: int, excluded_records: int, issue_summary: dict[str, int] = dict())
Output of the validation pipeline.
validate_dataset
¶
validate_dataset(data_path: Path, config: DatasetConfig, sampling_rate: int | None = None, max_workers: int = 4, progress: bool = True) -> ValidationResult
Validate all ECG records in a dataset.
- Read metadata CSV from data_path / config.metadata_csv
- For each record, load the signal file and run all checks
- Add 'is_valid' and 'quality_issues' columns to the DataFrame
- Return ValidationResult with both original and clean DataFrames
Uses concurrent.futures.ProcessPoolExecutor for parallel validation. Falls back to sequential if max_workers=1 or multiprocessing fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_path
|
Path
|
Path to the dataset root directory |
required |
config
|
DatasetConfig
|
DatasetConfig for this dataset |
required |
sampling_rate
|
int | None
|
Which sampling rate to validate (default: config.default_sampling_rate) |
None
|
max_workers
|
int
|
Number of parallel workers |
4
|
progress
|
bool
|
Show progress messages |
True
|
Returns:
| Type | Description |
|---|---|
ValidationResult
|
ValidationResult with original_df, clean_df, and statistics |
Source code in ecgbench/validation/engine.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | |
Checks¶
Each check is a function over a signal array, registered in CHECK_REGISTRY and
selected per dataset by the config's validation: block.
checks
¶
Individual quality check functions for ECG signal validation.
Every check shares one signature and is registered in CHECK_REGISTRY::
def check_<name>(signal: np.ndarray, config: DatasetConfig) -> list[str]
signal is an array of shape (leads, samples) and config the dataset's
DatasetConfig. The return value is a list of issue descriptions; an empty
list means the record passed that check.
check_missing_leads
¶
check_missing_leads(signal: ndarray, config: DatasetConfig) -> list[str]
Detect leads where ALL values are NaN or ALL values are exactly 0.0.
Source code in ecgbench/validation/checks.py
check_nan_values
¶
check_nan_values(signal: ndarray, config: DatasetConfig) -> list[str]
Detect any NaN values anywhere in the signal.
check_truncated_signal
¶
check_truncated_signal(signal: ndarray, config: DatasetConfig, sampling_rate: int | None = None) -> list[str]
Detect if signal has fewer samples than expected.
Source code in ecgbench/validation/checks.py
check_flat_line
¶
check_flat_line(signal: ndarray, config: DatasetConfig) -> list[str]
Detect leads with near-zero variance (not already caught by missing_leads).
Source code in ecgbench/validation/checks.py
check_amplitude_outlier
¶
check_amplitude_outlier(signal: ndarray, config: DatasetConfig) -> list[str]
Detect samples outside the physiological amplitude range.
Source code in ecgbench/validation/checks.py
check_name_for_issue
¶
Map an issue string back to the name of the check that produced it.
The single source of truth for that mapping — the check functions above use four different naming conventions, and the engine's summary, the validation report and any backfill must all agree on how to undo them.
Engine-generated issues (corrupt_header:, load_error:) and the
synthetic <check>_error: strings fall through to the generic rule.
Source code in ecgbench/validation/checks.py
Report¶
report
¶
Validation report generation.
Produces a JSON-serialisable report documenting the validation results, including per-check statistics and excluded record details.
describe_check
¶
Human-readable description for a check name appearing in the report.
Source code in ecgbench/validation/report.py
build_quality_checks
¶
build_quality_checks(records_failed: dict[str, int], issues: dict[str, int] | None = None) -> list[dict]
Build the report's quality_checks block from the two summaries.
records_failed counts records, issues counts individual issue
strings; they differ for the per-lead checks. The two do not sum to the
excluded-record total, because one record can fail several checks.
issues may be omitted for a result built without it (the
--skip-validation stub), in which case the record count is reused.
Source code in ecgbench/validation/report.py
generate_report
¶
generate_report(result: ValidationResult, config: DatasetConfig) -> dict
Generate a JSON-serialisable validation report dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
ValidationResult
|
ValidationResult from validate_dataset() |
required |
config
|
DatasetConfig
|
DatasetConfig for the dataset |
required |
Returns:
| Type | Description |
|---|---|
dict
|
dict suitable for json.dump() |
Source code in ecgbench/validation/report.py
save_report
¶
save_report(result: ValidationResult, config: DatasetConfig, output_path: Path) -> Path
Generate and save validation_report.json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
ValidationResult
|
ValidationResult from validate_dataset() |
required |
config
|
DatasetConfig
|
DatasetConfig for the dataset |
required |
output_path
|
Path
|
Where to write the JSON file |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the saved report file |