Commit 79b9fe3d authored by Holger Niemann's avatar Holger Niemann
Browse files

Add a function for the bad pixel correction and convertion to heatflux and...

Add a function for the bad pixel correction and convertion to heatflux and bugfix for the bad pixel correction
parent de606bea
# -*- coding: utf-8 -*-
"""
Created on Wed May 9 14:56:32 2018
Version: 3.3.3
Version: 3.4.0
@author: Holger Niemann, Peter Drewelow, Yu Gao
mainly to clean up the downloadversionIRdata code
......@@ -24,6 +24,7 @@ import datetime
def get_OP_by_time(time_ns=None, shot_no=None, program_str=None):
'''Derives operation phase (OP) of W7-X based on either:
a nanosacond time stamp, a MDSplus style shot no. or a program ID.
IN:
time_ns - integer of nanosecond time stamp,
e.g. 1511972727249834301 (OPTIONAL)
......@@ -64,6 +65,16 @@ def get_OP_by_time(time_ns=None, shot_no=None, program_str=None):
return OP
def bestimmtheitsmass_general(data, fit):
"""
INPUT
------
RESULT
------
NOTE
------
"""
R = 0
if len(fit) == len(data):
mittel = np.sum(data)/len(data)
......@@ -74,6 +85,16 @@ def bestimmtheitsmass_general(data, fit):
return R
def bestimmheitsmass_linear(data, fit, debugmode=False):
"""
INPUT
------
RESULT
------
NOTE
------
"""
R2 = 0
if len(fit) == len(data):
mittel_D = np.mean(data)#np.sum(data)/len(data)
......@@ -87,12 +108,32 @@ def bestimmheitsmass_linear(data, fit, debugmode=False):
return R2
def quad_abweich_mittel(data, mittel):
"""
INPUT
------
RESULT
------
NOTE
------
"""
R = 0
for i in data:
R = R+(i-mittel)**2
return R
def quad_abweich(data, fit):
"""
INPUT
------
RESULT
------
NOTE
------
"""
R = 0
if len(fit) == len(data):
for i in range(len(data)):
......@@ -102,6 +143,16 @@ def quad_abweich(data, fit):
return R
def find_nearest(array, value):
"""
INPUT
------
RESULT
------
NOTE
------
"""
#a=array
a = [x - value for x in array]
mini = np.min(np.abs(a))
......@@ -112,6 +163,15 @@ def find_nearest(array, value):
def check_coldframe(coldframe, references=None, threshold=0.5, plot_it=False):
'''
return true/false and the quality factor
INPUT
------
RESULT
------
NOTE
------
'''
shapi = np.shape(coldframe)
##function (np.arange(0,768)-384)**(2)/900-50
......@@ -147,6 +207,14 @@ 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):
'''
INPUT
------
RESULT
------
NOTE
------
'''
references = []
shapi = np.shape(reference_frame)
......@@ -158,6 +226,15 @@ def check_coldframe_by_refframe(coldframe, reference_frame, threshold=0.8, plot_
def check_backgroundframe(backgroundframe, threshold=50):
'''
return true or false
INPUT
------
RESULT
------
NOTE
------
'''
shapi = np.shape(backgroundframe)
valid = True
......@@ -181,6 +258,15 @@ def read_bad_pixels_from_file(port, shot_no=None, program=None, time_ns=None):
OUT
bad_pixle_list - list of tuples (row,column) of pixel coordinates
as integer
INPUT
------
RESULT
------
NOTE
------
'''
if shot_no is not None:
OP = get_OP_by_time(shot_no=shot_no)
......@@ -204,6 +290,15 @@ def find_outlier_pixels(frame, tolerance=3, plot_it=False):#worry_about_edges=Tr
'''
This function finds the bad pixels in a 2D dataset.
Tolerance is the number of standard deviations used for cutoff.
INPUT
------
RESULT
------
NOTE
------
'''
frame = np.array(frame)#, dtype=int)
from scipy.ndimage import median_filter
......@@ -242,6 +337,14 @@ def find_outlier_pixels(frame, tolerance=3, plot_it=False):#worry_about_edges=Tr
def correct_images(images, badpixels, verbose=0):
'''
INPUT
------
RESULT
------
NOTE
------
'''
if type(badpixels) != int:
if type(images) == list:
......@@ -263,8 +366,10 @@ def restore_bad_pixels(frames, bad_pixel, by_list=True, check_neighbours=True, p
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
the optinal alternative using a bad pixel mask.
IN:
frames - either list of frames as 2D numpy array,
INPUT
------
frames - either list of frames as 2D numpy array,
or 3D numpy array (frame number, n_rows, n_cols),
or 2D numpy array (n_rows, n_cols)
bad_pixel - either list of tuples of bad pixel coordinates,
......@@ -280,10 +385,13 @@ def restore_bad_pixels(frames, bad_pixel, by_list=True, check_neighbours=True, p
results or not
(OPTIONAL: if not provided, switched off)
verbose - integer of feedback level (amount of prints)
(OPTIONAL: if not provided, only ERROR output)
RETURN:
(OPTIONAL: if not provided, only ERROR output)
RESULT
------
frames - 3D numpy array (frame number, n_rows, n_cols) of
corrected frames
NOTE
------
"""
# make sure frames is correctly shaped
......@@ -430,6 +538,14 @@ def restore_bad_pixels(frames, bad_pixel, by_list=True, check_neighbours=True, p
def generate_new_hot_image(cold,reference_cold,reference_hot):
'''
INPUT
------
RESULT
------
NOTE
------
'''
if cold is None or reference_cold is None or reference_hot is None:
raise Exception("generate_new_hot_image: Cannot Calculate new Hot image, if images are missing!")
......@@ -438,6 +554,14 @@ def generate_new_hot_image(cold,reference_cold,reference_hot):
def calculate_gain_offset_image_pix(cold_image,hot_image=None,reference_cold=None,reference_hot=None,verbose=0):
'''
INPUT
------
RESULT
------
NOTE
------
'''
if hot_image is None:
hot_image=generate_new_hot_image(cold_image,reference_cold,reference_hot)
......@@ -452,6 +576,16 @@ 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,verbose=0):
"""
INPUT
------
RESULT
------
NOTE
------
"""
if hot_image is None:
hot_image=generate_new_hot_image(cold_image,reference_cold,reference_hot)
if verbose>0:
......@@ -502,17 +636,47 @@ def calculate_gain_offset_image(cold_image,hot_image=None,reference_cold=None,re
#==============================================================================
def reconstruct_coldframe (exposuretime, sT, a, bnew, coldref):
"""
INPUT
------
RESULT
------
NOTE
------
"""
cirebuild = a * sT + bnew * exposuretime + coldref
return cirebuild
#%% other functions
def check_dublicates(array):
"""
INPUT
------
RESULT
------
NOTE
------
"""
a = array
import collections
return [item for item, count in collections.Counter(a).items() if count > 1]
def check_dublicates_2(array):
"""
INPUT
------
RESULT
------
NOTE
------
"""
seen = set()
uniq = []
for x in array:
......@@ -523,6 +687,14 @@ def check_dublicates_2(array):
def get_work_list(pipepath,typ="q"):
"""
INPUT
------
RESULT
------
NOTE
------
"""
today=datetime.datetime.now()
cam_programs=[]
......@@ -1191,6 +1363,7 @@ def derive_wetted_area_per_module(heat_flux, mapping, mode='average', q_max=None
------
total_wetted_area: float or numpy array
wetted area in a shape that depends on the mode (see NOTES)
in average it is (upper,lower)
q_max: float or numpy array
peak heat flux used for normalizatin in a shape that depends on the mode (see NOTES)
NOTES
......@@ -1571,4 +1744,44 @@ def derive_wetted_area_per_module(heat_flux, mapping, mode='average', q_max=None
plt.legend()
plt.show()
return total_wetted_area, q_max
\ No newline at end of file
return total_wetted_area, q_max
def convert_Bad_Pixels(Badpixels,map2D):
"""
transform the badpixel information from the camera images into a bad pixel
information for the heat flux images
INPUT
-----
Badpixels: 2D array
image of the bad pixels with 0 no bad pixel and >0 as bad pixel
map2D: dictonary of the
see downloadversionIRdata.download_heatflux_scene_model_reference()
RESULT
-----
heatflux_badpixel: numpy array
good pixels have a zero, bad pixels have a 1
"""
heatflux_badpixel=np.zeros(np.shape(map2D['Pixel_Y']))
PX=map2D['Pixel_X']
PY=map2D['Pixel_Y']
tlocos=np.where(np.asarray(Badpixels)>0)
locos=[]
for i in range(len(tlocos[0])):
locos.append((tlocos[0][i],tlocos[1][i]))
for ele in locos:
Xloc=np.where(PX==ele[1])
Yloc=np.where(PY==ele[0])
if len(Xloc[0])>0 and len(Yloc[0])>0:#okay there are points in the heat flux image with the coordinates
PointsX=[]
# PointsY=[]
for k in range(len(Xloc[0])):
PointsX.append((Xloc[0][k],Xloc[1][k]))
for L in range(len(Yloc[0])):
YY=(Yloc[0][L],Yloc[1][L])
if YY in PointsX:
heatflux_badpixel[YY[0],YY[1]]=1
# PointsY.append((Yloc[0][L],Yloc[1][L]))
return heatflux_badpixel
\ No newline at end of file
This diff is collapsed.
......@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup(
name = 'ir-data-access',
version = '3.3.2',
version = '3.4.0',
author = 'Holger Niemann, Peter Drewelow',
author_email = 'holger.niemann@ipp.mpg.de',
description = 'Access Frontend for IR camera data',
......
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