• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python api.WorkspaceFactory类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了WorkspaceFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:trnielsen,项目名称:mantid,代码行数:31,代码来源:CreateLeBailFitInput.py


示例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)
开发者ID:dezed,项目名称:mantid,代码行数:25,代码来源:LoadFullprofFile.py


示例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)
开发者ID:mantidproject,项目名称:mantid,代码行数:10,代码来源:WorkspaceGroupTest.py


示例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)
开发者ID:rosswhitfield,项目名称:mantid,代码行数:25,代码来源:ITableWorkspaceTest.py


示例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)
开发者ID:nimgould,项目名称:mantid,代码行数:7,代码来源:WorkspaceFactoryTest.py


示例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)
开发者ID:nimgould,项目名称:mantid,代码行数:7,代码来源:WorkspaceFactoryTest.py


示例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
开发者ID:BigShows,项目名称:mantid,代码行数:33,代码来源:SelectPowderDiffPeaks.py


示例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)
开发者ID:jkrueger1,项目名称:mantid,代码行数:7,代码来源:ITableWorkspaceTest.py


示例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
开发者ID:nimgould,项目名称:mantid,代码行数:8,代码来源:ITableWorkspaceTest.py


示例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
开发者ID:jkrueger1,项目名称:mantid,代码行数:8,代码来源:ITableWorkspaceTest.py


示例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))
开发者ID:jkrueger1,项目名称:mantid,代码行数:8,代码来源:ITableWorkspaceTest.py


示例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)
开发者ID:mantidproject,项目名称:mantid,代码行数:8,代码来源:MatrixWorkspaceTest.py


示例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))
开发者ID:jkrueger1,项目名称:mantid,代码行数:8,代码来源:ITableWorkspaceTest.py


示例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)
开发者ID:mantidproject,项目名称:mantid,代码行数:10,代码来源:MatrixWorkspaceTest.py


示例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')
开发者ID:mantidproject,项目名称:mantid,代码行数:55,代码来源:AlignAndFocusPowderFromFilesTest.py


示例16: test_set_and_extract_vector_columns

    def test_set_and_extract_vector_columns(self):
        table = WorkspaceFactory.createTable()
        table.addColumn(type='vector_int', name='values')

        # Settings from general Python list
        table.addRow([ [1,2,3,4,5] ])
        # Setting from numpy array
        table.addRow([ numpy.array([6,7,8,9,10]) ])

        self.assertTrue( numpy.array_equal( table.cell(0,0), numpy.array([1,2,3,4,5]) ) )
        self.assertTrue( numpy.array_equal( table.cell(1,0), numpy.array([6,7,8,9,10]) ) )
开发者ID:jkrueger1,项目名称:mantid,代码行数:11,代码来源:ITableWorkspaceTest.py


示例17: create_test_workspace

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
开发者ID:DanNixon,项目名称:mantid,代码行数:11,代码来源:MsdTestHelper.py


示例18: test_setxy_data_coerced_correctly_to_float64

    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))
开发者ID:mantidproject,项目名称:mantid,代码行数:15,代码来源:MatrixWorkspaceTest.py


示例19: test_adding_table_data_using_dictionary

 def test_adding_table_data_using_dictionary(self):
     table = WorkspaceFactory.createTable()
     table.addColumn(type="int",name="index")
     self.assertEquals(table.columnCount(), 1)
     table.addColumn(type="str",name="value")
     self.assertEquals(table.columnCount(), 2)
     
     nextrow = {'index':1, 'value':'10'}
     table.addRow(nextrow)
     self.assertEquals(len(table), 1)
     insertedrow = table.row(0)
     self.assertEquals(insertedrow, nextrow)
     
     incorrect_type = {'index':1, 'value':10}
     self.assertRaises(ValueError, table.addRow, incorrect_type)
开发者ID:jkrueger1,项目名称:mantid,代码行数:15,代码来源:ITableWorkspaceTest.py


示例20: test_adding_table_data_using_list

 def test_adding_table_data_using_list(self):
     table = WorkspaceFactory.createTable()
     table.addColumn(type="int",name="index")
     self.assertEquals(table.columnCount(), 1)
     table.addColumn(type="str",name="value")
     self.assertEquals(table.columnCount(), 2)
     
     nextrow = {'index':1, 'value':'10'}
     values = nextrow.values()
     table.addRow(nextrow)
     self.assertEquals(len(table), 1)
     insertedrow = table.row(0)
     self.assertEquals(insertedrow, nextrow)
     insertedrow = table.row(0)
     self.assertEquals(insertedrow, nextrow)
开发者ID:jkrueger1,项目名称:mantid,代码行数:15,代码来源:ITableWorkspaceTest.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mtd.doesExist函数代码示例发布时间:2022-05-27
下一篇:
Python api.PythonAlgorithm类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap