tvaLib
Public Member Functions | Public Attributes | List of all members
lib.scene.SiteAnalysis Class Reference
Inheritance diagram for lib.scene.SiteAnalysis:

Public Member Functions

def __init__ (self, site_analysis, config, sites=None)
 
def write (self, site_analysis)
 
def getFullResultsFolder (self, analysis=None, customSubPath='')
 
def getFullConfigurationFilename (self, analysis='Analysis')
 
def getGridHexSize (self)
 
def getCombinedMasks (self)
 
def getCamSeqs (self)
 
def getCountObjects (self)
 
def getDurationUnit (self)
 
def getDuration (self)
 
def getStartTime (self)
 
def getEndTime (self)
 
def getSequenceCount (self)
 
def getCamSeqs_Hourly (self)
 
def getCamSeqs_AMPM (self)
 
def getCamSeqsInInterval (self, i)
 
def getADT (self, hourly_expansion_factors=None, kwargs)
 
def getAADT (self, hourly_expansion_factors=None, doweek_expansion_factors=None, monthly_expansion_factors=None, kwargs)
 
def exportToCode (self, moduleName='tvaMetaData', justifyCol1=55, justifyCol2=35)
 
def findLowestMPversion (self)
 

Public Attributes

 config
 
 idx
 
 name
 Cleanup. More...
 
 startTimes
 
 endTimes
 
 description
 
 configurationFilename
 
 temp_avg
 
 precipitation
 
 glare
 
 geo_1
 
 geo_2
 
 geo_3
 
 geo_4
 
 geo_5
 
 max_speed
 
 hex_grid_x
 
 hex_grid_y
 
 camIds
 Create and link abstract objects from data Camera stuff. More...
 
 cameras
 
 zone
 
 site
 
 virtual_loops
 
 xy_bounds
 
 cm_bounds
 
 timeIntervals
 
 monthly_expansion_factors_data
 
 doweek_expansion_factors_data
 
 hourly_expansion_factors_data
 
 monthly_expansion_factors
 
 doweek_expansion_factors
 
 hourly_expansion_factors
 
 resultsFolder
 

Detailed Description

Definition at line 637 of file scene.py.

Constructor & Destructor Documentation

◆ __init__()

def lib.scene.SiteAnalysis.__init__ (   self,
  site_analysis,
  config,
  sites = None 
)

Definition at line 638 of file scene.py.

638  def __init__(self, site_analysis, config, sites=None):
639  tvaLib.Constructors.SuperList.__init__(self)
640  self.config = config
641  self.idx = site_analysis.idx
642  self.name = site_analysis.name
643  self.startTimes = site_analysis.startTimes
644  self.endTimes = site_analysis.endTimes
645  self.description = site_analysis.description
646  self.configurationFilename = site_analysis.configurationFilename
647  self.temp_avg = site_analysis.temp_avg
648  self.precipitation = site_analysis.precipitation
649  self.glare = site_analysis.glare
650  self.geo_1 = site_analysis.geo_1
651  self.geo_2 = site_analysis.geo_2
652  self.geo_3 = site_analysis.geo_3
653  self.geo_4 = site_analysis.geo_4
654  self.geo_5 = site_analysis.geo_5
655  self.max_speed = site_analysis.max_speed
656  self.hex_grid_x = site_analysis.hex_grid_x
657  self.hex_grid_y = site_analysis.hex_grid_y
658 
659 
661  self.camIds = tvaLib.Constructors.SuperListParse(site_analysis.camIds, dimension=1)
662  self.cameras = [item for sublist in [[cam for cam in site if cam.idx in self.camIds] for site in sites] for item in sublist]
663  self.zone = tvaLib.Constructors.SuperListParse(site_analysis.zone, dimension=3, datatype='point')
664  if(self.cameras):
665  self.site = Site(self.cameras[0].site, self.config)
666  self.virtual_loops = VirtualLoops(site_analysis.virtual_loops, nLanes=len(self.site.alignments))
667  else: self.virtual_loops = VirtualLoops(site_analysis.virtual_loops, nLanes=0)
668  self.xy_bounds = tvaLib.Constructors.SuperListParse(site_analysis.xy_bounds, datatype='bound')
669  self.cm_bounds = tvaLib.Constructors.SuperListParse(site_analysis.cm_bounds, datatype='bound')
670  #Time Intervals
671  self.timeIntervals = []
672  if(self.startTimes != 'all' and self.endTimes != 'all'):
673  startTimes = tvaLib.Constructors.SuperListParse(self.startTimes, dimension=1)
674  endTimes = tvaLib.Constructors.SuperListParse(self.startTimes, dimension=1)
675  for intervalIx in range(min(len(startTimes),len(endTimes))):
676  self.timeIntervals.append([datetime.strptime(startTimes[intervalIx], '%Y-%m-%d %H:%M:%S'),datetime.strptime(endTimes[intervalIx], '%Y-%m-%d %H:%M:%S')])
677  #Expansion factors
678  try: self.monthly_expansion_factors_data = site_analysis.monthly_expansion_factors
679  except: self.monthly_expansion_factors_data = None
680  try: self.doweek_expansion_factors_data = site_analysis.doweek_expansion_factors
681  except: self.doweek_expansion_factors_data = None
682  try: self.hourly_expansion_factors_data = site_analysis.expansion_factors
683  except: self.hourly_expansion_factors_data = None
684  if(self.monthly_expansion_factors_data):
685  self.monthly_expansion_factors = tvaLib.Constructors.SuperListParse(self.monthly_expansion_factors_data, dimension=1)
686  if(len(self.monthly_expansion_factors) != 12): self.monthly_expansion_factors = None
687  else: self.monthly_expansion_factors = config.monthly_expansion_factors
688  if(self.doweek_expansion_factors_data):
689  self.doweek_expansion_factors = tvaLib.Constructors.SuperListParse(self.doweek_expansion_factors_data, dimension=1)
690  if(len(self.doweek_expansion_factors) != 7): self.doweek_expansion_factors = None
691  else: self.doweek_expansion_factors = config.doweek_expansion_factors
692  if(self.hourly_expansion_factors_data):
693  self.hourly_expansion_factors = tvaLib.Constructors.SuperListParse(self.hourly_expansion_factors_data, dimension=1)
694  if(len(self.hourly_expansion_factors) != 24): self.hourly_expansion_factors = None
695  else: self.hourly_expansion_factors = config.hourly_expansion_factors
696 
697  if(not self.name): self.name = tvaLib.flatten_list([[site.name for y in site if y.idx in self.camIds] for site in sites])[0]+':'+','.join([x.name for x in self.cameras])
698  self.resultsFolder = str(self.idx)+'_'+''.join([c for c in self.name if c.isalpha() or c.isdigit() or c==' ']).rstrip()[:35]
699  return
700 
def join(obj1, obj2, postSmoothing=True)
Definition: tools_obj.py:816

Member Function Documentation

◆ exportToCode()

def lib.scene.SiteAnalysis.exportToCode (   self,
  moduleName = 'tvaMetaData',
  justifyCol1 = 55,
  justifyCol2 = 35 
)
Dump this object's data as executable code. 

Definition at line 807 of file scene.py.

807  def exportToCode(self, moduleName='tvaMetaData', justifyCol1=55, justifyCol2=35):
808  ''' Dump this object's data as executable code. '''
809  camera_names = ["x.name=='"+x.name+"'" for x in self.cameras]
810  print("site_analyses.append("+moduleName+".SiteAnalysis(str([x.idx for x in cameras if "+(' and '.join(camera_names)).ljust(justifyCol1)+" and x.site.name=='"+(self.site.name+"']),").ljust(justifyCol2)+" startTimes='"+str(self.startTimes)+"', endTimes='"+str(self.endTimes)+"', zone='"+self.zone.write()+"', xy_bounds='"+self.xy_bounds.write()+"', cm_bounds='"+self.cm_bounds.write()+"', max_speed="+str(self.max_speed)+", virtual_loops='"+self.virtual_loops.write()+"', expansion_factors='"+self.hourly_expansion_factors.write()+"'))")
811 
812 
def join(obj1, obj2, postSmoothing=True)
Definition: tools_obj.py:816

◆ findLowestMPversion()

def lib.scene.SiteAnalysis.findLowestMPversion (   self)

Definition at line 813 of file scene.py.

813  def findLowestMPversion(self):
814  import cPickle as pickle
815  lowest_version = None
816  for saCam in self.cameras:
817  try:
818  with open(os.path.join(saCam.getBaseDirectory(), 'dmp.mp'), 'rb') as input_data:
819  s_version = pickle.load(input_data)
820  #TODO: Keep lowest version. not last
821  if(lowest_version): lowest_version = s_version.split()[0]
822  else: lowest_version = s_version.split()[0]
823  except: pass
824  return lowest_version
825 
826 

