Mercurial Hosting > traffic-intelligence
changeset 1150:14140b55e580
corrected issue with motion pattern for motion prediction for safety analysis (to few matches)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 28 May 2020 01:03:45 -0400 |
parents | 392db62ea1da |
children | 658f87232536 |
files | scripts/safety-analysis.py trafficintelligence/events.py trafficintelligence/tests/events.txt |
diffstat | 3 files changed, 25 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/safety-analysis.py Wed May 13 00:29:34 2020 -0400 +++ b/scripts/safety-analysis.py Thu May 28 01:03:45 2020 -0400 @@ -18,6 +18,7 @@ # TODO analyze only parser.add_argument('--prediction-method', dest = 'predictionMethod', help = 'prediction method (constant velocity (cvd: vector computation (approximate); cve: equation solving; cv: discrete time (approximate)), normal adaptation, point set prediction)', choices = ['cvd', 'cve', 'cv', 'na', 'ps', 'mp']) parser.add_argument('-p', dest = 'prototypeDatabaseFilename', help = 'name of the database containing the prototypes') +parser.add_argument('-c', dest = 'minPrototypeNMatchings', help = 'minimum number of matchings per prototype', type = int, default = 1) # parser.add_argument('--categorize', dest = 'categorize', help = 'computes interaction categories', action = 'store_true') TODO, add angle parameters in tracking.cfg - the safety analysis parameters should probably be spun off tracking.cfg parser.add_argument('--no-motion-prediction', dest = 'noMotionPrediction', help = 'does not compute indicators like TTC depending on motion prediction', action = 'store_true') parser.add_argument('--pet', dest = 'computePET', help = 'computes PET', action = 'store_true') @@ -61,6 +62,17 @@ prototypes = storage.loadPrototypesFromSqlite(params.databaseFilename) else: prototypes = storage.loadPrototypesFromSqlite(args.prototypeDatabaseFilename) + if args.minPrototypeNMatchings > 0: + prototypes = [p for p in prototypes if p.getNMatchings() >= args.minPrototypeNMatchings] + else: + nProto0Matching = 0 + for p in prototypes: + if p.getNMatchings() == 0: + nProto0Matching += 1 + print("Prototype {} has 0 matchings".format(p)) + if len(prototypes) == 0 or nProto0Matching > 0: + print('Database has {} prototypes without any matching. Exiting'.format(nProto0Matching)) + sys.exit() for p in prototypes: p.getMovingObject().computeCumulativeDistances() predictionParameters = prediction.PrototypePredictionParameters(prototypes, params.nPredictedTrajectories, params.maxLcssDistance, params.minLcssSimilarity, params.lcssMetric, params.minFeatureTime, params.constantSpeedPrototypePrediction, params.useFeaturesForPrediction)
--- a/trafficintelligence/events.py Wed May 13 00:29:34 2020 -0400 +++ b/trafficintelligence/events.py Thu May 28 01:03:45 2020 -0400 @@ -193,7 +193,10 @@ v1 = self.roadUser1.getVelocityAtInstant(instant) v2 = self.roadUser2.getVelocityAtInstant(instant) deltav = v2-v1 - velocityAngles[instant] = np.arccos(moving.Point.dot(v1, v2)/(v1.norm2()*v2.norm2())) + v1Norm = v1.norm2() + v2Norm = v2.norm2() + if v1Norm != 0. and v2Norm != 0.: + velocityAngles[instant] = np.arccos(moving.Point.dot(v1, v2)/(v1Norm*v2Norm)) collisionCourseDotProducts[instant] = moving.Point.dot(deltap, deltav) distances[instant] = deltap.norm2() speedDifferentials[instant] = deltav.norm2()
--- a/trafficintelligence/tests/events.txt Wed May 13 00:29:34 2020 -0400 +++ b/trafficintelligence/tests/events.txt Thu May 28 01:03:45 2020 -0400 @@ -11,6 +11,14 @@ >>> len([i for i in interactions if len(i.roadUserNumbers) == 1]) 0 +>>> o1 = MovingObject.generate(1, Point(-5.,0.), Point(0.,0.), TimeInterval(0,10)) +>>> o2 = MovingObject.generate(2, Point(0.,-5.), Point(0.,1.), TimeInterval(0,10)) +>>> inter = Interaction(roadUser1 = o1, roadUser2 = o2) +>>> inter.computeIndicators() # should not crash with 0 speed +>>> va = inter.getIndicator("Velocity Angle") +>>> va.empty() +True + >>> o1 = MovingObject.generate(1, Point(-5.,0.), Point(1.,0.), TimeInterval(0,10)) >>> o2 = MovingObject.generate(2, Point(0.,-5.), Point(0.,1.), TimeInterval(0,10)) >>> inter = Interaction(roadUser1 = o1, roadUser2 = o2) @@ -33,6 +41,7 @@ >>> inter.getIndicator(Interaction.indicatorNames[1])[6] # doctest:+ELLIPSIS 3.1415... +# test categorize >>> from collections import Counter >>> from numpy import pi >>> o1 = MovingObject.generate(0, Point(0,0), Point(1,0), TimeInterval(0,100))