Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise errors if we are trying to access values outside of the distance and pulse range of the time-of-flight lookup table #211

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

nvaytet
Copy link
Member

@nvaytet nvaytet commented Mar 10, 2025

Errors are now raised if we attempt to compute tof outside of the distance and pulse range of the lookup table.

We do not raise for the event_time_offset range (even though it should all wrap around 71ms) because histogrammed monitors often have binning which can be anything (does not necessarily stop at 71ms).
Raising an error here would be too restrictive, and warnings would add noise to the workflows.

@nvaytet nvaytet requested a review from jl-wynen March 10, 2025 14:33
@jl-wynen jl-wynen self-assigned this Mar 10, 2025
ltotal: sc.Variable,
event_time_offset: sc.Variable,
) -> sc.Variable:
if pulse_index.unit != sc.units.dimensionless:
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it have unit == None?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could... it comes from (event_time_zero - reference) // pulse_period. So it's kind of dimensionless, but it's true that it doesn't represent a physical quantity.

It would add some code like manually setting pulse_index.unit = None, which currently is not needed.
I don't mind either way.

Copy link
Member

Choose a reason for hiding this comment

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

We had a similar discussion at some point in ESSreflectometry. If the index is used in mathematical operations with non-index quantities, then it is easiest to stick with dimensionless. Otherwise, I'd switch to unit=None.

Copy link
Member Author

Choose a reason for hiding this comment

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

How about having if pulse_index.unit not in ('', None): so that we can decide to change it to None later and it won't break here?

Currently, we are using numpy/scipy to perform the interpolation, so the unit doesn't really matter.
But we may decide to change to using Scipp in the future.

Copy link
Member

Choose a reason for hiding this comment

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

Sure

f"pulse_index must be dimensionless, but got unit: {pulse_index.unit}."
)
if ltotal.unit != self._distance_unit:
raise ValueError(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
raise ValueError(
raise sc.UnitError(

?
And the same for the other cases.

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