def test_that_can_extract_information_from_file_for_SANS2D_single_period_and_ISISNexus(
            self):
        # Arrange
        # The file is a single period
        file_name = "SANS2D00022024"
        factory = SANSFileInformationFactory()

        # Act
        file_information = factory.create_sans_file_information(file_name)

        # Assert
        self.assertTrue(file_information.get_number_of_periods() == 1)
        self.assertTrue(
            file_information.get_date() == DateAndTime("2013-10-25T14:21:19"))
        self.assertTrue(
            file_information.get_instrument() == SANSInstrument.SANS2D)
        self.assertTrue(file_information.get_type() == FileType.ISISNexus)
        self.assertTrue(file_information.get_run_number() == 22024)
        self.assertFalse(file_information.is_event_mode())
        self.assertFalse(file_information.is_added_data())
        self.assertTrue(file_information.get_width() == 8.0)
        self.assertTrue(file_information.get_height() == 8.0)
        self.assertTrue(file_information.get_thickness() == 1.0)
        self.assertTrue(
            file_information.get_shape() is SampleShape.CylinderAxisAlong)
예제 #2
0
    def test_that_produces_correct_workspace_multiperiod_LARMOR(self):
        # Arrange
        # Build the data information
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            "LARMOR00013065")
        data_builder = get_data_builder(SANSFacility.ISIS, file_information)
        data_builder.set_sample_scatter("LARMOR00013065")

        data_state = data_builder.build()

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

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

        # Evaluate it up to a defined point
        reference_file_name = "LARMOR_ws_diagnostic_reference.nxs"
        self._compare_workspace(output_workspaces[0], reference_file_name)
    def _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()
예제 #4
0
    def test_that_angle_masking_is_applied(self):
        # Arrange
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            "SANS2D00028827")
        data_builder = get_data_builder(SANSFacility.ISIS, file_information)
        data_builder.set_sample_scatter("SANS2D00028827")
        data_info = data_builder.build()

        mask_builder = get_mask_builder(data_info)

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

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

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

        mask_info = mask_builder.build()

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

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

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

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

        # Assert
        self._do_assert_non_masked(workspace, expected_spectra)
예제 #5
0
    def test_that_produces_correct_workspace_for_SANS2D(self):
        # Arrange
        # Build the data information
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            "SANS2D00034484")
        data_builder = get_data_builder(SANSFacility.ISIS, file_information)
        data_builder.set_sample_scatter("SANS2D00034484")
        data_state = data_builder.build()

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

        # Act
        output_workspaces = run_integral('', True, IntegralEnum.Horizontal,
                                         DetectorType.LAB, state)
        self.assertEqual(len(output_workspaces), 1)
        # Evaluate it up to a defined point
        reference_file_name = "SANS2D_ws_centred_diagnostic_reference.nxs"
        self._compare_workspace(output_workspaces[0], reference_file_name)
예제 #6
0
def get_file_and_period_information_from_data(data):
    """
    Get the file information and period information from a StateData object

    :param data: a StateData object
    :return: a map of SANSFileInformation objects and map of period information
    """
    file_information_factory = SANSFileInformationFactory()
    file_information = dict()
    period_information = dict()
    if data.sample_scatter:
        update_file_information(file_information, file_information_factory,
                                SANSDataType.SAMPLE_SCATTER, data.sample_scatter)
        period_information.update({SANSDataType.SAMPLE_SCATTER: data.sample_scatter_period})
    if data.sample_transmission:
        update_file_information(file_information, file_information_factory,
                                SANSDataType.SAMPLE_TRANSMISSION, data.sample_transmission)
        period_information.update({SANSDataType.SAMPLE_TRANSMISSION: data.sample_transmission_period})
    if data.sample_direct:
        update_file_information(file_information, file_information_factory,
                                SANSDataType.SAMPLE_DIRECT, data.sample_direct)
        period_information.update({SANSDataType.SAMPLE_DIRECT: data.sample_direct_period})
    if data.can_scatter:
        update_file_information(file_information, file_information_factory,
                                SANSDataType.CAN_SCATTER, data.can_scatter)
        period_information.update({SANSDataType.CAN_SCATTER: data.can_scatter_period})
    if data.can_transmission:
        update_file_information(file_information, file_information_factory,
                                SANSDataType.CAN_TRANSMISSION, data.can_transmission)
        period_information.update({SANSDataType.CAN_TRANSMISSION: data.can_transmission_period})
    if data.can_direct:
        update_file_information(file_information, file_information_factory,
                                SANSDataType.CAN_DIRECT, data.can_direct)
        period_information.update({SANSDataType.CAN_DIRECT: data.can_direct_period})
    return file_information, period_information
예제 #7
0
    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)

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

        user_commands = CommandInterfaceAdapter(
            data_info=data_state,
            processed_state=self._processed_state_settings)
        run_data_parser = StateRunDataBuilder(
            file_information=file_information)

        self._state_director = StateBuilder(i_state_parser=user_commands,
                                            run_data_builder=run_data_parser)
        return self._state_director.get_all_states()
예제 #8
0
    def _get_simple_state(sample_scatter,
                          lab_x_translation_correction=None,
                          lab_z_translation_correction=None):
        # Set the data
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            sample_scatter)
        data_builder = get_data_builder(SANSFacility.ISIS, file_information)
        data_builder.set_sample_scatter(sample_scatter)
        data_info = data_builder.build()

        # Set the move parameters
        builder = get_move_builder(data_info)
        if lab_x_translation_correction is not None:
            builder.set_LAB_x_translation_correction(
                lab_x_translation_correction)
        if lab_z_translation_correction is not None:
            builder.set_LAB_z_translation_correction(
                lab_z_translation_correction)
        move_info = builder.build()

        # Get the sample state
        test_director = TestDirector()
        test_director.set_states(data_state=data_info, move_state=move_info)
        return test_director.construct()
예제 #9
0
    def test_that_can_extract_information_for_LARMOR_added_event_data_and_multi_period_and_nexus_format(
            self):
        # Arrange
        # The file is a single period, histogram-based and added
        file_name = "AddedEvent-add"
        factory = SANSFileInformationFactory()

        # Act
        file_information = factory.create_sans_file_information(file_name)

        # Assert
        self.assertEqual(file_information.get_number_of_periods(), 4)
        self.assertEqual(file_information.get_date(),
                         DateAndTime("2016-10-12T04:33:47"))
        self.assertEqual(file_information.get_instrument(),
                         SANSInstrument.LARMOR)
        self.assertEqual(file_information.get_type(),
                         FileType.ISIS_NEXUS_ADDED)
        self.assertEqual(file_information.get_run_number(), 13065)
        self.assertTrue(file_information.is_event_mode())
        self.assertTrue(file_information.is_added_data())
        self.assertEqual(file_information.get_width(), 6.0)
        self.assertEqual(file_information.get_height(), 8.0)
        self.assertEqual(file_information.get_thickness(), 1.0)
        self.assertEqual(file_information.get_shape(), SampleShape.FLAT_PLATE)
예제 #10
0
    def test_add_file_without_add_extension_is_found(self):
        file_name = "ZOOM9947-a"
        factory = SANSFileInformationFactory()
        file_information = factory.create_sans_file_information(file_name)

        self.assertIsInstance(file_information, SANSFileInformationISISAdded)
        self.assertTrue(file_information.is_event_mode())
예제 #11
0
    def test_event_data_not_added_is_detected(self):
        file_name = "ZOOM9898"
        factory = SANSFileInformationFactory()
        file_information = factory.create_sans_file_information(file_name)

        self.assertIsInstance(file_information, SANSFileInformationISISNexus)
        self.assertTrue(file_information.is_event_mode())
예제 #12
0
 def _init_run_selector_presenter(run_selector_view, on_selection_change,
                                  parent_view):
     title = 'Runs To Sum'
     run_finder = SummableRunFinder(SANSFileInformationFactory())
     run_selection = RunSelectionModel(on_selection_change)
     return RunSelectorPresenter(title, run_selection, run_finder,
                                 run_selector_view, parent_view)
    def test_that_cylinder_masking_is_applied(self):
        # Arrange
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            "SANS2D00028827")
        data_builder = get_data_builder(SANSFacility.ISIS, file_information)
        data_builder.set_sample_scatter("SANS2D00028827")
        data_info = data_builder.build()
        mask_builder = get_mask_builder(data_info)

        # Radius Mask
        radius_min = 0.01
        radius_max = 10.

        expected_spectra = []
        expected_spectra.extend([
            30469, 30470, 30471, 30472, 30473, 30474, 30475, 30476, 30477,
            30980, 30981, 30982, 30983, 30984, 30985, 30986, 30987, 30988
        ])
        mask_builder.set_radius_min(radius_min)
        mask_builder.set_radius_max(radius_max)

        mask_info = mask_builder.build()

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

        workspace = self._load_workspace(state, move_workspace=False)

        # Act
        workspace = self._run_mask(state, workspace, "LAB")

        # Assert
        self._do_assert(workspace, expected_spectra)
예제 #14
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)
예제 #15
0
    def _setup_instrument_specific_settings(self):
        # Get the first run number of the scatter data for the first table
        sample_scatter = self._view.get_cell(row=0, column=0, convert_to=str)

        # Check if it exists at all
        if not sample_scatter:
            return

        # Get the file information from
        file_information_factory = SANSFileInformationFactory()
        try:
            self._file_information = file_information_factory.create_sans_file_information(
                sample_scatter)
        except NotImplementedError:
            self.sans_logger.warning(
                "Could not get file information from {}.".format(
                    sample_scatter))
            self._file_information = None

        # Provide the instrument specific settings
        if self._file_information:
            # Set the instrument on the table
            instrument = self._file_information.get_instrument()
            self._view.set_instrument_settings(instrument)

            # Set the reduction mode
            reduction_mode_list = get_reduction_mode_strings_for_gui(
                instrument=instrument)
            self._view.set_reduction_modes(reduction_mode_list)
        else:
            self._view.set_instrument_settings(SANSInstrument.NoInstrument)
            reduction_mode_list = get_reduction_mode_strings_for_gui()
            self._view.set_reduction_modes(reduction_mode_list)
예제 #16
0
    def test_that_can_extract_information_for_added_histogram_data_and_nexus_format(
            self):
        # Arrange
        # The file is a single period, histogram-based and added
        file_name = "AddedHistogram-add"
        factory = SANSFileInformationFactory()

        # Act
        file_information = factory.create_sans_file_information(file_name)

        # Assert
        self.assertEqual(file_information.get_number_of_periods(), 1)
        self.assertEqual(file_information.get_date(),
                         DateAndTime("2013-10-25T14:21:19"))
        self.assertEqual(file_information.get_instrument(),
                         SANSInstrument.SANS2D)
        self.assertEqual(file_information.get_type(),
                         FileType.ISIS_NEXUS_ADDED)
        self.assertEqual(file_information.get_run_number(), 22024)
        self.assertFalse(file_information.is_event_mode())
        self.assertTrue(file_information.is_added_data())
        self.assertEqual(file_information.get_width(), 8.0)
        self.assertEqual(file_information.get_height(), 8.0)
        self.assertEqual(file_information.get_thickness(), 1.0)
        self.assertEqual(file_information.get_shape(), SampleShape.DISC)
예제 #17
0
    def _get_data_state(self):
        # Get the data commands
        data_commands = self._get_data_commands()
        data_elements = self._get_elements_with_key(
            DataCommandId.SAMPLE_SCATTER, data_commands)
        data_element = data_elements[-1]
        file_name = data_element.file_name
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            file_name)

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

        return data_builder.build()
예제 #18
0
    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)
예제 #19
0
    def test_batch_reduction_on_period_time_sliced_wavelength_range_data(self):
        # Arrange
        # Build the data information
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            "SANS2D0005512")

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

        data_info = data_builder.build()

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

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

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

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

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

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

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

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

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

        # Clean up
        for element in expected_workspaces:
            AnalysisDataService.remove(element)
예제 #20
0
    def test_that_single_reduction_evaluates_LAB_for_2D_reduction(self):
        # Arrange
        # Build the data information
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            "SANS2D00034484")
        data_builder = get_data_builder(SANSFacility.ISIS, file_information)
        data_builder.set_sample_scatter("SANS2D00034484")
        data_builder.set_sample_transmission("SANS2D00034505")
        data_builder.set_sample_direct("SANS2D00034461")
        data_builder.set_can_scatter("SANS2D00034481")
        data_builder.set_can_transmission("SANS2D00034502")
        data_builder.set_can_direct("SANS2D00034461")

        data_info = data_builder.build()

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

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

        state.compatibility.use_compatibility_mode = True

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

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

        # Compare the output of the reduction with the reference
        reference_file_name = "SANS2D_ws_D20_reference_LAB_2D.nxs"
        self._compare_to_reference(
            output_workspace,
            reference_file_name,
            mismatch_name=MantidSystemTest.mismatchWorkspaceName(
                reference_file_name))
예제 #21
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 _build_data_info():
        ws_name = "SANS2D00028827"

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        # Add the calibration
        if calibration is not None:
            data_builder.set_calibration(calibration)

        data_info = data_builder.build()

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

        return test_director.construct()
