changeset 1287:76f5693b530c

updated tests for numpy 2
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Sat, 20 Jul 2024 20:35:21 -0400
parents 8e30c9a6ac6f
children 96c7cfbdd226
files trafficintelligence/moving.py trafficintelligence/storage.py trafficintelligence/tests/cvutils.txt trafficintelligence/tests/events.txt trafficintelligence/tests/indicators.txt trafficintelligence/tests/moving.txt trafficintelligence/tests/prediction.txt trafficintelligence/tests/storage.txt trafficintelligence/tests/utils.txt trafficintelligence/utils.py
diffstat 10 files changed, 73 insertions(+), 73 deletions(-) [+]
line wrap: on
line diff
--- a/trafficintelligence/moving.py	Wed Jul 17 12:28:01 2024 -0400
+++ b/trafficintelligence/moving.py	Sat Jul 20 20:35:21 2024 -0400
@@ -4,7 +4,7 @@
 import copy
 from math import sqrt, atan2, cos, sin, inf
 
-from numpy import median, mean, array, arange, zeros, ones, hypot, NaN, std, floor, ceil, float32, argwhere, flatnonzero, minimum,  issubdtype, integer as npinteger, percentile, quantile, full
+from numpy import median, mean, array, arange, zeros, ones, hypot, nan, std, floor, ceil, float32, argwhere, flatnonzero, minimum,  issubdtype, integer as npinteger, percentile, quantile, full
 from matplotlib.pyplot import plot, text, arrow
 from scipy.spatial.distance import cdist
 from scipy.signal import savgol_filter
@@ -1667,8 +1667,8 @@
                         instants.append(t)
                         coords.append(p[0])
                     else:
-                        instants.append(NaN)
-                        coords.append(NaN)
+                        instants.append(nan)
+                        coords.append(nan)
                 plot(instants, coords, options, **kwargs)
                 if withOrigin and len(instants)>0:
                     plot([instants[0]], [coords[0]], 'ro', **kwargs)
--- a/trafficintelligence/storage.py	Wed Jul 17 12:28:01 2024 -0400
+++ b/trafficintelligence/storage.py	Sat Jul 20 20:35:21 2024 -0400
@@ -7,7 +7,7 @@
 from copy import copy
 import sqlite3, logging
 
-from numpy import log, min as npmin, max as npmax, round as npround, array, sum as npsum, loadtxt, floor as npfloor, ceil as npceil, linalg, int32, int64, reshape, dot, vstack, transpose, ones, zeros_like, pi, NaN
+from numpy import log, min as npmin, max as npmax, round as npround, array, sum as npsum, loadtxt, floor as npfloor, ceil as npceil, linalg, int32, int64, reshape, dot, vstack, transpose, ones, zeros_like, pi, nan
 from pandas import read_csv, merge, concat, DataFrame
 
 from trafficintelligence import utils, moving, events, indicators
@@ -1359,7 +1359,7 @@
         if len(tmp) != interval.length(): #interpolate
             print(objNum, len(tmp), interval.length())
             instants = set(interval).difference(tmp.frame)
-            missing = concat([tmp[['frame']+header[10:]], DataFrame([[t]+[NaN]*(len(header)-10) for t in instants], columns = ['frame']+header[10:])], ignore_index=True).sort_values('frame')
+            missing = concat([tmp[['frame']+header[10:]], DataFrame([[t]+[nan]*(len(header)-10) for t in instants], columns = ['frame']+header[10:])], ignore_index=True).sort_values('frame')
             tmp = missing.interpolate()
         featureTrajectories = [moving.Trajectory() for i in range(4)]
         for i, r in tmp.iterrows():
@@ -1501,7 +1501,7 @@
         if len(tmp) != interval.length(): #interpolate
             print(objNum, len(tmp), interval.length())
             instants = set(interval).difference(tmp.frame)
