diff --git a/lofar_station_client/statistics/writer/entry.py b/lofar_station_client/statistics/writer/entry.py index 0f600b16967f1ba02f81edfe55a406107b55de0a..4336967a441400fa74156117528dcc5b956ea764 100644 --- a/lofar_station_client/statistics/writer/entry.py +++ b/lofar_station_client/statistics/writer/entry.py @@ -128,6 +128,7 @@ def _create_writer( antennafield_device: DeviceProxy = None, sdp_device: DeviceProxy = None, tilebeam_device: DeviceProxy = None, + digitalbeam_device: DeviceProxy = None, ): """Create the writer""" if mode == "XST": @@ -153,6 +154,7 @@ def _create_writer( new_file_time_interval=interval, file_location=output_dir, decimation_factor=decimation, + digitalbeam_device=digitalbeam_device, ) logger.fatal("Invalid mode: %s", mode) sys.exit(1) diff --git a/lofar_station_client/statistics/writer/hdf5.py b/lofar_station_client/statistics/writer/hdf5.py index cb5eb3fe960820ab534f63024e5a58db51c4b5f1..2b2c25dfa94db72d0abb44cf998758cfa383f398 100644 --- a/lofar_station_client/statistics/writer/hdf5.py +++ b/lofar_station_client/statistics/writer/hdf5.py @@ -12,7 +12,7 @@ import os from abc import ABC, abstractmethod from datetime import datetime, timedelta from itertools import chain -from typing import TypeVar +from typing import TypeVar, List # python hdf5 import h5py @@ -132,6 +132,7 @@ class HDF5Writer(ABC): antennafield_device: DeviceProxy = None, sdp_device: DeviceProxy = None, tilebeam_device: DeviceProxy = None, + digitalbeam_device: DeviceProxy = None, ): # all variables that deal with the matrix that's currently being decoded self.file: StatisticsDataFile = None @@ -161,9 +162,10 @@ class HDF5Writer(ABC): self.antennafield_device = antennafield_device self.sdp_device = sdp_device self.tilebeam_device = tilebeam_device + self.digitalbeam_device = digitalbeam_device # By default, select all the values from SDP - self.antenna_selection: [] = None + self.antenna_selection: List[int] = None self.antenna_sdp_mapping = None if self.antennafield_device: @@ -232,6 +234,14 @@ class HDF5Writer(ABC): except DevFailed: logger.exception("Failed to read from %s", self.sdp_device.name()) + if self.digitalbeam_device: + try: + self.file.subbands = self.digitalbeam_device.subband_select_RW + except DevFailed: + logger.exception( + "Failed to read from %s", self.digitalbeam_device.name() + ) + def hdf5_matrix_header(self, statistics_packet_header: dict) -> dict: """Returns the header fields per statistics matrix.""" @@ -519,6 +529,7 @@ class SstHdf5Writer(HDF5Writer): antennafield_device=antennafield_device, sdp_device=sdp_device, tilebeam_device=tilebeam_device, + digitalbeam_device=None, ) def decoder(self, packet): @@ -548,12 +559,22 @@ class SstHdf5Writer(HDF5Writer): class BstHdf5Writer(HDF5Writer): """Writer for BST packets""" - def __init__(self, new_file_time_interval, file_location, decimation_factor): + def __init__( + self, + new_file_time_interval, + file_location, + decimation_factor, + digitalbeam_device: DeviceProxy = None, + ): super().__init__( new_file_time_interval, file_location, HDF5Writer.BST_MODE, decimation_factor, + antennafield_device=None, + sdp_device=None, + tilebeam_device=None, + digitalbeam_device=digitalbeam_device, ) def decoder(self, packet): @@ -591,6 +612,7 @@ class XstHdf5Writer(HDF5Writer): antennafield_device, tilebeam_device, sdp_device, + digitalbeam_device=None, ) self.subband_index = subband_index diff --git a/tests/test_devices.py b/tests/test_devices.py index de3adaffc45065bb90d4436d8f0a6b797ba455d6..741cca56377a27dcc32287fd6cc976c4bf8f94c5 100644 --- a/tests/test_devices.py +++ b/tests/test_devices.py @@ -306,3 +306,20 @@ class FakeOffAntennaFieldDeviceProxy: def __getattr__(self, attrname): raise DevFailed("Device is off") + + +class FakeDigitalBeamDeviceProxy: + """DeviceProxy that mocks access to an DigitalBeam device.""" + + N_beamlets_ctrl = 488 + + subband_select_RW = list(range(0, N_beamlets_ctrl)) + + def __init__(self, name): + self._name = name + + def name(self): + return self._name + + def __getattr__(self, attrname): + return getattr(self, attrname)