Grid#

Create grid objects based on the length of the grid, step size, and origin. The grid point is at the center of each voxel.

Example Usage#

To create a grid object:

grid = Grid(shape=[21, 11, 101], step=[20.0, 4.0, 20.0], origin=[0.0, 0.0, 0.0])

The resulting grid is rectangular with the shape of (21, 11, 101), the distance between two edge grid points in each direction are (200, 40, 2000) nm, and the full grid size is (220 \(\times\) 44 \(\times\) 2020) nm. The returned grid points are numpy “ogrid” points: np.ogrid.

To print out a summary of the grid properties:

>>> print(grid)
Grid(shape=[21, 11, 101]
        step=[20.0, 4.0, 20.0] nm
        origin=[0.0, 0.0, 0.0] nm
        voxel=1600.000 nm^3
        range=[ 400.   40. 2000.] nm
        length=[ 420.   44. 2020.] nm)

grid module#

class mrfmsim.component.grid.Grid(shape: tuple[int], step: list[float], origin: list[float])[source]#

Bases: ComponentBase

Instantiate a rectangular grid with shape, step, and origin.

The resulting grid has equal spacing in each dimension. The grid array uses numpy’s open mesh-grid, which has speed and storage benefits.

Parameters:
  • length (np.array) – array of lengths along (x, y, z)

  • step (list) – a list of step sizes

  • origin (list) – the grid origin

  • shape (tuple[int]) – grid dimension (number of points in x, y, z direction)

  • step – grid setup size in x, y, z direction

  • origin – grid origin

  • voxel (float) – the volume of each grid voxel

  • range (np.array) – range in (x, y, z direction), shape (3, 2)

  • length – actual lengths of the grid. This is recalculated based on the rounded value of grid shape and step size.

extend_grid_by_length(ext_length)[source]#

Extend the grid by the number of points in the x direction.

This is used to extend the grid by the cantilever motion. The length needs to be more than the step size to count.

Parameters:

ext_pts (int) – distance (one side) to extend along x direction (cantilever motion direction). The length should be a list of three dimensions.

extend_grid_by_points(ext_pts)[source]#

Extend the grid by the number of points in the x direction.

Parameters:

ext_pts (int) – points (one side) to extend along x direction (cantilever motion direction). The points should be a list of three dimensions.

property grid_array#

Generate an open mesh-grid of the given grid dimensions.

The benefit of the property is that it generates the grid array at run time.

static grid_extents(length, origin)[source]#

Calculate grid extents based on the grid length and origin.

The result is column stacked into a dimension of (3, 2)

length: array#
origin: list[float]#
range: array#
shape: tuple[int]#
step: list[float]#
voxel: float#