pept.processing.DynamicProbability2D#
- class pept.processing.DynamicProbability2D(diameter, column, dimensions='xy', resolution=(512, 512), xlim=None, ylim=None, max_workers=None, verbose=True)[source]#
Bases:
Reducer
Compute the 2D probability distribution of some tracer quantity (eg velocity in each cell).
Reducer signature:
PointData -> DynamicProbability2D.fit -> Pixels list[PointData] -> DynamicProbability2D.fit -> Pixels numpy.ndarray -> DynamicProbability2D.fit -> Pixels
This reducer calculates the average value of the tracer quantity in each cell of a 2D pixel grid; it uses the full projected tracer area for the pixelization step, so the distribution is accurate for arbitrarily fine resolutions.
- Parameters
- diameter
float
The diameter of the imaged tracer.
- column
str
orint
The PointData column used to compute the probability distribution, given as a name (str) or index (int).
- dimensions
str
orlist
[int
],default
“xy” The tracer coordinates used to rasterize its trajectory, given as a string (e.g. “xy” projects the points onto the XY plane) or a list with two column indices (e.g. [1, 3] for XZ).
- resolution
tuple
[int
,int
],default
(512, 512) The number of pixels used for the rasterization grid in the X and Y 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).
- 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
str
default
True
If True, time the computation and print the state of the execution.
- diameter
Examples
Compute the velocity probability distribution of a single tracer trajectory having a column named “v” corresponding to the tracer velocity:
>>> trajectories = pept.load(...) >>> pixels_vel = DynamicProbability2D(1.2, "v", "xy").fit(trajectories)
Plot the pixel grid:
>>> from pept.plots import PlotlyGrapher2D >>> PlotlyGrapher2D().add_pixels(pixels_vel).show()
For multiple tracer trajectories, you can use
Segregate
thenSplitAll('label')
before calling this reducer to rasterize each trajectory separately:>>> vel_pipeline = pept.Pipeline([ >>> Segregate(20, 10), >>> SplitAll("label"), >>> DynamicProbability2D(1.2, "v", "xy") >>> ]) >>> pixels_vel = vel_pipeline.fit(trajectories)
- __init__(diameter, column, dimensions='xy', resolution=(512, 512), xlim=None, ylim=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
filename
orfile
handle
If filepath is a path (rather than file handle), it is relative to where python is called.
- filepath
- Returns
pept.PEPTObject
subclass
instance
The 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
filename
orfile
handle
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")