Source code for production_configuration.histogram_output_metadata
"""Shared helpers for production outputs derived from trigger-histogram metadata."""
import astropy.units as u
def _read_source_value(source, column_name):
"""Read a value from a dict-like source, keeping units of table-column scalars."""
try:
value = source[column_name]
except KeyError, IndexError, TypeError:
return None
table = getattr(source, "table", None)
if table is not None and column_name in table.colnames:
unit = getattr(table[column_name], "unit", None)
if unit is not None:
return u.Quantity(value, unit)
return value