fusionlab.datasets.ludb module#

Lobachevsky University Electrocardiography Database (LUDB) link: https://physionet.org/content/ludb/1.0.1/ patient id: 1~200 LEADS: i, ii, iii, avr, avl, avf, v1, v2, v3, v4, v5, v6 segment annotaion symbols: p(P), N(QRS), t(T) file extensions: .dat, .hea, .i, .ii, .iii, .avr, .avl, .avf, .v1, .v2, .v3, .v4, .v5, .v6 filename format: {patient_id}.{file extensions}

signal shape: (5000, 12)

annotation format: symbols: [‘(’, ‘N’, ‘)’, ‘(’, ‘t’, ‘)’, ‘(’, ‘p’, ‘)’] symbol tpye: [‘p’ ‘N’ ‘t’ ‘(’ ‘)’] sample: [ 641 664 690 773 840 887] first symbol in signal index: 641 (all 200 patients) last symbol in signal index: 3996 (all 200 patients)

ref: byschii/ecg-segmentation

The generated annotation file follows the format of the label-studio timeserieslabels segment annotation

NOTE: since the annotation is channel independent, we only use the first channel (I) annotation TODO: provide different annotation for different leads

class fusionlab.datasets.ludb.LUDBDataset(data_dir, annotation_path, transform=None, start_idx=641, end_idx=3996, lead_name='i')[source]#

Bases: Dataset

Parameters:
  • data_dir (str) – path to the dataset folder

  • annotation_path (str) – path to the annotation json file

  • transform (callable, optional) – Optional transform to be applied on a sample.

  • start_idx (int) – start index of the signal

  • end_idx (int) – end index of the signal

  • lead_name (str) – lead name to extract annotation, default: ‘i’

Returns:

(channels, sequence lenth) label_seq: (sequence lenth,)

Return type:

signal

extract_signal_label(signal, label)[source]#

extract signal and label with respect to start and end index

Parameters:
  • signal (np.array) – (signal length, 12)

  • label (np.array) – (signal length,)

get_annotation(DATA_FOLDER, index, lead_name)[source]#
get_segment_annotation(pat_id, lead_name='i')[source]#
get_signal(DATA_FOLDER, index)[source]#
Parameters:
  • DATA_FOLDER (str) – path to the data folder

  • index (int) – patient id

Returns:

(signal length, 12)

Return type:

signal (np.array)

map_annotaion_to_label_seq(annotation, sig_len)[source]#
Parameters:
  • annotation (dict) – annotation dict

  • sig_len (int) – signal length

Returns:

label sequence with integer class index

Return type:

label_seq (np.array)

process_annotation(export_path, lead_name='i')[source]#

process annotation file and save to json

Parameters:
  • export_path (str) – path to save the annotation json file

  • lead_name (str) – lead name to extract annotation

validate_files()[source]#

validate number of files and file types 1. check if files exist 2. check if file types are valid 3. check if number of files are valid

Parameters:

data_dir (str) – path to the dataset folder

fusionlab.datasets.ludb.plot(signal, label_seq, sr=500, channel='v1')[source]#

plot signal with annotation

fusionlab.datasets.ludb.plot_leads(signal, label_seq, sr=500, channels=['i', 'ii', 'iii', 'avr', 'avl', 'avf', 'v1', 'v2', 'v3', 'v4', 'v5', 'v6'])[source]#