Esempio n. 1
0
    def test_points_histogram_bin_range(self):
        points = Points([float(i) for i in range(10)])
        op_hist = histogram(points, num_bins=3, bin_range=(0, 3))

        hist = Histogram(([0.25, 0.25, 0.5], [0., 1., 2., 3.]),
                         vdims=('x_frequency', 'Frequency'))
        self.assertEqual(op_hist, hist)
Esempio n. 2
0
    def test_points_histogram_cumulative(self):
        arr = np.arange(4)
        points = Points(arr)
        op_hist = histogram(points, cumulative=True, num_bins=3, normed=False)

        hist = Histogram(([0, 1, 2, 3], [1, 2, 4]), vdims=('x_count', 'Count'))
        self.assertEqual(op_hist, hist)
    def test_points_histogram_not_normed(self):
        points = Points([float(i) for i in range(10)])
        op_hist = histogram(points, num_bins=3, normed=False)

        hist = Histogram(([0, 3, 6, 9], [3, 3, 4]),
                         vdims=('x_count', 'Count'))
        self.assertEqual(op_hist, hist)
Esempio n. 4
0
    def test_points_histogram(self):
        points = Points([float(i) for i in range(10)])
        op_hist = histogram(points, num_bins=3)

        hist = Histogram(([0.1, 0.1, 0.133333], [0, 3, 6, 9]),
                         vdims=('x_frequency', 'Frequency'))
        self.assertEqual(op_hist, hist)
    def test_points_histogram_explicit_bins(self):
        points = Points([float(i) for i in range(10)])
        op_hist = histogram(points, bins=[0, 1, 3], normed=False)

        hist = Histogram(([0, 1, 3], [1, 3]),
                         vdims=('x_count', 'Count'))
        self.assertEqual(op_hist, hist)
Esempio n. 6
0
 def test_aggregate_zero_range_points(self):
     p = Points([(0, 0), (1, 1)])
     agg = rasterize(p, x_range=(0, 0), y_range=(0, 1), expand=False, dynamic=False,
                     width=2, height=2)
     img = Image(([], [0.25, 0.75], np.zeros((2, 0))), bounds=(0, 0, 0, 1),
                 xdensity=1, vdims=['Count'])
     self.assertEqual(agg, img)
Esempio n. 7
0
 def test_rasterize_points(self):
     points = Points([(0.2, 0.3), (0.4, 0.7), (0, 0.99)])
     img = rasterize(points, dynamic=False,  x_range=(0, 1), y_range=(0, 1),
                     width=2, height=2)
     expected = Image(([0.25, 0.75], [0.25, 0.75], [[1, 0], [2, 0]]),
                      vdims=['Count'])
     self.assertEqual(img, expected)
Esempio n. 8
0
 def test_aggregate_points_sampling(self):
     points = Points([(0.2, 0.3), (0.4, 0.7), (0, 0.99)])
     expected = Image(([0.25, 0.75], [0.25, 0.75], [[1, 0], [2, 0]]),
                      vdims=['Count'])
     img = aggregate(points, dynamic=False,  x_range=(0, 1), y_range=(0, 1),
                     x_sampling=0.5, y_sampling=0.5)
     self.assertEqual(img, expected)
Esempio n. 9
0
 def test_rasterize_trimesh_vertex_vdims(self):
     simplices = [(0, 1, 2), (3, 2, 1)]
     vertices = [(0., 0., 1), (0., 1., 2), (1., 0., 3), (1., 1., 4)]
     trimesh = TriMesh((simplices, Points(vertices, vdims='z')))
     img = rasterize(trimesh, width=3, height=3, dynamic=False)
     image = Image(np.array([[2., 3., np.NaN], [1.5, 2.5, np.NaN], [np.NaN, np.NaN, np.NaN]]),
                   bounds=(0, 0, 1, 1), vdims='z')
     self.assertEqual(img, image)
Esempio n. 10
0
 def test_rasterize_trimesh_node_explicit_vdim(self):
     simplices = [(0, 1, 2, 0.5), (3, 2, 1, 1.5)]
     vertices = [(0., 0., 1), (0., 1., 2), (1., 0, 3), (1, 1, 4)]
     trimesh = TriMesh((simplices, Points(vertices, vdims=['node_z'])), vdims=['z'])
     img = rasterize(trimesh, width=3, height=3, dynamic=False, aggregator=ds.mean('z'))
     image = Image(np.array([[1.5, 1.5, np.NaN], [0.5, 1.5, np.NaN], [np.NaN, np.NaN, np.NaN]]),
                   bounds=(0, 0, 1, 1))
     self.assertEqual(img, image)
Esempio n. 11
0
 def test_points_histogram_mean_weighted(self):
     points = Points([float(i) for i in range(10)])
     op_hist = histogram(points,
                         num_bins=3,
                         weight_dimension='y',
                         mean_weighted=True)
     hist = Histogram(([1., 4., 7.5], [0, 3, 6, 9]), vdims=['y'])
     self.assertEqual(op_hist, hist)
Esempio n. 12
0
 def test_aggregate_points_cudf(self):
     points = Points([(0.2, 0.3), (0.4, 0.7), (0, 0.99)], datatype=['cuDF'])
     self.assertIsInstance(points.data, cudf.DataFrame)
     img = aggregate(points, dynamic=False,  x_range=(0, 1), y_range=(0, 1),
                     width=2, height=2)
     expected = Image(([0.25, 0.75], [0.25, 0.75], [[1, 0], [2, 0]]),
                      vdims=['Count'])
     self.assertIsInstance(img.data.Count.data, cupy.ndarray)
     self.assertEqual(img, expected)
