changeset 665:15e244d2a1b5

corrected bug with circular import for VideoFilenameAddable, moved to base module
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 20 May 2015 13:57:47 +0200
parents 455f9b93819c
children 93633ce122c3
files python/base.py python/cvutils.py python/events.py python/indicators.py python/ml.py python/moving.py python/objectsmoothing.py python/pavement.py python/poly-utils.py python/prediction.py python/processing.py python/storage.py python/traffic_engineering.py python/ubc_utils.py python/utils.py
diffstat 15 files changed, 44 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/base.py	Wed May 20 13:57:47 2015 +0200
@@ -0,0 +1,7 @@
+'''Module for few base classes to avoid issues of circular import'''
+
+class VideoFilenameAddable(object):
+    'Base class with the capability to attach a video filename'
+
+    def setVideoFilename(self, videoFilename):
+        self.videoFilename = videoFilename
--- a/python/cvutils.py	Wed May 20 12:04:22 2015 +0200
+++ b/python/cvutils.py	Wed May 20 13:57:47 2015 +0200
@@ -1,6 +1,8 @@
 #! /usr/bin/env python
 '''Image/Video utilities'''
 
+import utils
+
 try:
     import cv2
     opencvAvailable = True
@@ -16,12 +18,8 @@
     
 from sys import stdout
 
-import utils
+#import aggdraw # agg on top of PIL (antialiased drawing)
 
-#import aggdraw # agg on top of PIL (antialiased drawing)
-#import utils
-
-__metaclass__ = type
 
 cvRed = (0,0,255)
 cvGreen = (0,255,0)
--- a/python/events.py	Wed May 20 12:04:22 2015 +0200
+++ b/python/events.py	Wed May 20 13:57:47 2015 +0200
@@ -2,15 +2,15 @@
 '''Libraries for events
 Interactions, pedestrian crossing...'''
 
+import moving, prediction, indicators, utils, cvutils
+from base import VideoFilenameAddable
+
 import numpy as np
 from numpy import arccos
 
 import multiprocessing
 import itertools
 
-import moving, prediction, indicators, utils, cvutils
-from storage import VideoFilenameAddable
-__metaclass__ = type
 
 def findRoute(prototypes,objects,i,j,noiseEntryNums,noiseExitNums,minSimilarity= 0.3, spatialThreshold=1.0, delta=180):
     if i[0] not in noiseEntryNums: 
--- a/python/indicators.py	Wed May 20 12:04:22 2015 +0200
+++ b/python/indicators.py	Wed May 20 13:57:47 2015 +0200
@@ -1,12 +1,11 @@
 #! /usr/bin/env python
 '''Class for indicators, temporal indicators, and safety indicators'''
 
-__metaclass__ = type
-
 import moving
 
+
 # need for a class representing the indicators, their units, how to print them in graphs...
-class TemporalIndicator:
+class TemporalIndicator(object):
     '''Class for temporal indicators
     i.e. indicators that take a value at specific instants
 
--- a/python/ml.py	Wed May 20 12:04:22 2015 +0200
+++ b/python/ml.py	Wed May 20 13:57:47 2015 +0200
@@ -3,7 +3,6 @@
 
 import numpy as np
 
-__metaclass__ = type
 
 class Model(object):
     '''Abstract class for loading/saving model'''    
@@ -28,7 +27,7 @@
         return np.float32([self.model.predict(s) for s in samples])
 
 
-class Centroid:
+class Centroid(object):
     'Wrapper around instances to add a counter'
 
     def __init__(self, instance, nInstances = 1):
--- a/python/moving.py	Wed May 20 12:04:22 2015 +0200
+++ b/python/moving.py	Wed May 20 13:57:47 2015 +0200
@@ -2,7 +2,7 @@
 '''Libraries for moving objects, trajectories...'''
 
 import utils, cvutils
-from storage import VideoFilenameAddable
+from base import VideoFilenameAddable
 
 from math import sqrt
 from numpy import median
@@ -15,7 +15,6 @@
     print('Shapely library could not be loaded')
     shapelyAvailable = False
 
-__metaclass__ = type
 
 class Interval(object):
     '''Generic interval: a subset of real numbers (not iterable)'''
--- a/python/objectsmoothing.py	Wed May 20 12:04:22 2015 +0200
+++ b/python/objectsmoothing.py	Wed May 20 13:57:47 2015 +0200
@@ -1,4 +1,5 @@
 import storage, moving, utils
+
 from math import atan2, degrees, sin, cos, pi
 from numpy import median
 
--- a/python/pavement.py	Wed May 20 12:04:22 2015 +0200
+++ b/python/pavement.py	Wed May 20 13:57:47 2015 +0200
@@ -5,7 +5,6 @@
 
 import numpy as np
 
-__metaclass__ = type
 
 paintTypes = {0: "Non-existant",
               1: "Eau",
@@ -235,7 +234,7 @@
 
     return (nbre_jours_T_negatif,nbre_jours_gel_degel, deltas_T, nbre_jours_gel_consecutifs, ecart_type_T)
 
-class RTSS:
+class RTSS(object):
     '''class for data related to a RTSS:
     - agregating pavement marking measurements
     - RTSS characteristics from FMR: pavement type, age, AADT, truck AADT
