diff python/storage.py @ 978:184f1dd307f9

corrected print and exception statements for Python 3
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 08 Feb 2018 05:53:50 -0500
parents 7f5cbdc107c5
children cc89267b5ff9
line wrap: on
line diff
--- a/python/storage.py	Tue Feb 06 11:50:43 2018 -0500
+++ b/python/storage.py	Thu Feb 08 05:53:50 2018 -0500
@@ -880,7 +880,7 @@
     try:
         return open(filename, option)
     except IOError:
-        print 'File {} could not be opened.'.format(filename)
+        print('File {} could not be opened.'.format(filename))
         if quitting:
             from sys import exit
             exit()
@@ -952,7 +952,7 @@
     return read_csv(filename, delimiter = ',', names = headers)
         
 def generatePDLaneColumn(data):
-    data['LANE'] = data['LANE\LINK\NO'].astype(str)+'_'+data['LANE\INDEX'].astype(str)
+    data['LANE'] = data['LANE\\LINK\\NO'].astype(str)+'_'+data['LANE\\INDEX'].astype(str)
 
 def convertTrajectoriesVissimToSqlite(filename):
     '''Relies on a system call to sqlite3
@@ -1098,7 +1098,7 @@
     if filename.endswith(".fzp"):
         columns = ['NO', '$VEHICLE:SIMSEC', 'POS']
         if lanes is not None:
-            columns += ['LANE\LINK\NO', 'LANE\INDEX']
+            columns += ['LANE\\LINK\\NO', 'LANE\\INDEX']
         data = read_csv(filename, delimiter=';', comment='*', header=0, skiprows = 1, usecols = columns, low_memory = lowMemory)
         data = selectPDLanes(data, lanes)
         data.sort(['$VEHICLE:SIMSEC'], inplace = True)
@@ -1128,15 +1128,15 @@
     (if the time are closer than collisionTimeDifference)
     If lanes is not None, only the data for the selected lanes will be provided
     (format as string x_y where x is link index and y is lane index)'''
-    data = read_csv(filename, delimiter=';', comment='*', header=0, skiprows = 1, usecols = ['LANE\LINK\NO', 'LANE\INDEX', '$VEHICLE:SIMSEC', 'NO', 'POS'], low_memory = lowMemory)
+    data = read_csv(filename, delimiter=';', comment='*', header=0, skiprows = 1, usecols = ['LANE\\LINK\\NO', 'LANE\\INDEX', '$VEHICLE:SIMSEC', 'NO', 'POS'], low_memory = lowMemory)
     data = selectPDLanes(data, lanes)
     data = data.convert_objects(convert_numeric=True)
 
-    merged = merge(data, data, how='inner', left_on=['LANE\LINK\NO', 'LANE\INDEX', '$VEHICLE:SIMSEC'], right_on=['LANE\LINK\NO', 'LANE\INDEX', '$VEHICLE:SIMSEC'], sort = False)
+    merged = merge(data, data, how='inner', left_on=['LANE\\LINK\\NO', 'LANE\\INDEX', '$VEHICLE:SIMSEC'], right_on=['LANE\\LINK\\NO', 'LANE\\INDEX', '$VEHICLE:SIMSEC'], sort = False)
     merged = merged[merged['NO_x']>merged['NO_y']]
 
     nCollisions = 0
-    for name, group in merged.groupby(['LANE\LINK\NO', 'LANE\INDEX', 'NO_x', 'NO_y']):
+    for name, group in merged.groupby(['LANE\\LINK\\NO', 'LANE\\INDEX', 'NO_x', 'NO_y']):
         diff = group['POS_x']-group['POS_y']
         # diff = group['POS_x']-group['POS_y'] # to check the impact of convert_objects and the possibility of using type conversion in read_csv or function to convert strings if any
         if len(diff) >= 2 and npmin(diff) < 0 and npmax(diff) > 0:
@@ -1188,7 +1188,7 @@
         if obj.getNum() != int(numbers[0]):
             # check and adapt the length to deal with issues in NGSIM data
             if (obj.length() != obj.positions.length()):
-                print 'length pb with object %s (%d,%d)' % (obj.getNum(),obj.length(),obj.positions.length())
+                print('length pb with object {} ({},{})'.format(obj.getNum(),obj.length(),obj.positions.length()))
                 obj.last = obj.getFirstInstant()+obj.positions.length()-1
                 #obj.velocities = utils.computeVelocities(f.positions) # compare norm to speeds ?
             objects.append(obj)
@@ -1206,9 +1206,9 @@
             obj.timeHeadways.append(float(numbers[17]))
 
             if (obj.size[0] != float(numbers[8])):
-                print 'changed length obj %d' % (obj.getNum())
+                print('changed length obj {}'.format(obj.getNum()))
             if (obj.size[1] != float(numbers[9])):
-                print 'changed width obj %d' % (obj.getNum())
+                print('changed width obj {}'.format(obj.getNum()))
     
     inputfile.close()
     return objects
@@ -1227,7 +1227,7 @@
         nObjectsPerType[f.userType-1] += 1
         f.write(out)
 
-    print nObjectsPerType
+    print(nObjectsPerType)
         
     out.close()