当前位置: 首页>>代码示例>>Python>>正文


Python Material.from_hdf5方法代码示例

本文整理汇总了Python中pyne.material.Material.from_hdf5方法的典型用法代码示例。如果您正苦于以下问题:Python Material.from_hdf5方法的具体用法?Python Material.from_hdf5怎么用?Python Material.from_hdf5使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyne.material.Material的用法示例。


在下文中一共展示了Material.from_hdf5方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_hdf5_protocol_1

# 需要导入模块: from pyne.material import Material [as 别名]
# 或者: from pyne.material.Material import from_hdf5 [as 别名]
def test_hdf5_protocol_1():
    if 'proto1.h5' in os.listdir('.'):
        os.remove('proto1.h5')

    # Test material writing
    leu = Material({'U235': 0.04, 'U238': 0.96}, 4.2, 2.72, 1.0)
    leu.metadata['comment'] = 'first light'
    leu.write_hdf5('proto1.h5', chunksize=10)

    for i in range(2, 11):
        leu = Material({'U235': 0.04, 'U238': 0.96}, i*4.2, 2.72, 1.0*i)
        leu.metadata['comment'] = 'fire in the disco - {0}'.format(i)
        leu.write_hdf5('proto1.h5')

    # Loads with protocol 1 now.
    m = Material()
    m.from_hdf5('proto1.h5', '/material', -3, 1)
    assert_equal(m.density, 2.72)
    assert_equal(m.atoms_per_molecule, 8.0)
    assert_equal(m.mass, 33.6)
    assert_equal(m.comp, {922350000: 0.04, 922380000: 0.96})
    assert_equal(m.metadata['comment'], 'fire in the disco - 8')

    m = from_hdf5('proto1.h5', '/material', 3, 1)
    assert_equal(m.density, 2.72)
    assert_equal(m.atoms_per_molecule, 4.0)
    assert_equal(m.mass, 16.8)
    assert_equal(m.comp, {922350000: 0.04, 922380000: 0.96})
    assert_equal(m.metadata['comment'], 'fire in the disco - 4')

    os.remove('proto1.h5')
开发者ID:NukespudWork,项目名称:pyne,代码行数:33,代码来源:test_material.py

示例2: test_hdf5_protocol_1

# 需要导入模块: from pyne.material import Material [as 别名]
# 或者: from pyne.material.Material import from_hdf5 [as 别名]
def test_hdf5_protocol_1():
    if 'proto1.h5' in os.listdir('.'):
        os.remove('proto1.h5')

    # Test material writing
    leu = Material({'U235': 0.04, 'U238': 0.96}, 4.2, "LEU", 1.0)
    leu.write_hdf5('proto1.h5', chunksize=10)

    for i in range(2, 11):
        leu = Material({'U235': 0.04, 'U238': 0.96}, i*4.2, "LEU", 1.0*i)
        leu.write_hdf5('proto1.h5')

    # Loads with protocol 1 now.
    m = Material()
    m.from_hdf5('proto1.h5', '/material', -3, 1)
    assert_equal(m.name, 'LEU')
    assert_equal(m.atoms_per_mol, 8.0)
    assert_equal(m.mass, 33.6)
    assert_equal(m.comp, {922350: 0.04, 922380: 0.96})

    m = from_hdf5('proto1.h5', '/material', 3, 1)
    assert_equal(m.name, 'LEU')
    assert_equal(m.atoms_per_mol, 4.0)
    assert_equal(m.mass, 16.8)
    assert_equal(m.comp, {922350: 0.04, 922380: 0.96})

    os.remove('proto1.h5')
开发者ID:chrisdembia,项目名称:pyne,代码行数:29,代码来源:test_material.py

示例3: xs_gen

# 需要导入模块: from pyne.material import Material [as 别名]
# 或者: from pyne.material.Material import from_hdf5 [as 别名]
    def xs_gen(self, idx, nucs):
        """Runs the cross-section generation portion of char.

        idx : a list of perturbation indices that 
              could be supplied to range() or slice().
        nucs : a set of nuclides to run (zzaaam-form).
        """
        nucs_in_serpent = (nucs & set(self.env['core_transmute_in_serpent']))
        nucs_not_in_serpent = (nucs & set(self.env['core_transmute_not_in_serpent']))

        # Loop over the perturbation steps
        for n in range(*idx):
            # Grab the Material at this time.
            ms_n = Material()
            ms_n.from_hdf5(self.env['reactor'] + ".h5", "/Ti0", n, protocol=0)

            # Calc restricted mass streams
            ms_n_in_serpent = ms_n[self.env['core_transmute_in_serpent']]
            ms_n_not_in_serpent = ms_n[self.env['core_transmute_not_in_serpent']]

            # Read in some common parameters from the data file
            with tb.openFile(self.env['reactor'] + ".h5", 'r') as  rx_h5:
                E_g = np.array(rx_h5.root.energy[n][::-1])
                E_n = np.array(rx_h5.root.hi_res.energy.read()[::-1])
                phi_n = np.array(rx_h5.root.hi_res.phi_g[n][::-1])

            # Run and write the high resolution flux
            if (phi_n < 0.0).all():
                res, det = self.n_code.run_flux_g_pert(n, ms_n_in_serpent)
                self.n_code.write_flux_g(n, res, det)
                with tb.openFile(self.env['reactor'] + ".h5", 'r') as  rx_h5:
                    phi_n = np.array(rx_h5.root.hi_res.phi_g[n][::-1])

            #
            # Loop over all output nuclides...
            #
            # ...that are valid in serpent
            for nuc in nucs_in_serpent:
                res, det = self.n_code.run_xs_gen_pert(nuc, n, ms_n_in_serpent, E_n, E_g, phi_n)
                self.n_code.write_xs_gen(nuc, n, res, det)

            # ...that are NOT valid in serpent
            for nuc in nucs_not_in_serpent:
                xsd = self.n_code.run_xs_mod_pert(nuc, n, E_n, E_g, phi_n)
                self.n_code.write_xs_mod(nuc, n, xsd)
