예제 #1
0
def find_data(file, instrument='', allow_multiple=False):
    """
        Finds a file path for the specified data set, which can either be:
            - a run number
            - an absolute path
            - a file name
        @param file: file name or part of a file name
        @param instrument: if supplied, FindNeXus will be tried as a last resort
    """
    # First, assume a file name
    file = str(file).strip()

    # If we allow multiple files, users may use ; as a separator,
    # which is incompatible with the FileFinder
    n_files = 1
    if allow_multiple:
        file=file.replace(';',',')
        toks = file.split(',')
        n_files = len(toks)

    instrument = str(instrument)
    file_path = FileFinder.getFullPath(file)
    if os.path.isfile(file_path):
        return file_path

    # Second, assume a run number and pass the instrument name as a hint
    try:
        # FileFinder doesn't like dashes...
        instrument=instrument.replace('-','')
        f = FileFinder.findRuns(instrument+file)
        if os.path.isfile(f[0]):
            if allow_multiple:
                # Mantid returns its own list object type, so make a real list out if it
                if len(f)==n_files:
                    return [i for i in f]
            else:
                return f[0]
    except:
        # FileFinder couldn't make sense of the the supplied information
        pass

    # Third, assume a run number, without instrument name to take care of list of full paths
    try:
        f = FileFinder.findRuns(file)
        if os.path.isfile(f[0]):
            if allow_multiple:
                # Mantid returns its own list object type, so make a real list out if it
                if len(f)==n_files:
                    return [i for i in f]
            else:
                return f[0]
    except:
        # FileFinder couldn't make sense of the the supplied information
        pass

    # If we didn't find anything, raise an exception
    Logger('find_data').error("\n\nCould not find a file for %s: check your reduction parameters\n\n" % str(file))
    raise RuntimeError("Could not find a file for %s" % str(file))
예제 #2
0
 def test_that_find_runs_accepts_a_list_of_string_and_a_bool(self):
     try:
         runs = FileFinder.findRuns("CNCS7860", useExtsOnly=True)
         FileFinder.findRuns("CNCS7860", [".nxs", ".txt"], useExtsOnly=True)
     except Exception as e:
         if type(e).__name__ == "ArgumentError":
             self.assertFalse(True, "Expected findRuns to accept a list of strings and a bool as input."
                                    " {} error was raised with message {}".format(type(e).__name__, str(e)))
     else:
         # Confirm that it works as above
         self.assertTrue(len(runs) == 1)
         self.assertTrue(os.path.exists(runs[0]))
예제 #3
0
def find_sans_file(file_name):
    """
    Finds a SANS file.
    The file can be specified as:
    1. file.ext or  path1 path2 file.ext
    2. run number
    :param file_name: a file name or a run number.
    :return: the full path.
    """
    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."
    try:
        full_path = find_full_file_path(file_name)
        if not full_path and not file_name.endswith('.nxs'):
            full_path = find_full_file_path(file_name + '.nxs')
        if not full_path:
            # TODO: If we only provide a run number for example 98843 for LOQ measurments, but have LARMOR specified as the
            #       Mantid instrument, then the FileFinder will search itself to death. This is a general Mantid issue.
            #       One way to handle this graceful would be a timeout option.
            file_name_as_bytes = str.encode(file_name)
            assert(type(file_name_as_bytes) == bytes)
            runs = FileFinder.findRuns(file_name_as_bytes)
            if runs:
                full_path = runs[0]
    except RuntimeError:
        raise RuntimeError(error_message.format(file_name))

    if not full_path:
        raise RuntimeError(error_message.format(file_name))
    return full_path
    def setUp(self):
        self._qapp = mock_widget.mockQapp()
        # Store an empty widget to parent all the views, and ensure they are deleted correctly
        self.obj = QtGui.QWidget()
        ConfigService['default.instrument'] = 'MUSR'

        setup_context_for_tests(self)
        self.context.instrument = 'MUSR'
        self.load_file_view = BrowseFileWidgetView(self.obj)
        self.load_run_view = LoadRunWidgetView(self.obj)
        self.load_file_model = BrowseFileWidgetModel(self.loaded_data, self.context)
        self.load_run_model = LoadRunWidgetModel(self.loaded_data, self.context)

        self.view = LoadWidgetView(parent=self.obj, load_file_view=self.load_file_view,
                                   load_run_view=self.load_run_view)
        self.presenter = LoadWidgetPresenter(self.view, LoadWidgetModel(self.loaded_data, self.context))
        self.presenter.set_load_file_widget(BrowseFileWidgetPresenter(self.load_file_view, self.load_file_model))
        self.presenter.set_load_run_widget(LoadRunWidgetPresenter(self.load_run_view, self.load_run_model))

        self.presenter.load_file_widget._view.warning_popup = mock.MagicMock()
        self.presenter.load_run_widget._view.warning_popup = mock.MagicMock()

        self.view.multiple_loading_check.setCheckState(1)
        self.presenter.handle_multiple_files_option_changed()

        self.runs = [15196, 15197]
        self.workspaces = [self.create_fake_workspace(1) for _ in self.runs]
        self.filenames = FileFinder.findRuns('MUSR00015196.nxs, MUSR00015197.nxs')
    def getDataFileNames(self, runsetupdict, advsetupdict):
        """ Obtain the data file names (run names + SUFFIX)

        Return: list of files
        """

        runnumbers_str = str(runsetupdict["RunNumber"])
        if runnumbers_str.count(':') > 0:
            runnumbers_str = runnumbers_str.replace(':', '-')
        runnumbers_str = FileFinder.findRuns('{}{}'.format(self.instrument_name, runnumbers_str))
        runnumbers_str = [os.path.split(filename)[-1] for filename in runnumbers_str]

        # create an integer version
        runnumbers = []
        for filename in runnumbers_str:
            for extension in ['_event.nxs', '.nxs.h5']:
                filename = filename.replace(extension, '')
            runnumber = filename.split('_')[-1]
            runnumbers.append(int(runnumber))

        # put together the output
        datafilenames = []
        for (filename, runnumber) in zip(runnumbers_str, runnumbers):
            datafilenames.append((runnumber, filename))

        return datafilenames
예제 #6
0
 def _get_workspace(self, file_name):
     full_file_name = FileFinder.findRuns(file_name)[0]
     load_name = "Load"
     load_options = {"Filename": full_file_name,
                     "OutputWorkspace": EMPTY_NAME}
     load_alg = create_unmanaged_algorithm(load_name, **load_options)
     load_alg.execute()
     return load_alg.getProperty("OutputWorkspace").value
    def test_browse_clicked_suceeds_if_table_in_ADS(self):
        filename = FileFinder.findRuns('MUSR00015196.nxs')[0]
        self.view.show_file_browser_and_return_selection = mock.MagicMock(return_value=[filename])
        self.model.check_dead_time_file_selection = mock.MagicMock(return_value=True)

        self.view.dead_time_browse_button.clicked.emit(True)

        self.assertEqual(self.view.dead_time_selector.currentIndex(), 2)
        self.view.warning_popup.assert_not_called()
        self.assertEqual(self.view.dead_time_file_selector.currentText(), 'MUSR00015196_deadTimes')
        self.gui_variable_observer.update.assert_called_once_with(self.gui_context.gui_variables_notifier, None)
