@@ -18,19 +18,21 @@ def load_ptb_xl(
18
18
path_to_zip : str = "./" ,
19
19
path_to_unzip : str = "./" ,
20
20
delete_zip : bool = True ,
21
+ frequency : int = 500 ,
21
22
) -> pd .DataFrame :
22
23
"""
23
24
Load PTB-XL dataset
24
25
:param download: whether to download PTB-XL from Physionet
25
26
:param path_to_zip: path where to store PTB-XL .zip file
26
27
:param path_to_unzip: path where to unarchive PTB-XL .zip file
27
28
:param delete_zip: whether to delete PTB-XL .zip file after unarchiving
29
+ :param frequency: sampling frequency of signals along the `fpath` column
28
30
29
31
:return: dataframe with PTB-XL dataset info
30
32
"""
31
33
32
34
if download :
33
- url = "https://physionet.org/static/published-projects/ptb-xl/ptb-xl-a-large-publicly-available-electrocardiography-dataset-1.0.2 .zip"
35
+ url = "https://physionet.org/static/published-projects/ptb-xl/ptb-xl-a-large-publicly-available-electrocardiography-dataset-1.0.3 .zip"
34
36
ptb_xl_zip = os .path .join (path_to_zip , "ptb_xl.zip" )
35
37
response = requests .get (url , stream = True )
36
38
total_size_in_bytes = int (response .headers .get ("content-length" , 0 ))
@@ -59,20 +61,26 @@ def load_ptb_xl(
59
61
os .remove (ptb_xl_zip )
60
62
print ("Deleting completed!" )
61
63
64
+ if frequency == 500 :
65
+ suffix = 'hr' # high rate
66
+ else :
67
+ assert frequency == 100 , f"PTB-XL signals are only supported with 100 or 500 sample frequency, recieved: { frequency } "
68
+ suffix = 'lr' # low rate
69
+
62
70
ptb_xl_info = pd .read_csv (
63
71
os .path .join (
64
72
path_to_unzip ,
65
- "ptb-xl-a-large-publicly-available-electrocardiography-dataset-1.0.2 " ,
73
+ "ptb-xl-a-large-publicly-available-electrocardiography-dataset-1.0.3 " ,
66
74
"ptbxl_database.csv" ,
67
75
)
68
76
)
69
77
ptb_xl_info ["fpath" ] = [
70
78
os .path .join (
71
79
path_to_unzip ,
72
- "ptb-xl-a-large-publicly-available-electrocardiography-dataset-1.0.2 " ,
73
- ptb_xl_info .iloc [i ]["filename_hr " ],
80
+ "ptb-xl-a-large-publicly-available-electrocardiography-dataset-1.0.3 " ,
81
+ ptb_xl_info .iloc [i ][f"filename_ { suffix } " ],
74
82
)
75
- for i in range (len (ptb_xl_info ["filename_hr " ]))
83
+ for i in range (len (ptb_xl_info [f"filename_ { suffix } " ]))
76
84
]
77
85
78
86
return ptb_xl_info
0 commit comments