Commit 0f09315d authored by Holger Niemann's avatar Holger Niemann
Browse files

bugfixing in the caching routine, caching now tested for heatflux, merging...

bugfixing in the caching routine, caching now tested for heatflux, merging worked, saving worked, loading worked so far
parent 02ec8432
......@@ -4786,7 +4786,7 @@ def download_heatflux_by_program(port, program, time_window=0, testmode=False,
return False, [0], [0]
if givealpha:
tstart=tstart-1.1e9
return download_heatflux_by_times(port=port, tstart=tstart, tend=tend, time_window=0,
return download_heatflux_by_times(port=port, tstart=tstart, tend=tend, time_window=time_window,
testmode=testmode, version=version, verbose=verbose,
request=request, framerate=framerate, caching=caching)
......@@ -6453,8 +6453,10 @@ def load_cache_file(typ,port,program,time_window,framerate='max',verbose=0):
portname=port
else:
portname="AEF"+str(port)
found = False
for f in list(os.walk(cpath))[0][2]:
if f.find(f"{typ}_{program}_{portname}") == 0:
print(f,typ,program,portname)
if f.find(f"{typ}_{program}_{portname}") > 0:
t_window = f.split("_")[4]
f_rate = f.split("_")[5].split(".")[0]
if verbose:
......@@ -6489,7 +6491,7 @@ def load_cache_file(typ,port,program,time_window,framerate='max',verbose=0):
### check time window. is the requested time window in the cache or partly in the cache?
##cases: 1 it fits perfect, 2 the requested is in the available, 3 the requested is partly in the available, 0 no fitting, 5 separated file needed
if "[" in t_window:
dummy = t_window
dummy = t_window.split("[")[1].split("]")[0]
t_window2 = [float(dummy.split(", ")[0]),float(dummy.split(", ")[1])]
else:
t_window2 = [0,float(t_window)]
......@@ -6523,6 +6525,7 @@ def load_cache_file(typ,port,program,time_window,framerate='max',verbose=0):
print(f"{program}: returning cached data")
dat = pickle.load(f)
#data loaded, not treating the cases, start with time window stuff
dat=[dat[i] for i in range(len(dat))]
if TW_case <= 2:
if TW_case == 1:#okay time fits
if fcase == 1:
......@@ -6543,7 +6546,7 @@ def load_cache_file(typ,port,program,time_window,framerate='max',verbose=0):
prog = get_program_from_PID(program)
if prog[0] and dat[0]:
t_start = prog[1]['trigger']['1'][0]
t_vec_s = (np.asarray(dat[1])-t_start)/1e6
t_vec_s = (np.asarray(dat[1])-t_start)/1e9
TID1 = IR_tools.find_nearest(t_vec_s, time_window2[0])
TID2 = IR_tools.find_nearest(t_vec_s, time_window2[1])
if fcase == 1:
......@@ -6578,7 +6581,7 @@ def load_cache_file(typ,port,program,time_window,framerate='max',verbose=0):
prog = get_program_from_PID(program)
if prog[0] and dat[0]:
t_start = prog[1]['trigger']['1'][0]
t_vec_s = (np.asarray(dat[1])-t_start)/1e6
t_vec_s = (np.asarray(dat[1])-t_start)/1e9
TID1 = IR_tools.find_nearest(t_vec_s, time_window2[0])
TID2 = IR_tools.find_nearest(t_vec_s, time_window2[1])
cas1 = False
......@@ -6593,7 +6596,7 @@ def load_cache_file(typ,port,program,time_window,framerate='max',verbose=0):
t_win = [t_vec_s[TID2],time_window2[1]]
t_win2 = [t_vec_s[TID1],time_window2[1]]
cachename = f"IR_{typ}_{program}_{portname}_{t_window}_{f_rate}.cache"
cachename_new = f"IR_{typ}_{program}_{portname}_{t_win2}_{f_rate}.cache"
cachename_new = f"IR_{typ}_{program}_{portname}_{t_win2}_{f_rate}.cache"
if typ == "temperature":
threads = os.cpu_count()*2
dat2 = get_temp_from_raw_by_program(port, program, time_window=t_win, threads=threads, verbose=int(verbose), framerate=framerate, caching=False)
......@@ -6604,19 +6607,19 @@ def load_cache_file(typ,port,program,time_window,framerate='max',verbose=0):
#merge dat and dat 2
if dat2[0] and dat[0]:
if cas1:
dat[1]=dat2[1]+dat[1]
dat[2]=dat2[2]+dat[2]
dat[1]=np.append(dat2[1],dat[1][1:])
dat[2]=dat2[2]+dat[2][1:]
else:
dat[1]=dat[1]+dat2[1]
dat[2]=dat[2]+dat2[2]
dat[1]=np.append(dat[1],dat2[1][1:])
dat[2]=dat[2]+dat2[2][1:]
#resave cache
os.remove(cpath+"\\"+cachename)
with open(cachename_new, "wb") as f:
with open(cpath+"\\"+cachename_new, "wb") as f:
pickle.dump(dat, f)
if verbose>0:
print(f"{program}: returning newly calculated {typ} data, cached for later use")
#extract framerate if needed
t_vec_s = (np.asarray(dat[1])-t_start)/1e6
t_vec_s = (np.asarray(dat[1])-t_start)/1e9
TID1 = IR_tools.find_nearest(t_vec_s, time_window2[0])
TID2 = IR_tools.find_nearest(t_vec_s, time_window2[1])
if fcase == 1:
......@@ -6659,7 +6662,7 @@ def load_cache_file(typ,port,program,time_window,framerate='max',verbose=0):
else:
raise Exception("load_cache_file: unknown data typ!")
if dat[0]:
with open(cachename, "wb") as f:
with open(cpath+"\\"+cachename, "wb") as f:
pickle.dump(dat, f)
if verbose>0:
print(f"{program}: returning newly calculated {typ} data, cached for later use")
......@@ -6668,6 +6671,8 @@ def load_cache_file(typ,port,program,time_window,framerate='max',verbose=0):
print("load_cache_file: download of data failed")
return dat
else:
if verbose > 0:
print(f"load_cache_file: no matching cache file found, creating cache file, framerate: {framerate}, time window: {time_window}")
cachename = f"IR_{typ}_{program}_{portname}_{time_window}_{framerate}.cache"
if typ == "temperature":
threads = os.cpu_count()*2
......@@ -6677,7 +6682,7 @@ def load_cache_file(typ,port,program,time_window,framerate='max',verbose=0):
else:
raise Exception("load_cache_file: unknown data typ!")
if dat[0]:
with open(cachename, "wb") as f:
with open(cpath+"\\"+cachename, "wb") as f:
pickle.dump(dat, f)
if verbose>0:
print(f"{program}: returning newly calculated {typ} data, cached for later use")
......
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 29 17:41:40 2018
V3.4.1
V3.6.0
@author: holn
"""
import numpy as np
......@@ -18,7 +18,7 @@ if __name__=='__main__':
#%% loading data
print(datetime.datetime.now(),"start")
status,times,images=IR.download_heatflux_by_program(port,program,time_window=[0,2],version=2,verbose=5,testmode=False)
status,times,images=IR.download_heatflux_by_program(port,program,time_window=[0,2],version=2,verbose=5,testmode=False,caching=True)
print('done')
#%% plotting data
......
......@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup(
name = 'ir-data-access',
version = '3.5.0',
version = '3.6.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