diff --git a/IR_image_tools.py b/IR_image_tools.py
index 736b6171d5f78ea8e11d64a49bc1d7f8dabc96de..5456e1de3a05f235d1f247b87d98d765b136ad50 100644
--- a/IR_image_tools.py
+++ b/IR_image_tools.py
@@ -217,11 +217,11 @@ def correct_images(images,badpixels):
     if type(badpixels)!=int:
         if type(images) == list:
             # 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)
         else:
             # 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)):
 #            images[i]=(restore_pixels(images[i],np.invert(badpixels==1))).astype(np.float32)
diff --git a/downloadversionIRdata.py b/downloadversionIRdata.py
index d35834fa126998757dd7f0cd64f598737e893504..4a46e5002a15280796a2e1b03ae44c8f782429f6 100644
--- a/downloadversionIRdata.py
+++ b/downloadversionIRdata.py
@@ -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]
         t1=prog[0]['trigger']['1'][0]
         t6=prog[0]['trigger']['6'][0]
-        OP=get_OP_by_program(program)
-        Camera=portcamdict[OP]['AEF'+str(port)]
-        if Camera.split("_")[0]=="Infratec":
-            cf=get_INFRATEC_filter_by_program(program,version)
-            if cf[0]:
-                cfilter=cf[2]
-            else:
-                cfilter=-1                
-                raise Exception("Filter not found for INFRATEC Camera")
+    except Exception as E:
+        print("Warning: Program trigger were not found")
+        print(E)
+        return 0,0,0,0,0,0,0,0,0,0
+    
+    OP=get_OP_by_program(program)
+    Camera=portcamdict[OP]['AEF'+str(port)]
+    if Camera.split("_")[0]=="Infratec":
+        cf=get_INFRATEC_filter_by_program(program,version)
+        if cf[0]:
+            cfilter=cf[2]
         else:
-            cfilter=0
-        expo_DL=get_exposure_by_times(port,t1,t6,version)
-        if expo_DL[0]:
-            t_exp=int(expo_DL[2][0])
-            del expo_DL
-            time=int(TimeToNs([2017,9,26],[8,0,0,0]))   
-            LUT_DL=download_LUT(port,time,t_exp,emissivity,cfilter,version, verbose=verbose-1)
-            if LUT_DL[0]:
-                LUT=LUT_DL[1]
-                del LUT_DL
-                back_DL=download_background_by_times(port,t0,t1,t_exp,cfilter,version)
-                if back_DL[0]:
-                    background=back_DL[2]
-                    if Temp_V==1:
-                        if verbose>0:
-                            print('use temperature calibration version 1')
-                        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)
+            cfilter=-1                
+            raise Exception("Filter not found for INFRATEC Camera")
+    else:
+        cfilter=0
+    expo_DL=get_exposure_by_times(port,t1,t6,version)
+    if expo_DL[0]:
+        t_exp=int(expo_DL[2][0])
+        del expo_DL
+        time=int(TimeToNs([2017,9,26],[8,0,0,0]))   
+        LUT_DL=download_LUT(port,time,t_exp,emissivity,cfilter,version, verbose=verbose-1)
+        if LUT_DL[0]:
+            LUT=LUT_DL[1]
+            del LUT_DL
+            back_DL=download_background_by_times(port,t0,t1,t_exp,cfilter,version)
+            if back_DL[0]:
+                background=back_DL[2]
+                if Temp_V==1:
+                    if verbose>0:
+                        print('use temperature calibration version 1')
+                    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]:
                             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]:
-                                refT=np.average(TCT_dl[2])
-                            else:
-                                raise Exception("Unable to find thermocouple data")
-                    elif Temp_V==2:
-                        if verbose>0:
-                            print('use temperature calibration version 2')
-                        frame=background.copy()
-                        background=get_average_background_recangle(port,background)
-                        refT=28.5
-                    elif Temp_V==3:
-                        if verbose>0:
-                            print('use temperature calibration version 3')
-                        frame=background.copy()
-                        background=get_average_background_recangle(port,background)
-                        refT=28.5
+                            raise Exception("Unable to find thermocouple data")
+                elif Temp_V==2:
+                    if verbose>0:
+                        print('use temperature calibration version 2')
+                    frame=background.copy()
+                    background=get_average_background_recangle(port,background)
+                    refT=28.5
+                elif Temp_V==3:
+                    if verbose>0:
+                        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)                      
 #                        background=(background-back_off)/(back_emissivity)+back_off
-                    else:
-                        raise Exception("Unknown temperature calibration method")
-                    if cfilter==0 and not Camera.split("_")[0]=="Infratec":
-                        if (port == 31) or (port == 21 and float(program[4:]) > 1110):
-                            print("rebuilding coldframe")
-                            #use any way the rebuilt coldframe.
-                            sT = get_sensor_temp_by_program(port, program)[2][0]
-                            coldref, hotref = IR_tools.load_ref_images('AEF' + str(port), t_exp)
-                            filestring = 'AEF' + str(port) + '_et' + str(t_exp)
-                            amap = np.load(join(IRCamColdframes_fittingpath, filestring + '_a.npy'))
-                            bmap = np.load(join(IRCamColdframes_fittingpath, filestring + '_b.npy'))
-                            cirebuild = IR_tools.reconstruct_coldframe(t_exp, sT, amap, bmap, coldref)
-                            gain, offset = IR_tools.calculate_gain_offset_image(cirebuild, 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("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:
+                    raise Exception("Unknown temperature calibration method")
+                if cfilter==0 and not Camera.split("_")[0]=="Infratec":
+                    if (port == 31) or (port == 21 and float(program[4:]) > 1110):
+                        print("rebuilding coldframe")
+                        #use any way the rebuilt coldframe.
+                        sT = get_sensor_temp_by_program(port, program)[2][0]
+                        coldref, hotref = IR_tools.load_ref_images('AEF' + str(port), t_exp)
+                        filestring = 'AEF' + str(port) + '_et' + str(t_exp)
+                        amap = np.load(join(IRCamColdframes_fittingpath, filestring + '_a.npy'))
+                        bmap = np.load(join(IRCamColdframes_fittingpath, filestring + '_b.npy'))
+                        cirebuild = IR_tools.reconstruct_coldframe(t_exp, sT, amap, bmap, coldref)
+                        gain, offset = IR_tools.calculate_gain_offset_image(cirebuild, None, coldref, hotref)
+                        gain[gain == np.inf] = 1
+                        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:
-                            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:
-                        gain=0
-                        offset=0
-                        badpixels=find_badpixels(port,frame-background,offset,niterations=10,tolerance=10,plot_it=False)#find_badpixels(port,gain,offset)
+                            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] = 1
+                        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:
+                        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:
-                    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:
-                raise Exception("no LUT found")
+                raise Exception("no background image found")
         else:
-            raise Exception("no exposure time found")
-        return background,LUT,refT,gain,offset,badpixels,t_exp,cfilter,gain_error,offset_error
-    except:
-        print("Warning: Program was not found")
-        return 0,0,0,0,0,0,0,0,0,0
+            raise Exception("no LUT found")
+    else:
+        raise Exception("no exposure time found")
+    return background,LUT,refT,gain,offset,badpixels,t_exp,cfilter,gain_error,offset_error
+   
 
 def find_badpixels(port, gain, offset, init_bp_list=None, niterations=3,
                    tolerance=10, plot_it=False, verbose=0):