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)
Exemplo n.º 2
0
    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_gets_None_for_empty_mask_files(self):
     # Arrange
     command_iface.Clean()
     command_iface.SANS2D()
     # Act
     result = command_iface.GetTransmissionMask()
     # Assert
     self.assertEqual(None, result, 'The transmission mask should be None')
 def test_throws_for_user_file_with_invalid_extension(self):
     # Arrange
     file_name = "/path1/path2/user_file.abc"
     command_iface.Clean()
     command_iface.SANS2D()
     # Act + Assert
     args = [file_name]
     self.assertRaises(RuntimeError, command_iface.MaskFile, *args)
 def test_setting_shift_with_invalid_input(self):
     # Arrange
     trans_spectrum_shift = '-55_thg'
     command_iface.Clean()
     command_iface.SANS2D()
     # Act
     command_iface.SetTransmissionMonitorSpectrumShift(trans_mon_shift = trans_spectrum_shift)
     # Assert
     self.assertEqual(None, command_iface.GetTransmissionMonitorSpectrumShift(), 'The transmission monitor shift should be None.')
 def test_setting_radius_to_valid_value(self):
     # Arrange
     trans_radius = 23
     command_iface.Clean()
     command_iface.SANS2D()
     # Act
     command_iface.SetTransmissionRadiusInMM(trans_radius = trans_radius)
     # Assert
     self.assertEqual(trans_radius, command_iface.GetTransmissionRadiusInMM(), 'The transmission radius should be set to 23.')
 def test_setting_transmission_monitor_to_valid_input(self):
     # Arrange
     trans_spectrum = 4
     command_iface.Clean()
     command_iface.SANS2D()
     # Act
     command_iface.SetTransmissionMonitorSpectrum(trans_mon = trans_spectrum)
     # Assert
     self.assertEqual(trans_spectrum, command_iface.GetTransmissionMonitorSpectrum(), 'The transmission spectrum should be set to 4.')
 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_setting_radius_with_invalid_input(self):
     # Arrange
     trans_radius = '23_yh'
     command_iface.Clean()
     command_iface.SANS2D()
     # Act
     command_iface.SetTransmissionRadiusInMM(trans_radius = trans_radius)
     # Assert
     self.assertEqual(None, command_iface.GetTransmissionRadiusInMM(), 'The transmission radius should be 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_shift_to_valid_value(self):
     # Arrange
     trans_spectrum_shift = -55.0
     command_iface.Clean()
     command_iface.SANS2D()
     # Act
     command_iface.SetTransmissionMonitorSpectrumShift(trans_mon_shift = trans_spectrum_shift)
     # Assert
     self.assertEqual(trans_spectrum_shift, command_iface.GetTransmissionMonitorSpectrumShift(), 'The transmission monitor shift should be set to -55.')
 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_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_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_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_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_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_that_correct_setting_can_be_passed_in(self):
     # Arrange
     run_number = "test12345"
     is_time = True
     is_mon = True
     is_mean = False
     mon_numbers= None
     command_iface.Clean()
     command_iface.LOQ()
     # Act
     command_iface.set_background_correction(run_number, is_time,
                                             is_mon, is_mean, mon_numbers)
     # Assert
     self._do_test_correct_setting(run_number, is_time, is_mon, is_mean, mon_numbers)
    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_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_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_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_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)
    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 test_that_for_non_existing_false_is_returned(self):
     command_iface.Clean()
     selected_idf = "LARMOR_Definition_NONEXIST.xml"
     # Act + Assert
     self.assertFalse(command_iface.LARMOR(selected_idf),
                      "A non existant idf path should return false")