@@ -148,7 +148,7 @@ def test_standard_unwrap_histogram_mode(dist, dim) -> None:
148
148
def test_pulse_skipping_unwrap () -> None :
149
149
distance = sc .scalar (100.0 , unit = "m" )
150
150
choppers = fakes .psc_choppers ()
151
- choppers ["pulse_skipping" ] = fakes .pulse_skipping
151
+ choppers ["pulse_skipping" ] = fakes .pulse_skipping_chopper ()
152
152
153
153
beamline = fakes .FakeBeamline (
154
154
choppers = choppers ,
@@ -189,10 +189,56 @@ def test_pulse_skipping_unwrap() -> None:
189
189
assert sc .isclose (mon .data .nansum (), tofs .data .nansum (), rtol = sc .scalar (1.0e-3 ))
190
190
191
191
192
+ def test_pulse_skipping_unwrap_180_phase_shift () -> None :
193
+ distance = sc .scalar (100.0 , unit = "m" )
194
+ choppers = fakes .psc_choppers ()
195
+ choppers ["pulse_skipping" ] = fakes .pulse_skipping_chopper ()
196
+ choppers ["pulse_skipping" ].phase .value += 180.0
197
+
198
+ beamline = fakes .FakeBeamline (
199
+ choppers = choppers ,
200
+ monitors = {"detector" : distance },
201
+ run_length = sc .scalar (1.0 , unit = "s" ),
202
+ events_per_pulse = 100_000 ,
203
+ seed = 4 ,
204
+ )
205
+ mon , ref = beamline .get_monitor ("detector" )
206
+
207
+ sim = time_of_flight .simulate_beamline (
208
+ choppers = choppers , neutrons = 300_000 , pulses = 2 , seed = 1234
209
+ )
210
+
211
+ pl = sl .Pipeline (
212
+ time_of_flight .providers (), params = time_of_flight .default_parameters ()
213
+ )
214
+
215
+ pl [time_of_flight .RawData ] = mon
216
+ pl [time_of_flight .SimulationResults ] = sim
217
+ pl [time_of_flight .LtotalRange ] = distance , distance
218
+ pl [time_of_flight .PulseStride ] = 2
219
+ pl [time_of_flight .PulseStrideOffset ] = 1 # Start the stride at the second pulse
220
+
221
+ tofs = pl .compute (time_of_flight .TofData )
222
+
223
+ # Convert to wavelength
224
+ graph = {** beamline_graph (scatter = False ), ** elastic_graph ("tof" )}
225
+ wavs = tofs .transform_coords ("wavelength" , graph = graph ).bins .concat ().value
226
+
227
+ diff = abs (
228
+ (wavs .coords ["wavelength" ] - ref .coords ["wavelength" ])
229
+ / ref .coords ["wavelength" ]
230
+ )
231
+ # All errors should be small
232
+ assert np .nanpercentile (diff .values , 100 ) < 0.01
233
+ # Make sure that we have not lost too many events (we lose some because they may be
234
+ # given a NaN tof from the lookup).
235
+ assert sc .isclose (mon .data .nansum (), tofs .data .nansum (), rtol = sc .scalar (1.0e-3 ))
236
+
237
+
192
238
def test_pulse_skipping_unwrap_when_all_neutrons_arrive_after_second_pulse () -> None :
193
239
distance = sc .scalar (150.0 , unit = "m" )
194
240
choppers = fakes .psc_choppers ()
195
- choppers ["pulse_skipping" ] = fakes .pulse_skipping
241
+ choppers ["pulse_skipping" ] = fakes .pulse_skipping_chopper ()
196
242
197
243
beamline = fakes .FakeBeamline (
198
244
choppers = choppers ,
@@ -237,7 +283,7 @@ def test_pulse_skipping_unwrap_when_all_neutrons_arrive_after_second_pulse() ->
237
283
def test_pulse_skipping_unwrap_when_first_half_of_first_pulse_is_missing () -> None :
238
284
distance = sc .scalar (100.0 , unit = "m" )
239
285
choppers = fakes .psc_choppers ()
240
- choppers ["pulse_skipping" ] = fakes .pulse_skipping
286
+ choppers ["pulse_skipping" ] = fakes .pulse_skipping_chopper ()
241
287
242
288
beamline = fakes .FakeBeamline (
243
289
choppers = choppers ,
@@ -307,7 +353,7 @@ def test_pulse_skipping_unwrap_when_first_half_of_first_pulse_is_missing() -> No
307
353
def test_pulse_skipping_unwrap_histogram_mode () -> None :
308
354
distance = sc .scalar (100.0 , unit = "m" )
309
355
choppers = fakes .psc_choppers ()
310
- choppers ["pulse_skipping" ] = fakes .pulse_skipping
356
+ choppers ["pulse_skipping" ] = fakes .pulse_skipping_chopper ()
311
357
312
358
beamline = fakes .FakeBeamline (
313
359
choppers = choppers ,
0 commit comments