本文整理汇总了Python中mantid.api.AnalysisDataService.remove方法的典型用法代码示例。如果您正苦于以下问题:Python AnalysisDataService.remove方法的具体用法?Python AnalysisDataService.remove怎么用?Python AnalysisDataService.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mantid.api.AnalysisDataService
的用法示例。
在下文中一共展示了AnalysisDataService.remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_saveGSS
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import remove [as 别名]
def test_saveGSS(self):
""" Test to Save a GSAS file to match V-drive
"""
# Create a test data file and workspace
binfilename = "testbin.dat"
self._createBinFile(binfilename)
datawsname = "TestInputWorkspace"
self._createDataWorkspace(datawsname)
# Execute
alg_test = run_algorithm("SaveVulcanGSS",
InputWorkspace = datawsname,
BinFilename = binfilename,
OutputWorkspace = datawsname+"_rebinned",
GSSFilename = "tempout.gda")
self.assertTrue(alg_test.isExecuted())
# Verify ....
outputws = AnalysisDataService.retrieve(datawsname+"_rebinned")
#self.assertEqual(4, tablews.rowCount())
# Delete the test hkl file
os.remove(binfilename)
AnalysisDataService.remove("InputWorkspace")
AnalysisDataService.remove(datawsname+"_rebinned")
return
示例2: test_LoadHKLFile
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import remove [as 别名]
def test_LoadHKLFile(self):
""" Test to load a .hkl file
"""
# 1. Create a test file
hklfilename = "test.hkl"
self._createHKLFile(hklfilename)
# 2.
alg_test = run_algorithm("LoadFullprofFile", Filename = hklfilename,
OutputWorkspace = "Foo", PeakParameterWorkspace = "PeakParameterTable")
self.assertTrue(alg_test.isExecuted())
# 3. Verify some values
tablews = AnalysisDataService.retrieve("PeakParameterTable")
self.assertEqual(4, tablews.rowCount())
# alpha of (11 5 1)/Row 0
self.assertEqual(0.34252, tablews.cell(0, 3))
# 4. Delete the test hkl file
os.remove(hklfilename)
AnalysisDataService.remove("PeakParameterTable")
AnalysisDataService.remove("Foo")
return
示例3: test_exportFileNew
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import remove [as 别名]
def test_exportFileNew(self):
""" Test to export logs without header file
"""
# Generate the matrix workspace with some logs
ws = self.createTestWorkspace()
AnalysisDataService.addOrReplace("TestMatrixWS", ws)
# Test algorithm
alg_test = run_algorithm("ExportExperimentLog",
InputWorkspace = "TestMatrixWS",
OutputFilename = "TestRecord001.txt",
SampleLogNames = ["run_number", "duration", "proton_charge", "proton_charge", "proton_charge"],
SampleLogTitles = ["RUN", "Duration", "ProtonCharge", "MinPCharge", "MeanPCharge"],
SampleLogOperation = [None, None, "sum", "min", "average"],
FileMode = "new")
# Validate
self.assertTrue(alg_test.isExecuted())
# Locate file
outfilename = alg_test.getProperty("OutputFilename").value
try:
ifile = open(outfilename)
lines = ifile.readlines()
ifile.close()
except IOError as err:
print("Unable to open file {0}.".format(outfilename))
self.assertTrue(False)
return
# Last line cannot be empty, i.e., before EOF '\n' is not allowed
lastline = lines[-1]
self.assertTrue(len(lastline.strip()) > 0)
# Number of lines
self.assertEquals(len(lines), 2)
# Check line
firstdataline = lines[1]
terms = firstdataline.strip().split("\t")
self.assertEquals(len(terms), 5)
# Get property
pchargelog = ws.getRun().getProperty("proton_charge").value
sumpcharge = numpy.sum(pchargelog)
minpcharge = numpy.min(pchargelog)
avgpcharge = numpy.average(pchargelog)
v2 = float(terms[2])
self.assertAlmostEqual(sumpcharge, v2)
v3 = float(terms[3])
self.assertAlmostEqual(minpcharge, v3)
v4 = float(terms[4])
self.assertAlmostEqual(avgpcharge, v4)
# Remove generated files
os.remove(outfilename)
AnalysisDataService.remove("TestMatrixWS")
return
示例4: test_setTitle
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import remove [as 别名]
def test_setTitle(self):
run_algorithm('CreateWorkspace', OutputWorkspace='ws1',DataX=[1.,2.,3.], DataY=[2.,3.], DataE=[2.,3.],UnitX='TOF')
ws1 = AnalysisDataService['ws1']
title = 'test_title'
ws1.setTitle(title)
self.assertEquals(title, ws1.getTitle())
AnalysisDataService.remove(ws1.getName())
示例5: test_removing_from_ads_calls_any_change_handle
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import remove [as 别名]
def test_removing_from_ads_calls_any_change_handle(self):
CreateSampleWorkspace(OutputWorkspace="ws1")
self.project.anyChangeHandle = mock.MagicMock()
ADS.remove("ws1")
self.assertEqual(1, self.project.anyChangeHandle.call_count)
示例6: test_len_increases_when_item_added
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import remove [as 别名]
def test_len_increases_when_item_added(self):
wsname = 'ADSTest_test_len_increases_when_item_added'
current_len = len(AnalysisDataService)
self._run_createws(wsname)
self.assertEquals(len(AnalysisDataService), current_len + 1)
# Remove to clean the test up
AnalysisDataService.remove(wsname)
示例7: test_batch_reduction_on_multiperiod_file
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import remove [as 别名]
def test_batch_reduction_on_multiperiod_file(self):
# Arrange
# Build the data information
data_builder = get_data_builder(SANSFacility.ISIS)
data_builder.set_sample_scatter("SANS2D0005512")
data_info = data_builder.build()
# Get the rest of the state from the user file
user_file_director = StateDirectorISIS(data_info)
user_file_director.set_user_file("MASKSANS2Doptions.091A")
# Set the reduction mode to LAB
user_file_director.set_reduction_builder_reduction_mode(ISISReductionMode.LAB)
state = user_file_director.construct()
# Act
states = [state]
self._run_batch_reduction(states, use_optimizations=False)
# Assert
# We only assert that the expected workspaces exist on the ADS
expected_workspaces = ["5512p1rear_1D_2.0_14.0Phi-45.0_45.0", "5512p2rear_1D_2.0_14.0Phi-45.0_45.0",
"5512p3rear_1D_2.0_14.0Phi-45.0_45.0", "5512p4rear_1D_2.0_14.0Phi-45.0_45.0",
"5512p5rear_1D_2.0_14.0Phi-45.0_45.0", "5512p6rear_1D_2.0_14.0Phi-45.0_45.0",
"5512p7rear_1D_2.0_14.0Phi-45.0_45.0", "5512p8rear_1D_2.0_14.0Phi-45.0_45.0",
"5512p9rear_1D_2.0_14.0Phi-45.0_45.0", "5512p10rear_1D_2.0_14.0Phi-45.0_45.0",
"5512p11rear_1D_2.0_14.0Phi-45.0_45.0", "5512p12rear_1D_2.0_14.0Phi-45.0_45.0",
"5512p13rear_1D_2.0_14.0Phi-45.0_45.0"]
for element in expected_workspaces:
self.assertTrue(AnalysisDataService.doesExist(element))
# Clean up
for element in expected_workspaces:
AnalysisDataService.remove(element)
示例8: test_LoadPRFFile
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import remove [as 别名]
def test_LoadPRFFile(self):
""" Test to load a .prf file
"""
# 1. Create test .prf file
prffilename = "test.prf"
self._createPrfFile(prffilename)
# 2. Execute the algorithm
alg_test = run_algorithm("LoadFullprofFile",
Filename = prffilename,
OutputWorkspace = "Data",
PeakParameterWorkspace = "Info")
self.assertTrue(alg_test.isExecuted())
# 3. Check data
dataws = AnalysisDataService.retrieve("Data")
self.assertEqual(dataws.getNumberHistograms(), 4)
self.assertEqual(len(dataws.readX(0)), 36)
# value
self.assertEqual(dataws.readX(0)[13], 5026.3223)
self.assertEqual(dataws.readY(1)[30], 0.3819)
# 4. Clean
os.remove(prffilename)
AnalysisDataService.remove("Data")
AnalysisDataService.remove("Info")
return
示例9: _determine_factors
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import remove [as 别名]
def _determine_factors(self, q_high_angle, q_low_angle, mode, scale, shift):
# We need to make suret that the fitting only occurs in the y direction
constant_x_shift_and_scale = ', f0.Shift=0.0, f0.XScaling=1.0'
# Determine the StartQ and EndQ values
q_min, q_max = self._get_start_q_and_end_q_values(rear_data=q_low_angle, front_data=q_high_angle)
# We need to transfer the errors from the front data to the rear data, as we are using the the front data as a model, but
# we want to take into account the errors of both workspaces.
error_correction = ErrorTransferFromModelToData()
front_data_corrected, rear_data_corrected = error_correction.get_error_corrected(rear_data=q_low_angle,
front_data=q_high_angle,
q_min=q_min, q_max=q_max)
fit = self.createChildAlgorithm('Fit')
# We currently have to put the front_data into the ADS so that the TabulatedFunction has access to it
front_data_corrected = AnalysisDataService.addOrReplace('front_data_corrected', front_data_corrected)
front_in_ads = AnalysisDataService.retrieve('front_data_corrected')
function = 'name=TabulatedFunction, Workspace="' + str(
front_in_ads.name()) + '"' + ";name=FlatBackground"
fit.setProperty('Function', function)
fit.setProperty('InputWorkspace', rear_data_corrected)
constant_x_shift_and_scale = 'f0.Shift=0.0, f0.XScaling=1.0'
if mode == Mode.BothFit:
fit.setProperty('Ties', constant_x_shift_and_scale)
elif mode == Mode.ShiftOnly:
fit.setProperty('Ties', 'f0.Scaling=' + str(scale) + ',' + constant_x_shift_and_scale)
elif mode == Mode.ScaleOnly:
fit.setProperty('Ties', 'f1.A0=' + str(shift) + '*f0.Scaling,' + constant_x_shift_and_scale)
else:
raise RuntimeError('Unknown fitting mode requested.')
fit.setProperty('StartX', q_min)
fit.setProperty('EndX', q_max)
fit.setProperty('CreateOutput', True)
fit.execute()
param = fit.getProperty('OutputParameters').value
AnalysisDataService.remove(front_in_ads.name())
# The outparameters are:
# 1. Scaling in y direction
# 2. Shift in x direction
# 3. Scaling in x direction
# 4. Shift in y direction
scale = param.row(0)['Value']
if scale == 0.0:
raise RuntimeError('Fit scaling as part of stitching evaluated to zero')
# In order to determine the shift, we need to remove the scale factor
shift = param.row(3)['Value'] / scale
return (shift, scale)
示例10: test_exportFileAppend
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import remove [as 别名]
def test_exportFileAppend(self):
""" Test to export logs without header file
"""
# Generate the matrix workspace with some logs
ws = self.createTestWorkspace()
AnalysisDataService.addOrReplace("TestMatrixWS", ws)
# Test algorithm
# create new file
alg_test = run_algorithm("ExportExperimentLog",
InputWorkspace = "TestMatrixWS",
OutputFilename = "TestRecord.txt",
SampleLogNames = ["run_number", "duration", "proton_charge"],
SampleLogTitles = ["RUN", "Duration", "ProtonCharge"],
SampleLogOperation = [None, None, "sum"],
FileMode = "new")
# append
alg_test = run_algorithm("ExportExperimentLog",
InputWorkspace = "TestMatrixWS",
OutputFilename = "TestRecord.txt",
SampleLogNames = ["run_number", "duration", "proton_charge"],
SampleLogTitles = ["RUN", "Duration", "ProtonCharge"],
SampleLogOperation = [None, None, "sum"],
FileMode = "fastappend")
# Validate
self.assertTrue(alg_test.isExecuted())
# Locate file
outfilename = alg_test.getProperty("OutputFilename").value
try:
print "Output file is %s. " % (outfilename)
ifile = open(outfilename)
lines = ifile.readlines()
ifile.close()
except IOError as err:
print "Unable to open file %s. " % (outfilename)
self.assertTrue(False)
return
# Last line cannot be empty, i.e., before EOF '\n' is not allowed
lastline = lines[-1]
self.assertTrue(len(lastline.strip()) > 0)
# Number of lines
self.assertEquals(len(lines), 3)
# Check line
firstdataline = lines[1]
terms = firstdataline.strip().split("\t")
self.assertEquals(len(terms), 3)
#
# # Remove generated files
os.remove(outfilename)
AnalysisDataService.remove("TestMatrixWS")
return
示例11: test_observeDelete_calls_deleteHandle_when_set_on_ads_and_a_workspace_is_deleted
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import remove [as 别名]
def test_observeDelete_calls_deleteHandle_when_set_on_ads_and_a_workspace_is_deleted(self):
CreateSampleWorkspace(OutputWorkspace="ws")
self.fake_class.observeDelete(True)
self.fake_class.deleteHandle = mock.MagicMock()
ADS.remove("ws")
self.assertEqual(self.fake_class.deleteHandle.call_count, 1)
示例12: test_add_raises_error_if_name_exists
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import remove [as 别名]
def test_add_raises_error_if_name_exists(self):
data = [1.0,2.0,3.0]
alg = run_algorithm('CreateWorkspace',DataX=data,DataY=data,NSpec=1,UnitX='Wavelength', child=True)
name = "testws"
ws = alg.getProperty("OutputWorkspace").value
AnalysisDataService.addOrReplace(name, ws)
self.assertRaises(RuntimeError, AnalysisDataService.add, name, ws)
AnalysisDataService.remove(name)
示例13: tearDown
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import remove [as 别名]
def tearDown(self):
self.cleanup_names.append(self.wsname)
for name in self.cleanup_names:
try:
AnalysisDataService.remove(name)
except KeyError:
pass
self.cleanup_names = []
示例14: _load_param_file
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import remove [as 别名]
def _load_param_file(self, inst_name):
InstrumentParameters.instrument_name = inst_name
if IS_IN_MANTIDPLOT:
idf_loc = config.getInstrumentDirectory()
idf_pattern = os.path.join(idf_loc, "%s_Definition*.xml") % inst_name
import glob
idf_files = glob.glob(idf_pattern)
emptyInst = LoadEmptyInstrument(Filename=str(idf_files[0]))
InstrumentParameters._instrument = emptyInst.getInstrument()
AnalysisDataService.remove(str(emptyInst)) # Don't need to keep workspace
示例15: test_setTitleAndComment
# 需要导入模块: from mantid.api import AnalysisDataService [as 别名]
# 或者: from mantid.api.AnalysisDataService import remove [as 别名]
def test_setTitleAndComment(self):
run_algorithm('CreateWorkspace', OutputWorkspace='ws1',DataX=[1.,2.,3.], DataY=[2.,3.], DataE=[2.,3.],UnitX='TOF')
ws1 = AnalysisDataService['ws1']
title = 'test_title'
ws1.setTitle(title)
self.assertEquals(title, ws1.getTitle())
comment = 'Some comment on this workspace.'
ws1.setComment(comment)
self.assertEquals(comment, ws1.getComment())
AnalysisDataService.remove(ws1.name())