Exemplo n.º 1
0
    def _get_data_state(self):
        # Get the data commands
        data_commands = self._get_data_commands()
        data_elements = self._get_elements_with_key(
            DataCommandId.SAMPLE_SCATTER, data_commands)
        data_element = data_elements[-1]
        file_name = data_element.file_name
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            file_name)

        # Build the state data
        data_builder = get_data_builder(self._facility, file_information)
        self._set_data_element(data_builder.set_sample_scatter,
                               data_builder.set_sample_scatter_period,
                               DataCommandId.SAMPLE_SCATTER, data_commands)
        self._set_data_element(data_builder.set_sample_transmission,
                               data_builder.set_sample_transmission_period,
                               DataCommandId.SAMPLE_TRANSMISSION,
                               data_commands)
        self._set_data_element(data_builder.set_sample_direct,
                               data_builder.set_sample_direct_period,
                               DataCommandId.SAMPLE_DIRECT, data_commands)
        self._set_data_element(data_builder.set_can_scatter,
                               data_builder.set_can_scatter_period,
                               DataCommandId.CAN_SCATTER, data_commands)
        self._set_data_element(data_builder.set_can_transmission,
                               data_builder.set_can_transmission_period,
                               DataCommandId.CAN_TRANSMISSION, data_commands)
        self._set_data_element(data_builder.set_can_direct,
                               data_builder.set_can_direct_period,
                               DataCommandId.CAN_DIRECT, data_commands)

        return data_builder.build()
Exemplo n.º 2
0
    def test_that_slice_event_state_can_be_built(self):
        # Arrange
        facility = SANSFacility.ISIS
        file_information = SANSFileInformationMock(run_number=74044)
        data_builder = get_data_builder(facility, file_information)
        data_builder.set_sample_scatter("LOQ74044")
        data_info = data_builder.build()

        # Act
        builder = get_scale_builder(data_info, file_information)
        self.assertTrue(builder)

        builder.set_scale(1.0)
        builder.set_shape(SampleShape.FLAT_PLATE)
        builder.set_thickness(3.6)
        builder.set_width(3.7)
        builder.set_height(5.8)

        # Assert
        state = builder.build()
        self.assertEqual(state.shape, SampleShape.FLAT_PLATE)
        self.assertEqual(state.scale, 1.0)
        self.assertEqual(state.thickness, 3.6)
        self.assertEqual(state.width, 3.7)
        self.assertEqual(state.height, 5.8)
Exemplo n.º 3
0
    def _get_sample_state(q_min=1., q_max=2., q_step=0.1, q_step_type=RangeStepType.LIN,
                          q_xy_max=None, q_xy_step=None, q_xy_step_type=None,
                          use_gravity=False, dim=ReductionDimensionality.ONE_DIM):
        facility = SANSFacility.ISIS
        file_information = SANSFileInformationMock(instrument=SANSInstrument.LOQ, run_number=74044)
        data_builder = get_data_builder(facility, file_information)
        data_builder.set_sample_scatter("LOQ74044")
        data_state = data_builder.build()

        convert_to_q_builder = get_convert_to_q_builder(data_state)
        convert_to_q_builder.set_reduction_dimensionality(dim)
        convert_to_q_builder.set_use_gravity(use_gravity)
        convert_to_q_builder.set_radius_cutoff(0.002)
        convert_to_q_builder.set_wavelength_cutoff(2.)
        convert_to_q_builder.set_q_min(q_min)
        convert_to_q_builder.set_q_max(q_max)
        prefix = 1. if q_step_type is RangeStepType.LIN else -1.
        q_step *= prefix
        rebin_string = str(q_min) + "," + str(q_step) + "," + str(q_max)
        convert_to_q_builder.set_q_1d_rebin_string(rebin_string)
        if q_xy_max is not None:
            convert_to_q_builder.set_q_xy_max(q_xy_max)
        if q_xy_step is not None:
            convert_to_q_builder.set_q_xy_step(q_xy_step)
        if q_xy_step_type is not None:
            convert_to_q_builder.set_q_xy_step_type(q_xy_step_type)

        convert_to_q_state = convert_to_q_builder.build()

        test_director = TestDirector()
        test_director.set_states(convert_to_q_state=convert_to_q_state, data_state=data_state)

        return test_director.construct()
Exemplo n.º 4
0
    def test_that_mask_can_be_built(self):
        # Arrange
        facility = SANSFacility.ISIS
        file_information = SANSFileInformationMock(run_number=74044)
        data_builder = get_data_builder(facility, file_information)
        data_builder.set_sample_scatter("LOQ74044")
        data_builder.set_sample_scatter_period(3)
        data_info = data_builder.build()

        # Act
        builder = get_mask_builder(data_info)
        self.assertTrue(builder)

        start_time = [0.1, 1.3]
        end_time = [0.2, 1.6]
        builder.set_bin_mask_general_start(start_time)
        builder.set_bin_mask_general_stop(end_time)
        builder.set_LAB_single_vertical_strip_mask([1, 2, 3])

        # Assert
        state = builder.build()
        self.assertEqual(len(state.bin_mask_general_start), 2)
        self.assertEqual(state.bin_mask_general_start[0], start_time[0])
        self.assertEqual(state.bin_mask_general_start[1], start_time[1])

        self.assertEqual(len(state.bin_mask_general_stop), 2)
        self.assertEqual(state.bin_mask_general_stop[0], end_time[0])
        self.assertEqual(state.bin_mask_general_stop[1], end_time[1])

        strip_mask = state.detectors[
            DetectorType.LAB.value].single_vertical_strip_mask
        self.assertEqual(len(strip_mask), 3)
        self.assertEqual(strip_mask[2], 3)
Exemplo n.º 5
0
 def get_state_data(self, file_information):
     if file_information:
         data_builder = get_data_builder(SANSFacility.ISIS,
                                         file_information)
         return data_builder.build()
     else:
         return StateData()
Exemplo n.º 6
0
    def test_that_state_for_larmor_can_be_built(self):
        # Arrange
        facility = SANSFacility.ISIS
        file_information = SANSFileInformationMock(
            instrument=SANSInstrument.LARMOR, run_number=2260)
        data_builder = get_data_builder(facility, file_information)
        data_builder.set_sample_scatter("LARMOR00002260")
        data_info = data_builder.build()

        # Act
        builder = get_move_builder(data_info)
        self.assertTrue(builder)
        value = 324.2
        builder.set_LAB_x_translation_correction(value)

        # Assert
        state = builder.build()
        self.assertEqual(
            state.detectors[DetectorType.LAB.value].x_translation_correction,
            value)
        self.assertEqual(state.detectors[DetectorType.LAB.value].detector_name,
                         "DetectorBench")
        self.assertTrue(DetectorType.HAB.value not in state.detectors)
        self.assertEqual(state.monitor_names[str(5)], "monitor5")
        self.assertEqual(len(state.monitor_names), 5)
Exemplo n.º 7
0
    def test_that_slice_event_state_can_be_built(self):
        # Arrange
        facility = SANSFacility.ISIS
        file_information = SANSFileInformationMock(
            instrument=SANSInstrument.LOQ, run_number=74044)
        data_builder = get_data_builder(facility, file_information)
        data_builder.set_sample_scatter("LOQ74044")
        data_info = data_builder.build()

        # Act
        builder = get_wavelength_builder(data_info)
        self.assertTrue(builder)

        builder.set_wavelength_low([10.0])
        builder.set_wavelength_high([20.0])
        builder.set_wavelength_step(3.0)
        builder.set_wavelength_step_type(RangeStepType.LIN)
        builder.set_rebin_type(RebinType.REBIN)

        # Assert
        state = builder.build()

        self.assertEqual(state.wavelength_low, [10.0])
        self.assertEqual(state.wavelength_high, [20.0])
        self.assertEqual(state.wavelength_step_type, RangeStepType.LIN)
        self.assertEqual(state.rebin_type, RebinType.REBIN)
Exemplo n.º 8
0
    def test_that_slice_event_state_can_be_built(self):
        # Arrange
        facility = SANSFacility.ISIS
        file_information = SANSFileInformationMock(
            instrument=SANSInstrument.LOQ, run_number=74044)
        data_builder = get_data_builder(facility, file_information)
        data_builder.set_sample_scatter("LOQ74044")
        data_info = data_builder.build()

        # Act
        builder = get_slice_event_builder(data_info)
        self.assertTrue(builder)

        start_time = [0.1, 1.3]
        end_time = [0.2, 1.6]
        builder.set_start_time(start_time)
        builder.set_end_time(end_time)

        # Assert
        state = builder.build()
        self.assertEqual(len(state.start_time), 2)
        self.assertEqual(state.start_time[0], start_time[0])
        self.assertEqual(state.start_time[1], start_time[1])

        self.assertEqual(len(state.end_time), 2)
        self.assertEqual(state.end_time[0], end_time[0])
        self.assertEqual(state.end_time[1], end_time[1])
Exemplo n.º 9
0
    def test_that_produces_correct_workspace_for_SANS2D(self):
        # Arrange
        # Build the data information
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            "SANS2D00034484")
        data_builder = get_data_builder(SANSFacility.ISIS, file_information)
        data_builder.set_sample_scatter("SANS2D00034484")
        data_state = data_builder.build()

        # Get the rest of the state from the user file
        user_file = "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt"
        user_file_director = UserFileReaderAdapter(
            file_information=file_information, user_file_name=user_file)
        state = user_file_director.get_all_states(
            file_information=file_information)
        state.compatibility.use_compatibility_mode = True
        state.adjustment.calibration = "TUBE_SANS2D_BOTH_31681_25Sept15.nxs"
        state.data = data_state

        # Act
        output_workspaces = run_integral('', True, IntegralEnum.Horizontal,
                                         DetectorType.LAB, state)
        self.assertEqual(len(output_workspaces), 1)
        # Evaluate it up to a defined point
        reference_file_name = "SANS2D_ws_centred_diagnostic_reference.nxs"
        self._compare_workspace(output_workspaces[0], reference_file_name)
Exemplo n.º 10
0
    def test_that_correct_scale_strategy_is_selected_for_loq_2(self):
        facility = SANSFacility.ISIS
        file_information = SANSFileInformationMock(
            instrument=SANSInstrument.LOQ, run_number=74044)
        data_builder = get_data_builder(facility, file_information)
        data_builder.set_sample_scatter("LOQ74044")
        data_state = data_builder.build()

        scale_builder = get_scale_builder(data_state, file_information)
        scale_builder.set_scale(2.4)
        scale_state = scale_builder.build()

        test_director = TestDirector()
        test_director.set_states(scale_state=scale_state,
                                 data_state=data_state)
        state_loq = test_director.construct()

        workspace = self._get_workspace()

        output_workspace = _multiply_by_abs_scale(
            instrument=SANSInstrument.LOQ,
            workspace=workspace,
            state_scale=state_loq.scale)

        # Assert
        expected_value = 0.3 * 2.4 / math.pi * 100.
        data_y = output_workspace.dataY(0)
        self.assertEqual(data_y[0], expected_value)
Exemplo n.º 11
0
    def test_that_produces_correct_workspace_multiperiod_LARMOR(self):
        # Arrange
        # Build the data information
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            "LARMOR00013065")
        data_builder = get_data_builder(SANSFacility.ISIS, file_information)
        data_builder.set_sample_scatter("LARMOR00013065")

        data_state = data_builder.build()

        # Get the rest of the state from the user file
        user_file = "USER_LARMOR_151B_LarmorTeam_80tubes_BenchRot1p4_M4_r3699.txt"
        user_file_director = UserFileReaderAdapter(
            file_information=file_information, user_file_name=user_file)
        state = user_file_director.get_all_states(
            file_information=file_information)
        state.adjustment.calibration = "80tubeCalibration_1-05-2015_r3157-3160.nxs"
        state.data = data_state

        # Act
        output_workspaces = run_integral('', True, IntegralEnum.Horizontal,
                                         DetectorType.LAB, state)

        # Evaluate it up to a defined point
        reference_file_name = "LARMOR_ws_diagnostic_reference.nxs"
        self._compare_workspace(output_workspaces[0], reference_file_name)
    def test_that_wavelength_and_pixel_adjustment_state_can_be_built(self):
        # Arrange
        facility = SANSFacility.ISIS
        file_information = SANSFileInformationMock(
            instrument=SANSInstrument.LOQ, run_number=74044)
        data_builder = get_data_builder(facility, file_information)
        data_builder.set_sample_scatter("LOQ74044")
        data_info = data_builder.build()

        # Act
        builder = get_wavelength_and_pixel_adjustment_builder(data_info)
        self.assertTrue(builder)

        builder.set_HAB_pixel_adjustment_file("test")
        builder.set_HAB_wavelength_adjustment_file("test2")
        builder.set_wavelength_low([1.5])
        builder.set_wavelength_high([2.7])
        builder.set_wavelength_step(0.5)
        builder.set_wavelength_step_type(RangeStepType.LIN)

        state = builder.build()

        # Assert
        self.assertTrue(state.adjustment_files[
            DetectorType.HAB.value].pixel_adjustment_file == "test")
        self.assertTrue(state.adjustment_files[
            DetectorType.HAB.value].wavelength_adjustment_file == "test2")
        self.assertEqual(state.wavelength_low, [1.5])
        self.assertEqual(state.wavelength_high, [2.7])
        self.assertEqual(state.wavelength_step, 0.5)
        self.assertEqual(state.wavelength_step_type, RangeStepType.LIN)
Exemplo n.º 13
0
    def test_that_divide_uses_settings_from_state_if_they_are_set(self):
        # Arrange
        facility = SANSFacility.ISIS
        file_information = SANSFileInformationMock(
            instrument=SANSInstrument.LOQ, run_number=74044)
        data_builder = get_data_builder(facility, file_information)
        data_builder.set_sample_scatter("SANS2D00022024")
        data_state = data_builder.build()

        scale_builder = get_scale_builder(data_state, file_information)
        width = 10.
        height = 5.
        thickness = 2.
        scale_builder.set_shape(SampleShape.DISC)
        scale_builder.set_thickness(thickness)
        scale_builder.set_width(width)
        scale_builder.set_height(height)
        scale_state = scale_builder.build()

        test_director = TestDirector()
        test_director.set_states(scale_state=scale_state,
                                 data_state=data_state)
        state = test_director.construct()

        workspace = self._get_workspace()

        output_workspace = _divide_by_sample_volume(workspace=workspace,
                                                    scale_info=state.scale)

        expected_volume = thickness * math.pi * math.pow(width, 2) / 4.0
        expected_value = 0.3 / expected_volume
        data_y = output_workspace.dataY(0)
        self.assertEqual(data_y[0], expected_value)
Exemplo n.º 14
0
    def test_that_state_for_loq_can_be_built(self):
        facility = SANSFacility.ISIS
        file_information = SANSFileInformationMock(
            instrument=SANSInstrument.LOQ, run_number=74044)
        data_builder = get_data_builder(facility, file_information)
        data_builder.set_sample_scatter("LOQ74044")
        data_builder.set_sample_scatter_period(3)
        data_info = data_builder.build()

        # Act
        builder = get_move_builder(data_info)
        self.assertTrue(builder)
        value = 324.2
        builder.set_center_position(value)
        builder.set_HAB_x_translation_correction(value)
        builder.set_LAB_sample_centre_pos1(value)

        # Assert
        state = builder.build()
        self.assertEqual(state.center_position, value)
        self.assertEqual(
            state.detectors[DetectorType.HAB.value].x_translation_correction,
            value)
        self.assertEqual(
            state.detectors[DetectorType.LAB.value].sample_centre_pos1, value)
Exemplo n.º 15
0
    def test_state_can_be_created_from_valid_user_file_with_data_information(self):
        # Arrange
        file_information = SANSFileInformationMock(instrument=SANSInstrument.SANS2D, run_number=22024)
        data_builder = get_data_builder(SANSFacility.ISIS, file_information)
        data_builder.set_sample_scatter("SANS2D00022024")
        data_builder.set_sample_scatter_period(3)
        data_state = data_builder.build()

        user_file_path = create_user_file(sample_user_file)

        parser = UserFileReaderAdapter(user_file_name=user_file_path, data_info=data_state)
        state = parser.get_all_states()

        # Assert
        self._assert_data(state)
        self._assert_move(state)
        self._assert_mask(state)
        self._assert_reduction(state)
        self._assert_wavelength(state)
        self._assert_scale(state)
        self._assert_adjustment(state)
        self._assert_convert_to_q(state)

        # clean up
        if os.path.exists(user_file_path):
            os.remove(user_file_path)
Exemplo n.º 16
0
    def test_that_state_for_sans2d_can_be_built(self):
        # Arrange
        facility = SANSFacility.ISIS
        file_information = SANSFileInformationMock(
            instrument=SANSInstrument.SANS2D, run_number=22048)
        data_builder = get_data_builder(facility, file_information)
        data_builder.set_sample_scatter("SANS2D00022048")
        data_info = data_builder.build()

        # Act
        builder = get_move_builder(data_info)
        self.assertTrue(builder)
        value = 324.2
        builder.set_HAB_x_translation_correction(value)

        # Assert
        state = builder.build()
        self.assertEqual(
            state.detectors[DetectorType.HAB.value].x_translation_correction,
            value)
        self.assertEqual(
            state.detectors[DetectorType.HAB.value].detector_name_short,
            "front")
        self.assertEqual(state.detectors[DetectorType.LAB.value].detector_name,
                         "rear-detector")
        self.assertEqual(state.monitor_names[str(4)], "monitor4")
        self.assertEqual(len(state.monitor_names), 4)
Exemplo n.º 17
0
    def test_that_reduction_state_can_be_built(self):
        # Arrange
        facility = SANSFacility.ISIS
        file_information = SANSFileInformationMock(
            instrument=SANSInstrument.LOQ, run_number=74044)
        data_builder = get_data_builder(facility, file_information)
        data_builder.set_sample_scatter("LOQ74044")
        data_info = data_builder.build()

        # Act
        builder = get_adjustment_builder(data_info)
        self.assertTrue(builder)

        builder.set_calculate_transmission(MockStateCalculateTransmission())
        builder.set_normalize_to_monitor(MockStateNormalizeToMonitor())
        builder.set_wavelength_and_pixel_adjustment(
            MockStateWavelengthAndPixelAdjustment())
        builder.set_wide_angle_correction(False)
        state = builder.build()

        # # Assert
        self.assertTrue(not state.wide_angle_correction)
        try:
            state.validate()
            is_valid = True
        except ValueError:
            is_valid = False
        self.assertTrue(is_valid)
Exemplo n.º 18
0
    def test_that_reduction_state_can_be_built(self):
        # Arrange
        facility = SANSFacility.ISIS
        file_information = SANSFileInformationMock(
            instrument=SANSInstrument.LOQ, run_number=74044)
        data_builder = get_data_builder(facility, file_information)
        data_builder.set_sample_scatter("LOQ74044")
        data_info = data_builder.build()

        # Act
        builder = get_save_builder(data_info)
        self.assertTrue(builder)

        user_specified_output_name = "test_file_name"
        zero_free_correction = True
        file_format = [SaveType.NEXUS, SaveType.CAN_SAS]

        builder.set_user_specified_output_name(user_specified_output_name)
        builder.set_zero_free_correction(zero_free_correction)
        builder.set_file_format(file_format)
        state = builder.build()

        # Assert
        self.assertEqual(state.user_specified_output_name,
                         user_specified_output_name)
        self.assertEqual(state.zero_free_correction, zero_free_correction)
        self.assertEqual(state.file_format, file_format)
