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


Python Material.write_hdf5方法代码示例

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


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

示例1: test_hdf5_protocol_1

# 需要导入模块: from pyne.material import Material [as 别名]
# 或者: from pyne.material.Material import write_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 write_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: make_materials_compendium

# 需要导入模块: from pyne.material import Material [as 别名]
# 或者: from pyne.material.Material import write_hdf5 [as 别名]
def make_materials_compendium(nuc_data):
    """Adds materials compendium to nuc_data.h5."""
    # open nuc_data, make nuc_zz an array
    with tb.openFile(nuc_data, 'r+', filters=tb.Filters(complevel=5, complib='zlib', shuffle=True, fletcher32=False)) as f:
        f.createGroup('/', 'materials_library')
        f.createArray('/materials_library', 'nuc_zz', np.array(list(nuc_zz)))
    # Writes elements for which we have compositional data to file
    for zz in elemental_mats:
        if 0 == len(elemental_mats[zz]):
            continue
        element = Material(elemental_mats[zz], mass = 1.0, attrs = {'name':nucname.name(zz)})
        element.write_hdf5(nuc_data, datapath="/materials_library/materials", nucpath="/materials_library/nuc_zz", chunksize=70)

    # Writes materials from mats to file, and names them.
    for i in range(len(mats)):
        mats[i].mass = 1.0
        mats[i].density = float(densities[i])
        mats[i].attrs = {'name': names[i]}
        mats[i].write_hdf5(nuc_data, datapath="/materials_library/materials", nucpath="/materials_library/nuc_zz", chunksize=70)
开发者ID:AliZeineddine,项目名称:pyne,代码行数:21,代码来源:materials_library.py


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