Commit 2ec333f8 authored by Holger Niemann's avatar Holger Niemann
Browse files

Update V3.3.2: bugfixes with respect to Issue 6 and 7, bug fixes in...

Update V3.3.2: bugfixes with respect to Issue 6 and 7, bug fixes in get_trigger_from_PID, setup.py updated
parent d4ebc56e
......@@ -4,7 +4,7 @@ Created on Wed Oct 25 15:51:46 2017
updated on Tue Aug 21 10:20:00 2018
last update on Fr Nov 23 15:37:00 2018
Version: 3.3.1
Version: 3.3.2
(Numbering: #of big changes(OP1.2a download V1, OP1.2b download V2, heatflux V3) . #of updates to add functionalities . #number of updates for bug fixes )
@author: holn
"""
......@@ -21,7 +21,9 @@ from IR_config_constants import archivepath,testarchivepath,portcamdict,camlimdi
#except:
# import read_restdb as AKF_1
import datetime
import urllib
import urllib.request
import urllib.error
import json
from PIL import Image
from io import BytesIO
......@@ -1071,6 +1073,7 @@ def download_raw_FLIR_images_via_png(t1,t6,time_window=0,version=0,threads=1,ver
# enddate=enddate.isoformat()
else:
starttime=int(t1-100)
tstart=t1
if time_window==0:
stoptime=t6
else:
......@@ -1140,7 +1143,7 @@ def get_FLIR_Pset_times(stdate,enddate,version=0,verbose=0,testmode=True):
counter=-1
for version0 in versions:
counter+=1
print(versions)
# print(versions)
try:
if version0>0:
found=False
......@@ -1872,7 +1875,7 @@ def get_temp_from_raw_by_program(portnr,program,time_window=0,emi=0.8,T_version=
verbose=0,testmode=False,framerate='max'):
"""
"""
FLIR=False
FLIR=False
trigger_exist, t0, t1, t6 = get_trigger_from_PID(program, portnr, testmode, verbose=verbose-1)
if not trigger_exist:
raise Exception("get_temp_from_raw_by_program: unknown Program")
......@@ -1881,14 +1884,18 @@ def get_temp_from_raw_by_program(portnr,program,time_window=0,emi=0.8,T_version=
OP=IR_tools.get_OP_by_time(time_ns=t1)
if type(portnr) is str:
try:
camera=portcamdict[OP][portnr]
if camera.split("_")[0]=='FLIR':
FLIR=True
else:
FLIR=False
portnr=int(portnr.split("AEF")[1])
except Exception as E:
raise Exception("get_temp_from_raw_by_program: unknown Port!"+E)
portnr=int(portnr)
FLIR=False
except:
try:
camera=portcamdict[OP][portnr]
if camera.split("_")[0]=='FLIR':
FLIR=True
else:
FLIR=False
portnr=int(portnr.split("AEF")[1])
except Exception as E:
raise Exception("get_temp_from_raw_by_program: unknown Port!"+E)
elif isinstance(portnr, (int, np.integer, float, np.float)):
FLIR=False
portnr=int(portnr)
......@@ -1978,7 +1985,7 @@ def get_temp_from_raw_by_program(portnr,program,time_window=0,emi=0.8,T_version=
else:
# --- IRcam case ---
#
# get calibration data
# get calibration data
cexist,background,LUT,refT,gain,offset,badpixels,t_exp,cfilter,gain_error,offset_error=get_calib_data(portnr,t0=t0,t1=t1,t6=t6,emissivity=emi,T_version=T_version,version=version,back_emissivity=back_emissivity,testmode=testmode,verbose=verbose-1)
if not cexist:
if verbose>0:
......@@ -2813,12 +2820,15 @@ def download_heatflux_by_program(port,program,time_window=0,threads=1,testmode=F
tstart=t1
tend=t6
elif type(time_window)==list or type(time_window)==np.ndarray:
if len(time_window)>1:
tstart=int(t1+time_window[0]*1e9)
tend=int(t1+time_window[1]*1e9)
else:
tstart=int(t1)
tend=int(t1+time_window[0]*1e9)
try:
if len(time_window)>1:
tstart=int(t1+time_window[0]*1e9)
tend=int(t1+time_window[1]*1e9)
else:
tstart=int(t1)
tend=int(t1+time_window[0]*1e9)
except Exception as E:
raise Exception("download_heatflux_by_program: an Exception occured interpretating the time_window: ",E)
elif type(time_window)==int or type(time_window)==float:
tstart=int(t1)
tend=int(t1+time_window*1e9)
......@@ -3101,7 +3111,7 @@ def download_heatflux_scene_model_reference(port,timepoint=None,program=None,
else:
return False,{}
def give_finger_ID(profile,finger=None):
def give_finger_ID(profile,finger=None,verbose=0):
"""
profile: string, integer or float, string: "TM3h_5_5" or "1605" or "16.05" or "5", similar for float and integer. single number only if the finger is given!
finger: string or integer, string "TM3h_5" or "16" or 16 or 1600 or None
......@@ -3132,17 +3142,20 @@ def give_finger_ID(profile,finger=None):
fingerID=int(profile)
success=True
else:
success=False
success=False
if verbose>0:
print("give_finger_ID: type of profile is not supported!")
else:#cases with both are given
if finger==str:
if type(finger)==str:
finger=finger.lower()
if "tm" in finger:
fing=finger.split("_")
offset=offsets[fing[0]]
finger=offset+int(prof[1])
finger=offset+int(fing[1])
else:
finger=int(finger)
if finger%100==0:
#finger is now an int
if finger%100==0: #check whether the finger format is 1600 or equal to it, reduce it to 16 or equal
finger=int(finger/100)
if type(profile)==int and type(finger)==int:#simple case
if finger<138 and profile<18:
......@@ -3150,26 +3163,39 @@ def give_finger_ID(profile,finger=None):
fingerID=finger*100+profile
else:
success=False
if verbose>0:
print("give_finger_ID: given finger or profile is out of valid range! (finger 0-137, profiles 0-17)")
### combinations left: str-str, float-str, float-int, str-int, int-str
elif type(profile)==str or type(profile)==float:#combinations str-str and str-int
try:### str: by logic only integer should be left if input is a valid one, float: in theory for a valid no further digits should be there
if type(profile)==float:
if profile<1.0:
profile=profile*100
fingerID=finger*100+int(profile)
success=True
except:
success=False
if verbose>0:
print("give_finger_ID: profile and finger defined, profile is not in a valid format!")
elif type(profile)==int:
if profile<18:
fingerID=finger*100+profile
success=True
else:
success=False
if verbose>0:
print("give_finger_ID: profile is out of valid range (0-17)")
else:
success=False
if verbose>0:
print("give_finger_ID: type of profile is not supported!")
if success:#last test
if fingerID%100<18 and fingerID//100<138 and not fingerID==-1:
success=True
else:
success=False
if verbose>0:
print("give_finger_ID: invalid fingerID found. Please check your input.")
return success,fingerID
def get_heatflux_profile(port,profile,finger=None,timepoint=1,program=None,tstart=None,
......@@ -3742,10 +3768,44 @@ def get_trigger_from_PID(program, port, testmode=False, verbose=0):
try:
# case port=='31'
port = int(port)
port = "AEF"+str(int(port))
except:
# case port=='... AEF31 ...'
port = int(port[port.find('AEF')+3:port.find('AEF')+5])
avports=[]
for key in portpathdict:
avports=avports+list(portpathdict[key].keys())
portprefix=[]
for portstr in avports:
if portstr[0:3] not in portprefix:
portprefix.append(portstr[0:3])
if len(port)<6:
if port not in avports:
print("get_trigger_from_PID: unknown port!",port,avports)
return False,0,0,0
else:
gotit=False
for key in portprefix:
if key in port:
port = int(port[port.find(key)+3:port.find(key)+5])
port=key+str(port)
gotit=True
break
if not gotit:
print("get_trigger_from_PID: unknown port!",port,avports)
return False,0,0,0
# if 'AEF' in port:
# port = int(port[port.find('AEF')+3:port.find('AEF')+5])
else:
try:
port="AEF"+str(int(port))
except:
print("get_trigger_from_PID: port format not supported")
return False,0,0,0
# check if program was defined in archive
if not isinstance(program, str):
program=str(program)
if len(program.split(".")[0])<3:
program=program+"0"
prog = get_program_from_PID(program)
if prog[0]:
t_preparation = prog[1]['trigger']['0'][0]
......@@ -3761,13 +3821,17 @@ def get_trigger_from_PID(program, port, testmode=False, verbose=0):
OP = IR_tools.get_OP_by_time(program_str=program)
# prepare Datastream url
if testmode:
stream_name = testarchivepath+project+"/"+portpathdict[OP]["AEF"+str(port)]+'raw_DATASTREAM'
stream_name = testarchivepath+project+"/"+portpathdict[OP][port]+'raw_DATASTREAM'
else:
stream_name = archivepath+project+"/"+portpathdict[OP]["AEF"+str(port)]+'raw_DATASTREAM'
stream_name = archivepath+project+"/"+portpathdict[OP][port]+'raw_DATASTREAM'
time_from = AKF_2.to_timestamp(date_str+' 00:00:00', fmt=u"%Y%m%d %H:%M:%S")
time_to = AKF_2.to_timestamp(date_str+' 23:59:59', fmt=u"%Y%m%d %H:%M:%S")
version = AKF_2.get_last_version(stream_name, time_from, time_to)
signal_name = stream_name+'/'+version+'/0/raw'
if version is not None:
signal_name = stream_name+'/'+version+'/0/raw'
else:
print("get_trigger_from_PID: no version with data found!")
return False,0,0,0
# load all time intervals with data in this datastream
intervals = AKF_2.get_time_intervals(signal_name, time_from, time_to)
frame_start = np.array(intervals[::-1,0])
......@@ -3813,19 +3877,19 @@ if __name__=='__main__':
print("local function calling")
#%% temperature download and plotting example
# port=31#"AEF50"#"AEF51"'20171114.053'#
# prog="20180911.008"#"20181011.033"#'20171122.035'#'20181011.010'#'20180823.037'#'20170927.020'#"20181011.036"#"20181016.037"#"20180920.042"#"20171109.021"#"20181010.036"
# status,time,images,valid=get_temp_from_raw_by_program(port,prog,time_window=[5,5.1],emi=0.80,T_version=2,version=0,threads=1,give_ERROR=False,use_firstframe_as_background=False,verbose=5)
## status2,time2,images2=download_raw_images_by_program(port,prog,time_window=0.02,verbose=5)
## bla=get_calib_data(50,program=prog,verbose=5)
## success,t,s,profile=extract_temperature_profile_from_DL(port,np.asarray(time-time[0])/1e9,images,profile="TM3h_5_5",verbose=10,reference_time=time[0])
# if status:
# plt.figure()
# plt.imshow(images[-1],vmin=330,vmax=1000,cmap=exJet)
# cb=plt.colorbar()
# cb.set_label("temperature in K",rotation=270,labelpad=20,fontsize=20)
# cb.ax.tick_params(labelsize=20)
# plt.title("AEF{0}".format(port))
port=31#"AEF50"#"AEF51"'20171114.053'#
prog="20180911.008"#"20181011.033"#'20171122.035'#'20181011.010'#'20180823.037'#'20170927.020'#"20181011.036"#"20181016.037"#"20180920.042"#"20171109.021"#"20181010.036"
status,time,images,valid=get_temp_from_raw_by_program(port,prog,time_window=[5,5.1],emi=0.80,T_version=2,version=0,threads=1,give_ERROR=False,use_firstframe_as_background=False,verbose=5)
# status2,time2,images2=download_raw_images_by_program(port,prog,time_window=0.02,verbose=5)
# bla=get_calib_data(50,program=prog,verbose=5)
# success,t,s,profile=extract_temperature_profile_from_DL(port,np.asarray(time-time[0])/1e9,images,profile="TM3h_5_5",verbose=10,reference_time=time[0])
if status:
plt.figure()
plt.imshow(images[-1],vmin=330,vmax=1000,cmap=exJet)
cb=plt.colorbar()
cb.set_label("temperature in K",rotation=270,labelpad=20,fontsize=20)
cb.ax.tick_params(labelsize=20)
plt.title("AEF{0}".format(port))
#%% heatflux test
# port = 20
......
......@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup(
name = 'ir-data-access',
version = '3.2.4',
version = '3.3.2',
author = 'Holger Niemann, Peter Drewelow',
author_email = 'holger.niemann@ipp.mpg.de',
description = 'Access Frontend for IR camera data',
......@@ -25,7 +25,9 @@ setup(
'data/AEF31_coldframes_background_fails_real.txt',
'data/AEF40_coldframes_background_fails_real.txt',
'data/AEF41_coldframes_background_fails_real.txt',
'data/AEF51_coldframes_background_fails_real.txt'])
'data/AEF51_coldframes_background_fails_real.txt',
'data/finger_info_HHF.csv',
'data/finger_info_TDU.csv'])
],
install_requires = [
'archivedb>=0.2.0'
......
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