pept.processing.SpatialProjections#
- class pept.processing.SpatialProjections(directory, start, end, dimension='x', num_divisions=500, max_distance=10, colorbar_col=-1, height=1000, width=1000, prefix='frame', **kwargs)[source]#
Bases:
Reducer
Project multiple tracer passes onto a moving 2D plane along a given direction between start and end coordinates, saving each frame in directory.
Reducer signature:
PointData -> SpatialProjections.fit -> None list[PointData] -> SpatialProjections.fit -> None list[np.ndarray] -> SpatialProjections.fit -> None
Each sample in the input `PointData` is treated as a separate streamline / tracer pass. You can group passes using `Segregate + GroupBy(“label”)`.
The generated images (saved in directory with height x width pixels) can be stitched into a video using pept.plots.make_video.
The extra keyword arguments
**kwargs
are passed to the histogram creation routine pept.plots.histogram. You can e.g. set the YAxis limits by adding ylim = [0, 20].New in pept-0.5.1
Examples
Consider a pipe-flow experiment, with tracers moving from side to side in multiple passes / streamlines. First locate the tracers, then split their trajectories into each individual pass:
>>> import pept >>> from pept.tracking import * >>> >>> split_pipe = pept.Pipeline([ >>> Segregate(window = 10, max_distance = 20), # Appends label column >>> GroupBy("label"), # Splits into samples >>> Reorient(), # Align with X axis >>> Center(), # Center points at 0 >>> Stack(), >>> ]) >>> streamlines = split_pipe.fit(trajectories)
Now each sample in streamlines corresponds to a single tracer pass, e.g. streamlines[0] is the first pass, streamlines[1] is the second. The passes were reoriented and centred such that the pipe is aligned with the X axis.
Now the RelativeDeviationsLinear reducer can be used to create images of the mixing between the pipe entrance and exit:
>>> from pept.processing import SpatialProjections >>> entrance_x = -100 # Pipe data was aligned with X >>> exit_x = 100 >>> SpatialProjections( >>> directory = "projections", # Creates directory to save images >>> start = entrance_x, >>> end = exit_x, >>> ).fit(streamlines)
Now the directory “projections” was created inside your current working folder, and eachc projected frame was saved there as “frame0000.png”, “frame0001.png”, etc. You can stitch all images together into a video using pept.plots.make_video:
>>> import pept >>> pept.plots.make_video( >>> "projections/frame*.png", >>> output = "projections/video.avi" >>> )
The raw projections can also be extracted directly:
>>> sp = SpatialProjections( >>> directory = "projections", # Creates directory to save images >>> p1 = entrance_x, >>> p2 = exit_x, >>> ) >>> sp.fit(streamlines) >>> sp.projections
- Attributes
- projections
list
[(N
, 5),np.ndarray
] A list of frames for each division between start and end, with each frame saving 5 columns [t, x, y, z, colorbar_col].
- projections
- __init__(directory, start, end, dimension='x', num_divisions=500, max_distance=10, colorbar_col=-1, height=1000, width=1000, prefix='frame', **kwargs)[source]#
Methods
__init__
(directory, start, end[, dimension, ...])copy
([deep])Create a deep copy of an instance of this class, including all inner attributes.
fit
(trajectories[, executor, max_workers, ...])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")