Skip to content
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

Add distance coord to result data #63

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
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
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)