def __init__(
        self,
        model,
        year,
        scenario_name=None,
        model_group=None,
        configuration=None,
        xml_configuration=None,
        cache_directory=None,
    ):
        self.model_group = model_group
        self.explored_model = model

        if configuration is None:
            if xml_configuration is None:
                raise StandardError, "Either dictionary based or XML based configuration must be given."
            config = xml_configuration.get_run_configuration(scenario_name)
        else:
            config = Configuration(configuration)

        self.scenario_models = config["models"]
        if config.get("models_in_year", None) is not None and config["models_in_year"].get(year, None) is not None:
            del config["models_in_year"][year]
        if model is not None:
            dependent_models = config["models_configuration"][model]["controller"].get("dependencies", [])
            config["models"] = dependent_models
            if model_group is None:
                config["models"] = config["models"] + [{model: ["run"]}]
            else:
                config["models"] = config["models"] + [{model: {"group_members": [{model_group: ["run"]}]}}]
        else:
            config["models"] = []

        config["years"] = [year, year]
        config["datasets_to_cache_after_each_model"] = []
        config["flush_variables"] = False

        self.config = Resources(config)
        self.xml_configuration = xml_configuration

        if cache_directory is None:
            cache_directory = config["creating_baseyear_cache_configuration"].baseyear_cache.existing_cache_to_copy
        self.simulation_state = SimulationState(
            new_instance=True, base_cache_dir=cache_directory, start_time=config.get("base_year", 0)
        )
        self.config["cache_directory"] = cache_directory

        SessionConfiguration(
            new_instance=True,
            package_order=self.config["dataset_pool_configuration"].package_order,
            in_storage=AttributeCache(),
        )
 def __new__(cls, *args, **kwargs):
     an_instance = object.__new__(cls)
     default_config = Configuration(an_instance.get_configuration())["init"]
     config = None
     if "model_configuration" in kwargs.keys():
         config = kwargs["model_configuration"]
         del kwargs["model_configuration"]
     an_instance.model_configuration = default_config.merge_defaults_with_arguments_and_config(
                             config, **kwargs)
                             
     if 'run' in map(lambda (name, obj): name, getmembers(an_instance, isroutine)):
         run_method = an_instance.run
         def config_run_method (*req_args, **opt_args):
             default_config = Configuration(an_instance.get_configuration())["run"]
             an_instance.model_configuration = default_config.merge_defaults_with_arguments_and_config(
                             an_instance.model_configuration, **opt_args)
             results = run_method(*req_args, **opt_args)                
             return results
         an_instance.run = config_run_method                        
    def __init__(self):
        Configuration.__init__(self)
        self['residential_regional_development_project_location_choice_model'] = {
                    'controller': RegionalDevelopmentProjectLocationChoiceModelConfigurationCreator(
                        project_type = 'residential',
                        coefficients_table = 'residential_development_location_choice_model_coefficients',
                        specification_table = 'residential_development_location_choice_model_specification',
                        #submodel_string = None
                        ).execute(),
                    }
        self['commercial_regional_development_project_location_choice_model'] = {
                    'controller': RegionalDevelopmentProjectLocationChoiceModelConfigurationCreator(
                        project_type = 'commercial',
                        coefficients_table = 'commercial_development_location_choice_model_coefficients',
                        specification_table = 'commercial_development_location_choice_model_specification',
                        #submodel_string = None
                        ).execute(),
                    }
        self['industrial_regional_development_project_location_choice_model'] = {
                    'controller': RegionalDevelopmentProjectLocationChoiceModelConfigurationCreator(
                        project_type = 'industrial',
                        coefficients_table = 'industrial_development_location_choice_model_coefficients',
                        specification_table = 'industrial_development_location_choice_model_specification',
                        #submodel_string = None
                        ).execute(),
                    }
        self['regional_development_project_transition_model'] =  {
                    'controller': RegionalDevelopmentProjectTransitionModelConfigurationCreator(
                        output_results = 'dptm_results',
                        ).execute(),
                    }
        self['regional_household_transition_model'] = {
                    'controller': RegionalHouseholdTransitionModelConfigurationCreator().execute(),
                    }
        self['regional_employment_transition_model'] = {
                    'controller': RegionalEmploymentTransitionModelConfigurationCreator().execute(),
                    }
        self['regional_employment_location_choice_model'] = {
                    'controller': RegionalEmploymentLocationChoiceModelConfigurationCreator(
                        ).execute(),
                    }
        self['home_based_regional_employment_location_choice_model'] = {
                    'controller': HomeBasedRegionalEmploymentLocationChoiceModelConfigurationCreator(
                        ).execute(),
                    }
        self['governmental_regional_employment_location_choice_model'] = {
                    'controller': GovernmentalRegionalEmploymentLocationChoiceModelConfigurationCreator(
                        ).execute(),
                    }
        self['regional_household_location_choice_model'] = {
                    'controller': RegionalHouseholdLocationChoiceModelConfigurationCreator(
                        ).execute(),
                                                            }
        self['regional_household_relocation_model'] = {
                    'controller': RegionalHouseholdRelocationModelConfigurationCreator(
                        ).execute(),
                    }
        self['regional_employment_relocation_model'] = {
                    'controller': RegionalEmploymentRelocationModelConfigurationCreator(
                        ).execute(),
                    }
        self['regional_distribute_unplaced_jobs_model'] = {
                    'controller': RegionalDistributeUnplacedJobsModelConfigurationCreator(
                        ).execute(),
                    }
        self['jobs_event_model'] = {
                    'controller': JobsEventModelConfigurationCreator(
                        ).execute(),
                    }
        self['households_event_model'] = {
                    'controller': HouseholdsEventModelConfigurationCreator(
                        ).execute(),
                    }

