Skip to content

User can manually configure tof or event_time_offset bin edges.#185

Merged
YooSunYoung merged 5 commits intomainfrom
tof-bin-edges
Jan 16, 2026
Merged

User can manually configure tof or event_time_offset bin edges.#185
YooSunYoung merged 5 commits intomainfrom
tof-bin-edges

Conversation

@YooSunYoung
Copy link
Copy Markdown
Member

@YooSunYoung YooSunYoung commented Jan 15, 2026

Fixes scipp/ess#194

Before, we just had the names in the configuration that does nothing.
Now the time-bin-edges are decided based on the user-configuration.

Selection of time bin edges.

User can decide to use event_time_offset or time-of-flight(tof) to histogram the data.
The former option means the output has histograms of all detectors without calculating time of flight or wavelength.

Setting time-bin-edges.

User can decide the bin edge - min/max and number of bins.
It both works for event_time_offset and time-of-flight.
reduction methods checks if the settings are reasonable based on the data.
It is because not like the event_time_offset,
the range of time-of-flight can change depends on the experiment settings.
Therefore it is good to have a safety check.

@github-project-automation github-project-automation Bot moved this to In progress in Development Board Jan 15, 2026
@YooSunYoung YooSunYoung moved this from In progress to Selected in Development Board Jan 15, 2026
Comment thread src/ess/nmx/executables.py Outdated
f"{wf_config.time_bin_coordinate} values.\n"
"The histogram will all have zero values.",
category=UserWarning,
stacklevel=3,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Different stacklevel compared to above; was that intentional?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

no...! : D.... I'll fix them. Thanks.

Comment thread src/ess/nmx/executables.py Outdated
Comment thread src/ess/nmx/executables.py Outdated
stacklevel=4,
)
else:
min_t = da_min_t
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you want to be careful with the max, because if you set it equal, then the last event will be dropped. See scipp/scipp#3566 for example.
You probably just want to add a nextafter to be safe.

Comment thread src/ess/nmx/executables.py Outdated

# Build the bin-edges to histogram the results.
n_edges = wf_config.nbins + 1
return sc.linspace(dim=t_coord_name, start=min_t, stop=max_tof, num=n_edges)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will users ever want to make log-spaced bins?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't recall. @aaronfinke will they...?

Comment thread tests/executable_test.py Outdated
)


def test_histogram_event_time_offset(reduction_config: ReductionConfig) -> None:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You could consider parametrizing the tests to use both tof and eto coordinates to improve coverage?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

test_reduction_only_number_of_time_bins already uses the tof coordinate since it's the default setting.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess I meant parametrize also the other tests:
test_histogram_invalid_min_max_raises, test_histogram_out_of_range_min_warns, test_histogram_out_of_range_max_warns etc.

They also call the top-level reduction and not the lower level function. This would just be to ensure that nothing specific to the name tof has crept into the _build_time_bin_edges function?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I see...! I parametrized some of them. One of them, there's no overlapping range for eto/tof so I just added one more test using event_time_offset.

They also call the top-level reduction and not the lower level function. This would just be to ensure that nothing specific to the name tof has crept into the _build_time_bin_edges function?

Yeah and the _build_time_bin_edges is just an implementation detail that shouldn't be tested separately I thought.

YooSunYoung and others added 2 commits January 16, 2026 09:04
Co-authored-by: Neil Vaytet <39047984+nvaytet@users.noreply.github.com>
@YooSunYoung
Copy link
Copy Markdown
Member Author

@nvaytet Thank you for reviewing! I fixed the parts you pointed out.

@YooSunYoung YooSunYoung merged commit 14deaf4 into main Jan 16, 2026
4 checks passed
@YooSunYoung YooSunYoung deleted the tof-bin-edges branch January 16, 2026 12:42
@github-project-automation github-project-automation Bot moved this from Selected to Done in Development Board Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

NMXWorkflow: Allow user to specify tof binning parameters from config

2 participants