'db_input_database':'psrc', 'db_output_database':None, 'cache_directory':cache_directory, 'base_year':2000, 'tables_to_cache':[ 'gridcells', # 'households', # 'jobs', ]}) #CacheScenarioDatabase().run(gridcell_config) # step 2 cache water demand data by dbcon = ScenarioDatabase(database_name = "water_demand_seattle2") print "Create Storage object." from opus_core.storage_factory import StorageFactory storage = StorageFactory().get_storage(type="mysql_storage", storage_location=dbcon) from waterdemand.datasets.consumption_dataset import ConsumptionDataset consumption_types = ['wrmr', 'wcsr', 'wrsr'] #'wcmr' for consumption_type in consumption_types: consumption = ConsumptionDataset(in_storage = storage, in_table_name=consumption_type+'_grid') for year in range(1990, 2001): print "%s %s" % (consumption_type, year) year_index = where(consumption.get_attribute("billyear") == year) out_storage = StorageFactory().get_storage(type="flt_storage", storage_location=os.path.join(cache_directory, str(year))) consumption_subset = DatasetSubset(consumption, year_index) consumption_subset.write_dataset(out_storage=out_storage, out_table_name=consumption_type.lower())
print "Create Storage object." from urbansim.storage_creator import StorageCreator storage = StorageCreator().build_storage(type="mysql", location=dbcon) consumption_type = "WRSR" print "Create ConsumptionDataset object" from waterdemand.datasets.consumption_dataset import ConsumptionDataset consumption = ConsumptionDataset(in_storage=storage, in_table_name=consumption_type + "_grid") from urbansim.datasets.gridcell_dataset import GridcellDataset from numpy import array from opus_core.misc import unique consumption_grid_id = consumption.get_attribute("grid_id") years = consumption.get_attribute("billyear") distinct_years = unique(years) import os from numpy import where, zeros, arange cache_directory = "D:/urbansim_cache/water_demand" for year in arange(1991, 2001): print year flt_storage = StorageCreator().build_storage(type="flt", location=os.path.join( cache_directory, str(year))) gridcells = GridcellDataset(in_storage=flt_storage) grid_id_idx = array( map(lambda x: gridcells.try_id_mapping(x, -1), consumption_grid_id))
print "Create Storage object." from urbansim.storage_creator import StorageCreator storage = StorageCreator().build_storage(type="mysql", location=dbcon) consumption_type = "WRSR" print "Create ConsumptionDataset object" from waterdemand.datasets.consumption_dataset import ConsumptionDataset consumption = ConsumptionDataset(in_storage = storage, in_table_name=consumption_type + "_grid") from urbansim.datasets.gridcell_dataset import GridcellDataset from numpy import array from opus_core.misc import unique consumption_grid_id = consumption.get_attribute("grid_id") years = consumption.get_attribute("billyear") distinct_years = unique(years) import os from numpy import where, zeros, arange cache_directory = "D:/urbansim_cache/water_demand" for year in arange(1991, 2001): print year flt_storage = StorageCreator().build_storage(type="flt", location=os.path.join(cache_directory, str(year))) gridcells = GridcellDataset(in_storage=flt_storage) grid_id_idx = array(map(lambda x: gridcells.try_id_mapping(x, -1), consumption_grid_id)) year_idx = where(years==year)[0] grid_id_idx_for_year = grid_id_idx[year_idx] for attr in gridcells.get_known_attribute_names(): if attr not in consumption.get_known_attribute_names():
] }) #CacheScenarioDatabase().run(gridcell_config) # step 2 cache water demand data by dbcon = ScenarioDatabase(database_name="water_demand_seattle2") print "Create Storage object." from opus_core.storage_factory import StorageFactory storage = StorageFactory().get_storage(type="mysql_storage", storage_location=dbcon) from waterdemand.datasets.consumption_dataset import ConsumptionDataset consumption_types = ['wrmr', 'wcsr', 'wrsr'] #'wcmr' for consumption_type in consumption_types: consumption = ConsumptionDataset(in_storage=storage, in_table_name=consumption_type + '_grid') for year in range(1990, 2001): print "%s %s" % (consumption_type, year) year_index = where(consumption.get_attribute("billyear") == year) out_storage = StorageFactory().get_storage( type="flt_storage", storage_location=os.path.join(cache_directory, str(year))) consumption_subset = DatasetSubset(consumption, year_index) consumption_subset.write_dataset( out_storage=out_storage, out_table_name=consumption_type.lower())