Exemplo n.º 1
0
 def _create_states(self, state_model, table_model, row_index=None):
     """
     Here we create the states based on the settings in the models
     :param state_model: the state model object
     :param table_model: the table model object
     :param row_index: the selected row, if None then all rows are generated
     """
     number_of_rows = self._view.get_number_of_rows()
     if row_index is not None:
         # Check if the selected index is valid
         if row_index >= number_of_rows:
             return None
         rows = [row_index]
     else:
         rows = range(number_of_rows)
     states = {}
     gui_state_director = GuiStateDirector(table_model, state_model,
                                           self._facility)
     for row in rows:
         self.sans_logger.information(
             "Generating state for row {}".format(row))
         if not self.is_empty_row(row):
             try:
                 state = gui_state_director.create_state(row)
                 states.update({row: state})
             except ValueError as e:
                 self.sans_logger.error(
                     "There was a bad entry for row {}. Ensure that the path to your files has "
                     "been added to the Mantid search directories! See here for more "
                     "details: {}".format(row, str(e)))
                 raise RuntimeError(
                     "There was a bad entry for row {}. Ensure that the path to your files has "
                     "been added to the Mantid search directories! See here for more "
                     "details: {}".format(row, str(e)))
     return states
Exemplo n.º 2
0
def _create_row_state(row_entry, state_model, facility, file_lookup,
                      gui_state_director, user_file):
    sans_logger.information("Generating state for row {}".format(row_entry))
    state = None

    try:
        if not row_entry.file_information and file_lookup:
            error_message = "Trying to find the SANS file {0}, but cannot find it. Make sure that " \
                            "the relevant paths are added and the correct instrument is selected."
            raise RuntimeError(error_message.format(row_entry.sample_scatter))

        if not row_entry.is_empty():
            row_user_file = row_entry.user_file
            if row_user_file:
                row_state_model = create_gui_state_from_userfile(
                    row_user_file, state_model)
                row_gui_state_director = GuiStateDirector(
                    row_state_model, facility)
                state = row_gui_state_director.create_state(
                    row_entry,
                    file_lookup=file_lookup,
                    user_file=row_user_file)
            else:
                state = gui_state_director.create_state(
                    row_entry, file_lookup=file_lookup, user_file=user_file)
        return state
    except (ValueError, RuntimeError) as e:
        return "{}".format(str(e))
Exemplo n.º 3
0
def create_state(state_model_with_view_update, file, period, facility):
    table_row = RowEntries(sample_scatter=file, sample_scatter_period=period)
    gui_state_director = GuiStateDirector(state_model_with_view_update, facility)

    state = gui_state_director.create_state(table_row).all_states

    return state
    def test_that_sample_thickness_set_on_state(self):
        table_model = self._get_table_model()
        state_model = self._get_state_gui_model()
        director = GuiStateDirector(table_model, state_model, SANSFacility.ISIS)

        state = director.create_state(0)
        self.assertTrue(isinstance(state, State))

        self.assertEqual(state.scale.thickness, 1.0)
    def test_that_shift_and_scale_set_on_state_from_options_column(self):
        table_model = self._get_table_model(option_string="MergeScale=1.2,MergeShift=0.5")
        state_model = self._get_state_gui_model()
        director = GuiStateDirector(table_model, state_model, SANSFacility.ISIS)

        state = director.create_state(0)
        self.assertTrue(isinstance(state, State))
        self.assertEqual(state.reduction.merge_scale, 1.2)
        self.assertEqual(state.reduction.merge_shift, 0.5)
    def test_that_column_options_are_set_on_state(self):
        table_model = self._get_table_model(option_string="WavelengthMin=3.14,WavelengthMax=10.3")
        state_model = self._get_state_gui_model()
        director = GuiStateDirector(table_model, state_model, SANSFacility.ISIS)

        state = director.create_state(0)
        self.assertTrue(isinstance(state, State))
        self.assertTrue(state.wavelength.wavelength_low == [3.14])
        self.assertTrue(state.wavelength.wavelength_high == [10.3])
Exemplo n.º 7
0
    def test_that_column_options_are_set_on_state(self):
        table_model = self._get_table_model(option_string="WavelengthMin=3.14,WavelengthMax=10.3")
        state_model = self._get_state_gui_model()
        director = GuiStateDirector(table_model, state_model, SANSFacility.ISIS)

        state = director.create_state(0)
        self.assertTrue(isinstance(state, State))
        self.assertTrue(state.wavelength.wavelength_low == [3.14])
        self.assertTrue(state.wavelength.wavelength_high == [10.3])
