pumapy.generation

pumapy.generation.cylinder_square_array

class pumapy.generation.cylinder_square_array.GeneratorSquareArray(size, porosity)[source]

Bases: object

error_check()[source]
generate()[source]
log_input()[source]
log_output()[source]
pumapy.generation.cylinder_square_array.generate_cylinder_square_array(size, porosity, segmented=True)[source]

Generate a 2D periodic array of circles

Parameters
  • size (int) – length of one side of the output domain

  • porosity (float) – porosity of the output domain

  • segmented (bool) – return a domain that is already segmented (i.e. each sphere with unique ID) or with grayscales 0-255 with threshold=128 for the input diameter

Returns

array of circles

Return type

Workspace

Example

>>> import pumapy as puma
>>> ws = puma.generate_cylinder_square_array(100, 0.8, segmented=True)
>>> puma.render_volume(ws)

pumapy.generation.random_fibers

The following function was copied and modified from the porespy project (distributed under the MIT License). See https://github.com/PMEAL/porespy/blob/dev/porespy/generators/_imgen.py for more information. See https://github.com/PMEAL/porespy/blob/dev/LICENSE for the license.

pumapy.generation.random_fibers.generate_random_fibers(shape, radius, nfibers=None, porosity=None, phi=90.0, theta=90.0, length=None, max_iter=3, allow_intersect=True, segmented=True)[source]

Generates random fibers from number of fibers or porosity

Parameters
  • shape ((int, int, int)) – the shape of the workspace to generate in (Nx, Ny, Nz) where N is the number of voxels.

  • radius (int) – the radius of the fibers in voxels

  • nfibers (int) – the number of fibers to add to the domain. Adjust this value to control the final porosity, which is not easily specified since cylinders overlap and intersect different fractions of the domain

  • porosity (float) – the target value for the porosity of the generated mat. The function uses an algorithm for predicting the number of required number of cylinder, and refines this over a certain number of fractional insertions (according to the ‘iterations’ input)

  • phi (float) – a value between 0 and 90 that controls the amount that the fibers lie out of the XY plane, with 0 meaning all fibers lie in the XY plane, and 90 meaning that cylinders are randomly oriented out of the plane by as much as +/- 90 degrees

  • theta (float) – a value between 0 and 90 that controls the amount of rotation in the XY plane, with 0 meaning all fibers point in the X-direction, and 90 meaning they are randomly rotated about the Z axis by as much as +/- 90 degrees

  • length (float) – the length of the cylinders to add. If None (default) then the cylinders will extend beyond the domain in both directions so no ends will exist. If a scalar value is given it will be interpreted as the Euclidean distance between the two ends of the cylinder. Note that one or both of the ends may still lie outside the domain, depending on the randomly chosen center point of the cylinder

  • max_iter (int) – the number of fractional fiber insertions used to target the requested porosity. By default a value of 3 is used (and this is typically effective in getting very close to the targeted porosity), but a greater number can be input to improve the achieved porosity

  • allow_intersect (bool) – allow intersection betweem the fibers

  • segmented (bool) – return a domain that is already segmented (i.e. each fiber with unique ID) or with grayscales 0-255 with threshold=128 for the input diameter

Returns

random fibers domain

Return type

Workspace

Example

>>> import pumapy as puma
>>> # specify porosity
>>> ws_fibers = puma.generate_random_fibers(shape=(100, 100, 100), radius=4, porosity=0.8, phi=90, theta=90, length=200, allow_intersect=True, segmented=True)
>>> puma.render_volume(ws_fibers, cutoff=(1, ws_fibers.max()), cmap='jet')
>>> puma.render_orientation(ws_fibers)
>>> # specify number of fibers
>>> ws_fibers = puma.generate_random_fibers(shape=(100, 100, 100), radius=4, nfibers=100, phi=90, theta=90, length=200, allow_intersect=True, segmented=False)
>>> puma.render_volume(ws_fibers, cutoff=(1, ws_fibers.max()), cmap='jet')
>>> puma.render_orientation(ws_fibers)
>>> # don't allow intersection between fibers
>>> ws_fibers = puma.generate_random_fibers(shape=(100, 100, 100), radius=4, porosity=0.8, phi=90, theta=90, length=200, allow_intersect=False, segmented=True)
>>> puma.render_volume(ws_fibers, cutoff=(1, ws_fibers.max()), cmap='jet')
>>> puma.render_orientation(ws_fibers)

