64 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			64 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| import numpy as np
 | |
| import os
 | |
| from scipy.stats import pearsonr
 | |
| 
 | |
| from global_var import global_var_init
 | |
| cycle, fs_ecg, fs_ppg, record_name, record_name_csv, data_path = global_var_init()
 | |
| 
 | |
| from ecg_peaks_val import ecg_peaks_val
 | |
| (P_peaks, Q_peaks, R_peaks, S_peaks, T_peaks,
 | |
| P_onsets, P_offsets, T_onsets, T_offsets,
 | |
| P_peaks_values, Q_peaks_values, R_peaks_values, S_peaks_values, T_peaks_values, 
 | |
| P_onsets_values, P_offsets_values, T_onsets_values, T_offsets_values,
 | |
| PQ_baseline) = ecg_peaks_val()
 | |
| 
 | |
| from ppg_peaks_val import ppg_peaks_val
 | |
| (on, on_toArea, sp, dn, dp,
 | |
| on_values, on_toArea_values, sp_values, dn_values, dp_values,
 | |
| u, u_toArea, v, w,
 | |
| u_values, u_toArea_values, v_values, w_values,
 | |
| a, a_toArea, b, c, e, f,
 | |
| a_values, a_toArea_values, b_values, c_values, e_values, f_values) = ppg_peaks_val()
 | |
| 
 | |
| num1 = [ 
 | |
|             np.diff(P_peaks), np.diff(Q_peaks), np.diff(R_peaks), np.diff(S_peaks), np.diff(T_peaks),
 | |
|             np.diff(P_onsets), np.diff(P_offsets),
 | |
|             np.diff(T_onsets), np.diff(T_offsets),
 | |
|             
 | |
| ]
 | |
| 
 | |
| 
 | |
| num2 = [
 | |
|             np.diff(on), np.diff(sp), np.diff(dn), np.diff(dp),
 | |
|             np.diff(u), np.diff(v), np.diff(w),
 | |
|             np.diff(a), np.diff(b), np.diff(c), np.diff(e), np.diff(f),
 | |
|             
 | |
| ]
 | |
| 
 | |
| # 定义保存的目录
 | |
| output_dir = f"D://python_study//big_boss//doc//output//{record_name}"
 | |
| # 定义文件名
 | |
| filename = f"{record_name}_output_2.txt"
 | |
| # 组合目录和文件名
 | |
| file_path = os.path.join(output_dir, filename)
 | |
| print("正在将相关性系数输出到文本中,请稍后。。。。。")
 | |
| 
 | |
| # 确保输出目录存在
 | |
| os.makedirs(output_dir, exist_ok=True)
 | |
| 
 | |
| for n1 in num1:
 | |
|     for n2 in num2:
 | |
|         # 检查 n1 和 n2 是否是有效的数组
 | |
|         if isinstance(n1, np.ndarray) and isinstance(n2, np.ndarray) and len(n1) > 1 and len(n2) > 1 and len(n1) == len(n2):
 | |
|             pearson_corr, _ = pearsonr(n1, n2)
 | |
|             # 打开文件,追加输出
 | |
|             with open(file_path, 'a') as f:
 | |
|                 f.write(str(pearson_corr) + '\n')
 | |
|         else:
 | |
|             print(f"Skipping invalid arrays: n1={n1}, n2={n2}")
 | |
| 
 | |
|     # 打开文件以进行追加
 | |
|     with open(file_path, 'a') as f:
 | |
|         f.write('##########################################' + '\n') 
 | |
| 
 | |
| print("输出完毕!") |