diff --git a/tangostationcontrol/tangostationcontrol/integration_test/default/statistics/test_writer_sst.py b/tangostationcontrol/tangostationcontrol/integration_test/default/statistics/test_writer_sst.py index 2d98e2fce13730e2e02ea49316c29fe2dd693b1f..992cc778db86c561bcebe89fd273189d5a8dbb0a 100644 --- a/tangostationcontrol/tangostationcontrol/integration_test/default/statistics/test_writer_sst.py +++ b/tangostationcontrol/tangostationcontrol/integration_test/default/statistics/test_writer_sst.py @@ -15,6 +15,7 @@ from tangostationcontrol.statistics import reader from tangostationcontrol.statistics.writer import entry import sys +from h5py import Empty from os.path import dirname, isfile, join from tempfile import TemporaryDirectory from unittest import mock @@ -182,9 +183,9 @@ class TestStatisticsWriterSST(BaseIntegrationTestCase): self.assertIsNotNone(stat) self.assertEqual(121, stat.data_id_signal_input_index) # Test RECV attributes - self.assertEqual(stat.rcu_attenuator_dB.tolist(), None) - self.assertEqual(stat.rcu_band_select.tolist(), None) - self.assertEqual(stat.rcu_dth_on.tolist(), None) + self.assertEqual(stat.rcu_attenuator_dB.tolist(), Empty("f")) + self.assertEqual(stat.rcu_band_select.tolist(), Empty("f")) + self.assertEqual(stat.rcu_dth_on.tolist(), Empty("f")) def test_SST_statistics_with_device_in_off(self): self.setup_recv_proxy() @@ -222,6 +223,6 @@ class TestStatisticsWriterSST(BaseIntegrationTestCase): self.assertIsNotNone(stat) self.assertEqual(121, stat.data_id_signal_input_index) # Test RECV attributes - self.assertEqual(stat.rcu_attenuator_dB.tolist(), None) - self.assertEqual(stat.rcu_band_select.tolist(), None) - self.assertEqual(stat.rcu_dth_on.tolist(), None) + self.assertEqual(stat.rcu_attenuator_dB.tolist(), Empty("f")) + self.assertEqual(stat.rcu_band_select.tolist(), Empty("f")) + self.assertEqual(stat.rcu_dth_on.tolist(), Empty("f")) diff --git a/tangostationcontrol/tangostationcontrol/statistics/reader.py b/tangostationcontrol/tangostationcontrol/statistics/reader.py index eb1594540554b443ec232bee33ffbc67a1cb4722..6aad1088439d1bb30dd2fdf837fdfdedae250a81 100644 --- a/tangostationcontrol/tangostationcontrol/statistics/reader.py +++ b/tangostationcontrol/tangostationcontrol/statistics/reader.py @@ -203,9 +203,9 @@ class statistics_data: # get SST specific stuff if self.marker == "S": self.data_id_signal_input_index = file[group_key].attrs["data_id_signal_input_index"] - self.rcu_attenuator_dB = numpy.array(file.get(f"{group_key}/rcu_attenuator_dB")) - self.rcu_band_select = numpy.array(file.get(f"{group_key}/rcu_band_select")) - self.rcu_dth_on = numpy.array(file.get(f"{group_key}/rcu_dth_on")) + self.rcu_attenuator_dB = numpy.array(file[group_key].attrs["rcu_attenuator_dB"]) + self.rcu_band_select = numpy.array(file[group_key].attrs["rcu_band_select"]) + self.rcu_dth_on = numpy.array(file[group_key].attrs["rcu_dth_on"]) # get XST specific stuff if self.marker == "X": diff --git a/tangostationcontrol/tangostationcontrol/statistics/writer/hdf5.py b/tangostationcontrol/tangostationcontrol/statistics/writer/hdf5.py index 2303c7d65c2a879941e554ba6f6ab614d0b43881..58b250f667f3313b60287364016cd6f654f3a3a1 100644 --- a/tangostationcontrol/tangostationcontrol/statistics/writer/hdf5.py +++ b/tangostationcontrol/tangostationcontrol/statistics/writer/hdf5.py @@ -87,7 +87,7 @@ class HDF5Writer(ABC): # Set device if any, defaults to None self.device = device - self.device_attributes = None + self.device_attributes = {} @abstractmethod def decoder(self, packet): @@ -120,10 +120,6 @@ class HDF5Writer(ABC): # grab the timestamp statistics_timestamp = statistics_packet.timestamp() - # device attributes - if self.mode == 'SST': - self.device_attributes = statistics_packet.device_attributes() - # ignore packets with no timestamp, as they indicate FPGA processing was # disabled and are useless anyway. if statistics_packet.block_serial_number == 0: @@ -337,10 +333,18 @@ class SstHdf5Writer(HDF5Writer): ].astype(numpy.float32), compression="gzip", ) - # store the device attributes - self.device_attributes["rcu_attenuator_dB"] = self.current_matrix.parameters["rcu_attenuator_dB"].astype(numpy.int64) - self.device_attributes["rcu_band_select"] = self.current_matrix.parameters["rcu_band_select"].astype(numpy.int64) - self.device_attributes["rcu_dth_on"] = self.current_matrix.parameters["rcu_dth_on"].astype(numpy.bool_) + + # write the device attributes + attribute_names = ["rcu_attenuator_dB", "rcu_band_select", "rcu_dth_on"] + attribute_types = {"rcu_attenuator_dB": numpy.int64, "rcu_band_select" : numpy.int64, "rcu_dth_on" : bool} + for a in attribute_names: + if self.current_matrix.parameters[a] is None: + self.device_attributes[a] = h5py.Empty("f") + else: + self.device_attributes[a] = self.current_matrix.parameters[a].astype(attribute_types[a]) + + for k,v in self.device_attributes.items(): + current_group.attrs[k] = v class BstHdf5Writer(HDF5Writer): def __init__(