本文整理汇总了Python中mantid.api.WorkspaceFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python WorkspaceFactory.create方法的具体用法?Python WorkspaceFactory.create怎么用?Python WorkspaceFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mantid.api.WorkspaceFactory
的用法示例。
在下文中一共展示了WorkspaceFactory.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_that_can_add_workspaces_to_WorkspaceGroup_when_not_in_ADS
# 需要导入模块: from mantid.api import WorkspaceFactory [as 别名]
# 或者: from mantid.api.WorkspaceFactory import create [as 别名]
def test_that_can_add_workspaces_to_WorkspaceGroup_when_not_in_ADS(self):
ws1 = WorkspaceFactory.create("Workspace2D", 2, 2, 2)
ws2 = WorkspaceFactory.create("Workspace2D", 2, 2, 2)
ws_group = WorkspaceGroup()
ws_group.addWorkspace(ws1)
ws_group.addWorkspace(ws2)
self.assertEqual(ws_group.size(), 2)
示例2: _loadFullprofPrfFile
# 需要导入模块: from mantid.api import WorkspaceFactory [as 别名]
# 或者: from mantid.api.WorkspaceFactory import create [as 别名]
def _loadFullprofPrfFile(self, prffilename):
""" Load Fullprof .prf file
"""
# 1. Parse the file to dictionary
infodict, data = self._parseFullprofPrfFile(prffilename)
# 2. Export information to table file
tablews = WorkspaceFactory.createTable()
tablews.addColumn("str", "Name")
tablews.addColumn("double", "Value")
for parname in infodict.keys():
parvalue = infodict[parname]
tablews.addRow([parname, parvalue])
# 3. Export the data workspace
datasize = len(data)
print "Data Size = ", datasize
dataws = WorkspaceFactory.create("Workspace2D", 4, datasize, datasize)
for i in xrange(datasize):
for j in xrange(4):
dataws.dataX(j)[i] = data[i][0]
dataws.dataY(j)[i] = data[i][j+1]
dataws.dataE(j)[i] = 1.0
return (tablews, dataws)
示例3: test_creating_a_workspace_from_another_with_different_size
# 需要导入模块: from mantid.api import WorkspaceFactory [as 别名]
# 或者: from mantid.api.WorkspaceFactory import create [as 别名]
def test_creating_a_workspace_from_another_with_different_size(self):
clean = self._create_clean_workspace(nhist=2, xlength=3, ylength=4)
nhist = 4
xlength = 5
ylength = 6
copy = WorkspaceFactory.create(clean, nhist, xlength, ylength)
self._verify(copy, nhist, xlength, ylength)
示例4: test_creating_a_workspace_from_another_gives_one_of_same_size
# 需要导入模块: from mantid.api import WorkspaceFactory [as 别名]
# 或者: from mantid.api.WorkspaceFactory import create [as 别名]
def test_creating_a_workspace_from_another_gives_one_of_same_size(self):
nhist = 2
xlength = 3
ylength = 4
clean = self._create_clean_workspace(nhist, xlength, ylength)
copy = WorkspaceFactory.create(clean)
self._verify(copy, nhist, xlength, ylength)
示例5: test_setting_spectra_from_array_using_incorrect_index_raises_error
# 需要导入模块: from mantid.api import WorkspaceFactory [as 别名]
# 或者: from mantid.api.WorkspaceFactory import create [as 别名]
def test_setting_spectra_from_array_using_incorrect_index_raises_error(self):
nvectors = 2
xlength = 11
ylength = 10
test_ws = WorkspaceFactory.create("Workspace2D", nvectors, xlength, ylength)
xvalues = np.arange(xlength)
self.assertRaises(RuntimeError, test_ws.setX, 3, xvalues)
示例6: test_setting_spectra_from_array_of_incorrect_length_raises_error
# 需要导入模块: from mantid.api import WorkspaceFactory [as 别名]
# 或者: from mantid.api.WorkspaceFactory import create [as 别名]
def test_setting_spectra_from_array_of_incorrect_length_raises_error(self):
nvectors = 2
xlength = 11
ylength = 10
test_ws = WorkspaceFactory.create("Workspace2D", nvectors, xlength, ylength)
values = np.arange(xlength + 1)
self.assertRaises(ValueError, test_ws.setX, 0, values)
self.assertRaises(ValueError, test_ws.setY, 0, values)
self.assertRaises(ValueError, test_ws.setE, 0, values)
示例7: runTest
# 需要导入模块: from mantid.api import WorkspaceFactory [as 别名]
# 或者: from mantid.api.WorkspaceFactory import create [as 别名]
def runTest(self):
PDLoadCharacterizations(Filename=self.char_file, OutputWorkspace='characterizations',
SpectrumIDs='1', L2='3.18', Polar='90', Azimuthal='0')
self.wksp_mem = os.path.basename(self.data_file).split('.')[0]
self.wksp_mem, self.wksp_file = self.wksp_mem + '_mem', self.wksp_mem + '_file'
# load then process
LoadEventAndCompress(Filename=self.data_file, OutputWorkspace=self.wksp_mem, MaxChunkSize=16, FilterBadPulses=0)
LoadDiffCal(Filename=self.cal_file, InputWorkspace=self.wksp_mem, WorkspaceName='PG3')
PDDetermineCharacterizations(InputWorkspace=self.wksp_mem, Characterizations='characterizations',
ReductionProperties='__snspowderreduction_inner')
# set-up the absorption calculation
num_wl_bins = 200
prop_manager = PropertyManagerDataService.retrieve('__snspowderreduction_inner')
wl_min, wl_max = prop_manager['wavelength_min'].value, prop_manager['wavelength_max'].value # 0.05, 2.20
absorptionWS = WorkspaceFactory.create(mtd[self.wksp_mem],
NVectors=mtd[self.wksp_mem].getNumberHistograms(), XLength=num_wl_bins+1,
YLength=num_wl_bins)
xaxis = np.arange(0., float(num_wl_bins + 1)) * (wl_max - wl_min) / (num_wl_bins) + wl_min
for i in range(absorptionWS.getNumberHistograms()):
absorptionWS.setX(i, xaxis)
absorptionWS.getAxis(0).setUnit('Wavelength')
mantid.api.AnalysisDataService.addOrReplace('V_abs', absorptionWS)
SetSample(InputWorkspace='V_abs',
Material={'ChemicalFormula': 'V', 'SampleNumberDensity': 0.0721},
Geometry={'Shape': 'Cylinder', 'Height': 6.97, 'Radius': (0.63 / 2), 'Center': [0., 0., 0.]})
self.assertEqual(absorptionWS.getNumberBins(), num_wl_bins)
# calculate the absorption
CylinderAbsorption(InputWorkspace='V_abs', OutputWorkspace='V_abs',
NumberOfSlices=20, NumberOfAnnuli=3)
# do the work in memory
ConvertUnits(InputWorkspace=self.wksp_mem, OutputWorkspace=self.wksp_mem, Target='Wavelength')
Divide(LHSWorkspace=self.wksp_mem, RHSWorkspace='V_abs', OutputWorkspace=self.wksp_mem)
ConvertUnits(InputWorkspace=self.wksp_mem, OutputWorkspace=self.wksp_mem, Target='TOF')
AlignAndFocusPowder(InputWorkspace=self.wksp_mem, OutputWorkspace=self.wksp_mem,
GroupingWorkspace='PG3_group', CalibrationWorkspace='PG3_cal', MaskWorkspace='PG3_mask',
Params=-.0002, CompressTolerance=0.01,
PrimaryFlightPath=60, SpectrumIDs='1', L2='3.18', Polar='90', Azimuthal='0',
ReductionProperties='__snspowderreduction_inner')
NormaliseByCurrent(InputWorkspace=self.wksp_mem, OutputWorkspace=self.wksp_mem)
ConvertUnits(InputWorkspace=self.wksp_mem, OutputWorkspace=self.wksp_mem, Target='dSpacing')
# everything inside the algorithm
AlignAndFocusPowderFromFiles(Filename=self.data_file, OutputWorkspace=self.wksp_file,
GroupingWorkspace='PG3_group', CalibrationWorkspace='PG3_cal',
MaskWorkspace='PG3_mask',
AbsorptionWorkspace='V_abs',
Params=-.0002, CompressTolerance=0.01,
PrimaryFlightPath=60, SpectrumIDs='1', L2='3.18', Polar='90', Azimuthal='0',
ReductionProperties='__snspowderreduction_inner')
NormaliseByCurrent(InputWorkspace=self.wksp_file, OutputWorkspace=self.wksp_file)
ConvertUnits(InputWorkspace=self.wksp_file, OutputWorkspace=self.wksp_file, Target='dSpacing')
示例8: create_test_workspace
# 需要导入模块: from mantid.api import WorkspaceFactory [as 别名]
# 或者: from mantid.api.WorkspaceFactory import create [as 别名]
def create_test_workspace(model, num_bins):
workspace = WorkspaceFactory.create("Workspace2D", NVectors=1,
XLength=num_bins, YLength=num_bins)
for i in range(1, num_bins):
noise = random.uniform(0.8, 1.2)
x_value = i * 1.2
workspace.dataX(0)[i] = x_value
workspace.dataY(0)[i] = noise * model(x_value)
workspace.dataE(0)[i] = 1
return workspace
示例9: test_setxy_data_coerced_correctly_to_float64
# 需要导入模块: from mantid.api import WorkspaceFactory [as 别名]
# 或者: from mantid.api.WorkspaceFactory import create [as 别名]
def test_setxy_data_coerced_correctly_to_float64(self):
nbins = 10
nspec = 2
xdata = np.arange(nbins+1)
ydata = np.arange(nbins)
ws = WorkspaceFactory.create("Workspace2D", NVectors=nspec, XLength=nbins+1, YLength=nbins)
for i in range(nspec):
ws.setX(i, xdata)
ws.setY(i, ydata)
# Verify
x_expected, y_expected = np.vstack((xdata, xdata)), np.vstack((ydata, ydata))
x_extracted, y_extracted = ws.extractX(), ws.extractY()
self.assertTrue(np.array_equal(x_expected, x_extracted))
self.assertTrue(np.array_equal(y_expected, y_extracted))
示例10: test_setxy_accepts_python_list
# 需要导入模块: from mantid.api import WorkspaceFactory [as 别名]
# 或者: from mantid.api.WorkspaceFactory import create [as 别名]
def test_setxy_accepts_python_list(self):
nbins = 10
nspec = 2
xdata = list(range(nbins+1))
ydata = list(range(nbins))
ws = WorkspaceFactory.create("Workspace2D", NVectors=nspec, XLength=nbins+1, YLength=nbins)
for i in range(nspec):
ws.setX(i, xdata)
ws.setY(i, ydata)
# Verify
xdata, ydata = np.array(xdata), np.array(ydata)
x_expected, y_expected = np.vstack((xdata, xdata)), np.vstack((ydata, ydata))
x_extracted, y_extracted = ws.extractX(), ws.extractY()
self.assertTrue(np.array_equal(x_expected, x_extracted))
self.assertTrue(np.array_equal(y_expected, y_extracted))
示例11: PyExec
# 需要导入模块: from mantid.api import WorkspaceFactory [as 别名]
# 或者: from mantid.api.WorkspaceFactory import create [as 别名]
def PyExec(self):
input_ws = self.getProperty("InputWorkspace").value
output_ws_name = self.getProperty('OutputWorkspace').valueAsStr
from_quantity = self.getProperty("From").value
to_quantity = self.getProperty("To").value
if input_ws.name() == output_ws_name:
output_ws = input_ws
else:
output_ws = WorkspaceFactory.create(input_ws)
self.setProperty('OutputWorkspace', output_ws)
if from_quantity == to_quantity:
logger.warning('The input and output functions are the same. Nothing to be done')
return
c = Converter()
transformation = {SQ: {FQ: c.S_to_F, FKQ: c.S_to_FK, DCS: c.S_to_DCS},
FQ: {SQ: c.F_to_S, FKQ: c.F_to_FK, DCS: c.F_to_DCS},
FKQ: {SQ: c.FK_to_S, FQ: c.FK_to_F, DCS: c.FK_to_DCS},
DCS: {SQ: c.DCS_to_S, FQ: c.DCS_to_F, FKQ: c.DCS_to_FK}}
if input_ws.sample().getMaterial():
sample_kwargs = {"<b_coh>^2": input_ws.sample().getMaterial().cohScatterLengthSqrd(),
"<b_tot^2>": input_ws.sample().getMaterial().totalScatterLengthSqrd(),
"rho": input_ws.sample().getMaterial().numberDensity}
else:
sample_kwargs = dict()
for sp_num in range(input_ws.getNumberHistograms()):
x = input_ws.readX(sp_num)
output_ws.setX(sp_num, x)
y = input_ws.readY(sp_num)
e = input_ws.readE(sp_num)
if len(x) == len(y) + 1:
x = 0.5 * (x[:-1] + x[1:])
new_y, new_e = transformation[from_quantity][to_quantity](x, y, e, **sample_kwargs)
output_ws.setY(sp_num, new_y)
output_ws.setE(sp_num, new_e)
示例12: test_setting_spectra_from_array_sets_expected_values
# 需要导入模块: from mantid.api import WorkspaceFactory [as 别名]
# 或者: from mantid.api.WorkspaceFactory import create [as 别名]
def test_setting_spectra_from_array_sets_expected_values(self):
nvectors = 2
xlength = 11
ylength = 10
test_ws = WorkspaceFactory.create("Workspace2D", nvectors, xlength, ylength)
ws_index = 1
values = np.linspace(0, 1, xlength)
test_ws.setX(ws_index, values)
ws_values = test_ws.readX(ws_index)
self.assertTrue(np.array_equal(values, ws_values))
values = np.ones(ylength)
test_ws.setY(ws_index, values)
ws_values = test_ws.readY(ws_index)
self.assertTrue(np.array_equal(values, ws_values))
values = np.sqrt(values)
test_ws.setE(ws_index, values)
ws_values = test_ws.readE(ws_index)
self.assertTrue(np.array_equal(values, ws_values))
示例13: _fill_s_1d_workspace
# 需要导入模块: from mantid.api import WorkspaceFactory [as 别名]
# 或者: from mantid.api.WorkspaceFactory import create [as 别名]
def _fill_s_1d_workspace(self, s_points=None, workspace=None, protons_number=None, nucleons_number=None):
"""
Puts 1D S into workspace.
:param protons_number: number of protons in the given type fo atom
:param nucleons_number: number of nucleons in the given type of atom
:param s_points: dynamical factor for the given atom
:param workspace: workspace to be filled with S
"""
if protons_number is not None:
s_points = s_points * self._scale * self._get_cross_section(protons_number=protons_number,
nucleons_number=nucleons_number)
dim = 1
length = s_points.size
wrk = WorkspaceFactory.create("Workspace2D", NVectors=dim, XLength=length + 1, YLength=length)
for i in range(dim):
wrk.getSpectrum(i).setDetectorID(i + 1)
wrk.setX(0, self._bins)
wrk.setY(0, s_points)
AnalysisDataService.addOrReplace(workspace, wrk)
# Set correct units on workspace
self._set_workspace_units(wrk=workspace)
示例14: PyExec
# 需要导入模块: from mantid.api import WorkspaceFactory [as 别名]
# 或者: from mantid.api.WorkspaceFactory import create [as 别名]
def PyExec(self):
fn = self.getPropertyValue("Filename")
wsn = self.getPropertyValue("OutputWorkspace")
monitor_workspace_name = self.getPropertyValue("OutputMonitorWorkspace")
if monitor_workspace_name == "":
self.setPropertyValue("OutputMonitorWorkspace", wsn+'_Monitors')
#print (fn, wsn)
self.override_angle = self.getPropertyValue("AngleOverride")
self.fxml = self.getPropertyValue("InstrumentXML")
#load data
parms_dict, det_udet, det_count, det_tbc, data = self.read_file(fn)
nrows=int(parms_dict['NDET'])
#nbins=int(parms_dict['NTC'])
xdata = np.array(det_tbc)
xdata_mon = np.linspace(xdata[0],xdata[-1], len(xdata))
ydata=data.astype(np.float)
ydata=ydata.reshape(nrows,-1)
edata=np.sqrt(ydata)
#CreateWorkspace(OutputWorkspace=wsn,DataX=xdata,DataY=ydata,DataE=edata,
# NSpec=nrows,UnitX='TOF',WorkspaceTitle='Data',YUnitLabel='Counts')
nr,nc=ydata.shape
ws = WorkspaceFactory.create("Workspace2D", NVectors=nr,
XLength=nc+1, YLength=nc)
for i in range(nrows):
ws.setX(i, xdata)
ws.setY(i, ydata[i])
ws.setE(i, edata[i])
ws.getAxis(0).setUnit('tof')
AnalysisDataService.addOrReplace(wsn,ws)
#self.setProperty("OutputWorkspace", wsn)
#print ("ws:", wsn)
#ws=mtd[wsn]
# fix the x values for the monitor
for i in range(nrows-2,nrows):
ws.setX(i,xdata_mon)
self.log().information("set detector IDs")
#set detetector IDs
for i in range(nrows):
ws.getSpectrum(i).setDetectorID(det_udet[i])
#Sample_logs the header values are written into the sample logs
log_names=[str(sl.encode('ascii','ignore').decode()) for sl in parms_dict.keys()]
log_values=[str(sl.encode('ascii','ignore').decode()) if isinstance(sl,UnicodeType) else str(sl) for sl in parms_dict.values()]
for i in range(len(log_values)):
if ('nan' in log_values[i]) or ('NaN' in log_values[i]):
log_values[i] = '-1.0'
AddSampleLogMultiple(Workspace=wsn, LogNames=log_names,LogValues=log_values)
SetGoniometer(Workspace=wsn, Goniometers='Universal')
if (self.fxml == ""):
LoadInstrument(Workspace=wsn, InstrumentName = "Exed", RewriteSpectraMap= True)
else:
LoadInstrument(Workspace=wsn, Filename = self.fxml, RewriteSpectraMap= True)
try:
RotateInstrumentComponent(Workspace=wsn,
ComponentName='Tank',
Y=1,
Angle=-float(parms_dict['phi'].encode('ascii','ignore')),
RelativeRotation=False)
except:
self.log().warning("The instrument does not contain a 'Tank' component. "
"This means that you are using a custom XML instrument definition. "
"OMEGA_MAG will be ignored.")
self.log().warning("Please make sure that the detector positions in the instrument definition are correct.")
# Separate monitors into seperate workspace
__temp_monitors = ExtractSpectra(InputWorkspace = wsn, WorkspaceIndexList = ','.join([str(s) for s in range(nrows-2, nrows)]),
OutputWorkspace = self.getPropertyValue("OutputMonitorWorkspace"))
# ExtractSpectra(InputWorkspace = wsn, WorkspaceIndexList = ','.join([str(s) for s in range(nrows-2, nrows)]),
# OutputWorkspace = wsn + '_Monitors')
MaskDetectors(Workspace = wsn, WorkspaceIndexList = ','.join([str(s) for s in range(nrows-2, nrows)]))
RemoveMaskedSpectra(InputWorkspace = wsn, OutputWorkspace = wsn)
self.setProperty("OutputWorkspace", wsn)
self.setProperty("OutputMonitorWorkspace", __temp_monitors)
示例15: PyExec
# 需要导入模块: from mantid.api import WorkspaceFactory [as 别名]
# 或者: from mantid.api.WorkspaceFactory import create [as 别名]
def PyExec(self):
ws = WorkspaceFactory.create("Workspace2D", NVectors=1, YLength=1,XLength=1)
ws.dataY(0)[0] = 5
self.setProperty("RequiredWorkspace", ws)
self.getLogger().notice("done!")