Changeset 471
- Timestamp:
- Jan 30, 2009 2:39:07 AM (14 years ago)
- Location:
- sans/utils/bt5/bt5plot2
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sans/utils/bt5/bt5plot2/bt5plot2
r470 r471 1 #!/usr/bin/env python 1 #!/usr/bin/env python 2 2 3 3 import sys … … 13 13 14 14 import usans 15 from BT5DataSet import BT5DataSet 15 16 16 17 try: … … 26 27 except: 27 28 sys.exit(1) 28 29 30 29 31 30 class appGui: … … 59 58 self.filelistview = self.wTree.get_widget("tv_filelist") 60 59 61 self.filelist = gtk.ListStore(str, 'gboolean', object , object, object)60 self.filelist = gtk.ListStore(str, 'gboolean', object) 62 61 self.filelist.set_sort_column_id(0, gtk.SORT_ASCENDING) 63 62 … … 78 77 79 78 #fill the file list 80 self.FillFileList( self.GetBT5DirList())79 self.FillFileList(usans.GetBT5DirList()) 81 80 82 81 # Set up graphing widget to display xpeek data … … 99 98 self.metadataView = self.wTree.get_widget("tv_metadata") 100 99 self.mdlist = gtk.ListStore(str,str) 101 102 103 #self.filelistview.enable_model_drag_source( gtk.gdk.BUTTON1_MASK,104 # self.TARGETS,105 # gtk.gdk.ACTION_COPY)106 107 #self.filelistview.connect("drag_data_get", self.dnd_data_getdata)108 100 109 101 … … 122 114 return 123 115 124 def GetBT5DirList(self):125 """Function to parse the directory listing of the current working directory126 and create a list of filenames that are BT5 data files"""127 128 dirlist = os.listdir(os.getcwd())129 130 bt5list = [ x for x in dirlist if (x.find('.bt5') > 0 and usans.isBT5Data(x))]131 132 return bt5list133 134 116 135 117 def FillFileList(self, filenames): 136 118 self.filelist.clear() 137 119 for filename in filenames: 138 self.filelist.append([filename, 0, 0, 0, 0])120 self.filelist.append([filename, 0, None]) 139 121 return 140 122 … … 148 130 149 131 for filename in filenames: 150 self.filelist.append([filename, 0, 0, 0, 0])132 self.filelist.append([filename, 0, None]) 151 133 152 134 deletelist.reverse() 153 135 for path in deletelist: 154 136 treestore.remove(treestore.get_iter(path)) 155 #print len(filenames)156 137 return 157 138 … … 169 150 def handle_refreshlist(self,widget): 170 151 171 self.RefreshFileList( self.GetBT5DirList())152 self.RefreshFileList(usans.GetBT5DirList()) 172 153 173 154 return … … 187 168 def handle_filter(self,widget): 188 169 189 print "Filtering"190 170 del self.filter_string[:] 191 171 self.filter_string.append(self.filter_entry.get_text()) 192 print self.filter_string[0]172 #print self.filter_string[0] 193 173 self.filelistfilter.refilter() 194 174 … … 209 189 if response == gtk.RESPONSE_OK: 210 190 os.chdir(chooser.get_filename()) 211 self.FillFileList( self.GetBT5DirList())191 self.FillFileList(usans.GetBT5DirList()) 212 192 chooser.destroy() 213 193 … … 219 199 if model[path][1]: 220 200 #load data 221 data,metadata = usans.getBT5DataFromFile(model[path][0]) 222 model[path][2] = (data,metadata) 201 model[path][2] = BT5DataSet(model[path][0]) 223 202 #add plot 224 self.add_plot(model, path) 203 model[path][2].plot_dataset(self.axis,self.plottype) 204 self.rescale_and_redraw() 225 205 else: 226 206 #remove plot 227 self.remove_plot(model, path) 228 return 229 230 def add_plot(self, model, path): 231 232 self.make_plottable_dataset(model, path, self.plottype) 233 234 if self.plottype == 'split': 235 model[path][4] = self.axis.plot(model[path][3][0],model[path][3][1], 'o', 236 model[path][3][0],model[path][3][2], 'o', 237 model[path][3][0],model[path][3][3], 'o', 238 model[path][3][0],model[path][3][4], 'o', 239 model[path][3][0],model[path][3][5], 'o') 240 else: 241 model[path][4] = self.axis.plot(model[path][3][0],model[path][3][1], 'bo', picker=5) 242 243 self.rescale_and_redraw() 244 #self.canvas.draw() 245 return 246 247 def make_plottable_dataset(self, model, path, type): 248 249 data,metadata = model[path][2] 250 251 if type == 'total': 252 #generate totals 253 xdata = [] 254 ydata = [] 255 256 mvals = data.keys() 257 mvals.sort(usans.numeric_compare) 258 for mval in mvals: 259 xdata.append(mval) 260 ydata.append(data[mval][1] + data[mval][2] + data[mval][4] + data[mval][5] + data[mval][6]) 261 262 model[path][3] = [xdata, ydata] 263 264 elif type == 'rate': 265 # generate countrate 266 xdata = [] 267 ydata = [] 268 269 mvals = data.keys() 270 mvals.sort(usans.numeric_compare) 271 for mval in mvals: 272 xdata.append(mval) 273 274 if metadata['base'] == 'TIME': 275 #Counting in TIME base, so normalize by seconds 276 cnttime = metadata['mon'] 277 for mval in mvals: 278 ydata.append((data[mval][1] + data[mval][2] + data[mval][4] + data[mval][5] + data[mval][6])/cnttime) 279 else: 280 #Must be counting in monitor base so normalize by monitor 281 moncts = metadata['mon'] 282 for mval in mvals: 283 ydata.append((data[mval][1] + data[mval][2] + data[mval][4] + data[mval][5] + data[mval][6])/cnttime) 284 285 model[path][3] = [xdata, ydata] 286 287 elif type == 'trans': 288 xdata = [] 289 ydata = [] 290 291 mvals = data.keys() 292 mvals.sort(usans.numeric_compare) 293 for mval in mvals: 294 xdata.append(mval) 295 ydata.append(data[mval][3]) 296 297 model[path][3] = [xdata, ydata] 298 299 elif type == 'mon': 300 xdata = [] 301 ydata = [] 302 303 mvals = data.keys() 304 mvals.sort(usans.numeric_compare) 305 for mval in mvals: 306 xdata.append(mval) 307 ydata.append(data[mval][0]) 308 309 model[path][3] = [xdata, ydata] 310 311 elif type == 'split': 312 xdata = [] 313 ydata1 = [] 314 ydata2 = [] 315 ydata3 = [] 316 ydata4 = [] 317 ydata5 = [] 318 319 mvals = data.keys() 320 mvals.sort(usans.numeric_compare) 321 for mval in mvals: 322 xdata.append(mval) 323 ydata1.append(data[mval][1]) 324 ydata2.append(data[mval][2]) 325 ydata3.append(data[mval][4]) 326 ydata4.append(data[mval][5]) 327 ydata5.append(data[mval][6]) 328 329 model[path][3] = [xdata,ydata1,ydata2,ydata3,ydata4,ydata5] 330 else: 331 pass 332 333 return 334 335 def remove_plot(self, model, path): 207 model[path][2].remove_plot() 208 self.rescale_and_redraw() 209 return 210 336 211 337 for line in model[path][4]:338 self.axis.lines.remove(line)339 340 if (len(self.axis.lines) > 0):341 self.rescale_and_redraw()342 else:343 self.canvas.draw()344 345 return346 347 212 def handle_xaxis_loglin(self, widget): 348 213 … … 373 238 if widget.get_active(): 374 239 self.plottype = widget.get_name().split('_')[1] 375 #print self.plottype376 240 377 241 return … … 390 254 path = model.get_path(iter) 391 255 if model[path][1] != 0: 392 for line in model[path][4]: 393 self.axis.lines.remove(line) 394 model[path][1] = not model[path][1] 256 model[path][2].remove_plot() 395 257 iter = model.iter_next(iter) 396 397 #Remove any lines left over - shouldn't be any, but let's tidy up398 #for line in self.axis.lines:399 #self.axis.lines.remove(line)400 258 401 259 self.canvas.draw() … … 407 265 ydata = [] 408 266 409 for line in self.axis.lines: 410 if self.axis.get_xscale() == 'log': 411 xdata.extend([xval for xval in line.get_xdata() if xval > 0]) 412 else: 413 xdata.extend(line.get_xdata()) 414 if self.axis.get_yscale() == 'log': 415 ydata.extend([xval for xval in line.get_ydata() if xval > 0]) 416 else: 417 ydata.extend(line.get_ydata()) 418 419 #set limits 420 xmin = float(min(xdata)) 421 xmax = float(max(xdata)) 422 ymin = float(min(ydata)) 423 ymax = float(max(ydata)) 424 425 #adjust for size of markers (sort of) 426 xmin = xmin - 0.1*abs(xmin) 427 xmax = xmax + 0.1*abs(xmax) 428 ymin = ymin - 0.1*abs(ymin) 429 ymax = ymax + 0.1*abs(ymax) 430 431 self.axis.set_xlim(xmin,xmax) 432 self.axis.set_ylim(ymin,ymax) 267 if len(self.axis.lines) > 0: 268 269 for line in self.axis.lines: 270 if self.axis.get_xscale() == 'log': 271 xdata.extend([xval for xval in line.get_xdata() if xval > 0]) 272 else: 273 xdata.extend(line.get_xdata()) 274 if self.axis.get_yscale() == 'log': 275 ydata.extend([xval for xval in line.get_ydata() if xval > 0]) 276 else: 277 ydata.extend(line.get_ydata()) 278 279 #set limits 280 xmin = float(min(xdata)) 281 xmax = float(max(xdata)) 282 ymin = float(min(ydata)) 283 ymax = float(max(ydata)) 284 285 #adjust for size of markers (sort of) 286 xmin = xmin - 0.1*abs(xmin) 287 xmax = xmax + 0.1*abs(xmax) 288 ymin = ymin - 0.1*abs(ymin) 289 ymax = ymax + 0.1*abs(ymax) 290 291 self.axis.set_xlim(xmin,xmax) 292 self.axis.set_ylim(ymin,ymax) 433 293 434 294 #self.axis.autoscale_view() … … 438 298 439 299 def handle_plot_click(self,event): 300 model = self.filelistview.get_model().get_model() 301 iter = model.iter_children(None) 302 303 440 304 if isinstance(event.artist, matplotlib.lines.Line2D): 305 print "Clicked..." 441 306 pickedline = event.artist 307 ind = event.ind 442 308 xdata = pickedline.get_xdata() 443 ydata = pickedline.get_ydata() 444 ind = event.ind 445 print 'Plot Click: ',zip(numpy.take(xdata,ind), numpy.take(ydata,ind)) 309 310 while iter: 311 path = model.get_path(iter) 312 if model[path][1] != 0: 313 for line in model[path][2].plot: 314 if line == pickedline: 315 model[path][2].calcAlignVals(xdata[ind]) 316 label = self.wTree.get_widget("lbl_alignvals") 317 label.set_text(model[path][2].alignvalstring) 318 break 319 iter = model.iter_next(iter) 320 321 322 446 323 447 324 app = appGui() -
sans/utils/bt5/bt5plot2/bt5plot2.glade
r469 r471 487 487 488 488 <child> 489 <placeholder/> 490 </child> 491 492 <child> 493 <placeholder/> 489 <widget class="GtkLabel" id="lbl_alignvals"> 490 <property name="visible">True</property> 491 <property name="label" translatable="yes"></property> 492 <property name="use_underline">False</property> 493 <property name="use_markup">False</property> 494 <property name="justify">GTK_JUSTIFY_LEFT</property> 495 <property name="wrap">False</property> 496 <property name="selectable">False</property> 497 <property name="xalign">0.5</property> 498 <property name="yalign">0.5</property> 499 <property name="xpad">0</property> 500 <property name="ypad">0</property> 501 <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> 502 <property name="width_chars">-1</property> 503 <property name="single_line_mode">False</property> 504 <property name="angle">0</property> 505 </widget> 506 <packing> 507 <property name="padding">0</property> 508 <property name="expand">True</property> 509 <property name="fill">True</property> 510 </packing> 494 511 </child> 495 512 … … 570 587 <property name="expand">False</property> 571 588 <property name="fill">False</property> 572 <property name="pack_type">GTK_PACK_END</property>573 589 </packing> 574 590 </child> -
sans/utils/bt5/bt5plot2/usans.py
r466 r471 1 1 #!/usr/bin/python 2 2 3 #import Tkinter as Tk 4 5 def numeric_compare(x, y): 6 x = float(x) 7 y = float(y) 8 9 if x < y: 10 return - 1 11 elif x == y: 12 return 0 13 else: # x>y 14 return 1 3 import os 4 import sys 15 5 16 6 def isBT5Data(fileName): … … 27 17 else: 28 18 inputfile.close() 19 return 0 20 21 def numeric_compare(x, y): 22 x = float(x) 23 y = float(y) 24 25 if x < y: 26 return - 1 27 elif x == y: 29 28 return 0 29 else: # x>y 30 return 1 30 31 31 32 def getBT5DataFromFile(fileName): 33 ''' 34 Takes a filename and returns a dictionary of the detector values 35 keyed by varying value (ususally A2 or A5) 36 ''' 37 detdata = {} 38 metadata = {} 39 motlist = [] 40 41 if isBT5Data(fileName): 42 43 #print "File: ",fileName 44 inputfile = open(fileName, "r") 45 46 inputdata = inputfile.readlines() 47 48 mdtmp = inputdata[0].replace("'", "") 49 mdtmp = mdtmp.split() 32 def GetBT5DirList(): 33 """Function to parse the directory listing of the current working directory 34 and create a list of filenames that are BT5 data files""" 35 36 dirlist = os.listdir(os.getcwd()) 50 37 51 #Sundry metadata about run settings 52 (metadata['filename'], metadata['datetime'], 53 metadata['mon'], metadata['prefactor'], 54 metadata['base'], metadata['numpnts'], 55 metadata['type']) = (mdtmp[0], ' '.join(mdtmp[1:5]), float(mdtmp[6]), int(mdtmp[7]), mdtmp[8], int(mdtmp[9]), mdtmp[10]) 38 bt5list = [ x for x in dirlist if (x.find('.bt5') > 0 and isBT5Data(x))] 56 39 57 #Comment string 58 metadata['title'] = inputdata[2].strip() 59 60 #Start, step and end values for motors 1-6 61 motlist.append(inputdata[5].split()[1:]) 62 motlist.append(inputdata[6].split()[1:]) 63 motlist.append(inputdata[7].split()[1:]) 64 motlist.append(inputdata[8].split()[1:]) 65 motlist.append(inputdata[9].split()[1:]) 66 motlist.append(inputdata[10].split()[1:]) 67 metadata['motorvals'] = motlist 68 69 for index in range(13, len(inputdata), 2): 70 detdata[float(inputdata[index].split()[0])] = inputdata[index + 1].split(',') 71 72 for key in detdata.keys(): 73 for val in range(0, len(detdata[key])): 74 detdata[key][val] = int(detdata[key][val]) 75 76 inputfile.close() 77 return detdata, metadata 78 79 else: 80 return 0,0 81 82 def printBT5DetData(detdata): 83 ''' 84 Print the contents of the file in a formatted fashion 85 86 Takes a dictionary of data as provided by getBT5DataFromFile() and prints out the contents 87 in a formatted fashion 88 ''' 89 motorvals = detdata.keys() 90 motorvals.sort(cmp=numeric_compare) 91 92 for motorval in motorvals: 93 str = repr(motorval) + ":" 94 str += "\tMon: " + repr(detdata[motorval][0]) 95 str += "\tDet 1-5: " + repr(detdata[motorval][2]) 96 str += "\t" + repr(detdata[motorval][1]) 97 str += "\t" + repr(detdata[motorval][4]) 98 str += "\t" + repr(detdata[motorval][5]) 99 str += "\t" + repr(detdata[motorval][6]) 100 str += "\tTrans: " + repr(detdata[motorval][3]) 101 print str 102 103 return 0 104 105 def getAlignVals(data, motorval): 106 ''' 107 Return the values we record in the logbook for a given motor position 108 109 Takes a dictionary as provided by getBT5DataFromFile and returns a dictionary with 110 keys Central, Trans and Sum 111 ''' 112 alignvals = {} 113 114 alignvals['Central'] = data[motorval][1] 115 alignvals['Trans'] = data[motorval][3] 116 alignvals['Sum'] = data[motorval][1] + data[motorval][2] + data[motorval][4] + data[motorval][5] + data[motorval][6] 117 return alignvals 118 119 def maxDetCount(data, detector): 120 ''' 121 Return the maximum value and corresponding motor position for a given detector 122 123 Takes a dictionary as provided by getBT5DataFromFile() and returns a dictionary with 124 keys Position and Value 125 ''' 126 maxpos = '' 127 maxval = 0 128 result = {} 129 130 mvals = data.keys() 131 det = {'1':2, '2':1, '3':4, '4':5, '5':6}[repr(detector)] 132 133 for mval in mvals: 134 if data[mval][det] > maxval: 135 maxval = data[mval][det] 136 maxpos = mval 137 138 result['Position'] = maxpos 139 result['Value'] = maxval 140 141 return result 142 143 144 40 return bt5list 145 41 146 42 if __name__ == '__main__':
Note: See TracChangeset
for help on using the changeset viewer.