#if __name__ == '__main__':
#    ControllerConfiguration()
Example #4
0
 def __init__(self):
     Configuration.__init__(self, config)
     self.merge(my_configuration)
     if not my_configuration['creating_baseyear_cache_configuration'].cache_from_database:
         del self["input_configuration"] # don't bother with the database if everything is in cache
Example #5
0
 def __init__(self):
     Configuration.__init__(self, self.__my_configuration())
 def __init__(self):
     Configuration.__init__(
         self,
         data={
             "scenario_database_configuration": ScenarioDatabaseConfiguration(database_name="washtenaw_class"),
             "datasets_to_cache_after_each_model": [],
             "low_memory_mode": False,
             "creating_baseyear_cache_configuration": CreatingBaseyearCacheConfiguration(
                 unroll_gridcells=True,
                 cache_from_database=False,
                 baseyear_cache=BaseyearCacheConfiguration(
                     existing_cache_to_copy="/urbansim_cache/workshop/cache_source",
                     # years_to_cache  = range(1996,2001)
                 ),
                 tables_to_cache=[
                     "annual_employment_control_totals",
                     "annual_household_control_totals",
                     "buildings",
                     "building_types",
                     "development_event_history",
                     "gridcells",
                     "households",
                     "job_building_types",
                     "jobs",
                     "travel_data",
                     "zones",
                     "counties",
                     "commercial_development_location_choice_model_coefficients",
                     "commercial_development_location_choice_model_specification",
                     "commercial_employment_location_choice_model_coefficients",
                     "commercial_employment_location_choice_model_specification",
                     "home_based_employment_location_choice_model_specification",
                     "home_based_employment_location_choice_model_coefficients",
                     "industrial_employment_location_choice_model_coefficients",
                     "industrial_employment_location_choice_model_specification",
                     "industrial_development_location_choice_model_coefficients",
                     "industrial_development_location_choice_model_specification",
                     "residential_development_location_choice_model_coefficients",
                     "residential_development_location_choice_model_specification",
                     "fazes",
                     "urbansim_constants",
                     "household_location_choice_model_coefficients",
                     "household_location_choice_model_specification",
                     "land_price_model_coefficients",
                     "land_price_model_specification",
                     "residential_land_share_model_coefficients",
                     "residential_land_share_model_specification",
                     "plan_type_group_definitions",
                     "plan_type_groups",
                     "large_areas",
                     "household_characteristics_for_ht",
                     "development_types",
                     "development_type_group_definitions",
                     "development_constraints",
                     "annual_relocation_rates_for_households",
                     "annual_relocation_rates_for_jobs",
                     "base_year",
                     "cities",
                     "development_events",
                     "development_type_groups",
                     "employment_adhoc_sector_group_definitions",
                     "employment_adhoc_sector_groups",
                     "employment_sectors",
                     "plan_types",
                     "race_names",
                     "target_vacancies",
                     "jobs_for_estimation",
                     "households_for_estimation",
                     "development_events_exogenous",
                     "job_building_types",
                 ],
                 tables_to_cache_nchunks={"gridcells": 1},
                 tables_to_copy_to_previous_years={
                     "development_type_group_definitions": 1995,
                     "development_type_groups": 1995,
                     "development_types": 1995,
                     "development_constraints": 1995,
                     "urbansim_constants": 1995,
                 },
             ),
             "dataset_pool_configuration": DatasetPoolConfiguration(
                 package_order=["washtenaw", "urbansim", "opus_core"]
             ),
             "base_year": 2000,
             "years": (2000, 2000),
         },
     )
 def __init__(self):
     Configuration.__init__(self)
     estimation_changes = self._get_estimation_changes()
     self.merge(estimation_changes)
 def __init__(self):
     my_config = self._get_initial_config()
     Configuration.__init__(self, my_config)
