Skip to content

Update lookup table generating tool using tof. #177

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
89 changes: 73 additions & 16 deletions tools/dream-make-tof-lookup-table.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@
"outputs": [],
"source": [
"import scipp as sc\n",
"import sciline as sl\n",
"from ess.reduce import time_of_flight\n",
"from ess.dream.beamline import InstrumentConfiguration, choppers"
"from ess.reduce.nexus.types import SampleRun, Position\n",
"from ess.reduce.time_of_flight.simulation import DiskChoppers, NumberOfSimulatedNeutrons\n",
"import scippnexus as snx\n",
"\n",
"\n",
"from ess.dream.beamline import InstrumentConfiguration, choppers\n",
"\n",
"DISPLAY_INTERMEDIATE_STEPS = False"
]
},
{
Expand All @@ -36,7 +42,11 @@
"metadata": {},
"outputs": [],
"source": [
"disk_choppers = choppers(InstrumentConfiguration.high_flux)"
"disk_choppers = choppers(InstrumentConfiguration.high_flux)\n",
"for chopper_name, chopper in disk_choppers.items():\n",
" if DISPLAY_INTERMEDIATE_STEPS:\n",
" display(chopper_name)\n",
" display(chopper)"
]
},
{
Expand All @@ -54,15 +64,21 @@
"metadata": {},
"outputs": [],
"source": [
"wf = sl.Pipeline(\n",
" time_of_flight.providers(), params=time_of_flight.default_parameters()\n",
"# Initialize the workflow\n",
"wf = time_of_flight.GenericTofWorkflow(\n",
" tof_lut_provider=time_of_flight.TofLutProvider.TOF, # This argument decides if the workflow uses `tof` to generate the lookup table\n",
" # RunType and MonitorType does not matter for lookup table generation.\n",
" run_types=[],\n",
" monitor_types=[],\n",
")\n",
"\n",
"wf[time_of_flight.LtotalRange] = sc.scalar(60.0, unit=\"m\"), sc.scalar(80.0, unit=\"m\")\n",
"wf[time_of_flight.SimulationResults] = time_of_flight.simulate_beamline(\n",
" choppers=disk_choppers, neutrons=5_000_000, source_position=sc.vector([0, 0, 0], unit='m'),\n",
")\n",
"# Set tof simulation parameters\n",
"wf[DiskChoppers[SampleRun]] = sc.DataGroup(disk_choppers) # Mapping of chopper names to `DisckChopper` objects\n",
"wf[Position[snx.NXsource, SampleRun]] = sc.vector([0, 0, 0], unit='m') # Position of the source\n",
"wf[NumberOfSimulatedNeutrons] = 5_000_000 # Number of neutrons to simulate. More neutrons means better resolution of the lookup table. Feel free to increase as much as you want.\n",
"\n",
"# Set lookup table parameters\n",
"wf[time_of_flight.LtotalRange] = sc.scalar(60.0, unit=\"m\"), sc.scalar(80.0, unit=\"m\")\n",
"wf[time_of_flight.DistanceResolution] = sc.scalar(0.1, unit=\"m\")\n",
"wf[time_of_flight.TimeResolution] = sc.scalar(250.0, unit='us')\n",
"wf[time_of_flight.LookupTableRelativeErrorThreshold] = 0.02\n",
Expand All @@ -72,17 +88,27 @@
]
},
{
"cell_type": "markdown",
"cell_type": "code",
"execution_count": null,
"id": "6",
"metadata": {},
"outputs": [],
"source": [
"wf.visualize(time_of_flight.TimeOfFlightLookupTable)"
]
},
{
"cell_type": "markdown",
"id": "7",
"metadata": {},
"source": [
"## Compute the table"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7",
"id": "8",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -93,7 +119,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "8",
"id": "9",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -102,7 +128,7 @@
},
{
"cell_type": "markdown",
"id": "9",
"id": "10",
"metadata": {},
"source": [
"## Save to file"
Expand All @@ -111,7 +137,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "10",
"id": "11",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -121,11 +147,41 @@
"# Write to file\n",
"table.save_hdf5('DREAM-high-flux-tof-lookup-table.h5')"
]
},
{
"cell_type": "markdown",
"id": "12",
"metadata": {},
"source": [
"## Load the file"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you add this here? This notebook is not a user-guide. That is what https://scipp.github.io/essreduce/user-guide/tof/index.html is for. Can you instead put a link to that page at the top of the notebook?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to link to an example that uses the time_of_flight.TofLutProvider.FILE mode but I couldn't find one...

]
},
{
"cell_type": "code",
"execution_count": null,
"id": "13",
"metadata": {},
"outputs": [],
"source": [
"# Initialize the workflow\n",
"wf = time_of_flight.GenericTofWorkflow(\n",
" tof_lut_provider=time_of_flight.TofLutProvider.FILE, # This argument decides if the workflow uses a file to load the lookup table\n",
" run_types=[],\n",
" monitor_types=[],\n",
")\n",
"# Set lookup table parameters\n",
"wf[time_of_flight.TimeOfFlightLookupTableFilename] = 'DREAM-high-flux-tof-lookup-table.h5'\n",
"loaded_table = wf.compute(time_of_flight.TimeOfFlightLookupTable)\n",
"if DISPLAY_INTERMEDIATE_STEPS:\n",
" display(wf.visualize(time_of_flight.TimeOfFlightLookupTable))\n",
" display(loaded_table)\n",
"table.plot()\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "diff-dev-310",
"language": "python",
"name": "python3"
},
Expand All @@ -138,7 +194,8 @@
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3"
"pygments_lexer": "ipython3",
"version": "3.10.17"
}
},
"nbformat": 4,
Expand Down