pept.processing.ResidenceDistribution3D#
- class pept.processing.ResidenceDistribution3D(diameter, column='t', dimensions='xyz', resolution=(50, 50, 50), xlim=None, ylim=None, zlim=None, max_workers=None, verbose=True)[source]#
Bases:
ReducerCompute the 3D residence distribution of some tracer quantity (eg time spent in each cell).
Reducer signature:
PointData -> ResidenceDistribution3D.fit -> Pixels list[PointData] -> ResidenceDistribution3D.fit -> Pixels numpy.ndarray -> ResidenceDistribution3D.fit -> Pixels
This reducer calculates the cumulative value of the tracer quantity in each cell of a 3D voxel grid; it uses the full projected tracer area for the voxelization step, so the distribution is accurate for arbitrarily fine resolutions.
- Parameters
- diameter
float The diameter of the imaged tracer.
- column
strorint The PointData column used to compute the probability distribution, given as a name (str) or index (int).
- dimensions
strorlist[int],default“xyz” The tracer coordinates used to rasterize its trajectory, given as a string (e.g. “xyz” or “zyx”) or a list with three column indices (e.g. [1, 2, 3] for XYZ).
- resolution
tuple[int,int,int],default(50, 50, 50) The number of pixels used for the rasterization grid in the X, Y, Z dimensions.
- xlim
tuple[float,float], optional The physical limits in the X dimension of the pixel grid. If unset, it is automatically computed to contain all tracer positions (default).
- ylim
tuple[float,float], optional The physical limits in the y dimension of the pixel grid. If unset, it is automatically computed to contain all tracer positions (default).
- zlim
tuple[float,float], optional The physical limits in the z dimension of the pixel grid. If unset, it is automatically computed to contain all tracer positions (default).
- max_workers
int, optional The maximum number of workers (threads, processes or ranks) to use by the parallel executor; if 1, it is sequential (and produces the clearest error messages should they happen). If unset, the
os.cpu_count()is used.- verbosebool or
strdefaultTrue If True, time the computation and print the state of the execution.
- diameter
Examples
Compute the residence time distribution of a single tracer trajectory:
>>> trajectories = pept.load(...) >>> voxels_rtd = ResidenceDistribution3D(1.2, "t").fit(trajectories)
Plot the pixel grid:
>>> from pept.plots import PlotlyGrapher >>> PlotlyGrapher().add_voxels(voxels_rtd).show()
For multiple tracer trajectories, you can use
SegregatethenSplitAll('label')before calling this reducer to rasterize each trajectory separately:>>> rtd_pipeline = pept.Pipeline([ >>> Segregate(20, 10), >>> SplitAll("label"), >>> ResidenceDistribution3D(1.2, "t") >>> ]) >>> voxels_rtd = rtd_pipeline.fit(trajectories)
- __init__(diameter, column='t', dimensions='xyz', resolution=(50, 50, 50), xlim=None, ylim=None, zlim=None, max_workers=None, verbose=True)[source]#
Methods
__init__(diameter[, column, dimensions, ...])copy([deep])Create a deep copy of an instance of this class, including all inner attributes.
fit(samples)load(filepath)Load a saved / pickled PEPTObject object from filepath.
save(filepath)Save a PEPTObject instance as a binary pickle object.
- copy(deep=True)#
Create a deep copy of an instance of this class, including all inner attributes.
- static load(filepath)#
Load a saved / pickled PEPTObject object from filepath.
Most often the full object state was saved using the .save method.
- Parameters
- filepath
filenameorfilehandle If filepath is a path (rather than file handle), it is relative to where python is called.
- filepath
- Returns
pept.PEPTObjectsubclassinstanceThe loaded object.
Examples
Save a LineData instance, then load it back:
>>> lines = pept.LineData([[1, 2, 3, 4, 5, 6, 7]]) >>> lines.save("lines.pickle")
>>> lines_reloaded = pept.LineData.load("lines.pickle")
- save(filepath)#
Save a PEPTObject instance as a binary pickle object.
Saves the full object state, including inner attributes, in a portable binary format. Load back the object using the load method.
- Parameters
- filepath
filenameorfilehandle If filepath is a path (rather than file handle), it is relative to where python is called.
- filepath
Examples
Save a LineData instance, then load it back:
>>> lines = pept.LineData([[1, 2, 3, 4, 5, 6, 7]]) >>> lines.save("lines.pickle")
>>> lines_reloaded = pept.LineData.load("lines.pickle")