diff --git a/Create_HDF5_from_archive_data.py b/Create_HDF5_from_archive_data.py index 731c6e81f9bea1807fa0fe4ba42e9086176638f3..2d108482c4cee4a604578a8abf36725d46e7e9de 100644 --- a/Create_HDF5_from_archive_data.py +++ b/Create_HDF5_from_archive_data.py @@ -11,15 +11,15 @@ if __name__=='__main__': import downloadversionIRdata as IR_DL import numpy as np localpath="" - time_s=13 + time_s=1.5 - programlist = ["20171121.013"] - ports=[10] + programlist = ["20171010.025"] + ports=[50] for program in programlist: for port in ports: try: - exist,dimof,data1,valid=IR_DL.get_temp_from_raw_by_program(portnr=port,program=program,time_s=time_s,threads=4,verbose=5) + exist,dimof,data1,valid=IR_DL.get_temp_from_raw_by_program(portnr=port,program=program,time_window=time_s,threads=4,verbose=5) if exist: print("data found") stream="images" diff --git a/IR_da_config_constants.py b/IR_da_config_constants.py index fa8e8b297cd706b80dd33f98fe58b338e793b89a..a24c7b6fa5d12838b5e6f50daf78b0ecd45aebd6 100644 --- a/IR_da_config_constants.py +++ b/IR_da_config_constants.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ Created on Tue Jun 5 09:26:06 2018 -Version: 3.3.0 +Version: 3.4.4 @author: holn constants and config parameters """ @@ -441,4 +441,4 @@ c2dict={ c3dict=c2dict.copy() exJet=cm.colors.LinearSegmentedColormap('mod_Jet', c2dict, 1024) c3dict['alpha']=((0.0,0.0,0.0),(0.33,0.99,0.99),(1.0,1.0,1.0)) -exJet_trans=cm.colors.LinearSegmentedColormap('mod_Jet_trans', c3dict, 1024) \ No newline at end of file +exJet_trans=cm.colors.LinearSegmentedColormap('mod_Jet_trans', c3dict, 1024) diff --git a/IR_image_tools.py b/IR_image_tools.py index 912598d67db369153a193c09d9ccce504fe57b66..8802128f40bb708e0e5c487c4e618a7aa3bf868e 100644 --- a/IR_image_tools.py +++ b/IR_image_tools.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ Created on Wed May 9 14:56:32 2018 -Version: 3.4.3 +Version: 3.4.4 @author: Holger Niemann, Peter Drewelow, Yu Gao mainly to clean up the downloadversionIRdata code @@ -833,7 +833,8 @@ def get_work_list(pipepath,typ="q"): the path to the folder where the files are located typ: string the typ of data which is requested in the working list\n - possiblities: q, Aw, qpeak, width, load\n + possiblities: q, Aw, qpeak, width, load. q_old, load_old\n + both old parameters are opening the files bevore version 3.4.1\n or anything else for the problematic programs RESULT ------ @@ -849,7 +850,7 @@ def get_work_list(pipepath,typ="q"): if typ in ('q_old','load_old'): typ = typ.split("_")[0] f=open(pipepath+str(today.year)+str(today.month)+"_"+typ+"_requests.txt") - elif typ in ('q','load','qpeak','Aw','width'): + elif typ in ('q','load','qpeak','Aw','width','pf'): f=open(pipepath+"Auto_"+typ+"_requests.txt") else: reasons=[] @@ -858,13 +859,13 @@ def get_work_list(pipepath,typ="q"): koline=line.split("\t") if len(koline)>1: prog = koline[0] - if typ in ('q','load','qpeak','Aw','width','q_old','load_old'): + if typ in ('q','load','qpeak','Aw','width','q_old','load_old','pf'): cam_programs.append((prog,koline[1].split("\n")[0])) else: cam_programs.append((prog,koline[1])) reasons.append(koline[2].split("\n")[0]) f.close() - if typ in ('q','load','qpeak','Aw','width','q_old','load_old'): + if typ in ('q','load','qpeak','Aw','width','q_old','load_old','pf'): bla=check_dublicates_2(cam_programs) cam_programs=bla[0] return cam_programs @@ -910,7 +911,7 @@ def read_finger_info(file_name=None, OP='OP1.2b', verbose=0): elif OP.startswith('OP2'): file_name='finger_info_HHF.csv' full_path = os.path.join(parameter_file_path, file_name) - print(full_path) + #print(full_path) if verbose > 0: print('read_finger_info: reading from file {0} in {1}'.format(file_name, parameter_file_path)) if not os.path.isfile(full_path): diff --git a/downloadversionIRdata.py b/downloadversionIRdata.py index 037a925ef558b58ba2a572be8175ce36e5f8d7d0..b67e7ec57278aeb326eb2bd614c1aa2db89bc557 100644 --- a/downloadversionIRdata.py +++ b/downloadversionIRdata.py @@ -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.4.3 +Version: 3.5.0 (Numbering: #of big changes(OP1.2a download V1, OP1.2b download V2, heatflux V3) . #of updates to add functionalities @@ -12,7 +12,7 @@ Version: 3.4.3 #number of updates for bug fixes ) @author: holn """ -version = "V3.4.3" +version = "V3.5.0" import numpy as np import IR_image_tools as IR_tools @@ -76,9 +76,14 @@ def get_started(): # When ever that fails, just print the links: print("Some slides can be found in the wiki:") print(link) + plt.figure() + im=plt.imread(image) + plt.imshow(im) print("And a flow-chart for getting and using the data can be found here:") print(image) + plt.show() + def get_latest_version(stream, project="W7X", testmode=False, t_from=None, t_to=None, program=None, verbose=0): @@ -216,7 +221,7 @@ def read_program(timestamp_start, timestamp_end=0, tol=60): def download_LUT(port, time, exposure=0, emissivity=0, camera_filter=0, version=0, testmode=False, verbose=0): """ - download_LUT(camera, port, time, exposure=0, emissivity=0, camera_filter=0, version=1): + download_LUT(port, time, exposure=0, emissivity=0, camera_filter=0, version=1): download of the look up table for the infrared cameras from the database for OP1.2(a+b) Have to swap 11, 21 until correction in the database INPUT @@ -267,7 +272,7 @@ def download_LUT(port, time, exposure=0, emissivity=0, camera_filter=0, version= return False, 0 # raise Exception if version == 0:#version check, if 0 - version = get_latest_version(portpathdict[OP]["AEF"+str(port)]+"LUT_DATASTREAM", t_from=time, testmode=testmode) + version = get_latest_version(portpathdict[OP]["AEF"+str(port)]+"LUT_PARLOG", t_from=time, testmode=testmode) if verbose > 0: print("download_LUT: LUT V"+str(version)+" is used") #time=int(fu.TimeToNs([2017,9,26], [8, 0, 0, 0])) @@ -3172,7 +3177,7 @@ def get_temp_from_raw_by_program_V1(portnr, program, time_window=0, emi=0.8,dive time: list a list containing the time stamp of each frame frames: list - a list of frames, 2D numpy arrays + a list of frames, 2D numpy arrays, values are in Kelvin valid: boolean True if the data can be used/trusted optional: error_frames: list @@ -3309,7 +3314,7 @@ def get_temp_from_raw_by_program_V2(portnr, program, time_window=0, emi=0.8, ver time: list a list containing the time stamp of each frame frames: list - a list of frames, 2D numpy arrays + a list of frames, 2D numpy arrays, values are in Kelvin valid: boolean True if the data can be used/trusted optional: error_frames: list @@ -3361,7 +3366,8 @@ def get_temp_from_raw_by_program(portnr, program, time_window=0, emi=0.8, T_vers testmode: boolean, optional, default False if True, the data will be loaded from the test archive framerate: string or integer, optional, default 'max' - sets the framerate to downsample the data. normal rate is 100. + sets the framerate to downsample the data. normal rate is 100. \n + works only if w7xarchive is available! RESULT ------ exist: boolean @@ -4705,7 +4711,8 @@ def download_heatflux_by_program(port, program, time_window=0, testmode=False, verbose: integer, optional, default 0 feedback level (details of print messages) givealpha: boolean, default False - switch to turn on or off the return of the alpha image from the THEODOR calculation, it wil be returned as first image + switch to turn on or off the return of the alpha image from the THEODOR calculation, it wil be returned as first image\n + it sets the timewindow start automatically to t1 if active request: boolean, default True switch to turn on or off the request of data if the data is not available in the database RESULT @@ -5546,7 +5553,7 @@ def download_divertor_load(port, targetmodule=None, program=None, tstart=None, port: int or str the port description for the camera as number or full string (e.g. 'AEF10') targetmodule: str or list/ndarray of str, optional - name or description of the target module, nothing wil return total load + name or description of the target module, nothing will return total load of the requested divertor(camera) program: str program id as str in the format yyyymmdd.pid tstart: integer @@ -5570,7 +5577,7 @@ def download_divertor_load(port, targetmodule=None, program=None, tstart=None, time: list a list containing the time stamp of each frame, time is in nanoseconds UTC load: list - a list of values, values in the images are in W + a list of values, values in the list are in W error: list a list of values, the error of each timepoint, values are in W """ @@ -5589,11 +5596,137 @@ def download_divertor_load(port, targetmodule=None, program=None, tstart=None, 'TM2V':(22,23, 'TM2v_load'), '2V':(22,23, 'TM2v_load'), 'TM3V':(24,25, 'TM3v_load'), '3V':(24,25, 'TM3v_load') } + return __download_module_based_data__(kind="load",TMchadict=TMchadict,port=port, + targetmodule=targetmodule,program=program, tstart=tstart, tend=tend, + version=version, verbose=verbose, testmode=testmode, + request=request, request_ALL=request_ALL) + +def download_peak_heatflux(port, targetmodule=None, program=None, tstart=None, + tend=None, version=0, verbose=0, testmode=False, + request=True, request_ALL=False): + """ + downloads the evaluated peak heat flux, based on the heat flux evaluation of the temperature data from the IR cameras.\n + The data is structed in maximum peak heat flux per divertor, identified by the port, and also in target-modules of the divertor.\n + An estiamted error for the data is given back. + To get the total divertor load, please download the data of each of the 10 AEF ports.\n + In case one or more ports are missing, request can be created (console will give feedback on the request).\n + The data will be evaluated by a server over time. + + INPUT + ------ + port: int or str + the port description for the camera as number or full string (e.g. 'AEF10') + targetmodule: str or list/ndarray of str, optional + name or description of the target module, nothing will return total load of the requested divertor(camera) + program: str + program id as str in the format yyyymmdd.pid + tstart: integer + time in ns where the search should start + tend: integer + time in ns where the search should end + version: integer, optional, default 0 + Version of the data in the archiveDB, in case of 0 the highest version will be used + verbose: integer, optional + feedback level (details of print messages) + testmode: boolean, default False + True to load data from testarchive + request: boolean, optional, default True + switch to turn on or off the request of data if the data is not available in the database + request_ALL: boolean, optional, default False + switch to turn on the request of data for all AEF ports + RESULT + ------ + exist: boolean + True if data was found, False if not + time: list + a list containing the time stamp of each frame, time is in nanoseconds UTC + peakflux: list + a list of values, values in the list are in W/m^2 + error: list + a list of values, the error of each timepoint, values are in W/m^2 + """ + TMchadict={ + 'ALL':(0,1, 'maximum_divertor_heatflux'), 'FULL':(0,1, 'maximum_divertor_heatflux'), + 'TM1H':(2,3, 'TM1h_peakflux'), '1H':(2,3, 'TM1h_peakflux'), + 'TM2H':(4,5, 'TM2h_peakflux'), '2H':(4,5, 'TM2h_peakflux'), + 'TM3H':(6,7, 'TM3h_peakflux'), '3H':(6,7, 'TM3h_peakflux'), + 'TM4H':(8,9, 'TM4h_peakflux'), '4H':(8,9, 'TM4h_peakflux'), + 'TM5H':(10,11, 'TM5h_peakflux'), '5H':(10,11, 'TM5h_peakflux'), + 'TM6H':(12,13, 'TM6h_peakflux'), '6H':(12,13, 'TM6h_peakflux'), + 'TM7H':(14,15, 'TM7h_peakflux'), '7H':(14,15, 'TM7h_peakflux'), + 'TM8H':(16,17, 'TM8h_peakflux'), '8H':(16,17, 'TM8h_peakflux'), + 'TM9H':(18,19, 'TM9h_peakflux'), '9H':(18,19, 'TM9h_peakflux'), + 'TM1V':(20,21, 'TM1v_peakflux'), '1V':(20,21, 'TM1v_peakflux'), + 'TM2V':(22,23, 'TM2v_peakflux'), '2V':(22,23, 'TM2v_peakflux'), + 'TM3V':(24,25, 'TM3v_peakflux'), '3V':(24,25, 'TM3v_peakflux') + } + return __download_module_based_data__(kind="qpeak",TMchadict=TMchadict,port=port, + targetmodule=targetmodule,program=program, tstart=tstart, tend=tend, + version=version, verbose=verbose, testmode=testmode, + request=request, request_ALL=request_ALL) + +def __download_module_based_data__(kind, TMchadict, port, targetmodule=None, + program=None, tstart=None, tend=None, + version=0, verbose=0, testmode=False, + request=True, request_ALL=False): + """ + downloads the integrated divertor load or the peak heat flux, based on the heat flux evaluation of the temperature data from the IR cameras.\n + The data is structed in total load/peak heat flux per divertor, identified by the port, and also in target-modules of the divertor.\n + An estiamted error for the data is given back. + To get the total divertor load, please download the data of each of the 10 AEF ports.\n + In case one or more ports are missing, request can be created (console will give feedback on the request).\n + The data will be evaluated by a server over time. + + INPUT + ------ + port: int or str + the port description for the camera as number or full string (e.g. 'AEF10') + targetmodule: str or list/ndarray of str, optional + name or description of the target module, nothing will return total load of the requested divertor(camera) + program: str + program id as str in the format yyyymmdd.pid + tstart: integer + time in ns where the search should start + tend: integer + time in ns where the search should end + version: integer, optional, default 0 + Version of the data in the archiveDB, in case of 0 the highest version will be used + verbose: integer, optional + feedback level (details of print messages) + testmode: boolean, default False + True to load data from testarchive + request: boolean, optional, default True + switch to turn on or off the request of data if the data is not available in the database + request_ALL: boolean, optional, default False + switch to turn on the request of data for all AEF ports + RESULT + ------ + exist: boolean + True if data was found, False if not + time: list + a list containing the time stamp of each frame, time is in nanoseconds UTC + load: list + a list of values, values in the list are in W + error: list + a list of values, the error of each timepoint, values are in W + """ + print(kind) + if kind in ["load","qpeak"]: + if kind == "load": + datcha_name = 'divertor_total_load' + funname = "download_divertor_load" + streamname = "loads" + else: + datcha_name = 'maximum_divertor_heatflux' + funname = "download_peak_heatflux" + streamname = "peakflux" + else: + raise Exception("__download_module_based_data__: wrong input!") #interpretation of the targetmodule input, string or List of strings, numbers does not make sense here? if targetmodule == None: datcha = 0 ercha = 1 - datcha_name='divertor_total_load' + elif type(targetmodule)== list or type(targetmodule)==np.ndarray:## okay maybe more than one targetmodule is requested datcha = [] datcha_name = [] @@ -5632,7 +5765,7 @@ def download_divertor_load(port, targetmodule=None, program=None, tstart=None, # else: exist, _, tstart, tend = get_trigger_from_PID(program, port, testmode, verbose=verbose-1) if not exist: - print("download_divertor_load: Error! program not found") + print(f"{funname}: Error! program not found") return False, 0,-1,-1 else: if tend == None: @@ -5642,7 +5775,7 @@ def download_divertor_load(port, targetmodule=None, program=None, tstart=None, # tend=prog[1]['trigger']['6'][0] exist, _, _, tend = get_trigger_from_PID(program, port, testmode, verbose=verbose-1) if not exist: - print("download_divertor_load: Error! end trigger not found") + print(f"{funname}: Error! end trigger not found") return False, 0,-1,-1 #channels known, time known, okay lets get the data # tstart=int(tstart-100e6) @@ -5654,8 +5787,8 @@ def download_divertor_load(port, targetmodule=None, program=None, tstart=None, if type(port) == int: port = "AEF"+str(port) if version == 0: - version = get_latest_version(portpathdict[OP][str(port)]+"loads_DATASTREAM", project=project_ana, t_from=tstart, t_to=tend, testmode=testmode) - larchivepath = base+project_ana+"/"+portpathdict[OP][str(port)]+"loads_DATASTREAM/V"+str(version) + version = get_latest_version(portpathdict[OP][str(port)]+streamname+"_DATASTREAM", project=project_ana, t_from=tstart, t_to=tend, testmode=testmode) + larchivepath = base+project_ana+"/"+portpathdict[OP][str(port)]+streamname+"_DATASTREAM/V"+str(version) if type(datcha) == list:#case of several requested channels load = [] error = [] @@ -5691,34 +5824,376 @@ def download_divertor_load(port, targetmodule=None, program=None, tstart=None, if exist == False: now = datetime.datetime.now() if verbose > 0: - print(now, "download_divertor_load: divertor_load data is not available") + print(now, f"{funname}: divertor_load data is not available") if request: try: programid=AKF_2.get_program_id(tstart) except Exception as E: if verbose > 0: - print('download_divertor_load: Error! ', E) + print(f'{funname}: Error! ', E) programid=str(tstart) - cam_progs=IR_tools.get_work_list(heatflux_requestlist_path, typ='load') + cam_progs=IR_tools.get_work_list(heatflux_requestlist_path, typ=kind) cam_progs_ig,reasons=IR_tools.get_work_list(heatflux_requestlist_path, typ='ignore') cam_p = cam_progs+cam_progs_ig if (programid, str(port)) not in cam_p and (programid, "ALL") not in cam_p: - f = open(heatflux_requestlist_path+"Auto_load_requests.txt", 'a') + f = open(heatflux_requestlist_path+"Auto_"+kind+"_requests.txt", 'a') if request_ALL: f.write(programid+"\tALL\n") else: f.write(programid+"\t"+str(port)+"\n") f.close() if verbose > 0: - print(now, "download_divertor_load: request created") + print(now,f"{funname}: request created") elif verbose > 0: if (programid, str(port)) in cam_progs: - print(now, "download_divertor_load: request exist already") + print(now, f"{funname}: request exist already") else: pid = cam_progs_ig.index((programid, str(port))) - print(now, "download_divertor_load: request ignored, data not available, reason: {0}".format(reasons[pid])) + print(now, f"{funname}: request ignored, data not available, reason: {0}".format(reasons[pid])) return exist, time, load, error +def download_wetted_area(typ="total", program=None, tstart=None, + tend=None, version=0, verbose=0, request=True, return_used_divertors=False): + """ + downloads the wetted area on the divertor, based on the heat flux evaluation of the temperature data from the IR cameras.\n + The data is structed in total wetted area, and also in wetted area on upper and on lower targets.\n + In case data is missing, request can be created (console will give feedback on the request).\n + The data will be evaluated by a server over time. + + INPUT + ------ + typ: string, optional, default 'total' + name or description of the requested data, nothing will return total wetted area\n + options are: "total", "all", "upper", "lower", "qmaxUP", "qmaxDOWN" + program: str + program id as str in the format yyyymmdd.pid + tstart: integer + time in ns where the search should start + tend: integer + time in ns where the search should end + version: integer, optional, default 0 + Version of the data in the archiveDB, in case of 0 the highest version will be used + verbose: integer, optional + feedback level (details of print messages) + testmode: boolean, default False + True to load data from testarchive + request: boolean, optional, default True + switch to turn on or off the request of data if the data is not available in the database + return_used_divertors: boolean, optional, default False + if turned on, it will return also the list of divertors which were used to calculated the wetted area + RESULT + ------ + exist: boolean + True if data was found, False if not + time: list + a list containing the time stamp of each frame, time is in nanoseconds UTC + wetted area/qmax: list or dictionary + for total, upper or lower type of data a list of values, values are in m^2\n + for qmaxUP or qmaxDOWN are list of values, vales are in W/m^2 + for all a dictionary with total, upper and lower as list in the dictionary are returned + reference divertors: list, optional + if return_used_divertors if True, it will return a list with the port numbers of the cameras + """ + return __download_derived_data__(kind="Aw",typ=typ,program=program,tstart=tstart, + tend=tend,version=version,verbose=verbose, + request=request,return_used_divertors=return_used_divertors) + +def download_strikeline_width(typ="total", program=None, tstart=None, + tend=None, version=0, verbose=0, request=True, return_used_divertors=False): + """ + downloads the averaged strike-line width on the divertors, based on the heat flux evaluation of the temperature data from the IR cameras.\n + The data is structed in mean strike-line width, and also in strike-line width on upper and on lower targets.\n + In case data is missing, request can be created (console will give feedback on the request).\n + The data will be evaluated by a server over time. + + INPUT + ------ + typ: string, optional, default 'total' + name or description of the requested data, nothing will return strike-line width\n + options are: "total"(mean over all divertors), "all", "upper", "lower", "qmaxUP", "qmaxDOWN" + program: str + program id as str in the format yyyymmdd.pid + tstart: integer + time in ns where the search should start + tend: integer + time in ns where the search should end + version: integer, optional, default 0 + Version of the data in the archiveDB, in case of 0 the highest version will be used + verbose: integer, optional + feedback level (details of print messages) + testmode: boolean, default False + True to load data from testarchive + request: boolean, optional, default True + switch to turn on or off the request of data if the data is not available in the database + return_used_divertors: boolean, optional, default False + if turned on, it will return also the list of divertors which were used to calculated the wetted area + RESULT + ------ + exist: boolean + True if data was found, False if not + time: list + a list containing the time stamp of each frame, time is in nanoseconds UTC + wetted area/qmax: list or dictionary + for total, upper or lower type of data a list of values, values are in m\n + for qmaxUP or qmaxDOWN are list of values, vales are in W/m^2 + for all a dictionary with total, upper and lower as list in the dictionary are returned + reference divertors: list, optional + if return_used_divertors if True, it will return a list with the port numbers of the cameras + """ + return __download_derived_data__(kind="width",typ=typ,program=program,tstart=tstart, + tend=tend,version=version,verbose=verbose, + request=request,return_used_divertors=return_used_divertors) + +def download_peaking_factor(typ="total", program=None, tstart=None, + tend=None, version=0, verbose=0, request=True, return_used_divertors=False): + """ + downloads the averaged peaking factor on the divertors, based on the heat flux evaluation of the temperature data from the IR cameras.\n + The data is structed in mean peaking factor, and also in peaking factor on upper and on lower targets.\n + In case data is missing, request can be created (console will give feedback on the request).\n + The data will be evaluated by a server over time. + + INPUT + ------ + typ: string, optional, default 'total' + name or description of the requested data, nothing will return strike-line width\n + options are: "total"(mean over all divertors), "all", "upper", "lower", "qmaxUP", "qmaxDOWN" + program: str + program id as str in the format yyyymmdd.pid + tstart: integer + time in ns where the search should start + tend: integer + time in ns where the search should end + version: integer, optional, default 0 + Version of the data in the archiveDB, in case of 0 the highest version will be used + verbose: integer, optional + feedback level (details of print messages) + testmode: boolean, default False + True to load data from testarchive + request: boolean, optional, default True + switch to turn on or off the request of data if the data is not available in the database + return_used_divertors: boolean, optional, default False + if turned on, it will return also the list of divertors which were used to calculated the wetted area + RESULT + ------ + exist: boolean + True if data was found, False if not + time: list + a list containing the time stamp of each frame, time is in nanoseconds UTC + wetted area/qmax: list or dictionary + for total, upper or lower type of data a list of values, values are in m\n + for qmaxUP or qmaxDOWN are list of values, vales are in W/m^2 + for all a dictionary with total, upper and lower as list in the dictionary are returned + reference divertors: list, optional + if return_used_divertors if True, it will return a list with the port numbers of the cameras + """ + return __download_derived_data__(kind="qpeak",typ=typ,program=program,tstart=tstart, + tend=tend,version=version,verbose=verbose, + request=request,return_used_divertors=return_used_divertors) + +def __download_derived_data__(kind, typ="total", program=None, tstart=None, + tend=None, version=0, verbose=0, request=True, return_used_divertors=False): + """ + downloads the averaged strike-line width, peaking factor or wetted area on the divertors, based on the heat flux evaluation of the temperature data from the IR cameras.\n + The data is structed in a total value (wetted area) or mean value(width and peaking), and also in strike-line width on upper and on lower targets.\n + In case data is missing, request can be created (console will give feedback on the request).\n + The data will be evaluated by a server over time. + + INPUT + ------ + kind: string + the kind of data which is should be downloaded, options are: "Aw","PF","width" + typ: string, optional, default 'total' + name or description of the requested data, nothing will return the requested kind of data\n + options are: "total", "all", "upper", "lower", "qmaxUP", "qmaxDOWN" + program: str + program id as str in the format yyyymmdd.pid + tstart: integer + time in ns where the search should start + tend: integer + time in ns where the search should end + version: integer, optional, default 0 + Version of the data in the archiveDB, in case of 0 the highest version will be used + verbose: integer, optional + feedback level (details of print messages) + testmode: boolean, default False + True to load data from testarchive + request: boolean, optional, default True + switch to turn on or off the request of data if the data is not available in the database + return_used_divertors: boolean, optional, default False + if turned on, it will return also the list of divertors which were used to calculated the wetted area + RESULT + ------ + exist: boolean + True if data was found, False if not + time: list + a list containing the time stamp of each frame, time is in nanoseconds UTC + wetted area/qmax: list or dictionary + for total, upper or lower type of data a list of values, values are in m\n + for qmaxUP or qmaxDOWN are list of values, vales are in W/m^2 + for all a dictionary with total, upper and lower as list in the dictionary are returned + reference divertors: list, optional + if return_used_divertors if True, it will return a list with the port numbers of the cameras + """ + #defining what function this function is in reality + if kind in ["Aw","PF","width","wetted_area","wetted area","peaking factor","peaking_factor","strike-line_width","strikeline_width","strike line width"]: + if kind in ["Aw","wetted_area","wetted area"]: + funname = "download_wetted_area" + kind = "Aw" + stream_name = "wetted_area" + channelnames = {'total':(0,"total_wetted_area"), + 'upper':(1,"mean_upper_wetted_area"), + 'lower':(2,"mean_lower_wetted_area") + } + elif kind in ["PF","peaking factor","peaking_factor"]: + funname = "download_peaking_factor" + kind = "pf" + stream_name = "peaking_factor" + channelnames = {'total':(0,"mean_peaking_factor"), + 'upper':(1,"mean_upper_peaking_factor"), + 'lower':(2,"mean_lower_peaking_factor") + } + else: + funname = "download_strikeline_width" + kind = "width" + stream_name = "strikeline_width" + channelnames = {'total':(0,"mean_strikeline_width"), + 'upper':(1,"mean_upper_strikeline_width"), + 'lower':(2,"mean_lower_strikeline_width") + } + else: + raise Exception("__download_derived_data__: wrong input!") + channelnames['qmaxUP']=(3,"max_upper_heatflux") + channelnames['qmaxDOWN']=(4,"max_lower_heatflux") + #"total", "all", "upper", "lower", "qmaxUP", "qmaxDOWN" + + # what is the time input? + if program == None and tstart == None: + if verbose > 0: + print("input for program and time invalid!") + return False, 0,-1,-1 + elif program != None: + exist, _, tstart, tend = get_trigger_from_PID(program, testmode=False, verbose=verbose-1) + if not exist: + print(f"{funname}: Error! program not found") + return False, 0,-1,-1 + else: + if tend == None: + program=AKF_2.get_program_id(tstart) + exist, _, _, tend = get_trigger_from_PID(program, testmode=False, verbose=verbose-1) + if not exist: + print(f"{funname}: Error! end trigger not found") + return False, 0,-1,-1 + # the real download part + print("Version 3.5.0: version test") + if typ in ['all','All','ALL']: + datcha = [] + datcha_name = [] + for key in ["total", "upper", "lower", "qmaxUP", "qmaxDOWN"]: + ele = channelnames[key] + datcha.append(ele[0]) + datcha_name.append(ele[1]) + else: + ele = channelnames[typ] + datcha = ele[0] + datcha_name = ele[1] + if version == 0: + version = get_latest_version(f"QRT_IRCAM/{stream_name}_DATASTREAM", project=project_ana, t_from=tstart, t_to=tend, testmode=False) + larchivepath = archivepath+project_ana+"/"+f"QRT_IRCAM/{stream_name}_DATASTREAM/V"+str(version) + if type(datcha) == list:#case of several requested channels + chadat = [] + exist = True + for i in range(len(datcha)): + data = read_restdb(larchivepath+"/"+str(datcha[i])+"/"+datcha_name[i]+"/_signal.json?from="+str(tstart)+"&upto="+str(tend)) + if i == 0: + if data[0]: + time = data[1] + else: + time = 0 + exist = False + if data[0]: + chadat.append(data[2]) + if len(datcha) != len(chadat): + exist = False + else:# case for a single channel + print(larchivepath+"/"+str(datcha)+"/"+datcha_name+"/_signal.json?from="+str(tstart)+"&upto="+str(tend)) + data = read_restdb(larchivepath+"/"+str(datcha)+"/"+datcha_name+"/_signal.json?from="+str(tstart)+"&upto="+str(tend)) + if data[0]: + print("data found") + exist = True + time = data[1] + chadat = data[2] + else: + exist = False + time = 0 + chadat = -1 + #the extra stuff + if return_used_divertors: + larchivepath_par = archivepath+project_ana+"/"+f"QRT_IRCAM/{stream_name}_PARLOG/V"+str(version) + try: + res = urllib.request.urlopen(larchivepath_par+"/_signal.json?from="+str(tstart)+"&upto="+str(tend)) + signal_list = json.loads(res.read().decode('utf-8')) + res.close() + goon=True + except urllib.error.URLError as e: + print('__download_derived_data__: Error! ', e, larchivepath_par+"/_signal.json?from="+str(tstart)+"&upto="+str(tend)) + goon=False + except Exception as E: + print('__download_derived_data__: Error! ', E) + goon=False + if not goon: + print("__download_derived_data__: Unable to download the used divertor list") + portlist = [] + else: + try: + portlist = signal_list['values'][0]['header']['divertor_ports'] + portlist = portlist.split('[')[1].split("]")[0].split(",") + for i in range(len(portlist)): + portlist[i]=int(portlist[i]) + except: + portlist = [] + print(signal_list['values'][0]['header']) + + # the request part + + if exist == False: + now = datetime.datetime.now() + if verbose > 0: + print(now, f"{funname}: wetted area data is not available") + if request: + try: + programid=AKF_2.get_program_id(tstart) + except Exception as E: + if verbose > 0: + print(f'{funname}: Error! ', E) + programid=str(tstart) + cam_progs=IR_tools.get_work_list(heatflux_requestlist_path, typ=kind) + cam_progs_ig,reasons=IR_tools.get_work_list(heatflux_requestlist_path, typ='ignore') + cam_p = cam_progs+cam_progs_ig + portsblocked = 0 + blockedports=[] + for port in [10,11,20,21,30,31,40,41,50,51]: + if (programid, str(port)) in cam_p: + portsblocked+=1 + blockedports.append(port) + if (programid, "ALL") not in cam_p and portsblocked < 5:#(programid, str(port)) not in cam_p and + f = open(heatflux_requestlist_path+"Auto_"+kind+"_requests.txt", 'a') + f.write(programid+"\tALL\n") + f.close() + if verbose > 0: + print(now, f"{funname}: request created") + elif verbose > 0: + if (programid, "ALL") in cam_progs: + print(now, f"{funname}: request exist already") + else: + for port in blockedports: + pid = cam_progs_ig.index((programid, str(port))) + print(now, f"{funname}: request ignored, data not available, reason: {0}".format(reasons[pid])) + if return_used_divertors: + return exist, time, chadat, portlist + else: + return exist, time, chadat + + def download_scene_model(port, program=None, timepoint=None, version=0, testmode=False, verbose=0): ''' downloading the scene model, provided by F. Pisano @@ -6327,4 +6802,4 @@ if __name__=='__main__': # if exist: # print('data of port {0} in program {1}:\n t_preparation {2}ns\n t_start {3}ns\n t_end {4}ns'.format(port, program, t0, t1, t6)) - \ No newline at end of file + diff --git a/setup.py b/setup.py index 1d07b44212646fc4385fbde002c55c855d6d0472..71dba4b8b7b20890af31b4277294851f1eb55084 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name = 'ir-data-access', - version = '3.4.3', + version = '3.4.4', author = 'Holger Niemann, Peter Drewelow', author_email = 'holger.niemann@ipp.mpg.de', description = 'Access Frontend for IR camera data', @@ -16,7 +16,7 @@ setup( 'plot_heatflux_example' ], data_files=[ - ('',['upload_config','CHANGELOG','ToDo.txt','README.md']), + ('',['download_config','CHANGELOG','ToDo.txt','README.md']), ('data',['data/AEF10_coldframes_background_fails_real.txt', 'data/AEF11_coldframes_background_fails_real.txt', 'data/AEF20_coldframes_background_fails_real.txt',