def setUp(self): self.path1 = Path([(-0.3, 0.4), (-0.3, 0.3), (-0.2, 0.3), (-0.2, 0.4), (-0.3, 0.4)]) self.path2 = Path([(-0.3, 0.4), (-0.3, 0.3), (-0.2, 0.3), (-0.2, 0.4), (-3, 4)]) self.contours1 = Contours([(-0.3, 0.4, 1), (-0.3, 0.3, 1), (-0.2, 0.3, 1), (-0.2, 0.4, 1), (-0.3, 0.4, 1)], vdims='Level') self.contours2 = Contours([(-0.3, 0.4, 1), (-0.3, 0.3, 1), (-0.2, 0.3, 1), (-0.2, 0.4, 1), (-3, 4, 1)], vdims='Level') self.contours3 = Contours([(-0.3, 0.4, 2), (-0.3, 0.3, 2), (-0.2, 0.3, 2), (-0.2, 0.4, 2), (-0.3, 0.4, 2)], vdims='Level') self.bounds1 = Bounds(0.3) self.bounds2 = Bounds(0.4) self.box1 = Box(-0.25, 0.3, 0.3) self.box2 = Box(-0.25, 0.3, 0.4) self.ellipse1 = Ellipse(-0.25, 0.3, 0.3) self.ellipse2 = Ellipse(-0.25, 0.3, 0.4)
def setUp(self): self.path1 = Path([(-0.3, 0.4), (-0.3, 0.3), (-0.2, 0.3), (-0.2, 0.4), (-0.3, 0.4)]) self.path2 = Path([(-0.3, 0.4), (-0.3, 0.3), (-0.2, 0.3), (-0.2, 0.4), (-3, 4)]) self.contours1 = Contours([(-0.3, 0.4), (-0.3, 0.3), (-0.2, 0.3), (-0.2, 0.4), (-0.3, 0.4)], level=1) self.contours2 = Contours([(-0.3, 0.4), (-0.3, 0.3), (-0.2, 0.3), (-0.2, 0.4), (-3, 4)], level=1) self.contours3 = Contours([(-0.3, 0.4), (-0.3, 0.3), (-0.2, 0.3), (-0.2, 0.4), (-0.3, 0.4)], level=2) self.bounds1 = Bounds(0.3) self.bounds2 = Bounds(0.4) self.box1 = Box(-0.25, 0.3, 0.3) self.box2 = Box(-0.25, 0.3, 0.4) self.ellipse1 = Ellipse(-0.25, 0.3, 0.3) self.ellipse2 = Ellipse(-0.25, 0.3, 0.4)
def test_image_contours(self): img = Image(np.array([[0, 1, 0], [3, 4, 5.], [6, 7, 8]])) op_contours = contours(img, levels=[0.5]) contour = Contours([[(-0.5, 0.416667, 0.5), (-0.25, 0.5, 0.5)], [(0.25, 0.5, 0.5), (0.5, 0.45, 0.5)]], vdims=img.vdims) self.assertEqual(op_contours, contour)
def test_qmesh_contours(self): qmesh = QuadMesh(([0, 1, 2], [1, 2, 3], np.array([[0, 1, 0], [3, 4, 5.], [6, 7, 8]]))) op_contours = contours(qmesh, levels=[0.5]) contour = Contours([[(0, 1.166667, 0.5), (0.5, 1., 0.5), (np.NaN, np.NaN, 0.5), (1.5, 1., 0.5), (2, 1.1, 0.5)]], vdims=qmesh.vdims) self.assertEqual(op_contours, contour)
def test_image_contours(self): img = Image(np.array([[0, 1, 0], [3, 4, 5.], [6, 7, 8]])) op_contours = contours(img) ndoverlay = NdOverlay(None, kdims=['Levels']) ndoverlay[0.5] = Contours([[(-0.5, 0.416667), (-0.25, 0.5)], [(0.25, 0.5), (0.5, 0.45)]], group='Level', level=0.5, vdims=img.vdims) self.assertEqual(op_contours, img * ndoverlay)
def test_qmesh_curvilinear_contours(self): x = y = np.arange(3) xs, ys = np.meshgrid(x, y) zs = np.array([[0, 1, 0], [3, 4, 5.], [6, 7, 8]]) qmesh = QuadMesh((xs, ys + 0.1, zs)) op_contours = contours(qmesh, levels=[0.5]) contour = Contours([[(0, 0.266667, 0.5), (0.5, 0.1, 0.5), (np.NaN, np.NaN, 0.5), (1.5, 0.1, 0.5), (2, 0.2, 0.5)]], vdims=qmesh.vdims) self.assertEqual(op_contours, contour)
def _update_proj_cog(self, p, proj): """Measure the CoG of the specified projection and register corresponding SheetViews.""" sheet = proj.dest rows, cols = sheet.activity.shape xcog = np.zeros((rows, cols), np.float64) ycog = np.zeros((rows, cols), np.float64) for r in xrange(rows): for c in xrange(cols): cf = proj.cfs[r, c] r1, r2, c1, c2 = cf.input_sheet_slice row_centroid, col_centroid = centroid(cf.weights) xcentroid, ycentroid = proj.src.matrix2sheet( r1 + row_centroid + 0.5, c1 + col_centroid + 0.5) xcog[r][c] = xcentroid ycog[r][c] = ycentroid metadata = AttrDict(precedence=sheet.precedence, row_precedence=sheet.row_precedence, src_name=sheet.name) timestamp = topo.sim.time() xsv = Matrix(xcog, sheet.bounds, label='X CoG', title='%s {label}' % proj.name) ysv = Matrix(ycog, sheet.bounds, label='Y CoG', title='%s {label}' % proj.name) lines = [] hlines, vlines = xsv.data.shape for hind in range(hlines)[::p.stride]: lines.append(np.vstack([xsv.data[hind, :].T, ysv.data[hind, :]]).T) for vind in range(vlines)[::p.stride]: lines.append(np.vstack([xsv.data[:, vind].T, ysv.data[:, vind]]).T) cogmesh = Contours(lines, lbrt=sheet.bounds.lbrt(), label='Center of Gravity', title='%s {label}' % proj.name) xcog_map = ViewMap((timestamp, xsv), dimensions=[features.Time]) xcog_map.metadata = metadata ycog_map = ViewMap((timestamp, ysv), dimensions=[features.Time]) ycog_map.metadata = metadata contour_map = ViewMap((timestamp, cogmesh), dimensions=[features.Time]) contour_map.metadata = metadata return {'XCoG': xcog_map, 'YCoG': ycog_map, 'CoG': contour_map}
def test_contours_string_signature(self): contours = Contours([], ['a', 'b']) self.assertEqual(contours.kdims, [Dimension('a'), Dimension('b')])
def test_aggregate_contours_without_vdim(self): contours = Contours([[(0.2, 0.3), (0.4, 0.7)], [(0.4, 0.7), (0.8, 0.99)]]) img = rasterize(contours, dynamic=False) self.assertEqual(img.vdims, ['Count'])
def test_aggregate_contours_with_vdim(self): contours = Contours([[(0.2, 0.3, 1), (0.4, 0.7, 1)], [(0.4, 0.7, 2), (0.8, 0.99, 2)]], vdims='z') img = rasterize(contours, dynamic=False) self.assertEqual(img.vdims, ['z'])
def test_image_contours_no_range(self): img = Image(np.zeros((2, 2))) op_contours = contours(img, levels=2) contour = Contours([], vdims=img.vdims) self.assertEqual(op_contours, contour)