Commit 08307ab1 authored by Holger Niemann's avatar Holger Niemann
Browse files

some changes back to old get program

parent 782d0a01
...@@ -217,7 +217,7 @@ def correct_images(images,badpixels): ...@@ -217,7 +217,7 @@ def correct_images(images,badpixels):
if type(badpixels)!=int: if type(badpixels)!=int:
if type(images) == list: if type(images) == list:
# return corrected images also as list of 2D arrays # return corrected images also as list of 2D arrays
images = restore_bad_pixels(images, np.invert(badpixels==1)).astype(np.float32) images = restore_bad_pixels(images, np.invert(badpixels==1))#.astype(np.float32)
images = list(images) images = list(images)
else: else:
# keep shape # keep shape
......
...@@ -375,13 +375,13 @@ def download_raw_images_by_times(port,starttime,stoptime,version=0,intervalSize= ...@@ -375,13 +375,13 @@ def download_raw_images_by_times(port,starttime,stoptime,version=0,intervalSize=
if fastDL: if fastDL:
def download_raw_images_by_program_via_png(port,program,time_s=0,version=0,threads=1, verbose=0): def download_raw_images_by_program_via_png(port,program,time_s=0,version=0,threads=1, verbose=0):
# prog=AKF_1.get_program_from_PID(program) prog=AKF_1.get_program_from_PID(program)
try: # try:
t_program = AKF_2.get_program_from_to(program) # t_program = AKF_2.get_program_from_to(program)
prog =AKF_2.get_program_list(t_program[0], t_program[1]) # prog =AKF_2.get_program_list(t_program[0], t_program[1])
# if prog[0]: if prog[0]:
starttime=prog[0]['trigger']['1'][0] starttime=prog[1]['trigger']['1'][0]
stoptime=prog[0]['trigger']['6'][0] stoptime=prog[1]['trigger']['6'][0]
success=True success=True
OP=get_OP_by_time(starttime) OP=get_OP_by_time(starttime)
Cam=portcamdict[OP]['AEF'+str(port)] Cam=portcamdict[OP]['AEF'+str(port)]
...@@ -465,8 +465,8 @@ if fastDL: ...@@ -465,8 +465,8 @@ if fastDL:
times=times+resultdict[order.index(i)][2] times=times+resultdict[order.index(i)][2]
del resultdict del resultdict
return success,np.array(times),images return success,np.array(times),images
except Exception as E: # except Exception as E:
raise Exception(E) # raise Exception(E)
def download_raw_images_png_by_times_thread(port,times,out_q,threadnumber,version=0): def download_raw_images_png_by_times_thread(port,times,out_q,threadnumber,version=0):
...@@ -593,15 +593,15 @@ def download_raw_parlog_by_times(port,starttime,stoptime,version=0): ...@@ -593,15 +593,15 @@ def download_raw_parlog_by_times(port,starttime,stoptime,version=0):
def get_INFRATEC_filter_by_program(program,version=0): def get_INFRATEC_filter_by_program(program,version=0):
# prog=AKF_1.get_program_from_PID(program) prog=AKF_1.get_program_from_PID(program)
try: # try:
t_program = AKF_2.get_program_from_to(program) # t_program = AKF_2.get_program_from_to(program)
prog =AKF_2.get_program_list(t_program[0], t_program[1]) # prog =AKF_2.get_program_list(t_program[0], t_program[1])
# if prog[0]: if prog[0]:
starttime=prog[0]['trigger']['1'][0] starttime=prog[1]['trigger']['1'][0]
stoptime=prog[0]['trigger']['6'][0] stoptime=prog[1]['trigger']['6'][0]
return get_INFRATEC_filter_by_times(starttime,stoptime,50,version) return get_INFRATEC_filter_by_times(starttime,stoptime,50,version)
except: else:#except:
print("cannot find the program") print("cannot find the program")
return False,0,0 return False,0,0
...@@ -679,15 +679,15 @@ def get_camera_temp_by_times(port,starttime,stoptime,version=0): ...@@ -679,15 +679,15 @@ def get_camera_temp_by_times(port,starttime,stoptime,version=0):
return AKF_1.read_restdb(larchivepath+"DATASTREAM/V"+str(version)+"/1/cameratempetarure/_signal.json?from="+str(starttime)+"&upto="+str(stoptime)) return AKF_1.read_restdb(larchivepath+"DATASTREAM/V"+str(version)+"/1/cameratempetarure/_signal.json?from="+str(starttime)+"&upto="+str(stoptime))
def get_sensor_temp_by_program(port,program,version=0): def get_sensor_temp_by_program(port,program,version=0):
# prog=AKF_1.get_program_from_PID(program) prog=AKF_1.get_program_from_PID(program)
try: # try:
t_program = AKF_2.get_program_from_to(program) # t_program = AKF_2.get_program_from_to(program)
prog =AKF_2.get_program_list(t_program[0], t_program[1]) # prog =AKF_2.get_program_list(t_program[0], t_program[1])
# if prog[0]: if prog[0]:
starttime=prog[0]['trigger']['1'][0] starttime=prog[1]['trigger']['1'][0]
stoptime=prog[0]['trigger']['6'][0] stoptime=prog[1]['trigger']['6'][0]
return get_sensor_temp_by_times(port,starttime,stoptime,version) return get_sensor_temp_by_times(port,starttime,stoptime,version)
except: else:#except:
print("cannot find the program") print("cannot find the program")
return False,0,0 return False,0,0
...@@ -1332,14 +1332,17 @@ def apply_NUC(images,gain,offset,gain_error=0,offset_error=0,give_error=False): ...@@ -1332,14 +1332,17 @@ def apply_NUC(images,gain,offset,gain_error=0,offset_error=0,give_error=False):
return 0 return 0
def get_calib_data(port,program,emissivity=0.8,Temp_V=2,version=0,back_emissivity=0.8, verbose=0): def get_calib_data(port,program,emissivity=0.8,Temp_V=2,version=0,back_emissivity=0.8, verbose=0):
# prog=AKF_1.get_program_from_PID(program) prog=AKF_1.get_program_from_PID(program)
try: # try:
t_program = AKF_2.get_program_from_to(program) # t_program = AKF_2.get_program_from_to(program)
prog =AKF_2.get_program_list(t_program[0], t_program[1]) # prog =AKF_2.get_program_list(t_program[0], t_program[1])
# if prog[0]: if prog[0]:
t0=prog[0]['trigger']['0'][0] t0=prog[1]['trigger']['0'][0]
t1=prog[0]['trigger']['1'][0] t1=prog[1]['trigger']['1'][0]
t6=prog[0]['trigger']['6'][0] t6=prog[1]['trigger']['6'][0]
# except Exception as E:
# print("Warning: Program was not found: ",E)
# return 0,0,0,0,0,0,0,0,0,0
OP=get_OP_by_program(program) OP=get_OP_by_program(program)
Camera=portcamdict[OP]['AEF'+str(port)] Camera=portcamdict[OP]['AEF'+str(port)]
if Camera.split("_")[0]=="Infratec": if Camera.split("_")[0]=="Infratec":
...@@ -1468,9 +1471,9 @@ def get_calib_data(port,program,emissivity=0.8,Temp_V=2,version=0,back_emissivit ...@@ -1468,9 +1471,9 @@ def get_calib_data(port,program,emissivity=0.8,Temp_V=2,version=0,back_emissivit
else: else:
raise Exception("no exposure time found") raise Exception("no exposure time found")
return background,LUT,refT,gain,offset,badpixels,t_exp,cfilter,gain_error,offset_error return background,LUT,refT,gain,offset,badpixels,t_exp,cfilter,gain_error,offset_error
except: # except Exception as E:
print("Warning: Program was not found") # print("Warning: Program was not found: ",E)
return 0,0,0,0,0,0,0,0,0,0 # return 0,0,0,0,0,0,0,0,0,0
def find_badpixels(port, gain, offset, init_bp_list=None, niterations=3, def find_badpixels(port, gain, offset, init_bp_list=None, niterations=3,
tolerance=10, plot_it=False, verbose=0): tolerance=10, plot_it=False, verbose=0):
...@@ -1607,122 +1610,56 @@ if __name__=='__main__': ...@@ -1607,122 +1610,56 @@ if __name__=='__main__':
print("local function calling") print("local function calling")
# #
# #status,time,images,valid=get_temp_from_raw_by_program_V1(51,"20171018.019",time_s=0,emi=0.8,divertorpart="all",version=1) # #status,time,images,valid=get_temp_from_raw_by_program_V1(51,"20171018.019",time_s=0,emi=0.8,divertorpart="all",version=1)
## status1,time1,images1,valid1=get_temp_from_raw_by_program_V1(41,"20171024.016",time_s=[0.75,0.99],emi=0.8,version=1) # status1,time1,images1,valid1=get_temp_from_raw_by_program_V1(41,"20171024.016",time_s=[0.75,0.99],emi=0.8,version=1)
## exist,time1,frames=download_raw_images_by_program_via_png(41,"20171024.016",time_s=[0.75,0.99],version=1,threads=1) ## exist,time1,frames=download_raw_images_by_program_via_png(41,"20171024.016",time_s=[0.75,0.99],version=1,threads=1)
# import h5py as h5 port=51
# # prog="20171108.015"
# for prog in ["20171108.015"]:#"20171109.010","20170926.009","20171207.009"]: # prog="20171025.030"
# for port in [20,21]: prog="20171012.035"
# try: status,time,images,valid=get_temp_from_raw_by_program(port,prog,time_s=[0,1],emi=0.82,T_version=2,version=0,threads=1,give_ERROR=False,use_firstframe_as_background=True)
# texp=get_exposure_by_program(port,prog)
# except: # bla=get_exposure_by_program(port,prog)
# texp=[False] # status2,time2,images2=download_raw_images_by_program_via_png(port,prog,time_s=[0,0.2],threads=1)
# if texp[0]: import holn.functions as fu
# texp=texp[2][0] import h5py as h5
# background=download_background_by_program(port,prog,texp) szene=h5.File("X:\\E4 Diagnostics\\QIR\Calibrations\\scene_models\\AEF"+str(port)+"\\AEF"+str(port)+"_scene_model.h5")
# Xloc=np.asarray(szene['x'])
# if background[0]: Yloc=np.asarray(szene['y'])
# Zloc=np.asarray(szene['z'])
## btest=check_backgroundframe(background[2]) CAD=np.asarray(szene['CAD'])
## if not btest[0]: plt.figure()#
# plt.figure() plt.imshow(CAD,cmap='gray')
# plt.imshow(background[2],vmin=np.mean(background[2])-200,vmax=np.mean(background[2])+200) plt.imshow(images[-1],vmin=300,vmax=750,cmap=fu.exJet_trans)
## plt.colorbar() cb=plt.colorbar()
# plt.title(prog+" "+str(port)) cb.set_label("temperature K", rotation=270,labelpad=26,fontsize=26)
cb.ax.tick_params(labelsize=26)
# cold=download_NUC_by_program(port,prog,texp)
# if cold[0]: # tmax=[]
# if port==11: # port=20
# portnr=21 # NUCblock=download_NUC_by_program(port,prog,bla[2][0])
# elif port==21: # background,LUT,refT,gain,offset,badpixels,t_exp,cfilter,gain_error,offset_error=get_calib_data(port,prog)
# portnr=11 # refcoldhot=IR_tools.load_ref_images("AEF"+str(port),bla[2][0])
# else: # recal_gain_offset=IR_tools.calculate_gain_offset_image_pix(NUCblock[1][2].copy(),None,refcoldhot[0].copy(),refcoldhot[1].copy())
# portnr=port
# camera=portcamdict['OP1.2a']['AEF'+str(portnr)]
# path="\\\\sv-e4-fs-1\\E4-Mitarbeiter\\E4 Diagnostics\\QIR\\Calibrations\\IRCamReferenceImages\\"
## path="\\\\sv-e4-fs-1\\E4-Mitarbeiter\\E4 Diagnostics\\QIR\\Software\\QI-RealTime\\v1.0.1\\QIR-IrAnalysis\\release\\Config\\Thermal calibration\\"
# file=h5.File(path+"IRCAM_"+camera.split("_")[2]+"\\"+camera+"_nuc_reference_cold_"+str(int(texp))+"us.h5",'r')
## file=h5.File(path+camera+"\\"+camera+"_nuc_reference_cold_"+str(int(texp))+"us.h5",'r')
# refframe=np.array(file[camera+"_nuc_reference_cold_"+str(int(texp))+"us.h5"])
## ctest=check_coldframe_by_refframe(cold[1][2],refframe,plot_it=False)
# references=[]
# shapi=np.shape(refframe)
# for i in [int(shapi[1]//4),int(shapi[1]//2),int(shapi[1]//4*3)]:
# dataline=refframe[0:shapi[0],i]
# references.append(dataline-np.mean(dataline))
# ctest=IR_tools.check_coldframe(cold[1][2],references,plot_it=True)
# print(ctest,port,prog)
# if not ctest[0]:
# bla=np.array(cold[1][2])-np.array(refframe)
# print(np.mean(bla),np.max(bla),np.min(bla),np.std(bla),(np.max(bla)-np.min(bla))/np.mean(bla),port)
# dataset=[]
# threshold=100
# shapi=np.shape(bla)
# plt.figure()
# for i in [int(shapi[1]//4),int(shapi[1]//2),int(shapi[1]//4*3)]:
# referenceline=bla[0:shapi[0],i]
# meanref=referenceline-np.mean(referenceline)
# dataset.append(meanref)#np.max(meanref[100:-99])-np.min(meanref[100:-99]))
## plt.plot(meanref,label=str(i))
# for j in range(len(dataset)):
# if j==0:
# plt.plot(dataset[j]-dataset[-1],label=str(j))
# else:
# plt.plot(dataset[j]-dataset[j-1],label=str(j))
# plt.title(prog+"_AEF"+str(port))
# if np.mean(dataset)>threshold:
# valid=False
# else:
# valid=True
# print(valid,np.mean(dataset))#,np.mean(dataset[0]-dataset[-1]),np.mean(dataset[1]-dataset[0]),np.mean(dataset[2]-dataset[1]))
# plt.figure() # plt.figure()
# plt.imshow(cold[1][2],vmin=np.mean(cold[1][2])-500,vmax=np.mean(cold[1][2])+500) # plt.imshow(NUCblock[1][0]-recal_gain_offset[0])
# plt.colorbar() # plt.title("gain")
# plt.title(prog+" "+str(port))
# plt.figure() # plt.figure()
# plt.imshow(bla,vmin=np.mean(bla)-100,vmax=np.mean(bla)+100) # plt.imshow(NUCblock[1][1]-recal_gain_offset[1])
# plt.colorbar() # plt.title("offset")
# ima1=apply_NUC(images2.copy(),NUCblock[1][0],NUCblock[1][1])
# ima2=apply_NUC(images2.copy(),recal_gain_offset[0],recal_gain_offset[1])
# ima1=apply_calib_on_raw(images2.copy(),background,LUT,gain=NUCblock[1][0],offset=NUCblock[1][1])
# ima2=apply_calib_on_raw(images2.copy(),background,LUT,gain=recal_gain_offset[0],offset=recal_gain_offset[1])
#
# plt.figure() # plt.figure()
# plt.imshow(refframe,vmin=np.mean(refframe)-100,vmax=np.mean(refframe)+100) # plt.imshow(ima1[0],vmin=300,vmax=400)
# plt.colorbar() # plt.colorbar()
# plt.title("referenceframe "+str(port)) # plt.title("aleix nuc")
#
port=20
prog="20171108.015"
# status,time,images,valid=get_temp_from_raw_by_program(port,prog,time_s=[0,0.2],emi=0.82,T_version=2,version=0,threads=1,give_ERROR=False,use_firstframe_as_background=True)
bla=get_exposure_by_program(port,prog)
status2,time2,images2=download_raw_images_by_program_via_png(port,prog,time_s=[0,0.2],threads=1)
# plt.figure() # plt.figure()
# plt.imshow(images[0],vmin=300,vmax=400) # plt.imshow(ima2[0],vmin=300,vmax=400)
# plt.colorbar() # plt.colorbar()
# tmax=[] # plt.title("adnan nuc")
# port=20
NUCblock=download_NUC_by_program(port,prog,bla[2][0])
background,LUT,refT,gain,offset,badpixels,t_exp,cfilter,gain_error,offset_error=get_calib_data(port,prog)
refcoldhot=IR_tools.load_ref_images("AEF"+str(port),bla[2][0])
recal_gain_offset=IR_tools.calculate_gain_offset_image_pix(NUCblock[1][2].copy(),None,refcoldhot[0].copy(),refcoldhot[1].copy())
plt.figure()
plt.imshow(NUCblock[1][0]-recal_gain_offset[0])
plt.title("gain")
plt.figure()
plt.imshow(NUCblock[1][1]-recal_gain_offset[1])
plt.title("offset")
# ima1=apply_NUC(images2.copy(),NUCblock[1][0],NUCblock[1][1])
# ima2=apply_NUC(images2.copy(),recal_gain_offset[0],recal_gain_offset[1])
ima1=apply_calib_on_raw(images2.copy(),background,LUT,gain=NUCblock[1][0],offset=NUCblock[1][1])
ima2=apply_calib_on_raw(images2.copy(),background,LUT,gain=recal_gain_offset[0],offset=recal_gain_offset[1])
plt.figure()
plt.imshow(ima1[0],vmin=300,vmax=400)
plt.colorbar()
plt.title("aleix nuc")
plt.figure()
plt.imshow(ima2[0],vmin=300,vmax=400)
plt.colorbar()
plt.title("adnan nuc")
# for i in range(len(images)): # for i in range(len(images)):
# tmax.append(np.max(images[i])) # tmax.append(np.max(images[i]))
# plt.figure() # plt.figure()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment