You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
401 lines
11 KiB
401 lines
11 KiB
import sys |
|
import numpy as np |
|
import processing |
|
import doc |
|
import datetime |
|
import os |
|
import numpy as np |
|
from matplotlib import pyplot as plt |
|
import docx |
|
import pandas |
|
import openpyxl |
|
import shutil |
|
|
|
|
|
def scinot(num: float, n: int) -> str: |
|
ret = "" |
|
if num < 0: |
|
ret += "-" |
|
num = -num |
|
r = 0 |
|
if num > 10: |
|
while num > 10: |
|
num = num / 10 |
|
r += 1 |
|
if num < 1: |
|
while num < 1: |
|
if num == 0: |
|
break |
|
num = num * 10 |
|
r -= 1 |
|
ret += str(int(num)) |
|
if n > 0: |
|
ret += "." |
|
while n > 0: |
|
num = num - int(num) |
|
num = num * 10 |
|
ret += str(int(num)) |
|
n -= 1 |
|
if r != 0: |
|
ret += "e" |
|
if r > 0: |
|
ret += "+" |
|
ret += str(r) |
|
return ret |
|
|
|
|
|
# 0 光功率 float |
|
# 1 黑体距离 |
|
# 2 低温温度 |
|
# 3 高温温度 |
|
# 4 测试时钟 |
|
# 5 帧频 |
|
# 6 环境温度 |
|
# 7 环境湿度 |
|
# 8 像元大小 |
|
# 9 积分时间 |
|
# 10 行数 |
|
# 11 列数 |
|
# 12 截止波长 |
|
# 13 GPOL值 |
|
# 14 探测器编号 |
|
# 15 NETD阈值 |
|
# 16 G因子 |
|
# 17 相邻阈值 |
|
# 18 相邻方向 |
|
# 19 低温文件 |
|
# 20 高温文件 |
|
# 21 参考电压 8192对应的电压值 |
|
|
|
|
|
if __name__ == "__main__": |
|
args = sys.argv |
|
|
|
os.chdir("reportGen/"+ args[14 +1]) |
|
t = datetime.datetime.now() |
|
fpath = ( |
|
|
|
str(t.year) |
|
+ "-" |
|
+ str(t.month) |
|
+ "-" |
|
+ str(t.day) |
|
+ "-" |
|
+ str(t.hour) |
|
+ "-" |
|
+ str(t.minute) |
|
+ "-" |
|
+ str(t.second) |
|
) |
|
os.mkdir(fpath) |
|
os.chdir(fpath) |
|
|
|
rows = int(float(args[10 +1])) |
|
cols = int(float(args[11 +1])) |
|
|
|
lows = np.frombuffer(open("../"+args[19 +1], "rb").read(), dtype=np.uint16).reshape( |
|
100, rows, cols |
|
).astype(np.float64)/4/8192*float(args[21+1]) |
|
vn1 = np.average(lows, axis=0) |
|
vnt1 = np.std(lows,axis=0) |
|
highs = np.frombuffer(open("../"+args[20 +1], "rb").read(), dtype=np.uint16).reshape( |
|
100, rows, cols |
|
).astype(np.float64)/4/8192*float(args[21+1]) |
|
vn2 = np.average(highs,axis=0) |
|
|
|
plt.cla() |
|
plt.clf() |
|
plt.imshow(vn1, cmap="gist_rainbow") |
|
plt.colorbar() |
|
plt.savefig("p7.png", bbox_inches="tight", pad_inches=0.3) |
|
|
|
plt.cla() |
|
plt.clf() |
|
plt.imshow(vn2, cmap="gist_rainbow") |
|
plt.colorbar() |
|
plt.savefig("p8.png", bbox_inches="tight", pad_inches=0.3) |
|
|
|
plt.cla() |
|
plt.clf() |
|
plt.imshow(vnt1, cmap="gist_rainbow") |
|
plt.colorbar() |
|
plt.savefig("p9.png", bbox_inches="tight", pad_inches=0.3) |
|
|
|
# plt.figure(dpi=192, figsize=(16, 12)) |
|
|
|
min, max, hist0, hist1 = processing.getDualHist(vn1, vn2) |
|
x = np.linspace(min, max, 256) |
|
plt.cla() |
|
plt.clf() |
|
plt.bar(x, hist0, color="red", width=(x[1] - x[0]) * 1.01) |
|
plt.title("VT1直方图", fontproperties="SimHei", fontsize=20) |
|
# plt.show() |
|
plt.savefig("p10.png", bbox_inches="tight", pad_inches=0.3) |
|
|
|
plt.cla() |
|
plt.clf() |
|
plt.bar(x, hist1, color="red", width=(x[1] - x[0]) * 1.01) |
|
plt.title("VT2直方图", fontproperties="SimHei", fontsize=20) |
|
# plt.show() |
|
plt.savefig("p11.png", bbox_inches="tight", pad_inches=0.3) |
|
|
|
min, max, hist = processing.getHist(vnt1) |
|
x = np.linspace(min, max, 256) |
|
plt.cla() |
|
plt.clf() |
|
plt.bar(x, hist, color="red", width=(x[1] - x[0]) * 1.01) |
|
plt.title("VnT1直方图", fontproperties="SimHei", fontsize=20) |
|
# plt.show() |
|
plt.savefig("P12.png", bbox_inches="tight", pad_inches=0.3) |
|
|
|
# 获取差值,根据平均值判断正负,再确保结果为正 |
|
dimage = vn2 - vn1 |
|
if np.average(dimage) < 0: |
|
dimage = -dimage |
|
|
|
plt.cla() |
|
plt.clf() |
|
plt.imshow(dimage, cmap="gist_rainbow") |
|
plt.colorbar() |
|
plt.clim(np.average(dimage) / 2, np.max(dimage)) |
|
plt.savefig("p2.png", bbox_inches="tight", pad_inches=0.3) |
|
|
|
min, max, hist = processing.getHist(dimage) |
|
x = np.linspace(min, max, 256) |
|
plt.cla() |
|
plt.clf() |
|
plt.bar(x, hist, color="red", width=(x[1] - x[0]) * 1.01) |
|
plt.title("摆幅V直方图", fontproperties="SimHei", fontsize=20) |
|
# plt.show() |
|
plt.savefig("p5.png", bbox_inches="tight", pad_inches=0.3) |
|
# 差值除以噪声, 确保为正数 |
|
snr = dimage / (vnt1 + 0.00001) |
|
|
|
plt.cla() |
|
plt.clf() |
|
plt.imshow(snr, cmap="gist_rainbow") |
|
plt.colorbar() |
|
plt.clim(np.average(snr) / 2, np.max(snr)) |
|
plt.savefig("p3.png", bbox_inches="tight", pad_inches=0.3) |
|
|
|
min, max, hist = processing.getHist(snr) |
|
x = np.linspace(min, max, 256) |
|
plt.cla() |
|
plt.clf() |
|
plt.bar(x, hist, color="red", width=(x[1] - x[0]) * 1.01) |
|
plt.title("SNR直方图", fontproperties="SimHei", fontsize=20) |
|
# plt.show() |
|
plt.savefig("p6.png", bbox_inches="tight", pad_inches=0.3) |
|
|
|
# stephen = 5.673*np.power(10,-12) # |
|
Ad = np.power(float(args[8 +1]), 2) / 100000000 # 像元尺寸 |
|
p = float(args[0 +1]) # 光功率(light power) |
|
tao = float(args[9 +1]) / 1000 # 积分时间(IT)ms |
|
# Dn图像生成 |
|
imageD = snr * np.sqrt(Ad / tao / 2) / p |
|
plt.cla() |
|
plt.clf() |
|
plt.imshow(imageD, cmap="gist_rainbow") |
|
plt.colorbar() |
|
plt.clim(np.average(imageD) / 2, np.max(imageD)) |
|
plt.savefig("p1.png", bbox_inches="tight", pad_inches=0.3) |
|
|
|
min, max, hist = processing.getHist(imageD) |
|
x = np.linspace(min, max, 256) |
|
plt.cla() |
|
plt.clf() |
|
plt.bar(x, hist, color="red", width=(x[1] - x[0]) * 1.01) |
|
plt.title("Dn直方图", fontproperties="SimHei", fontsize=20) |
|
# plt.show() |
|
plt.savefig("p4.png", bbox_inches="tight", pad_inches=0.3) |
|
|
|
maskd, maskh = processing.getValidPoint(dimage, vnt1) |
|
|
|
d = [] |
|
h = [] |
|
for i in range(dimage.shape[0]): |
|
for j in range(dimage.shape[1]): |
|
if maskd[i, j] > 0: |
|
d.append([i, j]) |
|
if maskh[i, j] > 0: |
|
h.append([i, j]) |
|
d = np.array(d) |
|
h = np.array(h) |
|
plt.imsave("坏点.png", maskd, cmap="gray") |
|
plt.imsave("热点.png", maskh, cmap="gray") |
|
f1 = open("坏点.txt", "w") |
|
f2 = open("热点.txt", "w") |
|
for i in range(d.shape[0]): |
|
f1.write(str(i) + ":" + str(d[i, 0]) + "," + str(d[i, 1]) + "\n") |
|
for i in range(h.shape[0]): |
|
f2.write(str(i) + ":" + str(h[i, 0]) + "," + str(h[i, 1]) + "\n") |
|
f1.close() |
|
f2.close() |
|
|
|
plt.cla() |
|
plt.clf() |
|
|
|
ax = plt.gca() |
|
ax.xaxis.set_ticks_position("top") |
|
# ax.invert_yaxis() |
|
# plt.figure(dpi=192, figsize=(16, 12)) |
|
plt.xlim(0, cols) |
|
plt.ylim(rows, 0) |
|
plt.scatter(d[:, 1], d[:, 0], color="blue", s=2) |
|
plt.scatter(h[:, 1], h[:, 0], color="red", s=2) |
|
plt.title( |
|
"死像元(蓝):" |
|
+ str(int(np.sum(maskd))) |
|
+ ";过热像元(红):" |
|
+ str(int(np.sum(maskh))), |
|
fontproperties="SimHei", |
|
fontsize=20, |
|
) |
|
plt.savefig("p13.png") |
|
|
|
imagedirs = [] |
|
|
|
envs = [] |
|
rsts = [] |
|
|
|
envs.append(args[0 +1]) |
|
envs.append(args[1 +1] + "cm") |
|
envs.append(args[8 +1] + "um") |
|
envs.append(args[12 +1] + "um") |
|
envs.append(args[13 +1] + "V") |
|
envs.append(args[9 +1] + "ms") |
|
envs.append(args[11 +1] + "x" + args[10 +1]) |
|
envs.append(args[2 +1] + "℃") |
|
envs.append(args[3 +1] + "℃") |
|
envs.append(args[4 +1] + "MHz") |
|
envs.append(args[5 +1]) |
|
envs.append(args[6 +1] + "℃") |
|
envs.append(args[7 +1] + "%RH") |
|
|
|
rsts.append(str(int(np.sum(maskd)))) |
|
rsts.append(str(int(np.sum(maskh)))) |
|
rsts.append( |
|
format( |
|
np.sum(vnt1 * (1 - np.sign(maskd + maskh))) |
|
/ np.sum(1 - np.sign(maskd + maskh)), |
|
".5f", |
|
) |
|
+ "V" |
|
) |
|
rsts.append( |
|
scinot( |
|
np.sum(dimage * (1 - np.sign(maskd + maskh))) |
|
/ np.sum(1 - np.sign(maskd + maskh)) |
|
/ p, |
|
2, |
|
) |
|
) |
|
rsts.append( |
|
scinot( |
|
np.sum(imageD * (1 - np.sign(maskd + maskh))) |
|
/ np.sum(1 - np.sign(maskd + maskh)), |
|
2, |
|
) |
|
) |
|
avg = np.sum(dimage * (1 - np.sign(maskd + maskh))) / np.sum( |
|
1 - np.sign(maskd + maskh) |
|
) |
|
nu = np.sqrt( |
|
np.sum(np.power((dimage - avg) * (1 - np.sign(maskd + maskh)), 2)) |
|
/ np.sum(1 - np.sign(maskd + maskh)) |
|
) |
|
rsts.append(format(nu / avg * 100, "5f") + "%") |
|
rsts.append(format(np.average(1 - np.sign(maskd + maskh)) * 100, ".5f") + "%") |
|
|
|
rsts.append( |
|
format( |
|
np.sum(dimage * (1 - np.sign(maskd + maskh))) |
|
/ np.sum(1 - np.sign(maskd + maskh)), |
|
".3f", |
|
) |
|
+ "V" |
|
) |
|
rsts.append( |
|
format( |
|
np.sum(vn1 * (1 - np.sign(maskd + maskh))) |
|
/ np.sum(1 - np.sign(maskd + maskh)), |
|
".3f", |
|
) |
|
+ "V" |
|
) |
|
rsts.append( |
|
format( |
|
np.sum(vn2 * (1 - np.sign(maskd + maskh))) |
|
/ np.sum(1 - np.sign(maskd + maskh)), |
|
".3f", |
|
) |
|
+ "V" |
|
) |
|
|
|
temp = float(args[3 +1]) - float(args[2 +1]) |
|
netd0 = vnt1 / (dimage + 0.000001) * (1 - np.sign(maskd + maskh)) * temp * 1000 |
|
netd1 = ( |
|
np.sum(vnt1 * (1 - np.sign(maskd + maskh))) |
|
/ np.sum(dimage * (1 - np.sign(maskd + maskh))) |
|
* temp |
|
* 1000 |
|
) |
|
print("temp = ", temp, "netd = ", netd1, "netd0 max = ", np.max(netd0)) |
|
rsts.append( |
|
format(np.sum(netd0) / np.sum(1 - np.sign(maskd + maskh)), ".3f") + "mK" |
|
) |
|
rsts.append( |
|
str(int(np.sum((netd0 * (1 - np.sign(maskd + maskh))) > float(args[15 +1])))) |
|
) |
|
|
|
Glamda = ( |
|
float(args[16 +1]) |
|
* np.sum(imageD * (1 - np.sign(maskd + maskh))) |
|
/ np.sum(1 - np.sign(maskd + maskh)) |
|
) |
|
|
|
plt.cla() |
|
plt.clf() |
|
plt.imshow(netd0, cmap="gist_rainbow") |
|
plt.colorbar() |
|
plt.clim(np.min(netd0), np.average(netd0) * 2) |
|
plt.savefig("p3.png", bbox_inches="tight", pad_inches=0.3) |
|
|
|
min, max, hist = processing.getHist(netd0) |
|
x = np.linspace(min, max, 256) |
|
plt.cla() |
|
plt.clf() |
|
plt.bar(x, hist, color="red", width=(x[1] - x[0]) * 1.01) |
|
plt.title("netd直方图", fontproperties="SimHei", fontsize=20) |
|
# plt.show() |
|
plt.savefig("p6.png", bbox_inches="tight", pad_inches=0.3) |
|
|
|
rsts.append(scinot(Glamda, 3)) |
|
rsts.append(format(netd1, ".3f") + "mK") |
|
|
|
temp = float(args[3]) - float(args[2]) |
|
|
|
imagedirs.append("p1.png") |
|
imagedirs.append("p2.png") |
|
imagedirs.append("p3.png") |
|
imagedirs.append("p4.png") |
|
imagedirs.append("p5.png") |
|
imagedirs.append("p6.png") |
|
imagedirs.append("p7.png") |
|
imagedirs.append("p8.png") |
|
imagedirs.append("p9.png") |
|
imagedirs.append("p10.png") |
|
imagedirs.append("p11.png") |
|
imagedirs.append("p12.png") |
|
imagedirs.append("p13.png") |
|
# imagedirs.append("p1.png") |
|
r = int(float(args[17 +1])) |
|
dir = int(float(args[18 +1])) |
|
clus = processing.calcCluster(r, dir, np.sign(maskd + maskh)) |
|
|
|
# self.model = docx.Document(self.pwd+"/model.docx") |
|
|
|
doc.rewrite("../../",args[14+1], envs, rsts, clus, imagedirs, type=1) |
|
|
|
today = datetime.date.today() |
|
# data = {}
|
|
|