예제 #8
0
    def __verifyRequiredFile(self, filename):
        '''Return True if the specified file name is findable by Mantid.'''
        from mantid.api import FileFinder

        # simple way is just getFullPath which never uses archive search
        if os.path.exists(FileFinder.getFullPath(filename)):
            return True

        # try full findRuns which will use archive search if it is turned on
        try:
            candidates = FileFinder.findRuns(filename)
            for item in candidates:
                if os.path.exists(item):
                    return True
        except RuntimeError, e:
            return False
    def test_runinfo_correct(self):
        file_path = FileFinder.findRuns('MUSR00022725.nxs')[0]
        ws, run, filename = load_utils.load_workspace_from_filename(file_path)
        self.context._loaded_data.remove_data(run=run)
        self.context._loaded_data.add_data(run=run, workspace=ws, filename=filename)
        self.context.update_current_data()
        test_pair = MuonPair('test_pair', 'top', 'bottom', alpha=0.75)
        self.context.add_pair(pair=test_pair)

        self.presenter.update_view_from_model()

        expected_string_list = ['Instrument:MUSR', 'Run:22725', 'Title:FeTeSeT=1F=100', 'Comment:FCfirstsample',
                                'Start:2009-03-24T04:18:58', 'End:2009-03-24T04:56:26', 'Counts(MEv):20.076704',
                                'GoodFrames:88540', 'CountsperGoodFrame:226.753',
                                'CountsperGoodFrameperdet:3.543', 'AverageTemperature(K):2.53386',
                                'SampleTemperature(K):1.0', 'SampleMagneticField(G):100.0']

        self.assertEqual(str(self.view.run_info_box.toPlainText()).replace(' ', '').splitlines(), expected_string_list)
예제 #10
0
def find_sans_file(file_name):
    """
    Finds a SANS file.
    The file can be specified as:
    1. file.ext or  path1 path2 file.ext
    2. run number
    :param file_name: a file name or a run number.
    :return: the full path.
    """
    full_path = find_full_file_path(file_name)
    if not full_path:
        runs = FileFinder.findRuns(file_name)
        if runs:
            full_path = runs[0]
    if not full_path:
        raise RuntimeError("Trying to find the SANS file {0}, but cannot find it. Make sure that "
                           "the relevant paths are added.".format(file_name))
    return full_path
    def setUp(self):
        setup_context_for_tests(self)
        self.frequency_context = FrequencyContext(self.context)
        self.gui_variable_observer = Observer()
        self.gui_variable_observer.update = mock.MagicMock()
        self.gui_context.gui_variables_notifier.add_subscriber(self.gui_variable_observer)
        self.data_context.instrument = 'CHRONUS'
        self.gui_variable_observer = Observer()
        self.gui_variable_observer.update = mock.MagicMock()
        self.gui_context.gui_variables_notifier.add_subscriber(self.gui_variable_observer)

        filepath = FileFinder.findRuns('CHRONUS00003422.nxs')[0]

        load_result, run, filename = load_workspace_from_filename(filepath)

        self.loaded_data.add_data(workspace=load_result, run=[run], filename=filename, instrument='CHRONUS')
        self.data_context.current_runs = [[run]]
        self.context.update_current_data()
예제 #12
0
def perform_musr_file_finder(self):
    ConfigService['default.instrument'] = 'MUSR'
    file_path = FileFinder.findRuns('MUSR00022725.nxs')[0]
    ws, run, filename, psi_data = load_utils.load_workspace_from_filename(
        file_path)
    self.assert_(not psi_data)
    self.data_context._loaded_data.remove_data(run=run)
    self.data_context._loaded_data.add_data(run=[run],
                                            workspace=ws,
                                            filename=filename,
                                            instrument='MUSR')
    self.data_context.current_runs = [[22725]]

    self.context.data_context._instrument = "MUSR"
    self.context.update_current_data()
    test_pair = MuonPair('test_pair', 'top', 'bottom', alpha=0.75)
    self.group_context.add_pair(pair=test_pair)
    self.presenter.update_view_from_model()