Exemplo n.º 8
0
    def test_that_sample_thickness_set_on_state(self):
        table_model = self._get_table_model(sample_thickness = 78.0)
        state_model = self._get_state_gui_model()
        director = GuiStateDirector(table_model, state_model, SANSFacility.ISIS)

        state = director.create_state(0)
        self.assertTrue(isinstance(state, State))

        self.assertEqual(state.scale.thickness, 78.0)
Exemplo n.º 9
0
    def test_that_shift_and_scale_set_on_state_from_options_column(self):
        state_model = self._get_state_gui_model()
        director = GuiStateDirector(state_model, SANSFacility.ISIS)

        state = self._get_row_entry(
            option_string="MergeScale=1.2,MergeShift=0.5")
        state = director.create_state(state)
        self.assertTrue(isinstance(state, StateGuiModel))
        self.assertEqual(state.all_states.reduction.merge_scale, 1.2)
        self.assertEqual(state.all_states.reduction.merge_shift, 0.5)
Exemplo n.º 10
0
    def test_that_column_options_are_set_on_state(self):
        state_model = self._get_state_gui_model()
        director = GuiStateDirector(state_model, SANSFacility.ISIS)

        row_entry = self._get_row_entry(
            option_string="WavelengthMin=3.14,WavelengthMax=10.3")
        state = director.create_state(row_entry)
        self.assertTrue(isinstance(state, AllStates))
        self.assertEqual(state.wavelength.wavelength_low, [3.14])
        self.assertEqual(state.wavelength.wavelength_high, [10.3])
Exemplo n.º 11
0
def create_state(state_model_with_view_update, file, period, facility):
    table_row = TableIndexModel(file, period, '', '', '', '', '', '', '', '', '', '')
    table = TableModel()
    table.add_table_entry_no_thread_or_signal(0, table_row)

    gui_state_director = GuiStateDirector(table, state_model_with_view_update, facility)

    state = gui_state_director.create_state(0)

    return state
Exemplo n.º 12
0
def create_state(state_model_with_view_update, file, period, facility):
    table_row = TableIndexModel(file, period, '', '', '', '', '', '', '', '', '', '')
    table = TableModel()
    table.add_table_entry_no_thread_or_signal(0, table_row)

    gui_state_director = GuiStateDirector(table, state_model_with_view_update, facility)

    state = gui_state_director.create_state(0)

    return state
Exemplo n.º 13
0
    def test_that_column_options_are_set_on_state(self):
        state_model = self._get_state_gui_model()
        director = GuiStateDirector(state_model, SANSFacility.ISIS)

        row_entry = self._get_row_entry(
            option_string="WavelengthMin=3.14,WavelengthMax=10.3")
        state = director.create_state(row_entry)
        self.assertTrue(isinstance(state, StateGuiModel))
        self.assertEqual(
            state.all_states.wavelength.wavelength_interval.
            wavelength_full_range, (3.14, 10.3))
Exemplo n.º 14
0
    def test_state_created_with_default_sample_thickness_when_file_lookup_disabled(self):
        table_model = self._get_table_model()
        state_model = self._get_state_gui_model()
        director = GuiStateDirector(table_model, state_model, SANSFacility.ISIS)

        state = director.create_state(0, file_lookup=False)
        self.assertTrue(isinstance(state, State))

        self.assertEqual(state.scale.thickness_from_file, 1.0)
        self.assertEqual(state.scale.height_from_file, 8.0)
        self.assertEqual(state.scale.width_from_file, 8.0)
        self.assertEqual(state.scale.thickness, 8.0)
Exemplo n.º 15
0
 def test_that_can_construct_state_from_models(self):
     state_model = self._get_state_gui_model()
     director = GuiStateDirector(state_model, SANSFacility.ISIS)
     state = director.create_state(self._get_row_entry())
     self.assertTrue(isinstance(state, AllStates))
     try:
         state.validate()
         has_raised = False
     except ValueError:
         has_raised = True
     self.assertFalse(has_raised)
     self.assertEqual(state.wavelength.wavelength_low, [1.5])
     self.assertEqual(state.wavelength.wavelength_high, [12.5])
