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..dfb548d3ed0b8d51edab43d2c74b280cf40c0162 100644 --- a/tangostationcontrol/tangostationcontrol/integration_test/default/statistics/test_writer_sst.py +++ b/tangostationcontrol/tangostationcontrol/integration_test/default/statistics/test_writer_sst.py @@ -182,9 +182,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, None) + self.assertEqual(stat.rcu_band_select, None) + self.assertEqual(stat.rcu_dth_on, None) def test_SST_statistics_with_device_in_off(self): self.setup_recv_proxy() @@ -222,6 +222,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, 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 eb1594540554b443ec232bee33ffbc67a1cb4722..efed9b52d0ffcac726284eb53db2306898a79403 100644 --- a/tangostationcontrol/tangostationcontrol/statistics/reader.py +++ b/tangostationcontrol/tangostationcontrol/statistics/reader.py @@ -161,7 +161,7 @@ class statistics_data: "source_info_fsub_type", "source_info_beam_repositioning_flag", "source_info_antenna_band_index", "source_info__raw", "observation_id", "nof_statistics_per_packet", "nof_signal_inputs", "nof_bytes_per_statistic", "marker", "integration_interval_raw", "integration_interval", "data_id__raw", "block_serial_number", "block_period_raw", "block_period", "data_id_signal_input_index", - "data_id_subband_index", "data_id_first_baseline", "data_id_beamlet_index", "nof_valid_payloads", "nof_payload_errors", "values", + "data_id_subband_index", "data_id_first_baseline", "data_id_beamlet_index", "nof_valid_payloads", "nof_payload_errors", "values", "rcu_attenuator_dB", "rcu_band_select", "rcu_dth_on") def __init__(self, file, group_key): @@ -202,10 +202,25 @@ 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")) + + # 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")) # 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 a22c909fd5ec461e449094003297c1adbda9e451..3906f436c1acce5beaad45b2f265c6f86fb7fbf8 100644 --- a/tangostationcontrol/tangostationcontrol/statistics/writer/hdf5.py +++ b/tangostationcontrol/tangostationcontrol/statistics/writer/hdf5.py @@ -332,32 +332,43 @@ class SstHdf5Writer(HDF5Writer): ].astype(numpy.float32), compression="gzip", ) + try: current_group.create_dataset( name="rcu_attenuator_dB", - data=self.current_matrix.parameters["rcu_attenuator_dB"].astype( - numpy.int64 - ), + 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 - ), + 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_ - ), + data=self.current_matrix.parameters["rcu_dth_on"].astype(numpy.bool_), compression="gzip", ) - except AttributeError as e: - logger.warning("Device values not written.") - except Exception as e: - raise Exception from e + except AttributeError: + current_group.create_dataset( + name="rcu_dth_on", + data=h5py.Empty("f"), + ) + class BstHdf5Writer(HDF5Writer):