Skip to content

Commit

Permalink
In base_camera.py, refactor how the start/end integration works to al…
Browse files Browse the repository at this point in the history
…low returning from a take image sequence as soon as the last image finishes exposing, instead of having to wait for the endReadout event.
  • Loading branch information
tribeiro committed Dec 3, 2024
1 parent dc3fc2f commit d7524e8
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions python/lsst/ts/observatory/control/base_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ async def _handle_snaps(self, camera_exposure: CameraExposure) -> typing.List[in
float(camera_exposure.exp_time) + self.read_out_time
) * camera_exposure.n + self.long_long_timeout

self.camera.evt_endReadout.flush()
await self.wait_for_camera_readiness()
await self.camera.cmd_takeImages.start(timeout=take_images_timeout)

exp_ids: typing.List[int] = []
Expand All @@ -1232,6 +1232,43 @@ async def _handle_snaps(self, camera_exposure: CameraExposure) -> typing.List[in

return exp_ids

async def wait_for_camera_readiness(self) -> None:
"""Wait until the camera is ready to take data."""
try:
self.camera.evt_endReadout.flush()
last_start_integration, last_end_readout = await asyncio.gather(
self.camera.evt_startIntegration.aget(timeout=self.long_timeout),
self.camera.evt_endReadout.aget(timeout=self.long_timeout),
)
except asyncio.TimeoutError:
self.log.info(
"Timeout getting last camera start integration and/or end readout events. "
"This usually means no data was taken with the camera yet, "
"or there is loss of historical data. Assuming camera is "
"ready to take data."
)
return

while last_end_readout.imageName != last_start_integration.imageName:
self.log.info(
f"Last integration started: {last_start_integration.imageName}, "
f"last integration completed: {last_end_readout.imageName}."
)
next_end_readout_timeout = (
self.long_timeout + last_start_integration.exposureTime
)
try:
last_end_readout = await self.camera.evt_endReadout.next(
flush=False, timeout=next_end_readout_timeout
)
except asyncio.TimeoutError:
raise RuntimeError(
f"No new end readout event in {next_end_readout_timeout}s. "
f"Cannot determine if camera is ready to take data."
)

self.camera.evt_startIntegration.flush()

async def _handle_take_stuttered(
self, camera_exposure: CameraExposure
) -> typing.List[int]:
Expand Down Expand Up @@ -1329,12 +1366,12 @@ async def next_exposure_id(self) -> int:
int
Exposure id from next endReadout event.
"""
end_readout = await self.camera.evt_endReadout.next(
start_integration = await self.camera.evt_startIntegration.next(
flush=False, timeout=self.long_long_timeout
)
# parse out visitID from filename
# (Patrick comment) this is highly annoying
_, _, yyyymmdd, seq_num = end_readout.imageName.split("_")
_, _, yyyymmdd, seq_num = start_integration.imageName.split("_")

return int((yyyymmdd + seq_num[1:]))

Expand Down

0 comments on commit d7524e8

Please sign in to comment.