예제 #25
0
def set_geometry_from_file(state, date_info):
    sample_scatter = date_info.sample_scatter
    file_information_factory = SANSFileInformationFactory()
    file_information = file_information_factory.create_sans_file_information(sample_scatter)

    # Get the geometry
    state.height_from_file = file_information.get_height()
    state.width_from_file = file_information.get_width()
    state.thickness_from_file = file_information.get_thickness()
    state.shape_from_file = file_information.get_shape()
예제 #26
0
    def test_batch_reduction_on_time_sliced_file(self):
        # Arrange
        # Build the data information
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            "SANS2D00034484")

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

        data_builder.set_calibration("TUBE_SANS2D_BOTH_31681_25Sept15.nxs")

        data_info = data_builder.build()

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

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

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

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

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

        # Clean up
        for element in expected_workspaces:
            AnalysisDataService.remove(element)
예제 #27
0
    def test_that_can_find_data_with_numbers_but_no_instrument(self):
        # Arrange
        # The file is a single period, histogram-based and added

        file_name = "74044-add"
        factory = SANSFileInformationFactory()

        # Act
        file_information = factory.create_sans_file_information(file_name)

        # Assert
        self.assertTrue(file_information)
예제 #28
0
    def add_table_entry_no_thread_or_signal(self, row, table_index_model):
        table_index_model.id = self._id_count
        self._id_count += 1
        self._table_entries.insert(row, table_index_model)
        if row >= self.get_number_of_rows():
            row = self.get_number_of_rows() - 1

        entry = self._table_entries[row]
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            entry.sample_scatter)
        self.update_thickness_from_file_information(entry.id, file_information)
예제 #29
0
    def _add_row_to_table_model(self, row, index):
        """
        Adds a row to the table
        """
        def get_string_entry(_tag, _row):
            _element = ""
            if _tag in _row:
                _element = _row[_tag]
            return _element

        def get_string_period(_tag):
            return "" if _tag == ALL_PERIODS else str(_tag)

        # 1. Pull out the entries
        sample_scatter = get_string_entry(BatchReductionEntry.SampleScatter,
                                          row)
        sample_scatter_period = get_string_period(
            get_string_entry(BatchReductionEntry.SampleScatterPeriod, row))
        sample_transmission = get_string_entry(
            BatchReductionEntry.SampleTransmission, row)
        sample_transmission_period = \
            get_string_period(get_string_entry(BatchReductionEntry.SampleTransmissionPeriod, row))
        sample_direct = get_string_entry(BatchReductionEntry.SampleDirect, row)
        sample_direct_period = get_string_period(
            get_string_entry(BatchReductionEntry.SampleDirectPeriod, row))
        can_scatter = get_string_entry(BatchReductionEntry.CanScatter, row)
        can_scatter_period = get_string_period(
            get_string_entry(BatchReductionEntry.CanScatterPeriod, row))
        can_transmission = get_string_entry(
            BatchReductionEntry.CanTransmission, row)
        can_transmission_period = get_string_period(
            get_string_entry(BatchReductionEntry.CanScatterPeriod, row))
        can_direct = get_string_entry(BatchReductionEntry.CanDirect, row)
        can_direct_period = get_string_period(
            get_string_entry(BatchReductionEntry.CanDirectPeriod, row))
        output_name = get_string_entry(BatchReductionEntry.Output, row)
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            sample_scatter)
        sample_thickness = file_information._thickness
        user_file = get_string_entry(BatchReductionEntry.UserFile, row)

        row_entry = [
            sample_scatter, sample_scatter_period, sample_transmission,
            sample_transmission_period, sample_direct, sample_direct_period,
            can_scatter, can_scatter_period, can_transmission,
            can_transmission_period, can_direct, can_direct_period,
            output_name, user_file, sample_thickness, ''
        ]

        table_index_model = TableIndexModel(*row_entry)

        self._table_model.add_table_entry(index, table_index_model)
예제 #30
0
    def test_two_file_informations_are_eq(self):
        # Arrange
        # The file is a multi period and event-based
        file_name = "LARMOR00003368"
        factory = SANSFileInformationFactory()

        # Act
        file_information = factory.create_sans_file_information(file_name)
        file_information_2 = factory.create_sans_file_information(file_name)

        # Two identical file informations should be equal even if they are different objects
        self.assertEqual(file_information, file_information_2)