diff --git a/python/lsst/ts/externalscripts/base_take_twilight_flats.py b/python/lsst/ts/externalscripts/base_take_twilight_flats.py index c3c849459..bc94af239 100644 --- a/python/lsst/ts/externalscripts/base_take_twilight_flats.py +++ b/python/lsst/ts/externalscripts/base_take_twilight_flats.py @@ -496,7 +496,8 @@ async def take_twilight_flats(self): while i < self.config.n_flat: - sky_counts = self.get_sky_counts() + # TODO: make consistent with LATISS and comcam + sky_counts = await self.get_sky_counts() self.log.info( f"Flat just taken with exposure time {exp_time} had counts of {sky_counts}" ) diff --git a/python/lsst/ts/externalscripts/maintel/take_twilight_flats_comcam.py b/python/lsst/ts/externalscripts/maintel/take_twilight_flats_comcam.py index 18e6cf297..a9d2865f7 100644 --- a/python/lsst/ts/externalscripts/maintel/take_twilight_flats_comcam.py +++ b/python/lsst/ts/externalscripts/maintel/take_twilight_flats_comcam.py @@ -22,12 +22,19 @@ import asyncio import functools +import warnings import yaml from lsst.ts.observatory.control.maintel.comcam import ComCam, ComCamUsages from lsst.ts.observatory.control.maintel.mtcs import MTCS from lsst.ts.observatory.control.utils import RotType +try: + from lsst.summit.utils import ConsDbClient +except ImportError: + warnings.warn("Cannot import required libraries. Script will not work.") + + from ..base_take_twilight_flats import BaseTakeTwilightFlats @@ -66,7 +73,7 @@ async def configure_camera(self) -> None: self.log.debug("Creating Camera.") self.comcam = ComCam( self.domain, - intended_usage=ComCamUsages.TakeImage, + intended_usage=ComCamUsages.TakeImageFull, log=self.log, tcs_ready_to_take_data=self.mtcs.ready_to_take_data, ) @@ -74,6 +81,14 @@ async def configure_camera(self) -> None: else: self.log.debug("Camera already defined, skipping.") + def configure_client(self) -> None: + """Handle creating the ConsDB client and waiting remote to start.""" + if self.client is None: + self.log.debug("Creating ConsDB client.") + self.client = ConsDbClient("http://consdb-pq.consdb:8080/consdb") + else: + self.log.debug("ConsDB client already defined, skipping.") + @classmethod def get_schema(cls): schema_yaml = """ @@ -111,7 +126,7 @@ async def get_sky_counts(self) -> float: Sky counts in electrons. """ timeout = 30 - query = f"SELECT * from cbd_lsstcomcam.exposure_quicklook \ + query = f"SELECT * from cbd_lsstcomcam.visit1_quicklook \ where exposure_id = {self.latest_exposure_id}" item = "post_isr_pixel_median_median" get_counts = functools.partial( @@ -203,3 +218,8 @@ async def slew_azel_and_setup_instrument(self, az, el): az=az, el=el, ) + + async def configure(self, config): + """Take the sequence of twilight flats twilight flats.""" + self.configure_client() + await super().configure(config) diff --git a/tests/auxtel/test_latiss_take_twilight_flats.py b/tests/auxtel/test_latiss_take_twilight_flats.py index 05eb184f5..816139b78 100644 --- a/tests/auxtel/test_latiss_take_twilight_flats.py +++ b/tests/auxtel/test_latiss_take_twilight_flats.py @@ -37,7 +37,8 @@ def mock_atcs(self): self.script.atcs.assert_liveliness = mock.AsyncMock() self.script.atcs.assert_all_enabled = mock.AsyncMock() self.script.atcs.offset_aos_lut = mock.AsyncMock() - self.script.atcs.get_sun_azel = mock.AsyncMock(return_value=(-3.0, 90.0)) + self.script.atcs.get_sun_azel = mock.Mock(return_value=(90, -3.0)) + self.script.atcs.radec_from_azel = mock.Mock(return_value={"ra": 6, "dec": 20}) def mock_camera(self): """Mock camera instance and its methods.""" diff --git a/tests/maintel/test_take_twilight_flats_comcam.py b/tests/maintel/test_take_twilight_flats_comcam.py index e76951f81..da2c77bab 100644 --- a/tests/maintel/test_take_twilight_flats_comcam.py +++ b/tests/maintel/test_take_twilight_flats_comcam.py @@ -1,5 +1,6 @@ import unittest import unittest.mock as mock +from collections import namedtuple import pytest from lsst.ts import externalscripts, salobj, standardscripts @@ -27,7 +28,11 @@ def mock_mtcs(self): self.script.mtcs.assert_liveliness = mock.AsyncMock() self.script.mtcs.assert_all_enabled = mock.AsyncMock() self.script.mtcs.offset_aos_lut = mock.AsyncMock() - self.script.mtcs.get_sun_azel = mock.AsyncMock(return_value=(-3.0, 90.0)) + self.script.mtcs.get_sun_azel = mock.Mock(return_value=(90.0, -3.0)) + Coordinates = namedtuple("Coordinates", ["ra", "dec"]) + self.script.mtcs.radec_from_azel = mock.Mock( + return_value=Coordinates(ra=6, dec=20) + ) def mock_camera(self): """Mock camera instance and its methods."""