photon_mosaic.core.motion#
Functions
|
Estimate motion for |
|
Return the class that applies motion computed by |
|
Register a |
|
Register the class that applies motion computed by |
Classes
|
Algorithm-agnostic container for motion correction artifacts. |
- photon_mosaic.core.motion.register_motion_class(motion_class)[source]#
Register a
Motionsubclass under itsmethod_name.Backend modules call this at import time so that
Motion.compute(..., method=...)can find them. Third-party backends can call it too, which is what makes the set of methods extensible.
- photon_mosaic.core.motion.register_registration_class(method, registration_class)[source]#
Register the class that applies motion computed by
method.Backend modules call this at import time, independently of
register_motion_class(), so thatphoton_mosaic.preprocessing.registration.RegisterImagingcan find the class that knows how to apply their motion.- Returns:
registration_class, unchanged, so this can be used as a decorator.- Return type:
type
- photon_mosaic.core.motion.get_registration_class(method)[source]#
Return the class that applies motion computed by
method.Built-in backends are imported lazily on first use, mirroring
_get_motion_class().- Return type:
type
- class photon_mosaic.core.motion.Motion(imaging, displacements, reference=None, yranges=None, xranges=None, corrected_badframes=None, metadata=None)[source]#
Algorithm-agnostic container for motion correction artifacts.
Holds outputs that any motion correction backend (Suite2P, CaImAn, …) is expected to produce. Backend-specific fields (e.g. Suite2P
opsor block-wise non-rigid offsets) belong on dedicated subclasses such asSuite2PMotion.Subclasses declare two class attributes so that they can be reached through
compute():method_name(the string users pass asmethod) andsettings_class(their pydantic settings model).The class that knows how to apply the stored motion (a
BasePreprocessorEpoch) is unrelated toMotionitself: a backend registers it under the samemethod_nameviaregister_registration_class(), independently of whether or how it registers itsMotionsubclass, andphoton_mosaic.preprocessing.registration.RegisterImagingresolves it viaget_registration_class().- Attributes:
- method_name
num_epochsNumber of epochs represented in the stored displacements.
- settings_class
Methods
compute(imaging[, method, settings, badframes])Estimate motion for
imagingwith the requested backend.from_dict(motion_dict, imaging)Rebuild a motion from
to_dict()output, as is or reloaded from json.get_displacement_at_frames(frame_indices[, ...])Return displacement vectors for the requested frames.
to_dict()Return a json-serializable description of this motion (with
SIJsonEncoder).- method_name: str | None = None#
- settings_class: type | None = None#
- classmethod compute(imaging, method=None, settings=None, badframes=None, **params)[source]#
Estimate motion for
imagingwith the requested backend.Called on
Motionitself,methodselects the backend (default"suite2p"); called on a subclass, that subclass is used andmethod, if given, must match itsmethod_name.- Parameters:
imaging (
BaseImaging) – Imaging object containing one or more epochs/planes to register.method (
Union[Literal['suite2p','jnormcorre'],str,None]) – Registration backend, e.g."suite2p".settings (
Any) – Backend settings. Dicts andNoneare coerced into the backend’ssettings_class.badframes (
NDArray|None) – Boolean array of shape(n_frames,)marking frames to exclude from reference image computation.**params (
Any) – Extra backend options, overridingsettings.
- Returns:
A backend-specific
Motionsubclass instance.- Return type:
- to_dict()[source]#
Return a json-serializable description of this motion (with
SIJsonEncoder).imagingis not included: the owner of the motion (e.g.photon_mosaic.preprocessing.registration.RegisterImaging) serializes it already and passes it back tofrom_dict().- Return type:
dict[str,Any]
- classmethod from_dict(motion_dict, imaging)[source]#
Rebuild a motion from
to_dict()output, as is or reloaded from json.Called on
Motionitself, the subclass is resolved from the storedmethod; called on a subclass, that subclass is used.- Return type:
- property num_epochs: int#
Number of epochs represented in the stored displacements.
- get_displacement_at_frames(frame_indices, plane_index=None, epoch_index=0)[source]#
Return displacement vectors for the requested frames.
With
plane_index=Nonethe planes axis is preserved ((..., n_planes, 2)); with an integerplane_indexit is dropped ((..., 2)).- Return type:
NDArray[floating[Any]]
- photon_mosaic.core.motion.compute_motion(imaging, method=None, settings=None, badframes=None, **params)#
Estimate motion for
imagingwith the requested backend.Called on
Motionitself,methodselects the backend (default"suite2p"); called on a subclass, that subclass is used andmethod, if given, must match itsmethod_name.- Parameters:
imaging (
BaseImaging) – Imaging object containing one or more epochs/planes to register.method (
Union[Literal['suite2p','jnormcorre'],str,None]) – Registration backend, e.g."suite2p".settings (
Any) – Backend settings. Dicts andNoneare coerced into the backend’ssettings_class.badframes (
NDArray|None) – Boolean array of shape(n_frames,)marking frames to exclude from reference image computation.**params (
Any) – Extra backend options, overridingsettings.
- Returns:
A backend-specific
Motionsubclass instance.- Return type: