Skip to content

Commit 03807cd

Browse files
committed
Remove CalibratedBeamline
1 parent b3707a9 commit 03807cd

File tree

5 files changed

+37
-62
lines changed

5 files changed

+37
-62
lines changed

src/ess/reduce/nexus/types.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,6 @@ class EmptyDetector(sciline.Scope[RunType, sc.DataArray], sc.DataArray):
203203
"""Detector without neutron data."""
204204

205205

206-
class CalibratedBeamline(sciline.Scope[RunType, sc.DataArray], sc.DataArray):
207-
"""Calibrated beamline with detector and other components."""
208-
209-
210206
class EmptyMonitor(sciline.Scope[RunType, MonitorType, sc.DataArray], sc.DataArray):
211207
"""Monitor without neutron data."""
212208

src/ess/reduce/nexus/workflow.py

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
COMPONENT_CONSTRAINTS,
2121
AllNeXusComponents,
2222
Beamline,
23-
CalibratedBeamline,
2423
Component,
2524
DetectorBankSizes,
2625
DetectorPositionOffset,
@@ -364,9 +363,7 @@ def get_calibrated_detector(
364363
"""
365364
Extract the data array corresponding to a detector's signal field.
366365
367-
The returned data array includes coords and masks pertaining directly to the
368-
signal values array, but not additional information about the detector. The
369-
data array is reshaped to the logical detector shape, which by folding the data
366+
The data array is reshaped to the logical detector shape, by folding the data
370367
array along the detector_number dimension.
371368
372369
Parameters
@@ -400,43 +397,8 @@ def get_calibrated_detector(
400397
)
401398

402399

403-
def assemble_beamline(
404-
detector: EmptyDetector[RunType],
405-
source_position: Position[snx.NXsource, RunType],
406-
sample_position: Position[snx.NXsample, RunType],
407-
gravity: GravityVector,
408-
) -> CalibratedBeamline[RunType]:
409-
"""
410-
Add beamline information (gravity vector, source- and sample-position) to detector.
411-
412-
This is performed separately and after :py:func:`get_calibrated_detector` to avoid
413-
as false dependency of, e.g., the reshaped detector numbers on the sample position.
414-
The latter can change during a run, e.g., for a rotating sample. The detector
415-
numbers might be used, e.g., to mask certain detector pixels, and should not depend
416-
on the sample position.
417-
418-
Parameters
419-
----------
420-
detector:
421-
NeXus detector group.
422-
source_position:
423-
Position of the neutron source.
424-
sample_position:
425-
Position of the sample.
426-
gravity:
427-
Gravity vector.
428-
"""
429-
return CalibratedBeamline[RunType](
430-
detector.assign_coords(
431-
source_position=source_position,
432-
sample_position=sample_position,
433-
gravity=gravity,
434-
)
435-
)
436-
437-
438400
def assemble_detector_data(
439-
detector: CalibratedBeamline[RunType],
401+
detector: EmptyDetector[RunType],
440402
event_data: NeXusData[snx.NXdetector, RunType],
441403
) -> RawDetector[RunType]:
442404
"""
@@ -655,7 +617,6 @@ def load_measurement_metadata_from_nexus(
655617
no_detector_position_offset,
656618
load_nexus_sample,
657619
get_calibrated_detector,
658-
assemble_beamline,
659620
assemble_detector_data,
660621
)
661622

src/ess/reduce/time_of_flight/eto_to_tof.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import numpy as np
1313
import scipp as sc
1414
import scippneutron as scn
15+
import scippnexus as snx
1516
from scippneutron._utils import elem_unit
1617

1718
try:
@@ -20,9 +21,11 @@
2021
from .interpolator_scipy import Interpolator as InterpolatorImpl
2122

2223
from ..nexus.types import (
23-
CalibratedBeamline,
24+
EmptyDetector,
2425
EmptyMonitor,
26+
GravityVector,
2527
MonitorType,
28+
Position,
2629
RawDetector,
2730
RawMonitor,
2831
RunType,
@@ -271,23 +274,35 @@ def _time_of_flight_data_events(
271274

272275

273276
def detector_ltotal_from_straight_line_approximation(
274-
detector_beamline: CalibratedBeamline[RunType],
277+
detector: EmptyDetector[RunType],
278+
source_position: Position[snx.NXsource, RunType],
279+
sample_position: Position[snx.NXsample, RunType],
280+
gravity: GravityVector,
275281
) -> DetectorLtotal[RunType]:
276-
"""
277-
Compute Ltotal for the detector pixels.
282+
"""Compute Ltotal for the detector pixels.
283+
278284
This is a naive straight-line approximation to Ltotal based on basic component
279285
positions.
280286
281287
Parameters
282288
----------
283-
detector_beamline:
284-
Beamline data for the detector that contains the positions necessary to compute
285-
the straight-line approximation to Ltotal (source, sample, and detector
286-
positions).
289+
detector:
290+
Data array with detector positions.
291+
source_position:
292+
Position of the neutron source.
293+
sample_position:
294+
Position of the sample.
295+
gravity:
296+
Gravity vector.
287297
"""
288-
graph = scn.conversion.graph.beamline.beamline(scatter=True)
298+
graph = {
299+
**scn.conversion.graph.beamline.beamline(scatter=True),
300+
'source_position': lambda: source_position,
301+
'sample_position': lambda: sample_position,
302+
'gravity': lambda: gravity,
303+
}
289304
return DetectorLtotal[RunType](
290-
detector_beamline.transform_coords(
305+
detector.transform_coords(
291306
"Ltotal", graph=graph, keep_intermediate=False
292307
).coords["Ltotal"]
293308
)

tests/nexus/workflow_test.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,6 @@ def test_load_detector_workflow(loki_tutorial_sample_run_60250: Path) -> None:
581581
wf[NeXusName[snx.NXdetector]] = 'larmor_detector'
582582
da = wf.compute(RawDetector[SampleRun])
583583
assert 'position' in da.coords
584-
assert 'sample_position' in da.coords
585-
assert 'source_position' in da.coords
586584
assert da.bins is not None
587585
assert da.dims == ('detector_number',)
588586

@@ -598,8 +596,6 @@ def test_generic_nexus_workflow(
598596
wf[PreopenNeXusFile] = preopen
599597
da = wf.compute(RawDetector[SampleRun])
600598
assert 'position' in da.coords
601-
assert 'sample_position' in da.coords
602-
assert 'source_position' in da.coords
603599
assert da.bins is not None
604600
assert da.dims == ('detector_number',)
605601
da = wf.compute(RawMonitor[SampleRun, FrameMonitor1])

tests/time_of_flight/workflow_test.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
from ess.reduce import time_of_flight
1111
from ess.reduce.nexus.types import (
1212
AnyRun,
13-
CalibratedBeamline,
1413
DiskChoppers,
14+
EmptyDetector,
1515
NeXusData,
16+
Position,
1617
RawDetector,
1718
SampleRun,
1819
)
@@ -77,8 +78,11 @@ def test_GenericTofWorkflow_with_tof_lut_from_tof_simulation(
7778
calibrated_beamline: sc.DataArray, nexus_data: sc.DataArray
7879
):
7980
wf = GenericTofWorkflow(run_types=[SampleRun], monitor_types=[])
80-
wf[CalibratedBeamline[SampleRun]] = calibrated_beamline
81+
wf[EmptyDetector[SampleRun]] = calibrated_beamline
8182
wf[NeXusData[snx.NXdetector, SampleRun]] = nexus_data
83+
# Unused because calibrated_beamline contains Ltotal but needed by wf structure
84+
wf[Position[snx.NXsample, SampleRun]] = sc.vector([1e10, 1e10, 1e10], unit='m')
85+
wf[Position[snx.NXsource, SampleRun]] = sc.vector([1e10, 1e10, 1e10], unit='m')
8286

8387
# Should be able to compute DetectorData without chopper and simulation params
8488
# This contains event_time_offset (time-of-arrival).
@@ -122,11 +126,14 @@ def test_GenericTofWorkflow_with_tof_lut_from_file(
122126
lut.save_hdf5(filename=tmp_path / "lut.h5")
123127

124128
wf = GenericTofWorkflow(run_types=[SampleRun], monitor_types=[])
125-
wf[CalibratedBeamline[SampleRun]] = calibrated_beamline
129+
wf[EmptyDetector[SampleRun]] = calibrated_beamline
126130
wf[NeXusData[snx.NXdetector, SampleRun]] = nexus_data
127131
wf[time_of_flight.TimeOfFlightLookupTableFilename] = (
128132
tmp_path / "lut.h5"
129133
).as_posix()
134+
# Unused because calibrated_beamline contains Ltotal but needed by wf structure
135+
wf[Position[snx.NXsample, SampleRun]] = sc.vector([1e10, 1e10, 1e10], unit='m')
136+
wf[Position[snx.NXsource, SampleRun]] = sc.vector([1e10, 1e10, 1e10], unit='m')
130137

131138
loaded_lut = wf.compute(time_of_flight.TimeOfFlightLookupTable)
132139
assert_identical(lut, loaded_lut)

0 commit comments

Comments
 (0)