Skip to content

Commit

Permalink
Merge pull request #234 from lsst-ts/tickets/DM-46309
Browse files Browse the repository at this point in the history
tickets/DM-46309: Add open and close mirror covers SAL scripts for MT
  • Loading branch information
cvillalon authored Oct 21, 2024
2 parents 934934b + a01392c commit c2956c3
Show file tree
Hide file tree
Showing 8 changed files with 309 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/news/DM-46309.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add open and close mirror covers SAL Scripts for ``maintel``.
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 import CloseMirrorCovers

asyncio.run(CloseMirrorCovers.amain())
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 import OpenMirrorCovers

asyncio.run(OpenMirrorCovers.amain())
2 changes: 2 additions & 0 deletions python/lsst/ts/standardscripts/maintel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from .base_close_loop import *
from .close_loop_comcam import *
from .close_loop_lsstcam import *
from .close_mirror_covers import *
from .disable_hexapod_compensation_mode import *
from .enable_comcam import *
from .enable_hexapod_compensation_mode import *
Expand All @@ -36,6 +37,7 @@
from .offset_camera_hexapod import *
from .offset_m2_hexapod import *
from .offset_mtcs import *
from .open_mirror_covers import *
from .point_azel import *
from .setup_mtcs import *
from .standby_comcam import *
Expand Down
66 changes: 66 additions & 0 deletions python/lsst/ts/standardscripts/maintel/close_mirror_covers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# 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__ = ["CloseMirrorCovers"]

from lsst.ts import salobj
from lsst.ts.observatory.control.maintel.mtcs import MTCS, MTCSUsages


class CloseMirrorCovers(salobj.BaseScript):
"""Run open mirror covers on MTCS.
Parameters
----------
index : `int`
Index of Script SAL component.
Notes
-----
**Checkpoints**
Closing mirror covers: before issuing close mirror covers command.
"""

def __init__(self, index):
super().__init__(index=index, descr="Close the MT mirror covers.")

self.mtcs = None

@classmethod
def get_schema(cls):
# This script does not require any configuration
return None

async def configure(self, config):
if self.mtcs is None:
self.mtcs = MTCS(
domain=self.domain, intended_usage=MTCSUsages.All, log=self.log
)
await self.mtcs.start_task

def set_metadata(self, metadata):
metadata.duration = self.mtcs.mirror_covers_timeout

async def run(self):
await self.mtcs.assert_all_enabled()
await self.checkpoint("Closing mirror covers.")
await self.mtcs.close_m1_cover()
66 changes: 66 additions & 0 deletions python/lsst/ts/standardscripts/maintel/open_mirror_covers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# 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__ = ["OpenMirrorCovers"]

from lsst.ts import salobj
from lsst.ts.observatory.control.maintel.mtcs import MTCS, MTCSUsages


class OpenMirrorCovers(salobj.BaseScript):
"""Run open mirror covers on MTCS.
Parameters
----------
index : `int`
Index of Script SAL component.
Notes
-----
**Checkpoints**
* Opening mirror covers: before issuing open mirror covers command.
"""

def __init__(self, index):
super().__init__(index=index, descr="Open the MT mirror covers.")

self.mtcs = None

@classmethod
def get_schema(cls):
# This script does not require any configuration
return None

async def configure(self, config):
if self.mtcs is None:
self.mtcs = MTCS(
domain=self.domain, intended_usage=MTCSUsages.All, log=self.log
)
await self.mtcs.start_task

def set_metadata(self, metadata):
metadata.duration = self.mtcs.mirror_covers_timeout

async def run(self):
await self.mtcs.assert_all_enabled()
await self.checkpoint("Opening mirror covers.")
await self.mtcs.open_m1_cover()
60 changes: 60 additions & 0 deletions tests/test_maintel_close_mirror_covers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 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 contextlib
import unittest

from lsst.ts import standardscripts
from lsst.ts.standardscripts.maintel import CloseMirrorCovers


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

return (self.script,)

@contextlib.asynccontextmanager
async def make_dry_script(self):
async with self.make_script(self):
self.script.mtcs = unittest.mock.AsyncMock()
self.script.mtcs.assert_all_enabled = unittest.mock.AsyncMock()
self.script.mtcs.close_m1_cover = unittest.mock.AsyncMock()
yield

async def test_run(self):
async with self.make_dry_script():
await self.configure_script()

await self.run_script()
self.script.mtcs.assert_all_enabled.assert_awaited_once()
self.script.mtcs.close_m1_cover.assert_awaited_once()

async def test_executable(self):
scripts_dir = standardscripts.get_scripts_dir()
script_path = scripts_dir / "maintel" / "close_mirror_covers.py"
await self.check_executable(script_path)


if __name__ == "__main__":
unittest.main()
60 changes: 60 additions & 0 deletions tests/test_maintel_open_mirror_covers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 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 contextlib
import unittest

from lsst.ts import standardscripts
from lsst.ts.standardscripts.maintel import OpenMirrorCovers


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

return (self.script,)

@contextlib.asynccontextmanager
async def make_dry_script(self):
async with self.make_script(self):
self.script.mtcs = unittest.mock.AsyncMock()
self.script.mtcs.assert_all_enabled = unittest.mock.AsyncMock()
self.script.mtcs.open_m1_cover = unittest.mock.AsyncMock()
yield

async def test_run(self):
async with self.make_dry_script():
await self.configure_script()

await self.run_script()
self.script.mtcs.assert_all_enabled.assert_awaited_once()
self.script.mtcs.open_m1_cover.assert_awaited_once()

async def test_executable(self):
scripts_dir = standardscripts.get_scripts_dir()
script_path = scripts_dir / "maintel" / "open_mirror_covers.py"
await self.check_executable(script_path)


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

0 comments on commit c2956c3

Please sign in to comment.