Changeset 3303

Show
Ignore:
Timestamp:
05/04/08 13:36:37 (2 months ago)
Author:
borning
Message:

fixed estimation runner in GUI to use the general estimation runner tool; refactored the tool to pass xml_configuration as an instance of XMLConfiguration rather than as a file name

Location:
trunk
Files:
1 removed
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/opus_gui/run/estimation/opusrunestimation.py

    r3196 r3303  
    1717from PyQt4.QtGui import * 
    1818import os, sys, time 
    19  
    20  
    2119try: 
    22     import os 
    2320    from opus_core.configurations.xml_configuration import XMLConfiguration 
    24     # from psrc_parcel.estimation.run_estimation import EstimationRunner 
    25     from gui_estimation_runner import EstimationRunner 
     21    from urbansim.estimation.estimation_runner import EstimationRunner 
    2622    WithOpus = True 
    2723except ImportError: 
    2824    WithOpus = False 
    2925    print "Unable to import opus core libs" 
    30  
     26     
    3127class RunEstimationThread(QThread): 
    3228    def __init__(self, parentThread,parent,xml_file): 
     
    113109    def run(self): 
    114110        if WithOpus: 
    115             # Run the Eugene model using the XML version of the Eugene configuration. 
    116             # This code adapted from opus_core/tools/start_run.py 
     111            # Start the estimation. This code adapted from urbansim/tools/start_estimation.py 
    117112            # statusdir is a temporary directory into which to write a status file 
    118113            # regarding the progress of the simulation - the progress bar reads this file 
    119114            statusfile = None 
    120             statusdir = None 
    121115            succeeded = False 
    122116            try: 
    123117                fileNameInfo = QFileInfo(self.xml_path) 
    124118                filename = fileNameInfo.absoluteFilePath().trimmed() 
    125                 print filename 
    126119                xml_config = XMLConfiguration(str(filename)) 
    127120                estimation_section = xml_config.get_section('model_manager/estimation') 
     
    137130                    if self.cancelled: 
    138131                        break 
    139                     model_config = estimation_config['model_parameters'][model_name] 
    140                     model = (model_config['abbreviation'], model_config['full_name']) 
    141                     if 'location' in model_config: 
    142                         model = model , (model_config['location'], model_config['add_member_prefix']) 
    143                     specification = xml_config.get_estimation_specification(model_config['full_name']) 
    144                     self.er = EstimationRunner() 
     132                    self.er = EstimationRunner(model=model_name, xml_configuration=xml_config, configuration=None) 
    145133                    self.running = True 
    146                     self.er.run_estimation(estimation_config, model, 
    147                                       specification, save_estimation_results=False, diagnose=False) 
     134                    self.er.estimate() 
    148135                    self.running = False 
    149136                succeeded = True 
  • trunk/urbansim/estimation/estimation_runner.py

    r3293 r3303  
    1515 
    1616from opus_core.configuration import Configuration 
    17 from opus_core.configurations.xml_configuration import XMLConfiguration 
    1817from urbansim.estimation.estimator import Estimator 
    1918from urbansim.estimation.estimator import plot_utility_diagnose 
     
    2625        """ 
    2726        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_configuration' argument (It is a full path to the xml file).  
     27        Alternatively, the specification can be passed in an xml format in the 'xml_configuration' argument  
     28        (which should be an instance of XMLConfiguration). 
    2929        If both of those arguments are None, the specification is taken from the cache. 
    3030        'configuration' is an Opus configuration.  
     
    3939        self.model_group = model_group 
    4040        self.estimated_model = model 
    41          
    42         xml_config = None 
    43         if self.xml_configuration is not None: 
    44             xml_config = XMLConfiguration(self.xml_configuration) 
    45              
     41                     
    4642        if configuration is None: 
    47             if xml_config is None: 
     43            if self.xml_configuration is None: 
    4844                raise StandardError, "Either dictionary based or XML based configuration must be given." 
    49             estimation_section = xml_config.get_section('model_manager/estimation') 
     45            estimation_section = self.xml_configuration.get_section('model_manager/estimation') 
    5046            config = estimation_section['estimation_config'] 
    51             xml_config._merge_controllers(config) 
     47            self.xml_configuration._merge_controllers(config) 
    5248        else: 
    5349            config = Configuration(configuration) 
     
    5551         
    5652        specification_dict=None 
    57         if xml_config is not None: 
    58             specification_dict = xml_config.get_estimation_specification(model) 
     53        if self.xml_configuration is not None: 
     54            specification_dict = self.xml_configuration.get_estimation_specification(model) 
    5955             
    6056        if model_group is None: 
     
    9793        specification_dict=None 
    9894        if self.xml_configuration is not None: 
    99             specification_dict = XMLConfiguration(self.xml_configuration).get_estimation_specification(self.estimated_model) 
     95            specification_dict = self.self.xml_configuration.get_estimation_specification(self.estimated_model) 
    10096        Estimator.reestimate(self, self.specification_module, specification_dict=specification_dict, type=self.model_group, submodels=submodels) 
    10197         
  • trunk/urbansim/tools/start_estimation.py

    r3293 r3303  
    1313#  
    1414 
    15 from optparse import OptionParser, OptionGroup 
     15from optparse import OptionParser 
    1616from opus_core.misc import get_config_from_opus_path 
    1717from opus_core.logger import logger 
     18from opus_core.configurations.xml_configuration import XMLConfiguration 
    1819from urbansim.estimation.estimation_runner import EstimationRunner 
    1920 
     
    4748    if (options.specification is None) and (options.xml_configuration is None): 
    4849        logger.log_warning("No specification given (arguments -s or -x). Specification taken from the cache.") 
    49  
     50    if options.xml_configuration is not None: 
     51        xconfig = XMLConfiguration(options.xml_configuration) 
     52    else: 
     53        xconfig = None 
    5054    if options.configuration_path is None: 
    5155        config = None 
    5256    else: 
    5357        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,  
     58    estimator = EstimationRunner(model=options.model_name, specification_module=options.specification, xml_configuration=xconfig,  
    5559                                 model_group=options.model_group, 
    5660                                 configuration=config,