Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-45743: Power Off Tunable Laser #228

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/news/DM-45743.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
New script to turn the Tunable Laser off, i.e. stop propagating
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python
# This file is part of ts_standardscripts
#
# Developed for the LSST Telescope and Site Systems.
# This product includes software developed by the LSST Project
# (https://www.lsst.org).
# See the COPYRIGHT file at the top-level directory of this distribution
# for details of code ownership.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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 asyncio

from lsst.ts.standardscripts.maintel.calibration import PowerOffTunableLaser

asyncio.run(PowerOffTunableLaser.amain())
22 changes: 22 additions & 0 deletions python/lsst/ts/standardscripts/maintel/calibration/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This file is part of ts_standardscripts
#
# Developed for the LSST Telescope and Site Systems.
# This product includes software developed by the LSST Project
# (https://www.lsst.org).
# See the COPYRIGHT file at the top-level directory of this distribution
# for details of code ownership.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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/>.

from .power_off_tunablelaser import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# This file is part of ts_standardscripts
#
# Developed for the LSST Telescope and Site Systems.
# This product includes software developed by the LSST Project
# (https://www.lsst.org).
# See the COPYRIGHT file at the top-level directory of this distribution
# for details of code ownership.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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__ = ["PowerOffTunableLaser"]


import yaml
from lsst.ts import salobj
from lsst.ts.observatory.control.maintel.mtcalsys import MTCalsys


class PowerOffTunableLaser(salobj.BaseScript):
"""Starts propagating the Tunable Laser for functional
testing.

Parameters
----------
index : `int`
Index of Script SAL component.

"""

def __init__(self, index):
super().__init__(
index=index,
descr="Power On Tunable Laser",
)

self.laser = None
self.mtcalsys = None

@classmethod
def get_schema(cls):
schema_yaml = """
$schema: http://json-schema.org/draft-07/schema#
$id: https://github.com/lsst-ts/ts_standardscripts/maintel/calibrations/power_on_tunablelaser.yaml
title: PowerOffTunableLaser v1
description: Configuration for PowerOffTunableLaser.
Each attribute can be specified as a scalar or array.
All arrays must have the same length (one item per image).
type: object
properties:
sequence_name:
description: Name of sequence in MTCalsys
type: string
default: laser_functional

additionalProperties: false
"""
return yaml.safe_load(schema_yaml)

def set_metadata(self, metadata):
metadata.duration = 30

async def configure(self, config):
"""Configure the script.

Parameters
----------
config : ``self.cmd_configure.DataType``

"""
self.log.info("Configure started")
if self.mtcalsys is None:
self.log.debug("Creating MTCalSys.")
self.mtcalsys = MTCalsys(domain=self.domain, log=self.log)
await self.mtcalsys.start_task

self.sequence_name = config.sequence_name
self.mtcalsys.load_calibration_config_file()
self.mtcalsys.assert_valid_configuration_option(name=self.sequence_name)

self.config_data = self.mtcalsys.get_calibration_configuration(
self.sequence_name
)

if self.laser is None:
self.laser = salobj.Remote(
domain=self.domain,
name="TunableLaser",
)

self.laser.start_task

self.log.info("Configure completed")

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

await self.checkpoint("Configuring TunableLaser")

params = await self.mtcalsys.get_laser_parameters()

self.log.info(
f"Laser Configuration is {params[0]}, \n"
f"wavelength is {params[1]}, \n"
f"Interlock is {params[2]}, \n"
f"Burst mode is {params[3]}, \n"
f"Cont. mode is {params[4]}"
)

await self.checkpoint("Stopping laser propagation")
await self.start_propagation_off()

async def start_propagation_off(self):
"""Starts propagation of the laser"""

await self.mtcalsys.laser_stop_propagate()

async def assert_components_enabled(self):
"""Checks if TunableLaser is ENABLED

Raises
------
RunTimeError:
If either component is not ENABLED"""

comps = [self.laser]

for comp in comps:
summary_state = await comp.evt_summaryState.aget()
if salobj.State(summary_state.summaryState) != salobj.State(
salobj.State.ENABLED
):
raise RuntimeError(f"{comp} is not ENABLED")
98 changes: 98 additions & 0 deletions tests/test_maintel_power_off_tunablelaser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# This file is part of ts_standardscripts
#
# Developed for the LSST Telescope and Site Systems.
# This product includes software developed by the LSST Project
# (https://www.lsst.org).
# See the COPYRIGHT file at the top-level directory of this distribution
# for details of code ownership.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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 os
import random
import types
import unittest

from lsst.ts import salobj, standardscripts, utils
from lsst.ts.standardscripts.maintel.calibration import PowerOffTunableLaser
from lsst.ts.xml.enums.TunableLaser import LaserDetailedState

random.seed(47) # for set_random_lsst_dds_partition_prefix

logging.basicConfig()


class TestPowerOffTunableLaser(
standardscripts.BaseScriptTestCase, unittest.IsolatedAsyncioTestCase
):
async def basic_make_script(self, index):
self.script = PowerOffTunableLaser(index=index)

await self.configure_mocks()

return [
self.script,
]

async def configure_mocks(self):
self.script.laser = unittest.mock.AsyncMock()
self.script.laser.start_task = utils.make_done_future()

# Configure mocks

self.script.laser.configure_mock(
**{
"evt_summaryState.aget.side_effect": self.mock_get_laser_summary_state,
"cmd_stopPropagateLaser.start.side_effect": self.mock_stop_laser,
}
)

async def mock_get_laser_summary_state(self, **kwargs):
return types.SimpleNamespace(summaryState=salobj.State.ENABLED)

async def mock_stop_laser(self, **kwargs):
self.laser_state = types.SimpleNamespace(
detailedState=LaserDetailedState.PROPAGATING_CONTINUOUS_MODE
)

async def test_run_without_failures(self):
async with self.make_script():
await self.configure_script()

await self.run_script()

self.script.laser.cmd_stopPropagateLaser.start.assert_awaited_with(
timeout=self.script.laser_warmup,
)

# Summary State
self.script.laser.evt_summaryState.aget.assert_awaited_once_with()

# Assert states are OK
assert (
self.laser_status.detailedState
== LaserDetailedState.NONPROPAGATING_CONTINUOUS_MODE
)

async def test_executable(self):
scripts_dir = standardscripts.get_scripts_dir()
script_path = os.path.join(
scripts_dir, "maintel", "calibration", "power_off_tunablelaser.py"
)
await self.check_executable(script_path)


if __name__ == "__main__":
unittest.main()
Loading