Skip to content
Snippets Groups Projects
Commit f6a60e22 authored by Stefano Di Frischia's avatar Stefano Di Frischia
Browse files

Merge branch 'L2SS-869-improve-querying-in-stats-writer' into 'master'

Resolve L2SS-869 "Improve querying in stats writer"

Closes L2SS-869

See merge request !426
parents 437f5d98 e7513c44
Branches
No related tags found
1 merge request!426Resolve L2SS-869 "Improve querying in stats writer"
...@@ -202,25 +202,14 @@ class statistics_data: ...@@ -202,25 +202,14 @@ class statistics_data:
# get SST specific stuff # get SST specific stuff
if self.marker == "S": if self.marker == "S":
self.data_id_signal_input_index = file[group_key].attrs["data_id_signal_input_index"] 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 # check if the dataset is empty or not. if empty, set to None, if not get the value
attribute_names = ["rcu_attenuator_dB", "rcu_band_select", "rcu_dth_on"]
if file.get(f'{group_key}/rcu_attenuator_dB').shape is None: for a in attribute_names:
self.rcu_attenuator_dB = None if file[group_key].attrs[a].shape is None:
else: setattr(self, a, None)
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 : else :
self.rcu_dth_on = numpy.array(file.get(f"{group_key}/rcu_dth_on")) setattr(self, a, numpy.array(file[group_key].attrs[a]))
# get XST specific stuff # get XST specific stuff
if self.marker == "X": if self.marker == "X":
......
...@@ -87,6 +87,7 @@ class HDF5Writer(ABC): ...@@ -87,6 +87,7 @@ class HDF5Writer(ABC):
# Set device if any, defaults to None # Set device if any, defaults to None
self.device = device self.device = device
self.device_attributes = {}
@abstractmethod @abstractmethod
def decoder(self, packet): def decoder(self, packet):
...@@ -169,6 +170,8 @@ class HDF5Writer(ABC): ...@@ -169,6 +170,8 @@ class HDF5Writer(ABC):
# write the finished (and checks if its the first matrix) # write the finished (and checks if its the first matrix)
if self.current_matrix is not None: if self.current_matrix is not None:
try: try:
# query the device attributes for updated values
self.retrieve_attribute_values()
self.write_matrix() self.write_matrix()
except Exception as e: except Exception as e:
time = self.current_timestamp.strftime( time = self.current_timestamp.strftime(
...@@ -187,6 +190,7 @@ class HDF5Writer(ABC): ...@@ -187,6 +190,7 @@ class HDF5Writer(ABC):
# create a new and empty current_matrix # create a new and empty current_matrix
self.current_matrix = self.new_collector() self.current_matrix = self.new_collector()
self.statistics_header = None self.statistics_header = None
self.device_attributes = {}
def write_matrix(self): def write_matrix(self):
"""Writes the finished matrix to the hdf5 file""" """Writes the finished matrix to the hdf5 file"""
...@@ -238,6 +242,10 @@ class HDF5Writer(ABC): ...@@ -238,6 +242,10 @@ class HDF5Writer(ABC):
else: else:
current_group.attrs[k] = v current_group.attrs[k] = v
@abstractmethod
def retrieve_attribute_values(self):
pass
@abstractmethod @abstractmethod
def write_values_matrix(self, current_group): def write_values_matrix(self, current_group):
pass pass
...@@ -323,6 +331,19 @@ class SstHdf5Writer(HDF5Writer): ...@@ -323,6 +331,19 @@ class SstHdf5Writer(HDF5Writer):
def new_collector(self): def new_collector(self):
return StationSSTCollector(self.device) 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): def write_values_matrix(self, current_group):
# store the SST values # store the SST values
current_group.create_dataset( current_group.create_dataset(
...@@ -333,43 +354,8 @@ class SstHdf5Writer(HDF5Writer): ...@@ -333,43 +354,8 @@ class SstHdf5Writer(HDF5Writer):
compression="gzip", compression="gzip",
) )
try: for k,v in self.device_attributes.items():
current_group.create_dataset( current_group.attrs[k] = v
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"),
)
class BstHdf5Writer(HDF5Writer): class BstHdf5Writer(HDF5Writer):
def __init__( def __init__(
...@@ -388,6 +374,9 @@ class BstHdf5Writer(HDF5Writer): ...@@ -388,6 +374,9 @@ class BstHdf5Writer(HDF5Writer):
def new_collector(self): def new_collector(self):
return BSTCollector() return BSTCollector()
def retrieve_attribute_values(self):
pass
def write_values_matrix(self, current_group): def write_values_matrix(self, current_group):
# store the BST values # store the BST values
current_group.create_dataset( current_group.create_dataset(
...@@ -428,6 +417,9 @@ class XstHdf5Writer(HDF5Writer): ...@@ -428,6 +417,9 @@ class XstHdf5Writer(HDF5Writer):
f"{time_str}{suffix}" f"{time_str}{suffix}"
) )
def retrieve_attribute_values(self):
pass
def write_values_matrix(self, current_group): def write_values_matrix(self, current_group):
# requires a function call to transform the xst_blocks in to the right # requires a function call to transform the xst_blocks in to the right
# structure # structure
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment