flatspin.grid#

Grid

flatspin.grid.add_values_fast(grid_values, grid_inds, values)#
class flatspin.grid.Grid(points, cell_size=None, padding=None)#

Create a regular grid over points

Allows quick lookup of point index -> grid index

pointsarray

List of points to place on the grid

cell_sizetuple

Size og each cell on the grid If not provided, attempts to auto-detect a suitable cell_size such that each cell contains at most one point.

paddingtuple

Offset each point by a padding to ensure they don’t fall exactly on a cell edge

centers()#

Return the centers of the grid cells

edges()#

Return the edges of the grid cells

center_grid()#

Make a grid with the cell centers

classmethod fixed_grid(pos, grid_size)#

Make a grid with a fixed size

grid_index(point_inds)#

Map point index to grid index

If point_inds is a single index i, a single grid index (gi, gj) is returned.

If point_inds is a list of indices, it should take the form of an integer array index: ([i0, i1, i2, …], [j0, j1, j2, …]) The corresponding grid indices are returned in the same format.

See https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#integer-array-indexing

point_index(grid_index)#

Map one grid index to zero or more point indices

map_values(values, fill_value=0, mask_empty=False)#

Map values onto the grid

Returns a 2D array with the values mapped onto the grid

add_values(values, fill_value=0, mask_empty=False, method='sum')#

Add values to the grid

Returns a 2D array with the values summed to the grid

valuesarray or list

Values to map onto the grid cells

fill_valuescalar

Fill value for empty cells

method{‘sum’, ‘mean’}

How to aggregate multiple values which map to the same cell