Commit 92f134ab authored by Holger Niemann's avatar Holger Niemann
Browse files

Merge branch 'master' into 'Holgers'

# Conflicts:
#   downloadversionIRdata.py
parents 86645bad a47486aa
...@@ -68,7 +68,7 @@ def bestimmtheitsmass_general(data,fit): ...@@ -68,7 +68,7 @@ def bestimmtheitsmass_general(data,fit):
qam=quad_abweich_mittel(fit,mittel) qam=quad_abweich_mittel(fit,mittel)
R=qam/(qam+quad_abweich(data,fit)) R=qam/(qam+quad_abweich(data,fit))
else: else:
print("Arrays must have same dimensions") print("bestimmtheitsmass_general: Arrays must have same dimensions")
return R return R
def quad_abweich_mittel(data,mittel): def quad_abweich_mittel(data,mittel):
...@@ -83,7 +83,7 @@ def quad_abweich(data,fit): ...@@ -83,7 +83,7 @@ def quad_abweich(data,fit):
for i in range(len(data)): for i in range(len(data)):
R=R+(data[i]-fit[i])**2 R=R+(data[i]-fit[i])**2
else: else:
print("Arrays must have same dimensions") print("quad_abweich: Arrays must have same dimensions")
return R return R
def find_nearest(array,value): def find_nearest(array,value):
...@@ -131,6 +131,8 @@ def check_coldframe(coldframe,references=None,threshold=0.5,plot_it=False): ...@@ -131,6 +131,8 @@ def check_coldframe(coldframe,references=None,threshold=0.5,plot_it=False):
return False,bestimmtheit return False,bestimmtheit
def check_coldframe_by_refframe(coldframe,reference_frame,threshold=0.8,plot_it=False): def check_coldframe_by_refframe(coldframe,reference_frame,threshold=0.8,plot_it=False):
'''
'''
references=[] references=[]
shapi=np.shape(reference_frame) shapi=np.shape(reference_frame)
for i in [int(shapi[1]//5),int(shapi[1]//2),int(shapi[1]//4*3)]: for i in [int(shapi[1]//5),int(shapi[1]//2),int(shapi[1]//4*3)]:
...@@ -185,8 +187,10 @@ def read_bad_pixels_from_file(port, shot_no=None, program=None,time_ns=None): ...@@ -185,8 +187,10 @@ def read_bad_pixels_from_file(port, shot_no=None, program=None,time_ns=None):
def find_outlier_pixels(frame,tolerance=3,worry_about_edges=True,plot_it=False): def find_outlier_pixels(frame,tolerance=3,worry_about_edges=True,plot_it=False):
# This function finds the bad pixels in a 2D dataset. '''
# Tolerance is the number of standard deviations used for cutoff. This function finds the bad pixels in a 2D dataset.
Tolerance is the number of standard deviations used for cutoff.
'''
frame = np.array(frame)#, dtype=int) frame = np.array(frame)#, dtype=int)
from scipy.ndimage import median_filter from scipy.ndimage import median_filter
blurred = median_filter(frame, size=9) blurred = median_filter(frame, size=9)
...@@ -222,26 +226,26 @@ def find_outlier_pixels(frame,tolerance=3,worry_about_edges=True,plot_it=False): ...@@ -222,26 +226,26 @@ def find_outlier_pixels(frame,tolerance=3,worry_about_edges=True,plot_it=False):
return bad_pixels return bad_pixels
def correct_images(images,badpixels): def correct_images(images,badpixels,verbose=0):
print('correct_images: New routine restore_bad_pixels() is used and can be called directly. Check out "help(restore_bad_pixels)"') '''
'''
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 = list(images)
for i in range(len(images)): for i in range(len(images)):
images[i]=restore_bad_pixels(images[i], np.invert(badpixels==1)) images[i]=restore_bad_pixels(images[i], np.invert(badpixels==1), verbose=verbose-1)
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), verbose=verbose-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)
print("done") if verbose>0:
print("correct_images: done")
return images return images
def restore_bad_pixels(frames, bad_pixel, by_list=True, check_neighbours=True, plot_it=False, verbose=0): def restore_bad_pixels(frames, bad_pixel, by_list=True, check_neighbours=True, plot_it=False,verbose=0):
"""Restore bad pixel by interpolation of adjacent pixels. Optionally make """Restore bad pixel by interpolation of adjacent pixels. Optionally make
sure that adjacent pixels are not bad (time consuming). Default is to use sure that adjacent pixels are not bad (time consuming). Default is to use
a list of bad pixels and a for loop. For many bad pixels consider using a list of bad pixels and a for loop. For many bad pixels consider using
...@@ -412,16 +416,20 @@ def restore_bad_pixels(frames, bad_pixel, by_list=True, check_neighbours=True, p ...@@ -412,16 +416,20 @@ def restore_bad_pixels(frames, bad_pixel, by_list=True, check_neighbours=True, p
def generate_new_hot_image(cold,reference_cold,reference_hot): def generate_new_hot_image(cold,reference_cold,reference_hot):
'''
'''
if cold is None or reference_cold is None or reference_hot is 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!") raise Exception("generate_new_hot_image: Cannot Calculate new Hot image, if images are missing!")
else: else:
return reference_hot+(cold-reference_cold) 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): def calculate_gain_offset_image_pix(cold_image,hot_image=None,reference_cold=None,reference_hot=None,verbose=0):
'''
'''
if hot_image is None: if hot_image is None:
hot_image=generate_new_hot_image(cold_image,reference_cold,reference_hot) hot_image=generate_new_hot_image(cold_image,reference_cold,reference_hot)
if bose>0: if verbose>0:
print("calculate gain and offset") print("calculate_gain_offset_image_pix: calculate gain and offset")
Sh_ref = hot_image[ ( np.int( np.shape(hot_image)[0] /2 ) ) ][np.int( (np.shape(hot_image)[1] /2 ) ) ] Sh_ref = hot_image[ ( np.int( np.shape(hot_image)[0] /2 ) ) ][np.int( (np.shape(hot_image)[1] /2 ) ) ]
Sc_ref = cold_image[ ( np.int( (np.shape(cold_image)[0]) /2 ) ) ][( np.int( (np.shape(cold_image)[1]) /2 ) ) ] Sc_ref = cold_image[ ( np.int( (np.shape(cold_image)[0]) /2 ) ) ][( np.int( (np.shape(cold_image)[1]) /2 ) ) ]
Gain_rel = ( Sh_ref - Sc_ref ) / ( hot_image - cold_image) Gain_rel = ( Sh_ref - Sc_ref ) / ( hot_image - cold_image)
...@@ -434,7 +442,7 @@ def calculate_gain_offset_image(cold_image,hot_image=None,reference_cold=None,re ...@@ -434,7 +442,7 @@ def calculate_gain_offset_image(cold_image,hot_image=None,reference_cold=None,re
if hot_image is None: if hot_image is None:
hot_image=generate_new_hot_image(cold_image,reference_cold,reference_hot) hot_image=generate_new_hot_image(cold_image,reference_cold,reference_hot)
if verbose>0: if verbose>0:
print("calculate gain and offset") print("calculate_gain_offset_image: calculate gain and offset")
# Sh_ref = hot_image[ ( np.int( np.shape(hot_image)[0] /2 ) ) ][np.int( (np.shape(hot_image)[1] /2 ) ) ] # Sh_ref = hot_image[ ( np.int( np.shape(hot_image)[0] /2 ) ) ][np.int( (np.shape(hot_image)[1] /2 ) ) ]
# Sc_ref = cold_image[ ( np.int( (np.shape(cold_image)[0]) /2 ) ) ][( np.int( (np.shape(cold_image)[1]) /2 ) ) ] # Sc_ref = cold_image[ ( np.int( (np.shape(cold_image)[0]) /2 ) ) ][( np.int( (np.shape(cold_image)[1]) /2 ) ) ]
...@@ -455,30 +463,32 @@ def calculate_gain_offset_image(cold_image,hot_image=None,reference_cold=None,re ...@@ -455,30 +463,32 @@ def calculate_gain_offset_image(cold_image,hot_image=None,reference_cold=None,re
#%% functions from Yu Gao #%% functions from Yu Gao
""" functions by Yu Gao""" """ functions by Yu Gao"""
def load_ref_images(port, exposuretime): def load_ref_images(port, exposuretime, verbose=0):
''' '''
load the reference cold and hot frame during calibration from local files. load the reference cold and hot frame during calibration from local files.
@port: e.g. 'AEF10' @port: e.g. 'AEF10'
@exposuretime: int number. @exposuretime: int number.
''' '''
cameraname = portcamdict['OP1.2a'][port] cameraname = portcamdict['OP1.2a'][port]
foldername = cameraname.split('_')[0] + '_' + cameraname.split('_')[2] foldername = cameraname.split('_')[0] + '_' + cameraname.split('_')[2]
scanpath = join(IRCamRefImagespath, foldername) scanpath = join(IRCamRefImagespath, foldername)
coldref, hotref = [], [] coldref, hotref = [], []
for filename in glob.iglob(scanpath + '\*' + str(int(exposuretime)) + 'us.h5', recursive=True): for filename in glob.iglob(scanpath + '\*' + str(int(exposuretime)) + 'us.h5', recursive=True):
if 'hot' in filename: if 'hot' in filename:
print (filename) if verbose>0:
with h5py.File(filename, 'r') as h5in: print('load_ref_images: read from ',filename)
hotref = h5in[basename(filename)].value with h5py.File(filename, 'r') as h5in:
elif 'cold' in filename: hotref = h5in[basename(filename)].value
print (filename) elif 'cold' in filename:
with h5py.File(filename, 'r') as h5in: if verbose>0:
coldref = h5in[basename(filename)].value print('load_ref_images: read from ',filename)
return coldref, hotref with h5py.File(filename, 'r') as h5in:
coldref = h5in[basename(filename)].value
return coldref, hotref
def reconstruct_coldframe (exposuretime, sT, a, bnew, coldref): def reconstruct_coldframe (exposuretime, sT, a, bnew, coldref):
cirebuild = a * sT + bnew * exposuretime + coldref cirebuild = a * sT + bnew * exposuretime + coldref
return cirebuild return cirebuild
#%% other functions #%% other functions
......
This diff is collapsed.
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