def _prepare_data_for_window(self, xlow, xhigh, ylow, yhigh): ''' This is called every time the chaco window is rendered and it dynamically computes and returns the data corresponding to the window limits. This allows rendering to stay relatively fast since data is binned down to a resolution roughly matching what the window can usefully display. ''' #if not self.update_content: if not self.loop1: return self.zi stack = self.dataset_stack.copy() # deal with restricted y-range if ylow < 1 or ylow >= yhigh: ylow = 1 if yhigh > stack.shape[0] or yhigh <= ylow: yhigh = stack.shape[0] stack = stack[int(np.round(ylow - 1)):int(np.round(yhigh))] if stack[0, 0, 0] > stack[0, -1, 0]: stack = stack[:, ::-1, :] # get a typical interval interval = np.median(np.diff(stack[0, :10, 0])) # get a region a couple of samples bigger on each side of the window to allow for # misalignment xs = stack[:, :, 0] xlow_expanded = xs[0, 0] - interval * 2 xhigh_expanded = xs[0, -1] + interval * 2 column_mask = (xs[0] >= xlow_expanded) & (xs[0] <= xhigh_expanded) stack = stack[:, column_mask][np.newaxis].reshape(xs.shape[0], -1, 3) # regrid all rows - use an interval half that of the original interval to minimise interpolation errors first_row = regrid_data(stack[0], start=xlow_expanded, end=xhigh_expanded, interval=interval / 2) new_stack = np.empty((xs.shape[0], first_row.shape[0], 3)) new_stack[0] = first_row for i, stack_row in enumerate(stack[1:]): new_stack[i + 1] = regrid_data(stack_row, start=xlow_expanded, end=xhigh_expanded, interval=interval / 2) # new_stack is the regridded version so window it properly xs = new_stack[:, :, 0] zs = new_stack[:, :, 1] mask = (xs[0] >= xlow) & (xs[0] <= xhigh) zs = zs[:, mask].reshape(zs.shape[0], -1) YBINS = zs.shape[0] * 10 BINS = min(5000, zs.shape[1]) zi = congrid(zs, (YBINS, BINS), method='neighbour', minusone=True) zi = np.clip(zi, 1, zi.max()) self.zi = zi self.loop1 = False return zi
def _prepare_data_for_window(self, xlow, xhigh, ylow, yhigh): ''' This is called every time the chaco window is rendered and it dynamically computes and returns the data corresponding to the window limits. This allows rendering to stay relatively fast since data is binned down to a resolution roughly matching what the window can usefully display. ''' #if not self.update_content: if not self.loop1: return self.zi stack = self.dataset_stack.copy() # deal with restricted y-range if ylow < 1 or ylow >= yhigh: ylow = 1 if yhigh > stack.shape[0] or yhigh <= ylow: yhigh = stack.shape[0] stack = stack[int(np.round(ylow-1)):int(np.round(yhigh))] if stack[0,0,0] > stack[0,-1,0]: stack = stack[:,::-1,:] # get a typical interval interval = np.median(np.diff(stack[0,:10,0])) # get a region a couple of samples bigger on each side of the window to allow for # misalignment xs = stack[:,:,0] xlow_expanded = xs[0,0] - interval*2 xhigh_expanded = xs[0,-1] + interval*2 column_mask = (xs[0]>=xlow_expanded) & (xs[0]<=xhigh_expanded) stack = stack[:,column_mask][np.newaxis].reshape(xs.shape[0],-1,3) # regrid all rows - use an interval half that of the original interval to minimise interpolation errors first_row = regrid_data(stack[0], start=xlow_expanded, end=xhigh_expanded, interval=interval/2) new_stack = np.empty((xs.shape[0], first_row.shape[0], 3)) new_stack[0] = first_row for i, stack_row in enumerate(stack[1:]): new_stack[i+1] = regrid_data(stack_row, start=xlow_expanded, end=xhigh_expanded, interval=interval/2) # new_stack is the regridded version so window it properly xs = new_stack[:,:,0] zs = new_stack[:,:,1] mask = (xs[0]>=xlow) & (xs[0]<=xhigh) zs = zs[:,mask].reshape(zs.shape[0],-1) YBINS = zs.shape[0]*10 BINS = min(5000, zs.shape[1]) zi = congrid(zs, (YBINS, BINS), method='neighbour', minusone=True) zi = np.clip(zi, 1, zi.max()) self.zi = zi self.loop1=False return zi
def regrid_data_test2(self): # test that regridding preserves the y-data if resampled near the x-data points np.random.seed(42) POINTS = 5 data = np.c_[np.arange(POINTS), np.random.rand(POINTS), np.arange(POINTS)] newdata = processing.regrid_data(data, start=0.000001, end=data[:,0][-1]+.000001, interval=1.0) self.assertTrue(np.allclose(data, newdata, atol=1e-4))
def regrid_data_test(self): # test that regridding preserves the y-data if resampled at the x-data points np.random.seed(42) POINTS = 50000 data = np.c_[np.arange(POINTS), np.random.rand(POINTS), np.arange(POINTS)] newdata = processing.regrid_data(data, interval=1.0) self.assertTrue(np.allclose(data, newdata))
def regrid_data_test2(self): # test that regridding preserves the y-data if resampled near the x-data points np.random.seed(42) POINTS = 5 data = np.c_[np.arange(POINTS), np.random.rand(POINTS), np.arange(POINTS)] newdata = processing.regrid_data(data, start=0.000001, end=data[:, 0][-1] + .000001, interval=1.0) self.assertTrue(np.allclose(data, newdata, atol=1e-4))