spheres_from_coords¶
- spheres_from_coords(df, mode='contained', smooth=False)[source]¶
Generates a sphere packing given a list of centers and radii
- Parameters:
df (DataFrame or dict) – The X, Y, Z center coordinates, and radius R of each sphere in the packing should be stored in their own column or key. The units should be in voxels. See
Notes
for more detail on how this should be formatted. If one of the dimensions has all 0’s then a 2D image is generated.smooth (bool) – Indicates if spheres should be smooth or have the single pixel bump on each face.
mode (str) –
How edges are handled. Options are:
mode
description
’contained’
(default) All spheres are fully contained within the image, meaning the image is padded beyond extents of the given coordinates by the maximum radius of the given sphere radii to ensure they all fit.
’extended’
Spheres extend beyond the edge of the image. In this mode the image is only as large enough to hold the given coordinates so the spheres may extend beyond the image boundary.
- Returns:
spheres – A numpy ndarray of
True
values indicating the spheres andFalse
elsewhere. The size of the returned image will be large enough to fit all the spheres plus the radius of the largest sphere.- Return type:
ndarray
Notes
The input data should be in column format as a dictionary of 1D numpy arrays like this:
d['X'] = np.array([1, 1, 2]) d['Y'] = np.array([1, 3, 2]) d['Z'] = np.array([1, 1, 1]) d['R'] = np.array([0.5, 0.7, 0.6])
Or a pandas ``DataFrame` like this:
ID
‘X’
‘Y’
‘Z’
‘R’
0
1
1
1
0.5
1
1
3
1
0.7
2
2
2
1
0.6
Or a numpy N-by-3(or 4) array like this:
array([[1, 1, 1, 0.5], [1, 3, 1, 0.7], [2, 2, 1, 0.6]])
Note that in all cases if the radius is not given that it is assumed to be a single pixel