Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 3
0
 def _parse_legacy(file_path, file_information):
     try:
         converter = UserFileReaderAdapter(
             user_file_name=file_path, file_information=file_information)
         return converter.get_all_states(file_information=file_information)
     except (RuntimeError, ValueError) as e:
         raise UserFileLoadException(e)
Esempio n. 4
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)
Esempio n. 5
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))
    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 = 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.reduction.reduction_mode = ReductionMode.LAB
        state.data = data_info

        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)
Esempio n. 7
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)
    def test_move_sets_shift_correctly_m4(self):
        mocked_values = {DetectorId.INSTRUMENT: [SANSInstrument.SANS2D],
                         TransId.SPEC_4_SHIFT: [-10.0]}
        adapter = mock.create_autospec(UserFileReader)
        adapter.read_user_file.return_value = mocked_values
        parser = UserFileReaderAdapter(file_information=None, user_file_name=None,
                                       txt_user_file_reader=adapter)
        state_move = parser.get_state_move(file_information=None)

        self.assertAlmostEqual(-10.0 / self.MM_TO_M, state_move.monitor_4_offset)
    def test_move_ignores_m5_for_non_zoom(self):
        mocked_values = {DetectorId.INSTRUMENT: [SANSInstrument.SANS2D],
                         TransId.SPEC_5_SHIFT: [-10.0]}
        adapter = mock.create_autospec(UserFileReader)
        adapter.read_user_file.return_value = mocked_values
        parser = UserFileReaderAdapter(file_information=None, user_file_name=None,
                                       txt_user_file_reader=adapter)
        state_move = parser.get_state_move(file_information=None)

        self.assertAlmostEqual(0.0, state_move.monitor_4_offset)
Esempio n. 10
0
    def test_that_create_state_creates_correct_state(self):
        user_file_path = create_user_file(sample_user_file)
        user_file_reader = UserFileReaderAdapter(user_file_name=user_file_path, file_information=None)
        user_file_items = user_file_reader.get_all_states(file_information=None)

        state_from_view = StateGuiModel(user_file_items)

        state = create_state(state_from_view, "SANS2D00022024", '', SANSFacility.ISIS)

        self.assertEqual(state.data.sample_scatter, "SANS2D00022024")
    def test_move_m5_works_on_zoom(self):
        mocked_values = {DetectorId.INSTRUMENT: [SANSInstrument.ZOOM],
                         TransId.SPEC_5_SHIFT: [-5.0]}
        adapter = mock.create_autospec(UserFileReader)
        adapter.read_user_file.return_value = mocked_values
        parser = UserFileReaderAdapter(file_information=None, user_file_name=None,
                                       txt_user_file_reader=adapter)
        state_move = parser.get_state_move(file_information=None)

        self.assertIsInstance(state_move, StateMoveZOOM)
        self.assertAlmostEqual(0.0, state_move.monitor_4_offset)
        self.assertAlmostEqual(-5.0 / self.MM_TO_M, state_move.monitor_5_offset)
Esempio n. 12
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_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.adjustment.calibration = "TUBE_SANS2D_BOTH_31681_25Sept15.nxs"

        state.compatibility.use_compatibility_mode = True
        state.data = data_state

        # 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)
Esempio n. 13
0
    def test_that_reduction_core_evaluates_LAB(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_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.adjustment.calibration = "TUBE_SANS2D_BOTH_31681_25Sept15.nxs"
        state.compatibility.use_compatibility_mode = True
        state.data = data_state

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

        # Act
        reduction_core_alg = self._run_reduction_core(state, workspace,
                                                      workspace_monitor,
                                                      transmission_workspace,
                                                      direct_workspace)
        output_workspace = reduction_core_alg.getProperty(
            "OutputWorkspaces").value
        calculated_transmission = reduction_core_alg.getProperty(
            "CalculatedTransmissionWorkspaces").value
        unfitted_transmission = reduction_core_alg.getProperty(
            "UnfittedTransmissionWorkspaces").value

        # Evaluate it up to a defined point
        reference_file_name = "SANS2D_ws_D20_reference.nxs"
        self._compare_workspace(output_workspace, reference_file_name)

        calculated_transmission_reference_file = "SANS2D_ws_D20_calculated_transmission_reference.nxs"
        unfitted_transmission_reference_file = "SANS2D_ws_D20_unfitted_transmission_reference.nxs"
        self._compare_workspace(calculated_transmission,
                                calculated_transmission_reference_file)
        self._compare_workspace(unfitted_transmission,
                                unfitted_transmission_reference_file)
Esempio n. 14
0
 def test_move_with_hab_centre_uses_hab_centre_value(self):
     user_file_centre = """
     set centre 160.2 -170.5
     set centre/hab 160.5 -170.1
     """
     user_file_path = create_user_file(user_file_centre)
     mocked_sans = self.create_mock_inst_file_information(SANSInstrument.SANS2D)
     parser = UserFileReaderAdapter(user_file_name=user_file_path, file_information=mocked_sans)
     state = parser.get_all_states(file_information=mocked_sans)
     move = state.move
     lab = move.detectors[DetectorType.LAB.value]
     hab = move.detectors[DetectorType.HAB.value]
     self.assertEqual(lab.sample_centre_pos1,  160.2/1000.)
     self.assertEqual(lab.sample_centre_pos2, -170.5/1000.)
     self.assertEqual(hab.sample_centre_pos1,  160.5/1000. )
     self.assertEqual(hab.sample_centre_pos2, -170.1/1000.)
    def test_that_batch_reduction_evaluates_LAB(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()

        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)
        # Get the rest of the state from the user file
        state = user_file_director.get_all_states(
            file_information=file_information)

        state.adjustment.calibration = "TUBE_SANS2D_BOTH_31681_25Sept15.nxs"
        state.data = data_info

        # Set the reduction mode to LAB
        state.reduction.reduction_mode = ReductionMode.LAB
        # Since we are dealing with event based data but we want to compare it with histogram data from the
        # old reduction system we need to enable the compatibility mode
        state.compatibility.use_compatibility_mode = True  # COMPATIBILITY BEGIN -- Remove when appropriate

        # Act
        states = [state]
        self._run_batch_reduction(states, use_optimizations=False)
        workspace_name = "34484_rear_1D_1.75_16.5"
        output_workspace = AnalysisDataService.retrieve(workspace_name)

        # Evaluate it up to a defined point
        reference_file_name = "SANS2D_ws_D20_reference_LAB_1D.nxs"
        self._compare_workspace(output_workspace, reference_file_name)

        if AnalysisDataService.doesExist(workspace_name):
            AnalysisDataService.remove(workspace_name)
Esempio n. 16
0
    def test_state_can_be_created_from_valid_user_file_with_data_information(self):
        user_file_path = create_user_file(sample_user_file)

        mocked_sans = self.create_mock_inst_file_information(SANSInstrument.SANS2D)

        parser = UserFileReaderAdapter(user_file_name=user_file_path, file_information=mocked_sans)
        state = parser.get_all_states(file_information=mocked_sans)

        # Assert
        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)
Esempio n. 17
0
    def test_batch_reduction_on_multiperiod_file(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_info = data_builder.build()

        # Get the rest of the state from the user file
        user_filename = "MASKSANS2Doptions.091A"
        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.reduction.reduction_mode = ReductionMode.LAB
        state.data = data_info

        # 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_p{0}rear_1D_2.0_14.0Phi-45.0_45.0".format(i)
            for i in range(1, 14)
        ]
        for element in expected_workspaces:
            does_exist = AnalysisDataService.doesExist(element)
            self.assertTrue(does_exist,
                            msg="{0} was not found".format(element))

        # Clean up
        for element in expected_workspaces:
            AnalysisDataService.remove(element)
Esempio n. 18
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
        mocked_parent = mock.create_autospec(DiagnosticsPagePresenter)
        async_worker = DiagnosticsAsync(parent_presenter=mocked_parent)
        async_worker.set_unit_test_mode(True)
        async_worker.run_integral('', True, IntegralEnum.Horizontal,
                                  DetectorType.LAB, state)

        mocked_parent.on_processing_success.assert_called_once()
        mocked_parent.on_processing_finished.assert_called_once()
        output_workspaces = mocked_parent.on_processing_success.call_args_list[
            0][1]["output"]

        # Evaluate it up to a defined point
        reference_file_name = "LARMOR_ws_diagnostic_reference.nxs"
        self._compare_workspace(output_workspaces[0], reference_file_name)
        mocked_parent.on_processing_finished.assert_called_once()
Esempio n. 19
0
 def _get_state_gui_model():
     user_file_path = create_user_file(sample_user_file)
     adapter = UserFileReaderAdapter(file_information=None,
                                     user_file_name=user_file_path)
     return StateGuiModel(adapter.get_all_states(file_information=None))
Esempio n. 20
0
    def test_similarity_between_results_in_compatibility_mode_and_non_compatibility_mode(
            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_state = data_builder.build()

        ################################################################################################################
        # Compatibility mode
        ################################################################################################################
        # 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.adjustment.calibration = "TUBE_SANS2D_BOTH_31681_25Sept15.nxs"
        state.compatibility.use_compatibility_mode = True
        state.data = data_state

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

        # Act
        reduction_core_alg = self._run_reduction_core(state, workspace,
                                                      workspace_monitor,
                                                      transmission_workspace,
                                                      direct_workspace)
        compatibility_output_workspace = reduction_core_alg.getProperty(
            "OutputWorkspaces").value

        ################################################################################################################
        # Non-compatibility mode
        ################################################################################################################
        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 = False
        state.data = data_state

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

        # Act
        reduction_core_alg = self._run_reduction_core(state, workspace,
                                                      workspace_monitor,
                                                      transmission_workspace,
                                                      direct_workspace)
        non_compatibility_output_workspace = reduction_core_alg.getProperty(
            "OutputWorkspaces").value

        ################################################################################################################
        # Compare workspaces
        ################################################################################################################
        compare_name = "CompareWorkspaces"
        compare_options = {
            "Workspace1": non_compatibility_output_workspace.getItem(0),
            "Workspace2": compatibility_output_workspace.getItem(0),
            "Tolerance": 1,
            "CheckInstrument": False,
            "CheckSample": False,
            "ToleranceRelErr": True,
            "CheckAllData": True,
            "CheckMasking": True,
            "CheckType": True,
            "CheckAxes": True,
            "CheckSpectraMap": True
        }
        compare_alg = create_unmanaged_algorithm(compare_name,
                                                 **compare_options)
        compare_alg.setChild(False)
        compare_alg.execute()
        result = compare_alg.getProperty("Result").value
        self.assertTrue(result)
Esempio n. 21
0
    def test_that_single_reduction_evaluates_LAB(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)
        state.adjustment.calibration = "TUBE_SANS2D_BOTH_31681_25Sept15.nxs"
        state.reduction.reduction_mode = ReductionMode.LAB
        state.compatibility.use_compatibility_mode = False
        state.data = data_info

        # Add some event slices
        state.slice.start_time = [0.00, 300.00]
        state.slice.end_time = [300.00, 600.00]

        # 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_v2_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,
            event_slice_optimisation=True,
            save_can=True,
            use_optimizations=True)

        # Check output workspaces
        output_workspace = single_reduction_v2_alg.getProperty(
            "OutputWorkspaceLAB").value
        lab_can = single_reduction_v2_alg.getProperty(
            "OutputWorkspaceLABCan").value
        lab_sample = single_reduction_v2_alg.getProperty(
            "OutputWorkspaceLABSample").value
        lab_can_count = single_reduction_v2_alg.getProperty(
            "OutputWorkspaceLABCanCount").value
        lab_can_norm = single_reduction_v2_alg.getProperty(
            "OutputWorkspaceLABCanNorm").value

        self._assert_group_workspace(output_workspace)
        self._assert_group_workspace(lab_can)
        self._assert_group_workspace(lab_sample)
        self._assert_group_workspace(lab_can_count)
        self._assert_group_workspace(lab_can_norm)

        # ---------------------------------------------------
        # Comparison test with version 1
        # This can be removed once version 2 has been adopted
        # ---------------------------------------------------
        # Run the first event slice
        state.slice.start_time = [0.00]
        state.slice.end_time = [300.00]

        single_reduction_alg_first_slice = 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,
            event_slice_optimisation=False,
            save_can=True)

        # Run the second event slice
        state.slice.start_time = [300.00]
        state.slice.end_time = [600.00]

        single_reduction_alg_second_slice = 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,
            event_slice_optimisation=False,
            save_can=True)
        # Now compare output workspaces from the two versions
        # Output LAB workspace
        event_slice_output_workspace = single_reduction_v2_alg.getProperty(
            "OutputWorkspaceLAB").value
        first_slice_output_workspace = single_reduction_alg_first_slice.getProperty(
            "OutputWorkspaceLAB").value
        second_slice_output_workspace = single_reduction_alg_second_slice.getProperty(
            "OutputWorkspaceLAB").value

        self._compare_workspace(event_slice_output_workspace[0],
                                first_slice_output_workspace,
                                tolerance=1e-6)
        self._compare_workspace(event_slice_output_workspace[1],
                                second_slice_output_workspace,
                                tolerance=1e-6)

        # LAB sample
        event_slice_output_sample = single_reduction_v2_alg.getProperty(
            "OutputWorkspaceLABSample").value
        first_slice_output_sample = single_reduction_alg_first_slice.getProperty(
            "OutputWorkspaceLABSample").value
        second_slice_output_sample = single_reduction_alg_second_slice.getProperty(
            "OutputWorkspaceLABSample").value

        self._compare_workspace(event_slice_output_sample[0],
                                first_slice_output_sample,
                                tolerance=1e-6)
        self._compare_workspace(event_slice_output_sample[1],
                                second_slice_output_sample,
                                tolerance=1e-6)

        # LAB can
        event_slice_output_can = single_reduction_v2_alg.getProperty(
            "OutputWorkspaceLABCan").value
        first_slice_output_can = single_reduction_alg_first_slice.getProperty(
            "OutputWorkspaceLABCan").value
        second_slice_output_can = single_reduction_alg_second_slice.getProperty(
            "OutputWorkspaceLABCan").value

        self._compare_workspace(event_slice_output_can[0],
                                first_slice_output_can,
                                tolerance=1e-6)
        self._compare_workspace(event_slice_output_can[1],
                                second_slice_output_can,
                                tolerance=1e-6)
Esempio n. 22
0
    def test_that_single_reduction_evaluates_merged(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)
        state.adjustment.calibration = "TUBE_SANS2D_BOTH_31681_25Sept15.nxs"
        state.reduction.reduction_mode = ReductionMode.MERGED
        state.reduction.merge_fit_mode = FitModeForMerge.BOTH
        state.reduction.merge_scale = 1.0
        state.reduction.merge_shift = 0.0
        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 = {"OutputWorkspaceMerged": 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(
            "OutputWorkspaceMerged").value
        output_scale_factor = single_reduction_alg.getProperty(
            "OutScaleFactor").value
        output_shift_factor = single_reduction_alg.getProperty(
            "OutShiftFactor").value

        tolerance = 1e-6
        expected_shift = 0.00278452
        expected_scale = 0.81439387

        self.assertTrue(abs(expected_shift - output_shift_factor) < tolerance)
        self.assertTrue(abs(expected_scale - output_scale_factor) < tolerance)

        # Compare the output of the reduction with the reference
        reference_file_name = "SANS2D_ws_D20_reference_Merged_1D.nxs"
        self._compare_to_reference(
            output_workspace,
            reference_file_name,
            mismatch_name=MantidSystemTest.mismatchWorkspaceName(
                reference_file_name))
Esempio n. 23
0
    def test_that_single_reduction_evaluates_LAB(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.data = data_info

        # Since we are dealing with event based data but we want to compare it with histogram data from the
        # old reduction system we need to enable the compatibility mode
        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
        calculated_transmission = single_reduction_alg.getProperty(
            "OutputWorkspaceCalculatedTransmission").value
        unfitted_transmission = single_reduction_alg.getProperty(
            "OutputWorkspaceUnfittedTransmission").value
        calculated_transmission_can = single_reduction_alg.getProperty(
            "OutputWorkspaceCalculatedTransmissionCan").value
        unfitted_transmission_can = single_reduction_alg.getProperty(
            "OutputWorkspaceUnfittedTransmissionCan").value

        # Compare the output of the reduction with the reference
        reference_file_name = "SANS2D_ws_D20_reference_LAB_1D.nxs"
        self._compare_to_reference(
            output_workspace,
            reference_file_name,
            mismatch_name=MantidSystemTest.mismatchWorkspaceName(
                reference_file_name))

        calculated_transmission_reference_file = "SANS2D_ws_D20_calculated_transmission_reference_LAB.nxs"
        unfitted_transmission_reference_file = "SANS2D_ws_D20_unfitted_transmission_reference_LAB.nxs"
        calculated_transmission_reference_file_can = "SANS2D_ws_D20_calculated_transmission_reference_LAB_can.nxs"
        unfitted_transmission_reference_file_can = "SANS2D_ws_D20_unfitted_transmission_reference_LAB_can.nxs"
        self._compare_to_reference(
            calculated_transmission,
            calculated_transmission_reference_file,
            check_spectra_map=False,
            mismatch_name=MantidSystemTest.mismatchWorkspaceName(
                calculated_transmission_reference_file))
        self._compare_to_reference(
            unfitted_transmission,
            unfitted_transmission_reference_file,
            mismatch_name=MantidSystemTest.mismatchWorkspaceName(
                unfitted_transmission_reference_file))
        self._compare_to_reference(
            calculated_transmission_can,
            calculated_transmission_reference_file_can,
            check_spectra_map=False,
            mismatch_name=MantidSystemTest.mismatchWorkspaceName(
                calculated_transmission_reference_file_can))
        self._compare_to_reference(
            unfitted_transmission_can,
            unfitted_transmission_reference_file_can,
            mismatch_name=MantidSystemTest.mismatchWorkspaceName(
                unfitted_transmission_reference_file_can))
Esempio n. 24
0
 def new_instance(file_information, data_information, user_filename):
     run_data = StateRunDataBuilder(file_information=file_information)
     user_file = UserFileReaderAdapter(data_info=data_information,
                                       user_file_name=user_filename)
     return StateBuilder(run_data_builder=run_data,
                         i_state_parser=user_file)