Changeset 471 for sans/utils/bt5/bt5plot2/bt5plot2
- Timestamp:
- Jan 30, 2009 2:39:07 AM (14 years ago)
- File:
-
- 1 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()
Note: See TracChangeset
for help on using the changeset viewer.