当前位置: 首页>>代码示例>>Python>>正文


Python FileFinder.findRuns方法代码示例

本文整理汇总了Python中mantid.api.FileFinder.findRuns方法的典型用法代码示例。如果您正苦于以下问题:Python FileFinder.findRuns方法的具体用法?Python FileFinder.findRuns怎么用?Python FileFinder.findRuns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mantid.api.FileFinder的用法示例。


在下文中一共展示了FileFinder.findRuns方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: find_data

# 需要导入模块: from mantid.api import FileFinder [as 别名]
# 或者: from mantid.api.FileFinder import findRuns [as 别名]
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))
开发者ID:DanNixon,项目名称:mantid,代码行数:60,代码来源:find_data.py

示例2: test_that_find_runs_accepts_a_list_of_string_and_a_bool

# 需要导入模块: from mantid.api import FileFinder [as 别名]
# 或者: from mantid.api.FileFinder import findRuns [as 别名]
 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]))
开发者ID:mantidproject,项目名称:mantid,代码行数:14,代码来源:FileFinderTest.py

示例3: getDataFileNames

# 需要导入模块: from mantid.api import FileFinder [as 别名]
# 或者: from mantid.api.FileFinder import findRuns [as 别名]
    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
开发者ID:mantidproject,项目名称:mantid,代码行数:28,代码来源:diffraction_reduction_script.py

示例4: find_sans_file

# 需要导入模块: from mantid.api import FileFinder [as 别名]
# 或者: from mantid.api.FileFinder import findRuns [as 别名]
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
开发者ID:samueljackson92,项目名称:mantid,代码行数:32,代码来源:file_information.py

示例5: setUp

# 需要导入模块: from mantid.api import FileFinder [as 别名]
# 或者: from mantid.api.FileFinder import findRuns [as 别名]
    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')
开发者ID:mantidproject,项目名称:mantid,代码行数:30,代码来源:loadwidget_presenter_multiple_file_test.py

示例6: _get_workspace

# 需要导入模块: from mantid.api import FileFinder [as 别名]
# 或者: from mantid.api.FileFinder import findRuns [as 别名]
 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
开发者ID:mantidproject,项目名称:mantid,代码行数:10,代码来源:crop_helper_test.py

示例7: test_browse_clicked_suceeds_if_table_in_ADS

# 需要导入模块: from mantid.api import FileFinder [as 别名]
# 或者: from mantid.api.FileFinder import findRuns [as 别名]
    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)
开发者ID:mantidproject,项目名称:mantid,代码行数:13,代码来源:home_instrument_widget_test.py

示例8: __verifyRequiredFile

# 需要导入模块: from mantid.api import FileFinder [as 别名]
# 或者: from mantid.api.FileFinder import findRuns [as 别名]
    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
开发者ID:mantidproject,项目名称:systemtests,代码行数:18,代码来源:stresstesting.py

示例9: setUp

# 需要导入模块: from mantid.api import FileFinder [as 别名]
# 或者: from mantid.api.FileFinder import findRuns [as 别名]
    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()
开发者ID:mantidproject,项目名称:mantid,代码行数:20,代码来源:frequency_domain_context_test.py

示例10: test_runinfo_correct

# 需要导入模块: from mantid.api import FileFinder [as 别名]
# 或者: from mantid.api.FileFinder import findRuns [as 别名]
    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)
开发者ID:mantidproject,项目名称:mantid,代码行数:21,代码来源:home_runinfo_presenter_test.py

示例11: setUp

# 需要导入模块: from mantid.api import FileFinder [as 别名]
# 或者: from mantid.api.FileFinder import findRuns [as 别名]
    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', '')
开发者ID:mantidproject,项目名称:mantid,代码行数:22,代码来源:muon_context_test.py

示例12: setUp

# 需要导入模块: from mantid.api import FileFinder [as 别名]
# 或者: from mantid.api.FileFinder import findRuns [as 别名]
    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()
开发者ID:mantidproject,项目名称:mantid,代码行数:41,代码来源:loadwidget_presenter_test.py

示例13: findFile

# 需要导入模块: from mantid.api import FileFinder [as 别名]
# 或者: from mantid.api.FileFinder import findRuns [as 别名]
    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)
开发者ID:rosswhitfield,项目名称:mantid,代码行数:25,代码来源:GetIPTS.py

示例14: setUp

# 需要导入模块: from mantid.api import FileFinder [as 别名]
# 或者: from mantid.api.FileFinder import findRuns [as 别名]
    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()
开发者ID:mantidproject,项目名称:mantid,代码行数:25,代码来源:home_grouping_widget_test.py

示例15: test_find_runs_returns_absolute_paths_of_given_runs

# 需要导入模块: from mantid.api import FileFinder [as 别名]
# 或者: from mantid.api.FileFinder import findRuns [as 别名]
 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]))
开发者ID:DanNixon,项目名称:mantid,代码行数:7,代码来源:FileFinderTest.py


注:本文中的mantid.api.FileFinder.findRuns方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。