Commit a4b6ebb4 authored by Peter Drewelow's avatar Peter Drewelow
Browse files

error propagation bugfix

upload_config: renamed to download_config
plot_IR_data.py: simplified plot and file naming; enabled download of temperature errors in example; added time trace plot of T(t) with error bars from some random point in image
downloadversionIRdata.py: get_temp_from_raw_by_program_V1() now reads error images for interval chunks and returns all in error_images
downloadversionIRdata.py: get_temp_from_raw_by_program() avoids crash when returning error_images in FLIR camera case (not computed for this camera)
downloadversionIRdata.py: apply_calib_on_raw() does now set error_images to 0 for each image, if no NUC happened (Infratech case), avoiding a crash in the error propagation
downloadversionIRdata.py: warning output made resilient for non-string type Exceptions
parent 7c7ec781
......@@ -3223,6 +3223,7 @@ def get_temp_from_raw_by_program_V1(portnr, program, time_window=0, emi=0.8,dive
intervalls.append(stoptime)
temperatureimages=[]
times=[]
error_images=[]
for i in range(nrinterv):
raw_dl=download_raw_images_by_times(portnr, intervalls[i], intervalls[i+1], version, intervalSize, testmode=testmode, verbose=verbose-1)
print(datetime.datetime.now(), "get_temp_from_raw_by_program_V1: download of raw images part {0} of {1} finished".format(i+1, nrinterv))
......@@ -3232,10 +3233,14 @@ def get_temp_from_raw_by_program_V1(portnr, program, time_window=0, emi=0.8,dive
del raw_dl
# images=images.swapaxes(1,2)
images=[im.swapaxes(0,1) for im in images]
success, images=apply_calib_on_raw(images, background, LUT,refT, gain, offset, True, verbose=verbose-1)
temperatureimages=temperatureimages+images
times=times+time
del time, images
if give_ERROR:
success, images, images_err=apply_calib_on_raw(images, background, LUT, refT, gain, offset, gain_error, offset_error, True, give_ERROR, verbose=verbose-1)
else:
success, images=apply_calib_on_raw(images, background, LUT, refT, gain, offset, gain_error, offset_error, True, give_ERROR, verbose=verbose-1)
temperatureimages += images
times += time
error_images += images_err
del time, images, images_err
else:
# raise Exception("get_temp_from_raw_by_program_V1: cannot download the raw images")
logging.warning("get_temp_from_raw_by_program_V1: cannot download the raw images")
......@@ -3555,7 +3560,7 @@ def get_temp_from_raw_by_program(portnr, program, time_window=0, emi=0.8, T_vers
if toff > 10e6:
print("get_temp_from_raw_by_program: time offset of {0}ns detected, correcting".format(toff))
time[:] = time[:]-toff
if give_ERROR:
if give_ERROR and not FLIR:
return exist, time, frames, valid, error_images
else:
return exist, time, frames, valid
......@@ -4009,6 +4014,7 @@ def apply_calib_on_raw(images, background, LUT,refT=28.5, gain=0, offset=0, gain
# del raw
# images=images.swapaxes(1,2)
if type(gain)!=int and type(offset)!=int:
# images has to be NUCed (e.g. IRcam Caleo image)
if verbose > 0:
print(datetime.datetime.now(), "apply_calib_on_raw: NUCing")
# eliminate bad offset and gain points
......@@ -4021,6 +4027,10 @@ def apply_calib_on_raw(images, background, LUT,refT=28.5, gain=0, offset=0, gain
images, error_images=apply_NUC(images, gain, offset, gain_error, offset_error, give_ERROR)
else:
images=apply_NUC(images, gain, offset)
else:
# images does not have to be NUCed (e.g. Infratech image),
# but error propagation requires an initial error image
error_images = np.zeros([len(images)], dtype='uint16')
if verbose > 0:
print(datetime.datetime.now(), "apply_calib_on_raw: background treatment")
# if fullbackground:
......@@ -4054,7 +4064,7 @@ def apply_calib_on_raw(images, background, LUT,refT=28.5, gain=0, offset=0, gain
return True, images
except Exception as E:
# raise Warning('apply_calib_on_raw: '+E)
logging.warning('apply_calib_on_raw: '+E)
logging.warning('apply_calib_on_raw: '+str(E))
return False, [0]
......
......@@ -11,27 +11,33 @@ loading IR data and printing plots
import datetime
import downloadversionIRdata as downIR
import matplotlib.pyplot as plt
import numpy as np
if __name__ == '__main__':
camera = 50
program_str = "20171207.054"
time_window = [0, 1]
T_0 = 273.15 # [K] of 0°C
#%% loading data
print(datetime.datetime.now(), "start")
status, time, images, valid = downIR.get_temp_from_raw_by_program(51,
"20171206.045",
time_window=[1, 1.1],
status, time, images, valid, error_images = downIR.get_temp_from_raw_by_program(camera,
program_str,
time_window=time_window,
emi=0.8,
T_version=2,
version=0,
threads=1,
give_ERROR=False,
give_ERROR=True,
verbose=5)
print('fertig')
#%% plotting data
plt.figure()
plt.imshow(images[0], cmap=plt.jet())
plt.clim([280, 630])
plt.imshow(images[50]-T_0, cmap=plt.jet())
plt.clim([0, np.max(images[50])-T_0])
plt.tick_params(axis='both', # changes apply to the x-axis
which='both', # both major and minor ticks are affected
bottom='off', # ticks along the bottom edge are off
......@@ -41,6 +47,28 @@ if __name__ == '__main__':
labelleft='off',
labelbottom='off') # labels along the bottom edge are off
c_ax = plt.colorbar()
c_ax.set_label('T [K]')
plt.savefig('20180726.028 - 2.2s - AEF50IR - in K.png', dpi=300, bbox_inches='tight')
c_ax.set_label('T [°C]')
plt.title('W7-X #{0} - camera AEF{1}'.format(program_str, camera))
save_file_name = '{0} - {1:.1f}s - AEF{2}IR - image.png'.format(program_str, time_window[0]+0.5, camera)
plt.savefig(save_file_name, dpi=300, bbox_inches='tight')
plt.show()
#%% plotting time trace
position = [255,505] # in pixel
plt.figure()
images = np.array(images)
error_images = np.array(error_images)
timetrace = images[:,position[0], position[1]]
timetrace_error = error_images[:,position[0], position[1]]
# plt.plot((time-time[0])/1E9+time_window[0], timetrace-T_0)
plt.errorbar((time-time[0])/1E9+time_window[0], timetrace-T_0, yerr=timetrace_error,
linestyle='', marker='.', markersize=2, color='k', capsize=3, ecolor='r')
plt.xlabel('time [s]')
plt.ylabel('T [°C]')
plt.title('W7-X #{0} - camera AEF{1}'.format(program_str, camera))
save_file_name = '{0} - pixel {1} - AEF{2}IR - timetrace.png'.format(program_str, position, camera)
plt.savefig(save_file_name, dpi=300, bbox_inches='tight')
plt.show()
print('max. T: {0:.1f}°C at t={1}ns'.format(np.max(timetrace-T_0), time[np.argmax(timetrace)]))
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