def dl_all_db(db_dir=None): if not db_dir: db_dir = _gen_default_dbdir() dbs = wfdb.get_dbs() for db in dbs: db_name = db[0] print('downloading db: ', db[0], ' ', db[1]) wfdb.dl_database(db_name + '/', dl_dir=os.path.join(db_dir, db_name))
def getDatasetInfo(): dbs = wfdb.get_dbs() dataset_keys = [] dataset_names = [] for i in range(0, len(dbs)): dataset_keys.append(str(dbs[i][0])) dataset_names.append(str(dbs[i][1])) total_info = [dataset_keys, dataset_names] return total_info
# -*- coding: utf-8 -*- #%% Data initialization import os import numpy as np # import PhysioNet ecg data package import wfdb # list of available datasets dbs = wfdb.get_dbs() #display(dbs) # we choose svdb svdb_dir = os.path.join(os.getcwd(), 'svdb_dir') #wfdb.dl_database('svdb', dl_dir=svdb_dir) # Display the downloaded content svdb_in_files = [ os.path.splitext(f)[0] for f in os.listdir(svdb_dir) if f.endswith('.dat') ] print(svdb_in_files) time_window = 48 all_beats = [] all_annotations = [] for in_file in svdb_in_files: print('...processing...' + in_file + '...file') signal, fields = wfdb.rdsamp(os.path.join(svdb_dir, in_file), channels=[0]) annotations = wfdb.rdann(os.path.join(svdb_dir, in_file), 'atr')
import os import wfdb import matplotlib.pyplot as plt import numpy as np import pandas as pd import tensorflow as tf from tensorflow import keras from tensorflow.keras import layers from sklearn.metrics import confusion_matrix import seaborn as sn os.chdir('C:\\Users\\Jerry\\Desktop\\Jerry\\projects\\heartbeat_python') #%% download all the files test = wfdb.get_dbs() wfdb.get_record_list('mitdb') wfdb.dl_database( 'mitdb', 'C:\\Users\\Jerry\\Desktop\\Jerry\\projects\\Heartbeat Python\\data') #%% building a loop to read in data and annotations then cutting the ECG into heartbeats def simple_plot(x, alpha=1, grid=True): plt.plot(np.arange(0, len(x)), x, alpha=alpha) if grid: plt.grid(True) sample = wfdb.rdsamp('data\\101')[0][:, 0] # read in the record annotation = wfdb.rdann('data\\101',
def getDBList(): # Retreive a list of available databases in Physionet dbs = wfdb.get_dbs() return dbs