Complete rewrite of dataset class, with (all) the necessary updates

This commit is contained in:
2006-04-24 09:53:07 +00:00
parent 53d0228074
commit a2e4392a72
9 changed files with 426 additions and 234 deletions

View File

@@ -224,25 +224,27 @@ class SinePlot(Plot):
class ScatterPlot(Plot):
def __init__(self,project):
def __init__(self,project,dataset,id_dim,sel_dim,id_1,id_2):
Plot.__init__(self,project)
self.project = project
fig = Figure(figsize=(5,4), dpi=72)
self.ax = ax = fig.add_subplot(111)
self.current_dim = id_dim
# testing testing
self.x_dataset = project.datasets[0]
x = self.x_dataset._data
self.xaxis_data = xaxis_data = x[:,0] + scipy.randn(scipy.shape(x)[0])
self.yaxis_data = yaxis_data = x[:,1]
self.current_dim = self.x_dataset._dim_names[0]
ax.plot(xaxis_data,yaxis_data,'og')
self.dataset = dataset
x_index = dataset[sel_dim][id_1]
y_index = dataset[sel_dim][id_2]
self.xaxis_data = dataset._array[:,x_index]
self.yaxis_data = dataset._array[:,y_index]
ax.plot(self.xaxis_data,self.yaxis_data,'og')
###
self.canvas = FigureCanvas(fig)
self.add(self.canvas)
rectprops = dict(facecolor='gray', edgecolor = 'black',
alpha=0.2, fill=True) #cool
sel = RectangleSelector(ax, self.rectangle_select_callback,
self.sel = RectangleSelector(ax, self.rectangle_select_callback,
drawtype='box',useblit=True,rectprops=rectprops)
self.canvas.show()
@@ -251,45 +253,36 @@ class ScatterPlot(Plot):
'event1 and event2 are the press and release events'
x1, y1 = event1.xdata, event1.ydata
x2, y2 = event2.xdata, event2.ydata
logger.log('debug', "(%3.2f, %3.2f) --> (%3.2f, %3.2f)"%(x1,y1,x2,y2))
logger.log('debug',"The button you used were:%s, %s "%(event1.button, event2.button))
# get all points within x1, y1, x2, y2
ydata = self.yaxis_data
xdata = self.xaxis_data
if x1>x2:
logger.log('debug','Selection x_start bigger than x_end')
if y1<y2:
logger.log('debug','Selection y_start less than y_end')
index =scipy.nonzero((xdata<x1) & (xdata>x2) & (ydata>y1) & (ydata<y2))
else:
logger.log('debug','Selection y_start larger than y_end')
index =scipy.nonzero((xdata<x1) & (xdata>x2) & (ydata<y1) & (ydata>y2))
else:
logger.log('debug','Selection x_start less than x_end')
#logger.log('debug','Selection x_start less than x_end')
if y1<y2:
logger.log('debug','Selection y_start less than y_end')
#logger.log('debug','Selection y_start less than y_end')
index =scipy.nonzero((xdata>x1) & (xdata<x2) & (ydata>y1) & (ydata<y2))
else:
logger.log('debug','Selection y_start bigger than y_end')
#logger.log('debug','Selection y_start bigger than y_end')
index =scipy.nonzero((xdata>x1) & (xdata<x2) & (ydata<y1) & (ydata>y2))
if len(index)==0:
logger.log('debug','No points selected!')
else:
logger.log('debug','Selected:\n%s'%index)
ids = self.x_dataset.extract_id_from_index('samples',index)
#update selection object
ids = [id for id,ind in self.dataset[self.current_dim].items() if ind in index]
self.project.set_selection(self.current_dim,ids)
logger.log('debug','Selected identifiers:\n%s'%ids)
def update(self,project,key):
curr_sel = project.get_selection() # get selection object
ids = curr_sel[self.current_dim] # current identifiers
index = self.x_dataset.extract_index_from_id(self.current_dim,ids) #conversion to index
index = [ind for id,ind in self.dataset[self.current_dim].items() if id in ids] #conversion to index
xdata_new = scipy.take(self.xaxis_data,index) #take data
ydata_new = scipy.take(self.yaxis_data,index)
self.ax.plot(self.xaxis_data,self.yaxis_data,'ob')
self.ax.plot(self.xaxis_data,self.yaxis_data,'og')
self.ax.plot(xdata_new,ydata_new,'or')
self.canvas.draw()