Esempio n. 13
0
 def test_aggregate_points_categorical(self):
     points = Points([(0.2, 0.3, 'A'), (0.4, 0.7, 'B'), (0, 0.99, 'C')], vdims='z')
     img = aggregate(points, dynamic=False,  x_range=(0, 1), y_range=(0, 1),
                     width=2, height=2, aggregator=ds.count_cat('z'))
     xs, ys = [0.25, 0.75], [0.25, 0.75]
     expected = NdOverlay({'A': Image((xs, ys, [[1, 0], [0, 0]]), vdims='z Count'),
                           'B': Image((xs, ys, [[0, 0], [1, 0]]), vdims='z Count'),
                           'C': Image((xs, ys, [[0, 0], [1, 0]]), vdims='z Count')},
                          kdims=['z'])
     self.assertEqual(img, expected)
Esempio n. 14
0
 def test_aggregate_points_categorical_zero_range(self):
     points = Points([(0.2, 0.3, 'A'), (0.4, 0.7, 'B'), (0, 0.99, 'C')], vdims='z')
     img = aggregate(points, dynamic=False,  x_range=(0, 0), y_range=(0, 1),
                     aggregator=ds.count_cat('z'))
     xs, ys = [], [0.25, 0.75]
     params = dict(bounds=(0, 0, 0, 1), xdensity=1)
     expected = NdOverlay({'A': Image((xs, ys, np.zeros((2, 0))), vdims='z Count', **params),
                           'B': Image((xs, ys, np.zeros((2, 0))), vdims='z Count', **params),
                           'C': Image((xs, ys, np.zeros((2, 0))), vdims='z Count', **params)},
                          kdims=['z'])
     self.assertEqual(img, expected)
Esempio n. 15
0
    def test_points_histogram_not_normed(self):
        points = Points([float(i) for i in range(10)])
        op_hist = histogram(points, num_bins=3, normed=False)

        # Make sure that the name and label are as desired
        op_freq_dim = op_hist.get_dimension('x_frequency')
        self.assertEqual(op_freq_dim.label, 'x Frequency')

        # Because the operation labels are now different from the
        #  default Element label, change back before comparing.
        op_hist = op_hist.redim(x_frequency='Frequency')
        hist = Histogram(([3, 3, 4], [0, 3, 6, 9]))
        self.assertEqual(op_hist, hist)
Esempio n. 16
0
    def test_points_histogram_cumulative(self):
        arr = np.arange(4)
        points = Points(arr)
        op_hist = histogram(points, cumulative=True, num_bins=3, normed=False)

        # Make sure that the name and label are as desired
        op_freq_dim = op_hist.get_dimension('x_frequency')
        self.assertEqual(op_freq_dim.label, 'x Frequency')

        # Because the operation labels are now different from the
        #  default Element label, change back before comparing.
        op_hist = op_hist.redim(x_frequency='Frequency')
        hist = Histogram(([0, 1, 2, 3], [1, 2, 4]))
        self.assertEqual(op_hist, hist)
Esempio n. 17
0
    def test_histogram_operation_kwargs(self):
        points = Points([float(j) for i in range(10) for j in [i] * (2 * i)])
        op_hist = histogram(
            points,
            dimension='y',
            normed=False,
            num_bins=10,
            bin_range=[0, 10],
        )

        hist = Histogram(
            ([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0
              ], [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]),
            vdims=('y_count', 'Count'),
            kdims='y')

        # Check histogram
        self.assertEqual(op_hist, hist)

        # Check operation kwargs for histogram generated with operation
        self.assertEqual(
            op_hist._operation_kwargs, {
                'dimension': 'y',
                'normed': False,
                'dynamic': False,
                'bins':
                [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
            })

        # Test that operation_kwargs is preserved through clone
        self.assertEqual(
            op_hist.clone()._operation_kwargs, {
                'dimension': 'y',
                'normed': False,
                'dynamic': False,
                'bins':
                [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
            })

        # Check that operation kwargs is None for histogram generated directly
        # from the Histogram constructor
        self.assertIsNone(hist._operation_kwargs)
Esempio n. 18
0
 def test_points_histogram_weighted(self):
     points = Points([float(i) for i in range(10)])
     op_hist = histogram(points, num_bins=3, weight_dimension='y')
     hist = Histogram(([0.022222, 0.088889, 0.222222], [0, 3, 6, 9]),
                      vdims=['y'])
     self.assertEqual(op_hist, hist)
Esempio n. 19
0
 def test_aggregate_points_target(self):
     points = Points([(0.2, 0.3), (0.4, 0.7), (0, 0.99)])
     expected = Image(([0.25, 0.75], [0.25, 0.75], [[1, 0], [2, 0]]),
                      vdims=['Count'])
     img = aggregate(points, dynamic=False,  target=expected)
     self.assertEqual(img, expected)
Esempio n. 20
0
def viz_mesh(verts, tris):
    points = Points(verts, vdims=['z'])
    return TriMesh((tris, points), crs=ccrs.GOOGLE_MERCATOR)
Esempio n. 21
0
 def test_points_string_signature(self):
     points = Points([], ['a', 'b'], 'c')
     self.assertEqual(points.kdims, [Dimension('a'), Dimension('b')])
     self.assertEqual(points.vdims, [Dimension('c')])
Esempio n. 22
0
    def setUp(self):
        "Variations on the constructors in the Elements notebook"

        self.points1 = Points([(1, i) for i in range(20)])
        self.points2 = Points([(1, i) for i in range(21)])
        self.points3 = Points([(1, i*2) for i in range(20)])