def _provide_reducer(self, is_larmor, is_new=True): ''' Provide a reducer with either Larmor or non-Larmor. If we have Larmor, then we want to be able to set the run number as well ''' command_iface.Clean() if is_larmor and is_new: command_iface.LARMOR() CreateSampleWorkspace(OutputWorkspace=self.workspace_name) AddSampleLog(Workspace=self.workspace_name, LogName='run_number', LogText='3000', LogType='Number') sample = self.MockSample(self.workspace_name) ReductionSingleton()._sample_run = sample return ReductionSingleton() elif is_larmor and not is_new: command_iface.LARMOR() CreateSampleWorkspace(OutputWorkspace=self.workspace_name) AddSampleLog(Workspace=self.workspace_name, LogName='run_number', LogText='1000', LogType='Number') sample = self.MockSample(self.workspace_name) ReductionSingleton()._sample_run = sample return ReductionSingleton() else: command_iface.LOQ() return ReductionSingleton()
def test_that_default_idf_is_being_selected(self): command_iface.Clean() # Act command_iface.LARMOR() # Assert instrument = ReductionSingleton().get_instrument() idf_file_path = instrument.get_idf_file_path() file_name = os.path.basename(idf_file_path) expected_name = "LARMOR_Definition.xml" self.assertEqual(file_name, expected_name)
def test_that_will_not_parse_DET_OVERLAP_with_three_subsequent_commands(self): # Arrange line = 'DET/OVERLAP 0.13 0.15 0.17' command_iface.Clean() command_iface.LOQ() user_file = reduction_steps.UserFile() # Act user_file.read_line(line=line, reducer=ReductionSingleton()) merge_Range = ReductionSingleton().instrument.getDetector('FRONT').mergeRange # Assert self.assertEqual(merge_Range.q_min, None, 'The q_min should have been read in') self.assertEqual(merge_Range.q_max, None, 'The q_max should have been read in') self.assertEqual(merge_Range.q_merge_range, False, 'q_merge_range should be true')
def test_can_parse_DET_OVERLAP_line(self): # Arrange line = 'DET/OVERLAP 0.13 0.15' command_iface.Clean() command_iface.LOQ() user_file = reduction_steps.UserFile() # Act user_file.read_line(line = line, reducer = ReductionSingleton()) merge_Range = ReductionSingleton().instrument.getDetector('FRONT').mergeRange # Assert self.assertEqual(merge_Range.q_min, 0.13, 'The q_min should have been read in') self.assertEqual(merge_Range.q_max, 0.15, 'The q_max should have been read in') self.assertEqual(merge_Range.q_merge_range, True, 'q_merge_range should be true')
def test_parse_line_for_back_trans_does_not_set_for_single_times(self): # Arrange start = 1000 line = 'BACK/TRANS'+ str(start) command_iface.Clean() command_iface.LOQ() user_file = reduction_steps.UserFile() # Act user_file.read_line(line = line, reducer = ReductionSingleton()) start_TOF_ROI, end_TOF_ROI = ReductionSingleton().inst.get_TOFs_for_ROI() # Assert self.assertEqual(None, start_TOF_ROI, 'The start time should not have been set') self.assertEqual(None, end_TOF_ROI, 'The end time should not have been set')
def test_parse_line_for_back_trans(self): # Arrange start = 1000 end = 2000 line = 'BACK/TRANS'+ str(start) +' ' + str(end) command_iface.Clean() command_iface.LOQ() user_file = reduction_steps.UserFile() # Act user_file.read_line(line = line, reducer = ReductionSingleton()) start_TOF_ROI, end_TOF_ROI = ReductionSingleton().inst.get_TOFs_for_ROI() # Assert self.assertEqual(start, start_TOF_ROI, 'The start time should be 1000 for ROI.') self.assertEqual(end, end_TOF_ROI, 'The end time should be 2000 for ROI.')
def _do_test_correct_setting(self, run_number, is_time, is_mon, is_mean, mon_numbers): # Assert that settings were set setting = ReductionSingleton().get_dark_run_setting(is_time, is_mon) self.assertEqual(setting.run_number, run_number) self.assertEqual(setting.time, is_time) self.assertEqual(setting.mean, is_mean) self.assertEqual(setting.mon, is_mon) self.assertEqual(setting.mon_numbers, mon_numbers) # Assert that other settings are None. Hence set up all combinations and remove the one which # has been set up earlier combinations = [[True, True], [True, False], [False, True], [False, False]] selected_combination = [is_time, is_mon] combinations.remove(selected_combination) for combination in combinations: self.assertTrue(ReductionSingleton().get_dark_run_setting(combination[0], combination[1]) is None)
def test_setting_roi_file_for_invalid_input(self): # Arrange trans_roi_files = ['file1g', 'file2.xml'] command_iface.Clean() command_iface.SANS2D() # Act command_iface.SetTransmissionROI(trans_roi_files = trans_roi_files) # Assert self.assertEqual(0, len(ReductionSingleton().transmission_calculator.roi_files), 'The transmission roi list should be empty.')
def test_setting_mask_file_for_invalid_input(self): # Arrange trans_mask_files = " file1g, file2.xml " command_iface.Clean() command_iface.SANS2D() # Act command_iface.SetTransmissionMask(trans_mask_files = trans_mask_files) # Assert self.assertEqual(0, len(ReductionSingleton().transmission_calculator.mask_files), 'The transmission mask list should be empty.')
def test_that_gets_transmission_monitor(self): # Arrange trans_spectrum = 4 command_iface.Clean() command_iface.SANS2D() ReductionSingleton().transmission_calculator.trans_mon = trans_spectrum # Act result = command_iface.GetTransmissionMonitorSpectrum() # Assert self.assertEqual(trans_spectrum, result, 'The transmission spectrum should be set to 4.')
def test_that_gets_transmission_radius(self): # Arrange trans_radius = 23/1000 command_iface.Clean() command_iface.SANS2D() ReductionSingleton().transmission_calculator.radius = trans_radius # Act result = command_iface.GetTransmissionRadiusInMM() # Assert self.assertEqual(trans_radius*1000, result, 'The transmission radius should be set to 23 mm.')
def test_that_gets_transmission_monitor_shift(self): # Arrange trans_spectrum_shift = -55 command_iface.Clean() command_iface.SANS2D() ReductionSingleton().get_instrument().monitor_4_offset = trans_spectrum_shift # Act result = command_iface.GetTransmissionMonitorSpectrumShift() # Assert self.assertEqual(trans_spectrum_shift, result, 'The transmission monitor shift should be set to -55.')
def test_that_gets_non_empty_mask_files(self): # Arrange trans_mask_files = ['mask_file1.xml', 'mask_file2.xml'] command_iface.Clean() command_iface.SANS2D() ReductionSingleton().transmission_calculator.mask_files = trans_mask_files # Act result = command_iface.GetTransmissionMask() # Assert self.assertEqual(trans_mask_files, result, 'The transmission mask should have two entries')
def test_setting_mask_file_for_valid_input(self): # Arrange trans_mask_files = ['file1.xml', 'file2.xml'] command_iface.Clean() command_iface.SANS2D() # Act command_iface.SetTransmissionMask(trans_mask_files = trans_mask_files) # Assert result = ReductionSingleton().transmission_calculator.mask_files self.assertEqual(2, len(result), 'The transmission mask list should have two entries') self.assertEqual("file1.xml", result[0], 'The first file should be file1.xml') self.assertEqual("file2.xml", result[1], 'The second file should be file2.xml')
def test_full_setup_for_circular_apertures(self): # Arrange command_iface.Clean() command_iface.SANS2D() a1 = 2 # in mm a2 = 3 # in mm delta_r = 4 # in mm collimation_length = 10 # in m norm = reduction_steps.CalculateNormISIS() ReductionSingleton().to_Q = reduction_steps.ConvertToQISIS(norm) # Act command_iface.set_q_resolution_a1(a1 = a1) command_iface.set_q_resolution_a2(a2 = a2) command_iface.set_q_resolution_delta_r(delta_r = delta_r) command_iface.set_q_resolution_collimation_length(collimation_length = collimation_length) command_iface.set_q_resolution_use(use = True) ReductionSingleton().to_Q._set_up_q_resolution_parameters() # Assert a1_stored = ReductionSingleton().to_Q.get_q_resolution_a1() # in m a1_expected = a1/1000. self.assertEqual(a1_stored, a1_expected) a2_stored = ReductionSingleton().to_Q.get_q_resolution_a2() # in m a2_expected = a2/1000. self.assertEqual(a2_stored, a2_expected) collimation_length_stored = ReductionSingleton().to_Q.get_q_resolution_collimation_length() # in m collimation_length_expected = collimation_length self.assertEqual(collimation_length_stored, collimation_length_expected) delta_r_stored = ReductionSingleton().to_Q.get_q_resolution_delta_r() # in m delta_r_expected = delta_r/1000. self.assertEqual(delta_r_stored, delta_r_expected)
def test_full_setup_for_rectangular_apertures(self): # Arrange command_iface.Clean() command_iface.SANS2D() a1 = 2 # in mm a2 = 3 # in mm delta_r = 4 # in mm collimation_length = 10 # in m h1 = 9 # in mm w1 = 8 # in mm h2 = 7 # in mm w2 = 5 # in mm norm = reduction_steps.CalculateNormISIS() ReductionSingleton().to_Q = reduction_steps.ConvertToQISIS(norm) # Act command_iface.set_q_resolution_a1(a1=a1) command_iface.set_q_resolution_a2(a2=a2) command_iface.set_q_resolution_delta_r(delta_r=delta_r) command_iface.set_q_resolution_h1(h1=h1) command_iface.set_q_resolution_w1(w1=w1) command_iface.set_q_resolution_h2(h2=h2) command_iface.set_q_resolution_w2(w2=w2) command_iface.set_q_resolution_collimation_length( collimation_length=collimation_length) command_iface.set_q_resolution_use(use=True) ReductionSingleton().to_Q._set_up_q_resolution_parameters() # Assert a1_stored = ReductionSingleton().to_Q.get_q_resolution_a1() # in m a1_expected = 2 * math.sqrt( (h1 / 1000. * h1 / 1000. + w1 / 1000. * w1 / 1000.) / 6) self.assertEqual(a1_stored, a1_expected) a2_stored = ReductionSingleton().to_Q.get_q_resolution_a2() # in m a2_expected = 2 * math.sqrt( (h2 / 1000. * h2 / 1000. + w2 / 1000. * w2 / 1000.) / 6) self.assertEqual(a2_stored, a2_expected) collimation_length_stored = ReductionSingleton( ).to_Q.get_q_resolution_collimation_length() # in m collimation_length_expected = collimation_length self.assertEqual(collimation_length_stored, collimation_length_expected) delta_r_stored = ReductionSingleton().to_Q.get_q_resolution_delta_r( ) # in m delta_r_expected = delta_r / 1000. self.assertEqual(delta_r_stored, delta_r_expected)
def test_full_setup_for_rectangular_apertures_which_are_only_partially_specified( self): # Arrange command_iface.Clean() command_iface.SANS2D() a1 = 2 # in mm a2 = 3 # in mm delta_r = 4 # in mm collimation_length = 10 # in m h1 = 9 # in mm w1 = 8 # in mm h2 = 7 # in mm # We take out w2, hence we don't have a full rectangular spec norm = reduction_steps.CalculateNormISIS() ReductionSingleton().to_Q = reduction_steps.ConvertToQISIS(norm) # Act command_iface.set_q_resolution_a1(a1=a1) command_iface.set_q_resolution_a2(a2=a2) command_iface.set_q_resolution_delta_r(delta_r=delta_r) command_iface.set_q_resolution_h1(h1=h1) command_iface.set_q_resolution_w1(w1=w1) command_iface.set_q_resolution_h2(h2=h2) command_iface.set_q_resolution_collimation_length( collimation_length=collimation_length) command_iface.set_q_resolution_use(use=True) ReductionSingleton().to_Q._set_up_q_resolution_parameters() # Assert a1_stored = ReductionSingleton().to_Q.get_q_resolution_a1() # in m a1_expected = a1 / 1000. self.assertEqual(a1_stored, a1_expected) a2_stored = ReductionSingleton().to_Q.get_q_resolution_a2() # in m a2_expected = a2 / 1000. self.assertEqual(a2_stored, a2_expected) collimation_length_stored = ReductionSingleton( ).to_Q.get_q_resolution_collimation_length() # in m collimation_length_expected = collimation_length self.assertEqual(collimation_length_stored, collimation_length_expected) delta_r_stored = ReductionSingleton().to_Q.get_q_resolution_delta_r( ) # in m delta_r_expected = delta_r / 1000. self.assertEqual(delta_r_stored, delta_r_expected)