예제 #13
0
    def setUp(self):
        # Store an empty widget to parent all the views, and ensure they are deleted correctly
        self.obj = QWidget()

        setup_context_for_tests(self)
        self.context.instrument = 'EMU'
        self.load_file_view = BrowseFileWidgetView(self.obj)
        self.load_run_view = LoadRunWidgetView(self.obj)
        self.load_file_model = BrowseFileWidgetModel(self.loaded_data, self.context)
        self.load_run_model = LoadRunWidgetModel(self.loaded_data, self.context)

        self.presenter = LoadWidgetPresenter(
            LoadWidgetView(parent=self.obj, load_file_view=self.load_file_view, load_run_view=self.load_run_view),
            LoadWidgetModel(self.loaded_data, self.context))
        self.presenter.set_load_file_widget(BrowseFileWidgetPresenter(self.load_file_view, self.load_file_model))
        self.presenter.set_load_run_widget(LoadRunWidgetPresenter(self.load_run_view, self.load_run_model))

        self.filepath = FileFinder.findRuns('MUSR00022725.nxs')[0]

        self.load_patcher = mock.patch('Muon.GUI.Common.load_file_widget.model.load_utils.load_workspace_from_filename')
        self.addCleanup(self.load_patcher.stop)
        self.load_mock = self.load_patcher.start()

        self.load_run_patcher = mock.patch(
            'Muon.GUI.Common.load_run_widget.load_run_model.load_utils.load_workspace_from_filename')
        self.addCleanup(self.load_run_patcher.stop)
        self.load_run_mock = self.load_run_patcher.start()

        self.mock_workspace = self.create_fake_workspace(1)
        self.mock_loading_from_browse(self.mock_workspace, "C:\dir1\dir2\dir3\EMU0001234.nxs", 1234)
        file_utils.get_current_run_filename = mock.Mock(return_value="C:\dir1\dir2\dir3\EMU0001234.nxs")

        self.presenter.load_file_widget._view.warning_popup = mock.MagicMock()
        self.presenter.load_run_widget._view.warning_popup = mock.MagicMock()

        self.popup_patcher = mock.patch('Muon.GUI.Common.thread_model.warning')
        self.addCleanup(self.popup_patcher.stop)
        self.popup_mock = self.popup_patcher.start()

        def setGroupAndPairsToEmptyList(grouping_context):
            grouping_context._groups = []
            grouping_context._pairs = []
        self.group_context.reset_group_and_pairs_to_default = mock.MagicMock(
            side_effect=setGroupAndPairsToEmptyList(self.group_context))
    def test_runinfo_correct(self):
        file_path = FileFinder.findRuns('MUSR00022725.nxs')[0]
        ws, run, filename = load_utils.load_workspace_from_filename(file_path)
        self.data_context._loaded_data.remove_data(run=run)
        self.data_context._loaded_data.add_data(run=[run], workspace=ws, filename=filename, instrument='MUSR')
        self.data_context.current_runs = [[22725]]
        self.context.update_current_data()
        test_pair = MuonPair('test_pair', 'top', 'bottom', alpha=0.75)
        self.group_context.add_pair(pair=test_pair)

        self.presenter.update_view_from_model()

        expected_string_list = ['Instrument:MUSR', 'Run:22725', 'Title:FeTeSeT=1F=100', 'Comment:FCfirstsample',
                                'Start:2009-03-24T04:18:58', 'End:2009-03-24T04:56:26', 'Counts(MEv):20.076704',
                                'GoodFrames:88540', 'CountsperGoodFrame:226.753',
                                'CountsperGoodFrameperdet:3.543', 'AverageTemperature(K):2.53386',
                                'SampleTemperature(K):1.0', 'SampleMagneticField(G):100.0']

        self.assertEqual(str(self.view.run_info_box.toPlainText()).replace(' ', '').splitlines(), expected_string_list)
예제 #15
0
    def __verifyRequiredFile(self, filename):
        '''Return True if the specified file name is findable by Mantid.'''
        from mantid.api import FileFinder

        # simple way is just getFullPath which never uses archive search
        if os.path.exists(FileFinder.getFullPath(filename)):
            return True

        # try full findRuns which will use archive search if it is turned on
        try:
            candidates = FileFinder.findRuns(filename)
            for item in candidates:
                if os.path.exists(item):
                    return True
        except RuntimeError as e:
            return False

        # file was not found
        return False
예제 #16
0
def find_sans_file(file_name):
    """
    Finds a SANS file.
    The file can be specified as:
    1. file.ext or  path1 path2 file.ext
    2. run number
    :param file_name: a file name or a run number.
    :return: the full path.
    """
    full_path = find_full_file_path(file_name)
    if not full_path:
        runs = FileFinder.findRuns(file_name)
        if runs:
            full_path = runs[0]
    if not full_path:
        raise RuntimeError(
            "Trying to find the SANS file {0}, but cannot find it. Make sure that "
            "the relevant paths are added.".format(file_name))
    return full_path