Example #9
0
    def __init__(self, model, specification_module=None,
                 xml_configuration=None, model_group=None, configuration={},
                 save_estimation_results=False):
        """
        If 'specification_module' is given, it contains the specification defined as a dictionary in a module.
        Alternatively, the specification can be passed in an xml format in the 'xml_configuration' argument
        (which should be an instance of XMLConfiguration).
        If both of those arguments are None, the specification is taken from the cache.
        'configuration' is an Opus configuration.
        It can contain an entry 'config_changes_for_estimation' which is a dictionary
        where keys are model names and values are controller changes for that model.
        If 'configuration' is None, it is taken from 'xml_configuration'.
        If xml_configuration is used, and if it has a non-empty expression library, the dictionary representing
        the expression library is added to the configuration under the key 'expression_library'.
        If save_estimation_results is True, the estimation results are saved in the output configuration
        (if given in 'configuration') and in the cache.
        """
        self.specification_module = specification_module
        self.xml_configuration = xml_configuration
        self.model_group = model_group
        self.estimated_model = model
        self.explored_model = model

        if configuration is None:
            if self.xml_configuration is None:
                raise StandardError, "Either dictionary based or XML based configuration must be given."
            config = self.xml_configuration.get_estimation_configuration(model, model_group)
        else:
            config = Configuration(configuration)
        config_changes = config.get('config_changes_for_estimation', {})

        specification_dict=None
        if self.xml_configuration is not None:
            specification_dict = self.xml_configuration.get_estimation_specification(model, model_group)

        if model_group is None:
            if model in config_changes.keys():
                config.merge(config_changes[model])
            else:
                config['models'] = [{model: ["estimate"]}]
            if specification_module is not None:
                config = update_controller_by_specification_from_module(
                                config, model, specification_module)
            elif specification_dict is not None:
                config = update_controller_by_specification_from_dict(config, model, specification_dict)
        else:
            if model in config_changes.keys():
                if model_group in config_changes[model]:
                    config.merge(config_changes[model][model_group])
                else:
                    config.merge(config_changes[model])
            else:
                config['models'] = [{model: {"group_members": [{model_group: ["estimate"]}]}}]
            if (specification_module is not None) or (specification_dict is not None):
                if '%s_%s' % (model_group, model) in config["models_configuration"].keys():
                    model_name_in_configuration = '%s_%s' % (model_group, model)
                else:
                    model_name_in_configuration = model
                if specification_module is not None:
                    config = update_controller_by_specification_from_module(config, model_name_in_configuration, specification_module)
                    config["models_configuration"][model_name_in_configuration]["controller"]["prepare_for_estimate"]["arguments"]["specification_dict"] = "spec['%s']" % model_group
                else:
                    config = update_controller_by_specification_from_dict(config, model, specification_dict[model_group])

            if model.startswith('%s_' % model_group):
                config['model_name_for_coefficients'] = model
            else:
                config['model_name_for_coefficients'] = '%s_%s' % (model_group, model)

        Estimator.__init__(self, config, save_estimation_results=save_estimation_results)
 def get_configuration(self):
     run_configuration = Configuration(config)
     local_configuration = self.get_local_configuration()
     run_configuration.merge(local_configuration)
     return run_configuration
Example #11
0
 def config_run_method (*req_args, **opt_args):
     default_config = Configuration(an_instance.get_configuration())["run"]
     an_instance.model_configuration = default_config.merge_defaults_with_arguments_and_config(
                     an_instance.model_configuration, **opt_args)
     results = run_method(*req_args, **opt_args)                
     return results
    def __init__(self):
        Configuration.__init__(self)
        self['models'] = [
                'real_estate_price_model',
                'development_project_transition_model',
                'commercial_development_project_location_choice_model',
                'industrial_development_project_location_choice_model',
                'residential_development_project_location_choice_model',
                'add_projects_to_buildings',
                'household_transition_model',
                'employment_transition_model',
                'household_relocation_model',
                'household_location_choice_model',
                'employment_relocation_model',
                {   'employment_location_choice_model': {   'group_members': '_all_'}},
                'distribute_unplaced_jobs_model',
                ]
        self['model_system'] = 'urbansim.model_coordinators.model_system'
        my_controller_configuration = {
        'real_estate_price_model': RealEstatePriceModelConfigurationCreator(
            dataset='building', 
            outcome_attribute = 'ln_unit_price=ln(building.avg_value)',
            submodel_string = 'building_type_id',
            filter_variable = None,
            ).execute(),
        'residential_development_project_location_choice_model': DevelopmentProjectLocationChoiceModelConfigurationCreator(
                        project_type = 'residential',
                        coefficients_table = 'residential_development_location_choice_model_coefficients',
                        specification_table = 'residential_development_location_choice_model_specification',
                        units = 'residential_units',
                        sampler = None,
                        capacity_string = 'urbansim_zone.zone.developable_residential_units',
                        ).execute(),
        'commercial_development_project_location_choice_model': DevelopmentProjectLocationChoiceModelConfigurationCreator(
                        project_type = 'commercial',
                        coefficients_table = 'commercial_development_location_choice_model_coefficients',
                        specification_table = 'commercial_development_location_choice_model_specification',
                        units = 'commercial_job_spaces',
                        sampler = None,
                        ).execute(),
        'industrial_development_project_location_choice_model': DevelopmentProjectLocationChoiceModelConfigurationCreator(
                        project_type = 'industrial',
                        coefficients_table = 'industrial_development_location_choice_model_coefficients',
                        specification_table = 'industrial_development_location_choice_model_specification',
                        units = 'industrial_job_spaces',
                        sampler = None,
                        ).execute(),
         'development_project_transition_model': DevelopmentProjectTransitionModelConfigurationCreator(
                        vacancy_variables = {"commercial": "urbansim_zone.zone.number_of_vacant_commercial_jobs",
                                             "industrial": "urbansim_zone.zone.number_of_vacant_industrial_jobs"
                                            },
                        output_results = 'dptm_results',
                        ).execute(),
        'add_projects_to_buildings': AddProjectsToBuildingsConfigurationCreator().execute(), 
        'employment_transition_model': 
                  EmploymentTransitionModelConfigurationCreator(
            location_id_name="zone_id",
            ).execute(),
        'household_transition_model': 
                  HouseholdTransitionModelConfigurationCreator(
            location_id_name="zone_id",
            ).execute(),
 
        'employment_relocation_model': 
                  EmploymentRelocationModelConfigurationCreator(
                               location_id_name = 'zone_id',
                               output_index = 'erm_index').execute(),
                               
        'household_relocation_model': HouseholdRelocationModelConfigurationCreator(
                        location_id_name = 'zone_id',
                        output_index = 'hrm_index',
                        ).execute(),
        'household_location_choice_model': HouseholdLocationChoiceModelConfigurationCreator(
                        location_set = "zone",
                        capacity_string = 'urbansim_zone.zone.vacant_residential_units',
                        estimation_weight_string = 'urbansim_zone.zone.vacant_residential_units',
                        portion_to_unplace = 1/3.0,
                        nchunks = 3,
                        number_of_units_string = None,                       
                        input_index = 'hrm_index',
                        ).execute(),
         'employment_location_choice_model': 
                   EmploymentLocationChoiceModelConfigurationCreator(
                                location_set = "zone",
                                input_index = 'erm_index',
                                agents_for_estimation_table = "jobs_for_estimation",
                                estimation_weight_string = None,
                                number_of_units_string = None,
                                portion_to_unplace = 0,
                                capacity_string = "urbansim_zone.zone.number_of_vacant_SSS_jobs",
                                ).execute(),
                                       
          'home_based_employment_location_choice_model': 
                   EmploymentLocationChoiceModelConfigurationCreator(
                                location_set = "zone",
                                input_index = 'erm_index',
                                estimation_weight_string = "urbansim.zone.number_of_households",
                                agents_for_estimation_table = None, # will take standard jobs table 
                                estimation_size_agents = 0.5,
                                number_of_units_string = None,
                                portion_to_unplace = 0,
                                capacity_string = "urbansim.zone.number_of_households",
                                ).execute(),
            'governmental_employment_location_choice_model': 
                   GovernmentalEmploymentLocationChoiceModelConfigurationCreator(
                        input_index = 'erm_index',
                        location_set = 'zone'
                        ).execute(),      
            'distribute_unplaced_jobs_model':  DistributeUnplacedJobsModelConfigurationCreator(
                                    location_set = 'zone'
                                            ).execute(),   
        }
        self['models_configuration'] = {}
        for model in my_controller_configuration.keys():
            if model not in self["models_configuration"].keys():
                self["models_configuration"][model] = {}
            self['models_configuration'][model]['controller'] = my_controller_configuration[model]

                
        self["datasets_to_preload"] = {
                'building':{},
                'zone':{},
                'household':{},
                'job': {},
                'job_building_type':{},
                'target_vacancy':{},
                'development_event_history':{},
                'building_type': {}
                }
