voronoi#
Create a Voronoi tessellator.
- class VoronoiTessellator#
Bases:
object
- __init__(grainsize, seed=None, max_idx=255, region_of_center=None)#
Create a Voronoi tessellator instance.
This class is used to generate a Voronoi tessellation, which can be done using either the
generate()
or thecoo_to_idx()
method.Important
Other methods in this class cannot be used unless
generate()
has been called. E.g. retrieving a list of region indices requires a specified world and grid.- Parameters:
grainsize (float) – The average grain diameter.
seed (int (default=None)) – The seed of the used random number generators. This seed affects the values of the generated region indices and the number and positions of the Voronoi centers. When set to None (default), a random integer from a uniform distribution [0,1234567) is chosen as the seed.
max_idx (int (default=255)) – The (inclusive) maximum region index within the tessellation. This value has no upper bound.
region_of_center (callable, optional) – A function with signature tuple(float)->int which assigns region indices to generated Voronoi centers. If not specified, a random region index will be generated.
- generate(world, grid, make_2d=False)#
Generates a Voronoi tessellation.
If make_2d is set to True (default: False) the VoronoiTesselator ignores the z-direction, resulting in a tessellation where a region index is uniform in the z-direction.
Important: 2D grids are assumed to lie in the xy-plane.
Returns an ndarray of shape (nz, ny, nx) which is filled with region indices.
- coo_to_idx(x, y, z)#
Returns the region index (int) of the given coordinate within the Voronoi tessellation.
Important
This method has no information about the used world and grid. E.g. this means that periodic boundary conditions will not apply. This can be overriden by calling
generate()
before assigning this function to theMagnet
’s regions parameter.
- property indexDictionary#
Create a dictionary where each region (key) is linked to a list of grid coordinates (value).
- property indices#
Returns list of unique region indices.
- property number_of_regions#
Returns number of unique region indices.