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

Make a wrapped lookup table to time-of-flight #180

Merged
merged 47 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
9b1347f
start making a wrapped lookup table instead of having to unwrap and t…
nvaytet Jan 31, 2025
6b858ab
use event_time_offset coord from raw data
nvaytet Jan 31, 2025
0208890
TimeOfArrivalResolution -> TimeResolution
nvaytet Feb 3, 2025
a313893
fix table bins in time and begin cleanup
nvaytet Feb 3, 2025
a931ce8
give a pulse_index to each event to allow for pulse skipping, and use…
nvaytet Feb 3, 2025
15f5f8b
fix mesh in pulse dimension
nvaytet Feb 3, 2025
1e54929
remove the need for concatenating bins using modulo
nvaytet Feb 3, 2025
7ba4464
compute table in chunks to avoid ram issues
nvaytet Feb 4, 2025
9110905
cleanup
nvaytet Feb 4, 2025
0eb5ae3
move pulse stride offset to table computation
nvaytet Feb 4, 2025
d41ffec
fix some unwrap tests
nvaytet Feb 4, 2025
ee922c4
support histogram data. there is still an issue with to_events
nvaytet Feb 4, 2025
96ef840
avoid interpolation for table values from centers to edges by using p…
nvaytet Feb 5, 2025
f05e123
cleanup and remove some duplicate calculations
nvaytet Feb 5, 2025
5c26a2c
add bin edge at 71ms in case of histogrammed data and refactor code f…
nvaytet Feb 5, 2025
525d6a5
update to_events tests
nvaytet Feb 5, 2025
3961df1
fix more unwrap tests
nvaytet Feb 5, 2025
a2f5487
fix more tests, but we still have an issue with the periodic boundary…
nvaytet Feb 5, 2025
5c792ff
start adding pulse index lookup
nvaytet Feb 5, 2025
204231f
Merge branch 'wrapped-tof-lookup' of github.com:scipp/essreduce into …
nvaytet Feb 5, 2025
8db738c
ditch the lookup and use modulo ops instead
nvaytet Feb 5, 2025
e391466
fix test when there are no events in the first pulse
nvaytet Feb 5, 2025
41d3b21
go back to the lookup as the algorithm is easier to understand and mo…
nvaytet Feb 6, 2025
d147477
fix remaining unwrap tests
nvaytet Feb 6, 2025
8b07aa0
fix some WFM tests
nvaytet Feb 6, 2025
e521b99
fix last wfm tests
nvaytet Feb 6, 2025
1b2d3a4
Merge branch 'main' into wrapped-tof-lookup
nvaytet Feb 6, 2025
7574f9c
update wfm notebook
nvaytet Feb 6, 2025
35cd5cb
update deps to get latest tof
nvaytet Feb 6, 2025
5866c55
update dream notebook
nvaytet Feb 7, 2025
e580323
update frame unwrapping notebook. No longer need the concept of pivot…
nvaytet Feb 7, 2025
8e22b1a
Update src/ess/reduce/time_of_flight/toa_to_tof.py
nvaytet Feb 7, 2025
8b9d47a
refactor flattening on simulation neutron event data
nvaytet Feb 7, 2025
0e6ee6c
compute table on frame period and fold along pulse dimension further …
nvaytet Feb 7, 2025
0a218fa
change time resolution to be a scalar variable
nvaytet Feb 7, 2025
51849f9
split long function into separate parts
nvaytet Feb 7, 2025
17e3e3a
fix pulse stride offset
nvaytet Feb 7, 2025
d4b8800
update deps in py310 env
nvaytet Feb 7, 2025
fa1d7e0
Merge branch 'main' into wrapped-tof-lookup
nvaytet Feb 7, 2025
c15c84c
add comment about pulse indices for data arriving in chunks
nvaytet Feb 10, 2025
2db88f3
Merge branch 'main' into wrapped-tof-lookup
nvaytet Feb 10, 2025
01ed6e7
simplify table folding
nvaytet Feb 10, 2025
f08200b
fix table folding
nvaytet Feb 10, 2025
18d7ee9
Merge branch 'wrapped-tof-lookup' of github.com:scipp/essreduce into …
nvaytet Feb 10, 2025
b9ed7b7
allow to simulate more than one pulse. This is sometimes required whe…
nvaytet Feb 11, 2025
975ef9b
add test with pulse skipping chopper phase offset by 180 deg
nvaytet Feb 11, 2025
fa28370
simplify distance bins
nvaytet Feb 11, 2025
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
81 changes: 39 additions & 42 deletions docs/user-guide/tof/dream.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
"raw_data = ess_beamline.get_monitor(\"detector\")[0]\n",
"\n",
"# Visualize\n",
"raw_data.hist(event_time_offset=300).sum(\"pulse\").plot()"
"raw_data.hist(event_time_offset=300).squeeze().plot()"
]
},
{
Expand Down Expand Up @@ -290,8 +290,10 @@
" time_of_flight.providers(), params=time_of_flight.default_parameters()\n",
")\n",
"workflow[time_of_flight.RawData] = raw_data\n",
"workflow[time_of_flight.LtotalRange] = (sc.scalar(75.5, unit='m'),\n",
" sc.scalar(78.0, unit='m'))\n",
"workflow[time_of_flight.LtotalRange] = (\n",
" sc.scalar(75.5, unit=\"m\"),\n",
" sc.scalar(78.0, unit=\"m\"),\n",
")\n",
"\n",
"workflow.visualize(time_of_flight.TofData)"
]
Expand All @@ -314,8 +316,7 @@
"outputs": [],
"source": [
"workflow[time_of_flight.SimulationResults] = time_of_flight.simulate_beamline(\n",
" choppers=disk_choppers,\n",
" neutrons=2_000_000\n",
" choppers=disk_choppers, neutrons=2_000_000\n",
")"
]
},
Expand Down Expand Up @@ -343,17 +344,24 @@
"outputs": [],
"source": [
"sim = workflow.compute(time_of_flight.SimulationResults)\n",
"# Compute time-of-arrival at the detector\n",
"tarrival = sim.time_of_arrival + ((Ltotal - sim.distance) / sim.speed).to(unit=\"us\")\n",
"# Compute time-of-flight at the detector\n",
"tflight = (Ltotal / sim.speed).to(unit=\"us\")\n",
"\n",
"events = sc.DataArray(\n",
" data=sim.weight,\n",
" coords={\"wavelength\": sim.wavelength, \"toa\": tarrival, \"tof\": tflight},\n",
")\n",
"fig1 = events.hist(wavelength=300, toa=300).plot(norm=\"log\")\n",
"fig2 = events.hist(tof=300, toa=300).plot(norm=\"log\")\n",
"\n",
"\n",
"def to_event_time_offset(sim):\n",
" # Compute event_time_offset at the detector\n",
" eto = (\n",
" sim.time_of_arrival + ((Ltotal - sim.distance) / sim.speed).to(unit=\"us\")\n",
" ) % sc.scalar(1e6 / 14.0, unit=\"us\")\n",
" # Compute time-of-flight at the detector\n",
" tof = (Ltotal / sim.speed).to(unit=\"us\")\n",
" return sc.DataArray(\n",
" data=sim.weight,\n",
" coords={\"wavelength\": sim.wavelength, \"event_time_offset\": eto, \"tof\": tof},\n",
" )\n",
"\n",
"\n",
"events = to_event_time_offset(sim)\n",
"fig1 = events.hist(wavelength=300, event_time_offset=300).plot(norm=\"log\")\n",
"fig2 = events.hist(tof=300, event_time_offset=300).plot(norm=\"log\")\n",
"fig1 + fig2"
]
},
Expand All @@ -374,10 +382,10 @@
"metadata": {},
"outputs": [],
"source": [
"table = workflow.compute(time_of_flight.TimeOfFlightLookupTable)\n",
"table = workflow.compute(time_of_flight.TimeOfFlightLookupTable).squeeze()\n",
"\n",
"# Overlay mean on the figure above\n",
"table[\"distance\", 13].plot(ax=fig2.ax, color=\"C1\", ls='-', marker=None)"
"table[\"distance\", 13].plot(ax=fig2.ax, color=\"C1\", ls=\"-\", marker=None)"
]
},
{
Expand Down Expand Up @@ -447,7 +455,8 @@
"# Define wavelength bin edges\n",
"wavs = sc.linspace(\"wavelength\", 0.8, 4.6, 201, unit=\"angstrom\")\n",
"\n",
"wav_wfm.hist(wavelength=wavs).sum(\"pulse\").plot()"
"histogrammed = wav_wfm.hist(wavelength=wavs).squeeze()\n",
"histogrammed.plot()"
]
},
{
Expand All @@ -473,7 +482,7 @@
"\n",
"pp.plot(\n",
" {\n",
" \"wfm\": wav_wfm.hist(wavelength=wavs).sum(\"pulse\"),\n",
" \"wfm\": histogrammed,\n",
" \"ground_truth\": ground_truth.hist(wavelength=wavs),\n",
" }\n",
")"
Expand Down Expand Up @@ -530,16 +539,12 @@
"outputs": [],
"source": [
"raw_data = sc.concat(\n",
" [ess_beamline.get_monitor(key)[0] for key in monitors.keys()],\n",
" [ess_beamline.get_monitor(key)[0].squeeze() for key in monitors.keys()],\n",
" dim=\"detector_number\",\n",
")\n",
"\n",
"# Visualize\n",
"pp.plot(\n",
" sc.collapse(\n",
" raw_data.hist(event_time_offset=300).sum(\"pulse\"), keep=\"event_time_offset\"\n",
" )\n",
")"
"pp.plot(sc.collapse(raw_data.hist(event_time_offset=300), keep=\"event_time_offset\"))"
]
},
{
Expand Down Expand Up @@ -655,22 +660,14 @@
"source": [
"# Update workflow\n",
"workflow[time_of_flight.SimulationResults] = time_of_flight.simulate_beamline(\n",
" choppers=disk_choppers,\n",
" neutrons=2_000_000\n",
" choppers=disk_choppers, neutrons=2_000_000\n",
")\n",
"workflow[time_of_flight.RawData] = ess_beamline.get_monitor(\"detector\")[0]\n",
"\n",
"sim = workflow.compute(time_of_flight.SimulationResults)\n",
"# Compute time-of-arrival at the detector\n",
"tarrival = sim.time_of_arrival + ((Ltotal - sim.distance) / sim.speed).to(unit=\"us\")\n",
"# Compute time-of-flight at the detector\n",
"tflight = (Ltotal / sim.speed).to(unit=\"us\")\n",
"\n",
"events = sc.DataArray(\n",
" data=sim.weight,\n",
" coords={\"wavelength\": sim.wavelength, \"toa\": tarrival, \"tof\": tflight},\n",
")\n",
"events.hist(wavelength=300, toa=300).plot(norm=\"log\")"
"\n",
"events = to_event_time_offset(sim)\n",
"events.hist(wavelength=300, event_time_offset=300).plot(norm=\"log\")"
]
},
{
Expand All @@ -696,7 +693,7 @@
"metadata": {},
"outputs": [],
"source": [
"table = workflow.compute(time_of_flight.TimeOfFlightLookupTable)\n",
"table = workflow.compute(time_of_flight.TimeOfFlightLookupTable).squeeze()\n",
"table.plot() / (sc.stddevs(table) / sc.values(table)).plot(norm=\"log\")"
]
},
Expand All @@ -720,9 +717,9 @@
"metadata": {},
"outputs": [],
"source": [
"workflow[time_of_flight.LookupTableRelativeErrorThreshold] = 1.0e-2\n",
"workflow[time_of_flight.LookupTableRelativeErrorThreshold] = 0.01\n",
"\n",
"workflow.compute(time_of_flight.MaskedTimeOfFlightLookupTable).plot()"
"workflow.compute(time_of_flight.TimeOfFlightLookupTable).squeeze().plot()"
]
},
{
Expand Down Expand Up @@ -757,7 +754,7 @@
"\n",
"pp.plot(\n",
" {\n",
" \"wfm\": wav_wfm.hist(wavelength=wavs).sum(\"pulse\"),\n",
" \"wfm\": wav_wfm.hist(wavelength=wavs).squeeze(),\n",
" \"ground_truth\": ground_truth.hist(wavelength=wavs),\n",
" }\n",
")"
Expand Down
Loading