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 dfb548d3ed0b8d51edab43d2c74b280cf40c0162..c088fd345c364ff95624002c6730e8bf60c16bd2 100644 --- a/tangostationcontrol/tangostationcontrol/integration_test/default/statistics/test_writer_sst.py +++ b/tangostationcontrol/tangostationcontrol/integration_test/default/statistics/test_writer_sst.py @@ -181,7 +181,7 @@ class TestStatisticsWriterSST(BaseIntegrationTestCase): ) self.assertIsNotNone(stat) self.assertEqual(121, stat.data_id_signal_input_index) - # Test RECV attributes + # Test RECV attributes self.assertEqual(stat.rcu_attenuator_dB, None) self.assertEqual(stat.rcu_band_select, None) self.assertEqual(stat.rcu_dth_on, None) diff --git a/tangostationcontrol/tangostationcontrol/statistics/reader.py b/tangostationcontrol/tangostationcontrol/statistics/reader.py index efed9b52d0ffcac726284eb53db2306898a79403..1ab326db03bf8fdb1b773ce3471cb0ddbe287846 100644 --- a/tangostationcontrol/tangostationcontrol/statistics/reader.py +++ b/tangostationcontrol/tangostationcontrol/statistics/reader.py @@ -202,25 +202,14 @@ 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"] - # check if the dataset is empty or not. if empty, set to None, if not get the value - - if file.get(f'{group_key}/rcu_attenuator_dB').shape is None: - self.rcu_attenuator_dB = None - else: - self.rcu_attenuator_dB = numpy.array(file.get(f"{group_key}/rcu_attenuator_dB")) - - if file.get(f'{group_key}/rcu_band_select').shape is None: - self.rcu_band_select = None - else: - self.rcu_band_select = numpy.array(file.get(f"{group_key}/rcu_band_select")) - - if file.get(f'{group_key}/rcu_dth_on').shape is None: - self.rcu_dth_on = None - else: - self.rcu_dth_on = numpy.array(file.get(f"{group_key}/rcu_dth_on")) + attribute_names = ["rcu_attenuator_dB", "rcu_band_select", "rcu_dth_on"] + for a in attribute_names: + if file[group_key].attrs[a].shape is None: + setattr(self, a, None) + else : + setattr(self, a, numpy.array(file[group_key].attrs[a])) # 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 3906f436c1acce5beaad45b2f265c6f86fb7fbf8..f1da6a4c5930599973b9f18ad17e8b6f2a28fc9f 100644 --- a/tangostationcontrol/tangostationcontrol/statistics/writer/hdf5.py +++ b/tangostationcontrol/tangostationcontrol/statistics/writer/hdf5.py @@ -87,6 +87,7 @@ class HDF5Writer(ABC): # Set device if any, defaults to None self.device = device + self.device_attributes = {} @abstractmethod def decoder(self, packet): @@ -169,6 +170,8 @@ class HDF5Writer(ABC): # write the finished (and checks if its the first matrix) if self.current_matrix is not None: try: + # query the device attributes for updated values + self.retrieve_attribute_values() self.write_matrix() except Exception as e: time = self.current_timestamp.strftime( @@ -187,6 +190,7 @@ class HDF5Writer(ABC): # create a new and empty current_matrix self.current_matrix = self.new_collector() self.statistics_header = None + self.device_attributes = {} def write_matrix(self): """Writes the finished matrix to the hdf5 file""" @@ -238,6 +242,10 @@ class HDF5Writer(ABC): else: current_group.attrs[k] = v + @abstractmethod + def retrieve_attribute_values(self): + pass + @abstractmethod def write_values_matrix(self, current_group): pass @@ -322,6 +330,19 @@ class SstHdf5Writer(HDF5Writer): def new_collector(self): return StationSSTCollector(self.device) + + def retrieve_attribute_values(self): + 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} + # write the device attributes + for a in attribute_names: + try: + 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].flatten().astype(attribute_types[a]) + except AttributeError: + self.device_attributes[a] = h5py.Empty("f") def write_values_matrix(self, current_group): # store the SST values @@ -333,43 +354,8 @@ class SstHdf5Writer(HDF5Writer): compression="gzip", ) - try: - current_group.create_dataset( - name="rcu_attenuator_dB", - data=self.current_matrix.parameters["rcu_attenuator_dB"].astype(numpy.int64), - compression="gzip", - ) - except AttributeError: - current_group.create_dataset( - name="rcu_attenuator_dB", - data=h5py.Empty("f"), - ) - - try: - current_group.create_dataset( - name="rcu_band_select", - data=self.current_matrix.parameters["rcu_band_select"].astype(numpy.int64), - compression="gzip", - ) - except AttributeError: - current_group.create_dataset( - name="rcu_band_select", - data=h5py.Empty("f"), - ) - - try: - current_group.create_dataset( - name="rcu_dth_on", - data=self.current_matrix.parameters["rcu_dth_on"].astype(numpy.bool_), - compression="gzip", - ) - except AttributeError: - current_group.create_dataset( - name="rcu_dth_on", - data=h5py.Empty("f"), - ) - - + for k,v in self.device_attributes.items(): + current_group.attrs[k] = v class BstHdf5Writer(HDF5Writer): def __init__( @@ -387,6 +373,9 @@ class BstHdf5Writer(HDF5Writer): def new_collector(self): return BSTCollector() + + def retrieve_attribute_values(self): + pass def write_values_matrix(self, current_group): # store the BST values @@ -427,6 +416,9 @@ class XstHdf5Writer(HDF5Writer): f"{self.file_location}/{self.mode}_SB{self.subband_index}_" f"{time_str}{suffix}" ) + + def retrieve_attribute_values(self): + pass def write_values_matrix(self, current_group): # requires a function call to transform the xst_blocks in to the right