konigcell.static2d#
- konigcell.static2d(positions, mode, values=None, radii=None, pixels=None, resolution=None, xlim=None, ylim=None, executor=<class 'concurrent.futures.thread.ThreadPoolExecutor'>, max_workers=None, verbose=True)[source]#
Pixelize / rasterize static particles’ positions onto a 2D pixel grid.
This is exactly like the dynamic2d function, but particles are not considered to be moving - so they are rasterized a circles.
The input parameters are equivalent to dynamic2d - check its documentation for full details.
Examples
Compute the occupancy grid of a 3 static 2D particles of radius 0.5:
>>> import numpy as np >>> positions = np.array([[0, 0], [1, 1], [2, 1]]) >>> >>> import konigcell as kc >>> pixels = kc.static2d( >>> positions, >>> kc.INTERSECTION, >>> radii = 0.5, >>> resolution = (500, 500), >>> xlim = [-2, 5], >>> ylim = [-2, 5], >>> )
The
kc.INTERSECTIONpixellisation mode adds the area shaded by the particle’s movement onto the grid.If you omit
xlimandylim, they will be computed automatically to include all particle positions.You can reuse the same pixels grid for multiple pixellisations:
>>> kc.static2d( >>> positions, >>> kc.INTERSECTION, >>> radii = 0.5, >>> pixels = pixels, >>> )
In this case the
resolution,xlimandylimdon’t need to be set anymore; they are extracted from the Pixels grid.You can set the maximum number of workers for the parallel pixellisation; e.g. for single-threaded execution:
>>> pixels = kc.static2d( >>> positions, >>> kc.ONE, >>> radii = 0.5, >>> resolution = (500, 500), >>> max_workers = 1, >>> )
The
kc.ONEpixellisation flag simply adds 1 to each pixel intersected by the moving particle.Finally, here is a complete example computing the occupancy grid of 10,000 static 2D particles:
>>> positions = np.random.random((10_000, 2)) * 5 >>> >>> occupancy = kc.static2d( >>> positions, >>> kc.INTERSECTION, >>> radii = 0.5, >>> resolution = (500, 500), >>> )