Skip to content
Snippets Groups Projects
Commit 12a0690a authored by Stefano Di Frischia's avatar Stefano Di Frischia
Browse files

Merge branch 'L2SS-694-common-beam-functionality' into 'master'

Resolve L2SS-694 "Common beam functionality"

Closes L2SS-694

See merge request !289
parents b5366e2c af51c6b1
No related branches found
No related tags found
1 merge request!289Resolve L2SS-694 "Common beam functionality"
# -*- 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)
......@@ -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
......
......@@ -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
# --------
......@@ -224,41 +216,10 @@ 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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment