Skip to content

Commit de70349

Browse files
authored
Merge pull request #621 from scipp/default-bifrost-detector-names
[ESSSPECTROSCOPY] Default BIFROST detector names
2 parents 18219bb + 49779b1 commit de70349

9 files changed

Lines changed: 88 additions & 126 deletions

File tree

packages/essspectroscopy/docs/user-guide/bifrost/bifrost-make-wavelength-lookup-table.ipynb

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,8 @@
5353
"metadata": {},
5454
"outputs": [],
5555
"source": [
56-
"input_filename = simulated_elastic_incoherent_with_phonon()\n",
57-
"with snx.File(input_filename) as f:\n",
58-
" detector_names = list(f['entry/instrument'][snx.NXdetector])"
59-
]
60-
},
61-
{
62-
"cell_type": "code",
63-
"execution_count": null,
64-
"id": "4",
65-
"metadata": {},
66-
"outputs": [],
67-
"source": [
68-
"bifrost_workflow = BifrostSimulationWorkflow(detector_names)\n",
69-
"bifrost_workflow[Filename[SampleRun]] = input_filename\n",
56+
"bifrost_workflow = BifrostSimulationWorkflow()\n",
57+
"bifrost_workflow[Filename[SampleRun]] = simulated_elastic_incoherent_with_phonon()\n",
7058
"\n",
7159
"M = nexus.types.EmptyMonitor[SampleRun, NormalizationMonitor]\n",
7260
"C = RawChoppers[SampleRun]\n",
@@ -78,7 +66,7 @@
7866
},
7967
{
8068
"cell_type": "markdown",
81-
"id": "5",
69+
"id": "4",
8270
"metadata": {},
8371
"source": [
8472
"Compute the required distance range to include the monitor and all detectors.\n",
@@ -89,7 +77,7 @@
8977
{
9078
"cell_type": "code",
9179
"execution_count": null,
92-
"id": "6",
80+
"id": "5",
9381
"metadata": {},
9482
"outputs": [],
9583
"source": [
@@ -106,7 +94,7 @@
10694
},
10795
{
10896
"cell_type": "markdown",
109-
"id": "7",
97+
"id": "6",
11098
"metadata": {},
11199
"source": [
112100
"The choppers in the simulated file need to be processed before they can be used for computing a lookup table.\n",
@@ -116,7 +104,7 @@
116104
{
117105
"cell_type": "code",
118106
"execution_count": null,
119-
"id": "8",
107+
"id": "7",
120108
"metadata": {},
121109
"outputs": [],
122110
"source": [
@@ -142,15 +130,15 @@
142130
},
143131
{
144132
"cell_type": "markdown",
145-
"id": "9",
133+
"id": "8",
146134
"metadata": {},
147135
"source": [
148136
"## Compute the lookup table"
149137
]
150138
},
151139
{
152140
"cell_type": "markdown",
153-
"id": "10",
141+
"id": "9",
154142
"metadata": {},
155143
"source": [
156144
"Construct a lookup table workflow:"
@@ -159,7 +147,7 @@
159147
{
160148
"cell_type": "code",
161149
"execution_count": null,
162-
"id": "11",
150+
"id": "10",
163151
"metadata": {},
164152
"outputs": [],
165153
"source": [
@@ -175,7 +163,7 @@
175163
{
176164
"cell_type": "code",
177165
"execution_count": null,
178-
"id": "12",
166+
"id": "11",
179167
"metadata": {},
180168
"outputs": [],
181169
"source": [
@@ -184,7 +172,7 @@
184172
},
185173
{
186174
"cell_type": "markdown",
187-
"id": "13",
175+
"id": "12",
188176
"metadata": {},
189177
"source": [
190178
"Compute a lookup table:"
@@ -193,7 +181,7 @@
193181
{
194182
"cell_type": "code",
195183
"execution_count": null,
196-
"id": "14",
184+
"id": "13",
197185
"metadata": {},
198186
"outputs": [],
199187
"source": [
@@ -204,7 +192,7 @@
204192
{
205193
"cell_type": "code",
206194
"execution_count": null,
207-
"id": "15",
195+
"id": "14",
208196
"metadata": {},
209197
"outputs": [],
210198
"source": [
@@ -213,7 +201,7 @@
213201
},
214202
{
215203
"cell_type": "markdown",
216-
"id": "16",
204+
"id": "15",
217205
"metadata": {},
218206
"source": [
219207
"## Save to file"
@@ -222,7 +210,7 @@
222210
{
223211
"cell_type": "code",
224212
"execution_count": null,
225-
"id": "17",
213+
"id": "16",
226214
"metadata": {},
227215
"outputs": [],
228216
"source": [

packages/essspectroscopy/docs/user-guide/bifrost/bifrost-reduction.ipynb

Lines changed: 13 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"import numpy as np\n",
2222
"import scipp as sc\n",
2323
"import sciline\n",
24-
"import scippnexus as snx\n",
2524
"\n",
2625
"from ess import bifrost\n",
2726
"from ess.bifrost.data import (\n",
@@ -36,58 +35,18 @@
3635
"id": "2",
3736
"metadata": {},
3837
"source": [
39-
"BIFROST NeXus files store detector data in 45 separate NXdetector groups, one per detector triplet.\n",
40-
"For the time being, we need to specify the names of these NXdetector groups when creating the workflow.\n",
41-
"So load them from the input file:"
42-
]
43-
},
44-
{
45-
"cell_type": "code",
46-
"execution_count": null,
47-
"id": "3",
48-
"metadata": {},
49-
"outputs": [],
50-
"source": [
51-
"with snx.File(simulated_elastic_incoherent_with_phonon()) as f:\n",
52-
" detector_names = list(f['entry/instrument'][snx.NXdetector])"
53-
]
54-
},
55-
{
56-
"cell_type": "markdown",
57-
"id": "4",
58-
"metadata": {},
59-
"source": [
60-
"Generally, we would use all triplets, but for this example, we only use the first two.\n",
61-
"This reduces the size of the data and the time to compute it."
62-
]
63-
},
64-
{
65-
"cell_type": "code",
66-
"execution_count": null,
67-
"id": "5",
68-
"metadata": {},
69-
"outputs": [],
70-
"source": [
71-
"detector_names = detector_names[:2]"
72-
]
73-
},
74-
{
75-
"cell_type": "markdown",
76-
"id": "6",
77-
"metadata": {},
78-
"source": [
79-
"Next, construct the workflow which is a [sciline.Pipeline](https://scipp.github.io/sciline/generated/classes/sciline.Pipeline.html) and encodes the entire reduction procedure.\n",
38+
"Construct the workflow which is a [sciline.Pipeline](https://scipp.github.io/sciline/generated/classes/sciline.Pipeline.html) and encodes the entire reduction procedure.\n",
8039
"We need to provide a couple of parameters so we can run the workflow:"
8140
]
8241
},
8342
{
8443
"cell_type": "code",
8544
"execution_count": null,
86-
"id": "7",
45+
"id": "3",
8746
"metadata": {},
8847
"outputs": [],
8948
"source": [
90-
"workflow = bifrost.BifrostSimulationWorkflow(detector_names)\n",
49+
"workflow = bifrost.BifrostSimulationWorkflow()\n",
9150
"# Set the input file name:\n",
9251
"workflow[Filename[SampleRun]] = simulated_elastic_incoherent_with_phonon()\n",
9352
"# Set the lookup table for frame unwrapping:\n",
@@ -107,7 +66,7 @@
10766
},
10867
{
10968
"cell_type": "markdown",
110-
"id": "8",
69+
"id": "4",
11170
"metadata": {},
11271
"source": [
11372
"Next, draw the workflow as a graph to inspect the steps it will take to reduce the data.\n",
@@ -119,7 +78,7 @@
11978
{
12079
"cell_type": "code",
12180
"execution_count": null,
122-
"id": "9",
81+
"id": "5",
12382
"metadata": {},
12483
"outputs": [],
12584
"source": [
@@ -128,7 +87,7 @@
12887
},
12988
{
13089
"cell_type": "markdown",
131-
"id": "10",
90+
"id": "6",
13291
"metadata": {},
13392
"source": [
13493
"We are ready to compute the reduced data.\n",
@@ -139,7 +98,7 @@
13998
{
14099
"cell_type": "code",
141100
"execution_count": null,
142-
"id": "11",
101+
"id": "7",
143102
"metadata": {},
144103
"outputs": [],
145104
"source": [
@@ -149,7 +108,7 @@
149108
},
150109
{
151110
"cell_type": "markdown",
152-
"id": "12",
111+
"id": "8",
153112
"metadata": {},
154113
"source": [
155114
"The result contains coordinates for the sample table and detector rotation angles `a3` and `a4`, respectively.\n",
@@ -159,7 +118,7 @@
159118
{
160119
"cell_type": "code",
161120
"execution_count": null,
162-
"id": "13",
121+
"id": "9",
163122
"metadata": {},
164123
"outputs": [],
165124
"source": [
@@ -168,7 +127,7 @@
168127
},
169128
{
170129
"cell_type": "markdown",
171-
"id": "14",
130+
"id": "10",
172131
"metadata": {},
173132
"source": [
174133
"We can plot the counts as a function of energy transfer and $a_3$ by removing the unused dimensions.\n",
@@ -178,7 +137,7 @@
178137
{
179138
"cell_type": "code",
180139
"execution_count": null,
181-
"id": "15",
140+
"id": "11",
182141
"metadata": {},
183142
"outputs": [],
184143
"source": [
@@ -191,7 +150,7 @@
191150
},
192151
{
193152
"cell_type": "markdown",
194-
"id": "16",
153+
"id": "12",
195154
"metadata": {},
196155
"source": [
197156
"We can also plot the counts as a function of the momentum transfer in the sample table frame $Q$.\n",
@@ -207,7 +166,7 @@
207166
{
208167
"cell_type": "code",
209168
"execution_count": null,
210-
"id": "17",
169+
"id": "13",
211170
"metadata": {},
212171
"outputs": [],
213172
"source": [

packages/essspectroscopy/src/ess/bifrost/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import importlib.metadata
77

8-
from .detector import providers
8+
from .detector import default_detector_names
99
from .io import nexus
1010
from .workflow import BifrostSimulationWorkflow, BifrostWorkflow
1111

@@ -16,4 +16,9 @@
1616

1717
del importlib
1818

19-
__all__ = ['BifrostSimulationWorkflow', 'BifrostWorkflow', 'nexus', 'providers']
19+
__all__ = [
20+
'BifrostSimulationWorkflow',
21+
'BifrostWorkflow',
22+
'default_detector_names',
23+
'nexus',
24+
]

packages/essspectroscopy/src/ess/bifrost/detector.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
"""Detector handling for BIFROST."""
55

6+
import itertools
67
from collections.abc import Callable
78

89
import scipp as sc
@@ -281,4 +282,17 @@ def merge_triplets(
281282
return concatenated
282283

283284

285+
def default_detector_names() -> list[str]:
286+
"""Return the list of detector names in a BIFROST NeXus file.
287+
288+
These names are based on the names in the NeXus schema.
289+
"""
290+
# c is the channel number
291+
# a is the arc number
292+
return [
293+
f"channel_{c}_{a}_triplet"
294+
for c, a in itertools.product(range(1, 10), range(1, 6))
295+
]
296+
297+
284298
providers = (arc_number, get_calibrated_detector_bifrost)

packages/essspectroscopy/src/ess/bifrost/live.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99

1010
import sciline
1111
import scipp as sc
12-
from ess.spectroscopy.types import (
13-
EnergyQDetector,
14-
NeXusDetectorName,
15-
RunType,
16-
)
12+
from ess.spectroscopy.types import EnergyQDetector, RunType
1713

1814
from .types import ArcEnergy
1915
from .workflow import BifrostWorkflow
@@ -170,9 +166,9 @@ def cut(
170166
)
171167

172168

173-
def BifrostQCutWorkflow(detector_names: list[NeXusDetectorName]) -> sciline.Pipeline:
169+
def BifrostQCutWorkflow(detector_names: list[str] | None = None) -> sciline.Pipeline:
174170
"""Workflow for BIFROST to compute cuts in Q-E-space."""
175-
workflow = BifrostWorkflow(detector_names)
171+
workflow = BifrostWorkflow(detector_names=detector_names)
176172
workflow.insert(arc_energy)
177173
workflow.insert(cut)
178174
return workflow

0 commit comments

Comments
 (0)