Exemplo n.º 19
0
    def test_that_reduction_state_can_be_built(self):
        # Arrange
        facility = SANSFacility.ISIS
        file_information = SANSFileInformationMock(
            instrument=SANSInstrument.LOQ, run_number=74044)
        data_builder = get_data_builder(facility, file_information)
        data_builder.set_sample_scatter("LOQ74044")
        data_info = data_builder.build()

        # Act
        builder = get_convert_to_q_builder(data_info)
        self.assertTrue(builder)

        builder.set_q_min(12.0)
        builder.set_q_max(17.0)
        builder.set_q_1d_rebin_string("12.0,-1.2,17.0")
        builder.set_reduction_dimensionality(ReductionDimensionality.ONE_DIM)

        state = builder.build()

        # Assert
        self.assertEqual(state.q_min, 12.0)
        self.assertEqual(state.q_max, 17.0)
        self.assertEqual(state.q_1d_rebin_string, "12.0,-1.2,17.0")
        self.assertEqual(state.reduction_dimensionality,
                         ReductionDimensionality.ONE_DIM)
Exemplo n.º 20
0
    def test_that_angle_masking_is_applied(self):
        # Arrange
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            "SANS2D00028827")
        data_builder = get_data_builder(SANSFacility.ISIS, file_information)
        data_builder.set_sample_scatter("SANS2D00028827")
        data_info = data_builder.build()

        mask_builder = get_mask_builder(data_info)

        # Expected_spectra
        phi_mirror = False
        phi_min = 0.
        phi_max = 90.
        # This should mask everything except for the upper right quadrant
        # | 120              |-------------------|
        # |                 |---------------------|
        # | 60               |-------------------|
        # |                 |----------------------|
        # |
        # |
        # |-------------------|------------------|
        # 512                256                 0

        expected_spectra = []
        # The strange double pattern arises from the offset of the SANS2D tube geometry (see InstrumentView)
        for y in range(60, 120):
            if y % 2 == 0:
                expected_spectra.extend(
                    ((y * 512) + 9 + x for x in range(0, 255)))
            else:
                expected_spectra.extend(
                    ((y * 512) + 9 + x for x in range(0, 257)))
        expected_spectra.extend((x for x in range(92169, 122889)))  # HAB

        mask_builder.set_use_mask_phi_mirror(phi_mirror)
        mask_builder.set_phi_min(phi_min)
        mask_builder.set_phi_max(phi_max)

        mask_info = mask_builder.build()

        test_director = TestDirector()
        test_director.set_states(data_state=data_info, mask_state=mask_info)
        state = test_director.construct()

        returned_data = SANSLoad(SANSState=Serializer.to_json(state),
                                 SampleScatterWorkspace="mask_sans_ws",
                                 SampleScatterMonitorWorkspace="dummy")

        workspace = returned_data[0]
        DeleteWorkspace(returned_data[1])

        # Act
        workspace = mask_workspace(state=state,
                                   component_as_string="LAB",
                                   workspace=workspace)

        # Assert
        self._do_assert_non_masked(workspace, expected_spectra)
Exemplo n.º 21
0
    def test_that_single_reduction_evaluates_LAB_for_2D_reduction(self):
        # Arrange
        # Build the data information
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            "SANS2D00034484")
        data_builder = get_data_builder(SANSFacility.ISIS, file_information)
        data_builder.set_sample_scatter("SANS2D00034484")
        data_builder.set_sample_transmission("SANS2D00034505")
        data_builder.set_sample_direct("SANS2D00034461")
        data_builder.set_can_scatter("SANS2D00034481")
        data_builder.set_can_transmission("SANS2D00034502")
        data_builder.set_can_direct("SANS2D00034461")

        data_info = data_builder.build()

        # Get the rest of the state from the user file
        user_file = "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt"
        user_file_director = UserFileReaderAdapter(
            file_information=file_information, user_file_name=user_file)
        state = user_file_director.get_all_states(
            file_information=file_information)

        # Set the reduction mode to LAB
        state.reduction.reduction_mode = ReductionMode.LAB
        state.adjustment.calibration = "TUBE_SANS2D_BOTH_31681_25Sept15.nxs"
        state.reduction.reduction_dimensionality = ReductionDimensionality.TWO_DIM
        state.convert_to_q.reduction_dimensionality = ReductionDimensionality.TWO_DIM
        state.data = data_info

        state.compatibility.use_compatibility_mode = True

        # Load the sample workspaces
        sample, sample_monitor, transmission_workspace, direct_workspace, can, can_monitor, \
        can_transmission, can_direct = self._load_workspace(state)  # noqa

        # Act
        output_settings = {"OutputWorkspaceLAB": EMPTY_NAME}
        single_reduction_alg = self._run_single_reduction(
            state,
            sample_scatter=sample,
            sample_transmission=transmission_workspace,
            sample_direct=direct_workspace,
            sample_monitor=sample_monitor,
            can_scatter=can,
            can_monitor=can_monitor,
            can_transmission=can_transmission,
            can_direct=can_direct,
            output_settings=output_settings)
        output_workspace = single_reduction_alg.getProperty(
            "OutputWorkspaceLAB").value

        # Compare the output of the reduction with the reference
        reference_file_name = "SANS2D_ws_D20_reference_LAB_2D.nxs"
        self._compare_to_reference(
            output_workspace,
            reference_file_name,
            mismatch_name=MantidSystemTest.mismatchWorkspaceName(
                reference_file_name))
