Skip to content

Commit 82cc062

Browse files
committed
アノテーションついてる部分抜き出すやつ追加
1 parent bf022e9 commit 82cc062

File tree

1 file changed

+172
-0
lines changed

1 file changed

+172
-0
lines changed

changepart_show.ipynb

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"# 指定データのaux_note(rhythm change)がついてる部分を切り出して波形表示する\n",
10+
"# とりあえず前後2秒を切り出したつもり"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"metadata": {},
17+
"outputs": [],
18+
"source": [
19+
"import os\n",
20+
"import glob\n",
21+
"import wfdb\n",
22+
"from IPython.display import display\n",
23+
"import matplotlib\n",
24+
"import matplotlib.pyplot as plt\n",
25+
"font = {'family':'IPAexGothic'}\n",
26+
"matplotlib.rc('font', **font)"
27+
]
28+
},
29+
{
30+
"cell_type": "code",
31+
"execution_count": null,
32+
"metadata": {},
33+
"outputs": [],
34+
"source": [
35+
"def get_sample_aux(filename):\n",
36+
" annotation = wfdb.rdann('data/%s'%filename, 'atr')\n",
37+
" header = wfdb.rdheader('data/%s'%filename)\n",
38+
" sample_list = annotation.sample.tolist()\n",
39+
" dic = dict(zip(sample_list, annotation.aux_note))\n",
40+
" # print(header.sig_len)\n",
41+
" for key in sorted(dic.keys()):\n",
42+
" sampfrom = max(0, key - annotation.fs*2)\n",
43+
" sampto = min(key + annotation.fs*2, header.sig_len)\n",
44+
" record = wfdb.rdrecord('data/%s'%filename, sampfrom = sampfrom, sampto = sampto)\n",
45+
" if dic[key] == '(BI\\x00':\n",
46+
" meaning = '1度房室ブロック(first degree heart block)'\n",
47+
" elif dic[key] == '(AFIB\\x00':\n",
48+
" meaning = '心房細動(atrial fibrillation)'\n",
49+
" elif dic[key] == '(ASYS\\x00':\n",
50+
" meaning = '心静止(asystole)'\n",
51+
" elif dic[key] == '(B\\x00':\n",
52+
" meaning = '心室二段脈(ventricular bigeminy)'\n",
53+
" elif dic[key] == '(HGEA\\x00':\n",
54+
" meaning = '異所性心室興奮(high grade ventricular ectopic activity)'\n",
55+
" elif dic[key] == '(N\\x00' or dic[key] == '(NSR\\x00':\n",
56+
" meaning = '正常洞調律(normal sinus rhythm)'\n",
57+
" elif dic[key] == '(NOD\\x00':\n",
58+
" meaning = '房室結節性リズム (nodal (\"AV junctional\") rhythm)'\n",
59+
" elif dic[key] == '(NOISE\\x00':\n",
60+
" meaning = 'ノイズ(noise)'\n",
61+
" elif dic[key] == '(PM\\x00':\n",
62+
" meaning = 'ペースメーカー (pacemaker(paced rhythm))'\n",
63+
" elif dic[key] == '(SBR\\x00':\n",
64+
" meaning = '洞性徐脈 (sinus bradycardia)'\n",
65+
" elif dic[key] == '(SVTA\\x00':\n",
66+
" meaning = '上室性頻脈性不整脈 (supraventricular tachyarrhythmia)'\n",
67+
" elif dic[key] == '(VER\\x00':\n",
68+
" meaning = '心室補充律動 (ventricular escape rhythm)'\n",
69+
" elif dic[key] == '(VF\\x00' or dic[key] == '(VFIB\\x00':\n",
70+
" meaning = '心室細動 (ventricular fibrillation)'\n",
71+
" elif dic[key] == '(VFL\\x00':\n",
72+
" meaning = '心室粗動 (ventricular flutter)'\n",
73+
" elif dic[key] == '(VT\\x00':\n",
74+
" meaning = '心室頻拍 (ventricular tachycardia)' \n",
75+
" else:\n",
76+
" meaning = None\n",
77+
" \n",
78+
" \n",
79+
" wfdb.plot_wfdb(record = record, time_units = 'seconds', title = meaning)\n",
80+
" # annotationをプロットしたいがなぜかエラー……\n",
81+
" # wfdb.plot_wfdb(record = record, annotation = annotation, time_units = 'seconds')"
82+
]
83+
},
84+
{
85+
"cell_type": "code",
86+
"execution_count": null,
87+
"metadata": {
88+
"scrolled": false
89+
},
90+
"outputs": [],
91+
"source": [
92+
"get_sample_aux(615)"
93+
]
94+
},
95+
{
96+
"cell_type": "code",
97+
"execution_count": null,
98+
"metadata": {},
99+
"outputs": [],
100+
"source": [
101+
"'''\n",
102+
" filename = 418\n",
103+
" annotation = wfdb.rdann('data/%s'%filename, 'atr')\n",
104+
" header = wfdb.rdheader('data/%s'%filename)\n",
105+
" sample_list = annotation.sample.tolist()\n",
106+
" dic = dict(zip(sample_list, annotation.aux_note))\n",
107+
" '''"
108+
]
109+
},
110+
{
111+
"cell_type": "code",
112+
"execution_count": null,
113+
"metadata": {},
114+
"outputs": [],
115+
"source": [
116+
"'''\n",
117+
" sampfrom = max(0, key - annotation.fs*2)\n",
118+
" sampto = min(key + annotation.fs*2, header.sig_len)\n",
119+
" record = wfdb.rdrecord('data/%s'%filename, sampfrom = sampfrom, sampto = sampto)\n",
120+
" meaning = None\n",
121+
" file_name = 'test_image.png'\n",
122+
" '''"
123+
]
124+
},
125+
{
126+
"cell_type": "code",
127+
"execution_count": null,
128+
"metadata": {},
129+
"outputs": [],
130+
"source": [
131+
"# fig = wfdb.plot_wfdb(record = record, time_units = 'seconds', title = meaning, return_fig = True)\n",
132+
"# showのあとにsavefigしてもうまくいかない!!!ちょっと!!"
133+
]
134+
},
135+
{
136+
"cell_type": "code",
137+
"execution_count": null,
138+
"metadata": {},
139+
"outputs": [],
140+
"source": []
141+
},
142+
{
143+
"cell_type": "code",
144+
"execution_count": null,
145+
"metadata": {},
146+
"outputs": [],
147+
"source": []
148+
}
149+
],
150+
"metadata": {
151+
"anaconda-cloud": {},
152+
"kernelspec": {
153+
"display_name": "Python [default]",
154+
"language": "python",
155+
"name": "python3"
156+
},
157+
"language_info": {
158+
"codemirror_mode": {
159+
"name": "ipython",
160+
"version": 3
161+
},
162+
"file_extension": ".py",
163+
"mimetype": "text/x-python",
164+
"name": "python",
165+
"nbconvert_exporter": "python",
166+
"pygments_lexer": "ipython3",
167+
"version": "3.5.4"
168+
}
169+
},
170+
"nbformat": 4,
171+
"nbformat_minor": 2
172+
}

0 commit comments

Comments
 (0)