Skip to content

Experiment factory module

This module contains helper classes and functions for creating ExperimentLevel instances using simplified parameters for each experiment type. Those instances should be used with Nd2Writer instance for altering / creating .nd2 files.

Info

Since this module is used to creating experiment data structures, you should not use any part of this module if you only read an .nd2 file.

For creating experiments, you should use ExperimentFactory class.

ExperimentFactory

ExperimentFactory(*, t: int | dict[str, Any] | None = None, m: int | dict[str, Any] | None = None, z: int | dict[str, Any] | None = None)

Helper class for creating experiments, see examples below on how to create timeloop, multipoint and z-stack experiments either directly on factory constructor or by modifying values later.

To actually create experiment instance, make sure to call either .createExperiment() method or use call operator.

Sample usage
from limnd2.experiment_factory import ExperimentFactory

# only frame counts
print(ExperimentFactory(t=10, m=5).createExperiment())
See example output

Timeloop experiment(10 frames, interval: No Delay, duration: Continuous), Multipoint experiment(5 frames, point coordinates: [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0])

# values from dict
print(ExperimentFactory(t={"count" : 3, "step": 350}, z={"count" : 5, "step": 150}).createExperiment())
See example output

Timeloop experiment(3 frames, interval: 0:00:00.350, duration: Continuous), Z-Stack experiment(5 frames, step: 150.0)

# combination
print(ExperimentFactory(t=3, z={"count" : 5, "step": 150}).createExperiment())
See example output

Timeloop experiment(3 frames, interval: No Delay, duration: Continuous), Z-Stack experiment(5 frames, step: 150.0)

# create factory and modify it
fac = ExperimentFactory()
fac.z.count = 10
fac.z.step = 100
print(fac())            # createExperiment is called implicitly
See example output

Z-Stack experiment(10 frames, step: 100.0)

fac = ExperimentFactory()
fac.m.addPoint(10, 50)
fac.m.addPoint(20, 70)
print(fac())
See example output

Multipoint experiment(2 frames, point coordinates: [10.0, 50.0], [20.0, 70.0])

# inlined multipoint
print(ExperimentFactory(t=3, z={"count" : 5, "step": 150}, m={"count" : 3, "xcoords" : [10,20,30], "ycoords" : [40,50,60]})())
See example output

Timeloop experiment(3 frames, interval: No Delay, duration: Continuous), Multipoint experiment(3 frames, point coordinates: [10.0, 40.0], [20.0, 50.0], [30.0, 60.0]), Z-Stack experiment(5 frames, step: 150.0)

fac = ExperimentFactory()
fac.t.count = 10
fac.z.step = 100
print(fac())

Warning

In this example Z-Stack experiment will be omitted from output since Z-stack frame count is not set, even though Z-stack step property was defined.

See example output

Timeloop experiment(10 frames, interval: No Delay, duration: Continuous)

__call__

__call__() -> ExperimentLevel | None

Create ExperimentLevel instance using specified settings.

createExperiment

createExperiment() -> ExperimentLevel | None

Create ExperimentLevel instance using specified settings.