pymmcore-plus / useq-schema

An implementation agnostic schema for describing a sequence of events during a multi-dimensional imaging acquisition.
https://pymmcore-plus.github.io/useq-schema/
BSD 3-Clause "New" or "Revised" License
15 stars 5 forks source link

Time plans with no delay and indeterminate length #156

Open tlambert03 opened 7 months ago

tlambert03 commented 7 months ago

It should be possible to specify a time plan with no delay but some known duration of number of loops (e.g. time_plan=TIntervalDuration(interval=0, duration=3)) ... and it is possible to instantiate it... but when you iterate over it in an MDASequence, you'll get an error:

File ~/dev/self/useq-schema/src/useq/_time.py:72, in TimePlan.deltas(self)
     70 def deltas(self) -> Iterator[datetime.timedelta]:
     71     current = timedelta(0)
---> 72     for _ in range(self.loops):  # type: ignore  # TODO
     73         yield current
     74         current += self.interval

File ~/dev/self/useq-schema/src/useq/_time.py:145, in TIntervalDuration.loops(self)
    143 @property
    144 def loops(self) -> int:
--> 145     return self.duration // self.interval + 1

ZeroDivisionError: integer division or modulo by zero

For this to work, I think the consumer (such as MDARunner.run) might actually need to special case an MDASequence with a TIntervalDuration plan of interval 0... or we should add something to MDAEvent like a kill_time: a total duration after which the experiment should be stopped.