Skip to content

Commit 51ffec6

Browse files
authored
Merge pull request #647 from scipp/add-pulse-shaping-choppers
[ESSDIFFRACTION] feat: add workflow using lookup tables for pulse shaping modes
2 parents 98b4ef0 + 6a0311c commit 51ffec6

12 files changed

Lines changed: 1110 additions & 534 deletions

File tree

packages/essdiffraction/docs/api-reference/index.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,14 @@
123123
.. autosummary::
124124
:toctree: ../generated/functions
125125
126+
BeerMcStasWorkflowPulseShaping
127+
BeerMcStasWorkflowPulseShapingAnalytical
126128
BeerModMcStasWorkflowKnownPeaks
127129
BeerModMcStasWorkflow
130+
BeerPowderWorkflow
131+
BeerPowderWorkflowAnalytical
132+
BeerPowderMcStasWorkflow
133+
BeerPowderMcStasWorkflowAnalytical
128134
```
129135

130136
### Top-level functions
@@ -135,7 +141,8 @@
135141
.. autosummary::
136142
:toctree: ../generated/functions
137143
138-
load_beer_mcstas
144+
dhkl_peaks_from_cif
145+
load_beer_mcstas
139146
```
140147

141148
### Submodules
@@ -150,6 +157,7 @@
150157
conversions
151158
data
152159
io
160+
mcstas
153161
workflow
154162
```
155163

packages/essdiffraction/src/ess/beer/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@
77

88
import importlib.metadata
99

10-
from .io import load_beer_mcstas
10+
from .mcstas import load_beer_mcstas
1111
from .peakfinding import dhkl_peaks_from_cif
1212
from .workflow import (
1313
BeerMcStasWorkflowPulseShaping,
14+
BeerMcStasWorkflowPulseShapingAnalytical,
1415
BeerModMcStasWorkflow,
1516
BeerModMcStasWorkflowKnownPeaks,
17+
BeerPowderMcStasWorkflow,
18+
BeerPowderMcStasWorkflowAnalytical,
19+
BeerPowderWorkflow,
20+
BeerPowderWorkflowAnalytical,
1621
default_parameters,
1722
)
1823

@@ -25,8 +30,13 @@
2530

2631
__all__ = [
2732
'BeerMcStasWorkflowPulseShaping',
33+
'BeerMcStasWorkflowPulseShapingAnalytical',
2834
'BeerModMcStasWorkflow',
2935
'BeerModMcStasWorkflowKnownPeaks',
36+
'BeerPowderMcStasWorkflow',
37+
'BeerPowderMcStasWorkflowAnalytical',
38+
'BeerPowderWorkflow',
39+
'BeerPowderWorkflowAnalytical',
3040
'__version__',
3141
'default_parameters',
3242
'dhkl_peaks_from_cif',

packages/essdiffraction/src/ess/beer/clustering.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from ess.powder.types import RunType
33
from scipy.signal import find_peaks, medfilt
44

5-
from .conversions import tof_from_t0_estimate_graph
5+
from .conversions import tof_from_nominal_time_at_chopper_graph
66
from .types import (
77
GeometryCoordTransformGraph,
88
RawDetector,
@@ -13,7 +13,7 @@
1313
def cluster_events_by_streak(
1414
da: RawDetector[RunType], gg: GeometryCoordTransformGraph
1515
) -> StreakClusteredData[RunType]:
16-
graph = tof_from_t0_estimate_graph(da, gg)
16+
graph = tof_from_nominal_time_at_chopper_graph(da, gg)
1717

1818
da = da.transform_coords(['dspacing'], graph=graph)
1919
da.bins.coords['coarse_d'] = da.bins.coords.pop('dspacing').to(unit='angstrom')

packages/essdiffraction/src/ess/beer/conversions.py

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ def compute_wavelength_in_each_cluster(
1919
da: StreakClusteredData[RunType],
2020
chopper_delay: WavelengthDefinitionChopperDelay,
2121
mod_period: ModulationPeriod,
22-
graph: GeometryCoordTransformGraph,
2322
) -> WavelengthDetector[RunType]:
2423
"""Fits a line through each cluster, the intercept of the line is t0.
2524
The line is fitted using linear regression with an outlier removal procedure.
@@ -38,7 +37,7 @@ def compute_wavelength_in_each_cluster(
3837
if isinstance(da, sc.DataGroup):
3938
return sc.DataGroup(
4039
{
41-
k: compute_wavelength_in_each_cluster(v, mod_period)
40+
k: compute_wavelength_in_each_cluster(v, chopper_delay, mod_period)
4241
for k, v in da.items()
4342
}
4443
)
@@ -133,7 +132,7 @@ def _compute_d_given_list_of_peaks(
133132
/ (scipp.constants.h / scipp.constants.m_n)
134133
).to(unit=f'{time_of_arrival.unit}/angstrom')
135134
for dhkl in dhkl_list:
136-
dt = sc.abs(t - dhkl * const)
135+
dt = sc.abs(t - dhkl * const - pulse_length / 2)
137136
dt_in_range = dt < pulse_length / 2
138137
no_dt_found = sc.isnan(dtfound)
139138
dtfound = sc.where(dt_in_range, sc.where(no_dt_found, dt, dtfound), dtfound)
@@ -191,34 +190,16 @@ def _tof_from_dhkl(
191190
return out
192191

193192

194-
def t0_estimate(
195-
wavelength_estimate: sc.Variable,
196-
source_to_wavelength_definition_chopper_distance: sc.Variable,
197-
) -> sc.Variable:
198-
"""
199-
Computes the time a neutron reaches a chopper at
200-
``source_to_wavelength_chopper_distance`` distance from the source
201-
if it has wavelength ``wavelength_estimate``.
202-
"""
203-
return (
204-
sc.constants.m_n
205-
/ sc.constants.h
206-
* wavelength_estimate
207-
* source_to_wavelength_definition_chopper_distance.to(
208-
unit=wavelength_estimate.unit
209-
)
210-
).to(unit='s')
211-
212-
213-
def tof_from_t0_estimate_graph(
193+
def tof_from_nominal_time_at_chopper_graph(
214194
da: RawDetector[RunType],
215195
gg: GeometryCoordTransformGraph,
216196
) -> ElasticCoordTransformGraph[RunType]:
217197
"""Graph for computing ``wavelength`` in pulse shaping chopper modes."""
218198
return {
219199
**gg,
220-
't0': t0_estimate,
221-
'tof': lambda time_of_arrival, t0: time_of_arrival - t0,
200+
'tof': lambda time_of_arrival, nominal_time_at_chopper: (
201+
time_of_arrival - nominal_time_at_chopper
202+
),
222203
'time_of_arrival': time_of_arrival,
223204
}
224205

@@ -287,7 +268,7 @@ def wavelength_detector(
287268
)
288269
convert_pulse_shaping = (
289270
geometry_graph,
290-
tof_from_t0_estimate_graph,
271+
tof_from_nominal_time_at_chopper_graph,
291272
wavelength_detector,
292273
)
293274
providers = (compute_wavelength_in_each_cluster, geometry_graph)

packages/essdiffraction/src/ess/beer/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# Simulations from new model with corrected(?) moderator to detector
3232
# distance.
3333
# For correct reduction you need to use
34-
# beer.io.mcstas_chopper_delay_from_mode_new_simulations
34+
# beer.mcstas.mcstas_chopper_delay_from_mode_new_simulations
3535
# to obtain the correct WavelengthDefinitionChopperDelay for these files.
3636
"silicon-mode10-new-model.h5": "md5:98500830f27700fc719634e1acd49944",
3737
"silicon-mode16-new-model.h5": "md5:393f9287e7d3f97ceedbe64343918413",

0 commit comments

Comments
 (0)