Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
isotuela committed Jun 9, 2023
1 parent 5575a22 commit c7cff59
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

__all__ = ["PowerOnATCalSys"]

Expand All @@ -31,9 +32,6 @@

from lsst.ts import salobj

track_lamp_warmup = 60


class PowerOnATCalSys(salobj.BaseScript):
"""Powers on the ATCalSys dome flat illuminator
(ATWhiteLight and ATMonochromator)
Expand All @@ -44,9 +42,6 @@ class PowerOnATCalSys(salobj.BaseScript):
index : `int`
Index of Script SAL component.
Notes
-----
"""

def __init__(self, index, add_remotes: bool = True):
Expand All @@ -60,37 +55,19 @@ def __init__(self, index, add_remotes: bool = True):

# White lamp config
self.timeout_lamp_warm_up = 60 * 15
self.track_lamp_warmup = 60
self.cmd_timeout = 30

# Chiller config
self.timeout_chiller_cool_down = 60 * 10
self.chiller_temp_tolerance_relative = 0.1

if self.white_light_source is None:
self.white_light_source = salobj.Remote(
domain=self.domain, name="ATWhiteLight",
intended_usage= None if add_remotes else Usages.DryTest,
log =self.log
)

if self.monochromator is None:
self.monochromator = salobj.Remote(
domain=self.domain, name="ATMonochromator",
intended_usage= None if add_remotes else Usages.DryTest,
log=self.log
)

asyncio.gather(
self.white_light_source.start_task,
self.monochromator.start_task,
)


@classmethod
def get_schema(cls):
schema_yaml = """
$schema: http://json-schema.org/draft-07/schema#
$id: https://github.com/lsst-ts/ts_standardscripts/auxtel/SlewTelescopeIcrs.yaml
$id: https://github.com/lsst-ts/ts_standardscripts/auxtel/calibrations/power_on_atcalsys.yaml
title: PowerOnATCalSys v1
description: Configuration for PowerOnATCalSys.
Each attribute can be specified as a scalar or array.
Expand Down Expand Up @@ -159,17 +136,24 @@ async def configure(self, config):
self.entrance_slit_width = config.entrance_slit_width
self.exit_slit_width = config.exit_slit_width

# if self.white_light_source is None:
# self.white_light_source = salobj.Remote(
# domain=self.domain, name="ATWhiteLight"
# )
if self.white_light_source is None:
self.white_light_source = salobj.Remote(
domain=self.domain, name="ATWhiteLight",
intended_usage= None if add_remotes else Usages.DryTest,
log =self.log
)

# if self.monochromator is None:
# self.monochromator = salobj.Remote(
# domain=self.domain, name="ATMonochromator"
# )
if self.monochromator is None:
self.monochromator = salobj.Remote(
domain=self.domain, name="ATMonochromator",
intended_usage= None if add_remotes else Usages.DryTest,
log=self.log
)

self.config = config
await asyncio.gather(
self.white_light_source.start_task,
self.monochromator.start_task,
)

self.log.info("Configure completed")

Expand All @@ -184,7 +168,7 @@ def set_metadata(self, metadata):

async def run(self):
"""Run script."""
#await self.assert_components_enabled()
await self.assert_components_enabled()

await self.checkpoint("Starting chiller")
await self.start_chiller()
Expand All @@ -211,18 +195,15 @@ async def start_chiller(self):
await self.white_light_source.cmd_startChiller.set(timeout=self.timeout_chiller_cool_down)

async def wait_for_chiller_temp_within_tolerance(self):
start_time_chill_time = time.time()
while time.time() - start_time_chill_time < self.timeout_chiller_cool_down:
start_chill_time = time.time()
while time.time() - start_chill_time < self.timeout_chiller_cool_down:
chiller_temps = await self.white_light_source.tel_chillerTemperatures.aget()
tel_chiller_temp = chiller_temps.supplyTemperature
if (
chiller_temps.setTemperature
* (1.0 - self.chiller_temp_tolerance_relative)
< tel_chiller_temp
< chiller_temps.setTemperature
* (1.0 + self.chiller_temp_tolerance_relative)
abs(chiller_temps.setTemperature - tel_chiller_temp)/chiller_temps.setTemperature
<= self.chiller_temp_tolerance_relative
):
chill_time = time.time() - start_time_chill_time
chill_time = time.time() - start_chill_time
self.log.info(
f"Chiller reached target temperature {tel_chiller_temp}"
f"within tolerance in {chill_time} s"
Expand Down Expand Up @@ -258,7 +239,7 @@ async def wait_for_lamp_to_warm_up(self):
lamp_state.warmupEndTime - lamp_state.private_sndStamp
)
self.log.info(f"Time Left for lamp warmup: {warmup_time_left} min.")
await asyncio.sleep(track_lamp_warmup)
await asyncio.sleep(self.track_lamp_warmup)

elif lamp_state.basicState == ATWhiteLight.LampBasicState.ON:
self.log.info(
Expand Down
23 changes: 12 additions & 11 deletions tests/test_auxtel_power_on_atcalsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import logging
import random
Expand Down Expand Up @@ -73,21 +74,21 @@ async def configure_mocks(self):

self.script.white_light_source.configure_mock(
**{
"evt_summaryState.aget": self.mock_get_whitelightsource_summary_state,
"cmd_setChillerTemperature.set_start": self.mock_start_chiller_temp,
"cmd_startChiller.set": self.mock_chiller_temp,
"tel_ChillerTemp.aget": self.mock_get_chiller_status,
"com_openShutter.set_start": self.mock_open_shutter,
"cmd_turnLampOn.set_start": self.mock_lamp_temp,
"evt_lampState.next": self.mock_get_lamp_status,
"evt_summaryState.aget.side_effect": self.mock_get_whitelightsource_summary_state,
"cmd_setChillerTemperature.set_start.side_effect": self.mock_start_chiller_temp,
"cmd_startChiller.set.side_effect": self.mock_chiller_temp,
"tel_ChillerTemp.aget.side_effect": self.mock_get_chiller_status,
"com_openShutter.set_start.side_effect": self.mock_open_shutter,
"cmd_turnLampOn.set_start.side_effect": self.mock_lamp_temp,
"evt_lampState.next.side_effect": self.mock_get_lamp_status,
}
)
self.script.monochromator.configure_mock(
**{
"evt_summaryState.aget": self.mock_get_monochromator_sumary_state,
"cmd_selectGrating.set_start": self.mock_change_grating,
"cmd_changeWavelength.set_start": self.mock_change_wavelength,
"cmd_changeSlitWidth.set_start": self.mock_change_slit_width,
"evt_summaryState.aget.side_effect": self.mock_get_monochromator_sumary_state,
"cmd_selectGrating.set_start.side_effect": self.mock_change_grating,
"cmd_changeWavelength.set_start.side_effect": self.mock_change_wavelength,
"cmd_changeSlitWidth.set_start.side_effect": self.mock_change_slit_width,
}
)

Expand Down

0 comments on commit c7cff59

Please sign in to comment.