示例#1
0
 def test_cap_development_city_total_growth(self):
     """ Test using city and total growth for controlling the growth.
     """
             
     storage = StorageFactory().get_storage('dict_storage')
     storage.write_table(table_name='parcels', table_data=self.parcels_data)
     pcl = ParcelDataset(in_storage=storage, in_table_name='parcels')
     pcl.modify_attribute("number_of_households", 20, index=0)
     dataset_pool = DatasetPool(package_order=['urbansim_parcel', 'urbansim', 'opus_core'],
                                datasets_dict={'parcel': pcl})
     storage.write_table(table_name='ct', table_data=self.annual_household_control_totals_data)
     hct_set = ControlTotalDataset(in_storage=storage, in_table_name='ct', what='household',
                                   id_name=[])
     
     model = CapDevelopmentModel(pcl, control_total_dataset=hct_set)
     model.run(year=2016, ct_growth_attribute_name='total_growth=0.95*psrc_parcel.control_total.household_total_growth_luv', 
               target_attribute_name="urbansim_parcel.parcel.number_of_households", annual=False, growth_rate=False,
               geo_id_name='city_id', cap_attribute_name="target_achieved", dataset_pool=dataset_pool                
               )
     # All parcels from city 1 exceeded the growth
     should_be = array([True, True, False, False, False, True, True])
     self.assertEqual(all(should_be == pcl["target_achieved"]), True, "Error, should_be: %s, but result: %s" % (should_be, pcl["target_achieved"]))       
示例#2
0
 def get_parcel_based_accessibility_into_cache(self, year):
     """ Imports accessibility results from MATSim into 
         UrbanSim cache (parcel table)
     """
     logger.log_status('Importing parcel-based accessibility indicators from MATSim ...')
     try:
         parcel_data_set = ParcelDataset(in_storage=self.in_storage, in_table_name=self.parcel_table_name)
         
         existing_parcel_data_set = ParcelDataset( in_storage=self.cache_storage, in_table_name=self.parcel_table_name )
         
         existing_parcel_data_set.join(parcel_data_set, parcel_data_set.get_non_id_primary_attribute_names(), metadata=AttributeType.PRIMARY)
         
         logger.log_status('Writing parcel data to cache ...')
         flt_dir_for_next_year = os.path.join(self.cache_directory, str(year+1))
         out_storage = StorageFactory().get_storage('flt_storage', storage_location = flt_dir_for_next_year)
         existing_parcel_data_set.write_dataset(attributes=existing_parcel_data_set.get_known_attribute_names(),
                                              out_storage=out_storage,
                                              out_table_name=self.parcel_table_name)
     except:
         logger.log_warning('There is no parcel dataset! The parcel-based accessibility indicators from MATSim can not be imported!')
     
     logger.log_status('Finished importing parcel-based accessibility indicators to parcel dataset.')