diff --git a/tangostationcontrol/tangostationcontrol/devices/beam_device.py b/tangostationcontrol/tangostationcontrol/devices/beam_device.py new file mode 100644 index 0000000000000000000000000000000000000000..0b436d89b2191b33f059094a89740d66382d927b --- /dev/null +++ b/tangostationcontrol/tangostationcontrol/devices/beam_device.py @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- +# +# Distributed under the terms of the APACHE license. +# See LICENSE.txt for more info. + +"""Beam Abstract Device Server for LOFAR2.0 + +""" +# PyTango imports +from tango.server import attribute, command +from tango import AttrWriteType, DebugIt + +# Additional import +from tangostationcontrol.common.entrypoint import entry +from tangostationcontrol.common.measures import get_measures_directory, get_available_measures_directories, download_measures, use_measures_directory, restart_python +from tangostationcontrol.common.lofar_logging import log_exceptions +from tangostationcontrol.devices.lofar_device import lofar_device + +__all__ = ["beam_device", "main"] + +import logging +logger = logging.getLogger() + + +class beam_device(lofar_device): + + # ---------- + # Attributes + # ---------- + + # Directory where the casacore measures that we use, reside. We configure ~/.casarc to + # use the symlink /opt/IERS/current, which we switch to the actual set of files to use. + measures_directory_R = attribute(dtype=str, access=AttrWriteType.READ, fget = lambda self: get_measures_directory()) + + # List of dowloaded measures (the latest 64, anyway) + measures_directories_available_R = attribute(dtype=(str,), max_dim_x=64, access=AttrWriteType.READ, fget = lambda self: sorted(get_available_measures_directories())[-64:]) + + # -------- + # Commands + # -------- + + @command(dtype_out=str, doc_out="Name of newly installed measures directory") + @DebugIt() + @log_exceptions() + def download_measures(self): + """ Download new measures tables into /opt/IERS, but do not activate them. + + NOTE: This may take a while to complete. You are advised to increase + the timeout of the proxy using `my_device.set_timeout_millis(10000)`. """ + + return download_measures() + + @command(dtype_in=str, doc_in="Measures directory to activate") + @DebugIt() + @log_exceptions() + def use_measures(self, newdir): + """ Activate a downloaded set of measures tables. + + NOTE: This will turn off and restart this device!! """ + + # switch to requested measures + use_measures_directory(newdir) + logger.info(f"Switched measures table to {newdir}") + + # turn off our device, to prepare for a python restart + self.Off() + + # restart this program to force casacore to adopt + # the new tables + logger.warning("Restarting device to activate new measures tables") + restart_python() + +# ---------- +# Run server +# ---------- +def main(**kwargs): + """Main function of the Docker module.""" + return entry(beam_device, **kwargs) diff --git a/tangostationcontrol/tangostationcontrol/devices/sdp/digitalbeam.py b/tangostationcontrol/tangostationcontrol/devices/sdp/digitalbeam.py index 147b0a6237d14b70683f778f220f304ffb2e3b86..256bd5b2cccd8531b2e9ff9aeedcc1acf25cd425 100644 --- a/tangostationcontrol/tangostationcontrol/devices/sdp/digitalbeam.py +++ b/tangostationcontrol/tangostationcontrol/devices/sdp/digitalbeam.py @@ -14,14 +14,14 @@ from tangostationcontrol.common.entrypoint import entry #from tangostationcontrol.clients.attribute_wrapper import attribute_wrapper -from tangostationcontrol.devices.lofar_device import lofar_device +from tangostationcontrol.devices.beam_device import beam_device #import numpy __all__ = ["DigitalBeam", "main"] -class DigitalBeam(lofar_device): +class DigitalBeam(beam_device): pass # ----------------- # Device Properties diff --git a/tangostationcontrol/tangostationcontrol/devices/tilebeam.py b/tangostationcontrol/tangostationcontrol/devices/tilebeam.py index b31a1aaa6c5050dd2377ffe3b7fdbbee4e42f40f..7adee9e269bf24d340175d1704448ded674c3684 100644 --- a/tangostationcontrol/tangostationcontrol/devices/tilebeam.py +++ b/tangostationcontrol/tangostationcontrol/devices/tilebeam.py @@ -18,11 +18,10 @@ from tango import Util # Additional import from tangostationcontrol.common.entrypoint import entry -from tangostationcontrol.devices.lofar_device import lofar_device from tangostationcontrol.common.lofar_logging import device_logging_to_python, log_exceptions -from tangostationcontrol.common.measures import get_measures_directory, use_measures_directory, download_measures, restart_python, get_available_measures_directories from tangostationcontrol.beam.delays import delay_calculator from tangostationcontrol.devices.device_decorators import * +from tangostationcontrol.devices.beam_device import beam_device import logging logger = logging.getLogger() @@ -32,7 +31,7 @@ logger = logging.getLogger() __all__ = ["TileBeam", "main", "BeamTracker"] @device_logging_to_python() -class TileBeam(lofar_device): +class TileBeam(beam_device): # ----------------- # Device Properties @@ -78,13 +77,6 @@ class TileBeam(lofar_device): dtype=numpy.bool, fget=lambda self: self._hbat_tracking_enabled_rw) - # Directory where the casacore measures that we use, reside. We configure ~/.casarc to - # use the symlink /opt/IERS/current, which we switch to the actual set of files to use. - measures_directory_R = attribute(dtype=str, access=AttrWriteType.READ, fget = lambda self: get_measures_directory()) - - # List of dowloaded measures (the latest 64, anyway) - measures_directories_available_R = attribute(dtype=(str,), max_dim_x=64, access=AttrWriteType.READ, fget = lambda self: sorted(get_available_measures_directories())[-64:]) - # -------- # overloaded functions # -------- @@ -223,42 +215,11 @@ class TileBeam(lofar_device): # -------- # Commands # -------- - - @command(dtype_out=str, doc_out="Name of newly installed measures directory") - @DebugIt() - @log_exceptions() - def download_measures(self): - """ Download new measures tables into /opt/IERS, but do not activate them. - - NOTE: This may take a while to complete. You are advised to increase - the timeout of the proxy using `my_device.set_timeout_millis(10000)`. """ - - return download_measures() - - @command(dtype_in=str, doc_in="Measures directory to activate") - @DebugIt() - @log_exceptions() - def use_measures(self, newdir): - """ Activate a downloaded set of measures tables. - - NOTE: This will turn off and restart this device!! """ - - # switch to requested measures - use_measures_directory(newdir) - logger.info(f"Switched measures table to {newdir}") - - # turn off our device, to prepare for a python restart - self.Off() - - # restart this program to force casacore to adopt - # the new tables - logger.warning("Restarting device to activate new measures tables") - restart_python() @command(dtype_in=DevVarStringArray, dtype_out=DevVarDoubleArray) @DebugIt() @log_exceptions() - @only_in_states(lofar_device.DEFAULT_COMMAND_STATES) + @only_in_states(beam_device.DEFAULT_COMMAND_STATES) def HBAT_delays(self, pointing_direction: numpy.array, timestamp: datetime.datetime = None): """ Calculate the delays (in seconds) based on the pointing list and the timestamp @@ -279,7 +240,7 @@ class TileBeam(lofar_device): @command(dtype_in=DevVarStringArray) @DebugIt() @log_exceptions() - @only_in_states(lofar_device.DEFAULT_COMMAND_STATES) + @only_in_states(beam_device.DEFAULT_COMMAND_STATES) def HBAT_set_pointing(self, pointing_direction: list, timestamp: datetime.datetime = None): """ Uploads beam weights based on a given pointing direction 2D array (96 tiles x 3 parameters) @@ -297,7 +258,7 @@ class TileBeam(lofar_device): @command(dtype_in = DevString) @DebugIt() - @only_in_states(lofar_device.DEFAULT_COMMAND_STATES) + @only_in_states(beam_device.DEFAULT_COMMAND_STATES) def HBAT_set_pointing_for_specific_time(self, parameters: DevString = None): """ Uploads beam weights based on a given pointing direction 2D array (96 tiles x 3 parameters) @@ -334,7 +295,7 @@ class BeamTracker(): DISCONNECT_TIMEOUT = 3.0 """ Object that encapsulates a Thread, resposible for beam tracking operations """ - def __init__(self, device: lofar_device): + def __init__(self, device: beam_device): self.thread = None self.device = device