开发者ID:bartonfriedland,项目名称:bright,代码行数:47,代码来源:runchar.py

示例4: test_from_hdf5_protocol_0

# 需要导入模块: from pyne.material import Material [as 别名]
# 或者: from pyne.material.Material import from_hdf5 [as 别名]
def test_from_hdf5_protocol_0():
    mat = Material()
    mat.from_hdf5("mat.h5", "/mat", protocol=0)
    assert_equal(mat.mass, 0.0)
    assert_equal(mat.comp, {922350000: 0.0, 942390000: 0.0})

    mat.from_hdf5("mat.h5", "/mat", 0, 0)
    assert_equal(mat.mass, 1.0)
    assert_equal(mat.comp, {922350000: 1.0, 942390000: 0.0})

    mat.from_hdf5("mat.h5", "/mat", 1, 0)
    assert_equal(mat.mass, 0.5)
    assert_equal(mat.comp, {922350000: 0.75, 942390000: 0.25})

    mat.from_hdf5("mat.h5", "/mat", 2, 0)
    assert_equal(mat.mass, 0.0)
    assert_equal(mat.comp, {922350000: 0.0, 942390000: 0.0})

    mat.from_hdf5("mat.h5", "/mat", -1, 0)
    assert_equal(mat.mass, 0.0)
    assert_equal(mat.comp, {922350000: 0.0, 942390000: 0.0})

    mat.from_hdf5("mat.h5", "/mat", -2, 0)
    assert_equal(mat.mass, 0.5)
    assert_equal(mat.comp, {922350000: 0.75, 942390000: 0.25})

    mat.from_hdf5("mat.h5", "/mat", -3, 0)
    assert_equal(mat.mass, 1.0)
    assert_equal(mat.comp, {922350000: 1.0, 942390000: 0.0})
开发者ID:NukespudWork,项目名称:pyne,代码行数:31,代码来源:test_material.py

示例5: main

# 需要导入模块: from pyne.material import Material [as 别名]
# 或者: from pyne.material.Material import from_hdf5 [as 别名]
def main( arguments = None ):

    # Instatiate options parser
    parser = OptionParser\
        (usage='%prog <material description> [options]')

    parser.add_option('-w', dest='xsdir_Path', default=None,\
        help='Path to the XSDIR file, default=%default')

    parser.add_option('-o', dest='H5M_Path', default='None',\
        help='Path to the H5M file, default=%default')

    parser.add_option('-p', dest='preferredLibsStr', default='None',\
        help='string of preffered libraries white space separated. Example: "21c 22c 67c", default=%default')
    OPT, ARG = parser.parse_args()
    
    #XS=XSDIR_Search2(OPT.xsdir_Path)
    mat_list= []
    # get the material list from the '.h5m' file
    mat_list= get_tag_values(OPT.H5M_Path)
    dictionary={}
    mat_comp_list=[]
    
    

    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ##### text material file of format: example: #####
    ##### Name    SomeMaterial
    ##### Mass    42
    ##### APerM   1
    ##### H1    0.04
    ##### U238    0.9
    ##### 6012	0.06
   



    # Both .txt or .h5 material files are compatible
    for Mat in mat_list:

    	Path= "Mat_Libs/" + Mat + ".txt"
	try:
    	    mat = Material(Path)
	except:
	    try :
	        Path= "Mat_Libs/" + Mat + ".h5"
	        mat = Material()
	        mat.from_hdf5(Path, "/mat", 1, protocol=0)
	    except:
	        print "The Material file '.h5' or '.txt' for material " , Mat, " was not found"
	        continue
    	# print "Composition of tempate '.h5' or '.text' file: ", Mat, ": ", mat.comp
    	isotopes=[]
	# get isotopes from mat.comp dictionary
    	for key in mat.comp.keys():
	    isotopes.append(str(key))
	# preppend the isotopes with their corresponding material tag in the list
    	isotopes.insert(0, Mat)
    
	# append the new list of Isotopes to Mat_Comp_list
    	mat_comp_list.append(isotopes)

    ####Example: Mat_Comp_list= [ [Mat1, iso1, iso2, iso3], [Mat2 , iso1, iso2 ,iso3], ...]
    print '\n', "list of 'Material,Composition' lists: ", mat_comp_list, '\n'

    for list in mat_comp_list:
	for iso in list:
	    if iso !=list[0]:
	        # get dictionary element for the current isotope in the list
	        resultDictElement=xsdir_get_iso_lib(OPT.xsdir_Path,iso,OPT.preferredLibsStr) 
	        ##### xsdir_get_iso_lib: RETURN example: ['6012', '90y'] if found, 0 if not found
	        print ' '
	        if resultDictElement !=0:
		    dictionary.update({resultDictElement[0]: resultDictElement[1]})
    print ' '
    print "Dictionary: ", dictionary
开发者ID:moatazharb,项目名称:dag_tag_study,代码行数:78,代码来源:mat_desc.py


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