Skip to content

Commit

Permalink
Merge pull request #63 from scipp/add-ltotal
Browse files Browse the repository at this point in the history
Add distance coord to result data
  • Loading branch information
nvaytet authored Nov 26, 2024
2 parents f93c00d + 8b4e829 commit 412241d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/tof/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def run(self):
container[c.name]['data'] = self.source.data.copy(deep=False)
t = birth_time + (c.distance / speed).to(unit=birth_time.unit, copy=False)
container[c.name]['data'].coords['toa'] = t
container[c.name]['data'].coords['distance'] = c.distance
# TODO: remove 'tof' coordinate once deprecation period is over
container[c.name]['data'].coords['tof'] = t
if isinstance(c, Detector):
Expand Down
32 changes: 32 additions & 0 deletions tests/model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,35 @@ def test_model_repr_does_not_raise():
source=source, choppers=[chopper1, chopper2], detectors=[detector]
)
assert repr(model) is not None


def test_component_distance():
# Make a chopper open from 10-20 ms. Assume zero phase.
topen = 10.0 * ms
tclose = 20.0 * ms
chopper = make_chopper(
topen=[topen],
tclose=[tclose],
f=10.0 * Hz,
phase=0.0 * deg,
distance=10 * meter,
name='chopper',
)
monitor = tof.Detector(distance=17 * meter, name='monitor')
detector = tof.Detector(distance=20 * meter, name='detector')

# Make a pulse with 3 neutrons with one neutron going through the chopper opening
# and the other two neutrons on either side of the opening.
source = make_source(
arrival_times=sc.concat(
[0.9 * topen, 0.5 * (topen + tclose), 1.1 * tclose], dim='event'
),
distance=chopper.distance,
)

model = tof.Model(source=source, choppers=[chopper], detectors=[monitor, detector])
res = model.run()

assert sc.identical(res['monitor'].data.coords['distance'], monitor.distance)
assert sc.identical(res['detector'].data.coords['distance'], detector.distance)
assert sc.identical(res['chopper'].data.coords['distance'], chopper.distance)

0 comments on commit 412241d

Please sign in to comment.