Exemplo n.º 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]])
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
 def render(self, gc, component):
     # Uses the component to map our path into screen space
     nan_mask = invert(isnan(self.path[:, 0])).astype(int)
     blocks = [b for b in arg_find_runs(nan_mask, "flat") if nan_mask[b[0]] != 0]
     screen_pts = component.map_screen(self.path)
     with gc:
         gc.clip_to_rect(component.x, component.y, component.width, component.height)
         gc.set_stroke_color(self.line_color_)
         for start, end in blocks:
             gc.begin_path()
             gc.lines(screen_pts[start:end])
             gc.stroke_path()
         self.render_turtle(gc, component)
Exemplo n.º 5
0
 def render(self, gc, component):
     # Uses the component to map our path into screen space
     nan_mask = invert(isnan(self.path[:, 0])).astype(int)
     blocks = [
         b for b in arg_find_runs(nan_mask, "flat") if nan_mask[b[0]] != 0
     ]
     screen_pts = component.map_screen(self.path)
     with gc:
         gc.clip_to_rect(component.x, component.y, component.width,
                         component.height)
         gc.set_stroke_color(self.line_color_)
         for start, end in blocks:
             gc.begin_path()
             gc.lines(screen_pts[start:end])
             gc.stroke_path()
         self.render_turtle(gc, component)
Exemplo n.º 6
0
 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 None.
     """
     ds = getattr(self.plot, self.axis)
     selection = ds.metadata[self.metadata_name]
     
     if selection is None or len(selection) == 1:
         return []
     # if not an even number of points, trim the last point
     elif len(selection)%2 != 0:
         del selection[-1]
     
     # "selections" metadata is a tuple of selection pairs
     if self.metadata_name == "selections":
         coords = []
         for index in range(len(selection)/2):
             interval = (selection[index*2],selection[index*2+1])
             coords.append(self.mapper.map_screen(array(interval)))
         return coords
         
     else:
         selection_points = len(selection)
         coords = []
         # treat the metadata as a mask on dataspace
         if len(ds._data) == selection_points:
             selected = nonzero(selection)[0]
             runs = arg_find_runs(selected)                
             for run in runs:
                 start = ds._data[selected[run[0]]]
                 end = ds._data[selected[run[1]-1]]
                 coords.append(self.mapper.map_screen(array((start, end))))
             
         # selection is tuples of selected regions in dataspace
         else:
             for index in range(len(selection)/2):
                 interval = (selection[index*2],selection[index*2+1])
                 coords.append(self.mapper.map_screen(array(interval)))
         return coords
Exemplo n.º 7
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]])
Exemplo n.º 8
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]])
Exemplo n.º 9
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]])
Exemplo n.º 10
0
 def test_arg_find_runs_end(self):
     x = array([18, 23, 24, 25])
     assert_equal(arg_find_runs(x), [[0, 1], [1, 4]])
Exemplo n.º 11
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]])
Exemplo n.º 12
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]])