def go(): from opus_gui.results_manager.run.indicator_framework.representations.indicator import Indicator import os indicators = { 'zone_jobs': Indicator(dataset_name='zone', attribute='urbansim.zone.number_of_jobs') } from opus_core.configurations.dataset_pool_configuration import DatasetPoolConfiguration from opus_gui.results_manager.run.indicator_framework.maker.source_data import SourceData project_name = 'eugene_gridcell' run_name1 = 'base_year_data' years = [1980, 1980] source_data = SourceData( cache_directory=paths.get_opus_data_path_path(project_name, run_name1), #comparison_cache_directory = '', years=years, dataset_pool_configuration=DatasetPoolConfiguration( package_order=['urbansim', 'opus_core'], ), project_name=project_name) ################################################################ #COMPUTE indicators ################################################################ from opus_gui.results_manager.run.indicator_framework.maker.maker import Maker maker = Maker(project_name) computed_indicators = maker.create_batch(indicators=indicators, source_data=source_data) ############################################ #VISUALIZE the resulting computed indicators ############################################ from opus_gui.results_manager.run.indicator_framework.visualizer.visualization_factory import VisualizationFactory visualizer = VisualizationFactory() visualizations = [] maps = [('zone_jobs', 'matplotlib_chart')] for item in maps: vistype = 'mapnik_map' # default to map if type(item) == type(()): item, vistype = item print "Generating indicator %s" % item visualizations += visualizer.visualize( indicators_to_visualize=[ item ], # override default indicators to visualize (all) computed_indicators=computed_indicators, visualization_type=vistype, name=item) print "Done generating indicators." return dict((v.name, v.get_file_path()) for v in visualizations)
def copy_dummy_travel_data(self): ''' Copies pre-calculated MATSim travel costs, travel times and workplace accessibility into the OPUS HOME tmp directory. ''' # get sensitivity test path as an anchor to determine the location of the MATSim travel_data file #test_dir_path = test_path.__path__[0] # set source location travel_data_source = paths.get_opus_data_path_path('psrc_parcel_cupum_preliminary', 'MATSimTravelData', 'travel_data.csv' ) if not self.travel_data_exsists( travel_data_source ): raise StandardError( 'Dummy MATSim travel data not fould! %s' % travel_data_source ) workplace_accessibility_source = paths.get_opus_data_path_path('psrc_parcel_cupum_preliminary', 'MATSimTravelData', 'zones.csv' ) if not self.travel_data_exsists( workplace_accessibility_source ): raise StandardError( 'Dummy MATSim travel data not fould! %s' % workplace_accessibility_source ) # set destination location destination_dir = paths.get_opus_home_path( "opus_matsim", "tmp" ) if not os.path.exists(destination_dir): try: os.mkdir(destination_dir) except: pass self.travel_data_destination = os.path.join( destination_dir, "travel_data.csv" ) self.workplace_accessibility_destination = os.path.join( destination_dir, "zones.csv" ) logger.log_status("Copying dummy travel data:") logger.log_status("Source: %s" % travel_data_source) logger.log_status("Destination %s:" % self.travel_data_destination) # copy travel data shutil.copy (travel_data_source, self.travel_data_destination) if os.path.isfile (self.travel_data_destination): logger.log_status("Copying successful ...") else: raise StandardError("Test travel data travel_data_destination not copied!") logger.log_status("Copying dummy workplace accessibility indicators:") logger.log_status("Source: %s" % workplace_accessibility_source) logger.log_status("Destination %s:" % self.workplace_accessibility_destination) # copy workplace accessibility indicators shutil.copy (workplace_accessibility_source, self.workplace_accessibility_destination) if os.path.isfile (self.workplace_accessibility_destination): logger.log_status("Copying successful ...") else: raise StandardError("Test travel data workplace_accessibility_destination not copied!")
def main(): REPORTDIR = paths.get_opus_data_path_path('reports') REPORTNAME = 'testindicatorreport' # form is project config, batch name, vis name, data source name, year preconfigured_indicators = { 'population': ('eugene_gridcell_default.xml', 'zone_indicator_batch', 'population', 'base_year_data', 1980), 'jobs': ('eugene_gridcell_default.xml', 'zone_indicator_batch', 'jobs', 'base_year_data', 1980), 'population_density': ('eugene_gridcell_default.xml', 'zone_indicator_batch', 'population_density', 'base_year_data', 1980), 'land_value': ('eugene_gridcell_default.xml', 'zone_indicator_batch', 'land_value', 'base_year_data', 1980), 'table': ('eugene_gridcell_default.xml', 'zone_indicator_batch', 'gridcell_table', 'base_year_data', 1980), } ir = IndicatorReport(preconfigured_indicators) ir.generate_indicators() filepaths = ir.filepaths import hardcoded_indicators hardcoded_visualizatons = hardcoded_indicators.go() for key, value in hardcoded_visualizatons.items(): filepaths[ key] = value # hardcoded indicators are now available for display ir.move_files(filepaths, REPORTDIR, REPORTNAME) def mapindicatornametocell(name): global filepaths if not name: return '' imgname = os.path.basename(filepaths[name]) return '<A HREF="%s"><IMG width=400 src="%s"></a><br>[%s]\n' % ( imgname, imgname, name) f = open(os.path.join(REPORTDIR, REPORTNAME, 'index.html'), 'w') rs = ReportSpec(f) rs.writeheader() rs.writeindicatortable( [['population', 'jobs'], ['population_density', None], ['land_value', None]], mapindicatornametocell, title='Various base year data indicators', headers=['Gridcell data', 'Zone data']) rs.writeindicatortable([['zone_jobs']], mapindicatornametocell, title='Silly demo chart') rs.writesimpletable(filepaths['table'], title='Table of gridcell data for 1980', numrows=20) rs.writefooter() print "Finished generating indicator report"
def setUp(self): """ set up opus data path, a base_year_data cache directory needs to exists or be created through downloading and unzipping etc """ self.opus_home = paths.OPUS_HOME self.data_path = paths.get_opus_data_path_path('sanfrancisco') self.xml_config = XMLConfiguration(os.path.join(self.opus_home, 'project_configs', 'sanfrancisco.xml')) base_year_data_path = os.path.join(self.data_path, 'base_year_data') if not os.path.exists(base_year_data_path): os.makedirs(base_year_data_path)
def setUp(self): """ set up opus data path, a base_year_data cache directory needs to exists or be created through downloading and unzipping etc """ self.opus_home = paths.OPUS_HOME self.data_path = paths.get_opus_data_path_path("psrc_parcel") self.xml_config = XMLConfiguration(os.path.join(self.opus_home, "project_configs", "psrc_parcel_test.xml")) base_year_data_path = os.path.join(self.data_path, "base_year_data") if not os.path.exists(base_year_data_path): os.makedirs(base_year_data_path)
def main(): REPORTDIR = paths.get_opus_data_path_path('reports') REPORTNAME = 'testindicatorreport' # form is project config, batch name, vis name, data source name, year preconfigured_indicators = { 'population': ('eugene_gridcell_default.xml', 'zone_indicator_batch', 'population', 'base_year_data', 1980), 'jobs': ('eugene_gridcell_default.xml', 'zone_indicator_batch', 'jobs', 'base_year_data', 1980), 'population_density': ('eugene_gridcell_default.xml', 'zone_indicator_batch', 'population_density', 'base_year_data', 1980), 'land_value': ('eugene_gridcell_default.xml', 'zone_indicator_batch', 'land_value', 'base_year_data', 1980), 'table': ('eugene_gridcell_default.xml', 'zone_indicator_batch', 'gridcell_table', 'base_year_data', 1980), } ir = IndicatorReport(preconfigured_indicators) ir.generate_indicators() filepaths = ir.filepaths import hardcoded_indicators hardcoded_visualizatons = hardcoded_indicators.go() for key, value in hardcoded_visualizatons.items(): filepaths[key] = value # hardcoded indicators are now available for display ir.move_files(filepaths,REPORTDIR,REPORTNAME) def mapindicatornametocell(name): global filepaths if not name: return '' imgname = os.path.basename(filepaths[name]) return '<A HREF="%s"><IMG width=400 src="%s"></a><br>[%s]\n' % (imgname,imgname,name) f = open(os.path.join(REPORTDIR,REPORTNAME,'index.html'),'w') rs = ReportSpec(f) rs.writeheader() rs.writeindicatortable([['population','jobs'],['population_density',None],['land_value',None]],mapindicatornametocell,title='Various base year data indicators',headers=['Gridcell data','Zone data']) rs.writeindicatortable([['zone_jobs']],mapindicatornametocell,title='Silly demo chart') rs.writesimpletable(filepaths['table'],title='Table of gridcell data for 1980',numrows=20) rs.writefooter() print "Finished generating indicator report"
def __init__(self, output_dir=None, year=None): ''' Constructor ''' # get working path as an anchor e.g. to determine the config file location. self.working_path = test_path.__path__[0] print "Working path: %s" % self.working_path # get config file location self.config_file = os.path.join( self.working_path, 'configs', 'seattle_parcel_travel_cost_test.xml') # get seattle_parcel configuration config = XMLConfiguration( self.config_file ).get_run_configuration( "Seattle_baseline" ) self.input_storage = None # get first simulation year self.year = year if self.year == None: self.year = config['base_year'] base_year_data_path = paths.get_opus_data_path_path('seattle_parcel', 'base_year_data') attribute_cache = AttributeCache(cache_directory=base_year_data_path) self.input_storage = attribute_cache.get_flt_storage_for_year(self.year) else: attribute_cache = AttributeCache().get_flt_storage_for_year(self.year) self.input_storage = attribute_cache # get output dir path output_directory = output_dir if output_directory == None: # set deafult output_directory = paths.get_opus_home_path('opus_matsim', 'tmp') if not os.path.exists( output_directory ): try: os.mkdir( output_directory ) except: pass # init self.csv_data_path = output_directory # os.path.join(output_directory, 'travel_data_dir')
def __init__(self): config = UrbansimParcelConfiguration() data_path_prefix = paths.get_opus_data_path_path('psrc_parcel') config_changes = { 'project_name':'psrc_parcel', 'description':'PSRC parcel baseline', 'cache_directory': os.path.join(data_path_prefix, 'base_year_data'), 'creating_baseyear_cache_configuration':CreatingBaseyearCacheConfiguration( cache_directory_root = os.path.join(data_path_prefix, 'runs'), cache_from_database = False, baseyear_cache = BaseyearCacheConfiguration( years_to_cache = [2000], #existing_cache_to_copy = r'/urbansim_cache/psrc_parcel/runs/cache_hh_persons_init', existing_cache_to_copy = os.path.join(data_path_prefix, 'base_year_data'), ), cache_scenario_database = 'urbansim.model_coordinators.cache_scenario_database', tables_to_cache = [ #'business', 'households', 'buildings', 'parcels', 'gridcells', 'zones', "jobs", "households_for_estimation", "households_for_estimation_LAG1", "jobs_for_estimation", #"development_event_history", "persons", "persons_for_estimation", "travel_data", "building_types", "job_building_types", 'urbansim_constants', "target_vacancies", "home_based_employment_location_choice_model_coefficients", "home_based_employment_location_choice_model_specification", "non_home_based_employment_location_choice_model_coefficients", "non_home_based_employment_location_choice_model_specification", "household_location_choice_model_coefficients", "household_location_choice_model_specification", "real_estate_price_model_coefficients", "real_estate_price_model_specification", "annual_household_control_totals", "annual_relocation_rates_for_households", "household_characteristics_for_ht", "annual_employment_control_totals", "annual_relocation_rates_for_jobs", "land_use_types", "generic_land_use_types", 'employment_sectors', 'employment_adhoc_sector_groups', 'employment_adhoc_sector_group_definitions', 'development_templates', 'development_template_components', 'development_constraints', "building_sqft_per_job", "fazes", "large_areas", "demolition_cost_per_sqft", 'constant_taz_columns', 'zipcodes', 'cities', 'districts', 'area_types', "work_at_home_choice_model_coefficients", "work_at_home_choice_model_specification", "workplace_choice_model_for_resident_coefficients", "workplace_choice_model_for_resident_specification", "development_project_proposals", "development_project_proposals_for_estimation", "school_districts", "tours", ## some attribute coding lookup tables "education", "employment_status", "grade", "race_names", "relationship", "sex", "student", ], tables_to_cache_nchunks={'parcels': 1}, unroll_gridcells = False ), 'scenario_database_configuration': ScenarioDatabaseConfiguration( database_name = 'psrc_2005_parcel_baseyear', #database_name = 'psrc_2005_parcel_baseyear_change_20080804E', #database_name = 'psrc_2005_parcel_baseyear_change_lmwang', ), 'dataset_pool_configuration': DatasetPoolConfiguration( package_order=['psrc_parcel', 'urbansim_parcel', 'urbansim', 'opus_core'], ), # 'models_configuration':models_configuration, 'base_year':2000, 'years':(2001, 2030), 'models':[ # models are executed in the same order as in this list #"process_pipeline_events", "real_estate_price_model", "expected_sale_price_model", "development_proposal_choice_model", "building_construction_model", "modify_workers_jobs_after_moving_households", # from demolished buildings "modify_workers_jobs_after_moving_jobs", # from demolished buildings "household_transition_model", "employment_transition_model", 'job_person_consistency_keeper', "household_relocation_model", "household_location_choice_model", "modify_workers_jobs_after_moving_households", "employment_relocation_model", #{"employment_location_choice_model":{'group_members': '_all_'}}, {"employment_location_choice_model":{'group_members': ['non_home_based']}}, 'distribute_unplaced_jobs_model', 'distribute_unplaced_mining_utilities_jobs_model', "modify_workers_jobs_after_moving_jobs", 'work_at_home_choice_model', 'workplace_choice_model_for_resident' ], 'models_in_year': {2000: [ # This is not run anymore, since all jobs are located and only a few households are not. "household_relocation_model_for_2000", "household_location_choice_model_for_2000", "employment_relocation_model_for_2000", {"employment_location_choice_model":{'group_members': '_all_'}} ] }, 'flush_dataset_to_cache_after_each_model':False, 'flush_variables':False, 'low_memory_run':False, 'datasets_to_cache_after_each_model':["parcel", "building", 'household', 'job', 'development_project_proposal_component', #to be cached for diagnostic purpose (lmwang) 'development_project_proposal', 'travel_data', 'persons'], 'unroll_gridcells':False, "datasets_to_preload":{ 'zone':{}, 'household':{}, 'building':{}, 'parcel':{'package_name':'urbansim_parcel'}, 'development_template': {'package_name':'urbansim_parcel'}, 'development_template_component': {'package_name':'urbansim_parcel'}, 'job':{}, 'person':{'package_name':'urbansim_parcel'}, "building_type":{'package_name':'urbansim_parcel'}, 'travel_data':{}, "job_building_type":{} } } config.replace(config_changes) config['models_configuration']["household_location_choice_model"]["controller"]["import"] = \ {"psrc_parcel.models.household_location_choice_model" : "HouseholdLocationChoiceModel"} config['models_configuration']["employment_location_choice_model"]['controller']["import"] = \ {"psrc_parcel.models.employment_location_choice_model" : "EmploymentLocationChoiceModel"} config['models_configuration']["home_based_employment_location_choice_model"]['controller']["import"] = \ {"psrc_parcel.models.employment_location_choice_model" : "EmploymentLocationChoiceModel"} config['models_configuration']['household_relocation_model_for_2000'] = {} config['models_configuration']['household_relocation_model_for_2000']['controller'] = \ HouseholdRelocationModelConfigurationCreator( location_id_name = 'building_id', probabilities = None, rate_table=None, output_index = 'hrm_index').execute() config['models_configuration']['household_location_choice_model_for_2000'] = Configuration( config['models_configuration']['household_location_choice_model'] ) config['models_configuration']['household_location_choice_model_for_2000']['controller']['run']['arguments']['chunk_specification'] = "{'nchunks':1}" config['models_configuration']['household_location_choice_model_for_2000']['controller']['run']['arguments']['maximum_runs'] = 1 config['models_configuration']['employment_relocation_model_for_2000'] = {} config['models_configuration']['employment_relocation_model_for_2000']['controller'] = \ EmploymentRelocationModelConfigurationCreator( location_id_name = 'building_id', probabilities = None, rate_table=None, output_index = 'erm_index').execute() self.merge(config) if self.multiple_runs: self.sample_inputs()
from opus_core.simulation_state import SimulationState from opus_core.datasets.dataset import Dataset from opus_core.store.attribute_cache import AttributeCache from opus_core.session_configuration import SessionConfiguration from opus_core.storage_factory import StorageFactory from opus_core.paths import get_opus_data_path_path from opus_core.logger import block import cPickle, pickle pickle_filename = '/workspace/price_equilibration/dump_cached.pickle' pickle_data = pickle.load(open(pickle_filename, 'rb')) pickle_filename = '/workspace/price_equilibration/submarket_id.pickle' submkt_data = pickle.load(open(pickle_filename, 'rb')) data_path = get_opus_data_path_path() cache_dir = os.path.join(data_path, 'bay_area_zone/base_year_data.original') year = 2000 simulation_state = SimulationState() simulation_state.set_current_time(year) SimulationState().set_cache_directory(cache_dir) attribute_cache = AttributeCache() dataset_pool = SessionConfiguration(new_instance=True, package_order=['bayarea', 'urbansim_parcel', 'urbansim', 'opus_core'], in_storage=attribute_cache ).get_dataset_pool() hh = dataset_pool.get_dataset('household') proportion = float(pickle_data['Xpagents'].size) / hh.size()
def __init__(self, config, year): """ Constructor """ self.config_dictionary = config self.sub_config_exists = False self.config_destination_location = None # get sub dictionaries from travel model configuration travel_model_configuration, matsim4urbansim_part, common_matsim_part = self.__get_travel_model_sub_dictionaries() # network parameter try: # checks if sub config for matsim network exists self.sub_config_exists = (common_matsim_part['matsim_network_file'] != None) except: pass if self.sub_config_exists: self.check_abolute_path( common_matsim_part['matsim_network_file'] ) self.network_file = paths.get_opus_home_path( common_matsim_part['matsim_network_file'] ) else: raise StandardError('No network given in the "travel_model_configuration" of your current configuration file. A network is required in order to run MATSim. ') self.sub_config_exists = False # input plans file parameter self.input_plans_file = self.__get_plans_file(common_matsim_part, 'input_plans_file') self.hotstart_plans_file = self.__get_plans_file(common_matsim_part, 'hotstart_plans_file') # controler parameter self.first_iteration = first_iteration self.last_iteration = common_matsim_part['last_iteration'] # planCalcScoreType self.activityType_0 = activity_type_0 self.activityType_1 = activity_type_1 # urbansim parameter self.year = year self.population_sampling_rate = matsim4urbansim_part['sampling_rate'] self.opus_home = paths.get_opus_home_path() self.opus_data_path = paths.get_opus_data_path_path() self.matsim4opus_path = paths.get_opus_home_path( matsim4opus ) self.checkAndCreateFolder(self.matsim4opus_path) self.matsim_config_path = os.path.join( self.matsim4opus_path, matsim_config ) self.checkAndCreateFolder(self.matsim_config_path) self.matsim_output_path = os.path.join( self.matsim4opus_path, matsim_output ) self.checkAndCreateFolder(self.matsim_output_path) self.matsim_temp_path = os.path.join( self.matsim4opus_path, matsim_temp ) self.checkAndCreateFolder(self.matsim_temp_path) self.isTestRun = False self.test_parameter = "" try: self.test_parameter = common_matsim_part[ test_parameter ] except: pass self.backup_run_data = False try: self.backup_run_data = common_matsim_part[ backup_run_data ] except: pass self.firstRun = "FALSE" try: # determine for MATSim if this is the fist run if travel_model_configuration['start_year'] == year: self.firstRun = "TRUE" except: pass self.config_destination_location = self.__set_config_destination( self.config_dictionary )
def go(): from opus_gui.results_manager.run.indicator_framework.representations.indicator import Indicator import os indicators = { 'zone_jobs':Indicator( dataset_name = 'zone', attribute = 'urbansim.zone.number_of_jobs') } from opus_core.configurations.dataset_pool_configuration import DatasetPoolConfiguration from opus_gui.results_manager.run.indicator_framework.maker.source_data import SourceData project_name = 'eugene_gridcell' run_name1 = 'base_year_data' years = [1980, 1980] source_data = SourceData( cache_directory = paths.get_opus_data_path_path(project_name,run_name1), #comparison_cache_directory = '', years = years, dataset_pool_configuration = DatasetPoolConfiguration( package_order=['urbansim','opus_core'], ), project_name = project_name ) ################################################################ #COMPUTE indicators ################################################################ from opus_gui.results_manager.run.indicator_framework.maker.maker import Maker maker = Maker(project_name) computed_indicators = maker.create_batch( indicators = indicators, source_data = source_data) ############################################ #VISUALIZE the resulting computed indicators ############################################ from opus_gui.results_manager.run.indicator_framework.visualizer.visualization_factory import VisualizationFactory visualizer = VisualizationFactory() visualizations = [] maps = [('zone_jobs','matplotlib_chart')] for item in maps: vistype = 'mapnik_map' # default to map if type(item) == type(()): item, vistype = item print "Generating indicator %s" % item visualizations += visualizer.visualize( indicators_to_visualize = [item], # override default indicators to visualize (all) computed_indicators = computed_indicators, visualization_type = vistype, name = item) print "Done generating indicators." return dict((v.name,v.get_file_path()) for v in visualizations)
# Copyright (C) 2010-2011 University of California, Berkeley, 2005-2009 University of Washington # See opus_core/LICENSE import os, cPickle, time, sys, string, StringIO try: from bayarea.accessibility.pyaccess import PyAccess except: from bayarea.accessibility.pyaccess import PyAccess from urbansim.datasets.dataset import Dataset as UrbansimDataset from opus_core.session_configuration import SessionConfiguration from opus_core import paths import numpy from numpy import array MAXDISTANCE=1500 path = paths.get_opus_data_path_path("bay_area_parcel","network.jar") d = cPickle.load(open(path)) pya = PyAccess() pya.createGraph(1,d['nodeids'],d['nodes'],d['edges'],d['edgeweights']) pya.precomputeRange(MAXDISTANCE) pya.initializePOIs(7,MAXDISTANCE,1) dataset_pool = SessionConfiguration().get_dataset_pool() transit_set = dataset_pool.get_dataset('transit_station') x = transit_set['x'] y = transit_set['y'] route_type = transit_set['route_type'] agency_id = transit_set['agency_id'] #x = numpy.load((os.path.join(paths.get_opus_data_path_path('bay_area_parcel','base_year_data','2010','transit_stations','x.lf4')))) #y = numpy.load((os.path.join(paths.get_opus_data_path_path('bay_area_parcel','base_year_data','2010','transit_stations','y.lf4')))) for i in range(6): if i == 1: # bart
def main(): project_name = 'eugene_gridcell' run_name1 = 'run_6473.2008_05_11_22_27' run_name2 = 'run_6478.2008_05_12_19_04' source_data = SourceData( cache_directory=paths.get_opus_data_path_path( project_name, 'runs', run_name1), # r'D:\urbansim_cache\run_1090.2006_11_14_12_12', # comparison_cache_directory = os.path.join(os.environ['OPUS_DATA_PATH'],project_name,'runs',run_name2), years=[1980, 1981], dataset_pool_configuration=DatasetPoolConfiguration( package_order=['eugene', 'urbansim', 'opus_core'], ), ) indicators = [ Map( source_data=source_data, dataset_name='zone', attribute='urbansim.zone.population', years=[1980], ), # Chart( # source_data = source_data, # dataset_name = 'gridcell', # attribute = 'urbansim.gridcell.population', # ), # # Table( # source_data = source_data, # dataset_name = 'zone', # attribute = 'urbansim.zone.industrial_sqft', # output_type = 'tab' # ), # Table( # source_data = source_data, # dataset_name = 'zone', # attribute = 'urbansim.zone.industrial_sqft', # output_type = 'dbf', # years = [1980, 1981] # ), # GeotiffMap( # source_data = source_data, # dataset_name = 'gridcell', # package = 'psrc', # attribute = 'urbansim.gridcell.number_of_jobs', # name = 'jobs', # ), # DatasetTable( # source_data = source_data, # dataset_name = 'zone', # name = 'pop_and_ind_sqft', # attributes = [ # 'urbansim.zone.population', # 'urbansim.zone.industrial_sqft', # ], # exclude_condition = 'urbansim.zone.population<100' #this accepts any opus expression # ), #Expression example # Table( # source_data = source_data, # dataset_name = 'large_area', # name = 'de_population_change', # attribute = 'psrc.large_area.de_population_DDDD - psrc.large_area.de_population_2000', # ), #example of using an operation ("change since baseyear"). Other available operations #are "percent_change" and "size" (of the dataset) # Table( # source_data = source_data, # attribute = 'urbansim.faz.population', # dataset_name = 'faz', # name = 'population_change(DDDD-00)', # operation = 'change', # years = [1980] # ), #example using regional-level aggregators # Table( # attribute = 'alldata.aggregate_all(urbansim.zone.number_of_home_based_jobs)', # dataset_name = 'alldata', # source_data = source_data, # name = 'number_of_home_based_jobs', # years = [1980, 1981] # ), ] from opus_core.indicator_framework.core.indicator_factory import IndicatorFactory IndicatorFactory().create_indicators(indicators=indicators, display_error_box=False, show_results=True)
name="bayarea.travel_model.invoke_run_travel_model", type="selectable") import_tm = etree.Element("selectable", name="bayarea.travel_model.import_travel_model_data", type="selectable") travel_model = os.getenv("HUDSON_TRAVEL_MODEL") tm_home = os.getenv("HUDSON_TRAVEL_MODEL_HOME") tm_sshfs = os.getenv("HUDSON_TRAVEL_MODEL_SSHFS") if travel_model: if (travel_model == "true") or (travel_model == "FULL"): invoke_tm.text = "True" import_tm.text = "True" elif travel_model == "SKIMS": invoke_tm.text = "False" import_tm.text = "True" tm_home = os.path.join(get_opus_data_path_path(), project_name, 'travel_model_skims') tm_sshfs = None else: invoke_tm.text = "False" import_tm.text = "False" tm_home = None tm_sshfs = None models.append(invoke_tm) models.append(import_tm) scenario.append(tmc) # set up a project-specific travel model base directory if necessary. if tm_home:
def __init__(self, config, year): """ Constructor """ #try: # tnicolai :for debugging # import pydevd # pydevd.settrace() #except: pass self.config_dictionary = config self.sub_config_exists = False self.config_destination_location = None # get directories self.opus_home = paths.get_opus_home_path() self.opus_data_path = paths.get_opus_data_path_path() self.matsim4opus_path = paths.get_opus_home_path( 'matsim4opus' ) self.checkAndCreateFolder(self.matsim4opus_path) cache_directory = config['cache_directory'] matsim4opus_target_path = os.path.join(cache_directory, 'matsim4opus') self.matsim_config_path = os.path.join( matsim4opus_target_path, 'matsim_config' ) # get sub dictionaries from travel model configuration # get travel model parameter from the opus dictionary travel_model_configuration = self.config_dictionary['travel_model_configuration'] # contains matsim4urbansim and matsim_config parameter # matsim4urbansim self.matsim4urbansim_dict = travel_model_configuration['matsim4urbansim'] # contains parameter for matsim/urbansim integration # matsim_config self.matsim_config_dict = travel_model_configuration['matsim_config'] # contains various matsim_config parameter self.accessibility_dict = self.matsim_config_dict['accessibility'] self.urbansim_zone_random_location_distribution_dict = self.matsim_config_dict['urbansim_zone_random_location_distribution'] self.common_dict = self.matsim_config_dict['common'] self.plan_calc_score_dict = self.matsim_config_dict['plan_calc_score'] ########################### # matsim4urbansim parameter ########################### self.matsim4urbansim_population_sampling_rate = self.matsim4urbansim_dict['population_sampling_rate'] self.matsim4urbansim_custom_parameter = self.matsim4urbansim_dict['custom_parameter'] self.matsim4urbansim_backup = self.__get_value_as_boolean('backup_run_data', self.matsim4urbansim_dict['backup']) self.matsim4urbansim_matsim_data_to_compute_zone2zone_impedance = self.__get_value_as_boolean('zone2zone_impedance', self.matsim4urbansim_dict['matsim_data_to_compute']) self.matsim4urbansim_matsim_data_to_compute_agent_performance = self.__get_value_as_boolean('agent_performance', self.matsim4urbansim_dict['matsim_data_to_compute']) self.matsim4urbansim_matsim_data_to_compute_zone_based_accessibility = self.__get_value_as_boolean('zone_based_accessibility', self.matsim4urbansim_dict['matsim_data_to_compute']) self.matsim4urbansim_matsim_data_to_compute_parcel_based_accessibility = self.__get_value_as_boolean('parcel_based_accessibility', self.matsim4urbansim_dict['matsim_data_to_compute']) self.matsim4urbansim_year = year self.matsim4urbansim_matsim_config_path = os.path.join( matsim4opus_target_path, 'matsim_config' ) self.checkAndCreateFolder(self.matsim4urbansim_matsim_config_path) self.matsim4urbansim_matsim_output_path = os.path.join( matsim4opus_target_path, 'output' ) self.checkAndCreateFolder(self.matsim4urbansim_matsim_output_path) self.matsim4urbansim_matsim_temp_path = os.path.join( matsim4opus_target_path, 'tmp' ) self.checkAndCreateFolder(self.matsim4urbansim_matsim_temp_path) ########################### # matsim_config parameter ########################### self.matsim_config_urbansim_zone_random_location_distribution_by_radius = self.urbansim_zone_random_location_distribution_dict['by_radius'] self.matsim_config_urbansim_zone_random_location_distribution_by_shape_file = self.__get_string_value(self.urbansim_zone_random_location_distribution_dict['by_zone_shape_file']) # matsim_config/accessibility parameter self.matsim_config_accessibility_cell_size = self.accessibility_dict['cell_size'] self.matsim_config_accessibility_study_area_boundary_shape_file = self.__get_string_value(self.accessibility_dict['study_area_boundary_shape_file']) self.matsim_config_accessibility_bounding_box_left = self.accessibility_dict['bounding_box_left'] self.matsim_config_accessibility_bounding_box_bottom = self.accessibility_dict['bounding_box_bottom'] self.matsim_config_accessibility_bounding_box_top = self.accessibility_dict['bounding_box_top'] self.matsim_config_accessibility_bounding_box_right = self.accessibility_dict['bounding_box_right'] accessibility_computation_area = self.accessibility_dict['accessibility_computation_area'] # loading sub directory ... if not(accessibility_computation_area.__len__ != 1): logger.log_error("Please select ONE item in 'travel_model_configuration/matsim_config/accessibility/accessibility_computation_area' to determine how the study area for the accessibility computation!") exit() self.matsim_config_accessibility_accessibility_computation_area_from_shapefile = self.__get_value_as_boolean( 'from_shapefile', accessibility_computation_area ) self.matsim_config_accessibility_accessibility_computation_area_from_bounding_box = self.__get_value_as_boolean( 'from_bounding_box', accessibility_computation_area ) self.matsim_config_accessibility_accessibility_computation_area_from_network = self.__get_value_as_boolean( 'from_network', accessibility_computation_area ) # matsim_config/common parameter self.matsim_config_common_network_file = self.__get_file_location( self.common_dict['network'], required=True) self.matsim_config_common_first_iteration = 0 self.matsim_config_common_last_iteration = self.common_dict['last_iteration'] self.matsim_config_common_external_matsim_configuration = self.__get_external_matsim_config_for_current_year(self.common_dict['external_matsim_config'], year) self.matsim_config_common_warm_start_plans_file = self.__get_plans_file(self.common_dict, 'warm_start_plans_file') self.matsim_config_common_use_hot_start = self.__get_value_as_boolean( 'use_hot_start', self.common_dict['hot_start'] ) self.matsim_config_common_hot_start_plans_file = '' if self.matsim_config_common_use_hot_start: self.matsim_config_common_hot_start_plans_file = os.path.join(matsim4opus_target_path, 'hot_start_plans_file.xml.gz') # matsim_config/plan_calc_score parameter self.matsim_config_plan_calc_score_work_activity_opening_time = self.plan_calc_score_dict['work_activity_opening_time'] self.matsim_config_plan_calc_score_home_activity_typical_duration = self.plan_calc_score_dict['home_activity_typical_duration'] self.matsim_config_plan_calc_score_work_activity_typical_duration = self.plan_calc_score_dict['work_activity_typical_duration'] self.matsim_config_plan_calc_score_work_activity_latest_start_time = self.plan_calc_score_dict['work_activity_latest_start_time'] self.matsim_config_plan_calc_score_activityType_0 = 'home' self.matsim_config_plan_calc_score_activityType_1 = 'work' # setting destination location for generated matsim config self.config_destination_location = os.path.join( self.matsim_config_path, config['project_name'] + "_matsim_config.xml" ) logger.log_status('MATSim4UrbanSim config file will be written to %s' %self.config_destination_location)
def main(): project_name = 'eugene_gridcell' run_name1 = 'run_6473.2008_05_11_22_27' run_name2 = 'run_6478.2008_05_12_19_04' source_data = SourceData( cache_directory = paths.get_opus_data_path_path(project_name,'runs',run_name1), # r'D:\urbansim_cache\run_1090.2006_11_14_12_12', # comparison_cache_directory = os.path.join(os.environ['OPUS_DATA_PATH'],project_name,'runs',run_name2), years = [1980, 1981], dataset_pool_configuration = DatasetPoolConfiguration( package_order=['eugene','urbansim','opus_core'], ), ) indicators = [ Map( source_data = source_data, dataset_name = 'zone', attribute = 'urbansim.zone.population', years = [1980], ), # Chart( # source_data = source_data, # dataset_name = 'gridcell', # attribute = 'urbansim.gridcell.population', # ), # # Table( # source_data = source_data, # dataset_name = 'zone', # attribute = 'urbansim.zone.industrial_sqft', # output_type = 'tab' # ), # Table( # source_data = source_data, # dataset_name = 'zone', # attribute = 'urbansim.zone.industrial_sqft', # output_type = 'dbf', # years = [1980, 1981] # ), # GeotiffMap( # source_data = source_data, # dataset_name = 'gridcell', # package = 'psrc', # attribute = 'urbansim.gridcell.number_of_jobs', # name = 'jobs', # ), # DatasetTable( # source_data = source_data, # dataset_name = 'zone', # name = 'pop_and_ind_sqft', # attributes = [ # 'urbansim.zone.population', # 'urbansim.zone.industrial_sqft', # ], # exclude_condition = 'urbansim.zone.population<100' #this accepts any opus expression # ), #Expression example # Table( # source_data = source_data, # dataset_name = 'large_area', # name = 'de_population_change', # attribute = 'psrc.large_area.de_population_DDDD - psrc.large_area.de_population_2000', # ), #example of using an operation ("change since baseyear"). Other available operations #are "percent_change" and "size" (of the dataset) # Table( # source_data = source_data, # attribute = 'urbansim.faz.population', # dataset_name = 'faz', # name = 'population_change(DDDD-00)', # operation = 'change', # years = [1980] # ), #example using regional-level aggregators # Table( # attribute = 'alldata.aggregate_all(urbansim.zone.number_of_home_based_jobs)', # dataset_name = 'alldata', # source_data = source_data, # name = 'number_of_home_based_jobs', # years = [1980, 1981] # ), ] from opus_core.indicator_framework.core.indicator_factory import IndicatorFactory IndicatorFactory().create_indicators( indicators = indicators, display_error_box = False, show_results = True)
# Copyright (C) 2010-2011 University of California, Berkeley, 2005-2009 University of Washington # See opus_core/LICENSE import os, cPickle, time, sys, string, StringIO try: from drcog.accessibility.pyaccess import PyAccess except: from drcog.accessibility.pyaccess import PyAccess from urbansim.datasets.dataset import Dataset as UrbansimDataset from opus_core.session_configuration import SessionConfiguration from opus_core import paths import numpy from numpy import array MAXDISTANCE=1500 path = paths.get_opus_data_path_path("drcog","network.jar") d = cPickle.load(open(path)) pya = PyAccess() pya.createGraph(1,d['nodeids'],d['nodes'],d['edges'],d['edgeweights']) pya.precomputeRange(MAXDISTANCE) pya.initializePOIs(7,MAXDISTANCE,1) # dataset_pool = SessionConfiguration().get_dataset_pool() # transit_set = dataset_pool.get_dataset('transit_station') # x = transit_set['x'] # y = transit_set['y'] # route_type = transit_set['route_type'] # agency_id = transit_set['agency_id'] #x = numpy.load((os.path.join(paths.get_opus_data_path_path('bay_area_parcel','base_year_data','2010','transit_stations','x.lf4')))) #y = numpy.load((os.path.join(paths.get_opus_data_path_path('bay_area_parcel','base_year_data','2010','transit_stations','y.lf4'))))
def __init__(my): my.isr = cPickle.load(open(os.path.join(paths.get_opus_data_path_path(),'bay_area_parcel','isr.jar'))) '''
def __init__(self, config, year): """ Constructor """ #try: # tnicolai :for debugging # import pydevd # pydevd.settrace() #except: pass self.config_dictionary = config self.sub_config_exists = False self.config_destination_location = None # get sub dictionaries from travel model configuration matsim4urbansim, matsim_controler, matsim_controler_parameter, matsim_accessibility_parameter, matsim_common, matsim_plan_calc_score, matsim_strategy = self.__get_travel_model_sub_dictionaries() # network parameter self.network_file = self.__get_file_location( matsim_common['matsim_network_file'], required=True) # input plans file parameter self.input_plans_file = self.__get_plans_file(matsim_common, warmstart_flag) self.hotstart_plans_file = self.__get_plans_file(matsim_common, hotstart_flag) #if self.hotstart_plans_file == None or self.hotstart_plans_file == "": # self.hotstart_plans_file = "matsim4opus/tmp/hotStartPlansFile.xml" # logger.log_note("Setting location for hot start plans file at %s" %self.hotstart_plans_file) # controler parameter self.first_iteration = first_iteration self.last_iteration = matsim_common['last_iteration'] self.matsim_configuration = self.__get_external_matsim_config_for_current_year(matsim_common['external_matsim_config'], year) #self.matsim_configuration = self.__get_file_location( matsim_common['matsim_config'] ) # planCalcScoreType self.activityType_0 = activity_type_0 self.activityType_1 = activity_type_1 self.home_activity_typical_duration = matsim_plan_calc_score['home_activity_typical_duration'] self.work_activity_typical_duration = matsim_plan_calc_score['work_activity_typical_duration'] self.work_activity_opening_time = matsim_plan_calc_score['work_activity_opening_time'] self.work_activity_latest_start_time= matsim_plan_calc_score['work_activity_latest_start_time'] # strategyType self.max_agent_plan_memory_size = matsim_strategy['max_agent_plan_memory_size'] self.time_accocation_mutator_probability = matsim_strategy['time_accocation_mutator_probability'] self.change_exp_beta_probability = matsim_strategy['change_exp_beta_probability'] self.reroute_dijkstra_probability = matsim_strategy['reroute_dijkstra_probability'] # urbansim parameter self.year = year self.population_sampling_rate = matsim4urbansim['population_sampling_rate'] self.random_location_distribution_radius_for_urbansim_zone = matsim4urbansim['random_location_distribution_radius_for_urbansim_zone'] self.opus_home = paths.get_opus_home_path() self.opus_data_path = paths.get_opus_data_path_path() self.matsim4opus_path = paths.get_opus_home_path( matsim4opus ) self.checkAndCreateFolder(self.matsim4opus_path) cache_directory = config['cache_directory'] matsim4opus_target_path = os.path.join(cache_directory, matsim4opus) self.matsim_config_path = os.path.join( matsim4opus_target_path, matsim_config ) self.checkAndCreateFolder(self.matsim_config_path) self.matsim_output_path = os.path.join( matsim4opus_target_path, matsim_output ) self.checkAndCreateFolder(self.matsim_output_path) self.matsim_temp_path = os.path.join( matsim4opus_target_path, matsim_temp ) self.checkAndCreateFolder(self.matsim_temp_path) self.isTestRun = False self.test_parameter = "" try: self.test_parameter = matsim_common[ test_parameter ] except: pass self.backup_run_data = self.__get_value_as_boolean( backup_run_data, matsim_common['backup']) # matsim4urbansim controler self.zone2zone_impedance = self.__get_value_as_boolean( 'zone2zone_impedance', matsim_controler ) self.agent_performance = self.__get_value_as_boolean( 'agent_performance', matsim_controler ) self.zone_based_accessibility = self.__get_value_as_boolean( 'zone_based_accessibility', matsim_controler ) self.cell_based_accessibility = self.__get_value_as_boolean( 'cell_based_accessibility', matsim_controler ) self.cell_size = matsim_controler_parameter['cell_size'] self.use_bounding_box = self.__get_value_as_boolean( 'use_bounding_box', matsim_controler_parameter['bounding_box']) self.bounding_box_top = matsim_controler_parameter['bounding_box_top'] self.bounding_box_left = matsim_controler_parameter['bounding_box_left'] self.bounding_box_right = matsim_controler_parameter['bounding_box_right'] self.bounding_box_bottom = matsim_controler_parameter['bounding_box_bottom'] self.shape_file = self.__get_file_location( matsim_controler_parameter['shape_file'] ) # matsim4urbansim accessibility parameter self.accessibility_destination_sampling_rate= matsim_accessibility_parameter['accessibility_destination_sampling_rate'] use_MATSim_parameter = matsim_accessibility_parameter['use_MATSim_parameter'] self.use_logit_scale_parameter_from_MATSim = self.__get_value_as_boolean( 'use_logit_scale_parameter_from_MATSim', use_MATSim_parameter ) self.use_car_parameter_from_MATSim = self.__get_value_as_boolean( 'use_car_parameter_from_MATSim', use_MATSim_parameter ) self.use_walk_parameter_from_MATSim = self.__get_value_as_boolean( 'use_walk_parameter_from_MATSim', use_MATSim_parameter ) self.use_raw_sums_without_ln = self.__get_value_as_boolean( 'use_raw_sums_without_ln', use_MATSim_parameter ) self.logit_scale_parameter = matsim_accessibility_parameter['logit_scale_parameter'] # beta car values car_parameter = matsim_accessibility_parameter['car_parameter'] self.betacar_travel_time = car_parameter['betacar_travel_time'] self.betacar_travel_time_power2 = car_parameter['betacar_travel_time_power2'] self.betacar_ln_travel_time = car_parameter['betacar_ln_travel_time'] self.betacar_travel_distance = car_parameter['betacar_travel_distance'] self.betacar_travel_distance_power2 = car_parameter['betacar_travel_distance_power2'] self.betacar_ln_travel_distance = car_parameter['betacar_ln_travel_distance'] self.betacar_travel_cost = car_parameter['betacar_travel_cost'] self.betacar_travel_cost_power2 = car_parameter['betacar_travel_cost_power2'] self.betacar_ln_travel_cost = car_parameter['betacar_ln_travel_cost'] # beta walk values walk_parameter = matsim_accessibility_parameter['walk_parameter'] self.betawalk_travel_time = walk_parameter['betawalk_travel_time'] self.betawalk_travel_time_power2 = walk_parameter['betawalk_travel_time_power2'] self.betawalk_ln_travel_time = walk_parameter['betawalk_ln_travel_time'] self.betawalk_travel_distance = walk_parameter['betawalk_travel_distance'] self.betawalk_travel_distance_power2 = walk_parameter['betawalk_travel_distance_power2'] self.betawalk_ln_travel_distance = walk_parameter['betawalk_ln_travel_distance'] self.betawalk_travel_cost = walk_parameter['betawalk_travel_cost'] self.betawalk_travel_cost_power2 = walk_parameter['betawalk_travel_cost_power2'] self.betawalk_ln_travel_cost = walk_parameter['betawalk_ln_travel_cost'] self.config_destination_location = self.__set_config_destination( self.config_dictionary )