@@ -253,7 +252,7 @@
         self.name = name
         self.data = data
 
-class MarkingTest:
+class MarkingTest(object):
     '''class for a test site for a given product
 
     including the series of measurements over the years'''
--- a/python/poly-utils.py	Wed May 20 12:04:22 2015 +0200
+++ b/python/poly-utils.py	Wed May 20 13:57:47 2015 +0200
@@ -1,13 +1,12 @@
 #! /usr/bin/env python
 '''Various utilities to load data saved by the POLY new output(s)'''
-import sys
-import utils
+
 from moving import  TimeInterval
+from indicators import SeverityIndicator
+
+import sys, utils
 import numpy as np
 
-__metaclass__ = type
-from indicators import SeverityIndicator
-
 
 def loadNewInteractions(videoFilename,interactionType,dirname, extension, indicatorsNames, roaduserNum1,roaduserNum2, selectedIndicators=[]):
     '''Loads interactions from the POLY traffic event format'''
--- a/python/prediction.py	Wed May 20 12:04:22 2015 +0200
+++ b/python/prediction.py	Wed May 20 13:57:47 2015 +0200
@@ -2,12 +2,13 @@
 '''Library for motion prediction methods'''
 
 import moving
-import math
-import random
-import numpy as np
 from utils import LCSS
 
-class PredictedTrajectory:
+import math, random
+import numpy as np
+
+
+class PredictedTrajectory(object):
     '''Class for predicted trajectories with lazy evaluation
     if the predicted position has not been already computed, compute it
 
@@ -294,7 +295,7 @@
     return currentInstant, collisionPoints, crossingZones
 
 
-class PredictionParameters:
+class PredictionParameters(object):
     def __init__(self, name, maxSpeed):
         self.name = name
         self.maxSpeed = maxSpeed
--- a/python/processing.py	Wed May 20 12:04:22 2015 +0200
+++ b/python/processing.py	Wed May 20 13:57:47 2015 +0200
@@ -1,11 +1,10 @@
 #! /usr/bin/env python
 '''Algorithms to process trajectories and moving objects'''
 
-__metaclass__ = type
+import moving
 
 import numpy as np
 
-import moving
 
 def extractSpeeds(objects, zone):
     speeds = {}
--- a/python/storage.py	Wed May 20 12:04:22 2015 +0200
+++ b/python/storage.py	Wed May 20 13:57:47 2015 +0200
@@ -3,11 +3,10 @@
 '''Various utilities to save and load data'''
 
 import utils, moving, events, indicators
+from base import VideoFilenameAddable
 
 import sqlite3, logging
 
-__metaclass__ = type
-
 
 commentChar = '#'
 
@@ -867,13 +866,6 @@
 # Utils to read .ini type text files for configuration, meta data...
 #########################
 
-class VideoFilenameAddable:
-    'Base class with the capability to attach a video filename'
-
-    def setVideoFilename(self, videoFilename):
-        self.videoFilename = videoFilename
-
-
 class ProcessParameters(VideoFilenameAddable):
     '''Class for all parameters controlling data processing: input,
     method parameters, etc. for tracking, classification and safety
@@ -929,7 +921,7 @@
         if filename is not None:
             self.loadConfigFile(filename)
 
