本文整理汇总了Python中urbansim.datasets.household_dataset.HouseholdDataset.modify_attribute方法的典型用法代码示例。如果您正苦于以下问题:Python HouseholdDataset.modify_attribute方法的具体用法?Python HouseholdDataset.modify_attribute怎么用?Python HouseholdDataset.modify_attribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urbansim.datasets.household_dataset.HouseholdDataset
的用法示例。
在下文中一共展示了HouseholdDataset.modify_attribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_controlling_with_three_marginal_characteristics
# 需要导入模块: from urbansim.datasets.household_dataset import HouseholdDataset [as 别名]
# 或者: from urbansim.datasets.household_dataset.HouseholdDataset import modify_attribute [as 别名]
def test_controlling_with_three_marginal_characteristics(self):
"""Controlling with all three possible marginal characteristics in this example, age_of_head, income, and persons,
this would partition the 8 groups into the same 8 groups, and with a control total specified for each group, we must
ensure that the control totals for each group exactly meet the specifications.
"""
#IMPORTANT: marginal characteristics grouping indices have to start at 0!
annual_household_control_totals_data = {
"year": array(8*[2000]),
#"age_of_head": array(4*[0] + 4*[1]),
"age_of_head_min": array([ 0, 0, 0, 0, 50, 50, 50, 50]),
"age_of_head_max": array([49,49,49,49,100,100,100,100]),
#"income": array(2*[0] + 2*[1] + 2*[0] + 2*[1]),
"income_min": array([ 0, 0,40000,40000, 0, 0,40000,40000]),
"income_max": array([39999,39999, -1, -1,39999,39999, -1, -1]),
#"persons": array([0,1,0,1,0,1,0,1]),
"persons_min": array([0, 3,0, 3,0, 3,0, 3]),
"persons_max": array([2,-1,2,-1,2,-1,2,-1]),
"total_number_of_households": array([4000, 5000, 1000, 3000, 0, 6000, 3000, 8000])
}
##size of columns was not even, removed last element of min and max
#household_characteristics_for_ht_data = {
#"characteristic": array(2*['age_of_head'] + 2*['income'] + 2*['persons']),
#"min": array([0, 50, 0, 40000, 0, 3]),
#"max": array([49, 100, 39999, -1, 2, -1])
#}
storage = StorageFactory().get_storage('dict_storage')
storage.write_table(table_name='hh_set', table_data=self.households_data)
hh_set = HouseholdDataset(in_storage=storage, in_table_name='hh_set')
storage.write_table(table_name='hct_set', table_data=annual_household_control_totals_data)
hct_set = ControlTotalDataset(in_storage=storage, in_table_name='hct_set', what='household', id_name=[])
#storage.write_table(table_name='hc_set', table_data=household_characteristics_for_ht_data)
#hc_set = HouseholdCharacteristicDataset(in_storage=storage, in_table_name='hc_set')
# unplace some households
where10 = where(hh_set.get_attribute("grid_id")<>10)[0]
hh_set.modify_attribute(name="grid_id", data=zeros(where10.size), index=where10)
model = TransitionModel(hh_set, control_total_dataset=hct_set)
model.run(year=2000, target_attribute_name="total_number_of_households", reset_dataset_attribute_value={'grid_id':-1})
#check that there are indeed 33000 total households after running the model
results = hh_set.size()
should_be = [30000]
self.assertEqual(ma.allclose(should_be, results, rtol=1e-1),
True, "Error, should_be: %s, but result: %s" % (should_be, results))
#check that the number of households in each group exactly match the control totals specified
results = self.get_count_all_groups(hh_set)
should_be = [4000, 5000, 1000, 3000, 0, 6000, 3000, 8000]
self.assertEqual(ma.allclose(results, should_be),
True, "Error, should_be: %s, but result: %s" % (should_be, results))