-            missing = concat([tmp[['frame', 'x', 'y']], DataFrame([[t, NaN, NaN] for t in instants], columns = ['frame', 'x', 'y'])], ignore_index=True).sort_values('frame')
+            missing = concat([tmp[['frame', 'x', 'y']], DataFrame([[t, nan, nan] for t in instants], columns = ['frame', 'x', 'y'])], ignore_index=True).sort_values('frame')
             tmp = missing.interpolate()
             #print(tmp.info())
         if interval.length()>1:
--- a/trafficintelligence/tests/cvutils.txt	Wed Jul 17 12:28:01 2024 -0400
+++ b/trafficintelligence/tests/cvutils.txt	Sat Jul 20 20:35:21 2024 -0400
@@ -10,7 +10,7 @@
 >>> [map1, map2], tmp = cvutils.computeUndistortMaps(width, height, multiplicationFactor, intrinsicCameraMatrix, distortionCoefficients)
 >>> undistorted = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR)
 >>> (undistorted.shape == array([int(round(height*multiplicationFactor)), int(round(width*multiplicationFactor)), 3])).all()
-True
+np.True_
 >>> imgPoints = array([[[150.,170.],[220.,340.],[340.,440.],[401.,521.]]])
 >>> newCameraMatrix = cv2.getDefaultNewCameraMatrix(intrinsicCameraMatrix, (int(round(width*multiplicationFactor)), int(round(height*multiplicationFactor))), True)
 >>> undistortedPoints = cv2.undistortPoints(imgPoints, intrinsicCameraMatrix, distortionCoefficients, P = newCameraMatrix).reshape(-1, 2) # undistort and project as if seen by new camera
@@ -20,28 +20,28 @@
 >>> reducedPoints = dot(invNewCameraMatrix, tmp.T).T
 >>> origPoints = cv2.projectPoints(reducedPoints, (0.,0.,0.), (0.,0.,0.), intrinsicCameraMatrix, distortionCoefficients)[0].reshape(-1,2)
 >>> (round(origPoints[1:,:]) == imgPoints[0][1:,:]).all()
-True
+np.True_
 >>> (absolute(origPoints[0,:]-imgPoints[0][0,:])).max() < 6.
-True
+np.True_
 >>> reducedPoints2 = cvutils.newCameraProject(undistortedPoints.T, invNewCameraMatrix)
 >>> (reducedPoints == reducedPoints).all()
-True
+np.True_
 
 >>> undistortedPoints2 = cv2.undistortPoints(imgPoints, intrinsicCameraMatrix, distortionCoefficients).reshape(-1, 2) # undistort and project as if seen by new camera
 >>> undistortedPoints2 = cvutils.newCameraProject(undistortedPoints2.T, newCameraMatrix)
 >>> (undistortedPoints == undistortedPoints2.T).all()
-True
+np.True_
 
 >>> undistortedPoints = cv2.undistortPoints(imgPoints, intrinsicCameraMatrix, distortionCoefficients).reshape(-1, 2) # undistort to ideal points
 >>> origPoints = cvutils.worldToImageProject(undistortedPoints.T, intrinsicCameraMatrix, distortionCoefficients).T
 >>> (round(origPoints[1:,:]) == imgPoints[0][1:,:]).all()
-True
+np.True_
 >>> (absolute(origPoints[0,:]-imgPoints[0][0,:])).max() < 6.
-True
+np.True_
 
 >>> undistortedPoints = cvutils.imageToWorldProject(imgPoints[0].T, intrinsicCameraMatrix, distortionCoefficients)
 >>> origPoints = cvutils.worldToImageProject(undistortedPoints, intrinsicCameraMatrix, distortionCoefficients).T
 >>> (round(origPoints[1:,:]) == imgPoints[0][1:,:]).all()
-True
+np.True_
 >>> (absolute(origPoints[0,:]-imgPoints[0][0,:])).max() < 6.
-True
+np.True_
--- a/trafficintelligence/tests/events.txt	Wed Jul 17 12:28:01 2024 -0400
+++ b/trafficintelligence/tests/events.txt	Sat Jul 20 20:35:21 2024 -0400
@@ -38,26 +38,26 @@
 >>> inter.computeCrossingsCollisions(predictionParams, 0.1, 10)
 >>> ttc = inter.getIndicator("Time to Collision")
 >>> ttc[0]
-5.0
+np.float64(5.0)
 >>> ttc[1]
-4.0
+np.float64(4.0)
 >>> (inter.collisionPoints[0][0] - Point(0.,0.)).norm2() < 0.0001
 True
 >>> (inter.collisionPoints[4][0] - Point(0.,0.)).norm2() < 0.0001
 True
 >>> inter.getIndicator(Interaction.indicatorNames[1])[4] < 0.000001 # collision angle
-True
+np.True_
 >>> inter.getIndicator(Interaction.indicatorNames[1])[5] is None
 True
 >>> inter.getIndicator(Interaction.indicatorNames[1])[6] # doctest:+ELLIPSIS
-3.1415...
+np.float64(3.1415...)
 
 # test if reseting object
 >>> o2 = MovingObject.generate(2, Point(0.,-5.), Point(0.,-1.), TimeInterval(0,10))
 >>> inter.setRoadUsers([o1,o2])
 >>> ttc = inter.getIndicator("Time to Collision")
 >>> ttc[0]
-5.0
+np.float64(5.0)
 >>> inter.computeIndicators()
 >>> inter.computeCrossingsCollisions(predictionParams, 0.1, 10)
 >>> inter.getIndicator("Time to Collision") is None
--- a/trafficintelligence/tests/indicators.txt	Wed Jul 17 12:28:01 2024 -0400
+++ b/trafficintelligence/tests/indicators.txt	Sat Jul 20 20:35:21 2024 -0400
@@ -21,29 +21,29 @@
 
 >>> ttc = SeverityIndicator('TTC', {t:t-1 for t in TimeInterval(1,11)}, mostSevereIsMax = False)
 >>> ttc.getMostSevereValue(1)
-0.0
+np.float64(0.0)
 >>> ttc.getMostSevereValue(2)
-0.5
+np.float64(0.5)
 >>> ttc.getMostSevereValue(centile = 10.)
-1.0
+np.float64(1.0)
 >>> ttc.mostSevereIsMax = True
 >>> ttc.getMostSevereValue(1)
-10.0
+np.float64(10.0)
 >>> ttc.getMostSevereValue(2)
-9.5
+np.float64(9.5)
 >>> ttc.getMostSevereValue(centile = 10.)
-9.0
+np.float64(9.0)
 
 >>> t1 = Trajectory([[0.5,1.5,2.5],[0.5,3.5,6.5]])
 >>> m = indicatorMap([1,2,3], t1, 1)
 >>> m[(1.0, 3.0)]
-2.0
+np.float64(2.0)
 >>> m[(2.0, 6.0)]
-3.0
+np.float64(3.0)
 >>> m[(0.0, 0.0)]
-1.0
+np.float64(1.0)
 >>> m = indicatorMap([1,2,3], t1, 4)
 >>> m[(0.0, 1.0)]
-3.0
+np.float64(3.0)
 >>> m[(0.0, 0.0)]
-1.5
+np.float64(1.5)
--- a/trafficintelligence/tests/moving.txt	Wed Jul 17 12:28:01 2024 -0400
+++ b/trafficintelligence/tests/moving.txt	Sat Jul 20 20:35:21 2024 -0400
@@ -187,10 +187,10 @@
 >>> from utils import LCSS
 >>> lcss = LCSS(lambda x,y: Point.distanceNorm2(x,y) <= 0.1)
 >>> Trajectory.lcss(t1, t1, lcss)
-3
+np.int64(3)
 >>> lcss = LCSS(lambda p1, p2: (p1-p2).normMax() <= 0.1)
 >>> Trajectory.lcss(t1, t1, lcss)
-3
+np.int64(3)
 
 >>> p1=Point(0,0)
 >>> p2=Point(1,0)
@@ -253,18 +253,18 @@
 Number of objects represented by object 1 must be greater or equal to 1 (0.5)
 >>> o2 = MovingObject.generate(2, Point(0.,-5.), Point(0.,1.), TimeInterval(0,10))
 >>> MovingObject.computePET(o1, o2, 0.1)
-(0.0, 5, 5)
+(np.float64(0.0), np.int64(5), np.int64(5))
 >>> o2 = MovingObject.generate(2, Point(0.,-5.), Point(0.,1.), TimeInterval(5,15))
 >>> MovingObject.computePET(o1, o2, 0.1)
-(5.0, 5, 10)
+(np.float64(5.0), np.int64(5), np.int64(10))
 >>> o2 = MovingObject.generate(2, Point(0.,-5.), Point(0.,1.), TimeInterval(15,30))
 >>> MovingObject.computePET(o1, o2, 0.1)
-(15.0, 5, 20)
+(np.float64(15.0), np.int64(5), np.int64(20))
 
 >>> o1 = MovingObject(1, TimeInterval(0,10), features=[MovingObject.generate(1, Point(0., 3.), Point(1., 0.), TimeInterval(0,10)), MovingObject.generate(2, Point(2., 3.), Point(1., 0.), TimeInterval(0,10)), MovingObject.generate(3, Point(2., 4.), Point(1., 0.), TimeInterval(0,10)), MovingObject.generate(4, Point(0., 4.), Point(1., 0.), TimeInterval(0,10))])
 >>> o2 = MovingObject(2, TimeInterval(0,10), features=[MovingObject.generate(5, Point(6., 0.), Point(0., 1.), TimeInterval(0,10)), MovingObject.generate(6, Point(7., 0.), Point(0., 1.), TimeInterval(0,10)), MovingObject.generate(7, Point(7., 2.), Point(0., 1.), TimeInterval(0,10)), MovingObject.generate(8, Point(6., 2.), Point(0., 1.), TimeInterval(0,10))])
 >>> MovingObject.computePET(o1, o2, useBoundingPoly = True)
-(2.0, 5, 3)
+(np.float64(2.0), np.int64(5), np.int64(3))
 
 >>> t1 = CurvilinearTrajectory.generate(3, 1., 10, 'b')
 >>> t1.length()
@@ -335,7 +335,7 @@
 True
 >>> t=5
 >>> o13.getPositionAtInstant(t) == (o1.getPositionAtInstant(t)+o3.getPositionAtInstant(t)).divide(2)
-True
+np.True_
 >>> len(o13.getFeatures())
 2
 
@@ -379,11 +379,11 @@
 True
 >>> o15.updatePositions()
 >>> o1.getPositionAtInstant(10) == o15.getPositionAtInstant(10)
-True
+np.True_
 >>> f15.getPositionAtInstant(11) == o15.getPositionAtInstant(11)
-True
+np.True_
 >>> o5.getPositionAtInstant(12) == o15.getPositionAtInstant(12)
-True
+np.True_
 
 >>> o1 = MovingObject.generate(1, Point(0., 2.), Point(0., 1.), TimeInterval(0,2))
 >>> o1.classifyUserTypeSpeedMotorized(0.5, np.median)
--- a/trafficintelligence/tests/prediction.txt	Wed Jul 17 12:28:01 2024 -0400
+++ b/trafficintelligence/tests/prediction.txt	Sat Jul 20 20:35:21 2024 -0400
@@ -26,7 +26,7 @@
 >>> et = PredictedTrajectoryRandomControl(moving.Point(0,0),moving.Point(1,1), acceleration, steering, maxSpeed = 2)
 >>> p = et.predictPosition(500)
 >>> max(et.getPredictedSpeeds()) <= 2.
-True
+np.True_
 
 >>> p = moving.Point(3,4)
 >>> sp = SafetyPoint(p, 0.1, 0)
@@ -53,16 +53,16 @@
 >>> proto.getPositions().computeCumulativeDistances()
 >>> et = PredictedTrajectoryPrototype(proto.getPositionAt(10)+moving.Point(0.5, 0.5), proto.getVelocityAt(10)*0.9, proto, True)
 >>> absolute(et.initialSpeed - proto.getVelocityAt(10).norm2()*0.9) < 1e-5