Exemplo n.º 16
0
 def test_that_can_construct_state_from_models(self):
     table_model = self._get_table_model()
     state_model = self._get_state_gui_model()
     director = GuiStateDirector(table_model, state_model, SANSFacility.ISIS)
     state = director.create_state(0)
     self.assertTrue(isinstance(state, State))
     try:
         state.validate()
         has_raised = False
     except ValueError:
         has_raised = True
     self.assertFalse(has_raised)
     self.assertTrue(state.wavelength.wavelength_low == [1.5])
     self.assertTrue(state.wavelength.wavelength_high == [12.5])
Exemplo n.º 17
0
 def test_that_can_construct_state_from_models(self):
     table_model = self._get_table_model()
     state_model = self._get_state_gui_model()
     director = GuiStateDirector(table_model, state_model, SANSFacility.ISIS)
     state = director.create_state(0)
     self.assertTrue(isinstance(state, State))
     try:
         state.validate()
         has_raised = False
     except ValueError:
         has_raised = True
     self.assertFalse(has_raised)
     self.assertTrue(state.wavelength.wavelength_low == [1.5])
     self.assertTrue(state.wavelength.wavelength_high == [12.5])
Exemplo n.º 18
0
 def test_that_can_construct_state_from_models(self):
     state_model = self._get_state_gui_model()
     director = GuiStateDirector(state_model, SANSFacility.ISIS)
     state = director.create_state(self._get_row_entry())
     self.assertTrue(isinstance(state, StateGuiModel))
     state = state.all_states
     try:
         state.validate()
         has_raised = False
     except ValueError:
         has_raised = True
     self.assertFalse(has_raised)
     self.assertEqual(
         state.wavelength.wavelength_interval.wavelength_full_range,
         (1.5, 12.5))
Exemplo n.º 19
0
    def test_save_settings_copied_from_gui(self):
        state_model = mock.Mock(spec=self._get_state_gui_model())
        state_model.all_states.save = mock.NonCallableMock()

        # Copy the top level model and reset save rather than load a file
        copied_state = copy.deepcopy(state_model)
        copied_state.all_states.save = None

        director = GuiStateDirector(state_model, SANSFacility.ISIS)
        director._load_current_state = mock.Mock(return_value=copied_state)
        new_state = director.create_state(self._get_row_entry(),
                                          row_user_file="NotThere.txt")

        self.assertEqual(state_model.all_states.save,
                         new_state.all_states.save)
Exemplo n.º 20
0
    def test_reduction_dim_copied_from_gui(self):
        state_model = mock.Mock(spec=self._get_state_gui_model())
        expected_dim = mock.NonCallableMock()
        # This is set by the user on the main GUI, so should be copied in with a custom user file still
        state_model.reduction_dimensionality = expected_dim

        # Copy the top level model and reset dim rather than load a file
        copied_state = copy.deepcopy(state_model)
        copied_state.reduction_dimensionality = None

        director = GuiStateDirector(state_model, SANSFacility.ISIS)
        director._load_current_state = mock.Mock(return_value=copied_state)
        state = director.create_state(self._get_row_entry(),
                                      row_user_file="NotThere.txt")

        self.assertEqual(expected_dim, state.reduction_dimensionality)
Exemplo n.º 21
0
def _create_row_state(row, table_model, state_model, facility, instrument,
                      file_lookup, gui_state_director):
    try:
        sans_logger.information("Generating state for row {}".format(row))
        state = None
        if not __is_empty_row(row, table_model):
            row_user_file = table_model.get_row_user_file(row)
            if row_user_file:
                row_state_model = create_gui_state_from_userfile(
                    row_user_file, state_model)
                row_gui_state_director = GuiStateDirector(
                    table_model, row_state_model, facility)
                state = row_gui_state_director.create_state(
                    row, instrument=instrument, file_lookup=file_lookup)
            else:
                state = gui_state_director.create_state(
                    row, instrument=instrument, file_lookup=file_lookup)
        return state
    except (ValueError, RuntimeError) as e:
        return "{}".format(str(e))
Exemplo n.º 22
0
 def test_that_will_raise_when_models_are_incomplete(self):
     state_model = self._get_state_gui_model()
     director = GuiStateDirector(state_model, SANSFacility.ISIS)
     with self.assertRaises(ValueError):
         director.create_state(RowEntries())