Skip to content

Commit

Permalink
small improvements to notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
nvaytet committed Jul 4, 2024
1 parent be26e47 commit 0f93492
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions docs/wfm-stitching.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,12 @@
"source": [
"model = tof.Model(source=source, choppers=choppers, detectors=detectors)\n",
"res = model.run()\n",
"f = res.detectors[\"detector\"].tofs.plot()\n",
"f = res.detectors[\"detector\"].tofs.plot(legend=False)\n",
"for i, bound in enumerate(frame_bounds):\n",
" f.ax.axvline(bound[0].value, color=f\"C{i}\")\n",
" f.ax.axvline(bound[1].value, color=f\"C{i}\")\n",
" col = f\"C{i + 1}\"\n",
" f.ax.axvspan(bound[0].value, bound[1].value, alpha=0.1, color=col)\n",
" f.ax.axvline(bound[0].value, color=col)\n",
" f.ax.axvline(bound[1].value, color=col)\n",
"f"
]
},
Expand Down Expand Up @@ -345,8 +347,8 @@
" + [f.coords[\"wavelength\"] for f in frame_max],\n",
" dim=\"event\",\n",
")\n",
"source = tof.Source.from_neutrons(birth_times=birth_times, wavelengths=wavelengths)\n",
"source"
"source_min_max = tof.Source.from_neutrons(birth_times=birth_times, wavelengths=wavelengths)\n",
"source_min_max"
]
},
{
Expand All @@ -365,7 +367,7 @@
"metadata": {},
"outputs": [],
"source": [
"model = tof.Model(source=source, choppers=choppers, detectors=detectors)\n",
"model = tof.Model(source=source_min_max, choppers=choppers, detectors=detectors)\n",
"model.run().plot()"
]
},
Expand Down Expand Up @@ -403,14 +405,11 @@
"outputs": [],
"source": [
"# Extract the tof data of the events that make it through to the detector\n",
"tofs = res[\"detector\"].tofs.data[\"visible\"][\"pulse:0\"]\n",
"tofs = res[\"detector\"].tofs.data[\"visible\"][\"pulse:0\"].copy()\n",
"tofs.coords[\"source_position\"] = sc.vector([0.0, 0.0, 0.0], unit=\"m\")\n",
"tofs.coords[\"position\"] = sc.vector(\n",
" [0.0, 0.0, detectors[0].distance.value], unit=detectors[0].distance.unit\n",
")\n",
"tofs.coords[\"sample_position\"] = 0.5 * (\n",
" tofs.coords[\"source_position\"] + tofs.coords[\"position\"]\n",
")\n",
"tofs"
]
},
Expand All @@ -430,7 +429,7 @@
"outputs": [],
"source": [
"# Make a coordinate transformation graph to compute wavelength from tof\n",
"graph = {**beamline(scatter=True), **elastic(\"tof\")}\n",
"graph = {**beamline(scatter=False), **elastic(\"tof\")}\n",
"wav_naive = tofs.transform_coords(\"wavelength\", graph=graph)\n",
"wav_naive.hist(wavelength=300).plot()"
]
Expand Down

0 comments on commit 0f93492

Please sign in to comment.