def modify_zone_based_accessibility_into_cache(self, year): """ Modifies accessibility results from MATSim in UrbanSim cache (zones table) """ logger.log_status('Importing zone-based accessibility indicators from MATSim ...') existing_zone_data_set = ZoneDataset( in_storage=self.cache_storage, in_table_name=self.zone_table_name ) for zone_id in range(1318,2042): # get row index of zone_id index = existing_zone_data_set.get_id_index(zone_id) # get and modify car accessibility car_accessibility = existing_zone_data_set.get_attribute_by_index('car_accessibility', index) car_accessibility = car_accessibility / self.factor existing_zone_data_set.modify_attribute('car_accessibility', car_accessibility, index ) # get and modify walk accessibility walk_accessibility = existing_zone_data_set.get_attribute_by_index('walk_accessibility', index) walk_accessibility = walk_accessibility / self.factor existing_zone_data_set.modify_attribute('walk_accessibility', walk_accessibility, index ) # get and modify bike accessibility #bike_accessibility = existing_zone_data_set.get_attribute_by_index('bike_accessibility', index) #bike_accessibility = bike_accessibility / self.factor #existing_zone_data_set.modify_attribute('bike_accessibility', bike_accessibility, index ) # get and modify free accessibility #freespeed_accessibility = existing_zone_data_set.get_attribute_by_index('freespeed_accessibility', index) #freespeed_accessibility = freespeed_accessibility / self.factor #existing_zone_data_set.modify_attribute('freespeed_accessibility', freespeed_accessibility, index ) logger.log_status('Writing modified zone 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_zone_data_set.write_dataset(attributes=existing_zone_data_set.get_known_attribute_names(), out_storage=out_storage, out_table_name=self.zone_table_name) logger.log_status('Finished modifying zone-based accessibility indicators in zone dataset.')
def modify_zone_based_accessibility_into_cache(self, year): """ Modifies accessibility results from MATSim in UrbanSim cache (zones table) """ logger.log_status('Importing zone-based accessibility indicators from MATSim ...') existing_zone_data_set = ZoneDataset( in_storage=self.cache_storage, in_table_name=self.zone_table_name ) size = existing_zone_data_set.size() counter = 0 for id in range(0,size): # get row index of id index = existing_zone_data_set.get_id_index(id) faz_id = existing_zone_data_set.get_attribute_by_index(self.faz_id, index) # get original accessibility values car_accessibility = existing_zone_data_set.get_attribute_by_index('car_accessibility', index) walk_accessibility = existing_zone_data_set.get_attribute_by_index('walk_accessibility', index) bike_accessibility = existing_zone_data_set.get_attribute_by_index('bike_accessibility', index) freespeed_accessibility = existing_zone_data_set.get_attribute_by_index('freespeed_accessibility', index) # decrease accessibility if int(faz_id) == int(self.faz_number_decrease_acc): counter = counter + 1 # modify and store car accessibility car_accessibility = car_accessibility / self.factor existing_zone_data_set.modify_attribute('car_accessibility', car_accessibility, index ) # modify and store walk accessibility walk_accessibility = walk_accessibility / self.factor existing_zone_data_set.modify_attribute('walk_accessibility', walk_accessibility, index ) # modify and store bike accessibility bike_accessibility = bike_accessibility / self.factor existing_zone_data_set.modify_attribute('bike_accessibility', bike_accessibility, index ) # modify and store free accessibility freespeed_accessibility = freespeed_accessibility / self.factor existing_zone_data_set.modify_attribute('freespeed_accessibility', freespeed_accessibility, index ) # increase accessibility elif (int(faz_id) == int(self.faz_number_increase_acc_1)) or (int(faz_id) == int(self.faz_number_increase_acc_2)) or (int(faz_id) == int(self.faz_number_increase_acc_3)) or (int(faz_id) == int(self.faz_number_increase_acc_4)): counter = counter + 1 # modify and store car accessibility car_accessibility = car_accessibility * self.factor existing_zone_data_set.modify_attribute('car_accessibility', car_accessibility, index ) # modify and store walk accessibility walk_accessibility = walk_accessibility * self.factor existing_zone_data_set.modify_attribute('walk_accessibility', walk_accessibility, index ) # modify and store bike accessibility bike_accessibility = bike_accessibility * self.factor existing_zone_data_set.modify_attribute('bike_accessibility', bike_accessibility, index ) # modify and store free accessibility freespeed_accessibility = freespeed_accessibility * self.factor existing_zone_data_set.modify_attribute('freespeed_accessibility', freespeed_accessibility, index ) logger.log_status('Writing modified zone 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_zone_data_set.write_dataset(attributes=existing_zone_data_set.get_known_attribute_names(), out_storage=out_storage, out_table_name=self.zone_table_name) logger.log_status('Modified %d zones' %counter) logger.log_status('Finished modifying zone-based accessibility indicators in zone dataset.')