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


Python PropertyTree.put_bool方法代码示例

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


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

示例1: test_consistency_pycap_simulation

# 需要导入模块: from pycap import PropertyTree [as 别名]
# 或者: from pycap.PropertyTree import put_bool [as 别名]
    def test_consistency_pycap_simulation(self):
        # 
        # weak run test; simply ensures that Dualfoil object
        # can be run with pycap.Charge
        #
        df1 = Dualfoil(path=path)  # will use pycap
        df2 = Dualfoil(path=path)  # manual runs
        im = df_manip.InputManager(path=path)

        # testing a charge-to-hold-const-voltage
        # manual 
        # use InputManager to set the input file
        c = -12.0  # constant current
        im.add_new_leg(c, 5.0, 1)
        df1.run()
        df1.outbot.update_output()
        v = 4.54  # constant voltage
        im.add_new_leg(v, 5.0, 0)
        df1.run()
        df1.outbot.update_output()
        
        # pycap simulation
        # build a ptree input
        ptree = PropertyTree()
        ptree.put_double('time_step', 300.0)  # 5 minutes
        ptree.put_string('charge_mode', 'constant_current')
        ptree.put_double('charge_current', 12.0)
        ptree.put_string('charge_stop_at_1', 'voltage_greater_than')
        ptree.put_double('charge_voltage_limit', 4.54)
        ptree.put_bool('charge_voltage_finish', True)
        # hold end voltage after either 5 minutes have passed
        # OR current falls under 1 ampere
        ptree.put_double('charge_voltage_finish_max_time', 300.0)
        ptree.put_double('charge_voltage_finish_current_limit', 1.0)

        const_current_const_voltage = Charge(ptree)
        const_current_const_voltage.run(df2)

        # check the output lists of both devices
        o1 = df1.outbot.output
        o2 = df2.outbot.output
        self.assertEqual(len(o1['time']), len(o2['time']))
        for i in range(len(o1['time'])):
            self.assertAlmostEqual(o1['time'][i], o2['time'][i])
            # BELOW: relaxed delta for voltage
            # REASON: dualfoil cuts off its voltages at 5
            #   decimal places, meaning that this end-digit
            #   is subject to roundoff errors
            error = 1e-5
            self.assertAlmostEqual(o1['voltage'][i], o2['voltage'][i],
                                   delta=error)
            self.assertAlmostEqual(o1['current'][i], o2['current'][i])
开发者ID:iSchomer,项目名称:Dualfoil_Storage_Device,代码行数:54,代码来源:test_energy_storage_device.py

示例2: run_discharge

# 需要导入模块: from pycap import PropertyTree [as 别名]
# 或者: from pycap.PropertyTree import put_bool [as 别名]
def run_discharge(device, ptree):
    data = initialize_data()

    # (re)charge the device
    initial_voltage = ptree.get_double('initial_voltage')

    charge_database = PropertyTree()
    charge_database.put_string('charge_mode', 'constant_current')
    charge_database.put_double('charge_current', 10.0)
    charge_database.put_string('charge_stop_at_1', 'voltage_greater_than')
    charge_database.put_double('charge_voltage_limit', initial_voltage)
    charge_database.put_bool('charge_voltage_finish', True)
    charge_database.put_double('charge_voltage_finish_current_limit', 1e-2)
    charge_database.put_double('charge_voltage_finish_max_time', 600)
    charge_database.put_double('charge_rest_time', 0)
    charge_database.put_double('time_step', 10.0)

    charge = Charge(charge_database)
    start = time()
    charge.run(device, data)
    end = time()
    # used for tracking time of this substep
    print('Charge: %s min' % ((end-start) / 60))

    data['time'] -= data['time'][-1]

    # discharge at constant power
    discharge_power = ptree.get_double('discharge_power')
    final_voltage = ptree.get_double('final_voltage')
    time_step = ptree.get_double('time_step')

    discharge_database = PropertyTree()
    discharge_database.put_string('discharge_mode', 'constant_power')
    discharge_database.put_double('discharge_power', discharge_power)
    discharge_database.put_string('discharge_stop_at_1', 'voltage_less_than')
    discharge_database.put_double('discharge_voltage_limit', final_voltage)
    discharge_database.put_double('discharge_rest_time', 10 * time_step)
    discharge_database.put_double('time_step', time_step)

    discharge = Discharge(discharge_database)
    start = time()
    discharge.run(device, data)
    end = time()
    # used for tracking time of this substep
    print('Discharge: %s min' % ((end-start) / 60))

    return data
