Skip to content

Commit

Permalink
Merge branch 'main' into debug-endless-docs-build
Browse files Browse the repository at this point in the history
  • Loading branch information
nvaytet authored Jan 24, 2025
2 parents cdec165 + e475965 commit e4f61e0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/user-guide/tof/wfm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"# Wavelength frame multiplication\n",
"\n",
"Wavelength frame multiplication (WFM) is a technique commonly used at long-pulse facilities to improve the resolution of the results measured at the neutron detectors.\n",
"See for example the article by [Schmakat et al. (2020)](https://www.sciencedirect.com/science/article/pii/S0168900220308640) for a description of how WFM works.\n",
"See for example the article by [Schmakat et al. (2020)](https://doi.org/10.1016/j.nima.2020.164467) for a description of how WFM works.\n",
"\n",
"In this notebook, we show how to use `essreduce`'s `time_of_flight` module to compute an accurate a time-of-flight coordinate,\n",
"from which a wavelength can be computed."
Expand Down Expand Up @@ -41,7 +41,7 @@
"We begin by defining the chopper settings for our beamline.\n",
"In principle, the chopper setting could simply be read from a NeXus file.\n",
"\n",
"For this example, we create choppers modeled on the [V20 ESS beamline at HZB](https://www.sciencedirect.com/science/article/pii/S0168900216309597).\n",
"For this example, we create choppers modeled on the [V20 ESS beamline at HZB](https://doi.org/10.1016/j.nima.2016.09.034).\n",
"It consists of 5 choppers:\n",
"\n",
"- 2 WFM choppers\n",
Expand Down
2 changes: 2 additions & 0 deletions src/ess/reduce/time_of_flight/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
FrameFoldedTimeOfArrival,
FramePeriod,
LookupTableRelativeErrorThreshold,
Ltotal,
LtotalRange,
MaskedTimeOfFlightLookupTable,
PivotTimeAtDetector,
Expand All @@ -40,6 +41,7 @@
"FrameFoldedTimeOfArrival",
"FramePeriod",
"LookupTableRelativeErrorThreshold",
"Ltotal",
"LtotalRange",
"MaskedTimeOfFlightLookupTable",
"PivotTimeAtDetector",
Expand Down
9 changes: 6 additions & 3 deletions src/ess/reduce/time_of_flight/toa_to_tof.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def compute_tof_lookup_table(
"""
Compute a lookup table for time-of-flight as a function of distance and
time-of-arrival.
Parameters
----------
simulation:
Expand Down Expand Up @@ -342,6 +343,7 @@ def time_of_flight_data(
"""
Convert the time-of-arrival data to time-of-flight data using a lookup table.
The output data will have a time-of-flight coordinate.
Parameters
----------
da:
Expand Down Expand Up @@ -410,15 +412,16 @@ def resample_tof_data(da: TofData) -> ResampledTofData:
da:
Histogrammed data with the time-of-flight coordinate.
"""
events = to_events(da.rename_dims(time_of_flight="tof"), "event")
dim = next(iter(set(da.dims) & {"time_of_flight", "tof"}))
events = to_events(da.rename_dims({dim: "tof"}), "event")

# Define a new bin width, close to the original bin width.
# TODO: this could be a workflow parameter
coord = da.coords["tof"]
bin_width = (coord["time_of_flight", 1:] - coord["time_of_flight", :-1]).nanmedian()
bin_width = (coord[dim, 1:] - coord[dim, :-1]).nanmedian()
rehist = events.hist(tof=bin_width)
for key, var in da.coords.items():
if "time_of_flight" not in var.dims:
if dim not in var.dims:
rehist.coords[key] = var
return ResampledTofData(rehist)

Expand Down
5 changes: 3 additions & 2 deletions tests/time_of_flight/unwrap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def test_standard_unwrap(dist) -> None:
# At 80m, event_time_offset does not wrap around (all events are within the same pulse).
# At 85m, event_time_offset wraps around.
@pytest.mark.parametrize("dist", [80.0, 85.0])
def test_standard_unwrap_histogram_mode(dist) -> None:
@pytest.mark.parametrize("dim", ["time_of_flight", "tof"])
def test_standard_unwrap_histogram_mode(dist, dim) -> None:
distance = sc.scalar(dist, unit="m")
choppers = fakes.psc_choppers()
beamline = fakes.FakeBeamline(
Expand All @@ -131,7 +132,7 @@ def test_standard_unwrap_histogram_mode(dist) -> None:
).to(unit="s")
)
.sum("pulse")
.rename(event_time_offset="time_of_flight")
.rename(event_time_offset=dim)
)

sim = time_of_flight.simulate_beamline(
Expand Down

0 comments on commit e4f61e0

Please sign in to comment.