def invoke_run_travel_model(config, year): """ """ tm_config = config['travel_model_configuration'] scenario = tm_config['travel_model_scenario'] try: travel_model_year = travel_model_year_mapping[year] except KeyError: logger.log_warning("no travel model year mapping for %d." % year) travel_model_year = year # put the travel model input data in place data_exchange_dir = mtc_common.tm_get_data_exchange_dir(config, year) cache_directory = config['cache_directory'] mtc_dir = os.path.join(cache_directory, "mtc_data") for f in glob.glob(os.path.join(mtc_dir, '*' + str(year) + '*')): logger.log_status("Copying over travel model input " + f + " to " + data_exchange_dir) shutil.copy(f, data_exchange_dir) my_location = os.path.split(__file__)[0] script_filepath = os.path.join(my_location, "run_travel_model.py") cmd = "%s %s -s %s -y %s -n" % (sys.executable, script_filepath, scenario, travel_model_year) # form the desired output dir for the travel model data. Make it look # like the urbansim run cache for easy association. Note that we # explicitly use the forward slash instead of os.sep and friends # because the travel model is managed via ssh on a cygwin machine, not # run on the local machine. outdir = "runs/" + config['cache_directory'].split(os.sep)[-1] outdir = outdir + "/%d_%s" % (year, scenario) cmd = cmd + " -o " + outdir logger.log_status("Launching %s" % cmd) if os.system(cmd) != 0: raise TravelModelError # Run the emfac report # TODO: the travel model server should come from the configuration. But # for this we must migrate the configuration from mtc_config.py to the # top-level xml. So for now we just hard-code it :-/ Same for # travel_model_home. tm_server = "*****@*****.**" travel_model_home = "/cygdrive/e/mtc_travel_model/" server_model = winssh.winssh(tm_server, "OPUS_MTC_SERVER_PASSWD") (rc, emfac_windir) = server_model.cmd("cygpath -w " + outdir) if rc != 0: logger.log_error("Failed to find windows path for emfac dir " + outdir) sys.exit(1) emfac_windir = emfac_windir.replace('\r', '').replace('\n','') logger.log_status("Attempting to generate EMFAC report...") cmd = 'cd ' + travel_model_home + 'model_support_files/EMFAC_Files' logger.log_status(cmd) server_model.cmd_or_fail(cmd) cmd = "cmd /c 'RunEmfac.bat " + emfac_windir + " " + str(year) + "' | tee emfac.log" logger.log_status(cmd) (rc, out) = server_model.cmd(cmd, supress_output=False, pipe_position=0) if rc != 0: logger.log_warning("WARNING: Failed to prepare emfac report")
"(relative to travel_model_home)") (options, args) = parser.parse_args() config = mtc_config.MTCConfig() if options.scenario == None: print "ERROR: Please specify a scenario with -s" sys.exit(1) if options.year == None: print "ERROR: Please specify a scenario year with -y" sys.exit(1) # Set up the server. print "Setting up proper directory structure..." server_admin = winssh.winssh(config.server_admin, "OPUS_MTC_SERVER_ADMIN_PASSWD") modeldir = options.year + "_" + options.scenario abs_modeldir = config.travel_model_home + modeldir if server_admin.cmd("test -e " + abs_modeldir)[0] != 0: print "ERROR: Model directory " + abs_modeldir + " does not appear to exist" sys.exit(1) server_admin.cmd("subst /D M:") (rc, windows_travel_model_home) = server_admin.cmd("cygpath -w " + config.travel_model_home) windows_travel_model_home = "'" + windows_travel_model_home.replace('\r\n','')[:-1] + "'" server_admin.cmd_or_fail("subst M: " + windows_travel_model_home) server_admin.cmd('rm /cygdrive/m/commpath') server_admin.cmd_or_fail('cmd /c "mklink /D M:\\\\commpath M:\\\\' + modeldir + '"') server = winssh.winssh(config.server, "OPUS_MTC_SERVER_PASSWD") # Clean house before proceeding print "Killing old processes..."