diff --git a/downloadversionIRdata.py b/downloadversionIRdata.py index 729c6e527e3ee6d84d2abe93ac354d9ae3e5dcf8..1d6972b2f253510b1707194c221b11db42f16a2e 100644 --- a/downloadversionIRdata.py +++ b/downloadversionIRdata.py @@ -257,7 +257,7 @@ def get_NUC_by_program(port,program,exposure,version=0,verbose=0): if prog[0]: starttime=prog[1]['trigger']['0'][0] stoptime=prog[1]['trigger']['1'][0] - return get_NUC_by_times(port,starttime,stoptime,exposure,version=0,verbose=verbose-1) + return get_NUC_by_times(port,starttime,stoptime,exposure,version=0,verbose=verbose) else: # except: print("get_NUC_by_program: Error! cannot find the program") @@ -567,12 +567,12 @@ def download_raw_images_by_program(port,program,time_window=0,version=0,verbose= tstop=time_window[1] if tstop<tstart: raise Exception("download_raw_images_by_program: endtime before starttime") - return download_raw_images_by_times(port,int(starttime+tstart*1e9),int(starttime+tstop*1e9),version,verbose=verbose-1) + return download_raw_images_by_times(port,int(starttime+tstart*1e9),int(starttime+tstop*1e9),version,verbose=verbose) else: if time_window==0: - return download_raw_images_by_times(port,starttime,stoptime,version,verbose=verbose-1) + return download_raw_images_by_times(port,starttime,stoptime,version,verbose=verbose) else: - return download_raw_images_by_times(port,starttime,int(starttime+time_window*1e9),version,verbose=verbose-1) + return download_raw_images_by_times(port,starttime,int(starttime+time_window*1e9),version,verbose=verbose) except: print("download_raw_images_by_program: Error! cannot find the program") return False,0,0 @@ -584,7 +584,7 @@ def download_raw_images_by_times(port,starttime,stoptime,version=0,intervalSize= if version==0: version=get_latest_version(portpathdict[OP]["AEF"+str(port)]+"raw_DATASTREAM",t_from=starttime,t_to=stoptime) larchivepath=archivepath+"W7X/"+portpathdict[OP]["AEF"+str(port)]+"raw_DATASTREAM/V"+str(version)+"/0/raw" - return download_images_by_times(larchivepath,starttime=starttime,stoptime=stoptime,version=version,intervalSize=intervalSize,verbose=verbose-1) + return download_images_by_times(larchivepath,starttime=starttime,stoptime=stoptime,version=version,intervalSize=intervalSize,verbose=verbose) def download_images_by_times(larchivepath,starttime,stoptime,version=0,intervalSize=1E9,verbose=0): """ @@ -606,7 +606,10 @@ def download_images_by_times(larchivepath,starttime,stoptime,version=0,intervalS success=False for i in range(nrinterv): try: - res = urllib.request.urlopen(larchivepath+"/_signal.json?from="+str(intervalls[i])+"&upto="+str(intervalls[i+1])) + url = larchivepath+"/_signal.json?from="+str(intervalls[i])+"&upto="+str(intervalls[i+1]) + if verbose>2: + print("download_images_by_times: reading from\n {0}".format(url)) + res = urllib.request.urlopen(url) signal_list = json.loads(res.read().decode('utf-8')) res.close() images=[np.array(ele, dtype=typo) for ele in signal_list['values']] @@ -2573,7 +2576,7 @@ def download_heatflux_by_program(port,program,time_window=0,threads=1,testmode=F if givealpha: tstart=tstart-1.1e9 return download_heatflux_by_times(port=port,tstart=tstart,tend=tend,time_window=0, - testmode=testmode,version=version,verbose=verbose-1, + testmode=testmode,version=version,verbose=verbose, request=request) else: print("download_heatflux_by_program: Error! program not found") @@ -2638,7 +2641,7 @@ def download_heatflux_by_times(port,tstart,tend,time_window=0,threads=1,testmode if exist==False: now=datetime.datetime.now() if verbose>0: - print(now,"download_heatflux_by_times: heat flux data is not available, creating request") + print(now,"download_heatflux_by_times: heat flux data is not available") if request: f=open(heatflux_requestlist_path+str(now.year)+str(now.month-1)+"_q_requests.txt",'a') try: @@ -2649,9 +2652,12 @@ def download_heatflux_by_times(port,tstart,tend,time_window=0,threads=1,testmode programid=str(tstart) f.write(programid+"\tAEF"+str(port)+"\n") f.close() + if verbose>0: + print("download_heatflux_by_times: heat flux calculation request logged for automatic processing (within ca. 1 day)") return exist,time,frames -def download_heatflux_mapping_reference(timepoint=None,version=0,testmode=False,verbose=0): +def download_heatflux_mapping_reference(timepoint=None,version=0,testmode=False, + get_thickness=False, verbose=0): """ return exist(boolean) and dictonary of the mappings informations """ @@ -2680,6 +2686,84 @@ def download_heatflux_mapping_reference(timepoint=None,version=0,testmode=False, mappings['Finger_Y']=frames[4] mappings['Finger_ID']=(frames[5],"legend: first three digits are fingernumber,starting @0, last two are the profile number") mappings['Target']=(frames[6],{1:"TM1-4h",2:"TM5-6h",3:"TM7-9h",4:"TM1-3v"}) + + # derive thickness of profile line (for integration) + if get_thickness: + profile_no = mappings['Finger_ID'][0] + profile_ID = np.unique(profile_no) + profile_ID = profile_ID[:np.where(np.isnan(profile_ID))[0][0]] + profile_ID = profile_ID.astype(np.int16) + + d = np.zeros(np.shape(mappings['s'])) + for i_profile in profile_ID: + x_f = mappings['Finger_X'][np.where(profile_no==i_profile)] + y_f = mappings['Finger_Y'][np.where(profile_no==i_profile)] + if i_profile-1 not in profile_ID: + # i_profile is first profile of finger + # + # thickness of this profile at each point [x_f,y_f] is equal to + # the distance to the next line from [x1, y1] to [x2, y2] + # https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line + x_f_next = mappings['Finger_X'][np.where(profile_no==i_profile+1)] + x1 = x_f_next[0] + x2 = x_f_next[-1] + y_f_next = mappings['Finger_Y'][np.where(profile_no==i_profile+1)] + y1 = y_f_next[0] + y2 = y_f_next[-1] + d[np.where(profile_no==i_profile)] = \ + abs((y2-y1)*x_f - (x2-x1)*y_f + x2*y1 - y2*x1) / np.sqrt((y2-y1)**2 + (x2-x1)**2) + elif i_profile+1 not in profile_ID: + # i_profile is last profile of finger + # + # thickness of this profile at each point [x_f,y_f] is equal to + # the distance to the previous line from [x1, y1] to [x2, y2] + # https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line + x_f_prev = mappings['Finger_X'][np.where(profile_no==i_profile-1)] + x1 = x_f_prev[0] + x2 = x_f_prev[-1] + y_f_prev = mappings['Finger_Y'][np.where(profile_no==i_profile-1)] + y1 = y_f_prev[0] + y2 = y_f_prev[-1] + d[np.where(profile_no==i_profile)] = \ + abs((y2-y1)*x_f - (x2-x1)*y_f + x2*y1 - y2*x1) / np.sqrt((y2-y1)**2 + (x2-x1)**2) + else: + # a previous and next profile line exists on this finger + # + # thickness of this profile at each point [x_f,y_f] is the sum + # of half the distance to the previous line from [x1_p, y1_p] to [x2_p, y2_p] + # and half the distance to the next line from [x1_n, y1_n] to [x2_n, y2_n] + # https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line + x_f_prev = mappings['Finger_X'][np.where(profile_no==i_profile-1)] + x1_p = x_f_prev[0] + x2_p = x_f_prev[-1] + y_f_prev = mappings['Finger_Y'][np.where(profile_no==i_profile-1)] + y1_p = y_f_prev[0] + y2_p = y_f_prev[-1] + x_f_next = mappings['Finger_X'][np.where(profile_no==i_profile+1)] + x1_n = x_f_next[0] + x2_n = x_f_next[-1] + y_f_next = mappings['Finger_Y'][np.where(profile_no==i_profile+1)] + y1_n = y_f_next[0] + y2_n = y_f_next[-1] + d[np.where(profile_no==i_profile)] = \ + abs((y2_p-y1_p)*x_f - (x2_p-x1_p)*y_f + x2_p*y1_p - y2_p*x1_p) / np.sqrt((y2_p-y1_p)**2 + (x2_p-x1_p)**2) /2 + \ + abs((y2_n-y1_n)*x_f - (x2_n-x1_n)*y_f + x2_n*y1_n - y2_n*x1_n) / np.sqrt((y2_n-y1_n)**2 + (x2_n-x1_n)**2) /2 + mappings['thickness'] = d + if verbose>0: + print("download_heatflux_mapping_reference: 'thickness' of profiles added to mapping reference dictionary") + + # shift vertical target in X and Y if it is centered on top of horizontal target + index_ver = np.where(mappings['Target'][0]==4) + X = mappings['X'] + Y = mappings['Y'] + if abs(np.nanmean(mappings['X'][index_ver])) < 0.015 and abs(np.nanmean(mappings['Y'][index_ver])) < 0.01: + x1 = X[index_ver] + y1 = Y[index_ver] + X[index_ver] = np.cos(22.5/180*np.pi)*x1 + np.sin(22.5/180*np.pi)*y1 - 0.9 + Y[index_ver] = -np.sin(22.5/180*np.pi)*x1 + np.cos(22.5/180*np.pi)*y1 + 0.7 + if verbose>0: + print("download_heatflux_mapping_reference: vertical target moved and rotated in 'X' and 'Y' for better plotting") + return exist,mappings def download_heatflux_scene_model_reference(port,timepoint=None,program=None,version=0,testmode=False,verbose=0): @@ -2752,7 +2836,7 @@ def give_finger_ID(profile,finger=None): "tm1h":0,"tm2h":6,"tm3h":13,"tm4h":21,"tm5h":29,"tm6h":53,"tm7h":77,"tm8h":83,"tm9h":95,"tm1v":107,"tm2v":117,"tm3v":127} ### go throw the different cases, case: only one if given fingerID=-1 - if finger==None:##combinations there only profile is given + if finger==None:##combinations where only profile is given if type(profile)==int: fingerID=profile success=True diff --git a/plot_heatflux_example.py b/plot_heatflux_example.py index 67e41e6c4734f611650469457eb11d7cf559b94c..195f9c86858aeb988310acf3aa575c5290dfcd35 100644 --- a/plot_heatflux_example.py +++ b/plot_heatflux_example.py @@ -9,8 +9,8 @@ import downloadversionIRdata as IR import matplotlib.pyplot as plt import datetime -port=20 -program="20181004.012" +port=10 # 20 +program="20171207.022" # "20181004.012" if __name__=='__main__': @@ -44,7 +44,7 @@ if __name__=='__main__': plt.xlabel("s [m]",fontsize=26) plt.ylabel("q [MW/m2]",fontsize=26) plt.tick_params(labelsize=26) - plt.title("20171109.008 heat flux profile for TM3, finger 5, profile 5 @1s",fontsize=26) + plt.title("{0} heat flux profile for TM3, finger 5, profile 5 @1s".format(program),fontsize=26) plt.grid() plt.ylim(bottom=0) plt.show() @@ -58,7 +58,7 @@ if __name__=='__main__': cb=plt.colorbar() cb.set_label('heatflux in MW/m²', rotation=270, labelpad=15,fontsize=26) cb.ax.tick_params(labelsize=26) - plt.title("20171109.008 heat flux profile for TM3, finger 5, profile 5",fontsize=26) + plt.title("{0} heat flux profile for TM3, finger 5, profile 5".format(program),fontsize=26) plt.show() # status3,mapping=IR.download_heatflux_scene_model_reference(port,program=program,verbose=0) # bild=np.zeros((768,1024))