From 8b4e8299b9a6534ff12f35ef94a5121a597c2e4f Mon Sep 17 00:00:00 2001 From: Neil Vaytet Date: Tue, 26 Nov 2024 16:57:47 +0100 Subject: [PATCH] add distance test --- tests/model_test.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/model_test.py b/tests/model_test.py index 043f1fc..c62042c 100644 --- a/tests/model_test.py +++ b/tests/model_test.py @@ -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)