-True
+np.True_
 >>> for t in range(int(proto.length())): x=et.predictPosition(t)
 >>> traj = et.getPredictedTrajectory()
 >>> traj.computeCumulativeDistances()
 >>> absolute(array(traj.distances).mean() - et.initialSpeed < 1e-3)
-True
+np.True_
 
 >>> et = PredictedTrajectoryPrototype(proto.getPositionAt(10)+moving.Point(0.6, 0.6), proto.getVelocityAt(10)*0.7, proto, False)
 >>> absolute(et.initialSpeed - proto.getVelocityAt(10).norm2()*0.7) < 1e-5
-True
+np.True_
 >>> proto = moving.MovingObject.generate(1, moving.Point(-5.,0.), moving.Point(1.,0.), moving.TimeInterval(0,10))
 >>> et = PredictedTrajectoryPrototype(proto.getPositionAt(0)+moving.Point(0., 1.), proto.getVelocityAt(0)*0.5, proto, False)
 >>> for t in range(int(proto.length()/0.5)): x=et.predictPosition(t)
--- a/trafficintelligence/tests/storage.txt	Wed Jul 17 12:28:01 2024 -0400
+++ b/trafficintelligence/tests/storage.txt	Sat Jul 20 20:35:21 2024 -0400
@@ -122,7 +122,7 @@
 >>> gmmId = 0
 >>> savePOIsToSqlite('pois-tmp.sqlite', gmm, 'end', gmmId)
 >>> reloadedGmm = loadPOIsFromSqlite('pois-tmp.sqlite')
->>> sum(gmm.predict(points) == reloadedGmm[gmmId].predict(points)) == nPoints
+>>> int(sum(gmm.predict(points) == reloadedGmm[gmmId].predict(points))) == nPoints
 True
 >>> reloadedGmm[gmmId].gmmTypes[0] == 'end'
 True
--- a/trafficintelligence/tests/utils.txt	Wed Jul 17 12:28:01 2024 -0400
+++ b/trafficintelligence/tests/utils.txt	Sat Jul 20 20:35:21 2024 -0400
@@ -86,78 +86,78 @@
 
 >>> lcss = LCSS(similarityFunc = lambda x,y: abs(x-y) <= 0.1)
 >>> lcss.compute(list(range(5)), list(range(5)))
-5
+np.int64(5)
 >>> lcss.compute(list(range(1,5)), list(range(5)))
-4
+np.int64(4)
 >>> lcss.compute(list(range(5,10)), list(range(5)))
-0
+np.int64(0)
 >>> lcss.compute(list(range(5)), list(range(10)))
-5
+np.int64(5)
 >>> lcss.similarityFunc = lambda x,y: x == y
 >>> lcss.compute(['a','b','c'], ['a','b','c', 'd'])
-3
+np.int64(3)
 >>> lcss.computeNormalized(['a','b','c'], ['a','b','c', 'd']) #doctest: +ELLIPSIS
 1.0
 >>> lcss.computeNormalized(['a','b','c','x'], ['a','b','c', 'd']) #doctest: +ELLIPSIS
 0.75
 >>> lcss.compute(['a','b','c'], ['a','b','c', 'd'])
-3
+np.int64(3)
 >>> lcss.compute(['a','x','b','c'], ['a','b','c','d','x'])
-3
+np.int64(3)
 >>> lcss.compute(['a','b','c','x','d'], ['a','b','c','d','x'])
-4
+np.int64(4)
 >>> lcss.delta = 1
 >>> lcss.compute(['a','b','c'], ['a','b','x','x','c'])
-2
+np.int64(2)
 
 >>> lcss.delta = float('inf')
 >>> lcss.compute(['a','b','c'], ['a','b','c', 'd'], computeSubSequence = True)
-3
+np.int64(3)
 >>> lcss.subSequenceIndices
 [(0, 0), (1, 1), (2, 2)]
 >>> lcss.compute(['a','b','c'], ['x','a','b','c'], computeSubSequence = True)