pumapy.generation.random_spheres

class pumapy.generation.random_spheres.GeneratorSpheres(size, diameter, porosity, allow_intersect, segmented)[source]

Bases: object

error_check()[source]
generate()[source]
log_input()[source]
log_output()[source]
pumapy.generation.random_spheres.generate_random_spheres(shape, diameter, porosity, allow_intersect=True, segmented=True)[source]

Generation of random spheres domains

Parameters
  • shape ((int, int, int)) – shape of 3D domain (x,y,z)

  • diameter (float) – diameter of the random spheres in voxels

  • porosity (float) – target porosity of the generated structure

  • allow_intersect (bool) – allow the spheres to intersect or not

  • segmented (bool) – return a domain that is already segmented (i.e. each sphere with unique ID) or with grayscales 0-255 with threshold=128 for the input diameter

Returns

random spheres domain

Return type

Workspace

Example

>>> import pumapy as puma
>>> ws_generated = puma.generate_random_spheres(shape=(100,100,100), diameter=10, porosity=0.8, allow_intersect=True, segmented=True)
>>> puma.render_volume(ws_generated, cutoff=(1, ws_generated.max()), cmap='jet')

pumapy.generation.single_sphere

class pumapy.generation.single_sphere.GeneratorSphere(size, center, diameter)[source]

Bases: object

error_check()[source]
generate()[source]
log_input()[source]
log_output()[source]
pumapy.generation.single_sphere.generate_sphere(shape, center, diameter, segmented=True)[source]

Generation of a sphere at a given point and diameter

Parameters
  • shape ((int, int, int)) – size of 3D domain (x,y,z)

  • center ((int, int, int)) – centerpoint of sphere (x,y,z)

  • diameter (float) – diameter of the random spheres in voxels

  • segmented (bool) – return a domain that is already segmented (i.e. each sphere with unique ID) or with grayscales 0-255 with threshold=128 for the input diameter

Returns

domain with sphere with input diameter

Return type

Workspace

Example

>>> import pumapy as puma
>>> ws = puma.generate_sphere((100, 100, 100), (50, 50, 50), 80)
>>> puma.render_volume(ws.matrix[:ws.matrix.shape[0]//2])
pumapy.generation.single_sphere.get_circle(diameter)[source]
pumapy.generation.single_sphere.get_circle_even(diameter)[source]
pumapy.generation.single_sphere.get_circle_odd(diameter)[source]
pumapy.generation.single_sphere.get_sphere(diameter)[source]

pumapy.generation.tpms

class pumapy.generation.tpms.GeneratorTPMS(size, w, q, equation)[source]

Bases: object

error_check()[source]
generate()[source]
log_input()[source]
log_output()[source]
pumapy.generation.tpms.generate_tpms(shape, w, q, equation=0, segmented=True)[source]

Generation of triply periodic minimal surface material

Parameters
  • shape ((int, int, int)) – shape of 3D domain (x,y,z)

  • w (float or (float, float)) – w parameter for tpms

  • q (float or (float, float)) – q parameter for tpms (float or tuple)

  • equation (int) – equation 0, 1, or 2 for tpms

  • segmented (bool) – return a domain that is already segmented (i.e. 1 for solid and 0 for void) or with grayscales 0-255 with threshold=128 for the solid

Returns

TPMS domain with grayscales from 0-255 with threshold=128 for the normal TPMS geometry

Return type

Workspace

Example

>>> import pumapy as puma
>>> shape = (200, 200, 200)  # size of the domain, in voxels.
>>> w = 0.08  # value of w in the equations above
>>> q = 0.2  # value of q in the equations above
>>> ws_eq0 = puma.generate_tpms(shape, w, q, equation=0, segmented=False)
>>> ws_eq1 = puma.generate_tpms(shape, w, q, equation=1, segmented=False)
>>> ws_eq2 = puma.generate_tpms(shape, w, q, equation=2, segmented=False)
>>> puma.render_contour(ws_eq0, cutoff=(128, 255)) #visualize the workspace
>>> puma.render_contour(ws_eq1, cutoff=(128, 255))
>>> puma.render_contour(ws_eq2, cutoff=(128, 255))

pumapy.generation.tpms_utils

pumapy.generation.tpms_utils.generate()

pumapy.generation.tpms_utils

pumapy.generation.tpms_utils.generate()