Simplified and documented parse_attribute function.

This commit is contained in:
2024-06-04 09:51:12 +02:00
parent 014bd14fcd
commit fa2990527e

View File

@ -39,19 +39,18 @@ def get_review_status(filename_path):
workflow_steps.append(line)
return workflow_steps[-1]
def parse_attribute(attr_value):
def parse_attribute(attr_value : dict):
"Parse a dictionary attribute into an equivalent numpy structured array, which compatible with compound HDF5 type"
dtype = []
values_list = []
max_length = max(len(item) for item in attr_value.keys())
max_length = max(len(str(attr_value[key])) for key in attr_value.keys())
for key in attr_value.keys():
if (not key=='rename_as'):
dtype.append((key,f'S{max_length}'))
values_list.append(attr_value[key])
if len(values_list)>1:
if values_list:
new_attr_value = np.array([tuple(values_list)],dtype=dtype)
elif values_list:
new_attr_value = values_list[0]
else:
new_attr_value = 'missing'