Exemplo n.º 22
0
    def test_batch_reduction_on_period_time_sliced_wavelength_range_data(self):
        # Arrange
        # Build the data information
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            "SANS2D0005512")

        data_builder = get_data_builder(SANSFacility.ISIS, file_information)
        data_builder.set_sample_scatter("SANS2D0005512")
        data_builder.set_sample_scatter_period(1)

        data_info = data_builder.build()

        # Get the rest of the state from the user file
        user_filename = "MASKSANS2Doptions.091A"
        user_file_director = StateBuilder.new_instance(
            file_information=file_information,
            data_information=data_info,
            user_filename=user_filename)

        state = user_file_director.get_all_states()
        # Set the reduction mode to LAB
        state.reduction.reduction_mode = ReductionMode.LAB

        state.slice.start_time = [1.0, 3.0]
        state.slice.end_time = [3.0, 5.0]

        start = [1.0, 1.0]
        end = [3.0, 2.0]
        state.wavelength.wavelength_low = start
        state.wavelength.wavelength_high = end

        state.adjustment.normalize_to_monitor.wavelength_low = start
        state.adjustment.normalize_to_monitor.wavelength_high = end

        state.adjustment.calculate_transmission.wavelength_low = start
        state.adjustment.calculate_transmission.wavelength_high = end

        state.adjustment.wavelength_and_pixel_adjustment.wavelength_low = start
        state.adjustment.wavelength_and_pixel_adjustment.wavelength_high = end

        # Act
        states = [state]
        self._run_batch_reduction(states, use_optimizations=False)

        # Assert
        # We only assert that the expected workspaces exist on the ADS
        expected_workspaces = [
            "5512_p1rear_1D_1.0_2.0Phi-45.0_45.0_t1.00_T3.00",
            "5512_p1rear_1D_1.0_2.0Phi-45.0_45.0_t3.00_T5.00",
            "5512_p1rear_1D_1.0_3.0Phi-45.0_45.0_t1.00_T3.00",
            "5512_p1rear_1D_1.0_3.0Phi-45.0_45.0_t3.00_T5.00"
        ]
        for element in expected_workspaces:
            self.assertTrue(AnalysisDataService.doesExist(element))

        # Clean up
        for element in expected_workspaces:
            AnalysisDataService.remove(element)
Exemplo n.º 23
0
 def _get_mock_data_info():
     # TODO I really really dislike having to do this in a test, but
     # TODO de-coupling StateData is required to avoid it
     file_information = SANSFileInformationMock(instrument=SANSInstrument.SANS2D, run_number=22024)
     data_builder = get_data_builder(SANSFacility.ISIS, file_information)
     data_builder.set_sample_scatter("SANS2D00022024")
     data_builder.set_sample_scatter_period(3)
     return data_builder.build()
    def _build_data_info():
        ws_name = "SANS2D00028827"

        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(ws_name)
        data_builder = get_data_builder(SANSFacility.ISIS, file_information)
        data_builder.set_sample_scatter(ws_name)
        data_info = data_builder.build()
        return data_info
Exemplo n.º 25
0
    def test_batch_reduction_with_wavelength_ranges(self):
        # Arrange
        # Build the data information
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            "SANS2D00034484")

        data_builder = get_data_builder(SANSFacility.ISIS, file_information)
        data_builder.set_sample_scatter("SANS2D00034484")
        data_builder.set_sample_transmission("SANS2D00034505")
        data_builder.set_sample_direct("SANS2D00034461")
        data_builder.set_can_scatter("SANS2D00034481")
        data_builder.set_can_transmission("SANS2D00034502")
        data_builder.set_can_direct("SANS2D00034461")
        data_info = data_builder.build()

        # Get the rest of the state from the user file
        user_filename = "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt"
        user_file_director = UserFileReaderAdapter(
            file_information=file_information, user_file_name=user_filename)
        state = user_file_director.get_all_states(
            file_information=file_information)

        # Set the reduction mode to LAB
        state.adjustment.calibration = "TUBE_SANS2D_BOTH_31681_25Sept15.nxs"
        state.reduction.reduction_mode = ReductionMode.LAB
        state.compatibility.use_compatibility_mode = True  # COMPATIBILITY BEGIN -- Remove when appropriate
        state.data = data_info

        selected_range = [(1.0, 2.0), (2.0, 3.0)]
        state.wavelength.wavelength_interval.selected_ranges = selected_range
        state.adjustment.normalize_to_monitor.wavelength_interval.selected_ranges = selected_range
        state.adjustment.calculate_transmission.wavelength_interval.selected_ranges = selected_range
        state.adjustment.wavelength_and_pixel_adjustment.wavelength_interval.selected_ranges = selected_range

        # Act
        states = [state]
        self._run_batch_reduction(states, use_optimizations=False)

        expected_workspaces = [
            "34484_rear_1D_1.0_2.0", "34484_rear_1D_2.0_3.0"
        ]
        reference_file_names = [
            "SANS2D_wavelength_range_1.0_2.0.nxs",
            "SANS2D_wavelength_range_2.0_3.0.nxs"
        ]

        for element, reference_file in zip(expected_workspaces,
                                           reference_file_names):
            self.assertTrue(AnalysisDataService.doesExist(element))
            # Evaluate it up to a defined point
            self._compare_workspace(element, reference_file)

        # Clean up
        for element in expected_workspaces:
            AnalysisDataService.remove(element)
