Skip to content

Commit b498768

Browse files
committed
#14: update ptbxl downloading
1 parent b7b9a5c commit b498768

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/ecglib/data/load_datasets.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,21 @@ def load_ptb_xl(
1818
path_to_zip: str = "./",
1919
path_to_unzip: str = "./",
2020
delete_zip: bool = True,
21+
frequency: int = 500,
2122
) -> pd.DataFrame:
2223
"""
2324
Load PTB-XL dataset
2425
:param download: whether to download PTB-XL from Physionet
2526
:param path_to_zip: path where to store PTB-XL .zip file
2627
:param path_to_unzip: path where to unarchive PTB-XL .zip file
2728
:param delete_zip: whether to delete PTB-XL .zip file after unarchiving
29+
:param frequency: sampling frequency of signals along the `fpath` column
2830
2931
:return: dataframe with PTB-XL dataset info
3032
"""
3133

3234
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"
3436
ptb_xl_zip = os.path.join(path_to_zip, "ptb_xl.zip")
3537
response = requests.get(url, stream=True)
3638
total_size_in_bytes = int(response.headers.get("content-length", 0))
@@ -59,20 +61,26 @@ def load_ptb_xl(
5961
os.remove(ptb_xl_zip)
6062
print("Deleting completed!")
6163

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+
6270
ptb_xl_info = pd.read_csv(
6371
os.path.join(
6472
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",
6674
"ptbxl_database.csv",
6775
)
6876
)
6977
ptb_xl_info["fpath"] = [
7078
os.path.join(
7179
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}"],
7482
)
75-
for i in range(len(ptb_xl_info["filename_hr"]))
83+
for i in range(len(ptb_xl_info[f"filename_{suffix}"]))
7684
]
7785

7886
return ptb_xl_info

0 commit comments

Comments
 (0)