def build(self): # output name for the osm file, will be used by osmBuild, can be # deleted after the process self.filename("osm", "_bbox.osm.xml") # output name for the net file, will be used by osmBuild, randomTrips and # sumo-gui self.filename("net", ".net.xml") if 'osm' in self.data: # testing mode shutil.copy(data['osm'], self.files["osm"]) else: self.report("Downloading map data") osmGet.get( ["-b", ",".join(map(str, self.data["coords"])), "-p", self.prefix]) options = ["-f", self.files["osm"], "-p", self.prefix, "-d", self.tmp] self.additionalFiles = [] self.routenames = [] if self.data["poly"]: # output name for the poly file, will be used by osmBuild and # sumo-gui self.filename("poly", ".poly.xml") options += ["-m", typemaps["poly"]] self.additionalFiles.append(self.files["poly"]) typefiles = [typemaps["net"]] netconvertOptions = osmBuild.DEFAULT_NETCONVERT_OPTS netconvertOptions += ",--tls.default-type,actuated" if "pedestrian" in self.data["vehicles"]: # sidewalks are already included via typefile netconvertOptions += ",--crossings.guess" typefiles.append(typemaps["urban"]) typefiles.append(typemaps["pedestrians"]) if "ship" in self.data["vehicles"]: typefiles.append(typemaps["ships"]) if "bicycle" in self.data["vehicles"]: typefiles.append(typemaps["bicycles"]) # special treatment for public transport if self.data["publicTransport"]: self.filename("stops", "_stops.add.xml") netconvertOptions += ",--ptstop-output,%s" % self.files["stops"] self.filename("ptlines", "_ptlines.xml") self.filename("ptroutes", "_pt.rou.xml") netconvertOptions += ",--ptline-output,%s" % self.files["ptlines"] self.additionalFiles.append(self.files["stops"]) self.routenames.append(self.files["ptroutes"]) netconvertOptions += ",--railway.topology.repair" if self.data["leftHand"]: netconvertOptions += ",--lefthand" options += ["--netconvert-typemap", ','.join(typefiles)] options += ["--netconvert-options", netconvertOptions] self.report("Converting map data") osmBuild.build(options) ptOptions = None if self.data["publicTransport"]: self.report("Generating public transport schedule") ptOptions = [ "-n", self.files["net"], "-e", self.data["duration"], "-p", "600", "--random-begin", "--seed", "42", "--ptstops", self.files["stops"], "--ptlines", self.files["ptlines"], "-o", self.files["ptroutes"], "--ignore-errors", # "--no-vtypes", "--vtype-prefix", "pt_", "--verbose", ] ptlines2flows.main(ptlines2flows.get_options(ptOptions)) if self.data["vehicles"] or ptOptions: # routenames stores all routefiles and will join the items later, will # be used by sumo-gui randomTripsCalls = [] self.edges = sumolib.net.readNet(self.files["net"]).getEdges() for vehicle, options in self.data["vehicles"].items(): self.report("Processing %s" % vehicleNames[vehicle]) self.filename("route", ".%s.rou.xml" % vehicle) self.filename("trips", ".%s.trips.xml" % vehicle) try: options = self.parseTripOpts(vehicle, options, self.data["publicTransport"]) except ZeroDivisionError: continue if vehicle == "pedestrian" and self.data["publicTransport"]: options += ["--additional-files", ",".join([self.files["stops"], self.files["ptroutes"]])] randomTrips.main(randomTrips.get_options(options)) randomTripsCalls.append(options) # --validate is not called for pedestrians if vehicle == "pedestrian": self.routenames.append(self.files["route"]) else: self.routenames.append(self.files["trips"]) # create a batch file for reproducing calls to randomTrips.py if os.name == "posix": SUMO_HOME_VAR = "$SUMO_HOME" else: SUMO_HOME_VAR = "%SUMO_HOME%" randomTripsPath = os.path.join( SUMO_HOME_VAR, "tools", "randomTrips.py") ptlines2flowsPath = os.path.join( SUMO_HOME_VAR, "tools", "ptlines2flows.py") batchFile = "build.bat" with open(batchFile, 'w') as f: if os.name == "posix": f.write("#!/bin/bash\n") if ptOptions is not None: f.write("python \"%s\" %s\n" % (ptlines2flowsPath, " ".join(map(quoted_str, ptOptions)))) for opts in sorted(randomTripsCalls): f.write("python \"%s\" %s\n" % (randomTripsPath, " ".join(map(quoted_str, opts))))
def build(self): # output name for the osm file, will be used by osmBuild, can be # deleted after the process self.filename("osm", "_bbox.osm.xml") # output name for the net file, will be used by osmBuild, randomTrips and # sumo-gui self.filename("net", ".net.xml") if 'osm' in self.data: # testing mode shutil.copy(data['osm'], self.files["osm"]) else: self.report("Downloading map data") osmGet.get( ["-b", ",".join(map(str, self.data["coords"])), "-p", self.prefix]) options = ["-f", self.files["osm"], "-p", self.prefix, "-d", self.tmp] if self.data["poly"]: # output name for the poly file, will be used by osmBuild and # sumo-gui self.filename("poly", ".poly.xml") options += ["-m", typemaps["poly"]] typefiles = [typemaps["net"]] netconvertOptions = osmBuild.DEFAULT_NETCONVERT_OPTS if "pedestrian" in self.data["vehicles"]: # sidewalks are already included via typefile netconvertOptions += ",--crossings.guess" typefiles.append(typemaps["urban"]) typefiles.append(typemaps["pedestrians"]) if "ship" in self.data["vehicles"]: typefiles.append(typemaps["ships"]) if "bicycle" in self.data["vehicles"]: typefiles.append(typemaps["bicycles"]) options += ["--netconvert-typemap", ','.join(typefiles)] options += ["--netconvert-options", netconvertOptions] self.report("Converting map data") osmBuild.build(options) if self.data["vehicles"]: # routenames stores all routefiles and will join the items later, will # be used by sumo-gui self.routenames = [] randomTripsCalls = [] self.edges = sumolib.net.readNet(self.files["net"]).getEdges() for vehicle, options in self.data["vehicles"].items(): self.report("Processing %s" % vehicleNames[vehicle]) self.filename("route", ".%s.rou.xml" % vehicle) self.filename("trips", ".%s.trips.xml" % vehicle) try: options = self.parseTripOpts(vehicle, options) except ZeroDivisionError: continue randomTrips.main(randomTrips.get_options(options)) randomTripsCalls.append(options) # --validate is not called for pedestrians if vehicle == "pedestrian": self.routenames.append(self.files["route"]) else: self.routenames.append(self.files["trips"]) # create a batch file for reproducing calls to randomTrips.py randomTripsPath = os.path.join( SUMO_HOME, "tools", "randomTrips.py") batchFile = "build.bat" with open(batchFile, 'w') as f: for opts in sorted(randomTripsCalls): f.write("python %s %s\n" % (randomTripsPath, " ".join(map(quoted_str, opts))))
(poi.id, poi.color, shape[:-1])) out.write("</additional>\n") print("building Evacuation Site") prefix = "evacuationArea" siteFile = "site.poly.xml" mappedSiteFile = "mappedSite.poly.xml" mergedPopulationFile = "population.poly.xml" intersectionFile = "intersections.poly.xml" if len(sys.argv) > 1: buildEvaSite(sys.argv[1], siteFile) else: buildEvaSite("inputLocations.poi.xml", siteFile) print("osm Get") osmGet.get(["-x", siteFile]) print("osm Build") osmOptions = ['-f', 'osm_bbox.osm.xml', '-p', prefix, '--vehicle-classes', 'road', '-m', os.path.join(SUMO_HOME, 'data', 'typemap', 'osmPolyconvert.typ.xml')] osmBuild.build(osmOptions) print("polyconvert") sys.stdout.flush() subprocess.call([sumolib.checkBinary('polyconvert'), '-n', '%s.net.xml' % prefix, '--xml-files', siteFile, '-o', mappedSiteFile]) print("merging") mergePopulationData("population.csv", 'regions.poly.xml', mergedPopulationFile) print("extracting population data") extract(mergedPopulationFile, mappedSiteFile, intersectionFile) print("generating traffic") generateTraffic.generate( '%s.net.xml' % prefix, mappedSiteFile, intersectionFile, '%s.rou.xml' % prefix)
def build(handler, prefix, bbox=False): sumo = sumolib.checkBinary('sumo') if bbox: sumogui = sumolib.checkBinary('sumo-gui') else: # offline test mode sumogui = sumo def callSumo(extraopts): guisettingsname = prefix + ".view.xml" print "Writing gui settings file:", guisettingsname with open(guisettingsname, 'w') as f: f.write(""" <viewsettings> <scheme name="real world"/> <delay value="20"/> </viewsettings> """) configname = prefix + ".sumocfg" print "Writing config file:", configname opts = [sumo, "-n", netname, "-a", polyname, "--gui-settings-file", guisettingsname, "-v", "--no-step-log", "--save-configuration", configname] opts += extraopts subprocess.call(opts) print "Calling SUMO GUI" try: subprocess.call([sumogui, "-c", configname]) except: print "SUMO GUI canceled" if bbox: # get the coordinates and cast them to float size = map(float, bbox.split(",")) # calculates the area size = (size[0] - size[2]) * (size[3] - size[1]) areaFactor = abs(size) * 5000 # to adjust period by the area print "Calling osmGet" osmGet.get(["-b", bbox, "-p", prefix]) else: # offline test mode areaFactor = 1 print "Calling osmBuild" # output name for the osm file, will be used by osmBuild, can be after the # process deleted osmname = prefix + "_bbox.osm.xml" # output name for the net file, will be used by osmBuild, randomTrips and # sumo-gui netname = prefix + ".net.xml" # output name for the poly file, will be used by osmBuild and sumo-gui polyname = prefix + ".poly.xml" options = ["-f", osmname, "-p", prefix, "-m", polyfile] typefiles = [] netconvertOptions = osmBuild.DEFAULT_NETCONVERT_OPTS + ",--junctions.corner-detail,5" if handler.pedestrians.enable: # drop? # sidewalks are already included via typefile netconvertOptions += ",--crossings.guess" typefiles.append(pedestrianstypefile) else: typefiles.append(typefile) if handler.ships.enable: typefiles.append(shipstypefile) options += ["--netconvert-typemap", ','.join(typefiles)] options += ["--netconvert-options", netconvertOptions] osmBuild.build(options) if handler.vehicles.enable or handler.bicycles.enable or handler.pedestrians.enable or handler.rails.enable or handler.ships.enable: print "Calling randomTrips" # routenames stores all routefiles and will join the items later, will # be used by sumo-gui routenames = [] if handler.vehicles.enable: routename = prefix + ".vehicles.rou.xml" tripname = prefix + ".vehicles.trips.xml" routenames.append(tripname) randomTrips.main(randomTrips.get_options( handler.vehicles.parseTripOpts(netname, routename, areaFactor))) route2trips.main([routename], outfile=tripname) if handler.bicycles.enable: routename = prefix + ".bicycles.rou.xml" tripname = prefix + ".bicycles.trips.xml" routenames.append(tripname) randomTrips.main(randomTrips.get_options( handler.bicycles.parseTripOpts(netname, routename, areaFactor))) route2trips.main([routename], outfile=tripname) if handler.pedestrians.enable: routename = prefix + ".pedestrians.rou.xml" routenames.append(routename) randomTrips.main(randomTrips.get_options( handler.pedestrians.parseTripOpts(netname, routename, areaFactor))) if handler.rails.enable: routename = prefix + ".rails.rou.xml" tripname = prefix + ".rails.trips.xml" routenames.append(tripname) randomTrips.main(randomTrips.get_options( handler.rails.parseTripOpts(netname, routename, areaFactor))) route2trips.main([routename], outfile=tripname) if handler.ships.enable: routename = prefix + ".ships.rou.xml" tripname = prefix + ".ships.trips.xml" routenames.append(tripname) randomTrips.main(randomTrips.get_options( handler.ships.parseTripOpts(netname, routename, areaFactor))) route2trips.main([routename], outfile=tripname) callSumo(["-r", ",".join(routenames), "--ignore-route-errors"]) else: callSumo([]) print "Done."
def build(self): # output name for the osm file, will be used by osmBuild, can be # deleted after the process self.filename("osm", "_bbox.osm.xml") # output name for the net file, will be used by osmBuild, randomTrips and # sumo-gui self.filename("net", ".net.xml") if 'osm' in self.data: # testing mode shutil.copy(data['osm'], self.files["osm"]) else: self.report("Downloading map data") osmGet.get( ["-b", ",".join(map(str, self.data["coords"])), "-p", self.prefix, "-d", self.tmp]) options = ["-f", self.files["osm"], "-p", self.prefix, "-d", self.tmp] self.additionalFiles = [] self.routenames = [] if self.data["poly"]: # output name for the poly file, will be used by osmBuild and # sumo-gui self.filename("poly", ".poly.xml") options += ["-m", typemaps["poly"]] self.additionalFiles.append(self.files["poly"]) typefiles = [typemaps["net"]] netconvertOptions = osmBuild.DEFAULT_NETCONVERT_OPTS netconvertOptions += ",--tls.default-type,actuated" if "pedestrian" in self.data["vehicles"]: # sidewalks are already included via typefile netconvertOptions += ",--crossings.guess" typefiles.append(typemaps["urban"]) typefiles.append(typemaps["pedestrians"]) if "ship" in self.data["vehicles"]: typefiles.append(typemaps["ships"]) if "bicycle" in self.data["vehicles"]: typefiles.append(typemaps["bicycles"]) # special treatment for public transport if self.data["publicTransport"]: self.filename("stops", "_stops.add.xml") netconvertOptions += ",--ptstop-output,%s" % self.files["stops"] self.filename("ptlines", "_ptlines.xml") self.filename("ptroutes", "_pt.rou.xml") netconvertOptions += ",--ptline-output,%s" % self.files["ptlines"] self.additionalFiles.append(self.files["stops"]) self.routenames.append(self.files["ptroutes"]) netconvertOptions += ",--railway.topology.repair" if self.data["leftHand"]: netconvertOptions += ",--lefthand" options += ["--netconvert-typemap", ','.join(typefiles)] options += ["--netconvert-options", netconvertOptions] self.report("Converting map data") osmBuild.build(options) ptOptions = None if self.data["publicTransport"]: self.report("Generating public transport schedule") self.filename("pt_stopinfos", "stopinfos.xml", False) self.filename("pt_vehroutes", "vehroutes.xml", False) self.filename("pt_trips", "trips.trips.xml", False) ptOptions = [ "-n", self.files["net"], "-e", self.data["duration"], "-p", "600", "--random-begin", "--seed", "42", "--ptstops", self.files["stops"], "--ptlines", self.files["ptlines"], "-o", self.files["ptroutes"], "--ignore-errors", # "--no-vtypes", "--vtype-prefix", "pt_", "--stopinfos-file", self.files["pt_stopinfos"], "--routes-file", self.files["pt_vehroutes"], "--trips-file", self.files["pt_trips"], "--min-stops", "0", "--extend-to-fringe", "--verbose", ] ptlines2flows.main(ptlines2flows.get_options(ptOptions)) if self.data["decal"]: self.report("Downloading background images") tileOptions = [ "-n", self.files["net"], "-t", "100", "-d", "background_images", "-l", "-300", ] try: os.chdir(self.tmp) os.mkdir("background_images") tileGet.get(tileOptions) self.report("Success.") except Exception: os.chdir(self.tmp) shutil.rmtree("background_images", ignore_errors=True) self.report("Error while downloading background images") if self.data["vehicles"] or ptOptions: # routenames stores all routefiles and will join the items later, will # be used by sumo-gui randomTripsCalls = [] self.edges = sumolib.net.readNet(os.path.join(self.tmp, self.files["net"])).getEdges() for vehicle, options in self.data["vehicles"].items(): self.report("Processing %s" % vehicleNames[vehicle]) self.filename("route", ".%s.rou.xml" % vehicle) self.filename("trips", ".%s.trips.xml" % vehicle) try: options = self.parseTripOpts(vehicle, options, self.data["publicTransport"]) except ZeroDivisionError: continue if vehicle == "pedestrian" and self.data["publicTransport"]: options += ["--additional-files", ",".join([self.files["stops"], self.files["ptroutes"]])] randomTrips.main(randomTrips.get_options(options)) randomTripsCalls.append(options) # --validate is not called for pedestrians if vehicle == "pedestrian": self.routenames.append(self.files["route"]) else: self.routenames.append(self.files["trips"]) # create a batch file for reproducing calls to randomTrips.py if os.name == "posix": SUMO_HOME_VAR = "$SUMO_HOME" else: SUMO_HOME_VAR = "%SUMO_HOME%" randomTripsPath = os.path.join( SUMO_HOME_VAR, "tools", "randomTrips.py") ptlines2flowsPath = os.path.join( SUMO_HOME_VAR, "tools", "ptlines2flows.py") self.filename("build.bat", "build.bat", False) batchFile = self.files["build.bat"] with open(batchFile, 'w') as f: if os.name == "posix": f.write("#!/bin/bash\n") if ptOptions is not None: f.write("python \"%s\" %s\n" % (ptlines2flowsPath, " ".join(map(quoted_str, self.getRelative(ptOptions))))) for opts in sorted(randomTripsCalls): f.write("python \"%s\" %s\n" % (randomTripsPath, " ".join(map(quoted_str, self.getRelative(opts)))))
def build(self): # output name for the osm file, will be used by osmBuild, can be # deleted after the process self.filename("osm", "_bbox.osm.xml") # output name for the net file, will be used by osmBuild, randomTrips and # sumo-gui self.filename("net", ".net.xml") if 'osm' in self.data: # testing mode shutil.copy(data['osm'], self.files["osm"]) else: self.report("Downloading map data") osmGet.get([ "-b", ",".join(map(str, self.data["coords"])), "-p", self.prefix ]) options = ["-f", self.files["osm"], "-p", self.prefix, "-d", self.tmp] if self.data["poly"]: # output name for the poly file, will be used by osmBuild and # sumo-gui self.filename("poly", ".poly.xml") options += ["-m", typemaps["poly"]] typefiles = [typemaps["net"]] netconvertOptions = osmBuild.DEFAULT_NETCONVERT_OPTS if "pedestrian" in self.data["vehicles"]: # sidewalks are already included via typefile netconvertOptions += ",--crossings.guess" typefiles.append(typemaps["urban"]) typefiles.append(typemaps["pedestrians"]) if "ship" in self.data["vehicles"]: typefiles.append(typemaps["ships"]) if "bicycle" in self.data["vehicles"]: typefiles.append(typemaps["bicycles"]) options += ["--netconvert-typemap", ','.join(typefiles)] options += ["--netconvert-options", netconvertOptions] self.report("Converting map data") osmBuild.build(options) if self.data["vehicles"]: # routenames stores all routefiles and will join the items later, will # be used by sumo-gui self.routenames = [] randomTripsCalls = [] self.edges = sumolib.net.readNet(self.files["net"]).getEdges() for vehicle, options in self.data["vehicles"].items(): self.report("Processing %s" % vehicleNames[vehicle]) self.filename("route", ".%s.rou.xml" % vehicle) self.filename("trips", ".%s.trips.xml" % vehicle) try: options = self.parseTripOpts(vehicle, options) except ZeroDivisionError: continue randomTrips.main(randomTrips.get_options(options)) randomTripsCalls.append(options) # --validate is not called for pedestrians if vehicle == "pedestrian": self.routenames.append(self.files["route"]) else: self.routenames.append(self.files["trips"]) # create a batch file for reproducing calls to randomTrips.py randomTripsPath = os.path.join(SUMO_HOME, "tools", "randomTrips.py") batchFile = "build.bat" with open(batchFile, 'w') as f: for opts in sorted(randomTripsCalls): f.write("python %s %s\n" % (randomTripsPath, " ".join(map(quoted_str, opts))))
% (poi.id, poi.color, shape[:-1])) out.write("</additional>\n") print("building Evacuation Site") prefix = "evacuationArea" siteFile = "site.poly.xml" mappedSiteFile = "mappedSite.poly.xml" mergedPopulationFile = "population.poly.xml" intersectionFile = "intersections.poly.xml" if len(sys.argv) > 1: buildEvaSite(sys.argv[1], siteFile) else: buildEvaSite("inputLocations.poi.xml", siteFile) print("osm Get") osmGet.get(["-x", siteFile]) print("osm Build") osmOptions = [ '-f', 'osm_bbox.osm.xml', '-p', prefix, '--vehicle-classes', 'road', '-m', os.path.join(SUMO_HOME, 'data', 'typemap', 'osmPolyconvert.typ.xml') ] osmBuild.build(osmOptions) print("polyconvert") sys.stdout.flush() subprocess.call([ sumolib.checkBinary('polyconvert'), '-n', '%s.net.xml' % prefix, '--xml-files', siteFile, '-o', mappedSiteFile ]) print("merging") mergePopulationData("population.csv", 'regions.poly.xml', mergedPopulationFile) print("extracting population data")
def build(self): # output name for the osm file, will be used by osmBuild, can be # deleted after the process self.filename("osm", "_bbox.osm.xml.gz") # output name for the net file, will be used by osmBuild, randomTrips and # sumo-gui self.filename("net", ".net.xml") if 'osm' in self.data: # testing mode self.files["osm"] = data['osm'] else: self.report("Downloading map data") osmArgs = ["-b=" + (",".join(map(str, self.data["coords"]))), "-p", self.prefix, "-d", self.tmp, "-z"] if self.data["poly"]: osmArgs.append("--shapes") if 'osmMirror' in self.data: osmArgs += ["-u", self.data["osmMirror"]] if 'roadTypes' in self.data: osmArgs += ["-r", json.dumps(self.data["roadTypes"])] osmGet.get(osmArgs) options = ["-f", self.files["osm"], "-p", self.prefix, "-d", self.tmp] self.additionalFiles = [] self.routenames = [] if self.data["poly"]: # output name for the poly file, will be used by osmBuild and sumo-gui self.filename("poly", ".poly.xml") options += ["-m", typemaps["poly"]] self.additionalFiles.append(self.files["poly"]) typefiles = [typemaps["net"]] # leading space ensures that arguments starting with -- are not # misinterpreted as options netconvertOptions = " " + osmBuild.DEFAULT_NETCONVERT_OPTS netconvertOptions += ",--tls.default-type,actuated" # netconvertOptions += ",--default.spreadtype,roadCenter" if "pedestrian" in self.data["vehicles"]: # sidewalks are already included via typefile netconvertOptions += ",--crossings.guess" netconvertOptions += ",--osm.sidewalks" typefiles.append(typemaps["urban"]) typefiles.append(typemaps["pedestrians"]) if "ship" in self.data["vehicles"]: typefiles.append(typemaps["ships"]) if "bicycle" in self.data["vehicles"]: typefiles.append(typemaps["bicycles"]) netconvertOptions += ",--osm.bike-access" # special treatment for public transport if self.data["publicTransport"]: self.filename("stops", "_stops.add.xml") netconvertOptions += ",--ptstop-output,%s" % self.files["stops"] self.filename("ptlines", "_ptlines.xml") self.filename("ptroutes", "_pt.rou.xml") netconvertOptions += ",--ptline-output,%s" % self.files["ptlines"] self.additionalFiles.append(self.files["stops"]) self.routenames.append(self.files["ptroutes"]) netconvertOptions += ",--railway.topology.repair" if self.data["leftHand"]: netconvertOptions += ",--lefthand" if self.data["decal"]: # change projection to web-mercator to match the background image projection netconvertOptions += ",--proj,+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs" # noqa if self.data["carOnlyNetwork"]: if self.data["publicTransport"]: options += ["--vehicle-classes", "publicTransport"] else: options += ["--vehicle-classes", "passenger"] options += ["--netconvert-typemap", ','.join(typefiles)] options += ["--netconvert-options", netconvertOptions] self.report("Converting map data") osmBuild.build(options) ptOptions = None if self.data["publicTransport"]: self.report("Generating public transport schedule") self.filename("pt_stopinfos", "stopinfos.xml", False) self.filename("pt_vehroutes", "vehroutes.xml", False) self.filename("pt_trips", "trips.trips.xml", False) ptOptions = [ "-n", self.files["net"], "-e", self.data["duration"], "-p", "600", "--random-begin", "--seed", "42", "--ptstops", self.files["stops"], "--ptlines", self.files["ptlines"], "-o", self.files["ptroutes"], "--ignore-errors", # "--no-vtypes", "--vtype-prefix", "pt_", "--stopinfos-file", self.files["pt_stopinfos"], "--routes-file", self.files["pt_vehroutes"], "--trips-file", self.files["pt_trips"], "--min-stops", "0", "--extend-to-fringe", "--verbose", ] ptlines2flows.main(ptlines2flows.get_options(ptOptions)) if self.data["decal"]: self.report("Downloading background images") tileOptions = [ "-n", self.files["net"], "-t", "100", "-d", "background_images", "-l", "-300", ] try: os.chdir(self.tmp) os.mkdir("background_images") tileGet.get(tileOptions) self.report("Success.") self.decalError = False except Exception: os.chdir(self.tmp) shutil.rmtree("background_images", ignore_errors=True) self.report("Error while downloading background images") self.decalError = True if self.data["vehicles"] or ptOptions: # routenames stores all routefiles and will join the items later, will # be used by sumo-gui randomTripsCalls = [] self.edges = sumolib.net.readNet(os.path.join(self.tmp, self.files["net"])).getEdges() for vehicle, options in self.data["vehicles"].items(): self.report("Processing %s" % vehicleNames[vehicle]) self.filename("route", ".%s.rou.xml" % vehicle) self.filename("trips", ".%s.trips.xml" % vehicle) try: options = self.parseTripOpts(vehicle, options, self.data["publicTransport"]) except ZeroDivisionError: continue if vehicle == "pedestrian" and self.data["publicTransport"]: options += ["--additional-files", ",".join([self.files["stops"], self.files["ptroutes"]])] options += ["--persontrip.walk-opposite-factor", "0.8"] randomTrips.main(randomTrips.get_options(options)) randomTripsCalls.append(options) # --validate is not called for pedestrians if vehicle == "pedestrian": self.routenames.append(self.files["route"]) else: self.routenames.append(self.files["trips"]) # clean up unused route file (was only used for validation) os.remove(self.files["route"]) # create a batch file for reproducing calls to randomTrips.py if os.name == "posix": SUMO_HOME_VAR = "$SUMO_HOME" else: SUMO_HOME_VAR = "%SUMO_HOME%" randomTripsPath = os.path.join(SUMO_HOME_VAR, "tools", "randomTrips.py") ptlines2flowsPath = os.path.join(SUMO_HOME_VAR, "tools", "ptlines2flows.py") self.filename("build.bat", "build.bat", False) batchFile = self.files["build.bat"] with open(batchFile, 'w') as f: if os.name == "posix": f.write("#!/bin/bash\n") if ptOptions is not None: f.write('python "%s" %s\n' % (ptlines2flowsPath, " ".join(map(quoted_str, self.getRelative(ptOptions))))) for opts in sorted(randomTripsCalls): f.write('python "%s" %s\n' % (randomTripsPath, " ".join(map(quoted_str, self.getRelative(opts))))) os.chmod(batchFile, BATCH_MODE)