@@ -2203,6 +2203,76 @@ def rm_last(*args):
22032203 return
22042204
22052205
2206+ def ann2rr (record_name , extension , pn_dir = None , start_time = None ,
2207+ stop_time = None , format = None ):
2208+ from wfdb .processing import hr
2209+ """
2210+ Obtain RR interval series from ECG annotation files.
2211+
2212+ Parameters
2213+ ----------
2214+ record_name : str
2215+ The record name of the WFDB annotation file. ie. for file '100.atr',
2216+ record_name='100'.
2217+ extension : str
2218+ The annotatator extension of the annotation file. ie. for file
2219+ '100.atr', extension='atr'.
2220+ pn_dir : str
2221+ Option used to stream data from Physionet. The Physionet database
2222+ directory from which to find the required annotation file. eg. For
2223+ record '100' in 'http://physionet.org/content/mitdb': pn_dir='mitdb'.
2224+ start_time : float
2225+ The time to start the intervals in seconds.
2226+ stop_time : float
2227+ The time to stop the intervals in seconds.
2228+ format : str
2229+ Print intervals in the specified format. By default, intervals are
2230+ printed in units of sample intervals. Other formats include
2231+ 's' (seconds), 'm' (minutes), 'h' (hours). Set to 'None' for samples.
2232+
2233+ Returns
2234+ -------
2235+ N/A
2236+
2237+ Examples
2238+ --------
2239+ >>> wfdb.ann2rr('sample-data/100', 'atr')
2240+ >>> 18
2241+ >>> 59
2242+ >>> ...
2243+ >>> 250
2244+ >>> 257
2245+
2246+ """
2247+ if (pn_dir is not None ) and ('.' not in pn_dir ):
2248+ dir_list = pn_dir .split (os .sep )
2249+ pn_dir = posixpath .join (dir_list [0 ], record .get_version (dir_list [0 ]),
2250+ * dir_list [1 :])
2251+
2252+ ann = rdann (record_name , extension , pn_dir = pn_dir )
2253+
2254+ rr_interval = hr .calc_rr (ann .sample , fs = ann .fs )
2255+ rr_interval = np .insert (rr_interval , 0 , ann .sample [0 ])
2256+
2257+ time_interval = rr_interval / ann .fs
2258+ if start_time is not None :
2259+ time_interval = time_interval [(time_interval > start_time ).astype (bool )]
2260+ if stop_time is not None :
2261+ time_interval = time_interval [(time_interval < stop_time ).astype (bool )]
2262+
2263+ # Already given in seconds (format == 's')
2264+ if format == 's' :
2265+ out_interval = time_interval
2266+ elif format == 'm' :
2267+ out_interval = time_interval / 60
2268+ elif format == 'h' :
2269+ out_interval = time_interval / (60 * 60 )
2270+ else :
2271+ out_interval = np .around (time_interval * ann .fs ).astype (np .int )
2272+
2273+ print (* out_interval , sep = '\n ' )
2274+
2275+
22062276## ------------- Annotation Field Specifications ------------- ##
22072277
22082278
0 commit comments