From eb8f2e0f8e97b3c2b74c0e522552f9588708dc65 Mon Sep 17 00:00:00 2001
From: Holger Niemann <holger.niemann@ipp.mpg.de>
Date: Wed, 1 Aug 2018 11:37:23 +0200
Subject: [PATCH] fixes of runtime and futurewarining (3.5, errors in 3.6) in
 the download code

---
 IR_image_tools.py        | 12 ++++++++----
 downloadversionIRdata.py |  2 +-
 plot_IR_data.py          |  4 ++--
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/IR_image_tools.py b/IR_image_tools.py
index 0ced53c..b40f67b 100644
--- a/IR_image_tools.py
+++ b/IR_image_tools.py
@@ -413,13 +413,13 @@ def restore_bad_pixels(frames, bad_pixel, by_list=True, check_neighbours=True, p
 
 
 def generate_new_hot_image(cold,reference_cold,reference_hot):
-    if cold==None or reference_cold==None or reference_hot==None:
+    if cold is None or reference_cold is None or reference_hot is None:
         raise Exception("Cannot Calculate new Hot image, if images are missing!")
     else:
         return reference_hot+(cold-reference_cold)
     
 def calculate_gain_offset_image_pix(cold_image,hot_image=None,reference_cold=None,reference_hot=None,bose=1):    
-    if hot_image==None:
+    if hot_image is None:
         hot_image=generate_new_hot_image(cold_image,reference_cold,reference_hot)
     if bose>0:
         print("calculate gain and offset")        
@@ -432,7 +432,7 @@ def calculate_gain_offset_image_pix(cold_image,hot_image=None,reference_cold=Non
     return Gain_rel,Offset_rel
 
 def calculate_gain_offset_image(cold_image,hot_image=None,reference_cold=None,reference_hot=None,bose=1):    
-    if hot_image==None:
+    if hot_image is None:
         hot_image=generate_new_hot_image(cold_image,reference_cold,reference_hot)
     if bose>0:
         print("calculate gain and offset")  
@@ -443,7 +443,11 @@ def calculate_gain_offset_image(cold_image,hot_image=None,reference_cold=None,re
 #    print(cold_image[( np.int( np.shape(hot_image)[0]/2) )-2: (np.int( np.shape(hot_image)[0]/2))+3,np.int((np.shape(hot_image)[1]/2))-2:np.int((np.shape(hot_image)[1]/2))+3 ])
     Sh_ref =  np.mean( hot_image[( np.int( np.shape(hot_image)[0]/2) )-2: (np.int( np.shape(hot_image)[0]/2))+3,np.int((np.shape(hot_image)[1]/2))-2:np.int((np.shape(hot_image)[1]/2))+3 ])    
     Sc_ref =  np.mean(cold_image[( np.int( np.shape(cold_image)[0]/2) )-2: (np.int( np.shape(cold_image)[0]/2))+3,np.int((np.shape(cold_image)[1]/2))-2:np.int((np.shape(cold_image)[1]/2))+3 ])    
-    Gain_rel =  ( Sh_ref  - Sc_ref ) / ( hot_image  - cold_image)    
+    difference_image=hot_image  - cold_image
+    indexlist=np.where(difference_image==0)
+    difference_image[indexlist]=0.001
+    Gain_rel =  ( Sh_ref  - Sc_ref ) / ( difference_image)    
+    Gain_rel[indexlist]=0
     Off_h_rel = Sh_ref -   hot_image*Gain_rel
     Off_c_rel = Sc_ref -   cold_image*Gain_rel    
     Offset_rel  = ( Off_h_rel + Off_c_rel ) /2
diff --git a/downloadversionIRdata.py b/downloadversionIRdata.py
index 098d00a..339bc80 100644
--- a/downloadversionIRdata.py
+++ b/downloadversionIRdata.py
@@ -504,7 +504,7 @@ def download_background_by_times(port,starttime,stoptime,exposure,camera_filter=
     else:
         return False,0,0
 
-def get_NUCed_background_by_times(port,t0,t1,t_exp,cfilter,gain,offset,version=0,plot_it=True):
+def get_NUCed_background_by_times(port,t0,t1,t_exp,cfilter,gain,offset,version=0,plot_it=False):
     "OP1.2b function"
     exist,btime,backgroundframes=download_calibration_raw_files_by_time(port,t_exp,t0,t1,frametype=1,version=version)
     camera=portcamdict["OP1.2b"]["AEF"+str(port)]    
diff --git a/plot_IR_data.py b/plot_IR_data.py
index 097703b..6547ffe 100644
--- a/plot_IR_data.py
+++ b/plot_IR_data.py
@@ -15,7 +15,7 @@ if __name__=='__main__':
     
     #%% loading data
     
-    status,time,images,valid=downIR.get_temp_from_raw_by_program(20,"20171207.006",time_s=3.5,emi=0.8,T_version=2,version=1,threads=8,give_ERROR=False)
+    status,time,images,valid=downIR.get_temp_from_raw_by_program(20,"20180726.015",time_s=2.5,emi=0.8,T_version=2,version=1,threads=4,give_ERROR=False)
     print('fertig')
     
     #%% plotting data
@@ -33,5 +33,5 @@ if __name__=='__main__':
                     labelbottom='off') # labels along the bottom edge are off
     c_ax = plt.colorbar()
     c_ax.set_label('T [K]')
-    plt.savefig('20171207.006 - 2.2s - AEF20IR - in K.png', dpi=300, bbox_inches='tight')
+    plt.savefig('20180726.015 - 2.2s - AEF20IR - in K.png', dpi=300, bbox_inches='tight')
     plt.show()
-- 
GitLab