Skip to content

Commit

Permalink
Smarter subclassing.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfcrenshaw committed Dec 7, 2024
1 parent 64b20fc commit 0860671
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
__all__ = ["TakeAOSSequenceBalancedComCam"]

import asyncio
import json

from lsst.ts.standardscripts.maintel import Mode, TakeAOSSequenceComCam
from lsst.ts.standardscripts.maintel import TakeAOSSequenceComCam


class TakeAOSSequenceBalancedComCam(TakeAOSSequenceComCam):
Expand All @@ -47,128 +46,15 @@ class TakeAOSSequenceBalancedComCam(TakeAOSSequenceComCam):
* sequence {n} of {m}: before taking a sequence.
"""

async def take_aos_sequence(self) -> None:
"""Take out-of-focus sequence images."""
supplemented_group_id = self.next_supplemented_group_id()

if (
self.mode == Mode.TRIPLET
or self.mode == Mode.INTRA
or self.mode == Mode.PAIR
):
self.log.debug("Moving to intra-focal position")
async def _apply_z_offset(self, z_offset: float) -> None:
"""Apply dz offset.
# Move the camera and M2 hexapods to the target z position
# Offset split in half and shared between each hexapod
z_offset = (-self.dz - self.current_z_position) / 2
await self.mtcs.offset_camera_hexapod(x=0, y=0, z=z_offset, u=0, v=0)
await self.mtcs.offset_m2_hexapod(x=0, y=0, z=z_offset, u=0, v=0)
self.current_z_position = -self.dz

self.log.info("Taking intra-focal image")
self.camera.rem.ccoods.evt_imageInOODS.flush()
intra_visit_id = await self.camera.take_cwfs(
exptime=self.exposure_time,
n=1,
group_id=supplemented_group_id,
filter=self.filter,
reason="INTRA" + ("" if self.reason is None else f"_{self.reason}"),
program=self.program,
note=self.note,
)

if (
self.mode == Mode.TRIPLET
or self.mode == Mode.EXTRA
or self.mode == Mode.PAIR
):
self.log.debug("Moving to extra-focal position")

# Move the camera and M2 hexapods to the target z position
# Offset split in half and shared between each hexapod
z_offset = (self.dz - self.current_z_position) / 2
await self.mtcs.offset_camera_hexapod(x=0, y=0, z=z_offset, u=0, v=0)
await self.mtcs.offset_m2_hexapod(x=0, y=0, z=z_offset, u=0, v=0)
self.current_z_position = self.dz

self.log.info("Taking extra-focal image")

self.camera.rem.ccoods.evt_imageInOODS.flush()
extra_visit_id = await self.camera.take_cwfs(
exptime=self.exposure_time,
n=1,
group_id=supplemented_group_id,
filter=self.filter,
reason="EXTRA" + ("" if self.reason is None else f"_{self.reason}"),
program=self.program,
note=self.note,
)

if self.mode == Mode.TRIPLET or self.mode == Mode.PAIR:
self.log.debug("Waiting for images to be ingested in OODS.")
extra_image_ingested = False
while not extra_image_ingested:
try:
image_in_oods = await self.camera.rem.ccoods.evt_imageInOODS.next(
flush=False, timeout=self.exposure_time
)
try:
image_name_split = image_in_oods.obsid.split("_")
image_index = int(
f"{image_name_split[-2]}{image_name_split[-1][1:]}"
)
extra_image_ingested = image_index == extra_visit_id[0]
except Exception:
self.log.exception(
"Failed to parse image name into index for {image_in_oods.obsid}."
)

self.log.info(
f"Image {image_in_oods.obsid} {image_in_oods.raft} {image_in_oods.sensor} ingested."
)

except asyncio.TimeoutError:
self.log.warning(
"Timeout waiting for images to ingest. Continuing."
)
break
self.log.info("Send processing request to RA OCPS.")
config = {
"LSSTComCam-FROM-OCS_DONUTPAIR": f"{intra_visit_id[0]},{extra_visit_id[0]}"
}
ocps_execute_task = asyncio.create_task(
self.ocps.cmd_execute.set_start(
config=json.dumps(config),
timeout=self.camera.fast_timeout,
)
)

self.log.debug("Moving to in-focus position")

# Move the camera and M2 hexapods to the target z position
# Offset split in half and shared between each hexapod
z_offset = (-self.current_z_position) / 2
await self.mtcs.offset_camera_hexapod(x=0, y=0, z=z_offset, u=0, v=0)
await self.mtcs.offset_m2_hexapod(x=0, y=0, z=z_offset, u=0, v=0)
self.current_z_position = 0

if self.mode != Mode.PAIR:
self.log.info("Taking in-focus image")
self.camera.rem.ccoods.evt_imageInOODS.flush()
await self.camera.take_acq(
exptime=self.exposure_time,
n=1,
group_id=self.group_id,
filter=self.filter,
reason="INFOCUS" + ("" if self.reason is None else f"_{self.reason}"),
program=self.program,
note=self.note,
)

if self.mode == Mode.TRIPLET:
try:
await ocps_execute_task
except Exception:
self.log.exception("Executing OCPS task failed. Ignoring.")
Parameters
----------
z_offset : float
dz offset to apply, in microns.
"""
await self.mtcs.offset_camera_hexapod(x=0, y=0, z=z_offset / 2, u=0, v=0)
await self.mtcs.offset_m2_hexapod(x=0, y=0, z=z_offset / 2, u=0, v=0)

16 changes: 13 additions & 3 deletions python/lsst/ts/standardscripts/maintel/take_aos_sequence_comcam.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ async def configure_tcs(self) -> None:
else:
self.log.debug("MTCS already defined, skipping.")

async def _apply_z_offset(self, z_offset: float) -> None:
"""Apply dz offset.
Parameters
----------
z_offset : float
dz offset to apply, in microns.
"""
await self.mtcs.offset_camera_hexapod(x=0, y=0, z=z_offset, u=0, v=0)

async def take_aos_sequence(self) -> None:
"""Take out-of-focus sequence images."""
supplemented_group_id = self.next_supplemented_group_id()
Expand All @@ -257,7 +267,7 @@ async def take_aos_sequence(self) -> None:

# Move the hexapod to the target z position
z_offset = -self.dz - self.current_z_position
await self.mtcs.offset_camera_hexapod(x=0, y=0, z=z_offset, u=0, v=0)
self._apply_z_offset(z_offset)
self.current_z_position = -self.dz

self.log.info("Taking in-focus image")
Expand All @@ -281,7 +291,7 @@ async def take_aos_sequence(self) -> None:

# Move the hexapod to the target z position
z_offset = self.dz - self.current_z_position
await self.mtcs.offset_camera_hexapod(x=0, y=0, z=z_offset, u=0, v=0)
self._apply_z_offset(z_offset)
self.current_z_position = self.dz

self.log.info("Taking extra-focal image")
Expand Down Expand Up @@ -340,7 +350,7 @@ async def take_aos_sequence(self) -> None:

# Move the hexapod to the target z position
z_offset = -self.current_z_position
await self.mtcs.offset_camera_hexapod(x=0, y=0, z=z_offset, u=0, v=0)
self._apply_z_offset(z_offset)
self.current_z_position = 0

if self.mode != Mode.PAIR:
Expand Down

0 comments on commit 0860671

Please sign in to comment.