-class SceneParameters:
+class SceneParameters(object):
     def __init__(self, config, sectionName):
         from ConfigParser import NoOptionError
         from ast import literal_eval
--- a/python/traffic_engineering.py	Wed May 20 12:04:22 2015 +0200
+++ b/python/traffic_engineering.py	Wed May 20 13:57:47 2015 +0200
@@ -1,11 +1,9 @@
 #! /usr/bin/env python
 ''' Traffic Engineering Tools and Examples'''
 
-from math import ceil
-
 import prediction
 
-__metaclass__ = type
+from math import ceil
 
 
 #########################
@@ -26,7 +24,7 @@
         totalTime += h
     return headways
 
-class RoadUser:
+class RoadUser(object):
     '''Simple example of inheritance to plot different road users '''
     def __init__(self, position, velocity):
         'Both fields are 2D numpy arrays'
@@ -61,7 +59,7 @@
 # fundamental diagram
 #########################
 
-class FundamentalDiagram:
+class FundamentalDiagram(object):
     ''' '''
     def __init__(self, name):
         self.name = name
@@ -119,7 +117,7 @@
 # intersection
 #########################
 
-class FourWayIntersection:
+class FourWayIntersection(object):
     '''Simple class for simple intersection outline'''
     def __init__(self, dimension, coordX, coordY):
         self.dimension = dimension
@@ -144,7 +142,7 @@
 # traffic signals
 #########################
 
-class Volume:
+class Volume(object):
     '''Class to represent volumes with varied vehicule types '''
     def __init__(self, volume, types = ['pc'], proportions = [1], equivalents = [1], nLanes = 1):
         '''mvtEquivalent is the equivalent if the movement is right of left turn'''
@@ -172,7 +170,7 @@
             v += p*e
         return v*self.volume
 
-class IntersectionMovement:
+class IntersectionMovement(object):
     '''Represents an intersection movement
     with a volume, a type (through, left or right)
     and an equivalent for movement type'''
@@ -183,7 +181,7 @@
     def getTVUVolume(self):
         return self.mvtEquivalent*self.volume.getPCUVolume()    
 
-class LaneGroup:
+class LaneGroup(object):
     '''Class that represents a group of mouvements'''
 
     def __init__(self, movements, nLanes):
@@ -203,7 +201,7 @@
     'degree of saturation can be used as the peak hour factor too'
     return lostTime/(1-criticalCharge/degreeSaturation)
 
-class Cycle:
+class Cycle(object):
     '''Class to compute optimal cycle and the split of effective green times'''
     def __init__(self, phases, lostTime, saturationVolume):
         '''phases is a list of phases
--- a/python/ubc_utils.py	Wed May 20 12:04:22 2015 +0200
+++ b/python/ubc_utils.py	Wed May 20 13:57:47 2015 +0200
@@ -4,7 +4,6 @@
 import utils, events
 from moving import MovingObject, TimeInterval, Trajectory
 
-__metaclass__ = type
 
 fileTypeNames = ['feature',
                  'object',
--- a/python/utils.py	Wed May 20 12:04:22 2015 +0200
+++ b/python/utils.py	Wed May 20 13:57:47 2015 +0200
@@ -1,12 +1,9 @@
 #! /usr/bin/env python
 ''' Generic utilities.'''
 
-#from numpy import *
-#from pylab import *
 from datetime import time, datetime
 from math import sqrt
 
-__metaclass__ = type
 
 datetimeFormat = "%Y-%m-%d %H:%M:%S"
 
@@ -57,7 +54,7 @@
         result += ((e-o)*(e-o))/e
     return result
 
-class EmpiricalDistribution:
+class EmpiricalDistribution(object):
     def nSamples(self):
         return sum(self.counts)
 
@@ -321,7 +318,7 @@
 # sequence section
 #########################
 
-class LCSS:
+class LCSS(object):
     '''Class that keeps the LCSS parameters
     and puts together the various computations'''
     def __init__(self, similarityFunc, delta = float('inf'), aligned = False, lengthFunc = min):
@@ -450,7 +447,7 @@
     counts.append(counts[-1])
     return [firstX]+sortedX+[lastX], counts
 
-class PlottingPropertyValues:
+class PlottingPropertyValues(object):
     def __init__(self, values):
         self.values = values