Commit 69d01578 authored by Peter Drewelow's avatar Peter Drewelow
Browse files

downloadversionIRdata: added new function get_NUCed_coldframe_by_program(), adjusted test section

parent 18b99445
......@@ -430,7 +430,8 @@ def download_hot_cold_reference_by_times(port,exposure,starttime=150390720000000
if version==0:
version=get_latest_version(portpathdict[OP]["AEF"+str(port)]+"raw_DATASTREAM",t_from=starttime)
try:
res = urllib.request.urlopen(larchivepath+"PARLOG/V"+str(version)+"/_signal.json?from="+str(starttime)+"&upto="+str(int(starttime+1e9)))
path_string = larchivepath+"PARLOG/V"+str(version)+"/_signal.json?from="+str(starttime)+"&upto="+str(int(starttime+1e9))
res = urllib.request.urlopen(path_string)
signal_list = json.loads(res.read().decode('utf-8'))
res.close()
goon=True
......@@ -550,6 +551,88 @@ def get_NUCed_background_by_times(port,t0,t1,t_exp,cfilter,gain,offset,version=0
plt.title("background image nuced")
return exist,btime[0],background
def get_NUCed_coldframe_by_program(port, program, exposure=None, version=0, plot_it=False, verbose=0):
"""
Load the raw cold refences frame taken bofore this program and NUC it with
the NUC of the previous program (or next one, if the previous does not exist).
INPUT
-----
port: int
number of camera AEF port (e.g. 10, 11, 20,...)
program: str
experiment program identifier as a string of format 'DATE.PROG_NO',
e.g. '20180904.015'
exposure: float, optional
camera exposure time in us
(OPTIONAL: default is to take the exposure time of the first data frame)
version: int, optional
calibration version to be used
(OPTIONAL: default is 0)
plot_it: bool, optional
switch of whether to plot intermediate results or not
(OPTIONAL: deafult is NOT to plot)
verbose: integer, optional
feedback level (details of print messages)
(OPTIONAL: if not provided, only ERROR output)
RESULT
------
exist: bool
indicator, of coldframe could be found
coldframe: numpy array
NUCed cold frame
"""
if exposure is None:
exist, t, exposure = get_exposure_by_program(port, program, version=version)
t_exp = exposure[0]
else:
if verbose>0:
print('get_NUCed_coldframe_by_program: using exposure time {0}'.format(exposure))
t_exp = exposure
exist, data, desc = get_NUC_by_program(port, program, t_exp, version=version, verbose=verbose-1)
if exist:
cold_raw = data[2]
porg_nr = int(program.split('.')[1])
ref_program = '{0}.{1:03d}'.format(program.split('.')[0], porg_nr-1)
exist2, data, desc = get_NUC_by_program(port, ref_program, t_exp, version=version, verbose=verbose-1)
if exist2:
coldframe = apply_NUC([cold_raw],data[0],data[1])[0]
if verbose>0:
print('get_NUCed_coldframe_by_program: using NUC of program {0}'.format(ref_program))
else:
ref_program = '{0}.{1:03d}'.format(program.split('.')[0], porg_nr+1)
if verbose>0:
print('get_NUCed_coldframe_by_program: program {0} is first of day.\n --> using NUC of {1}'.format(program, ref_program))
exist2, data, desc = get_NUC_by_program(port, ref_program, t_exp, version=version, verbose=verbose-1)
if exist2:
coldframe = apply_NUC([cold_raw],data[0],data[1])[0]
else:
print('get_NUCed_coldframe_by_program: WARNING! no adjacent program found! --> cold frame is not NUCed')
coldframe = cold_raw
if plot_it:
plt.figure(figsize=[8,4])
plt.subplot(1,2,1)
plt.imshow(cold_raw, vmin=np.percentile(cold_raw, 1), vmax=np.percentile(cold_raw, 99) )
plt.colorbar()
plt.title('raw cold frame\nof {0}'.format(program))
plt.subplot(1,2,2)
plt.imshow(coldframe, vmin=np.percentile(coldframe, 1), vmax=np.percentile(coldframe, 99) )
plt.colorbar()
plt.title('NUCed based on\ngain/offset from {0}'.format(ref_program))
plt.tight_layout()
plt.show()
else:
print('get_NUCed_coldframe_by_program: ERROR! No cold frame found for program {0}!'.foramt(program))
coldframe = []
return exist, coldframe
def download_raw_images_by_program(port,program,time_window=0,version=0,verbose=0):
"""
"""
......@@ -3470,8 +3553,8 @@ if __name__=='__main__':
# print(prog,port,"missing")
# plt.figure(),plt.imshow(images[0],vmin=0)
# plt.figure(),plt.imshow(images[50],vmin=0)
status,mapping=download_heatflux_mapping_reference(verbose=4)
test=get_heatflux_profile(20,1605,timepoint=1,program="20171109.008",verbose=4)
# status,mapping=download_heatflux_mapping_reference(verbose=4)
# test=get_heatflux_profile(20,1605,timepoint=1,program="20171109.008",verbose=4)
#%% loads test
# port=21
......@@ -3502,3 +3585,10 @@ if __name__=='__main__':
# dset.write_direct(imags)
# File.create_dataset('timestamps', data=list(bla[1]), dtype='uint64')#,compression="gzip")
# File.close()
#%% get hot cold image test
port=10
program="20180904.015"
exist, coldframe = get_NUCed_coldframe_by_program(port, program, exposure=None, version=0, plot_it=True, verbose=3)
\ No newline at end of file
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