Exemple #1
0
    def _match_IDF(self, run):
        '''
        Compares the IDF in the stored instrument with the IDF in the workspace.
        If they are the same all is well. If they diff, then load the adequate
        user file.
        @param run: name of the run for which the file is to be extracted
        '''
        # We need the instrument name and the measurement time to determine
        # the IDF
        measurement_time = None
        instrument_name = self.get_instrument_name()
        # We need to be able to handle file-based and workspace-based queries
        # If we have a workspace we look at the end time, else we
        # need a sophisticated extraction mechanism
        if isinstance(run, Workspace):
            ws = None
            if isinstance(run, WorkspaceGroup):
                # Just look at the first element in a workspace group
                ws = run[0]
            else:
                ws = run
            measurement_time = str(ws.getRun().endTime()).strip()
        else:
            if run is None or run == "":
                return
            measurement_time = su.get_measurement_time_from_file(run)

        # Get the path to the instrument definition file
        idf_path_workspace = ExperimentInfo.getInstrumentFilename(instrument_name, measurement_time)
        idf_path_workspace = os.path.normpath(idf_path_workspace)

        # Get the idf from the reducer
        idf_path_reducer = self.get_idf_file_path()
        idf_path_reducer = os.path.normpath(idf_path_reducer)

        # Now check if both idf paths and underlying files. If they are, then don't do anything
        # else switch the underlying instrument
        if idf_path_reducer == idf_path_workspace and su.are_two_files_identical(idf_path_reducer, idf_path_reducer):
            return
        else:
            logger.notice("Updating the IDF of the Reducer. Switching from " +
                          str(idf_path_reducer) + " to " + str(idf_path_workspace))
            idf_path = os.path.basename(idf_path_workspace)
            instrument = self._get_correct_instrument(instrument_name, idf_path)

            # Get detector of the old instrument
            old_instrument = self.get_instrument()
            old_detector_selection = old_instrument.get_detector_selection()

            if instrument is not None:
                self.set_instrument(instrument)

                # We need to update the instrument, by reloading the user file.
                # This is pretty bad, but looking at the reducer architecture this
                # seems to be the only reasonable way to do this.
                self.user_settings.execute(self)

                # Now we set the correct detector, this is also being done in the GUI
                self.get_instrument().setDetector(old_detector_selection)
Exemple #2
0
 def _do_test(self, file_name, expected_time):
     exists, full_path =  get_full_path_SANS_system_test(file_name)
     if exists:
         measurement_time = su.get_measurement_time_from_file(full_path)
         self.assertEqual(measurement_time, expected_time)
     else:
         print("Missing data files. Path to system test data needs to be set.")
         self.assertTrue(False)
Exemple #3
0
 def _get_idf_path_for_workspace(self, filename, instrument_name):
     exists, full_path =  get_full_path_SANS_system_test(filename)
     idf_path_workspace = None
     if exists:
         measurement_time = su.get_measurement_time_from_file(full_path)
         idf_path_workspace = ExperimentInfo.getInstrumentFilename(instrument_name, measurement_time)
     else:
         print("Missing data files. Path to system test data needs to be set.")
         self.assertTrue(False)
     return idf_path_workspace
Exemple #4
0
    def _match_IDF(self, run):
        '''
        Compares the IDF in the stored instrument with the IDF in the workspace.
        If they are the same all is well. If they diff, then load the adequate
        user file.
        @param run: name of the run for which the file is to be extracted
        '''
        # We need the instrument name and the measurement time to determine
        # the IDF
        measurement_time = None
        instrument_name = self.get_instrument_name()
        # We need to be able to handle file-based and workspace-based queries
        # If we have a workspace we look at the end time, else we
        # need a sophisticated extraction mechanism
        if isinstance(run, Workspace):
            ws = None
            if isinstance(run, WorkspaceGroup):
                # Just look at the first element in a workspace group
                ws = run[0]
            else:
                ws = run
            measurement_time = str(ws.getRun().endTime()).strip()
        else:
            if run is None or run == "":
                return
            measurement_time = su.get_measurement_time_from_file(run)

        # Get the path to the instrument definition file
        idf_path_workspace = ExperimentInfo.getInstrumentFilename(
            instrument_name, measurement_time)
        idf_path_workspace = os.path.normpath(idf_path_workspace)

        # Get the idf from the reducer
        idf_path_reducer = self.get_idf_file_path()
        idf_path_reducer = os.path.normpath(idf_path_reducer)

        # Now check if both idf paths and underlying files. If they are, then don't do anything
        # else switch the underlying instrument
        if idf_path_reducer == idf_path_workspace and su.are_two_files_identical(
                idf_path_reducer, idf_path_reducer):
            return
        else:
            logger.notice("Updating the IDF of the Reducer. Switching from " +
                          str(idf_path_reducer) + " to " +
                          str(idf_path_workspace))
            idf_path = os.path.basename(idf_path_workspace)
            instrument = self._get_correct_instrument(instrument_name,
                                                      idf_path)

            # Get detector of the old instrument
            old_instrument = self.get_instrument()
            old_detector_selection = old_instrument.get_detector_selection()

            if instrument is not None:
                self.set_instrument(instrument)

                # We need to update the instrument, by reloading the user file.
                # This is pretty bad, but looking at the reducer architecture this
                # seems to be the only reasonable way to do this.
                self.user_settings.execute(self)

                # Now we set the correct detector, this is also being done in the GUI
                self.get_instrument().setDetector(old_detector_selection)