Skip to content

Instantly share code, notes, and snippets.

@physhik
Last active March 20, 2019 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save physhik/d0b1d2899118ae95ae898acf957b9490 to your computer and use it in GitHub Desktop.
Save physhik/d0b1d2899118ae95ae898acf957b9490 to your computer and use it in GitHub Desktop.
irhythms ECG data
from tqdm import tqdm
def digitize():
import os
path = 'clean_30sec_recs/'
files = os.listdir(path)
d = dict()
for name in tqdm(files):
l = []
id = None
if ".ecg" in name:
id = name[:-4]
def makeIntlist():
import struct
with open( path + name ,"rb") as n:
while True:
try :
l.append(struct.unpack('i', n.read(4))[0])
except:
break
if id != None:
for i in range(3):
import json
arg = path + id + "_grp"+str(i)+".episodes.json"
if os.path.exists(arg):
id2 = arg
with open(id2, "r") as read_file:
ann=json.load(read_file)
ann = ann["episodes"][0]["rhythm_name"]
makeIntlist()
import pandas as pd
if id:
print(ann+id)
d["200 " +ann + " " + id] = l
df = pd.DataFrame.from_dict(d)
return df
if __name__ == '__main__':
df = digitize()
savepath = "data.csv"
df.to_csv(savepath, index = False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment