pNeuma_simulator.initialization.poissondisc module
- class pNeuma_simulator.initialization.poissondisc.PoissonDisc(n_cars: int, n_moto: int, cell: float = 2.25, L: int = 180, W: float = 7.2, k: int = 30, aspect: float = 2.5, clearance: float = 0.25, rng=None)[source]
Bases:
objectA class for generating Poisson-disc sampled points.
This class implements the Poisson-disc sampling algorithm to generate points that are evenly distributed within a specified area. It is adapted from the implementation available at https://scipython.com/blog/poisson-disc-sampling-in-python.
- L
The length of the sampling area.
- Type:
int
- W
The width of the sampling area.
- Type:
float
- n_cars
The number of cars to be sampled.
- Type:
int
- n_moto
The number of motorcycles to be sampled.
- Type:
int
- cell
The side length of each cell in the grid.
- Type:
float
- nx
The number of cells in the x-direction of the grid.
- Type:
int
- ny
The number of cells in the y-direction of the grid.
- Type:
int
- width
The width of the grid.
- Type:
float
- height
The height of the grid.
- Type:
float
- x_boundaries
The x-coordinates of the cell boundaries.
- Type:
numpy.ndarray
- y_boundaries
The y-coordinates of the cell boundaries.
- Type:
numpy.ndarray
- k
The number of candidate points to consider around each reference point.
- Type:
int
- aspect
The aspect ratio of the ellipses.
- Type:
float
- clearance
The clearance distance between points.
- Type:
float
- rng
The random number generator.
- Type:
numpy.random.Generator
- get_cell_coords(pt: Particle)[source]
Get the coordinates of the cell that pt = (x,y) falls in.
- Parameters:
pt (Particle) – A Particle object
- Returns:
A tuple (x, y) representing the coordinates of the cell.
- Return type:
tuple
- get_neighbours(coords)[source]
Return the indexes of points in cells neighbouring cell at coords.
For the cell at coords = (x,y), return the indexes of points in the cells with neighbouring coordinates illustrated below: ie those cells that could contain points closer than r.
ooooo ooXoo ooooo
- Parameters:
pt (tuple) – A tuple (x, y) representing the coordinates of the cell.
- get_point(ref_pt: Particle)[source]
Try to find a candidate point relative to ref_pt to emit in the sample.
We draw up to k points from the annulus of inner radius r, outer radius 2r around the reference point, ref_pt. If none of them are suitable (because they’re too close to existing points in the sample), return False. Otherwise, return the pt.
- is_valid(pt: Particle)[source]
Is pt a valid point to emit as a sample?
It must be no closer than r from any other point: check the cells in its immediate neighbourhood.
- sample(rng: Generator)[source]
Poisson disc random sampling in 2D.
Draw random samples on the domain width x height such that no two samples are closer than r apart. The parameter k determines the maximum number of candidate points to be chosen around each reference point before removing it from the “active” list.