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 test_single_path_list_constructor(self): path = Path([(0, 1), (1, 2), (2, 3), (3, 4)]) self.assertFalse(path.interface.multi) self.assertEqual(path.dimension_values(0), np.array([ 0, 1, 2, 3])) self.assertEqual(path.dimension_values(1), np.array([ 1, 2, 3, 4]))
def test_aggregate_dframe_nan_path(self): path = Path([Path([[(0.2, 0.3), (0.4, 0.7)], [(0.4, 0.7), (0.8, 0.99)]]).dframe()]) expected = Image(([0.25, 0.75], [0.25, 0.75], [[1, 0], [2, 1]]), vdims=['Count']) img = aggregate(path, dynamic=False, x_range=(0, 1), y_range=(0, 1), width=2, height=2) self.assertEqual(img, expected)
def test_multi_path_tuple(self): path = Path(([0, 1], [[1, 3], [2, 4]])) self.assertTrue(path.interface.multi) self.assertEqual(path.dimension_values(0), np.array([ 0, 1, np.nan, 0, 1])) self.assertEqual(path.dimension_values(1), np.array([ 1, 2, np.nan, 3, 4]))
def test_multi_path_list_constructor(self): path = Path([[(0, 1), (1, 2)], [(2, 3), (3, 4)]]) self.assertTrue(path.interface.multi) self.assertEqual(path.dimension_values(0), np.array([ 0, 1, np.nan, 2, 3])) self.assertEqual(path.dimension_values(1), np.array([ 1, 2, np.nan, 3, 4]))
def test_dataset_groupby_path(self): ds = Dataset([(0, 0, 1), (0, 1, 2), (1, 2, 3), (1, 3, 4)], ['group', 'x', 'y']) subpaths = ds.groupby('group', group_type=Path) self.assertEqual(len(subpaths), 2) self.assertEqual(subpaths[0], Path([(0, 1), (1, 2)])) self.assertEqual(subpaths[1], Path([(2, 3), (3, 4)]))
def test_single_path_tuple_constructor(self): path = Path(([0, 1, 2, 3], [1, 2, 3, 4])) self.assertFalse(path.interface.multi) self.assertEqual(path.dimension_values(0), np.array([ 0, 1, 2, 3])) self.assertEqual(path.dimension_values(1), np.array([ 1, 2, 3, 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_multi_path_cast_path(self): path = Path([[(0, 1), (1, 2)], [(2, 3), (3, 4)]]) path2 = Path(path) self.assertTrue(path2.interface.multi) self.assertEqual(path2.dimension_values(0), np.array([0, 1, np.nan, 2, 3])) self.assertEqual(path2.dimension_values(1), np.array([1, 2, np.nan, 3, 4]))
def test_rasterize_path(self): path = Path([[(0.2, 0.3), (0.4, 0.7)], [(0.4, 0.7), (0.8, 0.99)]]) expected = Image(([0.25, 0.75], [0.25, 0.75], [[1, 0], [2, 1]]), vdims=['Count']) img = rasterize(path, dynamic=False, x_range=(0, 1), y_range=(0, 1), width=2, height=2) self.assertEqual(img, expected)
def test_line_rasterize(self): path = Path([[(0, 0), (1, 1), (2, 0)], [(0, 0), (0, 1)]], datatype=['spatialpandas']) agg = rasterize(path, width=4, height=4, dynamic=False) xs = [0.25, 0.75, 1.25, 1.75] ys = [0.125, 0.375, 0.625, 0.875] arr = np.array([[2, 0, 0, 1], [1, 1, 0, 1], [1, 1, 1, 0], [1, 0, 1, 0]]) expected = Image((xs, ys, arr), vdims='Count') self.assertEqual(agg, expected)
def setUp(self): self.xs = np.linspace(0, 2 * np.pi, 11) self.hxs = np.arange(len(self.xs)) self.sin = np.sin(self.xs) self.cos = np.cos(self.xs) sine_data = np.column_stack((self.xs, self.sin)) cos_data = np.column_stack((self.xs, self.cos)) self.curve = Curve(sine_data) self.path = Path([sine_data, cos_data]) self.histogram = Histogram((self.hxs, self.sin)) super(ElementConstructorTest, self).setUp()
def test_multi_path_unpack_single_paths(self): path = Path([Path([(0, 1), (1, 2)]), Path([(2, 3), (3, 4)])]) self.assertTrue(path.interface.multi) self.assertEqual(path.dimension_values(0), np.array([ 0, 1, np.nan, 2, 3])) self.assertEqual(path.dimension_values(1), np.array([ 1, 2, np.nan, 3, 4]))
def test_ring_rasterize(self): path = Path([{'x': [0, 1, 2], 'y': [0, 1, 0], 'geom_type': 'Ring'}], datatype=['spatialpandas']) agg = rasterize(path, width=4, height=4, dynamic=False) xs = [0.25, 0.75, 1.25, 1.75] ys = [0.125, 0.375, 0.625, 0.875] arr = np.array([ [1, 1, 1, 1], [0, 1, 0, 1], [0, 1, 1, 0], [0, 0, 1, 0] ]) expected = Image((xs, ys, arr), vdims='Count') self.assertEqual(agg, expected)
def test_multi_path_unpack_multi_paths(self): path = Path([Path([[(0, 1), (1, 2)]]), Path([[(2, 3), (3, 4)], [(4, 5), (5, 6)]])]) self.assertTrue(path.interface.multi) self.assertEqual(path.dimension_values(0), np.array([ 0, 1, np.nan, 2, 3, np.nan, 4, 5])) self.assertEqual(path.dimension_values(1), np.array([ 1, 2, np.nan, 3, 4, np.nan, 5, 6]))
def test_multi_path_list_split(self): path = Path([[(0, 1), (1, 2)], [(2, 3), (3, 4)]]) subpaths = path.split() self.assertEqual(len(subpaths), 2) self.assertEqual(subpaths[0], Path([(0, 1), (1, 2)])) self.assertEqual(subpaths[1], Path([(2, 3), (3, 4)]))
def test_path_ziplist_construct(self): self.assertEqual( Path([list(zip(self.xs, self.sin)), list(zip(self.xs, self.cos))]), self.path)
def test_path_tuplelist_construct(self): self.assertEqual(Path([(self.xs, self.sin), (self.xs, self.cos)]), self.path)
def test_path_tuple_construct(self): self.assertEqual( Path((self.xs, np.column_stack((self.sin, self.cos)))), self.path)
def test_path_string_signature(self): path = Path([], ['a', 'b']) self.assertEqual(path.kdims, [Dimension('a'), Dimension('b')])
def test_single_path_split(self): path = Path(([0, 1, 2, 3], [1, 2, 3, 4])) self.assertEqual(path, path.split()[0])