Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions docs/user-guide/tof/dream.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@
"id": "21",
"metadata": {},
"source": [
"By default, the workflow tries to load a `TimeOfFlightLookupTable` from a file.\n",
"By default, the workflow tries to load a `TofLookupTable` from a file.\n",
"\n",
"In this notebook, instead of using such a pre-made file,\n",
"we will build our own lookup table from the chopper information and apply it to the workflow."
Expand Down Expand Up @@ -346,7 +346,7 @@
" sc.scalar(75.5, unit=\"m\"),\n",
" sc.scalar(78.0, unit=\"m\"),\n",
")\n",
"lut_wf.visualize(TimeOfFlightLookupTable)"
"lut_wf.visualize(TofLookupTable)"
]
},
{
Expand Down Expand Up @@ -411,7 +411,7 @@
"metadata": {},
"outputs": [],
"source": [
"table = lut_wf.compute(TimeOfFlightLookupTable)\n",
"table = lut_wf.compute(TofLookupTable)\n",
"\n",
"# Overlay mean on the figure above\n",
"table.array[\"distance\", 13].plot(ax=fig2.ax, color=\"C1\", ls=\"-\", marker=None)"
Expand Down Expand Up @@ -453,7 +453,7 @@
"outputs": [],
"source": [
"# Set the computed lookup table onto the original workflow\n",
"wf[TimeOfFlightLookupTable] = table\n",
"wf[TofLookupTable] = table\n",
"\n",
"# Compute time-of-flight of neutron events\n",
"tofs = wf.compute(TofDetector[SampleRun])\n",
Expand Down Expand Up @@ -743,7 +743,7 @@
"metadata": {},
"outputs": [],
"source": [
"table = lut_wf.compute(TimeOfFlightLookupTable).array\n",
"table = lut_wf.compute(TofLookupTable).array\n",
"table.plot() / (sc.stddevs(table) / sc.values(table)).plot(norm=\"log\")"
]
},
Expand All @@ -769,7 +769,7 @@
"source": [
"lut_wf[LookupTableRelativeErrorThreshold] = 0.01\n",
"\n",
"table = lut_wf.compute(TimeOfFlightLookupTable)\n",
"table = lut_wf.compute(TofLookupTable)\n",
"table.plot()"
]
},
Expand Down Expand Up @@ -797,7 +797,7 @@
"wf[RawDetector[SampleRun]] = ess_beamline.get_monitor(\"detector\")[0]\n",
"wf[DetectorLtotal[SampleRun]] = Ltotal\n",
"\n",
"wf[TimeOfFlightLookupTable] = table\n",
"wf[TofLookupTable] = table\n",
"\n",
"# Compute time-of-flight\n",
"tofs = wf.compute(TofDetector[SampleRun])\n",
Expand Down
12 changes: 6 additions & 6 deletions docs/user-guide/tof/frame-unwrapping.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
"id": "9",
"metadata": {},
"source": [
"By default, the workflow tries to load a `TimeOfFlightLookupTable` from a file.\n",
"By default, the workflow tries to load a `TofLookupTable` from a file.\n",
"\n",
"In this notebook, instead of using such a pre-made file,\n",
"we will build our own lookup table from the chopper information and apply it to the workflow.\n",
Expand Down Expand Up @@ -227,7 +227,7 @@
"}\n",
"lut_wf[SourcePosition] = sc.vector([0, 0, 0], unit=\"m\")\n",
"\n",
"lut_wf.visualize(TimeOfFlightLookupTable)"
"lut_wf.visualize(TofLookupTable)"
]
},
{
Expand All @@ -245,7 +245,7 @@
"metadata": {},
"outputs": [],
"source": [
"table = lut_wf.compute(TimeOfFlightLookupTable)\n",
"table = lut_wf.compute(TofLookupTable)\n",
"table.plot()"
]
},
Expand All @@ -267,7 +267,7 @@
"outputs": [],
"source": [
"# Set the computed lookup table on the original workflow\n",
"wf[TimeOfFlightLookupTable] = table\n",
"wf[TofLookupTable] = table\n",
"\n",
"# Compute neutron tofs\n",
"tofs = wf.compute(TofDetector[SampleRun])\n",
Expand Down Expand Up @@ -432,7 +432,7 @@
"metadata": {},
"outputs": [],
"source": [
"table = lut_wf.compute(TimeOfFlightLookupTable)\n",
"table = lut_wf.compute(TofLookupTable)\n",
"\n",
"table.plot(figsize=(9, 4))"
]
Expand All @@ -457,7 +457,7 @@
"nxevent_data = results.to_nxevent_data()\n",
"wf[RawDetector[SampleRun]] = nxevent_data\n",
"wf[DetectorLtotal[SampleRun]] = nxevent_data.coords[\"Ltotal\"]\n",
"wf[TimeOfFlightLookupTable] = table\n",
"wf[TofLookupTable] = table\n",
"\n",
"tofs = wf.compute(TofDetector[SampleRun])\n",
"\n",
Expand Down
8 changes: 4 additions & 4 deletions docs/user-guide/tof/wfm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@
"id": "20",
"metadata": {},
"source": [
"By default, the workflow tries to load a `TimeOfFlightLookupTable` from a file.\n",
"By default, the workflow tries to load a `TofLookupTable` from a file.\n",
"\n",
"In this notebook, instead of using such a pre-made file,\n",
"we will build our own lookup table from the chopper information and apply it to the workflow."
Expand Down Expand Up @@ -365,7 +365,7 @@
"lut_wf[SourcePosition] = source_position\n",
"lut_wf[LtotalRange] = Ltotal, Ltotal\n",
"lut_wf[LookupTableRelativeErrorThreshold] = 0.1\n",
"lut_wf.visualize(TimeOfFlightLookupTable)"
"lut_wf.visualize(TofLookupTable)"
]
},
{
Expand Down Expand Up @@ -430,7 +430,7 @@
"metadata": {},
"outputs": [],
"source": [
"table = lut_wf.compute(TimeOfFlightLookupTable)\n",
"table = lut_wf.compute(TofLookupTable)\n",
"\n",
"# Overlay mean on the figure above\n",
"table.array[\"distance\", 1].plot(ax=fig2.ax, color=\"C1\", ls=\"-\", marker=None)\n",
Expand Down Expand Up @@ -463,7 +463,7 @@
"metadata": {},
"outputs": [],
"source": [
"wf[TimeOfFlightLookupTable] = table\n",
"wf[TofLookupTable] = table\n",
"\n",
"tofs = wf.compute(TofDetector[SampleRun])\n",
"tofs"
Expand Down
4 changes: 4 additions & 0 deletions src/ess/reduce/time_of_flight/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
TimeOfFlightLookupTableFilename,
ToaDetector,
TofDetector,
TofLookupTable,
TofLookupTableFilename,
TofMonitor,
)
from .workflow import GenericTofWorkflow
Expand All @@ -54,6 +56,8 @@
"TimeResolution",
"ToaDetector",
"TofDetector",
"TofLookupTable",
"TofLookupTableFilename",
"TofLookupTableWorkflow",
"TofMonitor",
"providers",
Expand Down
16 changes: 8 additions & 8 deletions src/ess/reduce/time_of_flight/eto_to_tof.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
DetectorLtotal,
MonitorLtotal,
PulseStrideOffset,
TimeOfFlightLookupTable,
ToaDetector,
TofDetector,
TofLookupTable,
TofMonitor,
)

Expand Down Expand Up @@ -96,7 +96,7 @@ def __call__(


def _time_of_flight_data_histogram(
da: sc.DataArray, lookup: TimeOfFlightLookupTable, ltotal: sc.Variable
da: sc.DataArray, lookup: TofLookupTable, ltotal: sc.Variable
) -> sc.DataArray:
# In NeXus, 'time_of_flight' is the canonical name in NXmonitor, but in some files,
# it may be called 'tof' or 'frame_time'.
Expand Down Expand Up @@ -201,7 +201,7 @@ def _guess_pulse_stride_offset(

def _prepare_tof_interpolation_inputs(
da: sc.DataArray,
lookup: TimeOfFlightLookupTable,
lookup: TofLookupTable,
ltotal: sc.Variable,
pulse_stride_offset: int | None,
) -> dict:
Expand Down Expand Up @@ -295,7 +295,7 @@ def _prepare_tof_interpolation_inputs(

def _time_of_flight_data_events(
da: sc.DataArray,
lookup: TimeOfFlightLookupTable,
lookup: TofLookupTable,
ltotal: sc.Variable,
pulse_stride_offset: int | None,
) -> sc.DataArray:
Expand Down Expand Up @@ -395,7 +395,7 @@ def monitor_ltotal_from_straight_line_approximation(

def _compute_tof_data(
da: sc.DataArray,
lookup: TimeOfFlightLookupTable,
lookup: TofLookupTable,
ltotal: sc.Variable,
pulse_stride_offset: int,
) -> sc.DataArray:
Expand All @@ -413,7 +413,7 @@ def _compute_tof_data(

def detector_time_of_flight_data(
detector_data: RawDetector[RunType],
lookup: TimeOfFlightLookupTable,
lookup: TofLookupTable,
ltotal: DetectorLtotal[RunType],
pulse_stride_offset: PulseStrideOffset,
) -> TofDetector[RunType]:
Expand Down Expand Up @@ -447,7 +447,7 @@ def detector_time_of_flight_data(

def monitor_time_of_flight_data(
monitor_data: RawMonitor[RunType, MonitorType],
lookup: TimeOfFlightLookupTable,
lookup: TofLookupTable,
ltotal: MonitorLtotal[RunType, MonitorType],
pulse_stride_offset: PulseStrideOffset,
) -> TofMonitor[RunType, MonitorType]:
Expand Down Expand Up @@ -481,7 +481,7 @@ def monitor_time_of_flight_data(

def detector_time_of_arrival_data(
detector_data: RawDetector[RunType],
lookup: TimeOfFlightLookupTable,
lookup: TofLookupTable,
ltotal: DetectorLtotal[RunType],
pulse_stride_offset: PulseStrideOffset,
) -> ToaDetector[RunType]:
Expand Down
6 changes: 3 additions & 3 deletions src/ess/reduce/time_of_flight/lut.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import scipp as sc

from ..nexus.types import AnyRun, DiskChoppers
from .types import TimeOfFlightLookupTable
from .types import TofLookupTable


@dataclass
Expand Down Expand Up @@ -230,7 +230,7 @@ def make_tof_lookup_table(
pulse_period: PulsePeriod,
pulse_stride: PulseStride,
error_threshold: LookupTableRelativeErrorThreshold,
) -> TimeOfFlightLookupTable:
) -> TofLookupTable:
"""
Compute a lookup table for time-of-flight as a function of distance and
time-of-arrival.
Expand Down Expand Up @@ -372,7 +372,7 @@ def make_tof_lookup_table(
# In-place masking for better performance
_mask_large_uncertainty(table, error_threshold)

return TimeOfFlightLookupTable(
return TofLookupTable(
array=table,
pulse_period=pulse_period,
pulse_stride=pulse_stride,
Expand Down
11 changes: 9 additions & 2 deletions src/ess/reduce/time_of_flight/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@

from ..nexus.types import MonitorType, RunType

TimeOfFlightLookupTableFilename = NewType("TimeOfFlightLookupTableFilename", str)
TofLookupTableFilename = NewType("TofLookupTableFilename", str)
"""Filename of the time-of-flight lookup table."""

TimeOfFlightLookupTableFilename = TofLookupTableFilename
"""Filename of the time-of-flight lookup table (alias)."""


@dataclass
class TimeOfFlightLookupTable:
class TofLookupTable:
"""
Lookup table giving time-of-flight as a function of distance and time of arrival.
"""
Expand Down Expand Up @@ -47,6 +50,10 @@ def plot(self, *args, **kwargs) -> Any:
return self.array.plot(*args, **kwargs)


TimeOfFlightLookupTable = TofLookupTable
"""Lookup table giving time-of-flight as a function of distance and time of arrival
(alias)."""

PulseStrideOffset = NewType("PulseStrideOffset", int | None)
"""
When pulse-skipping, the offset of the first pulse in the stride. This is typically
Expand Down
10 changes: 5 additions & 5 deletions src/ess/reduce/time_of_flight/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
from . import eto_to_tof
from .types import (
PulseStrideOffset,
TimeOfFlightLookupTable,
TimeOfFlightLookupTableFilename,
TofLookupTable,
TofLookupTableFilename,
)


def load_tof_lookup_table(
filename: TimeOfFlightLookupTableFilename,
) -> TimeOfFlightLookupTable:
filename: TofLookupTableFilename,
) -> TofLookupTable:
"""Load a time-of-flight lookup table from an HDF5 file."""
table = sc.io.load_hdf5(filename)

Expand All @@ -40,7 +40,7 @@ def load_tof_lookup_table(
"error_threshold": table.coords["error_threshold"].value,
}

return TimeOfFlightLookupTable(**table)
return TofLookupTable(**table)


def GenericTofWorkflow(
Expand Down
8 changes: 4 additions & 4 deletions tests/time_of_flight/lut_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_lut_workflow_computes_table():
wf[time_of_flight.DistanceResolution] = dres
wf[time_of_flight.TimeResolution] = tres

table = wf.compute(time_of_flight.TimeOfFlightLookupTable)
table = wf.compute(time_of_flight.TofLookupTable)

assert table.array.coords['distance'].min() < lmin
assert table.array.coords['distance'].max() > lmax
Expand Down Expand Up @@ -56,7 +56,7 @@ def test_lut_workflow_computes_table_in_chunks():
wf[time_of_flight.DistanceResolution] = dres
wf[time_of_flight.TimeResolution] = tres

table = wf.compute(time_of_flight.TimeOfFlightLookupTable)
table = wf.compute(time_of_flight.TofLookupTable)

assert table.array.coords['distance'].min() < lmin
assert table.array.coords['distance'].max() > lmax
Expand Down Expand Up @@ -85,7 +85,7 @@ def test_lut_workflow_pulse_skipping():
wf[time_of_flight.DistanceResolution] = dres
wf[time_of_flight.TimeResolution] = tres

table = wf.compute(time_of_flight.TimeOfFlightLookupTable)
table = wf.compute(time_of_flight.TofLookupTable)

assert table.array.coords['event_time_offset'].max() == 2 * sc.scalar(
1 / 14, unit='s'
Expand All @@ -108,7 +108,7 @@ def test_lut_workflow_non_exact_distance_range():
wf[time_of_flight.DistanceResolution] = dres
wf[time_of_flight.TimeResolution] = tres

table = wf.compute(time_of_flight.TimeOfFlightLookupTable)
table = wf.compute(time_of_flight.TofLookupTable)

assert table.array.coords['distance'].min() < lmin
assert table.array.coords['distance'].max() > lmax
Expand Down
12 changes: 3 additions & 9 deletions tests/time_of_flight/unwrap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ def _make_workflow_event_mode(
lut_wf[time_of_flight.LtotalRange] = distance, distance
lut_wf[time_of_flight.LookupTableRelativeErrorThreshold] = error_threshold

pl[time_of_flight.TimeOfFlightLookupTable] = lut_wf.compute(
time_of_flight.TimeOfFlightLookupTable
)
pl[time_of_flight.TofLookupTable] = lut_wf.compute(time_of_flight.TofLookupTable)

return pl, ref

Expand All @@ -104,9 +102,7 @@ def _make_workflow_histogram_mode(dim, distance, choppers, lut_workflow, seed):
lut_wf = lut_workflow.copy()
lut_wf[time_of_flight.LtotalRange] = distance, distance

pl[time_of_flight.TimeOfFlightLookupTable] = lut_wf.compute(
time_of_flight.TimeOfFlightLookupTable
)
pl[time_of_flight.TofLookupTable] = lut_wf.compute(time_of_flight.TofLookupTable)

return pl, ref

Expand Down Expand Up @@ -340,9 +336,7 @@ def test_pulse_skipping_unwrap_when_first_half_of_first_pulse_is_missing() -> No
pl[RawDetector[SampleRun]] = a.bins.concat('event_time_zero')
pl[time_of_flight.DetectorLtotal[SampleRun]] = distance

pl[time_of_flight.TimeOfFlightLookupTable] = lut_wf.compute(
time_of_flight.TimeOfFlightLookupTable
)
pl[time_of_flight.TofLookupTable] = lut_wf.compute(time_of_flight.TofLookupTable)
pl[time_of_flight.PulseStrideOffset] = 1 # Start the stride at the second pulse

tofs = pl.compute(time_of_flight.TofDetector[SampleRun])
Expand Down
Loading
Loading