mechanochat.tools.cell2grid#
- mechanochat.tools.cell2grid(xc: ndarray[Any, dtype[_ScalarType_co]], Nx: int, padding: float = 1e-3)[source]#
Partition cells into a regular square grid.
The bounding box of xc is divided into Nx columns; the number of rows follows from the aspect ratio so that the grid cells stay square. Empty grid cells are not kept.
- Parameters:
xc (
numpy.ndarray) – (nc, 2) cell coordinates.Nx (
int) – Number of grid columns.padding (
float) – Relative enlargement of the bounding box. Must be > 0, otherwise the cells sitting exactly on the box boundary fall outside the grid (the bin test uses strict inequalities). A message is printed if any cell ends up outside.
- Returns:
xc2grid_map (
dict) – (i, j) -> array of the indices of the cells inside grid cell (i, j). Only non-empty grid cells are present.grid_center (
dict) – (i, j) -> mean coordinate of the cells inside grid cell (i, j) (not the geometric center of the square).x_grid (
numpy.ndarray) – (Nx + 1,) x coordinates of the grid lines.y_grid (
numpy.ndarray) – (Ny + 1,) y coordinates of the grid lines.
See also
signal_direction,signal_tensor,plotting.plot_xc2grid,plotting.plot_grid