Custom Pipelines#
The pipeline module provides a general chunked pipeline entry point
(massphoto.process()) and workflow helpers.
By default, parallel outputs carry an analysis_record in
DataFrame.attrs (attach_record=True in high-level APIs). Use
massphoto.resolve_record() to turn that record back into a defaults-aware
replay callable.
Pipeline Type Markers#
When assembling custom pipelines with massphoto.process(), function parameters
use type annotations to declare what data representation they consume (see
Define a custom detection function in the tutorial gallery):
- massphoto.NativeMovie: NewType('NativeMovie', np.ndarray)#
Annotates parameters that expect raw camera movie frames
(frames, y, x). The chunked pipeline runner passes slices of the original input movie to these parameters.
- massphoto.RatiometricMovie: NewType('RatiometricMovie', np.ndarray)#
Annotates parameters that expect background-subtracted ratiometric images. When requested, the pipeline ensures ratiometric frames are generated before invoking the step.
- massphoto.EventList: NewType('EventList', pd.DataFrame)#
Annotates functions returning or processing detected events in a
pandas.DataFramecontaining required spatial coordinates (x,y) and frame indices (frame).
Module Reference#
- massphoto.pipeline.resolve_record(obj, *, apply_defaults=False)[source]#
Resolve an analysis record into defaults overrides and a replay callable.
Note
Available as both
massphoto.resolve_recordandmassphoto.pipeline.resolve_record.- Parameters:
- Returns:
(defaults_overrides, replay_callable)where:defaults_overridesis the merged defaults state inferred from the record and its origin kwargs.replay_callableis a defaults-wrapped callable for the recorded origin (process,detect, orfit), preloaded withdefaults_overrides.
- Return type:
- Raises:
TypeError – If
objis neither a record dict nor a DataFrame with dictattrs['analysis_record'], or iforigin_kwargsis not a dict.ValueError – If required record keys are missing, the schema version is unsupported, or the record origin is unknown. The supported schema version is 2.
- massphoto.pipeline.process(movie, steps, *, events=None, movie_template=None, movie_normalize_frame_means=False, movie_correct_drift=False, return_ratiometric=False, ratiometric_args=None, ratiometric_func=<function calc_ratiometric>, chunk_overlap=-1, chunk_size=1000, postprocess=(), scheduler=None, progress_bar=True, attach_record=True, compute_movie_metrics=False)[source]#
Run a chunked, parallel processing pipeline over a movie.
Note
Available as both
massphoto.processandmassphoto.pipeline.process.Each step is a (callable, kwargs) pair. Inputs for each callable are inferred from type annotations (NativeMovie, RatiometricMovie, EventList/pd.DataFrame). Optional precomputed events can be provided to seed the pipeline.
movie_templateis the global native reference image used by movie-level preprocessing. Whenmovie_normalize_frame_means=True, each native frame is scaled so its mean matchesmovie_template.mean(). Whenmovie_correct_drift=True, the same template is passed to drift correction. If needed and not supplied, the template is computed as the mean image of the input movie.The optional postprocess callables are applied to the final (non-chunked) DataFrame after compute.
When
attach_record=True(default), the returned DataFrame stores ananalysis_recordinDataFrame.attrs. The record captures enough provenance to replay the analysis with equivalent defaults context:defaults_state: a copy ofmassphoto.defaultsat runtime.originandorigin_kwargs: the entry-point function name and the captured call kwargs.movie_info: input movie shape and dtype.
For tuple outputs (
return_ratiometric=True), the record is attached to the DataFrame element. Useresolve_record()to reconstruct a replay callable from the stored record.- Parameters:
movie_template (ndarray | None)
movie_normalize_frame_means (bool)
movie_correct_drift (bool)
return_ratiometric (bool)
ratiometric_args (dict | None)
ratiometric_func (Callable | None)
chunk_overlap (int)
chunk_size (int)
scheduler (str | None)
progress_bar (bool)
attach_record (bool)
compute_movie_metrics (bool)