-3
+np.int64(3)
 >>> lcss.subSequenceIndices
 [(0, 1), (1, 2), (2, 3)]
 >>> lcss.compute(['a','g','b','c'], ['a','b','c', 'd'], computeSubSequence = True)
-3
+np.int64(3)
 >>> lcss.subSequenceIndices
 [(0, 0), (2, 1), (3, 2)]
 
 >>> alignedLcss = LCSS(lambda x,y:(abs(x-y) <= 0.1), delta = 2, aligned = True)
 >>> alignedLcss.compute(list(range(5)), list(range(5)))
-5
+np.int64(5)
 >>> alignedLcss.compute(list(range(1,5)), list(range(5)))
-4
+np.int64(4)
 
 >>> alignedLcss.compute(list(range(5,10)), list(range(10)))
-5
+np.int64(5)
 
 >>> lcss.delta = 2
 >>> lcss.compute(list(range(5,10)), list(range(10)))
-0
+np.int64(0)
 >>> alignedLcss.delta = 6
 >>> alignedLcss.compute(list(range(5)), list(range(5)))
-5
+np.int64(5)
 >>> alignedLcss.compute(list(range(5)), list(range(6)))
-5
+np.int64(5)
 >>> lcss.delta = 10
 >>> alignedLcss.compute(list(range(1,7)), list(range(6)))
-5
+np.int64(5)
 >>> lcss = LCSS(lambda x,y: x == y, delta = 2, aligned = True)
 >>> lcss.compute(list(range(20)), [2,4,6,7,8,9,11,13], True)
-8
+np.int64(8)
 >>> lcss.subSequenceIndices
 [(2, 0), (4, 1), (6, 2), (7, 3), (8, 4), (9, 5), (11, 6), (13, 7)]
 
 >>> lcss = LCSS(metric = 'cityblock', epsilon = 0.1)
 >>> lcss.compute([[i] for i in range(5)], [[i] for i in range(5)])
-5
+np.int64(5)
 >>> lcss.compute([[i] for i in range(1,5)], [[i] for i in range(5)])
-4
+np.int64(4)
 >>> lcss.compute([[i] for i in range(5,10)], [[i] for i in range(5)])
-0
+np.int64(0)
 >>> lcss.compute([[i] for i in range(5)], [[i] for i in range(10)])
-5
+np.int64(5)
 
 
--- a/trafficintelligence/utils.py	Wed Jul 17 12:28:01 2024 -0400
+++ b/trafficintelligence/utils.py	Sat Jul 20 20:35:21 2024 -0400
@@ -11,7 +11,7 @@
 from scipy.stats import rv_continuous, kruskal, shapiro, lognorm, norm, t, chi2_contingency
 from scipy.spatial import distance
 from scipy.sparse import dok_matrix
-from numpy import zeros, array, exp, sum as npsum, int64 as npint, arange, cumsum, mean, median, percentile, isnan, ones, convolve,  dtype, isnan, NaN, ma, isinf, savez, load as npload, log, polyfit, float64
+from numpy import zeros, array, exp, sum as npsum, int64 as npint, arange, cumsum, mean, median, percentile, ones, convolve,  dtype, isnan, nan, ma, isinf, savez, load as npload, log, polyfit, float64
 from numpy.random import random_sample, permutation as nppermutation
 from pandas import DataFrame, concat, crosstab
 import matplotlib.pyplot as plt
@@ -501,7 +501,7 @@
             if not allVariables:
                 values = values[:-1]
             for val in values:
-                if val is not NaN:
+                if not isnan(val):
                     newVariable = (var+'_{}'.format(val)).replace('.','').replace(' ','').replace('-','')
                     data[newVariable] = (data[var] == val)
                     newVariables.append(newVariable)
@@ -736,7 +736,7 @@
         experiments[var] = pattern*(2**(nIndependentVariables-i-1))
     experiments = DataFrame(experiments)
     experiments['r2adj'] = 0.
-    experiments['condNum'] = NaN
+    experiments['condNum'] = nan
     experiments['shapiroP'] = -1
     experiments['nobs'] = -1
     return experiments