1#!/usr/local/bin/python3.8 2# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo 3# Copyright (C) 2008-2019 German Aerospace Center (DLR) and others. 4# This program and the accompanying materials 5# are made available under the terms of the Eclipse Public License v2.0 6# which accompanies this distribution, and is available at 7# http://www.eclipse.org/legal/epl-v20.html 8# SPDX-License-Identifier: EPL-2.0 9 10# @file plot_net_selection.py 11# @author Daniel Krajzewicz 12# @author Michael Behrisch 13# @date 2014-02-19 14# @version $Id$ 15 16from __future__ import absolute_import 17from __future__ import print_function 18 19import os 20import sys 21 22sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 23import sumolib # noqa 24from sumolib.visualization import helpers # noqa 25 26 27def main(args=None): 28 """The main function; parses options and plots""" 29 # ---------- build and read options ---------- 30 from optparse import OptionParser 31 optParser = OptionParser() 32 optParser.add_option("-n", "--net", dest="net", metavar="FILE", 33 help="Defines the network to read") 34 optParser.add_option("-i", "--selection", dest="selection", metavar="FILE", 35 help="Defines the selection to read") 36 optParser.add_option("--selected-width", dest="selectedWidth", 37 type="float", default=1, help="Defines the width of selected edges") 38 optParser.add_option("--color", "--selected-color", dest="selectedColor", 39 default='r', help="Defines the color of selected edges") 40 optParser.add_option("--edge-width", dest="defaultWidth", 41 type="float", default=.2, help="Defines the width of not selected edges") 42 optParser.add_option("--edge-color", dest="defaultColor", 43 default='#606060', help="Defines the color of not selected edges") 44 optParser.add_option("-v", "--verbose", dest="verbose", action="store_true", 45 default=False, help="If set, the script says what it's doing") 46 # standard plot options 47 helpers.addInteractionOptions(optParser) 48 helpers.addPlotOptions(optParser) 49 # parse 50 options, remaining_args = optParser.parse_args(args=args) 51 52 if options.net is None: 53 print("Error: a network to load must be given.") 54 return 1 55 if options.selection is None: 56 print("Error: a selection to load must be given.") 57 return 1 58 if options.verbose: 59 print("Reading network from '%s'" % options.net) 60 net = sumolib.net.readNet(options.net) 61 selection = sumolib.files.selection.read(options.selection) 62 63 colors = {} 64 widths = {} 65 for e in selection["edge"]: 66 colors[e] = options.selectedColor 67 widths[e] = options.selectedWidth 68 69 fig, ax = helpers.openFigure(options) 70 ax.set_aspect("equal", None, 'C') 71 helpers.plotNet(net, colors, widths, options) 72 options.nolegend = True 73 helpers.closeFigure(fig, ax, options) 74 75 76if __name__ == "__main__": 77 sys.exit(main(sys.argv)) 78