예제 #17
0
    def setUp(self):
        AnalysisDataService.clear()
        self.filepath = FileFinder.findRuns('EMU00019489.nxs')[0]
        self.load_result, self.run_number, self.filename = load_workspace_from_filename(self.filepath)
        self.loaded_data = MuonLoadData()
        self.data_context = MuonDataContext(self.loaded_data)
        self.gui_context = MuonGuiContext()
        self.group_pair_context = MuonGroupPairContext()
        self.gui_context.update({'RebinType': 'None'})

        self.context = MuonContext(muon_data_context=self.data_context, muon_gui_context=self.gui_context, muon_group_context=self.group_pair_context)

        self.data_context.instrument = 'EMU'

        self.loaded_data.add_data(workspace=self.load_result, run=[self.run_number], filename=self.filename,
                                  instrument='EMU')
        self.data_context.current_runs = [[self.run_number]]
        self.data_context.update_current_data()
        self.group_pair_context.reset_group_and_pairs_to_default(self.load_result['OutputWorkspace'][0]._workspace,
                                                                 'EMU', '')
예제 #18
0
def find_sans_file(file_name):
    """
    Finds a SANS file.
    The file can be specified as:
    1. file.ext or  path1 path2 file.ext
    2. run number
    :param file_name: a file name or a run number.
    :return: the full path.
    """
    full_path = find_full_file_path(file_name)
    if not full_path:
        # TODO: If we only provide a run number for example 98843 for LOQ measurments, but have LARMOR specified as the
        #       Mantid instrument, then the FileFinder will search itself to death. This is a general Mantid issue.
        #       One way to handle this graceful would be a timeout option.
        runs = FileFinder.findRuns(file_name)
        if runs:
            full_path = runs[0]
    if not full_path:
        raise RuntimeError("Trying to find the SANS file {0}, but cannot find it. Make sure that "
                           "the relevant paths are added.".format(file_name))
    return full_path
    def setUp(self):
        self.filepath = FileFinder.findRuns('EMU00019489.nxs')[0]
        self.load_result, self.run_number, self.filename, _ = load_workspace_from_filename(
            self.filepath)

        self.context = setup_context()
        self.context.gui_context.update({'RebinType': 'None'})
        self.model = CorrectionsModel(self.context)
        self.runs = [[84447], [84448], [84449]]
        self.coadd_runs = [[84447, 84448, 84449]]

        self.context.data_context.instrument = 'EMU'
        self.context.data_context._loaded_data.add_data(
            workspace=self.load_result,
            run=[self.run_number],
            filename=self.filename,
            instrument='EMU')
        self.context.data_context.current_runs = [[self.run_number]]
        self.context.data_context.update_current_data()
        self.context.group_pair_context.reset_group_and_pairs_to_default(
            self.load_result['OutputWorkspace'][0].workspace, 'EMU', '', 1)
예제 #20
0
파일: GetIPTS.py 프로젝트: yutiansut/mantid
    def findFile(self, instrument, runnumber):
        # start with run and check the five before it
        runIds = list(range(runnumber, runnumber - 6, -1))
        # check for one after as well
        runIds.append(runnumber + 1)

        runIds = [str(runId) for runId in runIds if runId > 0]

        # prepend non-empty instrument name for FileFinder
        if len(instrument) > 0:
            runIds = ['%s_%s' % (instrument, runId) for runId in runIds]

        # look for a file
        for runId in runIds:
            self.log().information("Looking for '%s'" % runId)
            try:
                return FileFinder.findRuns(runId)[0]
            except RuntimeError:
                pass  # just keep looking

        # failed to find any is an error
        raise RuntimeError("Cannot find IPTS directory for '%s'" % runnumber)
예제 #21
0
    def setUp(self):
        AnalysisDataService.clear()
        ConfigService['MantidOptions.InvisibleWorkspaces'] = 'True'
        self.filepath = FileFinder.findRuns('EMU00019489.nxs')[0]

        self.load_result, self.run_number, self.filename, psi_data = load_workspace_from_filename(self.filepath)
        self.assert_(not psi_data)

        self.context = setup_context()
        self.context.gui_context.update({'RebinType': 'None'})
        self.loaded_data = self.context.data_context._loaded_data
        self.data_context = self.context.data_context
        self.gui_context = self.context.gui_context
        self.group_pair_context = self.context.group_pair_context
        self.data_context.instrument = 'EMU'

        self.loaded_data.add_data(workspace=self.load_result, run=[self.run_number], filename=self.filename,
                                  instrument='EMU')
        self.data_context.current_runs = [[self.run_number]]
        self.data_context.update_current_data()
        self.group_pair_context.reset_group_and_pairs_to_default(self.load_result['OutputWorkspace'][0].workspace,
                                                                 'EMU', '')
예제 #22
0
    def setUp(self):
        setup_context_for_tests(self)
        self.gui_variable_observer = Observer()
        self.gui_variable_observer.update = mock.MagicMock()
        self.gui_context.gui_variables_notifier.add_subscriber(
            self.gui_variable_observer)
        self.data_context.instrument = 'CHRONUS'
        self.gui_variable_observer = Observer()
        self.gui_variable_observer.update = mock.MagicMock()
        self.gui_context.gui_variables_notifier.add_subscriber(
            self.gui_variable_observer)

        filepath = FileFinder.findRuns('CHRONUS00003422.nxs')[0]

        load_result, run, filename, _ = load_workspace_from_filename(filepath)

        self.loaded_data.add_data(workspace=load_result,
                                  run=[run],
                                  filename=filename,
                                  instrument='CHRONUS')
        self.data_context.current_runs = [[run]]
        self.context.update_current_data()
    def setUp(self):
        self._qapp = mock_widget.mockQapp()
        # Store an empty widget to parent all the views, and ensure they are deleted correctly
        self.obj = QtGui.QWidget()

        setup_context_for_tests(self)
        self.context.instrument = 'EMU'
        self.load_file_view = BrowseFileWidgetView(self.obj)
        self.load_run_view = LoadRunWidgetView(self.obj)
        self.load_file_model = BrowseFileWidgetModel(self.loaded_data, self.context)
        self.load_run_model = LoadRunWidgetModel(self.loaded_data, self.context)

        self.presenter = LoadWidgetPresenter(
            LoadWidgetView(parent=self.obj, load_file_view=self.load_file_view, load_run_view=self.load_run_view),
            LoadWidgetModel(self.loaded_data, self.context))
        self.presenter.set_load_file_widget(BrowseFileWidgetPresenter(self.load_file_view, self.load_file_model))
        self.presenter.set_load_run_widget(LoadRunWidgetPresenter(self.load_run_view, self.load_run_model))

        self.filepath = FileFinder.findRuns('MUSR00022725.nxs')[0]

        self.load_patcher = mock.patch('Muon.GUI.Common.load_file_widget.model.load_utils.load_workspace_from_filename')
        self.addCleanup(self.load_patcher.stop)
        self.load_mock = self.load_patcher.start()

        self.load_run_patcher = mock.patch(
            'Muon.GUI.Common.load_run_widget.load_run_model.load_utils.load_workspace_from_filename')
        self.addCleanup(self.load_run_patcher.stop)
        self.load_run_mock = self.load_run_patcher.start()

        self.mock_workspace = self.create_fake_workspace(1)
        self.mock_loading_from_browse(self.mock_workspace, "C:\dir1\dir2\dir3\EMU0001234.nxs", 1234)
        file_utils.get_current_run_filename = mock.Mock(return_value="C:\dir1\dir2\dir3\EMU0001234.nxs")

        self.presenter.load_file_widget._view.warning_popup = mock.MagicMock()
        self.presenter.load_run_widget._view.warning_popup = mock.MagicMock()

        self.popup_patcher = mock.patch('Muon.GUI.Common.thread_model.warning')
        self.addCleanup(self.popup_patcher.stop)
        self.popup_mock = self.popup_patcher.start()