开发者ID:iSchomer,项目名称:Dualfoil_Storage_Device,代码行数:49,代码来源:ragone.py

示例3: test_accuracy_pycap_simulation

# 需要导入模块: from pycap import PropertyTree [as 别名]
# 或者: from pycap.PropertyTree import put_bool [as 别名]
    def test_accuracy_pycap_simulation(self):
        #
        # tests the accuracy of a pycap simulation against a 
        # straight run dualfoil sim with different timesteps
        #
        df1 = Dualfoil(path=path)  # manual runs
        df2 = Dualfoil(path=path)  # pycap simulation
        im = df_manip.InputManager(path=path)

        # testing a charge-to-hold-const-voltage
        # manual 
        # use InputManager to set the input file
        c = -10.0  # constant charge current
        # charge for 5 minutes straight
        im.add_new_leg(c, 5, 1)
        df1.run()
        df1.outbot.update_output()
        v = 4.539  # expected voltage after 5 minutes
        # hold constant voltage for 3 minutes straight
        im.add_new_leg(v, 3.0, 0)
        df1.run()
        df1.outbot.update_output()

        # pycap simulation
        # build a ptree input
        ptree = PropertyTree()
        ptree.put_double('time_step', 30.0)  # 30 second time step
        ptree.put_string('charge_mode', 'constant_current')
        ptree.put_double('charge_current', 10.0)
        ptree.put_string('charge_stop_at_1', 'voltage_greater_than')
        ptree.put_double('charge_voltage_limit', v)
        ptree.put_bool('charge_voltage_finish', True)
        # hold end voltage after either 3 minutes have passed
        # OR current falls under 1 ampere
        ptree.put_double('charge_voltage_finish_max_time', 180.0)
        ptree.put_double('charge_voltage_finish_current_limit', 1.0)

        const_current_const_voltage = Charge(ptree)
        const_current_const_voltage.run(df2)

        o1 = df1.outbot.output     # contains sim1 output
        o2 = df2.outbot.output     # contains sim2 output

        # affirm we make it this far and have usable data
        self.assertTrue(len(o1['time']) > 0)
        self.assertTrue(len(o2['time']) > 0)
        # lengths of data should be different
        self.assertFalse(len(o1['time']) == len(o2['time']))

        # TEST LOGIC:
        #  -Merge the two outputs into one, sorted by
        #   increasing time stamps.
        #  -Compare the consistency of the two simulations
        #   by checking for smooth changes within the curves
        #   of the combined output lists
        o1['time'].extend(o2['time'])
        time = ar(o1['time'])  # nparray
        o1['voltage'].extend(o2['voltage'])
        voltage = ar(o1['voltage'])  # nparray
        o1['current'].extend(o2['current'])
        current = ar(o1['current'])  # np array
        # create a dictionary with the combined output lists
        output = {'time': time,
                  'voltage': voltage,
                  'current': current
                 }
        # sort based on time, keeping the three types aligned
        key = argsort(output['time'])
        # for using the key to sort the list
        tmp = {'time': [], 'voltage': [], 'current': []}
        for i in key:
            tmp['time'].append(output['time'][i])
            tmp['voltage'].append(output['voltage'][i])
            tmp['current'].append(output['current'][i])
        # reassign ordered set to `output` as nparrays
        output['time'] = ar(tmp['time'])
        output['voltage'] = ar(tmp['voltage'])
        output['current'] = ar(tmp['current'])

        # BELOW: first 20 seconds are identical time stamps;
        #     skip these to avoid errors from incorrect sorting
        # REASON FOR ERROR: Dualfoil only prints time data as 
        #     precice as minutes to three decimal places. So when
        #     the following is generated....
        #       Manual Run         |       Pycap Simulation
        #  (min)     (V)     (amp) |  (min)     (V)     (amp)
        #  .001   4.52345    10.0  |  .001   4.52345    10.0
        #  .001   4.52349    10.0  |  .001   4.52349    10.0
        #           ...                       ...
        #     ...python's `sorted()` function has no way of 
        #     distinguishing entries; it instead returns this:
        # [ 
        #   (.001, 4.52345, 10.0),
        #   (.001, 4.52349, 10.0),  <- these two should
        #   (.001, 4.52345, 10.0),  <-   be switched
        #   (.001, 4.52349, 10.0)
        # ] 
        # SOLUTION: consistency test affirms that the exact same
        #     time step will produce same current and voltage, so
        #     skip ahead to first instance where time stamps will 
#.........这里部分代码省略.........
开发者ID:iSchomer,项目名称:Dualfoil_Storage_Device,代码行数:103,代码来源:test_energy_storage_device.py


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