Mercurial > hg > nsaunier > traffic-intelligence
comparison trafficintelligence/tests/moving.txt @ 1028:cc5cb04b04b0
major update using the trafficintelligence package name and install through pip
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Fri, 15 Jun 2018 11:19:10 -0400 |
| parents | python/tests/moving.txt@5d2f6afae35b |
| children | aafbc0bab925 |
comparison
equal
deleted
inserted
replaced
| 1027:6129296848d3 | 1028:cc5cb04b04b0 |
|---|---|
| 1 >>> from moving import * | |
| 2 >>> import storage | |
| 3 >>> import numpy as np | |
| 4 | |
| 5 >>> Interval().empty() | |
| 6 True | |
| 7 >>> Interval(0,1).empty() | |
| 8 False | |
| 9 >>> Interval(0,1) | |
| 10 [0, 1] | |
| 11 >>> Interval(0,1).length() | |
| 12 1.0 | |
| 13 >>> Interval(23.2,24.9).length() | |
| 14 1.6999999999999993 | |
| 15 >>> Interval(10,8).length() | |
| 16 0.0 | |
| 17 | |
| 18 >>> TimeInterval(0,1).length() | |
| 19 2.0 | |
| 20 >>> TimeInterval(10,8).length() | |
| 21 0.0 | |
| 22 >>> TimeInterval(10,8) == TimeInterval(10,8) | |
| 23 True | |
| 24 >>> TimeInterval(10,8) == TimeInterval(8,10) | |
| 25 True | |
| 26 >>> TimeInterval(11,8) == TimeInterval(10,8) | |
| 27 False | |
| 28 | |
| 29 >>> [i for i in TimeInterval(9,13)] | |
| 30 [9, 10, 11, 12, 13] | |
| 31 | |
| 32 >>> TimeInterval(2,5).equal(TimeInterval(2,5)) | |
| 33 True | |
| 34 >>> TimeInterval(2,5).equal(TimeInterval(2,4)) | |
| 35 False | |
| 36 >>> TimeInterval(2,5).equal(TimeInterval(5,2)) | |
| 37 False | |
| 38 | |
| 39 >>> TimeInterval(3,6).distance(TimeInterval(4,6)) | |
| 40 0 | |
| 41 >>> TimeInterval(3,6).distance(TimeInterval(6,10)) | |
| 42 0 | |
| 43 >>> TimeInterval(3,6).distance(TimeInterval(8,10)) | |
| 44 2 | |
| 45 >>> TimeInterval(20,30).distance(TimeInterval(3,15)) | |
| 46 5 | |
| 47 >>> TimeInterval.unionIntervals([TimeInterval(3,6), TimeInterval(8,10),TimeInterval(11,15)]) | |
| 48 [3, 15] | |
| 49 | |
| 50 >>> Point(0,3) == Point(0,3) | |
| 51 True | |
| 52 >>> Point(0,3) == Point(0,3.2) | |
| 53 False | |
| 54 >>> Point(3,4)-Point(1,7) | |
| 55 (2.000000,-3.000000) | |
| 56 >>> -Point(1,2) | |
| 57 (-1.000000,-2.000000) | |
| 58 >>> Point(1,2)*0.5 | |
| 59 (0.500000,1.000000) | |
| 60 | |
| 61 >>> Point(3,2).norm2Squared() | |
| 62 13 | |
| 63 | |
| 64 >>> Point.distanceNorm2(Point(3,4),Point(1,7)) | |
| 65 3.605551275463989 | |
| 66 | |
| 67 >>> Point(3,2).inPolygon(np.array([[0,0],[1,0],[1,1],[0,1]])) | |
| 68 False | |
| 69 >>> Point(3,2).inPolygon(np.array([[0,0],[4,0],[4,3],[0,3]])) | |
| 70 True | |
| 71 | |
| 72 >>> predictPositionNoLimit(10, Point(0,0), Point(1,1)) # doctest:+ELLIPSIS | |
| 73 ((1.0...,1.0...), (10.0...,10.0...)) | |
| 74 | |
| 75 >>> segmentIntersection(Point(0,0), Point(0,1), Point(1,1), Point(2,3)) | |
| 76 >>> segmentIntersection(Point(0,1), Point(0,3), Point(1,0), Point(3,1)) | |
| 77 >>> segmentIntersection(Point(0.,0.), Point(2.,2.), Point(0.,2.), Point(2.,0.)) | |
| 78 (1.000000,1.000000) | |
| 79 >>> segmentIntersection(Point(0,0), Point(4,4), Point(0,4), Point(4,0)) | |
| 80 (2.000000,2.000000) | |
| 81 >>> segmentIntersection(Point(0,1), Point(1,2), Point(2,0), Point(3,2)) | |
| 82 | |
| 83 >>> t1 = Trajectory.fromPointList([(92.2, 102.9), (56.7, 69.6)]) | |
| 84 >>> t2 = Trajectory.fromPointList([(92.2, 102.9), (56.7, 69.6)]) | |
| 85 >>> t1 == t2 | |
| 86 True | |
| 87 >>> t3 = Trajectory.fromPointList([(92.24, 102.9), (56.7, 69.6)]) | |
| 88 >>> t1 == t3 | |
| 89 False | |
| 90 >>> t3 = Trajectory.fromPointList([(92.2, 102.9), (56.7, 69.6), (56.7, 69.6)]) | |
| 91 >>> t1 == t3 | |
| 92 False | |
| 93 | |
| 94 >>> left = Trajectory.fromPointList([(92.291666666666686, 102.99239033124439), (56.774193548387103, 69.688898836168306)]) | |
| 95 >>> middle = Trajectory.fromPointList([(87.211021505376351, 93.390778871978512), (59.032258064516128, 67.540286481647257)]) | |
| 96 >>> right = Trajectory.fromPointList([(118.82392473118281, 115.68263205013426), (63.172043010752688, 66.600268576544309)]) | |
| 97 >>> alignments = [left, middle, right] | |
| 98 >>> for a in alignments: a.computeCumulativeDistances() | |
| 99 >>> getSYfromXY(Point(73, 82), alignments) | |
| 100 [1, 0, (73.819977,81.106170), 18.172277808821125, 18.172277808821125, 1.2129694042343868] | |
| 101 >>> getSYfromXY(Point(78, 83), alignments, 0.5) | |
| 102 [1, 0, (77.033188,84.053889), 13.811799123113715, 13.811799123113715, -1.4301775140225983] | |
| 103 | |
| 104 >>> Trajectory().length() | |
| 105 0 | |
| 106 >>> t1 = Trajectory([[0.5,1.5,2.5],[0.5,3.5,6.5]]) | |
| 107 >>> t1.length() == 3. | |
| 108 True | |
| 109 >>> t1[1] | |
| 110 (1.500000,3.500000) | |
| 111 | |
| 112 >>> t1.differentiate() | |
| 113 (1.000000,3.000000) (1.000000,3.000000) | |
| 114 >>> t1.differentiate(True) | |
| 115 (1.000000,3.000000) (1.000000,3.000000) (1.000000,3.000000) | |
| 116 >>> t1 = Trajectory([[0.5,1.5,3.5],[0.5,2.5,7.5]]) | |
| 117 >>> t1.differentiate() | |
| 118 (1.000000,2.000000) (2.000000,5.000000) | |
| 119 | |
| 120 >>> t1.computeCumulativeDistances() | |
| 121 >>> t1.getDistance(0) | |
| 122 2.23606797749979 | |
| 123 >>> t1.getDistance(1) | |
| 124 5.385164807134504 | |
| 125 >>> t1.getDistance(2) | |
| 126 Index 2 beyond trajectory length 3-1 | |
| 127 >>> t1.getCumulativeDistance(0) | |
| 128 0.0 | |
| 129 >>> t1.getCumulativeDistance(1) | |
| 130 2.23606797749979 | |
| 131 >>> t1.getCumulativeDistance(2) | |
| 132 7.6212327846342935 | |
| 133 >>> t1.getCumulativeDistance(3) | |
| 134 Index 3 beyond trajectory length 3 | |
| 135 | |
| 136 | |
| 137 >>> from utils import LCSS | |
| 138 >>> lcss = LCSS(lambda x,y: Point.distanceNorm2(x,y) <= 0.1) | |
| 139 >>> Trajectory.lcss(t1, t1, lcss) | |
| 140 3 | |
| 141 >>> lcss = LCSS(lambda p1, p2: (p1-p2).normMax() <= 0.1) | |
| 142 >>> Trajectory.lcss(t1, t1, lcss) | |
| 143 3 | |
| 144 | |
| 145 >>> p1=Point(0,0) | |
| 146 >>> p2=Point(1,0) | |
| 147 >>> v1 = Point(0.1,0.1) | |
| 148 >>> v2 = Point(-0.1, 0.1) | |
| 149 >>> abs(Point.timeToCollision(p1, p2, v1, v2, 0.)-5.0) < 0.00001 | |
| 150 True | |
| 151 >>> abs(Point.timeToCollision(p1, p2, v1, v2, 0.1)-4.5) < 0.00001 | |
| 152 True | |
| 153 >>> p1=Point(0,1) | |
| 154 >>> p2=Point(1,0) | |
| 155 >>> v1 = Point(0,0.1) | |
| 156 >>> v2 = Point(0.1, 0) | |
| 157 >>> Point.timeToCollision(p1, p2, v1, v2, 0.) == None | |
| 158 True | |
| 159 >>> Point.timeToCollision(p2, p1, v2, v1, 0.) == None | |
| 160 True | |
| 161 >>> Point.midPoint(p1, p2) | |
| 162 (0.500000,0.500000) | |
| 163 >>> p1=Point(0.,0.) | |
| 164 >>> p2=Point(5.,0.) | |
| 165 >>> v1 = Point(2.,0.) | |
| 166 >>> v2 = Point(1.,0.) | |
| 167 >>> Point.timeToCollision(p1, p2, v1, v2, 0.) | |
| 168 5.0 | |
| 169 >>> Point.timeToCollision(p1, p2, v1, v2, 1.) | |
| 170 4.0 | |
| 171 | |
| 172 >>> objects = storage.loadTrajectoriesFromSqlite('../samples/laurier.sqlite', 'object') | |
| 173 >>> len(objects) | |
| 174 5 | |
| 175 >>> objects[0].hasFeatures() | |
| 176 False | |
| 177 >>> features = storage.loadTrajectoriesFromSqlite('../samples/laurier.sqlite', 'feature') | |
| 178 >>> for o in objects: o.setFeatures(features) | |
| 179 >>> objects[0].hasFeatures() | |
| 180 True | |
| 181 | |
| 182 >>> o1 = MovingObject.generate(1, Point(-5.,0.), Point(1.,0.), TimeInterval(0,10)) | |
| 183 >>> o2 = MovingObject.generate(2, Point(0.,-5.), Point(0.,1.), TimeInterval(0,10)) | |
| 184 >>> MovingObject.computePET(o1, o2, 0.1) | |
| 185 (0.0, 5, 5) | |
| 186 >>> o2 = MovingObject.generate(2, Point(0.,-5.), Point(0.,1.), TimeInterval(5,15)) | |
| 187 >>> MovingObject.computePET(o1, o2, 0.1) | |
| 188 (5.0, 5, 10) | |
| 189 >>> o2 = MovingObject.generate(2, Point(0.,-5.), Point(0.,1.), TimeInterval(15,30)) | |
| 190 >>> MovingObject.computePET(o1, o2, 0.1) | |
| 191 (15.0, 5, 20) | |
| 192 | |
| 193 >>> t = CurvilinearTrajectory(S = [1., 2., 3., 5.], Y = [0.5, 0.5, 0.6, 0.7], lanes = ['1']*4) | |
| 194 >>> t.differentiate() # doctest:+ELLIPSIS | |
| 195 [1.0, 0.0, '1'] [1.0, 0.099..., '1'] [2.0, 0.099..., '1'] | |
| 196 >>> t.differentiate(True) # doctest:+ELLIPSIS | |
| 197 [1.0, 0.0, '1'] [1.0, 0.099..., '1'] [2.0, 0.099..., '1'] [2.0, 0.099..., '1'] | |
| 198 >>> t = CurvilinearTrajectory(S = [1.], Y = [0.5], lanes = ['1']) | |
| 199 >>> t.differentiate().empty() | |
| 200 True | |
| 201 | |
| 202 >>> o1 = MovingObject.generate(1, Point(1., 2.), Point(1., 1.), TimeInterval(0,10)) | |
| 203 >>> o1.features = [o1] | |
| 204 >>> o2 = MovingObject.generate(2, Point(14., 14.), Point(1., 0.), TimeInterval(14,20)) | |
| 205 >>> o2.features = [o2] | |
| 206 >>> o3 = MovingObject.generate(3, Point(2., 2.), Point(1., 1.), TimeInterval(2,12)) | |
| 207 >>> o3.features = [o3] | |
| 208 >>> o13 = MovingObject.concatenate(o1, o3, 4) | |
| 209 >>> o13.getNum() | |
| 210 4 | |
| 211 >>> o13.getTimeInterval() == TimeInterval(0,12) | |
| 212 True | |
| 213 >>> t=5 | |
| 214 >>> o13.getPositionAtInstant(t) == (o1.getPositionAtInstant(t)+o3.getPositionAtInstant(t)).divide(2) | |
| 215 True | |
| 216 >>> len(o13.getFeatures()) | |
| 217 2 | |
| 218 >>> o12 = MovingObject.concatenate(o1, o2, 5) | |
| 219 >>> o12.getTimeInterval() == TimeInterval(o1.getFirstInstant(), o2.getLastInstant()) | |
| 220 True | |
| 221 >>> v = o12.getVelocityAtInstant(12) | |
| 222 >>> v == Point(3./4, 2./4) | |
| 223 True | |
| 224 >>> o12.getPositionAtInstant(11) == o1.getPositionAtInstant(10)+v | |
| 225 True | |
| 226 >>> len(o12.getFeatures()) | |
| 227 3 | |
| 228 | |
| 229 >>> o1 = MovingObject.generate(1, Point(0., 2.), Point(0., 1.), TimeInterval(0,2)) | |
| 230 >>> o1.classifyUserTypeSpeedMotorized(0.5, np.median) | |
| 231 >>> userTypeNames[o1.getUserType()] | |
| 232 'car' | |
| 233 >>> o1.classifyUserTypeSpeedMotorized(1.5, np.median) | |
| 234 >>> userTypeNames[o1.getUserType()] | |
| 235 'pedestrian' | |
| 236 | |
| 237 >>> o1 = MovingObject.generate(1, Point(0.,0.), Point(1.,0.), TimeInterval(0,10)) | |
| 238 >>> gt1 = BBMovingObject(1, TimeInterval(0,10), MovingObject.generate(1, Point(0.2,0.6), Point(1.,0.), TimeInterval(0,10)), MovingObject.generate(2, Point(-0.2,-0.4), Point(1.,0.), TimeInterval(0,10))) | |
| 239 >>> gt1.computeCentroidTrajectory() | |
| 240 >>> computeClearMOT([gt1], [], 0.2, 0, 10) | |
| 241 (None, 0.0, 11, 0, 0, 11, None, None) | |
| 242 >>> computeClearMOT([], [o1], 0.2, 0, 10) | |
| 243 (None, None, 0, 0, 11, 0, None, None) | |
| 244 >>> computeClearMOT([gt1], [o1], 0.2, 0, 10) # doctest:+ELLIPSIS | |
| 245 (0.0999..., 1.0, 0, 0, 0, 11, None, None) | |
| 246 >>> computeClearMOT([gt1], [o1], 0.05, 0, 10) | |
| 247 (None, -1.0, 11, 0, 11, 11, None, None) | |
| 248 | |
| 249 >>> o1 = MovingObject(1, TimeInterval(0,3), positions = Trajectory([list(range(4)), [0.1, 0.1, 1.1, 1.1]])) | |
| 250 >>> o2 = MovingObject(2, TimeInterval(0,3), positions = Trajectory([list(range(4)), [0.9, 0.9, -0.1, -0.1]])) | |
| 251 >>> gt1 = BBMovingObject(1, TimeInterval(0,3), MovingObject(positions = Trajectory([list(range(4)), [0.]*4])), MovingObject(positions = Trajectory([list(range(4)), [0.]*4]))) | |
| 252 >>> gt1.computeCentroidTrajectory() | |
| 253 >>> gt2 = BBMovingObject(2, TimeInterval(0,3), MovingObject(positions = Trajectory([list(range(4)), [1.]*4])), MovingObject(positions = Trajectory([list(range(4)), [1.]*4]))) | |
| 254 >>> gt2.computeCentroidTrajectory() | |
| 255 >>> computeClearMOT([gt1, gt2], [o1, o2], 0.2, 0, 3) # doctest:+ELLIPSIS | |
| 256 (0.1..., 0.75, 0, 2, 0, 8, None, None) | |
| 257 >>> computeClearMOT([gt2, gt1], [o2, o1], 0.2, 0, 3) # doctest:+ELLIPSIS | |
| 258 (0.1..., 0.75, 0, 2, 0, 8, None, None) | |
| 259 >>> computeClearMOT([gt1], [o1, o2], 0.2, 0, 3) | |
| 260 (0.1, -0.25, 0, 1, 4, 4, None, None) | |
| 261 >>> computeClearMOT([gt1], [o2, o1], 0.2, 0, 3) # symmetry | |
| 262 (0.1, -0.25, 0, 1, 4, 4, None, None) | |
| 263 >>> computeClearMOT([gt1, gt2], [o1], 0.2, 0, 3) # doctest:+ELLIPSIS | |
| 264 (0.100..., 0.375, 4, 1, 0, 8, None, None) | |
| 265 >>> computeClearMOT([gt2, gt1], [o1], 0.2, 0, 3) # doctest:+ELLIPSIS | |
| 266 (0.100..., 0.375, 4, 1, 0, 8, None, None) | |
| 267 >>> computeClearMOT([gt1, gt2], [o1, o2], 0.08, 0, 3) | |
| 268 (None, -1.0, 8, 0, 8, 8, None, None) |