예제 #24
0
    def setUp(self):
        self.context = setup_context()

        self.context.data_context.instrument = 'MUSR'

        self.context.gui_context.update({'RebinType': 'None'})
        self.model = maxent_model.MaxEntModel()

        self.view = maxent_view_new.MaxEntView()

        self.presenter = maxent_presenter_new.MaxEntPresenter(self.view, self.context)

        file_path = FileFinder.findRuns('MUSR00022725.nxs')[0]
        ws, run, filename, _ = load_utils.load_workspace_from_filename(file_path)
        self.context.data_context._loaded_data.remove_data(run=run)
        self.context.data_context._loaded_data.add_data(run=[run], workspace=ws, filename=filename, instrument='MUSR')
        self.context.data_context.current_runs = [[22725]]

        self.context.update_current_data()
        test_pair = MuonPair('test_pair', 'top', 'bottom', alpha=0.75)
        self.context.group_pair_context.add_pair(pair=test_pair)

        self.view.warning_popup = mock.MagicMock()
    def setUp(self):
        self._qapp = mock_widget.mockQapp()
        self.obj = QtGui.QWidget()
        ConfigService['default.instrument'] = 'MUSR'
        setup_context_for_tests(self)
        self.gui_context['RebinType'] = 'None'
        self.view = HomeGroupingWidgetView(self.obj)
        self.model = HomeGroupingWidgetModel(self.context)
        self.presenter = HomeGroupingWidgetPresenter(self.view, self.model)

        self.view.warning_popup = mock.MagicMock()
        self.view.instrument_changed_warning = mock.MagicMock(return_value=1)

        file_path = FileFinder.findRuns('MUSR00022725.nxs')[0]
        ws, run, filename = load_utils.load_workspace_from_filename(file_path)
        self.data_context._loaded_data.remove_data(run=run)
        self.data_context._loaded_data.add_data(run=[run], workspace=ws, filename=filename, instrument='MUSR')
        self.data_context.current_runs = [[22725]]

        self.context.update_current_data()
        test_pair = MuonPair('test_pair', 'top', 'bottom', alpha=0.75)
        self.group_context.add_pair(pair=test_pair)
        self.presenter.update_group_pair_list()
예제 #26
0
    def findFile(self, instrument, runnumber):
        # start with run and check the five before it
        runIds = list(range(runnumber, runnumber-6, -1))
        # check for one after as well
        runIds.append(runnumber + 1)

        runIds = [str(runId) for runId in runIds if runId > 0]

        # prepend non-empty instrument name for FileFinder
        if len(instrument) > 0:
            runIds = ['%s_%s' % (instrument, runId) for runId in runIds]

        # look for a file
        for runId in runIds:
            self.log().information("Looking for '%s'" % runId)
            try:
                return FileFinder.findRuns(runId)[0]
            except RuntimeError:
                pass  # just keep looking

        # failed to find any is an error
        raise RuntimeError("Cannot find IPTS directory for '%s'"
                           % runnumber)
    def getDataFileNames(self, runsetupdict, advsetupdict):
        """ Obtain the data file names (run names + SUFFIX)

        Return: list of files
        """

        runnumbers_str = str(runsetupdict["RunNumber"])
        runnumbers_str = FileFinder.findRuns(self.instrument_name + runnumbers_str)
        runnumbers_str = [os.path.split(filename)[-1] for filename in runnumbers_str]

        # create an integer version
        runnumbers = []
        for filename in runnumbers_str:
            for extension in ['_event.nxs', '.nxs.h5']:
                filename = filename.replace(extension, '')
            runnumber = filename.split('_')[-1]
            runnumbers.append(int(runnumber))

        # put together the output
        datafilenames = []
        for (filename, runnumber) in zip(runnumbers_str, runnumbers):
            datafilenames.append((runnumber, filename))

        return datafilenames
