本文整理汇总了Python中mantid.api.AnalysisDataService.getObjectNames方法的典型用法代码示例。如果您正苦于以下问题:Python AnalysisDataService.getObjectNames方法的具体用法?Python AnalysisDataService.getObjectNames怎么用?Python AnalysisDataService.getObjectNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mantid.api.AnalysisDataService
的用法示例。
在下文中一共展示了AnalysisDataService.getObjectNames方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _do_test_output
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import getObjectNames [as 别名]
def _do_test_output(self, load_alg, expected_number_of_workspaces, expected_number_on_ads, workspace_type):
# Check the number of workspaces
tags_numbers = ["NumberOfSampleScatterWorkspaces", "NumberOfSampleTransmissionWorkspaces",
"NumberOfSampleDirectWorkspaces", "NumberOfCanScatterWorkspaces",
"NumberOfCanTransmissionWorkspaces", "NumberOfCanDirectWorkspaces"]
for num_workspaces, num_name in zip(expected_number_of_workspaces, tags_numbers):
number_of_workspaces = load_alg.getProperty(num_name).value
self.assertTrue(number_of_workspaces == num_workspaces)
# Check that workspaces were loaded
tags_workspaces = ["SampleScatterWorkspace", "SampleTransmissionWorkspace",
"SampleDirectWorkspace", "CanScatterWorkspace",
"CanTransmissionWorkspace", "CanDirectWorkspace"]
index = 0
for num_workspaces, workspace_name in zip(expected_number_of_workspaces, tags_workspaces):
self._evaluate_workspace_type(load_alg, num_workspaces, workspace_name, workspace_type, index)
index += 1
# Check for the monitor workspaces
num_monitor_workspaces = [expected_number_of_workspaces[0], expected_number_of_workspaces[3]]
tags_monitors = ["SampleScatterMonitorWorkspace", "CanScatterMonitorWorkspace"]
workspace_type_monitor = [Workspace2D, Workspace2D]
index = 0
for num_workspaces, workspace_name in zip(num_monitor_workspaces, tags_monitors):
self._evaluate_workspace_type(load_alg, num_workspaces, workspace_name, workspace_type_monitor, index)
index += 1
# Confirm there is nothing on the ADS
workspaces_on_the_ads = AnalysisDataService.getObjectNames()
self.assertTrue(len(workspaces_on_the_ads) == expected_number_on_ads)
示例2: cleanup
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import getObjectNames [as 别名]
def cleanup(self):
# Delete all workspaces
for ws in AnalysisDataService.getObjectNames():
DeleteWorkspace(Workspace=ws)
# Delete the stored files
os.remove(os.path.join(config['defaultsave.directory'], 'SANS2D00028793-add.nxs'))
os.remove(os.path.join(config['defaultsave.directory'], 'SANS2D00028797-add.nxs'))
示例3: _save_workspaces
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import getObjectNames [as 别名]
def _save_workspaces(self, directory):
"""
Save all workspaces present in the ADS to the given directory
:param directory: String; Path to where to save the workspaces
"""
# Get all present workspaces
ws_list = ADS.getObjectNames()
if len(ws_list) == 0:
return
start_time = UsageService.getStartTime().toISO8601String()
alg_name = "GeneratePythonScript"
alg = AlgorithmManager.createUnmanaged(alg_name, 1)
alg.setChild(True)
alg.setLogging(False)
for index, ws in enumerate(ws_list):
if self._empty_group_workspace(ws):
continue
filename = str(index) + ".py"
filename = os.path.join(directory, filename)
alg.initialize()
alg.setProperty("AppendTimestamp", True)
alg.setProperty("AppendExecCount", True)
alg.setProperty("InputWorkspace", ws)
alg.setPropertyValue("Filename", filename)
alg.setPropertyValue("StartTimestamp", start_time)
alg.setProperty("IgnoreTheseAlgs", ALGS_TO_IGNORE)
alg.setProperty("IgnoreTheseAlgProperties", ALG_PROPERTIES_TO_IGNORE)
alg.execute()
示例4: populate_combobox
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import getObjectNames [as 别名]
def populate_combobox(self, combo):
ws_list = AnalysisDataService.getObjectNames()
for ws in ws_list:
ws_object = AnalysisDataService.retrieve(ws)
if not ws.startswith("__") and combo.findText(ws)<0\
and hasattr(ws_object, "getNumberHistograms")\
and ws_object.getNumberHistograms()==1:
combo.addItem(ws)
示例5: get_current_workspaces
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import getObjectNames [as 别名]
def get_current_workspaces(self):
"""
Get current workspaces' names
Returns
-------
a list of strings
"""
return AnalysisDataService.getObjectNames()
示例6: test_that_show_all_calculates_and_shows_all_pairs_with_rebin
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import getObjectNames [as 别名]
def test_that_show_all_calculates_and_shows_all_pairs_with_rebin(self):
self.gui_context['RebinType'] = 'Fixed'
self.gui_context['RebinFixed'] = 2
self.context.show_all_pairs()
self.assertEquals(AnalysisDataService.getObjectNames(),
['EMU19489', 'EMU19489 Pairs', 'EMU19489; Pair Asym; long; #1', 'EMU19489; Pair Asym; long; Rebin; #1', 'Muon Data'])
示例7: _save
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import getObjectNames [as 别名]
def _save(self):
workspaces_to_save = AnalysisDataService.getObjectNames()
plots_to_save = self.plot_gfm.figs
interfaces_to_save = self.interface_populating_function()
project_saver = ProjectSaver(self.project_file_ext)
project_saver.save_project(file_name=self.last_project_location, workspace_to_save=workspaces_to_save,
plots_to_save=plots_to_save, interfaces_to_save=interfaces_to_save)
self.__saved = True
示例8: test_that_show_all_calculates_and_shows_all_groups_with_rebin
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import getObjectNames [as 别名]
def test_that_show_all_calculates_and_shows_all_groups_with_rebin(self):
self.gui_context['RebinType'] = 'Fixed'
self.gui_context['RebinFixed'] = 2
self.context.show_all_groups()
self.assertEquals(AnalysisDataService.getObjectNames(),
['EMU19489', 'EMU19489 Groups', 'EMU19489; Group; bwd; Asymmetry; #1', 'EMU19489; Group; bwd; Asymmetry; Rebin; #1',
'EMU19489; Group; bwd; Counts; #1', 'EMU19489; Group; bwd; Counts; Rebin; #1',
'EMU19489; Group; fwd; Asymmetry; #1', 'EMU19489; Group; fwd; Asymmetry; Rebin; #1',
'EMU19489; Group; fwd; Counts; #1', 'EMU19489; Group; fwd; Counts; Rebin; #1', 'Muon Data'])
示例9: test_load_calls_loads_successfully
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import getObjectNames [as 别名]
def test_load_calls_loads_successfully(self):
working_directory = tempfile.mkdtemp()
return_value_for_load = os.path.join(working_directory, os.path.basename(working_directory) + ".mtdproj")
self.project._save_file_dialog = mock.MagicMock(return_value=working_directory)
CreateSampleWorkspace(OutputWorkspace="ws1")
self.project.save_as()
self.assertEqual(self.project._save_file_dialog.call_count, 1)
ADS.clear()
self.project._load_file_dialog = mock.MagicMock(return_value=return_value_for_load)
self.project.load()
self.assertEqual(self.project._load_file_dialog.call_count, 1)
self.assertEqual(["ws1"], ADS.getObjectNames())
示例10: recovery_save
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import getObjectNames [as 别名]
def recovery_save(self):
"""
The function to save a recovery checkpoint
"""
# Set that recovery thread is not running anymore
self.pr.thread_on = False
try:
# Get the interfaces_list
interfaces_list = find_all_windows_that_are_savable()
# Check if there is anything to be saved or not
if len(ADS.getObjectNames()) == 0 and len(interfaces_list) == 0:
logger.debug("Project Recovery: Nothing to save")
self._spin_off_another_time_thread()
return
logger.debug("Project Recovery: Saving started")
# Create directory for save location
recovery_dir = os.path.join(self.pr.recovery_directory_pid,
datetime.datetime.now().strftime('%d-%m-%YT%H-%M-%S'))
if not os.path.exists(recovery_dir):
os.makedirs(recovery_dir)
self._add_lock_file(directory=recovery_dir)
# Save workspaces
self._save_workspaces(directory=recovery_dir)
# Save project
self._save_project(directory=recovery_dir, interfaces_list=interfaces_list)
self._remove_lock_file(directory=recovery_dir)
# Clear the oldest checkpoints
self.pr.remove_oldest_checkpoints()
logger.debug("Project Recovery: Saving finished")
except Exception as e:
if isinstance(e, KeyboardInterrupt):
raise
# Fail and print to debugger
logger.debug("Project Recovery: Failed to save error msg: " + str(e))
# Spin off another timer thread
if not self.pr.closing_workbench:
self._spin_off_another_time_thread()
示例11: save_project
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import getObjectNames [as 别名]
def save_project(self, file_name, workspace_to_save=None, plots_to_save=None, interfaces_to_save=None,
project_recovery=True):
"""
The method that will actually save the project and call relevant savers for workspaces, plots, interfaces etc.
:param file_name: String; The file_name of the
:param workspace_to_save: List; of Strings that will have workspace names in it, if None will save all
:param plots_to_save: List; of matplotlib.figure objects to save to the project file.
:param interfaces_to_save: List of Lists of Window and Encoder; the interfaces to save and the encoders to use
:param project_recovery: Bool; If the behaviour of Project Save should be altered to function correctly inside
of project recovery
:return: None; If the method cannot be completed.
"""
# Check if the file_name doesn't exist
if file_name is None:
logger.warning("Please select a valid file name")
return
# Check this isn't saving a blank project file
if (workspace_to_save is None and plots_to_save is None and interfaces_to_save is None) and project_recovery:
logger.warning("Can not save an empty project")
return
directory = os.path.dirname(file_name)
# Save workspaces to that location
if project_recovery:
workspace_saver = WorkspaceSaver(directory=directory)
workspace_saver.save_workspaces(workspaces_to_save=workspace_to_save)
saved_workspaces = workspace_saver.get_output_list()
else:
# Assume that this is project recovery so pass a list of workspace names
saved_workspaces = ADS.getObjectNames()
# Generate plots
plots_to_save_list = PlotsSaver().save_plots(plots_to_save)
# Save interfaces
if interfaces_to_save is None:
interfaces_to_save = []
interfaces = self._return_interfaces_dicts(directory=directory, interfaces_to_save=interfaces_to_save)
# Pass dicts to Project Writer
writer = ProjectWriter(workspace_names=saved_workspaces,
plots_to_save=plots_to_save_list,
interfaces_to_save=interfaces,
save_location=file_name,
project_file_ext=self.project_file_ext)
writer.write_out()
示例12: get_workspaces_from_ads_if_exist
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import getObjectNames [as 别名]
def get_workspaces_from_ads_if_exist(file_tags, full_calibration_file_path, workspaces):
"""
Retrieves workspaces from the ADS depending on their file tags and calibration file tags which would have been
set by the sans loading mechanism when they were loaded the first time.
:param file_tags: a list of file tags which we look for on the workspaces on the ADS
:param full_calibration_file_path: the calibration file name which we look for on the workspaces on the ADS
:param workspaces: a list of workspaces which is being updated in this function.
"""
for workspace_name in AnalysisDataService.getObjectNames():
workspace = AnalysisDataService.retrieve(workspace_name)
try:
if has_tag(SANS_FILE_TAG, workspace):
file_tag = get_tag(SANS_FILE_TAG, workspace)
if file_tag in file_tags and is_calibration_correct(workspace, full_calibration_file_path):
workspaces.append(workspace)
except RuntimeError:
continue
示例13: pyexec_setup
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import getObjectNames [as 别名]
def pyexec_setup(new_options):
"""
Backup keys of mantid.config and clean up temporary files and workspaces
upon algorithm completion or exception raised.
Workspaces with names beginning with '_t_' are assumed temporary.
Parameters
----------
new_options: dict
Dictionary of mantid configuration options to be modified.
"""
# Hold in this tuple all temporary objects to be removed after completion
temp_objects = namedtuple('temp_objects', 'files workspaces')
temps = temp_objects(list(), list())
previous_config = dict()
for key, value in new_options.items():
previous_config[key] = mantid_config[key]
mantid_config[key] = value
try:
yield temps
finally:
# reinstate the mantid options
for key, value in previous_config.items():
mantid_config[key] = value
if debug_flag is True:
return
# delete temporary files
for file_name in temps.files:
os.remove(file_name)
# remove any workspace added to temps.workspaces or whose name begins
# with "_t_"
to_be_removed = set()
for name in AnalysisDataService.getObjectNames():
if '_t_' == name[0:3]:
to_be_removed.add(name)
for workspace in temps.workspaces:
if isinstance(workspace, str):
to_be_removed.add(workspace)
else:
to_be_removed.add(workspace.name())
for name in to_be_removed:
DeleteWorkspace(name)
示例14: runTest
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import getObjectNames [as 别名]
def runTest(self):
UseCompatibilityMode()
LARMOR()
Set1D()
Detector("DetectorBench")
MaskFile('USER_LARMOR_151B_LarmorTeam_80tubes_BenchRot1p4_M4_r3699.txt')
Gravity(True)
AddRuns(('13065', '13065'), 'LARMOR', 'nxs', lowMem=True)
AssignSample('13065-add.nxs')
WavRangeReduction(2, 4, DefaultTrans)
# Clean up
for element in AnalysisDataService.getObjectNames():
if AnalysisDataService.doesExist(element) and element != "13065p1rear_1D_2.0_4.0":
AnalysisDataService.remove(element)
paths = [os.path.join(config['defaultsave.directory'], 'LARMOR00013065-add.nxs'),
os.path.join(config['defaultsave.directory'], 'SANS2D00013065.log')] # noqa
for path in paths:
if os.path.exists(path):
os.remove(path)
示例15: test_that_instantiated_WorkspaceGroup_can_be_added_to_the_ADS
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import getObjectNames [as 别名]
def test_that_instantiated_WorkspaceGroup_can_be_added_to_the_ADS(self):
ws_group = WorkspaceGroup()
mtd.add("group1", ws_group)
self.assertEqual(AnalysisDataService.getObjectNames(), ["group1"])
self.assertIsInstance(mtd["group1"], WorkspaceGroup)