def getBreathingCurve(vxpPath,scanTimes,isplot=0): #读取vxp文档的信息 with open(vxpPath, 'rb') as f: num = 0 amplitudes=[] phases=[] timestamps=[] ttlins=[] marks=[] for line in f: num += 1 if num>=11: line = line.strip() line = str(line, encoding = "utf8") #print(line) line = line.split(',') amplitudes.append(float(line[0])) phases.append(line[1]) time = line[2] if len(time)<4: ms = int(time) s = 0 else: ms = int(time[len(time)-3:]) s = int(time[0:len(time)-3]) timestamps.append(s+ms/1000) # unit [s] ttlins.append(int(line[4])) marks.append(line[5]) amplitudes = np.array(amplitudes) timestamps = np.array(timestamps) ttlins = np.array(ttlins) marks = np.array(marks) indexP = np.where( marks=='P')[0] indexZ = np.where( marks=='Z')[0] if len(indexP)>len(indexZ): indexP=indexP[0:len(indexZ)] else: indexZ=indexP[0:len(indexP)] #print(amplitudes[indexP].tolist()) # 计算base line,使振幅均值为0 baseZ = np.average((amplitudes[indexP]+amplitudes[indexZ])/2) print('baseZ = {}'.format(baseZ)) amplitudes = np.array(amplitudes) amplitudes = amplitudes - baseZ if isplot==1: plt.figure(figsize=(20,5)) plt.plot(timestamps,amplitudes,'k') index = np.where( ttlins==0)[0] if isplot==1: plt.plot(timestamps[index].tolist(),amplitudes[index].tolist(),'b') plt.plot(timestamps[indexP].tolist(),amplitudes[indexP].tolist(),'go') plt.plot(timestamps[indexZ].tolist(),amplitudes[indexZ].tolist(),'yo') amplitudesA=np.zeros(scanTimes.shape) for i in range(0,scanTimes.shape[0]): for j in range(0,scanTimes.shape[1]): distance = abs(scanTimes[i,j]-timestamps) index = [np.argmin(distance)] amplitudesA[i,j] = amplitudes[index[0]] #timestamps1.append(timestamps[index[0]]) #amplitudes=amplitudes1 #timestamps=timestamps1 if isplot==1: plt.plot(scanTimes[i,:],amplitudesA[i,:],'r.') if isplot==1: plt.show() return amplitudesA
时间: 2023-12-23 17:05:26 浏览: 80
gee_packages:GEE很棒的稳定软件包
这是一个Python函数,用于读取vxp文档中的信息,并计算出相应的呼吸曲线。函数接受三个参数:vxpPath(vxp文档的路径),scanTimes(扫描时间)和isplot(是否绘制呼吸曲线图)。函数首先打开vxp文档,读取其中的振幅、相位、时间戳、TTL以及标记等信息。然后,函数计算出基线(base line),使得振幅均值为0。接下来,函数根据扫描时间计算出每个时间点对应的振幅值,并返回呼吸曲线。如果isplot参数为1,则函数还会绘制呼吸曲线图。
阅读全文