@@ -395,6 +395,58 @@ def test_no_parallel(mock_sqs_etof_calibration_run, tmp_path, mock_etof_mono_ene
395395 # check how well it matches
396396 assert np .allclose (ts , ts_true , rtol = 1e-2 , atol = 1e-2 )
397397
398+ # tests data reading parallelizing over etofs
399+ def test_parallel_tofs (mock_sqs_etof_calibration_run , tmp_path , mock_etof_mono_energies , mock_etof_calibration_constants ):
400+ # same as above, but tests only if a crash happens in `calc_mean`
401+ # somehow parallelization means that `calc_mean` is not shown in the coverage
402+ pulse_timing = 'SQS_RR_UTC/TSYS/TIMESERVER'
403+ monochromator_energy = 'SA3_XTD10_MONO/MDL/PHOTON_ENERGY'
404+ digitizer = 'SQS_DIGITIZER_UTC4/ADC/1:network'
405+ digitizer_control = 'SQS_DIGITIZER_UTC4/ADC/1'
406+ pulse_energy = 'SQS_DIAG1_XGMD/XGM/DOOCS'
407+ mock_sqs_etof_calibration_run = mock_sqs_etof_calibration_run .select ([pulse_timing ,
408+ digitizer , digitizer_control ,
409+ pulse_energy , f"{ pulse_energy } :output" ,
410+ monochromator_energy ], require_all = True ).select_trains (np .s_ [10 :])
411+ channel_name = "1_A"
412+ tof_ids = [0 ]
413+ tof_channel = {}
414+ tof_channel [0 ] = AdqRawChannel (mock_sqs_etof_calibration_run ,
415+ channel_name ,
416+ digitizer = digitizer ,
417+ first_pulse_offset = 1000 )
418+ scan = Scan (mock_sqs_etof_calibration_run [monochromator_energy , "actualEnergy" ], resolution = 2 )
419+ energy_axis = np .linspace (965 , 1070 , 160 )
420+ xgm = XGM (mock_sqs_etof_calibration_run , pulse_energy )
421+ cal = CookieboxCalibration (
422+ auger_start_roi = 1 ,
423+ start_roi = 75 ,
424+ stop_roi = 320 ,
425+ )
426+ cal .setup (run = mock_sqs_etof_calibration_run , energy_axis = energy_axis , tof_settings = tof_channel ,
427+ xgm = xgm ,
428+ scan = scan ,
429+ parallel = False ,
430+ parallel_over_tofs = 2 ,
431+ )
432+
433+ correct_energies = np .unique (mock_etof_mono_energies )
434+ correct_constants = np .array (mock_etof_calibration_constants )
435+ for tof_id in tof_ids :
436+ assert np .allclose (cal .tof_fit_result [tof_id ].energy , correct_energies , rtol = 1e-2 , atol = 1e-2 )
437+
438+ energy = correct_energies
439+
440+ # get calibration curve
441+ c , e0 , t0 = cal .model_params [tof_id ]
442+ ts = t0 + np .sqrt (c / (energy - e0 ))
443+
444+ c_true , e0_true , t0_true = correct_constants
445+ ts_true = t0_true + np .sqrt (c_true / (energy - e0_true ))
446+
447+ # check how well it matches
448+ assert np .allclose (ts , ts_true , rtol = 1e-2 , atol = 1e-2 )
449+
398450def test_deconvolve (mock_sqs_etof_calibration_run , tmp_path ):
399451 # use mock data and do the same as before, but with deconvolution
400452 # it should improve resolution, but lead to the same calibration constants
0 commit comments