最近想起来了,现在已经改了一遍,不过没加图形窗口,我觉得没必要以下是.py、.exe、源码
改动内容:增加了删去错误数据的部分,改动部分代码,增加可读性,改正时间和力标反的错误,改正数据单位的错误,减小exe文件大小
(第一行注释是改名了)
#by某倒吊的亚雷斯塔(辰星引力航天工作室)
import matplotlib.pyplot as plt
f = open("TEST_SD.TXT")
c = [i for i in f.read().split('\n') if i != '']
time = [float(i.split(',')[0]) for i in c]
force = [float(i.split(',')[1]) for i in c]
I = 0
for i in force:
if i < 0:
i = 0#删除负数的错误数据
while force[0] < 20:
force.pop(0)
time.pop(0)#删除试车前的数据
while force[-1] < 20:
force.pop(-1)
time.pop(-1)#删除试车后的数据,不直接设定阈值是考虑到多推力峰
t0 = time[0]
for i in range(len(time)):
force[i]*=0.098#我的实验得到的数据单位是0.098N,我不知道是不是都这样,如果不是的话可以改下代码
time[i] -= t0
for i in range(len(time)-1):
dt = time[i+1]-time[i]
di = force[i]*dt
I += di#积分算总冲
data = input('''请输入相关数据,格式如下:
发动机名称/直径(mm)/长度(mm)/开伞延时(s)/燃料质量(kg)/总质量(kg)/制造商
若要跳过请输入0,不计算比冲,不形成eng文件\n''')
if data != "0":
d = data.split("/")
name = d[0]
diameter = int(d[1])
length = int(d[2])
dertatime = int(d[3])
fuelmass = float(d[4])
mass = float(d[5])
maker = d[6]
else:
mass = 1
f.close()
f1 = open("时间-推力表.txt", "w")
f1.write("总冲(N.s):%f\n"%I)
if data != "0":
isp = (I/mass)/9.8#计算以秒为单位的比冲
f1.write("比冲(s):%f\n"%isp)
fmax = force[0]
for i in range(len(force)):
if fmax < force[i]:
fmax = force[i]#计算最大推力
f1.write("最大推力(N):%f\n"%fmax)
f1.write("时间(s) 推力(N)\n")
for i in range(len(time)):
f1.write("%f %f\n"%(time[i],force[i]))
f1.close()
fig = plt.figure(figsize=(20, 10), dpi=100)
plt.plot(time, force)
plt.xlabel("t(s)")
plt.ylabel("F(N)")
plt.title("F - t")
plt.show()
fig.savefig("F - t 图")#绘制并保存推力时间曲线
if data != "0":
f2 = open("导入openrocket的数据.eng","w")
f2.write("%s %d %d %d %f %f %s\n"%(name, diameter, length, dertatime, fuelmass, mass, maker))
for i in range(len(time)):
f2.write("%.3f %f\n"%(time[i], force[i]))
f2.write(";")
f2.close()#生成可以直接导入openrocket的.eng文件