def test_property_tree(self): # ptree as container to store int, double, string, and bool ptree = PropertyTree() ptree.put_int('dim', 3) self.assertEqual(ptree.get_int('dim'), 3) ptree.put_double('path.to.pi', 3.14) self.assertEqual(ptree.get_double('path.to.pi'), 3.14) ptree.put_string('good.news', 'it works') self.assertEqual(ptree.get_string('good.news'), 'it works') ptree.put_bool('is.that.a.good.idea', False) self.assertEqual(ptree.get_bool('is.that.a.good.idea'), False)
def test_get_children(self): ptree = PropertyTree() # put child child = PropertyTree() child.put_double('prune', 6.10) ptree.put_child('a.g', child) self.assertEqual(ptree.get_double('a.g.prune'), 6.10) # get child ptree.put_string('child.name', 'clement') ptree.put_int('child.age', -2) child = ptree.get_child('child') self.assertEqual(child.get_string('name'), 'clement') self.assertEqual(child.get_int('age'), -2)
#!/usr/bin/env python from puq import dump_hdf5 from optparse import OptionParser from pycap import PropertyTree,EnergyStorageDevice from pycap import measure_impedance_spectrum from numpy import real,imag,log10,absolute,angle # read uq database uq_database=PropertyTree() uq_database.parse_xml('uq.xml') # get number of parameters params=uq_database.get_int('uq.params') # usage usage='usage: %prog' for p in range(params): usage+=' --param_'+str(p)+' val_'+str(p) parser=OptionParser(usage) # register options for p in range(params): parser.add_option('--param_'+str(p),type=float) # parse the command line arguments (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:
#!/usr/bin/env python from puq import dump_hdf5 from optparse import OptionParser from pycap import PropertyTree, EnergyStorageDevice from pycap import measure_impedance_spectrum from numpy import real, imag, log10, absolute, angle # read uq database uq_database = PropertyTree() uq_database.parse_xml('uq.xml') # get number of parameters params = uq_database.get_int('uq.params') # usage usage = 'usage: %prog' for p in range(params): usage += ' --param_' + str(p) + ' val_' + str(p) parser = OptionParser(usage) # register options for p in range(params): parser.add_option('--param_' + str(p), type=float) # parse the command line arguments (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: