def bound_data(self, data): """ Returns a tuple of indices for the start and end of the first run of *data* that falls within the range. Implements AbstractDataRange. """ mask = self.mask_data(data) runs = arg_find_runs(mask, "flat") # Since runs of "0" are also considered runs, we have to cycle through # until we find the first run of "1"s. for run in runs: if mask[run[0]] == 1: return run[0],run[1]-1 # arg_find_runs returns 1 past the end return (0,0)
def bound_data(self, data): """ Returns a tuple of indices for the start and end of the first run of *data* that falls within the range. Implements AbstractDataRange. """ mask = self.mask_data(data) runs = arg_find_runs(mask, "flat") # Since runs of "0" are also considered runs, we have to cycle through # until we find the first run of "1"s. for run in runs: if mask[run[0]] == 1: # arg_find_runs returns 1 past the end return run[0], run[1] - 1 return (0, 0)
def _gather_points(self): """ Collects the data points that are within the bounds of the plot and caches them. """ if self._cache_valid: return if not self.index or not self.value: return index = self.index.get_data() varray = self._trace_data if varray.size == 0: self._cached_data_pts = [] self._cached_valid = True return coordinates = self.yindex.get_data() if self.fast_clip: coord_min = float(coordinates[0]) coord_max = coordinates[-1] slice_min = max(0,ceil((varray.shape[0]-1)*(self.value_range.low - coord_min)/(coord_max - coord_min))) slice_max = min(varray.shape[0], 1+floor((varray.shape[0]-1)*(self.value_range.high - coord_min)/(coord_max - coord_min))) varray = varray[slice_min:slice_max] # FIXME: The y coordinates must also be sliced to match varray. # Check to see if the data is completely outside the view region. outside = False # Check x coordinates. low, high = self.index.get_bounds() if low > self.index_range.high or high < self.index_range.low: outside = True # Check y coordinates. Use varray because it is nased on the yindex, # but has been shifted up or down depending on the values. ylow, yhigh = varray.min(), varray.max() if ylow > self.value_range.high or yhigh < self.value_range.low: outside = True if outside: self._cached_data_pts = [] self._cached_valid = True return if len(index) == 0 or varray.shape[0] == 0 or varray.shape[1] == 0 \ or len(index) != varray.shape[1]: self._cached_data_pts = [] self._cache_valid = True return size_diff = varray.shape[1] - len(index) if size_diff > 0: warnings.warn('Chaco.LinePlot: value.shape[1] %d - len(index) %d = %d\n' \ % (varray.shape[1], len(index), size_diff)) index_max = len(index) varray = varray[:,:index_max] else: index_max = varray.shape[1] index = index[:index_max] # Split the index and value raw data into non-NaN chunks. # nan_mask is a boolean M by N array. nan_mask = invert(isnan(varray)) & invert(isnan(index)) blocks_list = [] for nm in nan_mask: blocks = [b for b in arg_find_runs(nm, "flat") if nm[b[0]] != 0] blocks_list.append(blocks) line_points = [] for k, blocks in enumerate(blocks_list): points = [] for block in blocks: start, end = block block_index = index[start:end] block_value = varray[k, start:end] index_mask = self.index_mapper.range.mask_data(block_index) runs = [r for r in arg_find_runs(index_mask, "flat") \ if index_mask[r[0]] != 0] # Check to see if our data view region is between two points in the # index data. If so, then we have to reverse map our current view # into the appropriate index and draw the bracketing points. if runs == []: data_pt = self.map_data((self.x_mapper.low_pos, self.y_mapper.low_pos)) if self.index.sort_order == "none": indices = argsort(index) sorted_index = take(index, indices) sorted_value = take(varray[k], indices) sort = 1 else: sorted_index = index sorted_value = varray[k] if self.index.sort_order == "ascending": sort = 1 else: sort = -1 ndx = bin_search(sorted_index, data_pt, sort) if ndx == -1: # bin_search can return -1 if data_pt is outside the bounds # of the source data continue z = transpose(array((sorted_index[ndx:ndx+2], sorted_value[ndx:ndx+2]))) points.append(z) else: # Expand the width of every group of points so we draw the lines # up to their next point, outside the plot area data_end = len(index_mask) for run in runs: start, end = run if start != 0: start -= 1 if end != data_end: end += 1 run_data = transpose(array((block_index[start:end], block_value[start:end]))) points.append(run_data) line_points.append(points) self._cached_data_pts = line_points self._cache_valid = True return
def _gather_points(self): """ Collects the data points that are within the bounds of the plot and caches them. """ if not self._cache_valid: if not self.index or not self.value: return index = self.index.get_data() value = self.value.get_data() # Check to see if the data is completely outside the view region for ds, rng in ((self.index, self.index_range), (self.value, self.value_range)): low, high = ds.get_bounds() if low > rng.high or high < rng.low: self._cached_data_pts = [] self._cached_valid = True return if len(index) == 0 or len(value) == 0 or len(index) != len(value): self._cached_data_pts = [] self._cache_valid = True size_diff = len(value) - len(index) if size_diff > 0: warnings.warn('Chaco.LinePlot: len(value) %d - len(index) %d = %d\n' \ % (len(value), len(index), size_diff)) index_max = len(index) value = value[:index_max] else: index_max = len(value) index = index[:index_max] # TODO: restore the functionality of rendering highlighted portions # of the line #selection = self.index.metadata.get(self.metadata_name, None) #if selection is not None and type(selection) in (ndarray, list) and \ # len(selection) > 0: # Split the index and value raw data into non-NaN chunks nan_mask = invert(isnan(value)) & invert(isnan(index)) blocks = [b for b in arg_find_runs(nan_mask, "flat") if nan_mask[b[0]] != 0] points = [] for block in blocks: start, end = block block_index = index[start:end] block_value = value[start:end] index_mask = self.index_mapper.range.mask_data(block_index) runs = [r for r in arg_find_runs(index_mask, "flat") \ if index_mask[r[0]] != 0] # Check to see if our data view region is between two points in the # index data. If so, then we have to reverse map our current view # into the appropriate index and draw the bracketing points. if runs == []: data_pt = self.map_data((self.x_mapper.low_pos, self.y_mapper.low_pos)) if self.index.sort_order == "none": indices = argsort(index) sorted_index = take(index, indices) sorted_value = take(value, indices) sort = 1 else: sorted_index = index sorted_value = value if self.index.sort_order == "ascending": sort = 1 else: sort = -1 ndx = bin_search(sorted_index, data_pt, sort) if ndx == -1: # bin_search can return -1 if data_pt is outside the bounds # of the source data continue points.append(transpose(array((sorted_index[ndx:ndx+2], sorted_value[ndx:ndx+2])))) else: # Expand the width of every group of points so we draw the lines # up to their next point, outside the plot area data_end = len(index_mask) for run in runs: start, end = run if start != 0: start -= 1 if end != data_end: end += 1 run_data = transpose(array((block_index[start:end], block_value[start:end]))) points.append(run_data) self._cached_data_pts = points self._cache_valid = True return
def _gather_points(self): """ Collects the data points that are within the bounds of the plot and caches them. """ if self._cache_valid: return if not self.index or not self.value: return index = self.index.get_data() varray = self._trace_data if varray.size == 0: self._cached_data_pts = [] self._cached_valid = True return coordinates = self.yindex.get_data() if self.fast_clip: coord_min = float(coordinates[0]) coord_max = coordinates[-1] slice_min = max( 0, ceil((varray.shape[0] - 1) * (self.value_range.low - coord_min) / (coord_max - coord_min))) slice_max = min( varray.shape[0], 1 + floor((varray.shape[0] - 1) * (self.value_range.high - coord_min) / (coord_max - coord_min))) varray = varray[slice_min:slice_max] # FIXME: The y coordinates must also be sliced to match varray. # Check to see if the data is completely outside the view region. outside = False # Check x coordinates. low, high = self.index.get_bounds() if low > self.index_range.high or high < self.index_range.low: outside = True # Check y coordinates. Use varray because it is nased on the yindex, # but has been shifted up or down depending on the values. ylow, yhigh = varray.min(), varray.max() if ylow > self.value_range.high or yhigh < self.value_range.low: outside = True if outside: self._cached_data_pts = [] self._cached_valid = True return if len(index) == 0 or varray.shape[0] == 0 or varray.shape[1] == 0 \ or len(index) != varray.shape[1]: self._cached_data_pts = [] self._cache_valid = True return size_diff = varray.shape[1] - len(index) if size_diff > 0: warnings.warn('Chaco.LinePlot: value.shape[1] %d - len(index) %d = %d\n' \ % (varray.shape[1], len(index), size_diff)) index_max = len(index) varray = varray[:, :index_max] else: index_max = varray.shape[1] index = index[:index_max] # Split the index and value raw data into non-NaN chunks. # nan_mask is a boolean M by N array. nan_mask = invert(isnan(varray)) & invert(isnan(index)) blocks_list = [] for nm in nan_mask: blocks = [b for b in arg_find_runs(nm, "flat") if nm[b[0]] != 0] blocks_list.append(blocks) line_points = [] for k, blocks in enumerate(blocks_list): points = [] for block in blocks: start, end = block block_index = index[start:end] block_value = varray[k, start:end] index_mask = self.index_mapper.range.mask_data(block_index) runs = [r for r in arg_find_runs(index_mask, "flat") \ if index_mask[r[0]] != 0] # Check to see if our data view region is between two points in the # index data. If so, then we have to reverse map our current view # into the appropriate index and draw the bracketing points. if runs == []: data_pt = self.map_data( (self.x_mapper.low_pos, self.y_mapper.low_pos)) if self.index.sort_order == "none": indices = argsort(index) sorted_index = take(index, indices) sorted_value = take(varray[k], indices) sort = 1 else: sorted_index = index sorted_value = varray[k] if self.index.sort_order == "ascending": sort = 1 else: sort = -1 ndx = bin_search(sorted_index, data_pt, sort) if ndx == -1: # bin_search can return -1 if data_pt is outside the bounds # of the source data continue z = transpose( array((sorted_index[ndx:ndx + 2], sorted_value[ndx:ndx + 2]))) points.append(z) else: # Expand the width of every group of points so we draw the lines # up to their next point, outside the plot area data_end = len(index_mask) for run in runs: start, end = run if start != 0: start -= 1 if end != data_end: end += 1 run_data = transpose( array((block_index[start:end], block_value[start:end]))) points.append(run_data) line_points.append(points) self._cached_data_pts = line_points self._cache_valid = True return
def _gather_points(self): """ Collects the data points that are within the bounds of the plot and caches them. """ if not self._cache_valid: if not self.index or not self.value: return index = self.index.get_data() value = self.value.get_data() # Check to see if the data is completely outside the view region for ds, rng in ((self.index, self.index_range), (self.value, self.value_range)): low, high = ds.get_bounds() if low > rng.high or high < rng.low: self._cached_data_pts = [] self._cached_valid = True return if len(index) == 0 or len(value) == 0 or len(index) != len(value): self._cached_data_pts = [] self._cache_valid = True size_diff = len(value) - len(index) if size_diff > 0: warnings.warn('Chaco.LinePlot: len(value) %d - len(index) %d = %d\n' \ % (len(value), len(index), size_diff)) index_max = len(index) value = value[:index_max] else: index_max = len(value) index = index[:index_max] # TODO: restore the functionality of rendering highlighted portions # of the line #selection = self.index.metadata.get(self.metadata_name, None) #if selection is not None and type(selection) in (ndarray, list) and \ # len(selection) > 0: # Split the index and value raw data into non-NaN chunks nan_mask = invert(isnan(value)) & invert(isnan(index)) blocks = [ b for b in arg_find_runs(nan_mask, "flat") if nan_mask[b[0]] != 0 ] points = [] for block in blocks: start, end = block block_index = index[start:end] block_value = value[start:end] index_mask = self.index_mapper.range.mask_data(block_index) runs = [r for r in arg_find_runs(index_mask, "flat") \ if index_mask[r[0]] != 0] # Check to see if our data view region is between two points in the # index data. If so, then we have to reverse map our current view # into the appropriate index and draw the bracketing points. if runs == []: data_pt = self.map_data( (self.x_mapper.low_pos, self.y_mapper.low_pos)) if self.index.sort_order == "none": indices = argsort(index) sorted_index = take(index, indices) sorted_value = take(value, indices) sort = 1 else: sorted_index = index sorted_value = value if self.index.sort_order == "ascending": sort = 1 else: sort = -1 ndx = bin_search(sorted_index, data_pt, sort) if ndx == -1: # bin_search can return -1 if data_pt is outside the bounds # of the source data continue points.append( transpose( array((sorted_index[ndx:ndx + 2], sorted_value[ndx:ndx + 2])))) else: # Expand the width of every group of points so we draw the lines # up to their next point, outside the plot area data_end = len(index_mask) for run in runs: start, end = run if start != 0: start -= 1 if end != data_end: end += 1 run_data = (block_index[start:end], block_value[start:end]) run_data = column_stack(run_data) points.append(run_data) self._cached_data_pts = points self._cache_valid = True return