Skip to content

Add conversion to eV in UndulatorEnergyGap lut - #202

Merged
noemifrisina merged 5 commits into
mainfrom
convert_lut_if_unexpected_units
Sep 10, 2026
Merged

Add conversion to eV in UndulatorEnergyGap lut#202
noemifrisina merged 5 commits into
mainfrom
convert_lut_if_unexpected_units

Conversation

@noemifrisina

Copy link
Copy Markdown
Collaborator

On some beamlines, the lookup table for the UndulatorEnergyGap has the energies in KeV instead of eV, leading to incorrect calculations down the line. This change adds a conversion to the UndulatorEnergyGapLookupTable so that is a table has the units in KeV its rows will be converted to eV.
In case there is no Units line in the lookup table file, eV is assumed as the default and no conversion is done.

@jacob-williamson jacob-williamson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good to me. A couple comments in the code

) -> list[list[float]]:
if units_from_table.lower() == default_energy_unit.lower():
return rows
converted_rows = [[row[0] * 1000, row[1]] for row in rows]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could: explicitly check the if the units from the table are keV, in case some people have weird units. Something like

if units_from_table.lower() == "kev":
    return [[row[0] * 1000, row[1]] for row in rows]
else:
    raise ValueError(f"No conversion implemented for units: {units_from_table}")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, fair enough

Comment thread src/daq_config_server/models/utils.py Outdated
def get_units_from_lut(
contents: str,
default_units: list[str],
units_lines: tuple[str, str] = DEFAULT_IGNORE_LINES_STARTING_WITH[:2],

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think DEFAULT_IGNORE_LINES_STARTING_WITH could be added to/re-ordered which would have the unintended side affect of breaking this. Maybe a new constant DEFAULT_UNITS_LINES would be better, and DEFAULT_IGNORE_LINES_STARTING_WITH could become DEFAULT_UNITS_LINES + ("ScannableNames",)

@jacob-williamson jacob-williamson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@noemifrisina
noemifrisina merged commit f15ea4b into main Sep 10, 2026
15 checks passed
@noemifrisina
noemifrisina deleted the convert_lut_if_unexpected_units branch September 10, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants