Commit 1e537d25 authored by Holger Niemann's avatar Holger Niemann
Browse files

change to reconstruct cold frames and swapped cameras corrections

parent 776243d2
This diff is collapsed.
......@@ -2,7 +2,7 @@
"""
Created on Wed May 9 14:56:32 2018
@author: holn
@author: Holger Niemann, Peter Drewelow, Yu Gao
mainly to clean up the downloadversionIRdata code
Tools for:
......@@ -14,6 +14,12 @@ Tools for:
"""
import numpy as np
import matplotlib.pyplot as plt
from IR_config_constants import portcamdict,IRCamRefImagespath
import h5py
from os.path import join, basename
import glob
def bestimmtheitsmaß_general(data,fit):
R=0
......@@ -79,7 +85,7 @@ def check_coldframe(coldframe,references=None,threshold=0.5,plot_it=False):
def check_coldframe_by_refframe(coldframe,reference_frame,threshold=0.8,plot_it=False):
references=[]
shapi=np.shape(reference_frame)
for i in [int(shapi[1]//4),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)]:
dataline=reference_frame[0:shapi[0],i]
references.append(dataline-np.mean(dataline))
return check_coldframe(coldframe,references,threshold,plot_it)
......@@ -145,7 +151,7 @@ def correct_images(images,badpixels):
print("done")
return images
def restore_pixels(frame, bad_pixel):
def restore_pixels(frame, bad_pixel):# code from Peter from JET
# make sure bad pixel are provided as mask and list
if type(bad_pixel) is list:
blist = bad_pixel
......@@ -247,9 +253,11 @@ def generate_new_hot_image(cold,reference_cold,reference_hot):
else:
return reference_hot+(cold-reference_cold)
def calculate_gain_offset_image(cold_image,hot_image=None,reference_cold=None,reference_hot=None):
def calculate_gain_offset_image_pix(cold_image,hot_image=None,reference_cold=None,reference_hot=None,bose=1):
if hot_image==None:
hot_image=generate_new_hot_image(cold_image,reference_cold,reference_hot)
if bose>0:
print("calculate gain and offset")
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 ) ) ]
Gain_rel = ( Sh_ref - Sc_ref ) / ( hot_image - cold_image)
......@@ -257,3 +265,50 @@ def calculate_gain_offset_image(cold_image,hot_image=None,reference_cold=None,re
Off_c_rel = Sc_ref - cold_image*Gain_rel
Offset_rel = ( Off_h_rel + Off_c_rel ) /2
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:
hot_image=generate_new_hot_image(cold_image,reference_cold,reference_hot)
if bose>0:
print("calculate gain and offset")
# 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 ) ) ]
print(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 ])
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)
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
return Gain_rel,Offset_rel
#%% functions from Yu Gao
""" functions by Yu Gao"""
def load_ref_images(port, exposuretime):
'''
load the reference cold and hot frame during calibration from local files.
@port: e.g. 'AEF10'
@exposuretime: int number.
'''
cameraname = portcamdict['OP1.2a'][port]
foldername = cameraname.split('_')[0] + '_' + cameraname.split('_')[2]
scanpath = join(IRCamRefImagespath, foldername)
coldref, hotref = [], []
for filename in glob.iglob(scanpath + '\*' + str(int(exposuretime)) + 'us.h5', recursive=True):
if 'hot' in filename:
print (filename)
with h5py.File(filename, 'r') as h5in:
hotref = h5in[basename(filename)].value
elif 'cold' in filename:
print (filename)
with h5py.File(filename, 'r') as h5in:
coldref = h5in[basename(filename)].value
return coldref, hotref
def reconstruct_coldframe (exposuretime, sT, a, bnew, coldref):
cirebuild = a * sT + bnew * exposuretime + coldref
return cirebuild
\ No newline at end of file
from . import IR_image_tools
from . import downloadversionIRdata
from . import IR_config_constants
\ No newline at end of file
This diff is collapsed.
Markdown is supported
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