def __init__(self, index):
     super().__init__(
         index=index,
         descr="Slew and track a target with the main telescope.")
     self._mtcs = MTCS(self.domain,
                       intended_usage=MTCSUsages.Slew,
                       log=self.log)
    def __init__(self, index):

        super().__init__(index=index, descr="MTCS stop tracking.")

        self._mtcs = MTCS(self.domain,
                          intended_usage=MTCSUsages.Slew,
                          log=self.log)
    def __init__(self, index, add_remotes: bool = True):
        super().__init__(
            index=index,
            descr="Track target and take image with MainTel and ComCam.")

        mtcs_usage, comcam_usage = ((MTCSUsages.Slew,
                                     ComCamUsages.TakeImageFull)
                                    if add_remotes else
                                    (MTCSUsages.DryTest, ComCamUsages.DryTest))

        self.angle_filter_change = 0.0
        self.tolerance_angle_filter_change = 1e-2

        self.mtcs = MTCS(self.domain, intended_usage=mtcs_usage, log=self.log)
        self.comcam = ComCam(self.domain,
                             intended_usage=comcam_usage,
                             log=self.log)
Exemple #4
0
    def __init__(self, index):
        super().__init__(index=index, descr="Enable MTCS.")

        self.config = None

        self.mttcs = MTCS(self.domain,
                          intended_usage=MTCSUsages.Shutdown,
                          log=self.log)
    def __init__(self, index):

        super().__init__(index=index,
                         descr="Put all MTCS components in standby state.")

        self._mtcs = MTCS(self.domain,
                          intended_usage=MTCSUsages.StateTransition,
                          log=self.log)
    def __init__(self, index):
        super().__init__(index=index, descr="Enable MTCS.")

        self.config = None

        self._mtcs = MTCS(self.domain,
                          intended_usage=MTCSUsages.StateTransition,
                          log=self.log)
class TrackTargetAndTakeImageComCam(BaseTrackTargetAndTakeImage):
    """Track target and take image script.

    This script implements a simple visit consistig of slewing to a target,
    start tracking and take image.

    Parameters
    ----------
    index : `int`
        Index of Script SAL component.
    add_remotes : `bool` (optional)
        Create remotes to control components (default: `True`)? If False, the
        script will not work for normal operations. Useful for unit testing.
    """
    def __init__(self, index, add_remotes: bool = True):
        super().__init__(
            index=index,
            descr="Track target and take image with MainTel and ComCam.")

        mtcs_usage, comcam_usage = ((MTCSUsages.Slew,
                                     ComCamUsages.TakeImageFull)
                                    if add_remotes else
                                    (MTCSUsages.DryTest, ComCamUsages.DryTest))

        self.angle_filter_change = 0.0
        self.tolerance_angle_filter_change = 1e-2

        self.mtcs = MTCS(self.domain, intended_usage=mtcs_usage, log=self.log)
        self.comcam = ComCam(self.domain,
                             intended_usage=comcam_usage,
                             log=self.log)

    @classmethod
    def get_schema(cls):

        schema_dict = cls.get_base_schema()
        schema_dict[
            "$id"] = "https://github.com/lsst-ts/ts_standardscripts/maintel/track_target_and_take_image_comcam.py"
        schema_dict["title"] = "TrackTargetAndTakeImageComCam v1"
        schema_dict[
            "description"] = "Configuration for TrackTargetAndTakeImageComCam."

        return schema_dict

    async def track_target_and_setup_instrument(self):
        """Track target and setup instrument in parallel."""

        current_filter = await self.comcam.get_current_filter()

        self.tracking_started = True

        if current_filter != self.config.band_filter:
            self.log.debug(
                f"Filter change required: {current_filter} -> {self.config.band_filter}"
            )
            await self._handle_slew_and_change_filter()
        else:
            self.log.debug(
                f"Already in the desired filter ({current_filter}), slewing and tracking."
            )

        await self.mtcs.slew_icrs(
            ra=self.config.ra,
            dec=self.config.dec,
            rot=self.config.rot_sky,
            rot_type=RotType.Sky,
            target_name=self.config.name,
        )

    async def _handle_slew_and_change_filter(self):
        """Handle slewing and changing filter at the same time.

        For ComCam (and MainCam) we need to send the rotator to zero and keep
        it there while the filter is changing.
        """

        tasks_slew_with_fixed_rot = [
            asyncio.create_task(
                self.mtcs.slew_icrs(
                    ra=self.config.ra,
                    dec=self.config.dec,
                    rot=self.angle_filter_change,
                    rot_type=RotType.Physical,
                    target_name=f"{self.config.name} - filter change",
                )),
            asyncio.create_task(
                self._wait_rotator_reach_filter_change_angle()),
        ]

        await self.mtcs.process_as_completed(tasks_slew_with_fixed_rot)

        await self.comcam.setup_filter(filter=self.config.band_filter)

    async def _wait_rotator_reach_filter_change_angle(self):
        """Wait until the rotator reach the filter change angle."""

        while True:
            rotator_position = await self.mtcs.rem.mtrotator.tel_rotation.next(
                flush=True, timeout=self.mtcs.fast_timeout)

            if (abs(rotator_position.actualPosition - self.angle_filter_change)
                    < self.tolerance_angle_filter_change):
                self.log.debug("Rotator inside tolerance range.")
                break
            else:
                self.log.debug(
                    "Rotator not in position: "
                    f"{rotator_position.actualPosition} -> {self.angle_filter_change}"
                )
                await asyncio.sleep(self.mtcs.tel_settle_time)

    async def take_data(self):
        """Take data while making sure ATCS is tracking."""

        tasks = [
            asyncio.create_task(self._take_data()),
            asyncio.create_task(self.mtcs.check_tracking()),
        ]

        await self.mtcs.process_as_completed(tasks)

    async def _take_data(self):
        """Take data."""

        for exptime in self.config.exp_times:
            await self.comcam.take_object(
                exptime=exptime,
                group_id=self.group_id,
                reason=self.config.reason,
                program=self.config.program,
            )

    async def stop_tracking(self):
        """Execute stop tracking on MTCS."""
        await self.mtcs.stop_tracking()