本文整理汇总了Python中mantid.api.WorkspaceFactory类的典型用法代码示例。如果您正苦于以下问题:Python WorkspaceFactory类的具体用法?Python WorkspaceFactory怎么用?Python WorkspaceFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WorkspaceFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PyExec
def PyExec(self):
""" Main Execution Body
"""
# 1. Setup output workspaces
paramWS = WorkspaceFactory.createTable()
self.setProperty("InstrumentParameterWorkspace", paramWS)
hklWS = WorkspaceFactory.createTable()
self.setProperty("BraggPeakParameterWorkspace", hklWS)
# 2. Get Other Properties
instrument = self.getProperty("Instrument")
reflectionfilename = self.getPropertyValue("ReflectionsFile")
irffilename = self.getPropertyValue("FullprofParameterFile")
# 3. Import reflections list
hkldict = self.importFullProfHKLFile(reflectionfilename)
hkllist = sorted(hkldict.keys())
if _OUTPUTLEVEL == "INFORMATION":
for hkl in hkllist:
print "Import Peak (%d, %d, %d): FWHM = %f" % (hkl[0], hkl[1], hkl[2], hkldict[hkl]["FWHM"])
# 4. Import parameter file (.irf)
peakparamsdict = self.parseFullprofPeakProfileFile(irffilename)
# 5. Set up the table workspaces
self.createPeakParameterWorkspace(peakparamsdict, paramWS)
self.createReflectionWorkspace(hkldict, hklWS)
return
示例2: _loadFullprofPrfFile
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_that_can_add_workspaces_to_WorkspaceGroup_when_not_in_ADS
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)
示例4: test_adding_table_data_using_numpy
def test_adding_table_data_using_numpy(self):
table = WorkspaceFactory.createTable()
table.addColumn(type="int",name="index")
self.assertEquals(table.columnCount(), 1)
table.addColumn(type="int",name="value")
self.assertEquals(table.columnCount(), 2)
nextrow = [1, 10]
values32 = numpy.array(nextrow).astype(numpy.int32)
values64 = numpy.array(nextrow).astype(numpy.int64)
table.addRow(values32)
self.assertEquals(len(table), 1)
insertedrow = table.row(0)
self.assertEquals(1, insertedrow['index'])
self.assertEquals(10, insertedrow['value'])
table.addRow(values64)
self.assertEquals(len(table), 2)
insertedrow = table.row(1)
self.assertEquals(1, insertedrow['index'])
self.assertEquals(10, insertedrow['value'])
incorrect_type = numpy.array(['1', '10'])
self.assertRaises(TypeError, table.addRow, incorrect_type)
示例5: test_creating_a_workspace_from_another_gives_one_of_same_size
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)
示例6: test_creating_a_workspace_from_another_with_different_size
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)
示例7: PyExec
def PyExec(self):
""" Main Execution Body
"""
# 1. Get Input properties
inppeakws = self.getProperty("BraggPeakParameterWorkspace").value
inpzscows = self.getProperty("ZscoreWorkspace").value
minpeakheight = float(self.getPropertyValue("MinimumPeakHeight"))
zscorefilterstr = self.getPropertyValue("ZscoreFilter")
print "Input: PeakParameterWorkspace = %s; ZscoreWorkspace = %s" % (inppeakws.name, inpzscows.name)
print " Minimum peak height = %f" % (minpeakheight)
print " Zscore filter: %s" % (zscorefilterstr)
# 3. Parse Zscore table and peak parameters
self.mPeaks = {}
zscoredict = self.parseBraggPeakParameterTable(inpzscows)
self.mPeaks = self.parseBraggPeakParameterTable(inppeakws)
# 4. Filter by peak height
self.filterByPeakHeight(minpeakheight)
# 5. Filter by zscore
zscorefilterdict = self.parseZscoreFilter(zscorefilterstr)
self.filterByZscore(zscoredict, zscorefilterdict)
# 6. Generate the output
paramWS = WorkspaceFactory.createTable()
self.genBraggPeakParameterWorkspace(paramWS)
self.setProperty("OutputBraggPeakParameterWorkspace", paramWS)
return
示例8: test_table_is_resized_correctly
def test_table_is_resized_correctly(self):
table = WorkspaceFactory.createTable()
self.assertEquals(len(table), 0)
table.setRowCount(5)
self.assertEquals(len(table), 5)
self.assertTrue(table.addColumn(type="int",name="index"))
self.assertEquals(table.columnCount(), 1)
示例9: _create_test_table
def _create_test_table(self):
table = WorkspaceFactory.createTable()
table.addColumn(type="int", name="index")
table.addColumn(type="str", name="name")
table.addRow([0, "1"])
table.addRow([0, "2"])
table.addRow([0, "3"])
return table
示例10: _create_test_table
def _create_test_table(self):
table = WorkspaceFactory.createTable()
table.addColumn(type='int', name='index')
table.addColumn(type='str', name='name')
table.addRow([0,'1'])
table.addRow([0,'2'])
table.addRow([0,'3'])
return table
示例11: test_set_and_extract_v3d_columns
def test_set_and_extract_v3d_columns(self):
from mantid.kernel import V3D
table = WorkspaceFactory.createTable()
table.addColumn(type='V3D', name='pos')
table.addRow([V3D(1,1,1)])
self.assertEquals(V3D(1,1,1), table.cell(0, 0))
示例12: test_setting_spectra_from_array_using_incorrect_index_raises_error
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)
示例13: test_set_and_extract_boolean_columns
def test_set_and_extract_boolean_columns(self):
table = WorkspaceFactory.createTable()
table.addColumn(type='bool', name='yes_no')
table.addRow([True])
table.addRow([False])
self.assertTrue(table.cell(0, 0))
self.assertFalse(table.cell(1, 0))
示例14: test_setting_spectra_from_array_of_incorrect_length_raises_error
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)
示例15: runTest
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')