◆ getAADT()

def lib.scene.SiteAnalysis.getAADT (   self,
  hourly_expansion_factors = None,
  doweek_expansion_factors = None,
  monthly_expansion_factors = None,
  kwargs 
)
Compute, update, and return Average Annual Daily Traffic. See
    Scene.getADT() for list of exposure types.

Definition at line 795 of file scene.py.

795  def getAADT(self, hourly_expansion_factors=None, doweek_expansion_factors=None, monthly_expansion_factors=None, **kwargs):
796  ''' Compute, update, and return Average Annual Daily Traffic. See
797  Scene.getADT() for list of exposure types.
798  '''
799  if((not monthly_expansion_factors and not self.monthly_expansion_factors) or (not doweek_expansion_factors and not self.doweek_expansion_factors) or (not hourly_expansion_factors and not self.hourly_expansion_factors)): return False
800  if(self.monthly_expansion_factors): monthly_expansion_factors = self.monthly_expansion_factors
801  if(self.doweek_expansion_factors): doweek_expansion_factors = self.doweek_expansion_factors
802  if(self.hourly_expansion_factors): hourly_expansion_factors = self.hourly_expansion_factors
803  AADTs = filter(None, [cam.getAADT(hourly_expansion_factors, doweek_expansion_factors, monthly_expansion_factors, **kwargs) for cam in self.cameras])
804  if(AADTs == []): return None
805  else: return sum(AADTs)/float(len(AADTs))
806 

◆ getADT()

def lib.scene.SiteAnalysis.getADT (   self,
  hourly_expansion_factors = None,
  kwargs 
)
Compute, update, and return Average Daily Traffic. See
    Scene.getADT() for more information.

Definition at line 785 of file scene.py.

785  def getADT(self, hourly_expansion_factors=None, **kwargs):
786  ''' Compute, update, and return Average Daily Traffic. See
787  Scene.getADT() for more information.
788  '''
789  if(not hourly_expansion_factors and not self.hourly_expansion_factors): return False
790  if(self.hourly_expansion_factors): hourly_expansion_factors = self.hourly_expansion_factors
791  ADTs = filter(None, [cam.getAADT(hourly_expansion_factors, **kwargs) for cam in self.cameras])
792  if(ADTs == []): return None
793  else: return sum(ADTs)/float(len(ADTs))
794 

◆ getCamSeqs()

def lib.scene.SiteAnalysis.getCamSeqs (   self)

Definition at line 745 of file scene.py.

745  def getCamSeqs(self): return self.getCamSeqsInInterval(None)

◆ getCamSeqs_AMPM()

def lib.scene.SiteAnalysis.getCamSeqs_AMPM (   self)
Return a dictionary of AM and PM values containing a list of
    sequences associated with that time (AM->0-11, PM->12-23). 

Definition at line 763 of file scene.py.

763  def getCamSeqs_AMPM(self):
764  ''' Return a dictionary of AM and PM values containing a list of
765  sequences associated with that time (AM->0-11, PM->12-23). '''
766  ampm = {'am':[],'pm':[]}
767  for camera in self.cameras:
768  for sequence in camera:
769  if(sequence.getHour() <= 11): ampm['am'].append(sequence)
770  else: ampm['pm'].append(sequence)
771  return ampm
772 

◆ getCamSeqs_Hourly()

def lib.scene.SiteAnalysis.getCamSeqs_Hourly (   self)
Return dictionary of daily hours (0-23) containing a list of
    sequences associated with that hour. 

Definition at line 753 of file scene.py.

753  def getCamSeqs_Hourly(self):
754  ''' Return dictionary of daily hours (0-23) containing a list of
755  sequences associated with that hour. '''
756  hours = {}
757  for camera in self.cameras:
758  for sequence in camera:
759  if(sequence.getHour() not in hours): hours[sequence.getHour()] = [sequence]
760  else: hours[sequence.getHour()].append(sequence)
761  return hours
762 

◆ getCamSeqsInInterval()

def lib.scene.SiteAnalysis.getCamSeqsInInterval (   self,
  i 
)
If i is None (default), or no timeIntervals defined, returns all
    sequences on all intervals. 

Definition at line 773 of file scene.py.

773  def getCamSeqsInInterval(self, i):
774  ''' If i is None (default), or no timeIntervals defined, returns all
775  sequences on all intervals. '''
776  cam_seqs = []
777  for camera in self.cameras:
778  for sequence in camera:
779  if(i == None or not self.timeIntervals):
780  cam_seqs.append(sequence)
781  # TODO: filter by timeinterval (as opposed to just dumping all)
782  #import pdb; pdb.set_trace()
783  return cam_seqs
784 

