Python holoviews.Polygons() Examples
The following are 9
code examples of holoviews.Polygons().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
holoviews
, or try the search function
.
Example #1
Source File: testpaths.py From holoviews with BSD 3-Clause "New" or "Revised" License | 6 votes |
def setUp(self): xs = [1, 2, 3] ys = [2, 0, 7] holes = [[[(1.5, 2), (2, 3), (1.6, 1.6)], [(2.1, 4.5), (2.5, 5), (2.3, 3.5)]]] self.single_poly = Polygons([{'x': xs, 'y': ys, 'holes': holes}]) xs = [1, 2, 3, np.nan, 6, 7, 3] ys = [2, 0, 7, np.nan, 7, 5, 2] holes = [ [[(1.5, 2), (2, 3), (1.6, 1.6)], [(2.1, 4.5), (2.5, 5), (2.3, 3.5)]], [] ] self.multi_poly = Polygons([{'x': xs, 'y': ys, 'holes': holes}]) self.multi_poly_no_hole = Polygons([{'x': xs, 'y': ys}]) self.distinct_polys = Polygons([ {'x': xs, 'y': ys, 'holes': holes, 'value': 0}, {'x': [4, 6, 6], 'y': [0, 2, 1], 'value': 1}], vdims='value')
Example #2
Source File: grabcut.py From EarthSim with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _process(self, element, key=None): try: import cv2 as cv except: # HACK: Avoids error loading OpenCV the first time # ImportError dlopen: cannot load any more object with static TLS try: import cv2 as cv except ImportError: raise ImportError('GrabCut algorithm requires openCV') if isinstance(self.p.foreground, hv.Polygons): rasterize_op = rasterize_polygon else: rasterize_op = rasterize.instance(aggregator=ds.any()) kwargs = {'dynamic': False, 'target': element} fg_mask = rasterize_op(self.p.foreground, **kwargs) bg_mask = rasterize_op(self.p.background, **kwargs) fg_mask = fg_mask.dimension_values(2, flat=False) bg_mask = bg_mask.dimension_values(2, flat=False) if fg_mask[np.isfinite(fg_mask)].sum() == 0 or bg_mask[np.isfinite(bg_mask)].sum() == 0: return element.clone([], vdims=['Foreground'], new_type=gv.Image, crs=element.crs) mask = np.where(fg_mask, 1, 2) mask = np.where(bg_mask, 0, mask).copy() bgdModel = np.zeros((1,65), np.float64) fgdModel = np.zeros((1,65), np.float64) if isinstance(element, hv.RGB): img = np.dstack([element.dimension_values(d, flat=False) for d in element.vdims]) else: img = element.dimension_values(2, flat=False) mask, _, _ = cv.grabCut(img, mask.astype('uint8'), None, bgdModel, fgdModel, self.p.iterations, cv.GC_INIT_WITH_MASK) fg_mask = np.where((mask==2)|(mask==0),0,1).astype('bool') xs, ys = (element.dimension_values(d, expanded=False) for d in element.kdims) return element.clone((xs, ys, fg_mask), vdims=['Foreground'], new_type=gv.Image, crs=element.crs)
Example #3
Source File: grabcut.py From EarthSim with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, poly_data=[], **params): super(SelectRegionPanel, self).__init__(**params) self.boxes = gv.Polygons(poly_data).options( fill_alpha=0.5, color='grey', line_color='white', line_width=2, width=self.width, height=self.height ) if not self.boxes: self.boxes = self.boxes.options(global_extent=True) self.box_stream = BoxEdit(source=self.boxes, num_objects=1)
Example #4
Source File: teststatsoperations.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_bivariate_kde_contours_filled(self): np.random.seed(1) bivariate = Bivariate(np.random.rand(100, 2)) kde = bivariate_kde(bivariate, n_samples=100, x_range=(0, 1), y_range=(0, 1), contours=True, filled=True, levels=10) self.assertIsInstance(kde, Polygons) self.assertEqual(len(kde.data), 10)
Example #5
Source File: testpaths.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_multi_poly_empty_holes(self): poly = Polygons([]) self.assertFalse(poly.interface.has_holes(poly)) self.assertEqual(poly.interface.holes(poly), [])
Example #6
Source File: testpaths.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_single_poly_hole_validation(self): xs = [1, 2, 3] ys = [2, 0, 7] with self.assertRaises(DataError): Polygons([{'x': xs, 'y': ys, 'holes': [[], []]}])
Example #7
Source File: testpaths.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_multi_poly_hole_validation(self): xs = [1, 2, 3, np.nan, 6, 7, 3] ys = [2, 0, 7, np.nan, 7, 5, 2] with self.assertRaises(DataError): Polygons([{'x': xs, 'y': ys, 'holes': [[]]}])
Example #8
Source File: visualization.py From minian with GNU General Public License v3.0 | 5 votes |
def _box(self, data): if data is None: return hv.Polygons([]) else: diag = pd.DataFrame(data) corners = [] for ir, r in diag.iterrows(): corners.append( np.array([(r['x0'], r['y0']), (r['x0'], r['y1']), (r['x1'], r['y1']), (r['x1'], r['y0'])])) return hv.Polygons([{ ('x', 'y'): cnr.squeeze() } for cnr in corners])
Example #9
Source File: visualization.py From minian with GNU General Public License v3.0 | 5 votes |
def roi_draw(im): h, w = im.sizes['height'], im.sizes['width'] opts_im = {'plot': {'height': h, 'width': w}, 'style': {'cmap': 'Viridis'}} opts_box = {'style': {'fill_alpha': 0.3, 'line_color': 'white'}} hv_im = regrid(hv.Image(im, kdims=['width', 'height'])).opts(**opts_im) hv_box = hv.Polygons([]).opts(**opts_box) str_box = BoxEdit(source=hv_box) return hv_im * hv_box, str_box