Changeset 744 in ETALON
- Timestamp:
- Nov 2, 2017, 12:38:09 PM (7 years ago)
- Location:
- CLIO/control
- Files:
-
- 1 added
- 9 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
CLIO/control/CLIO_graphical_interface.py
r691 r744 15 15 import os 16 16 import subprocess 17 import urllib2 17 18 18 19 #from motor_function import * … … 26 27 from clio_constants import * 27 28 28 INSERTED_VALUE1= 400000029 INSERTED_VALUE1=5500000 29 30 INSERTED_VALUE2=5000000 30 31 … … 32 33 threshold_old= 100 33 34 34 ImagesDisplaySize=(600,400) 35 ImagesDisplaySize=(400,300) 36 N_IMAGES_LINES=2 37 N_IMAGES_COLS=3 38 N_IMAGES=N_IMAGES_LINES*N_IMAGES_COLS 35 39 36 40 PROCESSES_REFRESH_INTERVAL=10 37 41 38 42 imageNames=[] 39 imageNames.append(code_directory+"no_data.png") 40 imageNames.append(code_directory+"no_data.png") 43 for iimage in range(N_IMAGES): 44 imageNames.append(code_directory+"no_data.png") 45 46 URI='http://'+IP_POWER_IP+'/Set.cmd' 47 auth_handler=urllib2.HTTPBasicAuthHandler() 48 auth_handler.add_password(realm='IP9258',uri=URI,user='admin',passwd='12345678') 49 opener= urllib2.build_opener(auth_handler) 50 urllib2.install_opener(opener) 41 51 42 52 #This is used for variables that are not updated on each refresh cycle … … 58 68 self.terminate=0 59 69 self.refresh_loop=0 60 print(data_directory)61 70 # canvas for image 62 self.canvas = Canvas(self.parent, width=800, height= 400)71 self.canvas = Canvas(self.parent, width=800, height=800) 63 72 self.frameImages = Frame(self.parent, borderwidth=10) 64 73 self.frameImages.grid(row=1, column=0) 65 74 self.my_images=[] 66 self.my_images.append(ImageTk.PhotoImage(Image.open(imageNames[0]).resize(ImagesDisplaySize, Image.ANTIALIAS))) 67 self.my_images.append(ImageTk.PhotoImage(Image.open(imageNames[1]).resize(ImagesDisplaySize, Image.ANTIALIAS))) 68 self.imageLabel1=Label(self.frameImages,image=self.my_images[0]) 69 self.imageLabel1.pack(side = "left", fill = "both", expand = "yes") 70 self.imageLabel2=Label(self.frameImages,image=self.my_images[1]) 71 self.imageLabel2.pack(side = "right", fill = "both", expand = "yes") 75 self.imageLabel=[] 76 self.newImage=[] 77 for iline in range(N_IMAGES_LINES): 78 for icol in range(N_IMAGES_COLS): 79 iimage=iline*N_IMAGES_COLS+icol 80 self.my_images.append(ImageTk.PhotoImage(Image.open(imageNames[iimage]).resize(ImagesDisplaySize, Image.ANTIALIAS))) 81 self.imageLabel.append(Label(self.frameImages,image=self.my_images[iimage])) 82 self.imageLabel[iimage].grid(row=iline,column=icol) 72 83 73 84 #Control buttons … … 98 109 self.labelAcquisitionStatus=Label(self.frameAcquisition,text='Status: unkown', bg='magenta') 99 110 self.labelAcquisitionStatus.grid(row=3,column=0) 111 self.labelAcquisitionRate=Label(self.frameAcquisition,text='Rate: unkown', bg='magenta') 112 self.labelAcquisitionRate.grid(row=4,column=0) 113 self.labelAcquisitionPause=Label(self.frameAcquisition,text='Pause: unkown', bg='magenta') 114 self.labelAcquisitionPause.grid(row=5,column=0) 100 115 101 116 #Power status 117 self.framePower = Frame(self.frameAllControls, borderwidth=10, relief=SUNKEN) 118 self.framePower.pack(side=LEFT) 119 labelPower=Label(self.framePower,text='IP Power') 120 labelPower.grid(row=0,column=0,columnspan=2) 121 self.buttonPower=[ Button(self.framePower, text=str(ipower), command= lambda v=ipower: self.onButtonPower(v)) for ipower in range(4) ] 122 for ipower in range(4): 123 self.buttonPower[ipower].grid(row=ipower+1,column=0) 124 #self.buttonPower[ipower].pack(side=BOTTOM) 125 self.buttonPower[0].config(text="Camera") 126 self.buttonPower[1].config(text="Blinker") 127 self.buttonPower[2].config(text="Amplifier") 128 self.buttonPower[3].config(text="Wago+Pot") 129 102 130 #Motor function 103 131 self.frameMotors = Frame(self.frameAllControls, borderwidth=10, relief=SUNKEN) … … 135 163 self.frameProcesses = Frame(self.frameAllControls, borderwidth=10, relief=SUNKEN) 136 164 self.frameProcesses.pack(side=LEFT) 165 self.labelProcessIPPower=Label(self.frameProcesses,text='IP Power', bg='blue') 166 self.labelProcessIPPower.grid(row=0,column=0,columnspan=1) 137 167 self.labelProcessWago=Label(self.frameProcesses,text='WAGO', bg='blue') 138 self.labelProcessWago.grid(row= 0,column=0,columnspan=1)168 self.labelProcessWago.grid(row=1,column=0,columnspan=1) 139 169 self.labelProcessMotorMonitor=Label(self.frameProcesses,text='Motor monitor', bg='blue') 140 self.labelProcessMotorMonitor.grid(row= 1,column=0,columnspan=1)170 self.labelProcessMotorMonitor.grid(row=2,column=0,columnspan=1) 141 171 self.labelProcessSaveData=Label(self.frameProcesses,text='Savedata', bg='blue') 142 self.labelProcessSaveData.grid(row= 2,column=0,columnspan=1)172 self.labelProcessSaveData.grid(row=3,column=0,columnspan=1) 143 173 self.labelProcessProcessRecent=Label(self.frameProcesses,text='Process recent', bg='blue') 144 self.labelProcessProcessRecent.grid(row= 3,column=0,columnspan=1)174 self.labelProcessProcessRecent.grid(row=4,column=0,columnspan=1) 145 175 146 176 #Exit … … 165 195 if (time.time()-filetime)<threshold_recent: 166 196 bgcolortxt='green' 197 fgcolortxt='black' 167 198 elif (time.time()-filetime)<threshold_old: 168 199 bgcolortxt='blue' 169 else: 170 bgcolortxt='red' 171 self.latestFileAcquired.config(text=os.path.basename(latest_file_acquired),bg=bgcolortxt) 200 fgcolortxt='white' 201 else: 202 bgcolortxt='red' 203 fgcolortxt='black' 204 self.latestFileAcquired.config(text=os.path.basename(latest_file_acquired),bg=bgcolortxt,fg=fgcolortxt) 172 205 173 206 list_of_files_processed = glob.glob(data_directory+"data_CLIO*.png") 174 207 #print(list_of_files_processed) 175 208 if (len(list_of_files_processed)>0): 176 latest_file_processed = max(list_of_files_processed, key=os.path.getctime) 209 #latest_file_processed = max(list_of_files_processed, key=os.path.getctime) 210 latest_file_processed = max(sorted(list_of_files_processed)) 177 211 filetime=os.path.getctime(latest_file_processed) 178 212 if (time.time()-filetime)<threshold_recent: 179 213 bgcolortxt='green' 214 fgcolortxt='black' 180 215 elif (time.time()-filetime)<threshold_old: 181 216 bgcolortxt='blue' 182 else: 183 bgcolortxt='red' 184 self.latestFileProcessed.config(text=os.path.basename(latest_file_processed),bg=bgcolortxt) 217 fgcolortxt='white' 218 else: 219 bgcolortxt='red' 220 fgcolortxt='black' 221 self.latestFileProcessed.config(text=os.path.basename(latest_file_processed),bg=bgcolortxt,fg=fgcolortxt) 185 222 imageNames[0]=latest_file_processed; 186 223 … … 189 226 #print(list_of_files_with_signal) 190 227 if (len(list_of_files_with_signal)>0): 191 latest_file_with_signal = max(list_of_files_with_signal, key=os.path.getctime) 228 #latest_file_with_signal = max(list_of_files_with_signal, key=os.path.getctime) 229 latest_file_with_signal = max(sorted(list_of_files_with_signal)) 192 230 filetime=os.path.getctime(latest_file_with_signal) 193 231 if (time.time()-filetime)<threshold_recent: 194 232 bgcolortxt='green' 233 fgcolortxt='black' 195 234 elif (time.time()-filetime)<threshold_old: 196 235 bgcolortxt='blue' 197 else: 198 bgcolortxt='red' 199 self.latestFileWithSignal.config(text=os.path.basename(latest_file_with_signal),bg=bgcolortxt) 200 201 imageNames[0]=latest_file_with_signal.replace(".sig","_zoom.png") 202 imageNames[1]=latest_file_with_signal.replace(".sig","_signal.png") 236 fgcolortxt='white' 237 else: 238 bgcolortxt='red' 239 fgcolortxt='black' 240 self.latestFileWithSignal.config(text=os.path.basename(latest_file_with_signal),bg=bgcolortxt,fg=fgcolortxt) 241 242 imageNames[0]=latest_file_with_signal.replace(".sig",".png") 243 imageNames[1]=latest_file_with_signal.replace(".sig","_zoom.png") 244 imageNames[2]=latest_file_with_signal.replace(".sig","_signal.png") 203 245 time.sleep(0.1) 204 try: 205 self.newImage2=ImageTk.PhotoImage(Image.open(imageNames[1]).resize(ImagesDisplaySize, Image.ANTIALIAS)) 206 except: 207 print("An error occurred while opening the image") 208 self.imageLabel2.configure(image=self.newImage2) 209 self.imageLabel2.image=self.newImage2 210 time.sleep(0.1) 211 try: 212 self.newImage1=ImageTk.PhotoImage(Image.open(imageNames[0]).resize(ImagesDisplaySize, Image.ANTIALIAS)) 213 except: 214 print("An error occurred while opening the image") 215 self.imageLabel1.configure(image=self.newImage1) 216 self.imageLabel1.image=self.newImage1 217 246 247 self.newImage=[] 248 for iimage in range(N_IMAGES): 249 try: 250 self.newImage.append(ImageTk.PhotoImage(Image.open(imageNames[iimage]).resize(ImagesDisplaySize, Image.ANTIALIAS))) 251 self.imageLabel[iimage].configure(image=self.newImage[iimage]) 252 self.imageLabel[iimage].image=self.newImage[iimage] 253 except: 254 print("An error occurred while opening the image: "+imageNames[iimage]+" image "+str(iimage)) 255 time.sleep(0.1) 256 257 218 258 self.getMotorPosition() 219 259 #Check acquisition status … … 221 261 pause_file = glob.glob(FILE_PAUSE) 222 262 if (len(stop_file)): 223 self.labelAcquisitionStatus.config(text="Stop",bg='red' )263 self.labelAcquisitionStatus.config(text="Stop",bg='red',fg='black') 224 264 self.buttonAcqPause.config(text="Program stopped!") 225 265 elif (len(pause_file)): 226 self.labelAcquisitionStatus.config(text="Pause", bg='blue' )266 self.labelAcquisitionStatus.config(text="Pause", bg='blue',fg='white') 227 267 self.buttonAcqPause.config(text="Restart") 228 268 else: 229 self.labelAcquisitionStatus.config(text="Enabled", bg='green' )269 self.labelAcquisitionStatus.config(text="Enabled", bg='green',fg='black') 230 270 231 271 #check remote processes … … 270 310 if (self.refresh_loop%PROCESSES_REFRESH_INTERVAL==4): 271 311 try: 272 response=subprocess.check_output("ps -edf | grep -v grep | grep -c process_recent_files",shell=True) 312 # response=subprocess.check_output("ps -edf | grep -v grep | grep -c process_recent_files",shell=True) 313 response=subprocess.check_output("ps -edf | grep -v grep | grep -c makefile_recent",shell=True) 273 314 except: 274 315 response='0' … … 283 324 self.after(500, self.update_clock) 284 325 285 286 326 if (self.refresh_loop%PROCESSES_REFRESH_INTERVAL==5): 327 response=os.system("ping -c 1 "+IP_POWER_IP) 328 if response==0: 329 self.labelProcessIPPower.config(bg='green') 330 else: 331 self.labelProcessIPPower.config(bg='red') 332 333 if (self.refresh_loop%PROCESSES_REFRESH_INTERVAL==6): 334 self.set_power_buttons_color() 335 336 if (self.refresh_loop%PROCESSES_REFRESH_INTERVAL==7): 337 fid=open(FILE_ACQ_INFO,'r') 338 fileline=fid.readline() 339 print fileline 340 key_values={} 341 while len(fileline)>0: 342 print fileline 343 entries=fileline.replace('\n','').split(' ') 344 key_values[entries[0]]=entries[1] 345 fileline=fid.readline() 346 fid.close() 347 if (key_values['RATE']): 348 rate_value=36000./float(key_values['RATE']) 349 self.labelAcquisitionRate.config(text='Rate= '+str(rate_value)+'kS/s',bg='white') 350 351 if (key_values['PAUSE']): 352 self.labelAcquisitionPause.config(text='Wait= '+key_values['PAUSE']+' ms',bg='white') 353 287 354 def getMotorPosition(self): 288 355 if (len(glob.glob(motor_position_info))>0): … … 291 358 key_values={} 292 359 while len(fileline)>0: 293 #print fileline360 print fileline 294 361 entries=fileline.replace('#','').replace(' ','').replace('\n','').split('=') 295 362 key_values[entries[0]]=entries[1] … … 298 365 if key_values['motor_value']: 299 366 self.labelPositionStep.config(text=key_values['motor_value']); 300 self.labelPositionStep.config(bg='green' );301 else: 302 self.labelPositionStep.config(bg='red' );367 self.labelPositionStep.config(bg='green',fg='black'); 368 else: 369 self.labelPositionStep.config(bg='red',fg='black'); 303 370 304 371 if key_values['current_value']: 305 372 self.labelPositionCurrent.config(text=key_values['current_value']); 306 self.labelPositionCurrent.config(bg='green' );307 else: 308 self.labelPositionCurrent.config(bg='red' );373 self.labelPositionCurrent.config(bg='green',fg='black'); 374 else: 375 self.labelPositionCurrent.config(bg='red',fg='black'); 309 376 else: 310 self.labelPositionCurrent.config(bg='blue'); 311 self.labelPositionStep.config(bg='blue'); 377 self.labelPositionCurrent.config(bg='blue',fg='white'); 378 self.labelPositionStep.config(bg='blue',fg='white'); 379 380 def set_power_buttons_color(self): 381 power_request=urllib2.urlopen(URI+'?CMD=GetPower') 382 values=power_request.read().replace('<html>','').replace('</html>\r\n','').replace('p6','').split(',') 383 # print repr(values) 384 for ipower in range(4): 385 print values[ipower].split('=')[1] 386 if (values[ipower].split('=')[1]=='1'): 387 self.buttonPower[ipower].config(bg='green') 388 else: 389 self.buttonPower[ipower].config(bg='cyan') 312 390 313 391 #---------------- … … 360 438 self.moveMotor(1,1000000) 361 439 440 def onButtonPower(self,value): 441 print('Power value='+str(value)) 442 print(repr(self.buttonPower[value].cget("bg"))) 443 power_state=0 444 if (self.buttonPower[value].cget("bg")=='green'): 445 power_state=1 446 self.buttonPower[value].config(bg='blue') 447 power_request=urllib2.urlopen(URI+'?CMD=SetPower+P6'+str(value+1)+'='+str(1-power_state)) 448 values=power_request.read().replace('<html>','').replace('</html>\r\n','').replace('p6','').split(',') 449 self.after(2000, self.set_power_buttons_color) 362 450 363 451 #---------------- -
CLIO/control/clio_constants.py
r691 r744 48 48 motor_position_request=basedir+'acquisition_data/motor_requested_position.txt'; 49 49 data_directory_base="/var/www/html/CLIO/" 50 FILE_ACQ_INFO=basedir+'acquisition_data/acquisition_info.txt' 50 51 # data_dir="/home/etalon-admin/acquisition_data" 51 52 … … 68 69 69 70 70 # Scope IPs71 SCOPE1_IP='129.175.202.193'72 SCOPE2_IP='129.175.202.14'71 ##Scope IPs 72 #SCOPE1_IP='129.175.202.193' 73 #SCOPE2_IP='129.175.202.14' 73 74 74 motor_controller_IP='129.175.202.187' 75 IP_POWER_IP='10.20.60.10' 76 77 motor_controller_IP='10.20.60.7' 75 78 motor_controller_port=30000 76 79 -
CLIO/control/initialise_motors.py
r691 r744 44 44 value=isign*float(result[3:12]) 45 45 valueOK=1 46 except: 47 print 'Result with error '+result 46 except: 47 print 'Result with error '+result+'; message was ' +message 48 48 valueOK=0 49 49 result='' … … 268 268 "Sends ca_va query to the motor and display reply" 269 269 # write_to_motor("ça_va?",1) 270 ret=write_to_motor("ca_va?", 0)270 ret=write_to_motor("ca_va?", 1) 271 271 print "controller returned: ",ret 272 272 return ret -
CLIO/control/makefile
r691 r744 1 1 DATAFILES=$(wildcard data_CLIO_*.txt) 2 2 3 all: all_png 3 .PHONY: all all_done clean_done 4 4 5 all_gz: $(DATAFILES:.txt=.gz) 6 all_png: $(DATAFILES:.txt=.png) 5 all: all_done clean_done 7 6 8 %.png: %.txt 7 all_done: $(DATAFILES:.txt=.done) 8 9 %.done: %.txt 9 10 touch ~/acquisition_data/makefile_runing.date 10 python ~/control/run_read_data.py $? 11 echo $? 12 mv $? ../processed/ 13 cd ../processed && python ~/control/run_read_data.py $? 14 cd ../processed && ls -lart | tail -8 15 pwd 16 ls -lart | tail -5 11 17 12 13 %.gz: %.png 14 gzip -9 $*.txt 15 18 clean_done: 19 rm -f *.done ../processed/*.done -
CLIO/control/motor_go_in_and_out_wait_for_data_narrow_scan.py
r691 r744 7 7 global data_directory 8 8 9 WAIT_FOR_N_DATA_TAKEN= 19 WAIT_FOR_N_DATA_TAKEN=5 10 10 11 11 filedata=data_directory+'position_calibration.txt' … … 14 14 15 15 position_list=[4200000, 4500000] 16 position_list.extend(range( 5000000,6000000,100000))16 position_list.extend(range(4800000,5700000,100000)) 17 17 position_list.append(4000000) 18 18 print repr(position_list) -
CLIO/control/motor_go_in_and_out_wait_for_data_wide_scan.py
r691 r744 7 7 global data_directory 8 8 9 WAIT_FOR_N_DATA_TAKEN= 39 WAIT_FOR_N_DATA_TAKEN=5 10 10 11 11 filedata=data_directory+'position_calibration.txt' … … 14 14 15 15 #position_list=range(0,5000000,2500000) 16 position_list=range(0000000, 6000000,500000)17 position_list.extend(range( 6000000,0000000,-200000))16 position_list=range(0000000,5500000,500000) 17 position_list.extend(range(5600000,0000000,-200000)) 18 18 position_list.append(0) 19 19 print repr(position_list) -
CLIO/control/read_plot_data.py
r691 r744 1 <<<<<<< .mine2 1 # -*- coding: utf-8 -*- 3 2 """ … … 11 10 import matplotlib.pyplot as plt 12 11 #from time import sleep 13 from shutil import copyfile 12 from shutil import copyfile,move 14 13 import os.path 15 14 from scipy.fftpack import fft, ifft 15 from scipy import signal 16 16 17 17 def read_plot_data(filename): … … 21 21 #electron_signal 22 22 electrons_channel=26 23 electrons_signal_scaling=0.05 24 electrons_threshold=-50 23 electrons_signal_scaling=0.02 24 electrons_threshold=-1000 25 electrons_threshold_peak=200. 25 26 electrons_half_width=1 26 27 27 28 data_start=1 28 data_length= 703529 data_length=8000 29 30 electron_pretrig=5 30 31 # electron_trig_stop=500 … … 39 40 #channels_mapping=[17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27] 40 41 data_mapping=[ 0, 111, 83, 76, 48, 41 55, 104, 69, 62,0,42 97, 90, 0, 118,0,43 0, 125, 0, 0,0,44 0, 0, 0, 0,0,45 0, 0, 0, 0,0,42 55, 104, 69, 62, 0, 43 97, 90, 0, 118, 0, 44 0, 125, 0, 0, 0, 45 0, 0, 0, 0, 0, 46 0, 0, 0, 0, 0, 46 47 0, 0 ] 47 48 48 49 #code 49 50 fft_depth=150#lower value -- lower number of freq. 51 52 #figure_size (in inches, that is 100*pixels with dpi=100) 53 figure_size=(8, 6) 54 figure_dpi=100 55 56 #sort the angles and find corresponding channels 50 57 angles_sorted=[] 51 58 idx_angles_sorted=[] … … 61 68 idx_angles_sorted.append(data_mapping.index(angle)) 62 69 idx_data_mapping[data_mapping.index(angle)]=int(len(angles_sorted)) 63 64 key_values={} 70 #Check if the filename contains the path or not 65 71 if (len(os.path.dirname(filename))==0): 66 72 filename="./"+filename 67 73 dayname=os.path.basename(filename).replace("-","").split("_")[2] 74 target_directory=os.path.dirname(filename)+"/../"+dayname+"/" 75 target_filename=target_directory+os.path.basename(filename) 76 77 #read parameters 78 key_values={} 68 79 with open(filename,'r') as fid: 69 80 fileline=fid.readline() … … 74 85 fid.close() 75 86 76 print(key_values)77 87 for p in key_values: print p,'=', key_values[p] 88 #read data 78 89 alldata=np.loadtxt(filename, dtype='int32', comments='#', delimiter=' ', usecols=range(0,nchannels), converters={ _:lambda s: int(s , 16) for _ in range(0,nchannels) }) 79 90 80 91 #converting the data in the correct format 81 alldata=alldata%(2**16) 82 alldata=(2**15)-alldata 83 data_scaling_factor=(float(key_values['amplitude'])*5.)/(2.**15) 84 time_scaling_factor=(36./float(key_values['acquisition_rate']))*1.e-3 85 86 #Looking for electrons 92 alldata=alldata%(2**16)-2**15; 93 94 #Scaling 95 #data_scaling_factor=(float(key_values['amplitude'])*5.)/(2.**15) 96 data_scaling_factor=1; 97 time_scaling_factor=(float(key_values['acquisition_rate'])/36.)*1.e-3 98 99 #remove constant components from electron signal 100 FFT_spectrum=fft(alldata[1:data_length,electrons_channel]); 101 Amplitude=abs(FFT_spectrum); 102 Amplitude[0]=0;#remove constant component 103 alldata[1:data_length,electrons_channel]=np.real(ifft(Amplitude*np.exp(1j*np.angle(FFT_spectrum)))); 104 105 106 #look for the electrons 107 elec=alldata[1:data_length,electrons_channel] 108 pos_elec=[]; 109 Elec_sig_val_arr=[]; 110 step=round(data_length/(2*(data_length*time_scaling_factor/40.)))#40 ms repetition rate 111 for c in range(1,int(round(data_length/step)+1)): 112 llim=int((c-1)*step); 113 hlim=int(step*c); 114 if hlim>data_length: 115 hlim=int(data_length) 116 if (max(elec[llim:hlim])>electrons_threshold_peak): 117 pos_elec.append(llim+np.argmax(elec[llim:hlim])) 118 Elec_sig_val_arr.append(min(elec[llim:hlim])); 119 #print Elec_sig_val_arr 120 87 121 electrons_found=False 88 if (min(alldata[:,electrons_channel])<electrons_threshold): 89 elec=alldata[:,electrons_channel] 90 pos_elec=elec.argmin() 91 while ((pos_elec>100)and(elec[pos_elec]<electrons_threshold)): 92 pos_elec=pos_elec-1 93 if ((elec[pos_elec+electrons_half_width]<electrons_threshold)or(elec[pos_elec-electrons_half_width]<electrons_threshold)): 94 electrons_found=True 95 electron_data_start=pos_elec-electron_pretrig 96 electron_data_stop=pos_elec+electron_trig_stop 97 print('electrons found') 98 99 #Mean position value 100 # mean_position=np.mean(alldata[:,electrons_channel]) 101 # print('Mean position: ', mean_position) 102 # filename_position=filename.replace('.txt','.pos') 103 # fid=open(filename_position,'w') 104 # fid.write("pos: "+str(round(mean_position,3))) 105 # fid.close() 106 107 122 123 # fft filtering 124 for c in range(0,11): 125 FFT_spectrum=fft(alldata[1:data_length,idx_angles_sorted[c]]); 126 Phase=np.angle(FFT_spectrum); 127 Amplitude=abs(FFT_spectrum); 128 Amplitude[(1+fft_depth):(data_length-fft_depth)]=0; 129 Amplitude[0]=0;#remove constant component 130 Signal=ifft(Amplitude*np.exp(1j*Phase)); 131 alldata[1:data_length,idx_angles_sorted[c]]=np.real(Signal); 132 133 #Find the amplitude of the signal 134 Sig = [0 for x in range(len(pos_elec))] 135 Sig_mean=[0 for x in range(12)] 136 Sig_std=[0 for x in range(12)] 137 Elec_sig_val=0; 138 Elec_sig_val_err=0; 139 if (len(pos_elec)>0.): 140 electrons_found=True 141 if (pos_elec[0]-50)>0: 142 electron_data_start=pos_elec[0]-50 143 else: 144 electron_data_start=0 145 if (pos_elec[0]+50)<data_length: 146 electron_data_stop=pos_elec[0]+50 147 else: 148 electron_data_stop=(data_length-1) 149 Elec_sig_val=np.mean(Elec_sig_val_arr); 150 Elec_sig_val_err=np.std(Elec_sig_val_arr); 151 print 'electrons found:', Elec_sig_val,'+/-', Elec_sig_val_err 152 # Signal amplitude 153 for c in range(0,12): 154 for k in range(0,len(pos_elec)): 155 Sig[k]=alldata[(pos_elec[k]+14),idx_angles_sorted[c]]-alldata[(pos_elec[k]-14),idx_angles_sorted[c]] 156 Sig_mean[c]=-np.mean(Sig)#mean of signal in one file 157 Sig_std[c]=np.std(Sig)#std in one file 158 159 move(filename,target_filename) 160 161 #print Sig_mean, Sig_std 162 163 108 164 #prepare the figures 109 fig=plt.figure(1,figsize= (12, 8))165 fig=plt.figure(1,figsize=figure_size,dpi=figure_dpi) 110 166 if electrons_found: 111 figzoom=plt.figure(2,figsize=(12, 8)) 112 figsignal=plt.figure(3,figsize=(12, 8)) 113 datasignal=np.zeros(len(angles_sorted)) 114 filename_zoom_txt=filename.replace('.txt','.zoom_txt') 115 fidz=open(filename_zoom_txt,'w') 116 for jdata in range(electron_data_start,electron_data_stop): 117 fidz.write(str(jdata*time_scaling_factor)) 118 fidz.write(" ") 119 fidz.write("\n") 120 167 figzoom=plt.figure(2,figsize=figure_size,dpi=figure_dpi) 168 figsignal=plt.figure(3,figsize=figure_size,dpi=figure_dpi) 169 170 #set channels to plot 171 plotch=data_mapping; 172 plotch[electrons_channel]=1; 173 plotch[16]=0; 174 # plotch[electrons_channel+1]=1001; 121 175 122 176 for idata in range(0,nchannels-1): 123 this_data_scaling_factor=data_scaling_factor*-1 177 178 this_data_scaling_factor=data_scaling_factor 124 179 txtline='r' 125 if idata%12==0: 126 txtline='b' 127 if data_mapping[idata] >0: 180 linestyle='-'; 181 if data_mapping[idata] >0: 128 182 txtline='r' 129 else: 130 txtline='b' 131 132 linestyle='-' 133 if idata==electrons_channel: 134 txtline='k' 135 this_data_scaling_factor=this_data_scaling_factor*electrons_signal_scaling 136 137 if ((idata!=position_channel)and(idata!=22)and(idata!=21)): 138 # data_start=9022 139 # data_length=9035 183 if data_mapping[idata] >1000: 184 txtline='b' 185 186 if idata==electrons_channel: 187 txtline='k' 188 this_data_scaling_factor=this_data_scaling_factor*electrons_signal_scaling 140 189 plt.figure(1) 141 plt.plot(np.arange(data_start,data_length)*time_scaling_factor,alldata[range(data_start,data_length),idata].astype(np.float)*this_data_scaling_factor, txtline+linestyle) 142 # plt.show() 143 190 plt.plot(np.arange(data_start,data_length)*time_scaling_factor,alldata[range(data_start,data_length),idata]*this_data_scaling_factor, txtline+linestyle) 144 191 if (electrons_found): 145 plt.figure(2) 146 this_channel_baseline=0 147 baseline_offset=100 148 baseline_length=100 149 if (pos_elec>1000): 150 this_channel_baseline=np.mean(alldata[range(electron_data_start-baseline_offset-baseline_length,electron_data_stop-baseline_offset),idata]) 151 this_channel_baseline_rms=np.std(alldata[range(electron_data_start-baseline_offset-baseline_length,electron_data_stop-baseline_offset),idata])*-1 152 else: 153 this_channel_baseline=np.mean(alldata[range(electron_data_start+baseline_offset,electron_data_stop+baseline_offset+baseline_length),idata]) 154 this_channel_baseline_rms=np.sqrt(np.std(alldata[range(electron_data_start+baseline_offset,electron_data_stop+baseline_offset+baseline_length),idata]))*-1 155 156 plt.plot(np.arange(electron_data_start,electron_data_stop)*time_scaling_factor,(alldata[range(electron_data_start,electron_data_stop),idata].astype(np.float)-this_channel_baseline)*this_data_scaling_factor, txtline+linestyle) 157 plt.plot(np.arange(electron_data_start,electron_data_stop)*time_scaling_factor,np.zeros(len(range(electron_data_start,electron_data_stop)))+(this_channel_baseline_rms*this_data_scaling_factor), txtline+":") 158 for jdata in range(electron_data_start,electron_data_stop): 159 fidz.write('{:06.5e}'.format((alldata[jdata,idata].astype(np.float)-this_channel_baseline)*this_data_scaling_factor)) 160 fidz.write(" ") 161 fidz.write("\n") 162 163 if data_mapping[idata]>0: 164 plt.figure(3) 165 txtline=txtline+'^' 166 # datasignal[idx_data_mapping[idata]-1]=np.mean(alldata[range(pos_elec+electron_post_trig_integration_start,pos_elec+electron_post_trig_integration_stop),idata].astype(np.float)-this_channel_baseline)*this_data_scaling_factor 167 datasignal[idx_data_mapping[idata]-1]=np.mean(alldata[range(pos_elec+electron_post_trig_integration_start,pos_elec+electron_post_trig_integration_stop),idata].astype(np.float)-this_channel_baseline)*this_data_scaling_factor 168 plt.plot(data_mapping[idata], -1*datasignal[idx_data_mapping[idata]-1], txtline+linestyle) 192 plt.figure(2) 193 plt.plot(np.arange(electron_data_start,electron_data_stop)*time_scaling_factor, (alldata[range(electron_data_start,electron_data_stop),idata]-alldata[(pos_elec[0]-14),idata])*this_data_scaling_factor, txtline+linestyle) 194 169 195 170 196 plt.figure(1) 171 197 plt.title(key_values['date']+ ' --- Motor value: '+key_values['motor_value']+ ' --- Current: '+key_values['current_value']) 172 plt.ylabel('Signal amplitude [ V]')198 plt.ylabel('Signal amplitude [a.u.]') 173 199 plt.xlabel('Time [ms]') 174 200 plt.grid(True) 175 imagename= filename.replace('.txt','.png')201 imagename=target_filename.replace('.txt','.png') 176 202 print(imagename) 177 203 fig.savefig(imagename) 178 204 plt.close(fig) 179 205 imagename_no_path=os.path.basename(imagename) 180 fid=open('list.html','a'); 206 207 208 fid=open(target_directory+'list.html','a'); 181 209 fid.write("<A HREF=") 182 210 fid.write(imagename_no_path) … … 191 219 192 220 if (electrons_found): 193 fidz.close()194 221 plt.figure(2) 195 222 plt.title(key_values['date']+ ' --- Motor value: '+key_values['motor_value']+ ' --- Current: '+key_values['current_value']) 196 plt.ylabel('Signal amplitude [ V] - pedestal removed')223 plt.ylabel('Signal amplitude [a.u] - pedestal removed') 197 224 plt.xlabel('Time [ms]') 198 225 plt.grid(True) 199 imagenamezoom= filename.replace('.txt','_zoom.png')226 imagenamezoom=target_filename.replace('.txt','_zoom.png') 200 227 figzoom.savefig(imagenamezoom) 201 228 plt.close(figzoom) … … 215 242 216 243 plt.figure(3) 217 plt.plot( angles_sorted,-1*datasignal,'b--')244 plt.plot(range(48,132,7), Sig_mean,'r^-') 218 245 plt.title(key_values['date']+ ' --- Motor value: '+key_values['motor_value']+ ' --- Current: '+key_values['current_value']) 219 plt.ylabel('Signal amplitude [ V]')220 plt.xlabel('Detector angle (degree)')246 plt.ylabel('Signal amplitude [a.u.]') 247 plt.xlabel('Detector angle [deg.]') 221 248 plt.grid(True) 222 imagenamesignal= filename.replace('.txt','_signal.png')249 imagenamesignal=target_filename.replace('.txt','_signal.png') 223 250 figsignal.savefig(imagenamesignal) 224 251 plt.close(figsignal) 225 252 copyfile(imagenamesignal,os.path.dirname(imagename)+'/last_signal.png') 226 253 227 228 filenamesig=filename.replace('.txt','.sig')229 fid=open(filenamesig,'w');230 for idata in range(0,len(datasignal)):231 fid.write(str(angles_sorted[idata])+" "+str(datasignal[idata])+"\n")232 fid.write("\n")233 fid.close()234 235 filenameval=filename.replace('.txt','.val')236 fid=open(filenameval,'w');237 for key in key_values:238 fid.write(key+" = "+key_values[key]+" \n");239 fid.close()240 241 254 imagenamesignal_no_path=os.path.basename(imagenamesignal) 242 255 fid=open('signal_list.html','a'); … … 251 264 fid.close() 252 265 266 filenamesig=target_filename.replace('.txt','.sig') 267 fid=open(filenamesig,'w'); 268 for key in key_values: 269 fid.write("#" +key+" = "+key_values[key]+" \n"); 270 fid.write("#electronsig = "+ str(Elec_sig_val)+" \n"); 271 fid.write("#electronstd = "+ str(Elec_sig_val_err)+" \n"); 272 for idata in range(0,len(Sig_mean)): 273 fid.write(str(angles_sorted[idata])+"\t"+str(Sig_mean[idata])+"\t"+str(Sig_std[idata])+"\n") 274 fid.write("\n") 275 fid.close() 276 277 filenamedone=filename.replace('.txt','.done') 278 fid=open(filenamedone,'a'); 279 fid.write("done") 280 fid.close() 281 253 282 return; 254 283 255 256 #read_plot_data('/Users/delerue/Downloads/CLIO/data_CLIO_2017-02-08_17-26-53.txt')257 #read_plot_data('/Users/delerue/Downloads/CLIO_tmp/20170227/data_CLIO_2017-02-27_12-01-14.txt')258 #read_plot_data('/Users/delerue/Downloads/CLIO_tmp/20170227/data_CLIO_2017-02-27_12-43-46.txt')259 #HWaddr 64:00:6a:3a:6f:1c260 ||||||| .r0261 =======262 # -*- coding: utf-8 -*-263 """264 Created on Mon Feb 6 15:47:25 2017265 266 @author: delerue267 """268 269 270 import numpy as np271 import matplotlib.pyplot as plt272 #from time import sleep273 from shutil import copyfile274 import os.path275 276 277 def read_plot_data(filename):278 #Definitions279 nchannels=32280 281 #electron_signal282 electrons_channel=30283 electrons_signal_scaling=0.05284 electrons_threshold=-5000285 electrons_half_width=5286 287 data_start=1288 data_length=9035289 electron_pretrig=5290 # electron_trig_stop=500291 electron_trig_stop=20292 electron_post_trig_integration_start=1293 electron_post_trig_integration_stop=5294 295 #position signal296 position_channel=28297 298 #channels mapping299 #channels_mapping=[17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27]300 data_mapping=[ 0, 0, 0, 0, 0,301 0, 0, 0, 0, 0,302 0, 0, 0, 0, 0,303 30, 40, 50, 60, 70,304 80, 90, 100, 110, 120,305 130, 140, 0, 0, 0,306 0, 0 ]307 308 309 #code310 key_values={}311 if (len(os.path.dirname(filename))==0):312 filename="./"+filename313 314 with open(filename,'r') as fid:315 fileline=fid.readline()316 while fileline[0]=='#':317 entries=fileline.replace('#','').replace(' ','').replace('\n','').split('=')318 key_values[entries[0]]=entries[1]319 fileline=fid.readline()320 fid.close()321 322 print(key_values)323 324 alldata=np.loadtxt(filename, dtype='int32', comments='#', delimiter=' ', usecols=range(0,nchannels), converters={ _:lambda s: int(s , 16) for _ in range(0,nchannels) })325 326 #converting the data in the correct format327 alldata=alldata%(2**16)328 alldata=(2**15)-alldata329 data_scaling_factor=(float(key_values['amplitude'])*5.)/(2.**15)330 time_scaling_factor=(36./float(key_values['acquisition_rate']))*1.e-3331 332 #Looking for electrons333 electrons_found=False334 if (min(alldata[:,electrons_channel])<electrons_threshold):335 elec=alldata[:,electrons_channel]336 pos_elec=elec.argmin()337 while ((pos_elec>100)and(elec[pos_elec]<electrons_threshold)):338 pos_elec=pos_elec-1339 if ((elec[pos_elec+electrons_half_width]<electrons_threshold)or(elec[pos_elec-electrons_half_width]<electrons_threshold)):340 electrons_found=True341 electron_data_start=pos_elec-electron_pretrig342 electron_data_stop=pos_elec+electron_trig_stop343 print('electrons found')344 print elec[pos_elec]345 print pos_elec346 347 348 349 #Mean position value350 mean_position=np.mean(alldata[:,electrons_channel])351 print('Mean position: ', mean_position)352 filename_position=filename.replace('.txt','.pos')353 fid=open(filename_position,'w')354 fid.write("pos: "+str(round(mean_position,3)))355 fid.close()356 357 358 #prepare the figures359 fig=plt.figure(1,figsize=(12, 8))360 if electrons_found:361 figzoom=plt.figure(2,figsize=(12, 8))362 figsignal=plt.figure(3,figsize=(12, 8))363 datasignal=np.zeros(11)364 filename_zoom_txt=filename.replace('.txt','.zoom_txt')365 fidz=open(filename_zoom_txt,'w')366 for jdata in range(electron_data_start,electron_data_stop):367 fidz.write(str(jdata*time_scaling_factor))368 fidz.write(" ")369 fidz.write("\n")370 371 372 for idata in range(17,nchannels):373 this_data_scaling_factor=data_scaling_factor*-1374 txtline='r'375 if idata%6==0:376 txtline='b'377 if idata%6==1:378 txtline='g'379 if idata%6==2:380 txtline='k'381 if idata%6==3:382 txtline='c'383 if idata%6==4:384 txtline='m'385 if idata%6==5:386 txtline='y'387 if idata==17:388 txtline='r'389 if idata==20:390 txtline='r'391 if idata==22:392 txtline='r'393 if idata==30:394 txtline='bs'395 linestyle='-'396 if idata==electrons_channel:397 this_data_scaling_factor=this_data_scaling_factor*electrons_signal_scaling398 399 if ((idata!=position_channel)):400 # data_start=9022401 # data_length=9035402 plt.figure(1)403 plt.plot(np.arange(data_start,data_length)*time_scaling_factor,alldata[range(data_start,data_length),idata].astype(np.float)*this_data_scaling_factor, txtline+linestyle)404 # plt.show()405 406 if (electrons_found):407 plt.figure(2)408 this_channel_baseline=0409 baseline_offset=100410 baseline_length=100411 if (pos_elec>1000):412 this_channel_baseline=np.mean(alldata[range(electron_data_start-baseline_offset-baseline_length,electron_data_stop-baseline_offset),idata])413 this_channel_baseline_rms=np.std(alldata[range(electron_data_start-baseline_offset-baseline_length,electron_data_stop-baseline_offset),idata])*-1414 else:415 this_channel_baseline=np.mean(alldata[range(electron_data_start+baseline_offset,electron_data_stop+baseline_offset+baseline_length),idata])416 this_channel_baseline_rms=np.sqrt(np.std(alldata[range(electron_data_start+baseline_offset,electron_data_stop+baseline_offset+baseline_length),idata]))*-1417 418 plt.plot(np.arange(electron_data_start,electron_data_stop)*time_scaling_factor,(alldata[range(electron_data_start,electron_data_stop),idata].astype(np.float)-this_channel_baseline)*this_data_scaling_factor, txtline+linestyle)419 plt.plot(np.arange(electron_data_start,electron_data_stop)*time_scaling_factor,np.zeros(len(range(electron_data_start,electron_data_stop)))+(this_channel_baseline_rms*this_data_scaling_factor), txtline+":")420 for jdata in range(electron_data_start,electron_data_stop):421 fidz.write('{:06.5e}'.format((alldata[jdata,idata].astype(np.float)-this_channel_baseline)*this_data_scaling_factor))422 fidz.write(" ")423 fidz.write("\n")424 425 if data_mapping[idata]>0:426 plt.figure(3)427 txtline=txtline+'^'428 datasignal[(data_mapping[idata]/10)-4]=np.mean(alldata[range(pos_elec+electron_post_trig_integration_start,pos_elec+electron_post_trig_integration_stop),idata].astype(np.float)-this_channel_baseline)*this_data_scaling_factor429 plt.plot(data_mapping[idata], datasignal[(data_mapping[idata]/10)-4], txtline+linestyle)430 431 plt.figure(1)432 plt.title(key_values['date']+ ' --- Position: '+str(round(mean_position,2)))433 plt.ylabel('Signal amplitude [V]')434 plt.xlabel('Time [ms]')435 plt.grid(True)436 imagename=filename.replace('.txt','.png')437 print(imagename)438 fig.savefig(imagename)439 plt.close(fig)440 imagename_no_path=os.path.basename(imagename)441 fid=open('list.html','a');442 fid.write("<A HREF=")443 fid.write(imagename_no_path)444 fid.write("><IMG SRC=")445 fid.write(imagename_no_path)446 fid.write(" width=600>")447 fid.write("</A><BR/>")448 fid.write(imagename_no_path)449 fid.write("<BR/><BR/>\n")450 fid.close()451 copyfile(imagename,os.path.dirname(imagename)+'/last.png')452 453 if (electrons_found):454 fidz.close()455 plt.figure(2)456 plt.title(key_values['date']+ ' --- Position: '+str(round(mean_position,2)))457 plt.ylabel('Signal amplitude [V] - pedestal removed')458 plt.xlabel('Time [ms]')459 plt.grid(True)460 imagenamezoom=filename.replace('.txt','_zoom.png')461 figzoom.savefig(imagenamezoom)462 plt.close(figzoom)463 copyfile(imagenamezoom,os.path.dirname(imagename)+'/last_zoom.png')464 465 imagenamezoom_no_path=os.path.basename(imagenamezoom)466 fid=open('zoom_list.html','a');467 fid.write("<A HREF=")468 fid.write(imagenamezoom_no_path)469 fid.write("><IMG SRC=")470 fid.write(imagenamezoom_no_path)471 fid.write(" width=600>")472 fid.write("</A><BR/>")473 fid.write(imagenamezoom_no_path)474 fid.write("<BR/><BR/>\n")475 fid.close()476 477 plt.figure(3)478 plt.plot(range(40,150,10),datasignal,'b--')479 plt.title(key_values['date']+ ' --- Position: '+str(round(mean_position,2)))480 plt.ylabel('Signal amplitude [V]')481 plt.xlabel('Detector angle (degree)')482 plt.grid(True)483 imagenamesignal=filename.replace('.txt','_signal.png')484 figsignal.savefig(imagenamesignal)485 plt.close(figsignal)486 copyfile(imagenamesignal,os.path.dirname(imagename)+'/last_signal.png')487 488 filenamesig=filename.replace('.txt','.sig')489 fid=open(filenamesig,'w');490 fid.write(str(datasignal))491 fid.close()492 493 imagenamesignal_no_path=os.path.basename(imagenamesignal)494 fid=open('signal_list.html','a');495 fid.write("<A HREF=")496 fid.write(imagenamesignal_no_path)497 fid.write("><IMG SRC=")498 fid.write(imagenamesignal_no_path)499 fid.write(" width=600>")500 fid.write("</A><BR/>")501 fid.write(imagenamesignal_no_path)502 fid.write("<BR/><BR/>\n")503 fid.close()504 505 return;506 507 508 #read_plot_data('/Users/delerue/Downloads/CLIO/data_CLIO_2017-02-08_17-26-53.txt')509 #read_plot_data('/Users/delerue/Downloads/CLIO_tmp/20170227/data_CLIO_2017-02-27_12-01-14.txt')510 #read_plot_data('/Users/delerue/Downloads/CLIO_tmp/20170227/data_CLIO_2017-02-27_12-43-46.txt')511 #HWaddr 64:00:6a:3a:6f:1c512 >>>>>>> .r690 -
CLIO/control/run_acq.sh
r639 r744 4 4 5 5 #create directory for today 6 cd /var/www/html/CLIO/ 7 mkdir `date +%Y%m%d`8 cd `date +%Y%m%d`6 cd /var/www/html/CLIO/new 7 #mkdir `date +%Y%m%d` 8 #cd `date +%Y%m%d` 9 9 #check that acquisition is running 10 10 rm /home/etalon-admin/acquisition_data/stop_acquisition -
CLIO/control/run_all.sh
r638 r744 16 16 fi 17 17 18 if [ -eq `ps -edf | grep motor_monitor | grep -cv grep ` 0 ]; 19 echo "To start the motors monitor type cd control ; python motor_monitor.py " 20 exit -1 21 fi 22 23 24 if [ -eq `ps -edf | grep run_makefile_recent | grep -cv grep ` 0 ]; 25 echo "To start the files process type /home/etalon-admin/control/run_makefile_recent.sh " 26 exit -1 27 fi 28 29 30 18 31 #launch makefile 19 32 # run_makefile -
CLIO/control/run_makefile.sh
r638 r744 1 1 #!/bin/bash 2 2 3 4 5 #create directory for today 6 cd /var/www/html/CLIO/ 7 mkdir `date +%Y%m%d` 8 cd `date +%Y%m%d` 9 10 while true; do 11 make -f /home/etalon-admin/control/makefile; 12 sleep 5 13 done 3 ./run_makefile_recent.sh
Note: See TracChangeset
for help on using the changeset viewer.