◆ getCombinedMasks()

def lib.scene.SiteAnalysis.getCombinedMasks (   self)

Definition at line 744 of file scene.py.

744  def getCombinedMasks(self): return self.site.getCombinedMasks()

◆ getCountObjects()

def lib.scene.SiteAnalysis.getCountObjects (   self)

Definition at line 746 of file scene.py.

746  def getCountObjects(self): return sum([cam.getCountObjects() for cam in self.cameras])

◆ getDuration()

def lib.scene.SiteAnalysis.getDuration (   self)

Definition at line 748 of file scene.py.

748  def getDuration(self): return sum([cam.getDuration() for cam in self.cameras])

◆ getDurationUnit()

def lib.scene.SiteAnalysis.getDurationUnit (   self)

Definition at line 747 of file scene.py.

747  def getDurationUnit(self): return self.cameras[0].getDurationUnit()

◆ getEndTime()

def lib.scene.SiteAnalysis.getEndTime (   self)

Definition at line 750 of file scene.py.

750  def getEndTime(self): return max([cam.getEndTime() for cam in self.cameras])

◆ getFullConfigurationFilename()

def lib.scene.SiteAnalysis.getFullConfigurationFilename (   self,
  analysis = 'Analysis' 
)

Definition at line 737 of file scene.py.

737  def getFullConfigurationFilename(self, analysis='Analysis'):
738  if(self.configurationFilename and os.path.exists(os.path.join(self.getFullResultsFolder(analysis), self.configurationFilename))): return os.path.join(self.getFullResultsFolder(self.config.dir, analysis), self.configurationFilename)
739  else: return self.cameras[0].getFullConfigurationFilename()
740 

◆ getFullResultsFolder()

def lib.scene.SiteAnalysis.getFullResultsFolder (   self,
  analysis = None,
  customSubPath = '' 
)

Definition at line 733 of file scene.py.

733  def getFullResultsFolder(self, analysis=None, customSubPath=''):
734  if(analysis==None): analysis = self.config.output_folder
735  if(not os.path.exists(os.path.join(self.config.dir, analysis, self.resultsFolder, customSubPath))): os.makedirs(os.path.join(self.config.dir, analysis, self.resultsFolder, customSubPath))
736  return os.path.join(self.config.dir, analysis, self.resultsFolder, customSubPath)

◆ getGridHexSize()

def lib.scene.SiteAnalysis.getGridHexSize (   self)

Definition at line 741 of file scene.py.

741  def getGridHexSize(self):
742  if(not self.hex_grid_x or not self.hex_grid_y): return self.config.hex_grid_dimension
743  else: return [self.hex_grid_x, self.hex_grid_y]

◆ getSequenceCount()

def lib.scene.SiteAnalysis.getSequenceCount (   self)

Definition at line 751 of file scene.py.

751  def getSequenceCount(self): return sum([len(cam) for cam in self.cameras])
752 

◆ getStartTime()

def lib.scene.SiteAnalysis.getStartTime (   self)

Definition at line 749 of file scene.py.

749  def getStartTime(self): return min([cam.getStartTime() for cam in self.cameras])

◆ write()

def lib.scene.SiteAnalysis.write (   self,
  site_analysis 
)

Definition at line 701 of file scene.py.

701  def write(self, site_analysis):
702  site_analysis.idx = self.idx
703  site_analysis.name = self.name
704  site_analysis.startTimes = self.startTimes
705  site_analysis.endTimes = self.endTimes
706  site_analysis.description = self.description
707  site_analysis.configurationFilename = self.configurationFilename
708  site_analysis.temp_avg = self.temp_avg
709  site_analysis.precipitation = self.precipitation
710  site_analysis.glare = self.glare
711  site_analysis.geo_1 = self.geo_1
712  site_analysis.geo_2 = self.geo_2
713  site_analysis.geo_3 = self.geo_3
714  site_analysis.geo_4 = self.geo_4
715  site_analysis.geo_5 = self.geo_5
716  site_analysis.max_speed = self.max_speed
717  site_analysis.hex_grid_x = self.hex_grid_x
718  site_analysis.hex_grid_y = self.hex_grid_y
719 
720  site_analysis.zone = self.zone.write()
721  site_analysis.virtual_loops = self.virtual_loops.write()
722  site_analysis.xy_bounds = self.xy_bounds.write()
723  site_analysis.cm_bounds = self.cm_bounds.write()
724 
725  try: site_analysis.monthly_expansion_factors = self.monthly_expansion_factors.write()
726  except: pass
727  try: site_analysis.doweek_expansion_factors = self.doweek_expansion_factors.write()
728  except: pass
729  try: site_analysis.expansion_factors = self.hourly_expansion_factors.write()
730  except: pass
731  return site_analysis
732 

