def test_arg_find_runs_offset(self): # because of the nature of the find_runs algorithm, there may be # fencepost errors with runs that start at x[1] or x[-2] x = array([10, 12, 13, 14, 28, 16]) assert_equal(arg_find_runs(x) , [[0, 1], [1, 4], [4, 5], [5, 6]]) x = array([10, 15, 16, 17, 34]) assert_equal(arg_find_runs(x) , [[0, 1], [1, 4], [4, 5]])
def _get_selection_screencoords(self): """ Returns a tuple of (x1, x2) screen space coordinates of the start and end selection points. If there is no current selection, then returns an empty list. """ ds = getattr(self.plot, self.axis) selection = ds.metadata.get(self.metadata_name, None) if selection is None: return [] # "selections" metadata must be a tuple if self.metadata_name == "selections" or \ (selection is not None and isinstance(selection, tuple)): if selection is not None and len(selection) == 2: return [self.mapper.map_screen(array(selection))] else: return [] # All other metadata is interpreted as a mask on dataspace else: ar = arange(0, len(selection), 1) runs = arg_find_runs(ar[selection]) coords = [] for inds in runs: start = ds._data[ar[selection][inds[0]]] end = ds._data[ar[selection][inds[1] - 1]] coords.append(self.mapper.map_screen(array((start, end)))) return coords
def test_arg_find_runs_flat(self): x = array([0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0]) assert_equal(arg_find_runs(x, order='flat'), \ [[0, 3], [3, 7], [7, 11]])
def test_arg_find_runs_descending(self): x = array([30, 41, 40, 39, 38, 37, 12]) assert_equal(arg_find_runs(x, order='descending'), \ [[0, 1], [1, 6], [6, 7]])
def test_arg_find_runs_none(self): x = array([]) assert_equal(arg_find_runs(x) , []) x = array([12, 15, 27]) assert_equal(arg_find_runs(x) , [[0, 1], [1, 2], [2, 3]])
def test_arg_find_runs_end(self): x = array([18, 23, 24, 25]) assert_equal(arg_find_runs(x) , [[0, 1], [1, 4]])
def test_arg_find_runs_start(self): x = array([3, 4, 5, 12, 9, 17]) assert_equal(arg_find_runs(x) , [[0, 3], [3, 4], [4, 5], [5, 6]])
def test_arg_find_runs_middle(self): x = array([0, 8, 7, 8, 9, 2, 3, 4, 10]) assert_equal(arg_find_runs(x), [[0, 1], [1, 2], [2, 5], [5, 8], [8, 9]])