Example #13
0
# Opus/UrbanSim urban simulation software.
# Copyright (C) 2010-2011 University of California, Berkeley, 2005-2009 University of Washington
# See opus_core/LICENSE

from urbansim.configs.base_config_zone import run_configuration as config
from urbansim.configs.estimation_base_config import estimation_configuration
from opus_core.configuration import Configuration

run_configuration = Configuration(config)
run_configuration.merge(estimation_configuration)
run_configuration["models_configuration"]["prepare_datasets_for_aggregation"]["controller"]["run"]["arguments"] = {
                     "datasets_variables": "{household: ['urbansim.household.zone_id'], " + 
                         "job: ['urbansim.job.zone_id'], " + 
                         "building: ['urbansim.building.zone_id'], " + 
                         "zone: ['urbansim.zone.industrial_sqft_per_job', " + 
                                  "'urbansim.zone.commercial_sqft_per_job', " + 
                                  "'is_near_arterial = zone.aggregate(urbansim.gridcell.is_near_arterial, function=aggregate)', " + 
                                  "'is_near_highway = zone.aggregate(urbansim.gridcell.is_near_highway, function=aggregate)', " + 
                                  "'acres_of_land = zone.aggregate(urbansim.gridcell.acres_of_land)', " + 
                                  "'urbansim.zone.avg_val_per_unit_commercial', " + 
                                  "'urbansim.zone.avg_val_per_unit_industrial', " + 
                                  "'urbansim.zone.avg_val_per_unit_governmental', " + 
                                  "'urbansim.zone.avg_val_per_unit_vacant_land', " + 
                                  "'urbansim.zone.avg_val_per_unit_residential', ]" + 
                             "}",
                      "data_objects": "datasets"
                      }
