Skip to content

Commit

Permalink
fixing style refs #12
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Jan 27, 2025
1 parent e16f304 commit adf7de2
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 31 deletions.
2 changes: 1 addition & 1 deletion tools/assign/duaIterate_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def parse_args():
parser.add_argument("dualog", category="output", nargs=1, type=parser.file, help="file path to dua log file")
options = parser.parse_args()
options.dualog = options.dualog[0]

if options.limit is None:
options.limit = uMax
return options
Expand Down
2 changes: 1 addition & 1 deletion tools/build_config/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
"countEdgeUsage.py",
"createVehTypeDistribution.py",
"edgesInDistricts.py",
#"extractTest.py", NOT_SUITABLE
# "extractTest.py", NOT_SUITABLE
"fcdReplay.py",
"findAllRoutes.py",
"generateBidiDistricts.py",
Expand Down
6 changes: 3 additions & 3 deletions tools/build_config/update_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
This script finds tools that should be added to templates.py
"""

import os,sys
import os
import sys
from os import path
import glob
import re
from templates import TOOLS, generateToolTemplates

toolDir = path.join(path.dirname(__file__), '..')
Expand All @@ -35,7 +35,7 @@
for line in f:
if "ArgumentParser" in line:
candidates.append(fname)
break;
break
print("found %s files that use ArgumentParser" % len(candidates))

candidates = [f for f in candidates if path.dirname(f) not in ('build_config', 'devel', 'game', 'purgatory')]
Expand Down
2 changes: 0 additions & 2 deletions tools/edgesInDistricts.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import sys
import argparse
import collections
from xml.sax import parse

import sumolib


Expand Down
2 changes: 1 addition & 1 deletion tools/import/opendrive/signal_POIs_from_xodr.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def extract_lanes_width_data(rte, ):

if __name__ == "__main__":
op = sumolib.options.ArgumentParser()
op.add_argument("xodr_file", category="input",
op.add_argument("xodr_file", category="input",
help="file path of open drive file")
op.add_argument("net_file", category="input",
help="file path of net file")
Expand Down
1 change: 0 additions & 1 deletion tools/output/tripinfoByTAZ.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from __future__ import print_function
import os
import sys
import argparse
from collections import defaultdict
sys.path.append(os.path.join(os.environ["SUMO_HOME"], 'tools'))
from sumolib.output import parse # noqa
Expand Down
1 change: 0 additions & 1 deletion tools/output/tripinfoDiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from __future__ import print_function
import os
import sys
import argparse
from collections import OrderedDict
sys.path.append(os.path.join(os.environ["SUMO_HOME"], 'tools'))
from sumolib.output import parse # noqa
Expand Down
42 changes: 21 additions & 21 deletions tools/shapes/poly2edgedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(THIS_DIR, '..'))
import sumolib # noqa
import sumolib.geomhelper as gh
import sumolib.geomhelper as gh #noqa

PATCH_NONE = 'None'


def get_options(args=None):
op = sumolib.options.ArgumentParser(description="Transform polygons with params into edgedata with attributes")

Expand All @@ -56,7 +57,7 @@ def get_options(args=None):
op.add_option("-n", "--netfile", category="input", required=True, type=op.net_file,
help="Network file on which to map the polygons")
op.add_option("-p", "--patchfile", category="input", type=op.file,
help="Load a file with patches to apply during import")
help="Load a file with patches to apply during import")
op.add_option("-r", "--radius", type=float, default=20,
help="radius for finding edges near polygons")
op.add_option("--shapecut", type=float, default=40,
Expand All @@ -66,11 +67,11 @@ def get_options(args=None):
op.add_option("--min-length", type=float, default=10, dest="minLength",
help="minimum edge length that may be mapped to")
op.add_option("-s", "--split-attributes", dest="splitAttrs",
help="If a reverse edge is found, split the values of the given attribute list among edge and reverse edge")
help="If a reverse edge is found, split the values of the given attribute list among edge and reverse edge") # noqa
op.add_option("-S", "--nosplit-attributes", dest="noSplitAttrs",
help="If a reverse edge is found, split the values of all attributes except the given attribute list among edge and reverse edge") # noqa
op.add_option("-f", "--filter", dest="filter",
help="Read a list of triplets ATTR,MIN,MAX and only keep polygons where value ATTR is within [MIN,MAX]")
help="Read a list of triplets ATTR,MIN,MAX and only keep polygons where value ATTR is within [MIN,MAX]") # noqa
op.add_option("-b", "--begin", default=0, type=op.time,
help="edgedata interval begin time")
op.add_option("-e", "--end", default="1:0:0:0", type=op.time,
Expand All @@ -87,7 +88,7 @@ def get_options(args=None):
options.splitAttrs = set(options.splitAttrs.split(',')) if options.splitAttrs else []
options.noSplitAttrs = set(options.noSplitAttrs.split(',')) if options.noSplitAttrs else []
tuples = options.filter.split(',') if options.filter else []
options.filter = {} # attr -> (min, max)
options.filter = {} # attr -> (min, max)
for i in range(0, len(tuples), 3):
options.filter[tuples[i]] = (float(tuples[i + 1]), float(tuples[i + 2]))
return options
Expand All @@ -103,7 +104,7 @@ def hasReverse(edge):
def readPatches(net, pfile):
patchEdg = {} # polyID->edge
patchRev = {} # forwardEdge->reverseEdge
patchDat = defaultdict(lambda: {}) # polyID->attr->data (-1 ignores)
patchDat = defaultdict(lambda: {}) # polyID->attr->data (-1 ignores)
if pfile is not None:
with open(pfile) as pf:
for line in pf:
Expand All @@ -112,7 +113,7 @@ def readPatches(net, pfile):
if patchtype == "rev":
edgeID, reverseID = items[1:]
patchRev[edgeID] = reverseID
test = net.getEdge(edgeID)
net.getEdge(edgeID) # provoke error if edgeID does not exist in net
elif patchtype == "edg":
polyID, edgeID = items[1:]
patchEdg[polyID] = edgeID
Expand All @@ -131,7 +132,7 @@ def readPatches(net, pfile):
def main(options):
net = sumolib.net.readNet(options.netfile)
patchEdg, patchRev, patchDat = readPatches(net, options.patchfile)
usedEdges = set() # do not assign different polygons/counts to the same edge
usedEdges = set() # do not assign different polygons/counts to the same edge
scut = options.shapecut

with open(options.outfile, 'w') as foutobj:
Expand All @@ -143,7 +144,7 @@ def main(options):

shape = []
for lonlat in poly.shape.split():
lon,lat = lonlat.split(',')
lon, lat = lonlat.split(',')
shape.append(net.convertLonLat2XY(float(lon), float(lat)))
shapelen = gh.polyLength(shape)
cx, cy = gh.positionAtShapeOffset(shape, shapelen / 2)
Expand Down Expand Up @@ -179,8 +180,9 @@ def main(options):
angle = gh.angleTo2D(gh.positionAtShapeOffset(eShape, offset1),
gh.positionAtShapeOffset(eShape, offset2))
revAngle = gh.angleTo2D(gh.positionAtShapeOffset(eShape, offset2),
gh.positionAtShapeOffset(eShape, offset1))
if degrees(fabs(polyAngle - angle)) < options.atol or degrees(fabs(polyAngle - revAngle)) < options.atol:
gh.positionAtShapeOffset(eShape, offset1))
if (degrees(fabs(polyAngle - angle)) < options.atol or
degrees(fabs(polyAngle - revAngle)) < options.atol):
cands.append(e)
edges = cands
if not edges:
Expand All @@ -196,8 +198,6 @@ def main(options):
maxDist = max([gh.distancePointToPolygon(xy, shape) for xy in e.getShape()])
else:
maxDist = max([gh.distancePointToPolygon(xy, e.getShape()) for xy in shape])
#if poly.id == "241517.0":
# print(e.getID(), maxDist, "shapelen", shapelen, "eLen", e.getLength())
if maxDist < bestDist:
bestDist = maxDist
bestEdge = e
Expand All @@ -214,8 +214,7 @@ def main(options):
continue
# find opposite direction for undivided road
for e in edges:
if (e.getFromNode() == bestEdge.getToNode() and
e.getToNode() == bestEdge.getFromNode()):
if e.getFromNode() == bestEdge.getToNode() and e.getToNode() == bestEdge.getFromNode():
bestReverse = e
break
# apply revers edge patch
Expand Down Expand Up @@ -253,18 +252,19 @@ def main(options):
if poly.id in patchDat:
if param.key in patchDat[poly.id]:
value = patchDat[poly.id][param.key]
#print("patched %s to %s" % (param.value, value))
# print("patched %s to %s" % (param.value, value))
if value == PATCH_NONE:
continue
if param.key in options.filter:
if (float(value) < options.filter[param.key][0] or
float(value) > options.filter[param.key][1]):
if ((float(value) < options.filter[param.key][0] or
float(value) > options.filter[param.key][1])):
skip = True
if bestReverse is not None and (param.key in options.splitAttrs
or options.noSplitAttrs and param.key not in options.noSplitAttrs):
if (bestReverse is not None
and (param.key in options.splitAttrs
or options.noSplitAttrs and param.key not in options.noSplitAttrs)):
try:
value = float(value) / 2
except:
except ValueError:
pass
attrs += ' %s="%s"' % (param.key, value)

Expand Down

0 comments on commit adf7de2

Please sign in to comment.