加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Raw_wave.py 5.09 KB
一键复制 编辑 原始数据 按行查看 历史
Liangwei 提交于 2023-06-30 15:11 . EASTimeDistribution
from enda_analys_result.RAW import CheckPackage
from enda_analys_result.RAW import OutData
import matplotlib.pyplot as plt
import os
import numpy as np
import time
# 波形检查
def Raw_wave(filename, length,status=0):
"""绘制原始数据包中的波形
status=0单波形画图
status=1时画整个通道波形图
"""
file = "Data/RAW/" + filename
data_Raw = [[0] for i in range(0, 16)]
with open(file, "r") as fd:
num=0
for line in fd.readlines():
if len(line) < 40:
continue
else:
datalist = line.split()
# print(datalist)
if CheckPackage(datalist, length):
data, channal,baseline= OutData(datalist, length)
max_index=data.index(max(data))
# print(data)
# print(channal)
#print(max_index%5==3)
#if channal <= 16 and max_index%5==3:
if channal!=33 :#channal == 10 or channal ==9:# channal == 16 or channal ==15 and max_index>=43: #筛选条件
if status ==0 :
'''average_data=[[0] for i in range(0, 100)] # 平滑
for i in range(0, 100):
if i==96 or i==97 or i==98 or i==99:
average_data[i]=0
data[i]=data[i]-baseline
else:
average_data[i]=(data[i]+data[i+1]+data[i+2]+data[i+3]+data[i+4])/5-baseline
data[i]=data[i]-baseline'''
WavePlot(data,channal,num,status,0)
#WavdePlot(data,channal,num,status,max_index)
#WavePlot(average_data,channal,num,status)
if max(data)<=8:
WriteTxt("peak8",[num,max(data)])
#if max(average_data)<=8:
# WriteTxt("average_data8",[num,max(average_data)])
num=num+1
else:
data_Raw[channal - 1].extend(data[:70]) ## 在画通道波形图时的截图原始数据包长度
WavePlot(data_Raw,0,0,status)
else:
continue
else:
continue
print(num)
def WavePlot(data,channal=0,num=0,status=0,max_index=0):
"""当max_index==0时将所有的wave存储在同一个文件夹下,
当max_index!=0时将波形按照位置存储在不同文件夹下"""
if status == 0:
if max_index==0:
ResultPath="./Consequence/Rawdata_20230312/"+"CH_"+str(channal) #
else:
ResultPath="./Consequence/Rawdata_20230312/"+str(max_index)+"_CH_"+str(channal) #
# 检查结果路径是否存在
if os.path.exists(ResultPath):
pass
# print("This path exists of " + ResultPath)
else:
os.makedirs(ResultPath)
print("create path:" + ResultPath + " success")
result = ResultPath +"\\"+ str(num)+".PNG"
fig, axs = plt.subplots()
title_Raw = "Wave:CH " + str(channal)
axs.set_title(title_Raw)
axs.set_xticks(np.linspace(0,100,51),minor=True) # 设置x轴小网格宽度
axs.grid(which="major",alpha=0.6) #大网格
axs.grid(which="minor",alpha=0.3) #小网格
#local=range(0,len(data))
axs.plot(data)
#标志最大值
max_data=max(data)
max_index=data.index(max_data)
show_max = '[' + str(max_index) + ' ' + str(max_data) + ']'
#axs.plot(max_index,show_max, 'ks')
axs.annotate(show_max, xy=(max_index, max_data),
xytext=(0.05, 0.9),
textcoords='figure fraction', # | 'figure fraction' | 0,0 是图形左下角,1,1 是右上角 |
horizontalalignment='left',
verticalalignment='bottom',
arrowprops=dict(arrowstyle="->", connectionstyle="arc3", color="r")
)
#save
fig.savefig(result)
plt.close()
print(str(num)+".PNG success")
return num
else:
for i in range(0, 16):
fig, axs = plt.subplots()
title_Raw = "Wave:CH" + str(i + 1)
axs.set_title(title_Raw)
axs.plot(data[i][1:])
plt.show()
def WriteTxt(filename,data):
file="./Result/Rawdata/"+filename+".txt"
if os.path.isfile(file):
pass
else:
creat_file = open(file, 'w')
creat_file.close()
with open(file,"a") as fp:
fp.write(str(data)+"\n")
if __name__=="__main__":
FileName=input("请输入文件名:")+".log"
time_start = time.time() #start
Raw_wave(FileName, 100,0)
time_end = time.time() #end_time
print("Begin time:"+str(time_start))
print("End_time:"+str(time_end))
print("time cost =%f s" %(time_end-time_start))
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化