def _process_command_queue(self, data_state):
        """
        Process the command queue sequentially as FIFO structure

        @param data_state: the data state.
        @return: a SANSState object.
        """
        file_name = data_state.sample_scatter
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(file_name)

        self._state_director = StateDirectorISIS(data_state, file_information)

        # If we have a clean instruction in there, then we should apply it to all commands
        self._apply_clean_if_required()

        # Evaluate all commands which adds them to the _processed_state_settings dictionary,
        # except for DataCommands which we deal with separately
        for command in self._commands:
            if isinstance(command, DataCommand):
                continue
            command_id = command.command_id
            process_function = self._method_map[command_id]
            process_function(command)

        # The user file state director
        self._state_director.add_state_settings(self._processed_state_settings)
        return self._state_director.construct()
Esempio n. 2
0
    def test_state_can_be_created_from_valid_user_file_with_data_information(self):
        # Arrange
        data_builder = get_data_builder(SANSFacility.ISIS)
        data_builder.set_sample_scatter("SANS2D00022024")
        data_builder.set_sample_scatter_period(3)
        data_state = data_builder.build()

        director = StateDirectorISIS(data_state)
        user_file_path = create_user_file(sample_user_file)

        director.set_user_file(user_file_path)
        state = director.construct()

        # 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 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,
                                        user_file="USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger_FRONT.txt")
        data_builder.set_sample_scatter("SANS2D00022024")
        data_builder.set_sample_scatter_period(3)
        data_state = data_builder.build()

        director = StateDirectorISIS(data_state, file_information)
        user_file_path = create_user_file(sample_user_file)

        director.set_user_file(user_file_path)
        state = director.construct()

        # 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. 4
0
    def test_state_can_be_created_from_valid_user_file_with_data_information(
            self):
        # Arrange
        data_builder = get_data_builder(SANSFacility.ISIS)
        data_builder.set_sample_scatter("SANS2D00022024")
        data_builder.set_sample_scatter_period(3)
        data_state = data_builder.build()

        director = StateDirectorISIS(data_state)
        user_file_path = create_user_file(sample_user_file)

        director.set_user_file(user_file_path)
        state = director.construct()

        # 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. 5
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_builder.set_calibration(
            "80tubeCalibration_1-05-2015_r3157-3160.nxs")
        data_state = data_builder.build()

        # Get the rest of the state from the user file
        user_file_director = StateDirectorISIS(data_state, file_information)
        user_file_director.set_user_file(
            "USER_LARMOR_151B_LarmorTeam_80tubes_BenchRot1p4_M4_r3699.txt")

        # Construct the final state
        state = user_file_director.construct()

        # 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_single_reduction_evaluates_HAB(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_file_director = StateDirectorISIS(data_info, file_information)
        user_file_director.set_user_file(
            "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt")
        # Set the reduction mode to LAB
        user_file_director.set_reduction_builder_reduction_mode(
            ISISReductionMode.HAB)

        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY BEGIN -- Remove when appropriate
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # 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
        user_file_director.set_compatibility_builder_use_compatibility_mode(
            True)
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY END
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        state = user_file_director.construct()

        # 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 = {"OutputWorkspaceHAB": 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(
            "OutputWorkspaceHAB").value

        # # Compare the output of the reduction with the reference
        reference_file_name = "SANS2D_ws_D20_reference_HAB_1D.nxs"
        self._compare_workspace(output_workspace, 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_file_director = StateDirectorISIS(data_info, file_information)
        user_file_director.set_user_file("MASKSANS2Doptions.091A")
        # Set the reduction mode to LAB
        user_file_director.set_reduction_builder_reduction_mode(ISISReductionMode.LAB)

        user_file_director.set_slice_event_builder_start_time([1.0, 3.0])
        user_file_director.set_slice_event_builder_end_time([3.0, 5.0])

        state = user_file_director.construct()

        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 = ["5512p1rear_1D_1.0_2.0Phi-45.0_45.0_t1.00_T3.00", "5512p1rear_1D_1.0_2.0Phi-45.0_45.0_t3.00_T5.00",
                               "5512p1rear_1D_1.0_3.0Phi-45.0_45.0_t1.00_T3.00", "5512p1rear_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. 8
0
    def create_state(self, row, file_lookup=True, instrument=SANSInstrument.SANS2D,
                     user_file=""):
        # 1. Get the data settings, such as sample_scatter, etc... and create the data state.
        table_index_model = self._table_model.get_table_entry(row)
        if file_lookup:
            file_information = table_index_model.file_information
        else:
            file_information = SANSFileInformationMock(instrument=instrument, facility=self._facility)

        data_builder = get_data_builder(self._facility, file_information, user_file)

        self._set_data_entry(data_builder.set_sample_scatter, table_index_model.sample_scatter)
        self._set_data_period_entry(data_builder.set_sample_scatter_period, table_index_model.sample_scatter_period)
        self._set_data_entry(data_builder.set_sample_transmission, table_index_model.sample_transmission)
        self._set_data_period_entry(data_builder.set_sample_transmission_period, table_index_model.sample_transmission_period)  # noqa
        self._set_data_entry(data_builder.set_sample_direct, table_index_model.sample_direct)
        self._set_data_period_entry(data_builder.set_sample_direct_period, table_index_model.sample_direct_period)
        self._set_data_entry(data_builder.set_can_scatter, table_index_model.can_scatter)
        self._set_data_period_entry(data_builder.set_can_scatter_period, table_index_model.can_scatter_period)
        self._set_data_entry(data_builder.set_can_transmission, table_index_model.can_transmission)
        self._set_data_period_entry(data_builder.set_can_transmission_period, table_index_model.can_transmission_period)
        self._set_data_entry(data_builder.set_can_direct, table_index_model.can_direct)
        self._set_data_period_entry(data_builder.set_can_direct_period, table_index_model.can_direct_period)

        data = data_builder.build()

        # 2. Add elements from the options column
        state_gui_model = copy.deepcopy(self._state_gui_model)
        options_column_model = table_index_model.options_column_model
        self._apply_column_options_to_state(options_column_model, state_gui_model)

        # 3. Add other columns
        output_name = table_index_model.output_name
        if output_name:
            state_gui_model.output_name = output_name

        if table_index_model.sample_thickness:
            state_gui_model.sample_thickness = float(table_index_model.sample_thickness)
        if table_index_model.sample_height:
            state_gui_model.sample_height = float(table_index_model.sample_height)
        if table_index_model.sample_width:
            state_gui_model.sample_width = float(table_index_model.sample_width)
        if table_index_model.sample_shape:
            state_gui_model.sample_shape = table_index_model.sample_shape

        # 4. Create the rest of the state based on the builder.
        user_file_state_director = StateDirectorISIS(data, file_information)
        settings = copy.deepcopy(state_gui_model.settings)
        user_file_state_director.add_state_settings(settings)

        return user_file_state_director.construct()
Esempio n. 9
0
    def create_state(self, row, file_lookup=True, instrument=SANSInstrument.SANS2D):
        # 1. Get the data settings, such as sample_scatter, etc... and create the data state.
        table_index_model = self._table_model.get_table_entry(row)
        if file_lookup:
            file_information = table_index_model.file_information
        else:
            file_information = SANSFileInformationMock(instrument=instrument, facility=self._facility)

        data_builder = get_data_builder(self._facility, file_information)

        self._set_data_entry(data_builder.set_sample_scatter, table_index_model.sample_scatter)
        self._set_data_period_entry(data_builder.set_sample_scatter_period, table_index_model.sample_scatter_period)
        self._set_data_entry(data_builder.set_sample_transmission, table_index_model.sample_transmission)
        self._set_data_period_entry(data_builder.set_sample_transmission_period, table_index_model.sample_transmission_period)  # noqa
        self._set_data_entry(data_builder.set_sample_direct, table_index_model.sample_direct)
        self._set_data_period_entry(data_builder.set_sample_direct_period, table_index_model.sample_direct_period)
        self._set_data_entry(data_builder.set_can_scatter, table_index_model.can_scatter)
        self._set_data_period_entry(data_builder.set_can_scatter_period, table_index_model.can_scatter_period)
        self._set_data_entry(data_builder.set_can_transmission, table_index_model.can_transmission)
        self._set_data_period_entry(data_builder.set_can_transmission_period, table_index_model.can_transmission_period)
        self._set_data_entry(data_builder.set_can_direct, table_index_model.can_direct)
        self._set_data_period_entry(data_builder.set_can_direct_period, table_index_model.can_direct_period)

        data = data_builder.build()

        # 2. Add elements from the options column
        state_gui_model = copy.deepcopy(self._state_gui_model)
        options_column_model = table_index_model.options_column_model
        self._apply_column_options_to_state(options_column_model, state_gui_model)

        # 3. Add other columns
        output_name = table_index_model.output_name
        if output_name:
            state_gui_model.output_name = output_name

        if table_index_model.sample_thickness:
            state_gui_model.sample_thickness = float(table_index_model.sample_thickness)
        if table_index_model.sample_height:
            state_gui_model.sample_height = float(table_index_model.sample_height)
        if table_index_model.sample_width:
            state_gui_model.sample_width = float(table_index_model.sample_width)
        if table_index_model.sample_shape:
            state_gui_model.sample_shape = table_index_model.sample_shape

        # 4. Create the rest of the state based on the builder.
        user_file_state_director = StateDirectorISIS(data, file_information)
        settings = copy.deepcopy(state_gui_model.settings)
        user_file_state_director.add_state_settings(settings)

        return user_file_state_director.construct()
Esempio n. 10
0
    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_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_file_director = StateDirectorISIS(data_info, file_information)
        user_file_director.set_user_file(
            "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt")
        # Set the reduction mode to LAB
        user_file_director.set_reduction_builder_reduction_mode(
            ISISReductionMode.LAB)
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY BEGIN -- Remove when appropriate
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # 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
        user_file_director.set_compatibility_builder_use_compatibility_mode(
            True)
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY END
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        state = user_file_director.construct()

        # Act
        states = [state]
        self._run_batch_reduction(states, use_optimizations=False)
        workspace_name = "34484rear_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. 11
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_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_director = StateDirectorISIS(data_state, file_information)
        user_file_director.set_user_file("USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt")

        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY BEGIN -- Remove when appropriate
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # 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
        user_file_director.set_compatibility_builder_use_compatibility_mode(True)
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY END
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

        # Construct the final state
        state = user_file_director.construct()

        # 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. 12
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_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_director = StateDirectorISIS(data_state, file_information)
        user_file_director.set_user_file(
            "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt")

        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY BEGIN -- Remove when appropriate
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # 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
        user_file_director.set_compatibility_builder_use_compatibility_mode(
            True)
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY END
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

        # Construct the final state
        state = user_file_director.construct()
        state.adjustment.show_transmission = True

        # 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(
            "OutputWorkspace").value
        calculated_transmission = reduction_core_alg.getProperty(
            "CalculatedTransmissionWorkspace").value
        unfitted_transmission = reduction_core_alg.getProperty(
            "UnfittedTransmissionWorkspace").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)
    def test_that_single_reduction_evaluates_HAB(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_file_director = StateDirectorISIS(data_info, file_information)
        user_file_director.set_user_file("USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt")
        # Set the reduction mode to LAB
        user_file_director.set_reduction_builder_reduction_mode(ISISReductionMode.HAB)

        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY BEGIN -- Remove when appropriate
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # 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
        user_file_director.set_compatibility_builder_use_compatibility_mode(True)
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY END
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        state = user_file_director.construct()

        # 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 = {"OutputWorkspaceHAB": 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("OutputWorkspaceHAB").value

        # # Compare the output of the reduction with the reference
        reference_file_name = "SANS2D_ws_D20_reference_HAB_1D.nxs"
        self._compare_workspace(output_workspace, reference_file_name)
Esempio n. 14
0
    def test_that_beam_centre_core_produces_correct_workspaces(self):
        # Arrange
        # Build the data information
        data_builder = get_data_builder(SANSFacility.ISIS)
        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_director = StateDirectorISIS(data_state)
        user_file_director.set_user_file(
            "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt")

        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY BEGIN -- Remove when appropriate
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # 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
        user_file_director.set_compatibility_builder_use_compatibility_mode(
            True)
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY END
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

        # Construct the final state
        state = user_file_director.construct()

        # 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. 15
0
    def test_batch_reduction_on_multiperiod_file(self):
        # Arrange
        # Build the data information
        data_builder = get_data_builder(SANSFacility.ISIS)
        data_builder.set_sample_scatter("SANS2D0005512")

        data_info = data_builder.build()

        # Get the rest of the state from the user file
        user_file_director = StateDirectorISIS(data_info)
        user_file_director.set_user_file("MASKSANS2Doptions.091A")
        # Set the reduction mode to LAB
        user_file_director.set_reduction_builder_reduction_mode(ISISReductionMode.LAB)
        state = user_file_director.construct()

        # 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 = ["5512p1rear_1D_2.0_14.0Phi-45.0_45.0", "5512p2rear_1D_2.0_14.0Phi-45.0_45.0",
                               "5512p3rear_1D_2.0_14.0Phi-45.0_45.0", "5512p4rear_1D_2.0_14.0Phi-45.0_45.0",
                               "5512p5rear_1D_2.0_14.0Phi-45.0_45.0", "5512p6rear_1D_2.0_14.0Phi-45.0_45.0",
                               "5512p7rear_1D_2.0_14.0Phi-45.0_45.0", "5512p8rear_1D_2.0_14.0Phi-45.0_45.0",
                               "5512p9rear_1D_2.0_14.0Phi-45.0_45.0", "5512p10rear_1D_2.0_14.0Phi-45.0_45.0",
                               "5512p11rear_1D_2.0_14.0Phi-45.0_45.0", "5512p12rear_1D_2.0_14.0Phi-45.0_45.0",
                               "5512p13rear_1D_2.0_14.0Phi-45.0_45.0"]
        for element in expected_workspaces:
            self.assertTrue(AnalysisDataService.doesExist(element))

        # Clean up
        for element in expected_workspaces:
            AnalysisDataService.remove(element)
Esempio n. 16
0
    def create_state(self, row):
        # 1. Get the data settings, such as sample_scatter, etc... and create the data state.
        table_index_model = self._table_model.get_table_entry(row)
        file_name = table_index_model.sample_scatter
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(file_name)
        data_builder = get_data_builder(self._facility, file_information)

        self._set_data_entry(data_builder.set_sample_scatter, table_index_model.sample_scatter)
        self._set_data_period_entry(data_builder.set_sample_scatter_period, table_index_model.sample_scatter_period)
        self._set_data_entry(data_builder.set_sample_transmission, table_index_model.sample_transmission)
        self._set_data_period_entry(data_builder.set_sample_transmission_period, table_index_model.sample_transmission_period)  # noqa
        self._set_data_entry(data_builder.set_sample_direct, table_index_model.sample_direct)
        self._set_data_period_entry(data_builder.set_sample_direct_period, table_index_model.sample_direct_period)
        self._set_data_entry(data_builder.set_can_scatter, table_index_model.can_scatter)
        self._set_data_period_entry(data_builder.set_can_scatter_period, table_index_model.can_scatter_period)
        self._set_data_entry(data_builder.set_can_transmission, table_index_model.can_transmission)
        self._set_data_period_entry(data_builder.set_can_transmission_period, table_index_model.can_transmission_period)
        self._set_data_entry(data_builder.set_can_direct, table_index_model.can_direct)
        self._set_data_period_entry(data_builder.set_can_direct_period, table_index_model.can_direct_period)

        data = data_builder.build()

        # 2. Add elements from the options column
        state_gui_model = copy.deepcopy(self._state_gui_model)
        options_column_model = table_index_model.options_column_model
        self._apply_column_options_to_state(options_column_model, state_gui_model)

        # 3. Add other columns
        output_name = table_index_model.output_name
        if output_name:
            state_gui_model.output_name = output_name

        # 4. Create the rest of the state based on the builder.
        user_file_state_director = StateDirectorISIS(data, file_information)
        settings = copy.deepcopy(state_gui_model.settings)
        user_file_state_director.add_state_settings(settings)

        return user_file_state_director.construct()
    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_builder.set_calibration("80tubeCalibration_1-05-2015_r3157-3160.nxs")
        data_state = data_builder.build()

        # Get the rest of the state from the user file
        user_file_director = StateDirectorISIS(data_state, file_information)
        user_file_director.set_user_file("USER_LARMOR_151B_LarmorTeam_80tubes_BenchRot1p4_M4_r3699.txt")

        # Construct the final state
        state = user_file_director.construct()

        # 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_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_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_file_director = StateDirectorISIS(data_info, file_information)
        user_file_director.set_user_file("USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt")
        # Set the reduction mode to LAB
        user_file_director.set_reduction_builder_reduction_mode(ISISReductionMode.LAB)
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY BEGIN -- Remove when appropriate
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # 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
        user_file_director.set_compatibility_builder_use_compatibility_mode(True)
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY END
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        state = user_file_director.construct()

        # Act
        states = [state]
        self._run_batch_reduction(states, use_optimizations=False)
        workspace_name = "34484rear_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. 19
0
    def create_state(self, row):
        # 1. Get the data settings, such as sample_scatter, etc... and create the data state.
        table_index_model = self._table_model.get_table_entry(row)
        data_builder = get_data_builder(self._facility)

        self._set_data_entry(data_builder.set_sample_scatter, table_index_model.sample_scatter)
        self._set_data_period_entry(data_builder.set_sample_scatter_period, table_index_model.sample_scatter_period)
        self._set_data_entry(data_builder.set_sample_transmission, table_index_model.sample_transmission)
        self._set_data_period_entry(data_builder.set_sample_transmission_period, table_index_model.sample_transmission_period)  # noqa
        self._set_data_entry(data_builder.set_sample_direct, table_index_model.sample_direct)
        self._set_data_period_entry(data_builder.set_sample_direct_period, table_index_model.sample_direct_period)
        self._set_data_entry(data_builder.set_can_scatter, table_index_model.can_scatter)
        self._set_data_period_entry(data_builder.set_can_scatter_period, table_index_model.can_scatter_period)
        self._set_data_entry(data_builder.set_can_transmission, table_index_model.can_transmission)
        self._set_data_period_entry(data_builder.set_can_transmission_period, table_index_model.can_transmission_period)
        self._set_data_entry(data_builder.set_can_direct, table_index_model.can_direct)
        self._set_data_period_entry(data_builder.set_can_direct_period, table_index_model.can_direct_period)

        data = data_builder.build()

        # 2. Add elements from the options column
        state_gui_model = copy.deepcopy(self._state_gui_model)
        options_column_model = table_index_model.options_column_model
        self._apply_column_options_to_state(options_column_model, state_gui_model)

        # 3. Add other columns
        output_name = table_index_model.output_name
        if output_name:
            state_gui_model.output_name = output_name

        # 4. Create the rest of the state based on the builder.
        user_file_state_director = StateDirectorISIS(data)
        settings = copy.deepcopy(state_gui_model.settings)
        user_file_state_director.add_state_settings(settings)

        return user_file_state_director.construct()
    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_file_director = StateDirectorISIS(data_info, file_information)
        user_file_director.set_user_file("MASKSANS2Doptions.091A")
        # Set the reduction mode to LAB
        user_file_director.set_reduction_builder_reduction_mode(
            ISISReductionMode.LAB)
        state = user_file_director.construct()

        # 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 = [
            "5512p1rear_1D_2.0_14.0Phi-45.0_45.0",
            "5512p2rear_1D_2.0_14.0Phi-45.0_45.0",
            "5512p3rear_1D_2.0_14.0Phi-45.0_45.0",
            "5512p4rear_1D_2.0_14.0Phi-45.0_45.0",
            "5512p5rear_1D_2.0_14.0Phi-45.0_45.0",
            "5512p6rear_1D_2.0_14.0Phi-45.0_45.0",
            "5512p7rear_1D_2.0_14.0Phi-45.0_45.0",
            "5512p8rear_1D_2.0_14.0Phi-45.0_45.0",
            "5512p9rear_1D_2.0_14.0Phi-45.0_45.0",
            "5512p10rear_1D_2.0_14.0Phi-45.0_45.0",
            "5512p11rear_1D_2.0_14.0Phi-45.0_45.0",
            "5512p12rear_1D_2.0_14.0Phi-45.0_45.0",
            "5512p13rear_1D_2.0_14.0Phi-45.0_45.0"
        ]
        for element in expected_workspaces:
            self.assertTrue(AnalysisDataService.doesExist(element))

        # Clean up
        for element in expected_workspaces:
            AnalysisDataService.remove(element)
    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_director = StateDirectorISIS(data_state, file_information)
        user_file_director.set_user_file("USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt")

        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY BEGIN -- Remove when appropriate
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # 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
        user_file_director.set_compatibility_builder_use_compatibility_mode(True)
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY END
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

        # Construct the final state
        state = user_file_director.construct()

        # 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_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_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_director = StateDirectorISIS(data_state, file_information)
        user_file_director.set_user_file("USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt")

        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY BEGIN -- Remove when appropriate
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # 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
        user_file_director.set_compatibility_builder_use_compatibility_mode(True)
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY END
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

        # Construct the final state
        state = user_file_director.construct()
        state.adjustment.show_transmission = True

        # 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("OutputWorkspace").value
        calculated_transmission = reduction_core_alg.getProperty("CalculatedTransmissionWorkspace").value
        unfitted_transmission = reduction_core_alg.getProperty("UnfittedTransmissionWorkspace").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)
    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_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_file_director = StateDirectorISIS(data_info, file_information)
        user_file_director.set_user_file("USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt")
        # Set the reduction mode to LAB
        user_file_director.set_reduction_builder_reduction_mode(ISISReductionMode.LAB)
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY BEGIN -- Remove when appropriate
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # 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
        user_file_director.set_compatibility_builder_use_compatibility_mode(True)
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY END
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

        state = user_file_director.construct()
        start = [1.0,2.0]
        end = [2.0,3.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)

        expected_workspaces = ["34484rear_1D_1.0_2.0", "34484rear_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)
Esempio n. 24
0
    def test_stat_can_be_crated_from_valid_user_file_and_later_on_reset(self):
        # Arrange
        data_builder = get_data_builder(SANSFacility.ISIS)
        data_builder.set_sample_scatter("SANS2D00022024")
        data_builder.set_sample_scatter_period(3)
        data_state = data_builder.build()

        director = StateDirectorISIS(data_state)
        user_file_path = create_user_file(sample_user_file)
        director.set_user_file(user_file_path)

        # Set additional items
        director.set_mask_builder_radius_min(0.001298)
        director.set_mask_builder_radius_max(0.003298)
        director.set_scale_builder_width(1.)
        director.set_scale_builder_height(1.5)
        director.set_scale_builder_thickness(12.)
        director.set_scale_builder_shape(SampleShape.Cuboid)

        # Act
        state = director.construct()

        # Assert
        self.assertTrue(state.mask.radius_min == 0.001298)
        self.assertTrue(state.mask.radius_max == 0.003298)
        self.assertTrue(state.scale.width == 1.)
        self.assertTrue(state.scale.height == 1.5)
        self.assertTrue(state.scale.thickness == 12.)
        self.assertTrue(state.scale.shape is SampleShape.Cuboid)

        # clean up
        if os.path.exists(user_file_path):
            os.remove(user_file_path)
Esempio n. 25
0
    def test_stat_can_be_created_from_valid_user_file_and_later_on_reset(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()

        director = StateDirectorISIS(data_state, file_information)
        user_file_path = create_user_file(sample_user_file)
        director.set_user_file(user_file_path)

        # Set additional items
        director.set_mask_builder_radius_min(0.001298)
        director.set_mask_builder_radius_max(0.003298)
        director.set_scale_builder_width(1.)
        director.set_scale_builder_height(1.5)
        director.set_scale_builder_thickness(12.)
        director.set_scale_builder_shape(SampleShape.FlatPlate)

        # Act
        state = director.construct()

        # Assert
        self.assertEqual(state.mask.radius_min,  0.001298)
        self.assertEqual(state.mask.radius_max,  0.003298)
        self.assertEqual(state.scale.width,  1.)
        self.assertEqual(state.scale.height,  1.5)
        self.assertEqual(state.scale.thickness,  12.)
        self.assertEqual(state.scale.shape, SampleShape.FlatPlate)

        # clean up
        if os.path.exists(user_file_path):
            os.remove(user_file_path)
Esempio n. 26
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_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_file_director = StateDirectorISIS(data_info, file_information)
        user_file_director.set_user_file("USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt")
        # Set the reduction mode to LAB
        user_file_director.set_reduction_builder_reduction_mode(ISISReductionMode.LAB)
        user_file_director.set_compatibility_builder_use_compatibility_mode(False)

        # Add some event slices
        user_file_director.set_slice_event_builder_start_time([0.00, 300.00])
        user_file_director.set_slice_event_builder_end_time([300.00, 600.00])

        # Construct
        state = user_file_director.construct()

        # 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}
        start_time = time.time()
        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)
        version_2_execution_time = time.time() - start_time

        # 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
        user_file_director.set_slice_event_builder_start_time([0.00])
        user_file_director.set_slice_event_builder_end_time([300.00])
        state = user_file_director.construct()

        start_time = time.time()
        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)
        first_slice_execution_time = time.time() - start_time

        # Run the second event slice
        user_file_director.set_slice_event_builder_start_time([300.00])
        user_file_director.set_slice_event_builder_end_time([600.00])
        state = user_file_director.construct()

        start_time = time.time()
        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)
        version_1_execution_time = time.time() - start_time + first_slice_execution_time

        # Check that running version 2 once is quicker than running version 1 twice (once for each slice)
        # version 2 has been significantly quicker that multiple runs are not necessary to ensure this test
        # does not sporadically fail. However, this check could be removed if this changes.
        self.assertLess(version_2_execution_time, version_1_execution_time)

        # 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. 27
0
    def test_that_single_reduction_evaluates_merged(self):
        # Arrange
        # Build the data information
        data_builder = get_data_builder(SANSFacility.ISIS)
        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_file_director = StateDirectorISIS(data_info)
        user_file_director.set_user_file("USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt")
        # Set the reduction mode to LAB
        user_file_director.set_reduction_builder_reduction_mode(ISISReductionMode.Merged)
        user_file_director.set_reduction_builder_merge_fit_mode(FitModeForMerge.Both)
        user_file_director.set_reduction_builder_merge_scale(1.0)
        user_file_director.set_reduction_builder_merge_shift(0.0)
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY BEGIN -- Remove when appropriate
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # 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
        user_file_director.set_compatibility_builder_use_compatibility_mode(True)
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY END
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        state = user_file_director.construct()

        # 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.81439154

        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_workspace(output_workspace, reference_file_name)
Esempio n. 28
0
    def test_that_single_reduction_evaluates_merged(self):
        # Arrange
        # Build the data information
        data_builder = get_data_builder(SANSFacility.ISIS)
        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_file_director = StateDirectorISIS(data_info)
        user_file_director.set_user_file(
            "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt")
        # Set the reduction mode to LAB
        user_file_director.set_reduction_builder_reduction_mode(
            ISISReductionMode.Merged)
        user_file_director.set_reduction_builder_merge_fit_mode(
            FitModeForMerge.Both)
        user_file_director.set_reduction_builder_merge_scale(1.0)
        user_file_director.set_reduction_builder_merge_shift(0.0)
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY BEGIN -- Remove when appropriate
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # 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
        user_file_director.set_compatibility_builder_use_compatibility_mode(
            True)
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY END
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        state = user_file_director.construct()

        # 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.81439154

        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_workspace(output_workspace, reference_file_name)
Esempio n. 29
0
    def test_stat_can_be_crated_from_valid_user_file_and_later_on_reset(self):
        # Arrange
        data_builder = get_data_builder(SANSFacility.ISIS)
        data_builder.set_sample_scatter("SANS2D00022024")
        data_builder.set_sample_scatter_period(3)
        data_state = data_builder.build()

        director = StateDirectorISIS(data_state)
        user_file_path = create_user_file(sample_user_file)
        director.set_user_file(user_file_path)

        # Set additional items
        director.set_mask_builder_radius_min(0.001298)
        director.set_mask_builder_radius_max(0.003298)
        director.set_scale_builder_width(1.)
        director.set_scale_builder_height(1.5)
        director.set_scale_builder_thickness(12.)
        director.set_scale_builder_shape(SampleShape.Cuboid)

        # Act
        state = director.construct()

        # Assert
        self.assertTrue(state.mask.radius_min == 0.001298)
        self.assertTrue(state.mask.radius_max == 0.003298)
        self.assertTrue(state.scale.width == 1.)
        self.assertTrue(state.scale.height == 1.5)
        self.assertTrue(state.scale.thickness == 12.)
        self.assertTrue(state.scale.shape is SampleShape.Cuboid)

        # clean up
        if os.path.exists(user_file_path):
            os.remove(user_file_path)
class CommandInterfaceStateDirector(object):
    def __init__(self, facility):
        super(CommandInterfaceStateDirector, self).__init__()
        self._commands = []
        self._state_director = None

        self._processed_state_settings = {}

        self._facility = facility
        self._method_map = None
        self._set_up_method_map()

    def add_command(self, command):
        self._commands.append(command)

    def clear_commands(self):
        self._commands = []
        self._processed_state_settings = {}

    def process_commands(self):
        """
        Here we process the commands that have been set. This would be triggered by a command which requests a reduction

        The execution strategy is:
        1. Find the data entries and great a SANSStateData object out of them
        2. Go sequentially through the commands in a FIFO manner (except for the data entries)
        3. Delete the processed state settings. We only need to retain the commands. If we also retain the
           processed state settings then we will populate some entries twice.
        4. Returns the constructed state
        @returns a list of valid SANSState object which can be used for data reductions or raises an exception.
        """
        # 1. Get a SANSStateData object.
        data_state = self._get_data_state()

        # 2. Go through
        state = self._process_command_queue(data_state)

        # 3. Leave commands in place put clear the list of processed commands, else they will be reused.
        self._processed_state_settings = {}

        # 4. Provide the state
        return state

    def get_commands(self):
        return self._commands

    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()

    def _get_data_commands(self):
        """
        Grabs and removes the data commands from the command queue.

        @return: a list of data commands
        """
        # Grab the data commands
        data_commands = [element for element in self._commands if isinstance(element, DataCommand)]
        return data_commands

    def _set_data_element(self, data_builder_file_setter, data_builder_period_setter, command_id, commands):
        """
        Sets a data element (e.g. sample scatter file and sample scatter period) on the data builder.

        @param data_builder_file_setter: a handle to the correct setter for the file on the data builder.
        @param data_builder_period_setter: a handle to the correct setter for the period on the data builder.
        @param command_id: the command id
        @param commands: a list of commands.
        """
        data_elements = self._get_elements_with_key(command_id, commands)

        # If there is no element, then there is nothing to do
        if len(data_elements) == 0:
            return

        # If there is more than one element, then we are only interested in the last element. The user could
        # have overridden his wishes, e.g.
        # ...
        # AssignSample('SANS2D1234')
        # ...
        # AssignSample('SANS2D4321')
        # ...
        # We select therefore the last element
        data_element = data_elements[-1]
        file_name = data_element.file_name
        period = data_element.period
        data_builder_file_setter(file_name)
        data_builder_period_setter(period)

    @staticmethod
    def _get_elements_with_key(command_id, command_list):
        """
        Get all elements in the command list with a certain id

        @param command_id: the id of the command.
        @param command_list: a list of commands.
        @return: a list of commands which match the id.
        """
        return [element for element in command_list if element.command_id is command_id]

    def _process_command_queue(self, data_state):
        """
        Process the command queue sequentially as FIFO structure

        @param data_state: the data state.
        @return: a SANSState object.
        """
        file_name = data_state.sample_scatter
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(file_name)

        self._state_director = StateDirectorISIS(data_state, file_information)

        # If we have a clean instruction in there, then we should apply it to all commands
        self._apply_clean_if_required()

        # Evaluate all commands which adds them to the _processed_state_settings dictionary,
        # except for DataCommands which we deal with separately
        for command in self._commands:
            if isinstance(command, DataCommand):
                continue
            command_id = command.command_id
            process_function = self._method_map[command_id]
            process_function(command)

        # The user file state director
        self._state_director.add_state_settings(self._processed_state_settings)
        return self._state_director.construct()

    def _set_up_method_map(self):
        """
        Sets up a mapping between command ids and the adequate processing methods which can handle the command.
        """
        self._method_map = {NParameterCommandId.user_file: self._process_user_file,
                            NParameterCommandId.mask: self._process_mask,
                            NParameterCommandId.incident_spectrum: self._process_incident_spectrum,
                            NParameterCommandId.clean: self._process_clean,
                            NParameterCommandId.reduction_dimensionality: self._process_reduction_dimensionality,
                            NParameterCommandId.sample_offset: self._process_sample_offset,
                            NParameterCommandId.detector: self._process_detector,
                            NParameterCommandId.gravity: self._process_gravity,
                            NParameterCommandId.centre: self._process_centre,
                            NParameterCommandId.trans_fit: self._process_trans_fit,
                            NParameterCommandId.front_detector_rescale: self._process_front_detector_rescale,
                            NParameterCommandId.event_slices: self._process_event_slices,
                            NParameterCommandId.flood_file: self._process_flood_file,
                            NParameterCommandId.phi_limit: self._process_phi_limit,
                            NParameterCommandId.wavelength_correction_file: self._process_wavelength_correction_file,
                            NParameterCommandId.mask_radius: self._process_mask_radius,
                            NParameterCommandId.wavelength_limit: self._process_wavelength_limit,
                            NParameterCommandId.qxy_limit: self._process_qxy_limit,
                            NParameterCommandId.wavrange_settings: self._process_wavrange,
                            NParameterCommandId.compatibility_mode: self._process_compatibility_mode,
                            NParameterCommandId.detector_offsets: self._process_detector_offsets,
                            NParameterCommandId.save: self._process_save,
                            NParameterCommandId.user_specified_output_name: self._process_user_specified_output_name,
                            NParameterCommandId.user_specified_output_name_suffix:
                                self._process_user_specified_output_name_suffix,
                            NParameterCommandId.use_reduction_mode_as_suffix:
                                self._process_use_reduction_mode_as_suffix
                            }

    def add_to_processed_state_settings(self, new_state_settings, treat_list_as_element=False):
        """
        Adds the new entries to the already processed state settings

        @param new_state_settings: a dictionary with new entries for the processed state settings
        @param treat_list_as_element: if we have a list and add it for the fist time, then we should treat it as an
                                      element if true. For example, if the state is [1, 2] the a new settint would, be
                                      [[1, 2,]] and not [1, 2]. With a further entry it could be [[1,2], [3,4]].
        """
        for key, value in list(new_state_settings.items()):
            # Add the new entry
            # 1. A similar entry can already exist, then append it (or extend it)
            # 2. The entry does not exist, but it is in form of a list (you would get that for example when
            #    dealing with input from the UserFileReader
            # 3. The entry does not exist and is not in a list. In this case we need to add it to a list.
            if key in self._processed_state_settings:
                # If the key already exists then we have to be careful. We have the current value V = [A, B, ...]
                # and our new element N
                # i. If the existing entries (ie A, ...) are not lists and N is not a list, then append to V.
                # ii. If the existing entries (ie A, ...) are not lists and N is a list then extend V.
                # iii. If the existing entries (ie A, ...) are lists and N is a list then append to V.
                # iv. If the existing entries (ie A, ...) are lists and N is not a list, then raise
                # The reason we have to be careful is that we might get an N from a user file which comes always already
                # in the form of a list.
                old_values = self._processed_state_settings[key]
                is_old_first_entry_a_list = isinstance(old_values[0], list)
                is_new_entry_a_list = isinstance(value, list)

                if not is_old_first_entry_a_list and not is_new_entry_a_list:
                    old_values.append(value)
                elif not is_old_first_entry_a_list and is_new_entry_a_list:
                    old_values.extend(value)
                elif is_old_first_entry_a_list and is_new_entry_a_list:
                    old_values.append(value)
                else:
                    raise RuntimeError("CommandInterfaceStateDirector: Trying to insert {0} which is a list into {0} "
                                       "which is collection of non-list elements".format(value, old_values))
            elif isinstance(value, list) and treat_list_as_element:
                self._processed_state_settings.update({key: [value]})
            elif isinstance(value, list):
                self._processed_state_settings.update({key: value})
            else:
                self._processed_state_settings.update({key: [value]})

    def _process_user_file(self, command):
        """
        Processes a user file and retain the parased tags

        @param command: the command with the user file path
        """
        file_name = command.values[0]
        user_file_reader = UserFileReader(file_name)
        new_state_entries = user_file_reader.read_user_file()
        self.add_to_processed_state_settings(new_state_entries)

    def _process_mask(self, command):
        """
        We need to process a mask line as specified in the user file.
        """
        mask_command = command.values[0]
        # Use the user file parser to extract the values from the user file setting.
        user_file_parser = UserFileParser()
        parsed_output = user_file_parser.parse_line(mask_command)
        self.add_to_processed_state_settings(parsed_output)

    def _process_incident_spectrum(self, command):
        incident_monitor = command.values[0]
        interpolate = command.values[1]
        is_trans = command.values[2]
        new_state_entries = {MonId.spectrum: monitor_spectrum(spectrum=incident_monitor,
                                                              is_trans=is_trans,
                                                              interpolate=interpolate)}
        self.add_to_processed_state_settings(new_state_entries)

    def _apply_clean_if_required(self):
        """
        The cleans all commands up to the clean command point.

        We have to do this clean before we start processing the elements.
        """
        index_first_clean_command = None
        for index in reversed(list(range(0, len(self._commands)))):
            element = self._commands[index]
            if element.command_id == NParameterCommandId.clean:
                index_first_clean_command = index
                break
        if index_first_clean_command is not None:
            del(self._commands[0:(index_first_clean_command + 1)])
            self._processed_state_settings = {}

    def _process_clean(self, command):
        _ = command  # noqa
        raise RuntimeError("Trying the process a Clean command. The clean command should have removed itself and "
                           "all previous commands. If it is still here, then this is a bug")

    def _process_reduction_dimensionality(self, command):
        _ = command  # noqa
        reduction_dimensionality = command.values[0]
        new_state_entries = {OtherId.reduction_dimensionality: reduction_dimensionality}
        self.add_to_processed_state_settings(new_state_entries)

    def _process_sample_offset(self, command):
        sample_offset = command.values[0]
        new_state_entries = {SampleId.offset: sample_offset}
        self.add_to_processed_state_settings(new_state_entries)

    def _process_detector(self, command):
        reduction_mode = command.values[0]
        new_state_entries = {DetectorId.reduction_mode: reduction_mode}
        self.add_to_processed_state_settings(new_state_entries)

    def _process_gravity(self, command):
        use_gravity = command.values[0]
        extra_length = command.values[1]
        new_state_entries = {GravityId.on_off: use_gravity,
                             GravityId.extra_length: extra_length}
        self.add_to_processed_state_settings(new_state_entries)

    def _process_centre(self, command):
        pos1 = command.values[0]
        pos2 = command.values[1]
        detector_type = command.values[2]
        new_state_entries = {SetId.centre: position_entry(pos1=pos1, pos2=pos2, detector_type=detector_type)}
        self.add_to_processed_state_settings(new_state_entries)

    def _process_trans_fit(self, command):
        def fit_type_to_data_type(fit_type_to_convert):
            return DataType.Can if fit_type_to_convert is FitData.Can else DataType.Sample

        fit_data = command.values[0]
        wavelength_low = command.values[1]
        wavelength_high = command.values[2]
        fit_type = command.values[3]
        polynomial_order = command.values[4]
        if fit_data is FitData.Both:
            data_to_fit = [FitData.Sample, FitData.Can]
        else:
            data_to_fit = [fit_data]

        new_state_entries = {}
        for element in data_to_fit:
            data_type = fit_type_to_data_type(element)
            new_state_entries.update({FitId.general: fit_general(start=wavelength_low, stop=wavelength_high,
                                                                 fit_type=fit_type, data_type=data_type,
                                                                 polynomial_order=polynomial_order)})
        self.add_to_processed_state_settings(new_state_entries)

    def _process_front_detector_rescale(self, command):
        scale = command.values[0]
        shift = command.values[1]
        fit_scale = command.values[2]
        fit_shift = command.values[3]
        q_min = command.values[4]
        q_max = command.values[5]

        # Set the scale and the shift
        new_state_entries = {DetectorId.rescale: scale, DetectorId.shift: shift}

        # Set the fit for the scale
        new_state_entries.update({DetectorId.rescale_fit: det_fit_range(start=q_min, stop=q_max, use_fit=fit_scale)})

        # Set the fit for shift
        new_state_entries.update({DetectorId.shift_fit: det_fit_range(start=q_min, stop=q_max, use_fit=fit_shift)})

        self.add_to_processed_state_settings(new_state_entries)

    def _process_event_slices(self, command):
        event_slice_value = command.values
        new_state_entries = {OtherId.event_slices: event_binning_string_values(value=event_slice_value)}
        self.add_to_processed_state_settings(new_state_entries)

    def _process_flood_file(self, command):
        file_path = command.values[0]
        detector_type = command.values[1]
        new_state_entries = {MonId.flat: monitor_file(file_path=file_path, detector_type=detector_type)}
        self.add_to_processed_state_settings(new_state_entries)

    def _process_phi_limit(self, command):
        phi_min = command.values[0]
        phi_max = command.values[1]
        use_phi_mirror = command.values[2]
        new_state_entries = {LimitsId.angle: mask_angle_entry(min=phi_min, max=phi_max, use_mirror=use_phi_mirror)}
        self.add_to_processed_state_settings(new_state_entries)

    def _process_wavelength_correction_file(self, command):
        file_path = command.values[0]
        detector_type = command.values[1]
        new_state_entries = {MonId.direct: monitor_file(file_path=file_path, detector_type=detector_type)}
        self.add_to_processed_state_settings(new_state_entries)

    def _process_mask_radius(self, command):
        radius_min = command.values[0]
        radius_max = command.values[1]
        new_state_entries = {LimitsId.radius: range_entry(start=radius_min, stop=radius_max)}
        self.add_to_processed_state_settings(new_state_entries)

    def _process_wavelength_limit(self, command):
        wavelength_low = command.values[0]
        wavelength_high = command.values[1]
        wavelength_step = command.values[2]
        wavelength_step_type = command.values[3]
        new_state_entries = {LimitsId.wavelength: simple_range(start=wavelength_low, stop=wavelength_high,
                                                               step=wavelength_step, step_type=wavelength_step_type)}
        self.add_to_processed_state_settings(new_state_entries)

    def _process_wavrange(self, command):
        wavelength_low = command.values[0]
        wavelength_high = command.values[1]
        full_wavelength_range = command.values[2]
        reduction_mode = command.values[3]

        # Update the lower and the upper wavelength values. Note that this is considered an incomplete setting, since
        # not step or step type have been specified. This means we need to update one of the processed commands, which
        # is not nice but the command interface forces us to do so. We take a copy of the last LimitsId.wavelength
        # entry, we copy it and then change the desired settings. This means it has to be set at this point, else
        # something is wrong
        if LimitsId.wavelength in self._processed_state_settings:
            last_entry = self._processed_state_settings[LimitsId.wavelength][-1]

            new_wavelength_low = wavelength_low if wavelength_low is not None else last_entry.start
            new_wavelength_high = wavelength_high if wavelength_high is not None else last_entry.stop
            new_range = simple_range(start=new_wavelength_low, stop=new_wavelength_high, step=last_entry.step,
                                     step_type=last_entry.step_type)

            if wavelength_low is not None or wavelength_high is not None:
                copied_entry = {LimitsId.wavelength: new_range}
                self.add_to_processed_state_settings(copied_entry)
        else:
            raise RuntimeError("CommandInterfaceStateDirector: Setting the lower and upper wavelength bounds is not"
                               " possible. We require also a step and step range")

        if full_wavelength_range is not None:
            full_wavelength_range_entry = {OtherId.use_full_wavelength_range: full_wavelength_range}
            self.add_to_processed_state_settings(full_wavelength_range_entry)

        if reduction_mode is not None:
            reduction_mode_entry = {DetectorId.reduction_mode: reduction_mode}
            self.add_to_processed_state_settings(reduction_mode_entry)

    def _process_qxy_limit(self, command):
        q_min = command.values[0]
        q_max = command.values[1]
        q_step = command.values[2]
        q_step_type = command.values[3]
        new_state_entries = {LimitsId.qxy: simple_range(start=q_min, stop=q_max, step=q_step, step_type=q_step_type)}
        self.add_to_processed_state_settings(new_state_entries)

    def _process_compatibility_mode(self, command):
        use_compatibility_mode = command.values[0]
        new_state_entries = {OtherId.use_compatibility_mode: use_compatibility_mode}
        self.add_to_processed_state_settings(new_state_entries)

    def _process_detector_offsets(self, command):
        detector_type = command.values[0]
        x = command.values[1]
        y = command.values[2]
        z = command.values[3]
        rotation = command.values[4]
        radius = command.values[5]
        side = command.values[6]
        x_tilt = command.values[7]
        y_tilt = command.values[8]

        # Set the offsets
        new_state_entries = {DetectorId.correction_x: single_entry_with_detector(entry=x, detector_type=detector_type),
                             DetectorId.correction_y: single_entry_with_detector(entry=y, detector_type=detector_type),
                             DetectorId.correction_z: single_entry_with_detector(entry=z, detector_type=detector_type),
                             DetectorId.correction_rotation:
                                 single_entry_with_detector(entry=rotation, detector_type=detector_type),
                             DetectorId.correction_radius:
                                 single_entry_with_detector(entry=radius, detector_type=detector_type),
                             DetectorId.correction_translation:
                                 single_entry_with_detector(entry=side, detector_type=detector_type),
                             DetectorId.correction_x_tilt:
                                 single_entry_with_detector(entry=x_tilt, detector_type=detector_type),
                             DetectorId.correction_y_tilt:
                                 single_entry_with_detector(entry=y_tilt, detector_type=detector_type),
                             }
        self.add_to_processed_state_settings(new_state_entries)

    def _process_save(self, command):
        save_algorithms = command.values[0]
        save_as_zero_error_free = command.values[1]
        new_state_entries = {OtherId.save_types: save_algorithms,
                             OtherId.save_as_zero_error_free: save_as_zero_error_free}
        self.add_to_processed_state_settings(new_state_entries,  treat_list_as_element=True)

    def _process_user_specified_output_name(self, command):
        user_specified_output_name = command.values[0]
        new_state_entry = {OtherId.user_specified_output_name: user_specified_output_name}
        self.add_to_processed_state_settings(new_state_entry)

    def _process_user_specified_output_name_suffix(self, command):
        user_specified_output_name_suffix = command.values[0]
        new_state_entry = {OtherId.user_specified_output_name_suffix: user_specified_output_name_suffix}
        self.add_to_processed_state_settings(new_state_entry)

    def _process_use_reduction_mode_as_suffix(self, command):
        use_reduction_mode_as_suffix = command.values[0]
        new_state_entry = {OtherId.use_reduction_mode_as_suffix: use_reduction_mode_as_suffix}
        self.add_to_processed_state_settings(new_state_entry)

    def remove_last_user_file(self):
        """
        Removes the last added user file from the commands.

        See _remove_last_element for further explanation.
        """
        self._remove_last_element(NParameterCommandId.user_file)

    def remove_last_scatter_sample(self):
        """
        Removes the last added scatter sample from the commands.

        See _remove_last_element for further explanation.
        """
        self._remove_last_element(DataCommandId.sample_scatter)

    def remove_last_sample_transmission_and_direct(self):
        """
        Removes the last added scatter transmission and direct from the commands.

        See _remove_last_element for further explanation.
        """
        self._remove_last_element(DataCommandId.sample_transmission)
        self._remove_last_element(DataCommandId.sample_direct)

    def remove_last_scatter_can(self):
        """
        Removes the last added scatter can from the commands.

        See _remove_last_element for further explanation.
        """
        self._remove_last_element(DataCommandId.can_scatter)

    def remove_last_can_transmission_and_direct(self):
        """
        Removes the last added can transmission and direct from the commands.

        See _remove_last_element for further explanation.
        """
        self._remove_last_element(DataCommandId.can_transmission)
        self._remove_last_element(DataCommandId.can_direct)

    def _remove_last_element(self, command_id):
        """
        Removes the last instance of a command associated with the command_id.

        This method is vital for batch reduction.
        TODO: more explanation
        @param command_id: the command_id of the command which whose last instance we want to remove
        """
        index_to_remove = None
        for index, element in reversed(list(enumerate(self._commands))):
            if element.command_id == command_id:
                index_to_remove = index
                break
        if index_to_remove is not None:
            del(self._commands[index_to_remove])
        else:
            raise RuntimeError("Tried to delete the last instance of {0}, but none was present in the list of "
                               "commands".format(command_id))
Esempio n. 31
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_builder.set_calibration("TUBE_SANS2D_BOTH_31681_25Sept15.nxs")
        data_state = data_builder.build()

        ################################################################################################################
        # Compatibility mode
        ################################################################################################################
        # Get the rest of the state from the user file
        user_file_director = StateDirectorISIS(data_state, file_information)
        user_file_director.set_user_file(
            "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt")

        user_file_director.set_compatibility_builder_use_compatibility_mode(
            True)

        # Construct the final state
        state = user_file_director.construct()

        # 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(
            "OutputWorkspace").value

        ################################################################################################################
        # Non-compatibility mode
        ################################################################################################################
        user_file_director = StateDirectorISIS(data_state, file_information)
        user_file_director.set_user_file(
            "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt")

        user_file_director.set_compatibility_builder_use_compatibility_mode(
            False)

        # Construct the final state
        state = user_file_director.construct()

        # 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(
            "OutputWorkspace").value

        ################################################################################################################
        # Compare workspaces
        ################################################################################################################
        compare_name = "CompareWorkspaces"
        compare_options = {
            "Workspace1": non_compatibility_output_workspace,
            "Workspace2": compatibility_output_workspace,
            "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. 32
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_file_director = StateDirectorISIS(data_info, file_information)
        user_file_director.set_user_file("MASKSANS2Doptions.091A")
        # Set the reduction mode to LAB
        user_file_director.set_reduction_builder_reduction_mode(
            ISISReductionMode.LAB)

        user_file_director.set_slice_event_builder_start_time([1.0, 3.0])
        user_file_director.set_slice_event_builder_end_time([3.0, 5.0])

        state = user_file_director.construct()

        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 = [
            "5512p1rear_1D_1.0_2.0Phi-45.0_45.0_t1.00_T3.00",
            "5512p1rear_1D_1.0_2.0Phi-45.0_45.0_t3.00_T5.00",
            "5512p1rear_1D_1.0_3.0Phi-45.0_45.0_t1.00_T3.00",
            "5512p1rear_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. 33
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_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_file_director = StateDirectorISIS(data_info, file_information)
        user_file_director.set_user_file(
            "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt")
        # Set the reduction mode to LAB
        user_file_director.set_reduction_builder_reduction_mode(
            ISISReductionMode.LAB)
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY BEGIN -- Remove when appropriate
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # 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
        user_file_director.set_compatibility_builder_use_compatibility_mode(
            True)
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # COMPATIBILITY END
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

        state = user_file_director.construct()
        start = [1.0, 2.0]
        end = [2.0, 3.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)

        expected_workspaces = ["34484rear_1D_1.0_2.0", "34484rear_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)