Esempio n. 1
0
 def test_plot_point_cloud_2d_large(self):
     spheres = PointCloud(
         Sphere(wrap([(2, 4), (9, 8), (7, 8)], instance('points'),
                     channel('vector')),
                radius=1))
     cells = PointCloud(
         geom.pack_dims(
             CenteredGrid(0, 0, x=3, y=3, bounds=Box[4:6, 2:4]).elements,
             'x,y', instance('points')))
     cloud = field.stack([spheres, cells], instance('stack'))
     self._test_plot(cloud)
Esempio n. 2
0
 def test_plot_point_cloud_2d(self):
     spheres = PointCloud(
         Sphere(wrap([(.2, .4), (.9, .8), (.7, .8)], instance('points'),
                     channel('vector')),
                radius=.1))
     cells = PointCloud(
         geom.pack_dims(
             CenteredGrid(0, 0, x=3, y=3,
                          bounds=Box[.4:.6, .2:.4]).elements, 'x,y',
             instance('points')))
     cloud = field.stack([spheres, cells], instance('stack'))
     self._test_plot(cloud)
Esempio n. 3
0
    def points(self,
               points: Tensor or Number or tuple or list,
               values: Tensor or Number = None,
               radius: Tensor or float or int or None = None,
               extrapolation: math.Extrapolation = math.extrapolation.ZERO,
               color: str or Tensor or tuple or list or None = None) -> PointCloud:
        """
        Create a `phi.field.PointCloud` from the given `points`.
        The created field has no channel dimensions and all points carry the value `1`.

        Args:
            points: point locations in physical units
            values: (optional) values of the particles, defaults to 1.
            radius: (optional) size of the particles
            extrapolation: (optional) extrapolation to use, defaults to extrapolation.ZERO
            color: (optional) color used when plotting the points

        Returns:
            `phi.field.PointCloud` object
        """
        extrapolation = extrapolation if isinstance(extrapolation, math.Extrapolation) else self.boundaries[extrapolation]
        if radius is None:
            radius = math.mean(self.bounds.size) * 0.005
        # --- Parse points: tuple / list ---
        if isinstance(points, (tuple, list)):
            if len(points) == 0:  # no points
                points = math.zeros(instance(points=0), channel(vector=1))
            elif isinstance(points[0], Number):  # single point
                points = math.tensor([points], instance('points'), channel('vector'))
            else:
                points = math.tensor(points, instance('points'), channel('vector'))
        elements = Sphere(points, radius)
        if values is None:
            values = math.tensor(1.)
        return PointCloud(elements, values, extrapolation, add_overlapping=False, bounds=self.bounds, color=color)
Esempio n. 4
0
 def test_plot_multiple(self):
     grid = CenteredGrid(Noise(batch(b=2)), 0, Box[0:1, 0:1], x=50, y=10)
     grid2 = CenteredGrid(grid, 0, Box[0:2, 0:1], x=20, y=50)
     points = wrap([(.2, .4), (.9, .8)], instance('points'),
                   channel('vector'))
     cloud = PointCloud(Sphere(points, radius=0.1), bounds=Box(0, [1, 1]))
     titles = math.wrap([['b=0', 'b=0', 'points'], ['b=1', 'b=1', '']],
                        spatial('rows,cols'))
     self._test_plot(grid, grid2, cloud, row_dims='b', title=titles)
Esempio n. 5
0
 def test_convert_point_cloud(self):
     loc = math.random_uniform(instance(points=4), channel(vector=2))
     val = math.random_normal(instance(points=4), channel(vector=2))
     points = PointCloud(Sphere(loc, radius=1), val)
     for backend in BACKENDS:
         converted = field.convert(points, backend)
         self.assertEqual(converted.values.default_backend, backend)
         self.assertEqual(converted.elements.center.default_backend,
                          backend)
         self.assertEqual(converted.elements.radius.default_backend,
                          backend)
Esempio n. 6
0
 def test_overlay(self):
     grid = CenteredGrid(Noise(),
                         extrapolation.ZERO,
                         x=64,
                         y=8,
                         bounds=Box(0, [1, 1]))
     points = wrap([(.2, .4), (.9, .8)], instance('points'),
                   channel('vector'))
     cloud = PointCloud(Sphere(points, radius=.1))
     self._test_plot(overlay(grid, grid * (0.1, 0.02), cloud),
                     title='Overlay')
Esempio n. 7
0
 def test_plot_point_cloud_3d_points(self):
     self._test_plot(
         PointCloud(
             math.random_normal(instance(points=5),
                                channel(vector='x,y,z'))))
Esempio n. 8
0
 def test_plot_point_cloud_3d(self):
     points = math.random_uniform(instance(points=50), channel(vector=3))
     cloud = PointCloud(Sphere(points, radius=.1),
                        bounds=Box(x=2, y=1, z=1))
     self._test_plot(cloud)
Esempio n. 9
0
 def test_plot_point_cloud_vector_field_2d_bounded(self):
     points = math.random_uniform(instance(points='a,b,c,d,e'),
                                  channel(vector='x,y'))
     velocity = PointCloud(Sphere(points, radius=.1), bounds=Box(x=1, y=1))
     self._test_plot(velocity * (.05, 0))
Esempio n. 10
0
 def test_plot_point_cloud_2d_bounded(self):
     points = wrap([(.2, .4), (.9, .8)], instance('points'),
                   channel('vector'))
     self._test_plot(
         PointCloud(Sphere(points, radius=0.1), bounds=Box(0, [1, 1])))