Skip to content

Commit

Permalink
Merge pull request #170 from scipp/resample-dim-fix
Browse files Browse the repository at this point in the history
Allow `tof` dim in addition to `time_of_flight` in resampling provider for histogrammed data
  • Loading branch information
nvaytet authored Jan 24, 2025
2 parents 1d39793 + df248a6 commit e475965
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
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
7 changes: 4 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 @@ -412,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 e475965

Please sign in to comment.