jLM.RegionBuilder#

Design lattice geometry

Classes

RegionBuilder([net, dims])

Helper object to design site lattice geometry

class jLM.RegionBuilder.RegionBuilder(net=None, dims=None)[source]#

Bases: object

Helper object to design site lattice geometry

Helper object to design site lattice geometry

Parameters:
  • net (SpatialModel) – If present, take dimensions from simulation

  • dims ([int]) – Dimensions of lattice

box(lx, ly, lz, xs=None, angles=None, center=None)[source]#

Construct a rectangular cuboid mask

Parameters:
  • lx (float) – Length in x-direction

  • ly (float) – Length in y-direction

  • lz (float) – Length in z-direction

  • center (ndarray(shape=(3,), dtype=float)) – Centroid

  • angles (ndarray(shape=(3,), dtype=float)) – [alpha, beta, gamma] ZXZ Euler angles

  • xs (ndarray(shape=(3,nx,ny,nz), dtype=int)) – Index grid of dimensions [3, nx, ny, nz]

Returns:

Lattice mask

Return type:

ndarray(shape=(nx,ny,nz), dtype=bool)

capsule(length, width, xs=None, angles=None, center=None)[source]#

Construct spherocylinder mask

Parameters:
  • length (float) – Length including endcaps

  • width (float) – Diameter of cylindrical region

  • center (ndarray(shape=(3,), dtype=float)) – Centroid

  • angles (ndarray(shape=(3,), dtype=float)) – [alpha, beta, gamma] ZXZ’ Euler angles

  • xs (ndarray(shape=(3,nx,ny,nz), dtype=int)) – Index grid of dimensions [3, nx, ny, nz]

Returns:

Lattice mask

Return type:

ndarray(shape=(nx,ny,nz), dtype=bool)

classmethod closing(binaryMask, radius=None, se=None, radius1=None, se1=None)[source]#

Morphological closing of a binary mask

Parameters:
  • binaryMask (ndarray(shape=(nx,ny,nz), dtype=bool)) – Binary mask

  • radius (int) – If provided use a 6-connected structuring element iterated radius times.

  • radius1 (int) – If provided use the iterated SE for the erosion (optional)

  • se (ndarray(shape=(nx,ny,nz), dtype=bool)) – Structuring element

  • se1 (ndarray(shape=(nx,ny,nz), dtype=bool)) – Structuring element for erosion (optional)

Returns:

Closed lattice

Return type:

ndarray(shape=(nx,ny,nz), dtype=bool)

compose(*siteSpec, net=None)[source]#

Compose a series of binary masks into a site lattice

This function takes an indefinite number of (region, mask) tuples. The lattice is created by setting the lattice to the index of region over all masked subvolumes in the order given.

Parameters:
  • *siteSpec ((Region, ndarray(shape=(nx,ny,nz), dtype=bool))) – Region, mask tuple

  • net (SpatialModel) – If given, modify this model’s site lattice

classmethod convexHull(binaryMask)[source]#

Convex hull of lattice

Parameters:

binaryMask (ndarray(shape=(nx,ny,nz), dtype=bool)) – Binary mask

Returns:

Convex hull of lattice

Return type:

ndarray(shape=(nx,ny,nz), dtype=bool)

cylinder(radius, length, xs=None, angles=None, center=None)[source]#

Construct cylinder mask

Parameters:
  • radius (float) – Radius

  • length (float) – Length

  • center (ndarray(shape=(3,), dtype=float)) – Centroid

  • angles (ndarray(shape=(3,), dtype=float)) – [alpha, beta, gamma] ZXZ’ Euler angles

  • xs (ndarray(shape=(3,nx,ny,nz), dtype=int)) – Index grid of dimensions [3, nx, ny, nz]

Returns:

Lattice mask

Return type:

ndarray(shape=(nx,ny,nz), dtype=bool)

classmethod dilate(binaryMask, radius=None, se=None)[source]#

Morphological dialation of a binary mask

Parameters:
  • binaryMask (ndarray(shape=(nx,ny,nz), dtype=bool)) – Binary mask

  • radius (int) – If provided use a 6-connected structuring element iterated radius times.

  • se (ndarray(shape=(nx,ny,nz), dtype=bool)) – Structuring element

