Changeset 3293
- Timestamp:
- 05/03/08 12:18:06 (2 months ago)
- Location:
- trunk/urbansim
- Files:
-
- 2 modified
-
estimation/estimation_runner.py (modified) (3 diffs)
-
tools/start_estimation.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/urbansim/estimation/estimation_runner.py
r3249 r3293 22 22 class EstimationRunner(Estimator): 23 23 24 def __init__(self, model, specification_module=None, xml_ specification=None, model_group=None,24 def __init__(self, model, specification_module=None, xml_configuration=None, model_group=None, 25 25 configuration={}, save_estimation_results=False): 26 26 """ 27 27 If 'specification_module' is given, it contains the specification defined as a dictionary in a module. 28 Alternatively, the specification can be passed in an xml format in the 'xml_ specification' argument (It is a full path to the xml file).28 Alternatively, the specification can be passed in an xml format in the 'xml_configuration' argument (It is a full path to the xml file). 29 29 If both of those arguments are None, the specification is taken from the cache. 30 'configuration' is an Opus configuration. It can contain an entry 'config_changes_for_estimation' which is a dictionary 30 'configuration' is an Opus configuration. 31 It can contain an entry 'config_changes_for_estimation' which is a dictionary 31 32 where keys are model names and values are controller changes for that model. 33 If 'configuration' is None, it is taken from 'xml_configuration'. 32 34 If save_estimation_results is True, the estimation results are saved in the oputput configuration 33 35 (if given in 'configuration') and in the cache. 34 36 """ 35 37 self.specification_module = specification_module 36 self.xml_ specification = xml_specification38 self.xml_configuration = xml_configuration 37 39 self.model_group = model_group 38 40 self.estimated_model = model 39 41 40 config = Configuration(configuration) 42 xml_config = None 43 if self.xml_configuration is not None: 44 xml_config = XMLConfiguration(self.xml_configuration) 45 46 if configuration is None: 47 if xml_config is None: 48 raise StandardError, "Either dictionary based or XML based configuration must be given." 49 estimation_section = xml_config.get_section('model_manager/estimation') 50 config = estimation_section['estimation_config'] 51 xml_config._merge_controllers(config) 52 else: 53 config = Configuration(configuration) 41 54 config_changes = config.get('config_changes_for_estimation', {}) 42 55 43 56 specification_dict=None 44 if xml_ specificationis not None:45 specification_dict = XMLConfiguration(xml_specification).get_estimation_specification(model)57 if xml_config is not None: 58 specification_dict = xml_config.get_estimation_specification(model) 46 59 47 60 if model_group is None: 48 61 if model in config_changes.keys(): 49 62 config.merge(config_changes[model]) 63 else: 64 config['models'] = [{model: ["estimate"]}] 50 65 if specification_module is not None: 51 66 config = update_controller_by_specification_from_module( … … 58 73 config.merge(config_changes[model][model_group]) 59 74 else: 60 config.merge(config_changes[model]) 75 config.merge(config_changes[model]) 76 else: 77 config['models'] = [{model: {"group_members": [{model_group: ["estimate"]}]}}] 61 78 if (specification_module is not None) or (specification_dict is not None): 62 79 if '%s_%s' % (model_group, model) in config["models_configuration"].keys(): … … 79 96 """ 80 97 specification_dict=None 81 if self.xml_ specification is not None:82 specification_dict = XMLConfiguration(self.xml_ specification).get_estimation_specification(self.estimated_model)98 if self.xml_configuration is not None: 99 specification_dict = XMLConfiguration(self.xml_configuration).get_estimation_specification(self.estimated_model) 83 100 Estimator.reestimate(self, self.specification_module, specification_dict=specification_dict, type=self.model_group, submodels=submodels) 84 101 -
trunk/urbansim/tools/start_estimation.py
r3268 r3293 26 26 self.parser.add_option("-s", "--specification", dest="specification", default = None, 27 27 action="store", help="Specification module containing model specification in a dictionary format") 28 self.parser.add_option("-x", "--xml- specification", dest="xml_specification", default = None,29 action="store", help="Full path to an XML file containing the specification. One of the options -s and -x should be given, otherwise the specification is taken from cache.")28 self.parser.add_option("-x", "--xml-configuration", dest="xml_configuration", default = None, 29 action="store", help="Full path to an XML configuration file. One of the options -s and -x should be given, otherwise the specification is taken from cache.") 30 30 self.parser.add_option("-c", "--configuration-path", dest="configuration_path", default=None, 31 help="Opus path to Python module defining a configuration .")31 help="Opus path to Python module defining a configuration in dictionary format. One of the options -s and -x must be given.") 32 32 self.parser.add_option("--save-results", dest="save_results", default=False, action="store_true", 33 33 help="Results will be saved in the output configuration (if given) and in the cache") … … 43 43 if options.model_name is None: 44 44 raise StandardError, "Model name (argument -m) must be given." 45 if options.configuration_path is None:46 raise StandardError, "Configuration path (argument -c) must be given."47 if (options.specification is None) and (options.xml_ specification is None):45 if (options.configuration_path is None) and (options.xml_configuration is None): 46 raise StandardError, "Configuration path (argument -c) or XML configuration (argument -x) must be given." 47 if (options.specification is None) and (options.xml_configuration is None): 48 48 logger.log_warning("No specification given (arguments -s or -x). Specification taken from the cache.") 49 49 50 config = get_config_from_opus_path(options.configuration_path) 51 estimator = EstimationRunner(model=options.model_name, specification_module=options.specification, xml_specification=options.xml_specification, 50 if options.configuration_path is None: 51 config = None 52 else: 53 config = get_config_from_opus_path(options.configuration_path) 54 estimator = EstimationRunner(model=options.model_name, specification_module=options.specification, xml_configuration=options.xml_configuration, 52 55 model_group=options.model_group, 53 configuration=config, save_estimation_results=options.save_results) 56 configuration=config, 57 save_estimation_results=options.save_results) 54 58 estimator.estimate()
