def test_gridcell_unrolling(self): """Checks that the unrolling of the gridcells by CacheScenarioDatabase worked correctly. """ cache_directory = SimulationState().get_cache_directory() gridcells = SessionConfiguration().get_dataset_from_pool('gridcell') development_event_history = SessionConfiguration().get_dataset_from_pool('development_event_history') unroller = UnrollGridcells() unroller.unroll_gridcells_to_cache(gridcells, development_event_history, cache_directory, self.base_year) self.assertEqual(self.temp_dir, os.path.split(cache_directory)[0]) gridcell = {} for year in [1976, 1977, 1979, 1980]: #current_year = SimulationState().get_current_time() #SimulationState().set_current_time(year) #gridcell[year] = SessionConfiguration().get_dataset_from_pool('gridcell') #SimulationState().set_current_time(current_year) flt_directory = os.path.join(cache_directory, str(year)) gridcell[year] = DatasetFactory().get_dataset('gridcell', package='urbansim', subdir='datasets', arguments={'in_storage':StorageFactory().get_storage('flt_storage', storage_location=flt_directory)} ) diff = gridcell[1980].get_attribute('residential_units') - gridcell[1979].get_attribute('residential_units') self.assertEqual(1, sum(diff)) diff = gridcell[1977].get_attribute('commercial_sqft') - gridcell[1976].get_attribute('commercial_sqft') self.assertEqual(2255+199+332+2785, sum(diff))
def tmp_skip_test_gridcell_unrolling_changes_development_type_id(self): """Does unrolling update development_type_id? """ # Force one grid cell to be "vacant", so can check that development_type_id changes. cache_directory = SimulationState().get_cache_directory() flt_directory = os.path.join(cache_directory, str(self.base_year)) development_event_history = DatasetFactory().get_dataset('development_event_history', package='urbansim', subdir='datasets', arguments={'in_storage':StorageFactory().get_storage('flt_storage', storage_location=flt_directory)} ) changed_grid_id = 10123 new_row = { 'grid_id':array([changed_grid_id]), 'scheduled_year':array([self.base_year - 1]), 'residential_units':array([1000]), 'commercial_sqft':array([10000000]), 'industrial_sfft':array([10000000]), 'governmental_sqft':array([10000000]), 'starting_development_type_id':array([1000]), } development_event_history.add_elements(new_row, require_all_attributes=False) development_event_history.flush_dataset() gridcells = SessionConfiguration().get_dataset_from_pool('gridcell') development_event_history = SessionConfiguration().get_dataset_from_pool('development_event_history') unroller = UnrollGridcells() unroller.unroll_gridcells_to_cache(gridcells, development_event_history, cache_directory, self.base_year) cache_directory = SimulationState().get_cache_directory() self.assertEqual(self.temp_dir, os.path.split(cache_directory)[0]) gridcell = {} for year in [1978, 1979]: flt_directory = os.path.join(cache_directory, str(year)) gridcell[year] = DatasetFactory().get_dataset('gridcell', package='urbansim', subdir='datasets', arguments={'in_storage':StorageFactory().get_storage('flt_storage', storage_location=flt_directory)} ) self.assertEqual(gridcell[1978].get_attribute_by_id('development_type_id', changed_grid_id), 1000) self.assertNotEqual(gridcell[1979].get_attribute_by_id('development_type_id', changed_grid_id), gridcell[1978].get_attribute_by_id('development_type_id', changed_grid_id))
def prepare_data_before_baseyear(self, cache_directory, base_year, creating_baseyear_cache_configuration): if creating_baseyear_cache_configuration.unroll_gridcells: sc = SessionConfiguration() gridcells = sc.get_dataset_from_pool('gridcell') development_event_history = sc.get_dataset_from_pool( 'development_event_history') UnrollGridcells().unroll_gridcells_to_cache( gridcells, development_event_history, cache_directory, base_year) # If you want to unroll the gridcells using your buildings table, exchange the # previous two calls by the two following ones. #buildings = sc.get_dataset_from_pool('building') #UnrollGridcells().unroll_gridcells_to_cache_from_buildings(gridcells, buildings, # cache_directory, base_year) attribute_cache = AttributeCache() self._initialize_previous_years(attribute_cache, base_year, creating_baseyear_cache_configuration)