run_configuration["models_configuration"]["household_location_choice_model"]["controller"]["run"]["arguments"]["maximum_runs"]=1
run_configuration["models_configuration"]["employment_location_choice_model"]["controller"]["run"]["arguments"]["maximum_runs"]=1
 def __init__(self):
     Configuration.__init__(self, data = {
         'scenario_database_configuration':ScenarioDatabaseConfiguration(
             database_name = "washtenaw_class",
             ),
         'datasets_to_cache_after_each_model':[],
         'low_memory_mode':False,
         'creating_baseyear_cache_configuration':CreatingBaseyearCacheConfiguration(
             unroll_gridcells = True,
             cache_from_database = False,
             baseyear_cache = BaseyearCacheConfiguration(
                 existing_cache_to_copy = '/urbansim_cache/workshop/cache_source',
                 #years_to_cache  = range(1996,2001)
                 ),
             tables_to_cache = [
                 'annual_employment_control_totals',
                 'annual_household_control_totals',
                 'buildings',
                 'building_types',
                 'development_event_history',
                 'gridcells',
                 'households',
                 'job_building_types',
                 'jobs',
                 'travel_data',
                 'zones',
                 'counties',
                 'commercial_development_location_choice_model_coefficients',
                 'commercial_development_location_choice_model_specification',
                 'commercial_employment_location_choice_model_coefficients',
                 'commercial_employment_location_choice_model_specification',
                 'home_based_employment_location_choice_model_specification',
                 'home_based_employment_location_choice_model_coefficients',
                 'industrial_employment_location_choice_model_coefficients',
                 'industrial_employment_location_choice_model_specification',
                 'industrial_development_location_choice_model_coefficients',
                 'industrial_development_location_choice_model_specification',
                 'residential_development_location_choice_model_coefficients',
                 'residential_development_location_choice_model_specification',
                 'fazes',
                 'urbansim_constants',
                 'household_location_choice_model_coefficients',
                 'household_location_choice_model_specification',
                 'land_price_model_coefficients',
                 'land_price_model_specification',
                 'residential_land_share_model_coefficients',
                 'residential_land_share_model_specification',
                 'plan_type_group_definitions',
                 'plan_type_groups',
                 'large_areas',
                 'household_characteristics_for_ht',
                 'development_types',
                 'development_type_group_definitions',
                 'development_constraints',
                 'annual_relocation_rates_for_households',
                 'annual_relocation_rates_for_jobs',
                 'base_year',
                 'cities',
                 'development_events',
                 'development_type_groups',
                 'employment_adhoc_sector_group_definitions',
                 'employment_adhoc_sector_groups',
                 'employment_sectors',
                 'plan_types',
                 'race_names',
                 'target_vacancies',
                 'jobs_for_estimation',
                 'households_for_estimation',
                 'development_events_exogenous',
                 'job_building_types'
                 ],
             tables_to_cache_nchunks = {'gridcells':1},
             tables_to_copy_to_previous_years = {
                 'development_type_group_definitions':1995,
                 'development_type_groups':1995,
                 'development_types':1995,
                 'development_constraints':1995,
                 'urbansim_constants':1995,
                 },
             ),
         'dataset_pool_configuration': DatasetPoolConfiguration(
             package_order=['washtenaw', 'urbansim', 'opus_core'],
             ),
         'base_year': 2000,
         'years': (2000,2000),
         })
Example #15
0
 def __init__(self, data={}):
     """The argument 'data' is a python native dictionary (class 'dict').
     """ 
     Configuration.__init__(self, data)
Example #16
0
 def __getitem__(self, key):
     """First check for key in my configuration; then check in Session configuration"""
     try:
         return Configuration.__getitem__(self, key)
     except KeyError:
         return SessionConfiguration().get_dataset_from_pool(key)