Exemplo n.º 26
0
    def test_batch_reduction_on_time_sliced_file(self):
        # Arrange
        # Build the data information
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            "SANS2D00034484")

        data_builder = get_data_builder(SANSFacility.ISIS, file_information)
        data_builder.set_sample_scatter("SANS2D00034484")
        data_builder.set_sample_transmission("SANS2D00034505")
        data_builder.set_sample_direct("SANS2D00034461")
        data_builder.set_can_scatter("SANS2D00034481")
        data_builder.set_can_transmission("SANS2D00034502")
        data_builder.set_can_direct("SANS2D00034461")

        data_builder.set_calibration("TUBE_SANS2D_BOTH_31681_25Sept15.nxs")

        data_info = data_builder.build()

        # Get the rest of the state from the user file
        user_filename = "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt"
        user_file_director = StateBuilder.new_instance(
            file_information=file_information,
            data_information=data_info,
            user_filename=user_filename)

        state = user_file_director.get_all_states()
        # Set the reduction mode to LAB
        state.reduction.reduction_mode = ReductionMode.LAB
        state.compatibility.use_compatibility_mode = True  # COMPATIBILITY BEGIN -- Remove when appropriate
        state.slice.start_time = [1.0, 3.0]
        state.slice.end_time = [3.0, 5.0]

        # Act
        states = [state]
        self._run_batch_reduction(states, use_optimizations=False)

        expected_workspaces = [
            "34484_rear_1D_1.75_16.5_t1.00_T3.00",
            "34484_rear_1D_1.75_16.5_t3.00_T5.00"
        ]
        reference_file_names = [
            "SANS2D_event_slice_referance_t1.00_T3.00.nxs",
            "SANS2D_event_slice_referance_t3.00_T5.00.nxs"
        ]

        for element, reference_file in zip(expected_workspaces,
                                           reference_file_names):
            self.assertTrue(AnalysisDataService.doesExist(element))
            # Evaluate it up to a defined point
            self._compare_workspace(element, reference_file)

        # Clean up
        for element in expected_workspaces:
            AnalysisDataService.remove(element)
Exemplo n.º 27
0
    def _get_simple_state(sample_scatter, sample_trans=None, sample_direct=None,
                          can_scatter=None, can_trans=None, can_direct=None, calibration=None,
                          sample_scatter_period=None, sample_trans_period=None, sample_direct_period=None,
                          can_scatter_period=None, can_trans_period=None, can_direct_period=None):
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(sample_scatter)

        data_builder = get_data_builder(SANSFacility.ISIS, file_information)
        data_builder.set_sample_scatter(sample_scatter)

        # Set the file names
        if sample_trans is not None:
            data_builder.set_sample_transmission(sample_trans)

        if sample_direct is not None:
            data_builder.set_sample_direct(sample_direct)

        if can_scatter is not None:
            data_builder.set_can_scatter(can_scatter)

        if can_trans is not None:
            data_builder.set_can_transmission(can_trans)

        if can_direct is not None:
            data_builder.set_can_direct(can_direct)

        # Set the periods
        if sample_scatter_period is not None:
            data_builder.set_sample_scatter_period(sample_scatter_period)

        if sample_trans_period is not None:
            data_builder.set_sample_transmission_period(sample_trans_period)

        if sample_direct_period is not None:
            data_builder.set_sample_direct_period(sample_direct_period)

        if can_scatter_period is not None:
            data_builder.set_can_scatter_period(can_scatter_period)

        if can_trans_period is not None:
            data_builder.set_can_transmission_period(can_trans_period)

        if can_direct_period is not None:
            data_builder.set_can_direct_period(can_direct_period)

        data_info = data_builder.build()

        # Get the sample state
        test_director = TestDirector()
        test_director.set_states(data_state=data_info)

        state = test_director.construct()
        state.adjustment.calibration = calibration

        return state
Exemplo n.º 28
0
    def test_that_beam_centre_core_produces_correct_workspaces(self):
        # Arrange
        # Build the data information
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            "SANS2D00034484")

        data_builder = get_data_builder(SANSFacility.ISIS, file_information)
        data_builder.set_sample_scatter("SANS2D00034484")
        data_builder.set_sample_transmission("SANS2D00034505")
        data_builder.set_sample_direct("SANS2D00034461")
        data_builder.set_calibration("TUBE_SANS2D_BOTH_31681_25Sept15.nxs")
        data_state = data_builder.build()

        # Get the rest of the state from the user file
        user_file = "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt"
        user_file_director = StateBuilder.new_instance(
            data_information=data_state,
            file_information=file_information,
            user_filename=user_file)
        state = user_file_director.get_all_states()

        state.compatibility.use_compatibility_mode = True

        # Load the sample workspaces
        workspace, workspace_monitor, transmission_workspace, direct_workspace = self._load_workspace(
            state)

        # Act
        reduction_core_alg = self._run_beam_centre_core(
            state, workspace, workspace_monitor, transmission_workspace,
            direct_workspace)
        output_workspace_left = reduction_core_alg.getProperty(
            "OutputWorkspaceLeft").value
        output_workspace_right = reduction_core_alg.getProperty(
            "OutputWorkspaceRight").value
        output_workspace_top = reduction_core_alg.getProperty(
            "OutputWorkspaceTop").value
        output_workspace_bottom = reduction_core_alg.getProperty(
            "OutputWorkspaceBottom").value

        # Evaluate it up to a defined point
        reference_file_name_left = "SANS2D_ws_D20_reference_left.nxs"
        reference_file_name_right = "SANS2D_ws_D20_reference_right.nxs"
        reference_file_name_top = "SANS2D_ws_D20_reference_top.nxs"
        reference_file_name_bottom = "SANS2D_ws_D20_reference_bottom.nxs"
        self._compare_workspace(output_workspace_left,
                                reference_file_name_left)
        self._compare_workspace(output_workspace_right,
                                reference_file_name_right)
        self._compare_workspace(output_workspace_top, reference_file_name_top)
        self._compare_workspace(output_workspace_bottom,
                                reference_file_name_bottom)
    def test_that_reduction_state_can_be_built(self):
        # Arrange
        facility = SANSFacility.ISIS
        file_information = SANSFileInformationMock(
            instrument=SANSInstrument.LOQ, run_number=74044)
        data_builder = get_data_builder(facility, file_information)
        data_builder.set_sample_scatter("LOQ74044")
        data_info = data_builder.build()

        # Act
        builder = get_normalize_to_monitor_builder(data_info)
        self.assertTrue(builder)

        builder.set_prompt_peak_correction_min(12.0)
        builder.set_prompt_peak_correction_max(17.0)
        builder.set_rebin_type(RebinType.REBIN)
        builder.set_wavelength_low([1.5])
        builder.set_wavelength_high([2.7])
        builder.set_wavelength_step(0.5)
        builder.set_wavelength_step_type(RangeStepType.LIN)
        builder.set_incident_monitor(1)
        builder.set_background_TOF_general_start(1.4)
        builder.set_background_TOF_general_stop(34.4)
        builder.set_background_TOF_monitor_start({"1": 123, "2": 123})
        builder.set_background_TOF_monitor_stop({"1": 234, "2": 2323})

        state = builder.build()

        # Assert
        self.assertEqual(state.prompt_peak_correction_min, 12.0)
        self.assertEqual(state.prompt_peak_correction_max, 17.0)
        self.assertEqual(state.rebin_type, RebinType.REBIN)
        self.assertEqual(state.wavelength_low, [1.5])
        self.assertEqual(state.wavelength_high, [2.7])
        self.assertEqual(state.wavelength_step, 0.5)
        self.assertEqual(state.wavelength_step_type, RangeStepType.LIN)
        self.assertEqual(state.background_TOF_general_start, 1.4)
        self.assertEqual(state.background_TOF_general_stop, 34.4)
        self.assertEqual(
            len(
                set(state.background_TOF_monitor_start.items()) & set({
                    "1": 123,
                    "2": 123
                }.items())), 2)
        self.assertEqual(
            len(
                set(state.background_TOF_monitor_stop.items()) & set({
                    "1": 234,
                    "2": 2323
                }.items())), 2)
        self.assertEqual(state.incident_monitor, 1)
Exemplo n.º 30
0
    def get_state_move_obj(monitor_4_dist):
        facility = SANSFacility.ISIS
        file_information = SANSFileInformationMock(
            instrument=SANSInstrument.SANS2D, run_number=22048)
        data_builder = get_data_builder(facility, file_information)
        data_builder.set_sample_scatter("SANS2D22048")
        data_builder.set_sample_scatter_period(3)
        data_info = data_builder.build()

        state_builder = get_move_builder(data_info)

        state = state_builder.build()
        state.monitor_4_offset = monitor_4_dist
        return state