コード例 #1
0
def main():
    option_group = EstimationOptionGroup()
    parser = option_group.parser
    (options, args) = parser.parse_args()
    if options.model_name is None:
        raise StandardError, "Model name (argument -m) must be given."
    if (options.configuration_path is None) and (options.xml_configuration is
                                                 None):
        raise StandardError, "Configuration path (argument -c) or XML configuration (argument -x) must be given."
    if (options.specification is None) and (options.xml_configuration is None):
        logger.log_warning(
            "No specification given (arguments -s or -x). Specification taken from the cache."
        )
    if options.xml_configuration is not None:
        xconfig = XMLConfiguration(options.xml_configuration)
    else:
        xconfig = None
    if options.configuration_path is None:
        config = None
    else:
        config = get_config_from_opus_path(options.configuration_path)
    estimator = EstimationRunner(model=options.model_name,
                                 specification_module=options.specification,
                                 xml_configuration=xconfig,
                                 model_group=options.model_group,
                                 configuration=config,
                                 save_estimation_results=options.save_results)
    estimator.estimate()
    return estimator
コード例 #2
0
    def run(self):
        # Start the estimation. This code adapted from urbansim/tools/start_estimation.py
        # statusdir is a temporary directory into which to write a status file
        # regarding the progress of the simulation - the progress bar reads this file
        statusfile = None
        succeeded = False
        try:
            # get the configuration for estimations
            estimation_section = self.xml_config.get_section('model_manager')
            estimation_config = estimation_section['estimation_config']
            self.config = estimation_config
            # TODO: put this option into post run dialog
            save_results = estimation_config['save_estimation_results']

            # If we've paused the estimation, wait 10 seconds, and see if we are unpaused.  If we've cancelled,
            # exit the loop.  Note that this is a fairly coarse level of pause/resume/stop (at the level of
            # estimating an entire model, rather than a bit of a model).
            while self.paused and not self.cancelled:
                time.sleep(10)
            if not self.cancelled:
                self.er = EstimationRunner(model = self.model_name,
                                           specification_module = None,
                                           xml_configuration = self.xml_config,
                                           model_group = self.model_group,
                                           configuration = None,
                                           save_estimation_results=save_results)
                self.running = True
                self.er.estimate()
                self.running = False
                succeeded = True
        except:
            succeeded = False
            self.running = False
            errorInfo = formatExceptionInfo(custom_message = 'Unexpected Error From Estimation')
            self.errorCallback(errorInfo)
        if statusfile is not None:
            os.remove(statusfile)
        del self.er
        self.er = None
        gc.collect()
        self.finishedCallback(succeeded)