Member Data Documentation

◆ cameras

lib.scene.SiteAnalysis.cameras

Definition at line 662 of file scene.py.

◆ camIds

lib.scene.SiteAnalysis.camIds

Create and link abstract objects from data Camera stuff.

Definition at line 661 of file scene.py.

◆ cm_bounds

lib.scene.SiteAnalysis.cm_bounds

Definition at line 669 of file scene.py.

◆ config

lib.scene.SiteAnalysis.config

Definition at line 640 of file scene.py.

◆ configurationFilename

lib.scene.SiteAnalysis.configurationFilename

Definition at line 646 of file scene.py.

◆ description

lib.scene.SiteAnalysis.description

Definition at line 645 of file scene.py.

◆ doweek_expansion_factors

lib.scene.SiteAnalysis.doweek_expansion_factors

Definition at line 689 of file scene.py.

◆ doweek_expansion_factors_data

lib.scene.SiteAnalysis.doweek_expansion_factors_data

Definition at line 680 of file scene.py.

◆ endTimes

lib.scene.SiteAnalysis.endTimes

Definition at line 644 of file scene.py.

◆ geo_1

lib.scene.SiteAnalysis.geo_1

Definition at line 650 of file scene.py.

◆ geo_2

lib.scene.SiteAnalysis.geo_2

Definition at line 651 of file scene.py.

◆ geo_3

lib.scene.SiteAnalysis.geo_3

Definition at line 652 of file scene.py.

◆ geo_4

lib.scene.SiteAnalysis.geo_4

Definition at line 653 of file scene.py.

◆ geo_5

lib.scene.SiteAnalysis.geo_5

Definition at line 654 of file scene.py.

◆ glare

lib.scene.SiteAnalysis.glare

Definition at line 649 of file scene.py.

◆ hex_grid_x

lib.scene.SiteAnalysis.hex_grid_x

Definition at line 656 of file scene.py.

◆ hex_grid_y

lib.scene.SiteAnalysis.hex_grid_y

Definition at line 657 of file scene.py.

◆ hourly_expansion_factors

lib.scene.SiteAnalysis.hourly_expansion_factors

Definition at line 693 of file scene.py.

◆ hourly_expansion_factors_data

lib.scene.SiteAnalysis.hourly_expansion_factors_data

Definition at line 682 of file scene.py.

◆ idx

lib.scene.SiteAnalysis.idx

Definition at line 641 of file scene.py.

◆ max_speed

lib.scene.SiteAnalysis.max_speed

Definition at line 655 of file scene.py.

◆ monthly_expansion_factors

lib.scene.SiteAnalysis.monthly_expansion_factors

Definition at line 685 of file scene.py.

◆ monthly_expansion_factors_data

lib.scene.SiteAnalysis.monthly_expansion_factors_data

Definition at line 678 of file scene.py.

◆ name

lib.scene.SiteAnalysis.name

Cleanup.

Definition at line 642 of file scene.py.

◆ precipitation

lib.scene.SiteAnalysis.precipitation

Definition at line 648 of file scene.py.

◆ resultsFolder

lib.scene.SiteAnalysis.resultsFolder

Definition at line 698 of file scene.py.

◆ site

lib.scene.SiteAnalysis.site

Definition at line 665 of file scene.py.

◆ startTimes

lib.scene.SiteAnalysis.startTimes

Definition at line 643 of file scene.py.

◆ temp_avg

lib.scene.SiteAnalysis.temp_avg

Definition at line 647 of file scene.py.

◆ timeIntervals

lib.scene.SiteAnalysis.timeIntervals

Definition at line 671 of file scene.py.

◆ virtual_loops

lib.scene.SiteAnalysis.virtual_loops

Definition at line 666 of file scene.py.

◆ xy_bounds

lib.scene.SiteAnalysis.xy_bounds

Definition at line 668 of file scene.py.

◆ zone

lib.scene.SiteAnalysis.zone

Definition at line 663 of file scene.py.


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