예제 #28
0
    def setUp(self):
        self.context = setup_context(True)

        self.context.data_context.instrument = 'MUSR'

        self.context.gui_context.update({'RebinType': 'None'})

        self.view = fft_view.FFTView()
        self.model1 = fft_model.FFTModel()
        self.model = fft_model.FFTWrapper

        self.run_list = [22725]
        self.groups = [MuonGroup(group) for group in GROUP_LIST]
        self.rebins = [False] * len(self.groups)
        self.pairs = [MuonPair(EXAMPLE_PAIR, 'top', 'bottom', alpha=0.75)]

        self.presenter = fft_presenter.FFTPresenter(self.view, self.model,
                                                    self.context)

        file_path = FileFinder.findRuns('MUSR00022725.nxs')[0]
        ws, run, filename, _ = load_utils.load_workspace_from_filename(
            file_path)
        self.context.data_context._loaded_data.remove_data(run=run)
        self.context.data_context._loaded_data.add_data(run=[run],
                                                        workspace=ws,
                                                        filename=filename,
                                                        instrument='MUSR')
        self.context.data_context.current_runs = [[22725]]

        self.context.update_current_data()
        self.context.group_pair_context.add_pair(pair=self.pairs[0])
        self._calculate_all_data()
        self.context.group_pair_context._selected_groups = GROUP_LIST
        self.context.group_pair_context._selected_pairs = [EXAMPLE_PAIR]

        self.view.warning_popup = mock.MagicMock()
    def setUp(self):
        self._qapp = mock_widget.mockQapp()
        # Store an empty widget to parent all the views, and ensure they are deleted correctly
        self.obj = QtGui.QWidget()
        ConfigService['default.instrument'] = 'MUSR'

        setup_context_for_tests(self)
        self.context.instrument = 'MUSR'
        self.load_file_view = BrowseFileWidgetView(self.obj)
        self.load_run_view = LoadRunWidgetView(self.obj)
        self.load_file_model = BrowseFileWidgetModel(self.loaded_data,
                                                     self.context)
        self.load_run_model = LoadRunWidgetModel(self.loaded_data,
                                                 self.context)

        self.view = LoadWidgetView(parent=self.obj,
                                   load_file_view=self.load_file_view,
                                   load_run_view=self.load_run_view)
        self.presenter = LoadWidgetPresenter(
            self.view, LoadWidgetModel(self.loaded_data, self.context))
        self.presenter.set_load_file_widget(
            BrowseFileWidgetPresenter(self.load_file_view,
                                      self.load_file_model))
        self.presenter.set_load_run_widget(
            LoadRunWidgetPresenter(self.load_run_view, self.load_run_model))

        self.presenter.load_file_widget._view.warning_popup = mock.MagicMock()
        self.presenter.load_run_widget._view.warning_popup = mock.MagicMock()

        self.view.multiple_loading_check.setCheckState(1)
        self.presenter.handle_multiple_files_option_changed()

        self.runs = [15196, 15197]
        self.workspaces = [self.create_fake_workspace(1) for _ in self.runs]
        self.filenames = FileFinder.findRuns(
            'MUSR00015196.nxs, MUSR00015197.nxs')
예제 #30
0
 def setUpClass(cls):
     super(MuonDataContextTest, cls).setUpClass()
     cls.filepath = FileFinder.findRuns('EMU00019489.nxs')[0]
     cls.load_result, cls.run_number, cls.filename, _ = load_workspace_from_filename(
         cls.filepath)
예제 #31
0
 def test_find_runs_returns_absolute_paths_of_given_runs(self):
     runs = FileFinder.findRuns("CNCS7860")
     self.assertTrue(len(runs) == 1)
     # We can't be sure what the full path is in general but it should certainly exist!
     self.assertTrue(os.path.exists(runs[0]))
예제 #32
0
 def test_find_runs_returns_absolute_paths_of_given_runs(self):
     runs = FileFinder.findRuns("CNCS7860")
     self.assertTrue(len(runs) == 1)
     # We can't be sure what the full path is in general but it should certainly exist!
     self.assertTrue(os.path.exists(runs[0]))
예제 #33
0
 def setUpClass(cls):
     cls.filepath = FileFinder.findRuns('EMU00019489.nxs')[0]
     cls.load_result, cls.run_number, cls.filename = load_workspace_from_filename(cls.filepath)