Returns:

Dilated lattice

Return type:

ndarray(shape=(nx,ny,nz), dtype=bool)

ellipsoid(xs=None, radius=None, angles=None, center=None)[source]#

Construct ellipsoid mask

Parameters:
  • radius (ndarray(shape=(3,), dtype=float)) – Semiaxes of ellipse

  • center (ndarray(shape=(3,), dtype=float)) – Centroid

  • angles (ndarray(shape=(3,), dtype=float)) – [alpha, beta, gamma] ZXZ’ Euler angles

  • xs (ndarray(shape=(3,nx,ny,nz), dtype=int)) – Index grid of dimensions [3, nx, ny, nz]

Returns:

Lattice mask

Return type:

ndarray(shape=(nx,ny,nz), dtype=bool)

emptyLatticeMask()[source]#

Return an empty lattice mask

classmethod erode(binaryMask, radius=None, se=None)[source]#

Morphological erosion of a binary mask

Parameters:
  • binaryMask (ndarray(shape=(nx,ny,nz), dtype=bool)) – Binary mask

  • radius (int) – If provided use a 6-connected structuring element iterated radius times.

  • se (ndarray(shape=(nx,ny,nz), dtype=bool)) – Structuring element

Returns:

Eroded lattice

Return type:

ndarray(shape=(nx,ny,nz), dtype=bool)

static octoStructElem(r)[source]#

Iterated 6-connected structuring element

Parameters:

r (int) – Number of iterations

Returns:

Structuring element

Return type:

ndarray(shape=(nx,ny,nz), dtype=bool)

classmethod opening(binaryMask, radius=None, se=None, radius1=None, se1=None)[source]#

Morphological opening of a binary mask

Parameters:
  • binaryMask (ndarray(shape=(nx,ny,nz), dtype=bool)) – Binary mask

  • radius (int) – If provided use a 6-connected structuring element iterated radius times.

  • radius1 (int) – If provided use the iterated SE for the dilation (optional)

  • se (ndarray(shape=(nx,ny,nz), dtype=bool)) – Structuring element

  • se1 (ndarray(shape=(nx,ny,nz), dtype=bool)) – Structuring element for dilation (optional)

Returns:

Opened lattice

Return type:

ndarray(shape=(nx,ny,nz), dtype=bool)

static showBinaryLattices(*args, **kwargs)#
static showStack(*args, **kwargs)#
static sphereStructElem(r)[source]#

Spherical structuring element

Parameters:

r (int) – radius

Returns:

Structuring element

Return type:

ndarray(shape=(nx,ny,nz), dtype=bool)

spoke(x0, length, spoke_radius, r, phi, theta)[source]#

Construct spoke

For a sphere of radius, \(r\), centered on \(x_0\), a spoke is a cylinder centered on the surface of the sphere at the polar coordinates \((r,\phi,\theta)\), rotated to be normal to the sphere surface.

Parameters:
  • x0 (ndarray(shape=(3,), dtype=float)) – Center of sphere

  • length (float) – Length of spoke. Spoke will protrude 0.5*length from the inside and outside of the sphere

  • spoke_radius (float) – Radius (thickness) of the spoke

  • r (float) – Radius of sphere

  • phi (float) – Azimuthal position of spoke with respect to the sphere center

  • theta (float) – Polar position of spoke with respect to the sphere center

Returns:

Lattice mask

Return type:

ndarray(shape=(nx,ny,nz), dtype=bool)

static transformGrid(xs, x0, alpha, beta, gamma)[source]#

Compute the translation/rotation of an index grid

Parameters:
  • xs (ndarray(shape=(3,nx,ny,nz), dtype=int)) – Index grid of dimensions [3, nx, ny, nz]

  • x0 (ndarray(shape=(3,), dtype=float)) – Center of rotation

  • alpha (float) – Euler Z-rotation (radians)

  • beta (float) – Euler X-rotation (radians)

  • gamma (float) – Euler Z’-rotation (radians)

Returns:

Transformed grid

Return type:

ndarray(shape=(3,nx,ny,nz), dtype=int)

property se26#

Structuring element connecting all 26 neighbors

property se6#

Structuring element connecting all 6 nearest neighbors

xs#

Index grid of dimensions [3, nx, ny, nz]