@@ -84,15 +84,15 @@ def analyze(rrfile, ecgfile, locfile=None, axislimit=DEFAULT_AXIS_LIMIT, thresho
84
84
fig , ax = plt .subplots (3 , 1 , figsize = (24 , 12 ), layout = "constrained" , sharex = True )
85
85
ax [0 ].xaxis .grid (True )
86
86
ax [0 ].yaxis .grid (True )
87
- ax [0 ].scatter (time_p ,rr_p ,marker = 'x' )
87
+ ax [0 ].scatter (time_p , rr_p , marker = 'x' )
88
88
ax [0 ].set_ylabel ("RR(msec)" , fontsize = 12 )
89
89
ax [1 ].xaxis .grid (True )
90
90
ax [1 ].yaxis .grid (True )
91
- ax [1 ].plot (time_p ,sigma_p )
91
+ ax [1 ].plot (time_p , sigma_p )
92
92
ax [1 ].set_ylabel ("SDΔRR(msec)" , fontsize = 12 )
93
93
ax [2 ].xaxis .grid (True )
94
94
ax [2 ].yaxis .grid (True )
95
- ax [2 ].plot (ecgtime ,ecguv )
95
+ ax [2 ].plot (ecgtime , ecguv )
96
96
ax [2 ].set_xlabel ("time" , fontsize = 12 )
97
97
ax [2 ].set_ylabel (R"ECG($\mu$v)" , fontsize = 12 )
98
98
ax [0 ].set_title (f"{ rrfile } , { ecgfile } " , fontsize = 14 )
@@ -112,7 +112,7 @@ def analyze(rrfile, ecgfile, locfile=None, axislimit=DEFAULT_AXIS_LIMIT, thresho
112
112
# fig, ax = plt.subplots(1, 1, figsize=(24, 12), layout="constrained", sharex=True)
113
113
# ax.xaxis.grid(True)
114
114
# ax.yaxis.grid(True)
115
- # ax.plot(time_p,sigma_p)
115
+ # ax.plot(time_p, sigma_p)
116
116
# ax.set_xlabel("time", fontsize=12)
117
117
# ax.set_ylabel("SDΔRR(msec)", fontsize=12)
118
118
# #ax.scatter(list(range(len(sigma_l))), sigma_l, marker='+', c='r')
@@ -123,11 +123,11 @@ def analyze(rrfile, ecgfile, locfile=None, axislimit=DEFAULT_AXIS_LIMIT, thresho
123
123
warn = np .insert (warn , 0 , False )
124
124
warn = np .append (warn , False )
125
125
indices = np .nonzero (np .diff (warn ))[0 ]
126
- warns = np .reshape (indices , (int (len (indices )/ 2 ),2 ))
126
+ warns = np .reshape (indices , (int (len (indices )/ 2 ), 2 ))
127
127
time_pn = time_p .to_numpy ()
128
128
durations = np .diff (time_pn [warns ])/ np .timedelta64 (1 , 's' )
129
129
longds = durations >= 20
130
- qualified_warn_indices_p = warns [longds [:,0 ]]
130
+ qualified_warn_indices_p = warns [longds [:, 0 ]]
131
131
if len (qualified_warn_indices_p ) > 0 :
132
132
print ("Suspicious events found in " + rrfile , file = sys .stderr )
133
133
@@ -138,22 +138,46 @@ def analyze(rrfile, ecgfile, locfile=None, axislimit=DEFAULT_AXIS_LIMIT, thresho
138
138
139
139
figno = 0
140
140
for w in qualified_warn_indices_p :
141
+
141
142
wstart = time_p [w [0 ]]
142
143
wend = time_p [w [1 ]]
143
144
deltat = (wend - wstart ) / np .timedelta64 (1 , 's' )
144
145
print (f"warning from { wstart } to { wend } , duration { deltat } seconds." )
145
146
147
+ # plot the RR, SDΔRR, ecg waveforms in the zone
148
+ ecguv_subset = ecguv [np .logical_and (ecgtime >= wstart , ecgtime <= wend )]
149
+ ecgtime_subset = ecgtime [np .logical_and (ecgtime >= wstart , ecgtime <= wend )]
150
+ fig , ax = plt .subplots (3 , 1 , figsize = (24 , 12 ), layout = "constrained" , sharex = True )
151
+ ax [0 ].xaxis .grid (True )
152
+ ax [0 ].yaxis .grid (True )
153
+ ax [0 ].scatter (time_p [w [0 ]:w [1 ]], rr_p [w [0 ]:w [1 ]], marker = 'x' )
154
+ ax [0 ].set_ylabel ("RR(msec)" , fontsize = 12 )
155
+ ax [1 ].xaxis .grid (True )
156
+ ax [1 ].yaxis .grid (True )
157
+ ax [1 ].plot (time_p [w [0 ]:w [1 ]], sigma_p [w [0 ]:w [1 ]])
158
+ ax [1 ].set_ylabel ("SDΔRR(msec)" , fontsize = 12 )
159
+ ax [2 ].xaxis .grid (True )
160
+ ax [2 ].yaxis .grid (True )
161
+ ax [2 ].plot (ecgtime_subset , ecguv_subset )
162
+ ax [2 ].set_xlabel ("time" , fontsize = 12 )
163
+ ax [2 ].set_ylabel (R"ECG($\mu$v)" , fontsize = 12 )
164
+ ax [0 ].set_title (f"{ rrfile } , { ecgfile } " , fontsize = 14 )
165
+ plt .savefig (ecgfile .replace (".csv" , "" ) + "-" + str (figno ) + ".png" )
166
+ plt .close (fig )
167
+
168
+ # update the zone in the location plot
146
169
if locfile :
147
170
lats = np .interp (time_p [w [0 ]:w [1 ]].to_numpy ().view ('int' ), time_l .astype (int ), latlon_l ['lat' ])
148
171
lons = np .interp (time_p [w [0 ]:w [1 ]].to_numpy ().view ('int' ), time_l .astype (int ), latlon_l ['lon' ])
149
- subset = np .column_stack ((lats ,lons ))
172
+ ll_subset = np .column_stack ((lats , lons ))
150
173
151
- folium .PolyLine (cleanll (subset ), color = "red" ).add_to (eventmap )
152
- folium .Circle (subset [0 , :], color = "red" , fill = True , radius = 10 ).add_to (eventmap )
153
- folium .Circle (subset [- 1 , :], color = "green" , fill = True , radius = 10 ).add_to (eventmap )
174
+ folium .PolyLine (cleanll (ll_subset ), color = "red" ).add_to (eventmap )
175
+ folium .Circle (ll_subset [0 , :], color = "red" , fill = True , radius = 10 ).add_to (eventmap )
176
+ folium .Circle (ll_subset [- 1 , :], color = "green" , fill = True , radius = 10 ).add_to (eventmap )
154
177
178
+ # create a Poincaré plot for the zone
155
179
fig , ax = plt .subplots (figsize = (10 , 10 ), layout = "constrained" )
156
- rr_p_subset = rr_p [np .logical_and (time_p >= wstart , time_p <= wend )]
180
+ rr_p_subset = rr_p [np .logical_and (time_p >= wstart , time_p <= wend )]
157
181
x = rr_p_subset [0 :- 2 ]
158
182
y = rr_p_subset [1 :- 1 ]
159
183
ax .scatter (x , y )
@@ -176,14 +200,14 @@ def analyze(rrfile, ecgfile, locfile=None, axislimit=DEFAULT_AXIS_LIMIT, thresho
176
200
ax .set_ylabel (r"$RR_{n+1}(msec)$" , fontsize = 12 )
177
201
ax .xaxis .grid (True )
178
202
ax .yaxis .grid (True )
179
-
180
203
plt .savefig (rrfile .replace (".csv" , "" ) + "-" + str (figno ) + ".png" )
181
204
plt .close (fig )
182
205
183
206
figno += 1
184
207
185
- if locfile :
186
- eventmap .save (locfile .replace (".csv" , ".html" ))
208
+ # save the location plot with all zones updated
209
+ if locfile :
210
+ eventmap .save (locfile .replace (".csv" , ".html" ))
187
211
188
212
def main ():
189
213
parser = argparse .ArgumentParser (
0 commit comments