示例#1
0
 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]])
示例#2
0
 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
示例#4
0
 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]])
示例#5
0
 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]])
示例#6
0
 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]])
示例#7
0
 def test_arg_find_runs_end(self):
     x = array([18, 23, 24, 25])
     assert_equal(arg_find_runs(x) , [[0, 1], [1, 4]])
示例#8
0
 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]])
示例#9
0
 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]])
示例#10
0
 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]])
示例#11
0
 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]])
示例#12
0
 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]])
示例#13
0
 def test_arg_find_runs_end(self):
     x = array([18, 23, 24, 25])
     assert_equal(arg_find_runs(x) , [[0, 1], [1, 4]])
示例#14
0
 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]])
示例#15
0
 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]])