def extractTimeDomain(self, x): try: nni = self.extractRR(x) nniParams = td.nni_parameters(nni=nni) nniSD = td.sdnn(nni=nni) nniDiff = td.nni_differences_parameters(nni=nni) nniDiffRM = td.rmssd(nni=nni) nniDiffSD = td.sdsd(nni=nni) hrParams = td.hr_parameters(nni=nni) return np.array([nniParams["nni_mean"], nniParams["nni_counter"], nniSD["sdnn"], nniDiff["nni_diff_mean"], nniDiffRM["rmssd"], nniDiffSD["sdsd"], hrParams["hr_mean"], hrParams["hr_std"]]) except: return np.array([])
def compute_features(nni): features = {} features['mean_hr'] = tools.heart_rate(nni).mean() features['sdnn'] = td.sdnn(nni)[0] features['rmssd'] = td.rmssd(nni)[0] features['sdsd'] = td.sdsd(nni)[0] features['nn20'] = td.nn20(nni)[0] features['pnn20'] = td.nn20(nni)[1] features['nn50'] = td.nn50(nni)[0] features['pnn50'] = td.nn50(nni)[1] features['hf_lf_ratio'] = fd.welch_psd(nni, show=False)['fft_ratio'] features['very_lf'] = fd.welch_psd(nni, show=False)['fft_peak'][0] features['lf'] = fd.welch_psd(nni, show=False)['fft_peak'][1] features['hf'] = fd.welch_psd(nni, show=False)['fft_peak'][2] features['log_very_lf'] = fd.welch_psd(nni, show=False)['fft_log'][0] features['log_lf'] = fd.welch_psd(nni, show=False)['fft_log'][1] features['log_hf'] = fd.welch_psd(nni, show=False)['fft_log'][2] features['sampen'] = nl.sample_entropy(nni)[0] return features
def cal_hrv(data_list): if (np.nan in data_list) or (len(data_list) <= 1): sdsd = np.nan rmssd = np.nan sd1 = np.nan sd2 = np.nan sd_ratio = np.nan a1 = np.nan a2 = np.nan a_ratio = np.nan sampen = np.nan else: # sdsd sdsd = round(td.sdsd(nni=data_list)['sdsd'], 5) # rmssd rmssd = round(td.rmssd(nni=data_list)['rmssd'], 5) # sd1, sd2 nl_results = nl.poincare(nni=data_list) sd1 = round(nl_results['sd1'], 5) sd2 = round(nl_results['sd2'], 5) sd_ratio = round(sd2 / sd1, 5) # dfa a1, a2 dfa_results = nl.dfa(data_list) try: a1 = round(dfa_results['dfa_alpha1'], 5) a2 = round(dfa_results['dfa_alpha2'], 5) a_ratio = round(a2 / a1, 5) except: a1 = np.nan print(a1, type(a1)) a2 = np.nan print(a2, type(a2)) a_ratio = np.nan # Sampen t = np.std(data_list) sampen = round( nl.sample_entropy(nni=data_list, tolerance=t)['sampen'], 6) return sdsd, rmssd, sd1, sd2, sd_ratio, a1, a2, a_ratio, sampen
def extractTimeDomain(self, x): try: nni = self.extractRR(x) nniParams = td.nni_parameters(nni=nni) nniSD = td.sdnn(nni=nni) nniDiff = td.nni_differences_parameters(nni=nni) nniDiffRM = td.rmssd(nni=nni) nniDiffSD = td.sdsd(nni=nni) hrParams = td.hr_parameters(nni=nni) nn20 = td.nn20(nni=nni) nn30 = td.nnXX(nni=nni, threshold=30) nn50 = td.nn50(nni=nni) # return np.array([nniParams["nni_mean"], nniParams["nni_counter"], nniSD["sdnn"], # nniDiff["nni_diff_mean"], nniDiffRM["rmssd"], nniDiffSD["sdsd"], # hrParams["hr_mean"], hrParams["hr_std"]]) return np.array([nniParams["nni_mean"], nniParams["nni_counter"], nniSD["sdnn"], nniDiff["nni_diff_mean"], nniDiffRM["rmssd"], nniDiffSD["sdsd"], hrParams["hr_mean"], hrParams["hr_std"], hrParams["hr_max"] - hrParams["hr_min"], nn20["nn20"], nn20["pnn20"], nn30["nn30"], nn30["pnn30"], nn50["nn50"], nn50["pnn50"]]) except: return np.array([])
def _computeSignal(self, signal): obj = {} # Best min_dist & thres for sphygmogram signal peaks = peak.indexes(signal, min_dist=56, thres=0.16) # Ignore un normal signls (with no peaks) if (len(peaks) == 0): return obj nn = tools.nn_intervals(peaks) # Ignore un normal signls (with no NN) if (len(nn) == 0): return # Standard obj = dict(td.nni_parameters(nn, peaks), **obj) obj = dict(td.nni_differences_parameters(nn, peaks), **obj) obj = dict(td.sdnn(nn, peaks), **obj) obj = dict(td.sdnn_index(nn, peaks), **obj) obj = dict(td.sdann(nn, peaks), **obj) obj = dict(td.rmssd(nn, peaks), **obj) obj = dict(td.sdsd(nn, peaks), **obj) obj = dict(td.nn50(nn, peaks), **obj) obj = dict(td.nn20(nn, peaks), **obj) obj = dict(td.geometrical_parameters(nn, peaks, plot=False), **obj) del obj['nni_histogram'] # Additional obj = dict({'cv': self._cv(obj['sdnn'], obj['nni_mean'])}, **obj) peaks_diff = tools.nni_diff(peaks) obj = dict({'MxDMn': max(peaks_diff) - min(peaks_diff)}, **obj) obj = dict({'MxRMn': max(peaks_diff) / min(peaks_diff)}, **obj) obj = dict({'Mo': stats.mode(peaks_diff)[0][0]}, **obj) counter = Counter(peaks_diff) idx = list(counter.keys()).index(obj["Mo"]) obj = dict({'AMo': list(counter.values())[idx]}, **obj) obj = dict({'SI': obj['AMo'] / (2 * obj['Mo'] * obj['MxDMn'])}, **obj) # Autocorrelation function # Frequency stats welch = frequency_domain(signal).stats['welch']['params'] bands = list(welch['fft_bands'].keys()) obj = dict({'TP': welch['fft_total']}, **obj) obj = dict({'HF': welch['fft_rel'][bands.index('hf')]}, **obj) obj = dict({'LF': welch['fft_rel'][bands.index('lf')]}, **obj) obj = dict({'VLF': welch['fft_rel'][bands.index('vlf')]}, **obj) obj = dict({'ULF': welch['fft_rel'][bands.index('ulf')]}, **obj) obj = dict({'HFav': welch['fft_abs'][bands.index('hf')]}, **obj) obj = dict({'LFav': welch['fft_abs'][bands.index('lf')]}, **obj) obj = dict({'VLFav': welch['fft_abs'][bands.index('vlf')]}, **obj) obj = dict({'ULFav': welch['fft_abs'][bands.index('ulf')]}, **obj) obj = dict({'(LF/HF)av': obj['LFav'] / obj['HFav']}, **obj) obj = dict({'IC': obj['LF'] / obj['VLF']}, **obj) for k in obj: if (math.isnan(obj[k])): obj[k] = 0 return obj