Commit 08098036 authored by Peter Drewelow's avatar Peter Drewelow
Browse files

clarified error message of program trigger were not found in get_calib_data

parent 782d0a01
...@@ -217,11 +217,11 @@ def correct_images(images,badpixels): ...@@ -217,11 +217,11 @@ 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))
images = list(images) images = list(images)
else: else:
# keep shape # keep shape
images = restore_bad_pixels(images, np.invert(badpixels==1)).astype(np.float32) images = restore_bad_pixels(images, np.invert(badpixels==1))
# for i in range(len(images)): # for i in range(len(images)):
# images[i]=(restore_pixels(images[i],np.invert(badpixels==1))).astype(np.float32) # images[i]=(restore_pixels(images[i],np.invert(badpixels==1))).astype(np.float32)
......
...@@ -1340,137 +1340,140 @@ def get_calib_data(port,program,emissivity=0.8,Temp_V=2,version=0,back_emissivit ...@@ -1340,137 +1340,140 @@ def get_calib_data(port,program,emissivity=0.8,Temp_V=2,version=0,back_emissivit
t0=prog[0]['trigger']['0'][0] t0=prog[0]['trigger']['0'][0]
t1=prog[0]['trigger']['1'][0] t1=prog[0]['trigger']['1'][0]
t6=prog[0]['trigger']['6'][0] t6=prog[0]['trigger']['6'][0]
OP=get_OP_by_program(program) except Exception as E:
Camera=portcamdict[OP]['AEF'+str(port)] print("Warning: Program trigger were not found")
if Camera.split("_")[0]=="Infratec": print(E)
cf=get_INFRATEC_filter_by_program(program,version) return 0,0,0,0,0,0,0,0,0,0
if cf[0]:
cfilter=cf[2] OP=get_OP_by_program(program)
else: Camera=portcamdict[OP]['AEF'+str(port)]
cfilter=-1 if Camera.split("_")[0]=="Infratec":
raise Exception("Filter not found for INFRATEC Camera") cf=get_INFRATEC_filter_by_program(program,version)
if cf[0]:
cfilter=cf[2]
else: else:
cfilter=0 cfilter=-1
expo_DL=get_exposure_by_times(port,t1,t6,version) raise Exception("Filter not found for INFRATEC Camera")
if expo_DL[0]: else:
t_exp=int(expo_DL[2][0]) cfilter=0
del expo_DL expo_DL=get_exposure_by_times(port,t1,t6,version)
time=int(TimeToNs([2017,9,26],[8,0,0,0])) if expo_DL[0]:
LUT_DL=download_LUT(port,time,t_exp,emissivity,cfilter,version, verbose=verbose-1) t_exp=int(expo_DL[2][0])
if LUT_DL[0]: del expo_DL
LUT=LUT_DL[1] time=int(TimeToNs([2017,9,26],[8,0,0,0]))
del LUT_DL LUT_DL=download_LUT(port,time,t_exp,emissivity,cfilter,version, verbose=verbose-1)
back_DL=download_background_by_times(port,t0,t1,t_exp,cfilter,version) if LUT_DL[0]:
if back_DL[0]: LUT=LUT_DL[1]
background=back_DL[2] del LUT_DL
if Temp_V==1: back_DL=download_background_by_times(port,t0,t1,t_exp,cfilter,version)
if verbose>0: if back_DL[0]:
print('use temperature calibration version 1') background=back_DL[2]
backtime=back_DL[1] if Temp_V==1:
backtime=backtime.tolist() if verbose>0:
divertorpart="all" print('use temperature calibration version 1')
TCT_dl=get_average_divertor_TC_for_camtemp(port,int(backtime-2e9),int(backtime+2e9),divertorpart) backtime=back_DL[1]
backtime=backtime.tolist()
divertorpart="all"
TCT_dl=get_average_divertor_TC_for_camtemp(port,int(backtime-2e9),int(backtime+2e9),divertorpart)
if TCT_dl[0]:
refT=np.average(TCT_dl[2])
else:
TCT_dl=get_average_divertor_TC_for_camtemp(port,int(backtime-6e9),int(backtime+6e9),divertorpart)
if TCT_dl[0]: if TCT_dl[0]:
refT=np.average(TCT_dl[2]) refT=np.average(TCT_dl[2])
else: else:
TCT_dl=get_average_divertor_TC_for_camtemp(port,int(backtime-6e9),int(backtime+6e9),divertorpart) raise Exception("Unable to find thermocouple data")
if TCT_dl[0]: elif Temp_V==2:
refT=np.average(TCT_dl[2]) if verbose>0:
else: print('use temperature calibration version 2')
raise Exception("Unable to find thermocouple data") frame=background.copy()
elif Temp_V==2: background=get_average_background_recangle(port,background)
if verbose>0: refT=28.5
print('use temperature calibration version 2') elif Temp_V==3:
frame=background.copy() if verbose>0:
background=get_average_background_recangle(port,background) print('use temperature calibration version 3')
refT=28.5 frame=background.copy()
elif Temp_V==3: background=get_average_background_recangle(port,background)
if verbose>0: refT=28.5
print('use temperature calibration version 3')
frame=background.copy()
background=get_average_background_recangle(port,background)
refT=28.5
# back_off=estimate_offset(port,program) # back_off=estimate_offset(port,program)
# background=(background-back_off)/(back_emissivity)+back_off # background=(background-back_off)/(back_emissivity)+back_off
else: else:
raise Exception("Unknown temperature calibration method") raise Exception("Unknown temperature calibration method")
if cfilter==0 and not Camera.split("_")[0]=="Infratec": if cfilter==0 and not Camera.split("_")[0]=="Infratec":
if (port == 31) or (port == 21 and float(program[4:]) > 1110): if (port == 31) or (port == 21 and float(program[4:]) > 1110):
print("rebuilding coldframe") print("rebuilding coldframe")
#use any way the rebuilt coldframe. #use any way the rebuilt coldframe.
sT = get_sensor_temp_by_program(port, program)[2][0] sT = get_sensor_temp_by_program(port, program)[2][0]
coldref, hotref = IR_tools.load_ref_images('AEF' + str(port), t_exp) coldref, hotref = IR_tools.load_ref_images('AEF' + str(port), t_exp)
filestring = 'AEF' + str(port) + '_et' + str(t_exp) filestring = 'AEF' + str(port) + '_et' + str(t_exp)
amap = np.load(join(IRCamColdframes_fittingpath, filestring + '_a.npy')) amap = np.load(join(IRCamColdframes_fittingpath, filestring + '_a.npy'))
bmap = np.load(join(IRCamColdframes_fittingpath, filestring + '_b.npy')) bmap = np.load(join(IRCamColdframes_fittingpath, filestring + '_b.npy'))
cirebuild = IR_tools.reconstruct_coldframe(t_exp, sT, amap, bmap, coldref) cirebuild = IR_tools.reconstruct_coldframe(t_exp, sT, amap, bmap, coldref)
gain, offset = IR_tools.calculate_gain_offset_image(cirebuild, None, coldref, hotref) gain, offset = IR_tools.calculate_gain_offset_image(cirebuild, None, coldref, hotref)
gain[gain == np.inf] = 0 gain[gain == np.inf] = 1
offset[offset == np.inf] = 0 offset[offset == np.inf] = 0
badpixels=find_badpixels(port,gain,offset,niterations=10,tolerance=10) badpixels=find_badpixels(port,gain,offset,niterations=10,tolerance=10)
gain_error=0 gain_error=0
offset_error=0 offset_error=0
exist,time,frames=download_raw_images_by_times(port,t1,int(t1+0.02*1e9),version) exist,time,frames=download_raw_images_by_times(port,t1,int(t1+0.02*1e9),version)
if exist: if exist:
frames=[im.swapaxes(0,1) for im in frames] frames=[im.swapaxes(0,1) for im in frames]
bim=apply_NUC([frames[0]],gain,offset) bim=apply_NUC([frames[0]],gain,offset)
background=get_average_background_recangle(port,bim[0]) background=get_average_background_recangle(port,bim[0])
else:
raise Exception("cannot find the first frame of the discharge, reconstruction failed")
elif (port == 11) or (port == 21):
coldref, hotref = IR_tools.load_ref_images('AEF' + str(port), t_exp)
NUC_DL=download_NUC_by_times(port,t0,t1,t_exp,version)
if NUC_DL[0]==False:
raise Exception("NUC was not found")
else:
ci = NUC_DL[1][2]
gain, offset = IR_tools.calculate_gain_offset_image(ci, None, coldref, hotref)
gain[gain == np.inf] = 0
offset[offset == np.inf] = 0
badpixels=find_badpixels(port,gain,offset,niterations=10,tolerance=10)
gain_error=0
offset_error=0
exist,time,frames=download_raw_images_by_times(port,t1,int(t1+0.02*1e9),version)
if exist:
frames=[im.swapaxes(0,1) for im in frames]
bim=apply_NUC([frames[0]],gain,offset)
background=get_average_background_recangle(port,bim[0])
else:
raise Exception("background wrong due to wrong NUC, firstframe not found, reconstruction failed")
else: else:
NUC_DL=download_NUC_by_times(port,t0,t1,t_exp,version) raise Exception("cannot find the first frame of the discharge, reconstruction failed")
if NUC_DL[0]==False: elif (port == 11) or (port == 21):
raise Exception("NUC was not found") coldref, hotref = IR_tools.load_ref_images('AEF' + str(port), t_exp)
else: NUC_DL=download_NUC_by_times(port,t0,t1,t_exp,version)
gain=np.array(NUC_DL[1][0]) if NUC_DL[0]==False:
offset=np.array(NUC_DL[1][1]) raise Exception("NUC was not found")
offset[offset<-1e300]=0 else:
gain_error=np.array(NUC_DL[1][4]) ci = NUC_DL[1][2]
offset_error=np.array(NUC_DL[1][5]) gain, offset = IR_tools.calculate_gain_offset_image(ci, None, coldref, hotref)
badpixels=np.array(NUC_DL[1][3],dtype=np.ubyte) gain[gain == np.inf] = 1
if np.max(badpixels)==0: offset[offset == np.inf] = 0
if verbose>0: badpixels=find_badpixels(port,gain,offset,niterations=10,tolerance=10)
print(datetime.datetime.now(),"Scanning for bad pixel")
# initial list from config files
init_bp_list = IR_tools.read_bad_pixels_from_file(port, program=program)
# find more bad pixel
badpixels = find_badpixels(port, gain, offset, init_bp_list=init_bp_list, niterations=10, tolerance=10, verbose=verbose-1)
else:
gain=0
offset=0
badpixels=find_badpixels(port,frame-background,offset,niterations=10,tolerance=10,plot_it=False)#find_badpixels(port,gain,offset)
gain_error=0 gain_error=0
offset_error=0 offset_error=0
exist,time,frames=download_raw_images_by_times(port,t1,int(t1+0.02*1e9),version)
if exist:
frames=[im.swapaxes(0,1) for im in frames]
bim=apply_NUC([frames[0]],gain,offset)
background=get_average_background_recangle(port,bim[0])
else:
raise Exception("background wrong due to wrong NUC, firstframe not found, reconstruction failed")
else:
NUC_DL=download_NUC_by_times(port,t0,t1,t_exp,version)
if NUC_DL[0]==False:
raise Exception("NUC was not found")
else:
gain=np.array(NUC_DL[1][0])
offset=np.array(NUC_DL[1][1])
offset[offset<-1e300]=0
gain_error=np.array(NUC_DL[1][4])
offset_error=np.array(NUC_DL[1][5])
badpixels=np.array(NUC_DL[1][3],dtype=np.ubyte)
if np.max(badpixels)==0:
if verbose>0:
print(datetime.datetime.now(),"Scanning for bad pixel")
# initial list from config files
init_bp_list = IR_tools.read_bad_pixels_from_file(port, program=program)
# find more bad pixel
badpixels = find_badpixels(port, gain, offset, init_bp_list=init_bp_list, niterations=10, tolerance=10, verbose=verbose-1)
else: else:
raise Exception("no background image found") gain=0
offset=0
badpixels=find_badpixels(port,frame-background,offset,niterations=10,tolerance=10,plot_it=False)#find_badpixels(port,gain,offset)
gain_error=0
offset_error=0
else: else:
raise Exception("no LUT found") raise Exception("no background image found")
else: else:
raise Exception("no exposure time found") raise Exception("no LUT found")
return background,LUT,refT,gain,offset,badpixels,t_exp,cfilter,gain_error,offset_error else:
except: raise Exception("no exposure time found")
print("Warning: Program was not found") return background,LUT,refT,gain,offset,badpixels,t_exp,cfilter,gain_error,offset_error
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):
......
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