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


Python PropertyTree.get_child方法代码示例

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


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

示例1: run

# 需要导入模块: from pycap import PropertyTree [as 别名]
# 或者: from pycap.PropertyTree import get_child [as 别名]
def run():
    # parse uq database
    input_database=PropertyTree()
    input_database.parse_xml('uq.xml')
    uq_database=input_database.get_child('uq')

    # declare parameters
    params=uq_database.get_int('params')
    parameter_list=[]
    for p in range(params):
        parameter_database=uq_database.get_child('param_'+str(p))
        distribution_type=parameter_database.get_string('distribution_type')
        parameter_name=parameter_database.get_string('name')
        if distribution_type=='uniform':
            parameter_range=parameter_database.get_array_double('range')
            parameter_list.append(UniformParameter('param_'+str(p),
                                                   parameter_name,
                                                   min=parameter_range[0],
                                                   max=parameter_range[1]))
        elif distribution_type=='normal':
            parameter_mean=parameter_database.get_double('mean')
            parameter_standard_deviation=parameter_database.get_double('standard_deviation')
            parameter_list.append(NormalParameter('param_'+str(p),
                                                  parameter_name,
                                                  mean=parameter_mean,
                                                  dev=parameter_standard_deviation))
        else:
            raise RuntimeError('invalid distribution type '+distribution_type+' for param_'+str(p))

    # create a host
    host_database=uq_database.get_child('host')
    host_type=host_database.get_string('type')
    if host_type=="Interactive":
        host=InteractiveHost(cpus=host_database.get_int_with_default_value('cpus',1),
                             cpus_per_node=host_database.get_int_with_default_value('cpus_per_node',0))
    elif host_type=="PBS":
        host=PBSHost(host_database.get_string('env'),
                     cpus=host_database.get_int_with_default_value('cpus',0),
                     cpus_per_node=host_database.get_int_with_default_value('cpus_per_node',0),
                     qname=host_database.get_string_with_default_value('qname','standby'),
                     walltime=host_database.get_string_with_default_value('walltime','1:00:00'),
                     modules=host_database.get_string_with_default_value('modules',''),
                     pack=host_database.get_int_with_default_value('pack',1),
                     qlimit=host_database.get_int_with_default_value('qlimit',200))
    else:
        raise RuntimeError('invalid host type '+host_type)

    # pick UQ method
    method=uq_database.get_string('method')
    if method=='SmolyakSparseGrid':
        level=uq_database.get_int('level')
        uq=Smolyak(parameter_list,level=level)
    elif method=='MonteCarlo':
        samples=uq_database.get_int('samples')
        uq=MonteCarlo(parameter_list,num=samples)
    elif method=='LatinHypercubeSampling':
        samples=uq_database.get_int('samples')
        uq=LHS(parameter_list,num=samples)
    else:
        raise RuntimeError('invalid UQ method '+method)

    # make a test program
    test_program_database=uq_database.get_child('test_program')
    description=test_program_database.get_string('description')
    executable_name=test_program_database.get_string('executable')
    for p in range(params):
        executable_name+=' --param_'+str(p)+' $param_'+str(p)
    prog=TestProgram(exe=executable_name,
                     desc=description)

    # run
    return Sweep(uq,host,prog)
开发者ID:dalg24,项目名称:cap-notebooks,代码行数:74,代码来源:run_sweep.py

示例2:

# 需要导入模块: from pycap import PropertyTree [as 别名]
# 或者: from pycap.PropertyTree import get_child [as 别名]
(options,args)=parser.parse_args()

# make device database
device_database=PropertyTree()
device_database.parse_xml('super_capacitor.xml')
# adjust the parameters in the database
options_dict=vars(options)
for var in options_dict:
    path=uq_database.get_string('uq.'+var+'.name')
    # next line is there to ensure that path already exists
    old_value=device_database.get_double(path)
    new_value=options_dict[var]
    print var,path,new_value
    device_database.put_double(path,new_value)
# build the energy storage device
device=EnergyStorageDevice(device_database.get_child('device'))

# parse the electrochmical impedance spectroscopy database
eis_database=PropertyTree()
eis_database.parse_xml('eis.xml')
# measure the impedance
impedance_spectrum_data=measure_impedance_spectrum(device,eis_database.get_child('eis'))
# extract the results
frequency=impedance_spectrum_data['frequency']
complex_impedance=impedance_spectrum_data['impedance']
resistance=real(complex_impedance)
reactance=imag(complex_impedance)
modulus=absolute(complex_impedance)
argument=angle(complex_impedance,deg=True)
magnitude=20*log10(absolute(complex_impedance))
# and report 
开发者ID:dalg24,项目名称:cap-notebooks,代码行数:33,代码来源:pycap_measure_impedance_spectrum.py


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