Skip to content

Commit

Permalink
Setup ComCam consdb and fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elanaku committed Oct 22, 2024
1 parent 77fe9a6 commit be55ffb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
3 changes: 2 additions & 1 deletion python/lsst/ts/externalscripts/base_take_twilight_flats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -66,14 +73,22 @@ 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,
)
await self.comcam.start_task
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 = """
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
3 changes: 2 additions & 1 deletion tests/auxtel/test_latiss_take_twilight_flats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
7 changes: 6 additions & 1 deletion tests/maintel/test_take_twilight_flats_comcam.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
import unittest.mock as mock
from collections import namedtuple

import pytest
from lsst.ts import externalscripts, salobj, standardscripts
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit be55ffb

Please sign in to comment.