Select Git revision
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
observation.py 2.07 KiB
# -*- coding: utf-8 -*-
#
# This file is part of the LOFAR2.0 Station Control project.
#
# Distributed under the terms of the APACHE license.
# See LICENSE.txt for more info.
"""
Contains class for pythonic interface with observations
"""
from json import dumps
import logging
from tango import DeviceProxy
logger = logging.getLogger()
class Observation:
"""
This class provides a pythonic interface to the
ObservationControl and Observation devices on a station.
"""
def __init__(
self,
specification: dict,
host: str = "databaseds.tangonet:10000",
station="STAT",
):
# create device proxies to station at "host"
self._observation_control_dev = DeviceProxy(
f"tango://{host}/{station}/ObservationControl/1"
)
self.host = host
self.station = station
# convert specification dict to json
self._specification = dumps(specification)
# get the ID
self._id = int(specification["observation_id"])
def observation_id(self) -> int:
"""
Returns the observation ID of this observation
"""
return self._id
def start(self):
"""
Starts this observation
"""
self._observation_control_dev.start_observation(self._specification)
def abort(self):
"""
Aborts this observation
"""
self._observation_control_dev.stop_observation(self._id)
def observation_proxy(self):
"""
Returns the DeviceProxy of this observation
"""
# return a proxy to the correct Observation device on the station (
# "STAT/Observation/{observation_id}")
return DeviceProxy(f"tango://{self.host}/{self.station}/Observation/{self._id}")
def is_running(self):
"""
Returns whether this observation is currently running or not
"""
# return whether the observation is still running (
# ObservationControl.is_observation_running command)
return self._observation_control_dev.is_observation_running(self._id)