tvaLib
Public Member Functions | Public Attributes | List of all members
lib.scene.VirtualLoops Class Reference

Declare virtual_loops object. More...

Public Member Functions

def __init__ (self, coordinates='', nLanes=1, radius=3, days=1, expansionFactors=False)
 
def __len__ (self)
 
def __getitem__ (self, i)
 
def __repr__ (self)
 
def __str__ (self)
 
def __iter__ (self)
 
def __add__ (self, slist)
 
def append (self, value)
 
def reverse (self)
 
def count (self, value)
 
def index (self, value)
 
def addCoordCounts (self, objects, start=0, fps=15, verbose=0)
 
def addEdgeCounts (self, objects, fps=15, verbose=0)
 
def getCoordCounts (self, i=[0, None, id=[0, None, m='hour')
 
def getEdgeCounts (self, i=[0, None, lane=[0, None, side=0, m='hour')
 
def getCoordCountVector (self, i=[0, None, m='hour')
 
def getEdgeCountVector (self, i=[0, None, m='hour')
 
def getCoordMeanSpeed (self, i=[0, None, id=[0, None, m='hour')
 
def getEdgeMeanSpeed (self, i=[0, None, lane=[0, None, side=0, m='hour')
 
def getCoordMeanSpeedVector (self, i=[0, None, m='hour')
 
def getEdgeMeanSpeedVector (self, i=[0, None, m='hour')
 
def write (self)
 

Public Attributes

 coordinates
 
 loops
 
 lanes
 
 radius
 
 edge_hourly
 
 edge_m15
 
 coord_hourly
 
 coord_m15
 

Detailed Description

Declare virtual_loops object.

Definition at line 1392 of file scene.py.

Constructor & Destructor Documentation

◆ __init__()

def lib.scene.VirtualLoops.__init__ (   self,
  coordinates = '',
  nLanes = 1,
  radius = 3,
  days = 1,
  expansionFactors = False 
)

Definition at line 1393 of file scene.py.

1393  def __init__(self, coordinates='', nLanes=1, radius=3, days=1, expansionFactors=False):
1394  self.coordinates = tvaLib.Constructors.SuperListParse(coordinates)
1395 
1396  self.loops = len(self.coordinates)
1397  self.lanes = nLanes
1398  self.radius = radius
1399  self.edge_hourly = [[[[0,[]],[0,[]]] for x in range(nLanes)] for x in range(24*days)]
1400  self.edge_m15 = [[[[0,[]],[0,[]]] for x in range(nLanes)] for x in range(24*days*4)]
1401  self.coord_hourly = [[[0,[]] for x in range(len(self.coordinates))] for x in range(24*days)]
1402  self.coord_m15 = [[[0,[]] for x in range(len(self.coordinates))] for x in range(24*days*4)]
1403  return
1404 

Member Function Documentation

◆ __add__()

def lib.scene.VirtualLoops.__add__ (   self,
  slist 
)

Definition at line 1410 of file scene.py.

1410  def __add__(self, slist): self.coordinates += slist.coordinates; return None

◆ __getitem__()

def lib.scene.VirtualLoops.__getitem__ (   self,
  i 
)

Definition at line 1406 of file scene.py.

1406  def __getitem__(self,i): return self.coord_hourly[i]

◆ __iter__()

def lib.scene.VirtualLoops.__iter__ (   self)

Definition at line 1409 of file scene.py.

1409  def __iter__(self): return iter(self.coordinates)

◆ __len__()

def lib.scene.VirtualLoops.__len__ (   self)

Definition at line 1405 of file scene.py.

1405  def __len__(self): return len(self.coord_hourly)

◆ __repr__()

def lib.scene.VirtualLoops.__repr__ (   self)

Definition at line 1407 of file scene.py.

1407  def __repr__(self): return self.__class__.__name__+' '+str(self.coordinates)

◆ __str__()

def lib.scene.VirtualLoops.__str__ (   self)

Definition at line 1408 of file scene.py.

1408  def __str__(self): return self.__class__.__name__+' '+str(self.coordinates)

◆ addCoordCounts()

def lib.scene.VirtualLoops.addCoordCounts (   self,
  objects,
  start = 0,
  fps = 15,
  verbose = 0 
)
Add counts and speeds from virtual loop coordinates.

    Input:
    ======
    objects: a nested camera/sequence ObjectSpace

Definition at line 1416 of file scene.py.

1416  def addCoordCounts(self, objects, start=0, fps=15, verbose=0):
1417  ''' Add counts and speeds from virtual loop coordinates.
1418 
1419  Input:
1420  ======
1421  objects: a nested camera/sequence ObjectSpace
1422  '''
1423  if(not objects.getAll()): return False
1424  if(verbose >= 2): print(' Compiling virtual loop counts...')
1425  for loop in range(self.loops):
1426  for camIx in range(len(objects)):
1427  for fileIx in range(len(objects[camIx])):
1428  for i in range(len(objects[camIx][fileIx])):
1429  obj = objects[camIx][fileIx][i]
1430  t = 0
1431  for point in obj.getPositions():
1432  if(m.sqrt(pow(point.x-self.coordinates[loop].x,2)+pow(point.y-self.coordinates[loop].y,2)) < self.radius):
1433  time_h = int(m.floor(float(obj.getFirstInstant()+t)/fps/60/60))
1434  time_m15 = int(m.floor(float(obj.getFirstInstant()+t)/fps/60/15))
1435  self.coord_hourly[objects[camIx].metadatas[fileIx].getHour()+time_h][loop][0] += 1
1436  self.coord_hourly[objects[camIx].metadatas[fileIx].getHour()+time_h][loop][1].append(obj.velocities.positions[2][t])
1437  self.coord_m15[objects[camIx].metadatas[fileIx].getHour()*4+objects[camIx].metadatas[fileIx].getMinute()/15+time_m15][loop][0] += 1
1438  self.coord_m15[objects[camIx].metadatas[fileIx].getHour()*4+objects[camIx].metadatas[fileIx].getMinute()/15+time_m15][loop][1].append(obj.velocities.positions[2][t])
1439  break
1440  t += 1
1441  return True
1442 

◆ addEdgeCounts()

def lib.scene.VirtualLoops.addEdgeCounts (   self,
  objects,
  fps = 15,
  verbose = 0 
)
Add counts and speeds from edge of mask (in/out lanes).

    Input:
    ======
    objects: a nested camera/sequence ObjectSpace

Definition at line 1443 of file scene.py.

1443  def addEdgeCounts(self, objects, fps=15, verbose=0):
1444  ''' Add counts and speeds from edge of mask (in/out lanes).
1445 
1446  Input:
1447  ======
1448  objects: a nested camera/sequence ObjectSpace
1449  '''
1450  if(not objects.getAll()): return False
1451  if(verbose >= 2): print(' Compiling edge counts...')
1452  for camIx in range(len(objects)):
1453  for fileIx in range(len(objects[camIx])):
1454  for i in range(len(objects[camIx][fileIx])):
1455  obj = objects[camIx][fileIx][i]
1456  time_h_in = int(m.floor(float(obj.timeInterval.first)/fps/60/60))
1457  time_h_out = int(m.floor(float(obj.timeInterval.last)/fps/60/60))
1458  time_m15_in = int(m.floor(float(obj.timeInterval.first)/fps/60/15))
1459  time_m15_out = int(m.floor(float(obj.timeInterval.last)/fps/60/15))
1460  try:
1461  self.edge_hourly[objects[camIx].metadatas[fileIx].getHour()+time_h_in][obj.curvilinearPositions.getLanes()[0]][0][0] += 1
1462  self.edge_hourly[objects[camIx].metadatas[fileIx].getHour()+time_h_out][obj.curvilinearPositions.getLanes()[-1]][1][0] += 1
1463  self.edge_hourly[objects[camIx].metadatas[fileIx].getHour()+time_h_in][obj.curvilinearPositions.getLanes()[0]][0][1].append(obj.velocities.positions[2][0])
1464  self.edge_hourly[objects[camIx].metadatas[fileIx].getHour()+time_h_out][obj.curvilinearPositions.getLanes()[-1]][1][1].append(obj.velocities.positions[2][-1])
1465  self.edge_m15[objects[camIx].metadatas[fileIx].getHour()*4+objects[camIx].metadatas[fileIx].getMinute()/15+time_m15_in][obj.curvilinearPositions.getLanes()[0]][0][0] += 1
1466  self.edge_m15[objects[camIx].metadatas[fileIx].getHour()*4+objects[camIx].metadatas[fileIx].getMinute()/15+time_m15_out][obj.curvilinearPositions.getLanes()[-1]][1][0] += 1
1467  self.edge_m15[objects[camIx].metadatas[fileIx].getHour()*4+objects[camIx].metadatas[fileIx].getMinute()/15+time_m15_in][obj.curvilinearPositions.getLanes()[0]][0][1].append(obj.velocities.positions[2][0])
1468  self.edge_m15[objects[camIx].metadatas[fileIx].getHour()*4+objects[camIx].metadatas[fileIx].getMinute()/15+time_m15_out][obj.curvilinearPositions.getLanes()[-1]][1][1].append(obj.velocities.positions[2][-1])
1469  except AttributeError: raise Exception, [2056, 'Attempting to compile edge counts from non-existant curvilinear data for object num '+str(obj.num)+' in '+objects.metadatas[camIx].site.name+'/'+objects.metadatas[camIx].name+'/'+objects[camIx].metadatas[fileIx].name+'.']
1470  #if(verbose):
1471  # print(' Compilation report: Average objects per non-empty lane: '+str(format(sum(self.edgeChunks[-1])/len(np.nonzero(vl)[1]))))
1472  # print(' Compilation report: Missing objects report: '+str(format(m.fabs(vl[0,:].sum()-vl[1,:].sum()))))
1473  return True
1474 

◆ append()

def lib.scene.VirtualLoops.append (   self,
  value 
)

Definition at line 1411 of file scene.py.

1411  def append(self,value): return self.coordinates.append(value)

◆ count()

def lib.scene.VirtualLoops.count (   self,
  value 
)

Definition at line 1413 of file scene.py.

1413  def count(self, value): return self.coordinates.count(value)

◆ getCoordCounts()

def lib.scene.VirtualLoops.getCoordCounts (   self,
  i = [0,
  None,
  id = [0,
  None,
  m = 'hour' 
)

Definition at line 1475 of file scene.py.

1475  def getCoordCounts(self, i=[0,None], id=[0,None], m='hour'):
1476  if(m=='hour'): source = self.coord_hourly
1477  else: source = self.coord_m15
1478 
1479  if(type(i) == int): i = [i,i+1]
1480  if(type(id) == int): id = [id,id+1]
1481 
1482  r = 0
1483  for j,v in enumerate(source[i[0]:i[1]]):
1484  for k,w in enumerate(v[id[0]:id[1]]):
1485  r += w[0]
1486  return r
1487 

◆ getCoordCountVector()

def lib.scene.VirtualLoops.getCoordCountVector (   self,
  i = [0,
  None,
  m = 'hour' 
)

Definition at line 1501 of file scene.py.

1501  def getCoordCountVector(self, i=[0,None], m='hour'):
1502  r = []
1503  for j in range(self.loops):
1504  r.append(self.getCoordCounts(i=i, id=j, m=m))
1505  return r
1506 

◆ getCoordMeanSpeed()

def lib.scene.VirtualLoops.getCoordMeanSpeed (   self,
  i = [0,
  None,
  id = [0,
  None,
  m = 'hour' 
)

Definition at line 1515 of file scene.py.

1515  def getCoordMeanSpeed(self, i=[0,None], id=[0,None], m='hour'):
1516  if(m=='hour'): source = self.coord_hourly
1517  else: source = self.coord_m15
1518 
1519  if(type(i) == int): i = [i,i+1]
1520  if(type(id) == int): id = [id,id+1]
1521 
1522  r = []
1523  for j,v in enumerate(source[i[0]:i[1]]):
1524  for k,w in enumerate(v[id[0]:id[1]]):
1525  r += w[1]
1526 
1527  if(len(r)==0): return 0
1528  return sum(r)/self.getCoordCounts(i=i, id=id, m=m)
1529 

◆ getCoordMeanSpeedVector()

def lib.scene.VirtualLoops.getCoordMeanSpeedVector (   self,
  i = [0,
  None,
  m = 'hour' 
)

Definition at line 1545 of file scene.py.

1545  def getCoordMeanSpeedVector(self, i=[0,None], m='hour'):
1546  r = []
1547  for j in range(self.loops):
1548  r.append(self.getCoordMeanSpeed(i=i, id=j, m=m))
1549  return r
1550 

◆ getEdgeCounts()

def lib.scene.VirtualLoops.getEdgeCounts (   self,
  i = [0,
  None,
  lane = [0,
  None,
  side = 0,
  m = 'hour' 
)

Definition at line 1488 of file scene.py.

1488  def getEdgeCounts(self, i=[0,None], lane=[0,None], side=0, m='hour'):
1489  if(m=='hour'): source = self.edge_hourly
1490  else: source = self.edge_m15
1491 
1492  if(type(i) == int): i = [i,i+1]
1493  if(type(lane) == int): lane = [lane,lane+1]
1494 
1495  r = 0
1496  for j,v in enumerate(source[i[0]:i[1]]):
1497  for k,w in enumerate(v[lane[0]:lane[1]]):
1498  r += w[side][0]
1499  return r
1500 

◆ getEdgeCountVector()

def lib.scene.VirtualLoops.getEdgeCountVector (   self,
  i = [0,
  None,
  m = 'hour' 
)

Definition at line 1507 of file scene.py.

1507  def getEdgeCountVector(self, i=[0,None], m='hour'):
1508  r = []
1509  for j in range(self.lanes):
1510  r.append(self.getEdgeCounts(i=i, lane=j, side=0, m=m))
1511  for j in range(self.lanes):
1512  r.append(self.getEdgeCounts(i=i, lane=j, side=1, m=m))
1513  return r
1514 

◆ getEdgeMeanSpeed()

def lib.scene.VirtualLoops.getEdgeMeanSpeed (   self,
  i = [0,
  None,
  lane = [0,
  None,
  side = 0,
  m = 'hour' 
)

Definition at line 1530 of file scene.py.

1530  def getEdgeMeanSpeed(self, i=[0,None], lane=[0,None], side=0, m='hour'):
1531  if(m=='hour'): source = self.edge_hourly
1532  else: source = self.edge_m15
1533 
1534  if(type(i) == int): i = [i,i+1]
1535  if(type(lane) == int): lane = [lane,lane+1]
1536 
1537  r = []
1538  for j,v in enumerate(source[i[0]:i[1]]):
1539  for k,w in enumerate(v[lane[0]:lane[1]]):
1540  r += w[side][1]
1541 
1542  if(len(r)==0): return 0
1543  return sum(r)/self.getEdgeCounts(i=i, lane=lane, side=side, m=m)
1544 

◆ getEdgeMeanSpeedVector()

def lib.scene.VirtualLoops.getEdgeMeanSpeedVector (   self,
  i = [0,
  None,
  m = 'hour' 
)

Definition at line 1551 of file scene.py.

1551  def getEdgeMeanSpeedVector(self, i=[0,None], m='hour'):
1552  r = []
1553  for j in range(self.lanes):
1554  r.append(self.getEdgeMeanSpeed(i=i, lane=j, side=0, m=m))
1555  for j in range(self.lanes):
1556  r.append(self.getEdgeMeanSpeed(i=i, lane=j, side=1, m=m))
1557  return r
1558 

◆ index()

def lib.scene.VirtualLoops.index (   self,
  value 
)

Definition at line 1414 of file scene.py.

1414  def index(self, value): return self.coordinates.index(value)
1415 

◆ reverse()

def lib.scene.VirtualLoops.reverse (   self)

Definition at line 1412 of file scene.py.

1412  def reverse(self): self.coordinates.reverse();return None

◆ write()

def lib.scene.VirtualLoops.write (   self)
This should be called from the parent object in order to store the
    data properly in a DB using SQLAlchemy.

Definition at line 1559 of file scene.py.

1559  def write(self):
1560  ''' This should be called from the parent object in order to store the
1561  data properly in a DB using SQLAlchemy.
1562  '''
1563  storage_value = []
1564  for data in self.coordinates:
1565  storage_value.append(data.write())
1566  return_val = '['+','.join(map(str, storage_value))+']'
1567 
1568  if(return_val == '[]'): return ''
1569  else: return return_val
1570 
1571 
def join(obj1, obj2, postSmoothing=True)
Definition: tools_obj.py:816

Member Data Documentation

◆ coord_hourly

lib.scene.VirtualLoops.coord_hourly

Definition at line 1401 of file scene.py.

◆ coord_m15

lib.scene.VirtualLoops.coord_m15

Definition at line 1402 of file scene.py.

◆ coordinates

lib.scene.VirtualLoops.coordinates

Definition at line 1394 of file scene.py.

◆ edge_hourly

lib.scene.VirtualLoops.edge_hourly

Definition at line 1399 of file scene.py.

◆ edge_m15

lib.scene.VirtualLoops.edge_m15

Definition at line 1400 of file scene.py.

◆ lanes

lib.scene.VirtualLoops.lanes

Definition at line 1397 of file scene.py.

◆ loops

lib.scene.VirtualLoops.loops

Definition at line 1396 of file scene.py.

◆ radius

lib.scene.VirtualLoops.radius

Definition at line 1398 of file scene.py.


The documentation for this class was generated from the following file: