Exemplo n.º 1
0
def processConsistency(config, scbFile=None):
    '''Performs the work of deviation from data in the config file, with an optional
    override on the scbFile to process'''

    if (scbFile == None):
        scbFile = config['SCB']

    # TODO: ultimately extract start, max frames, max agents, target agent, frame sample from config
    try:
        # TODO: for testing purposes, I've got these arguments to facilitate testing
        ##        data = NPFrameSet( scbFile )
        data = NPFrameSet(scbFile, startFrame=5, maxFrames=15, maxAgents=1)
    except IOError:
        raise IOError('No such scb file: %s' % (scbFile))
    except:
        raise IOError("Unable to read scb file: %s" % (scbFile))

    if (data.version != '2.2'):
        raise ValueError(
            'Can only perform consistency analysis on scb version 2.2. Indicated scb file is version %s'
            % (data.version))

    print "SCB file: ", scbFile
    print "\tNumber of agents:", data.agentCount()

    # compute the deviation, producing a .deviation file
    computeDeviation(data, config)
    # compute the consistency, producing a .consistency file
    computeConsistency(config)
    # compute correlation between density and consistency
    correlateConsistency(config)
Exemplo n.º 2
0
def addSCBOrientation( inFile, outFile, maxVel, window=1 ):
    '''Given an scb file, adds orientation to it based on max angular velocity, saving the result to
    the outFile.'''
    scbData = NPFrameSet( inFile )
    fullData = scbData.fullData()
    addOrientation( fullData, scbData.simStepSize * maxVel * window, window)

    scbData.close()
    writeNPSCB( outFile, fullData, scbData, scbData.version )  
Exemplo n.º 3
0
 def execute(self):
     '''Perform the work of the task'''
     if (self.work):
         print 'Population analysis: %s' % (self.workName)
         print "\tAccessing scb file:", self.scbName
         frameSet = NPFrameSet(self.scbName)
         names = self.rectNames
         rects = self.rects
         workPath = self.getWorkPath('population')
         tempFile = os.path.join(workPath, self.workName)
         if (self.work & AnalysisTask.COMPUTE):
             print '\tComputing'
             s = time.clock()
             Crowd.computePopulation(frameSet, rects, tempFile, names)
             print '\t\tdone in %.2f seconds' % (time.clock() - s)
         if (self.work & AnalysisTask.VIS):
             if (not os.path.exists(tempFile + ".pop")):
                 print "\tCan't create population plots - unable to locate file: %s" % tempFile
                 return
             print '\tComputing plots'
             s = time.clock()
             Crowd.plotPopulation(tempFile,
                                  frameSet.simStepSize,
                                  titlePrefix=self.workName,
                                  legendStr=names)
             print '\t\tdone in %.2f seconds' % (time.clock() - s)
Exemplo n.º 4
0
 def execute(self):
     '''Perform the work of the task'''
     if (self.work):
         print 'Flow analysis: %s' % (self.workName)
         print "\tAccessing scb file:", self.scbName
         frameSet = NPFrameSet(self.scbName)
         names = self.lineNames
         lines = self.lines
         workPath = self.getWorkPath('flow')
         tempFile = os.path.join(workPath, self.workName)
         if (self.work & AnalysisTask.COMPUTE):
             print '\tComputing'
             s = time.clock()
             Crowd.computeFlow(frameSet, lines, tempFile, names)
             print '\t\tdone in %.2f seconds' % (time.clock() - s)
         if (self.work & AnalysisTask.VIS):
             if (not os.path.exists(tempFile + ".flow")):
                 print "\tCan't create flow plots - unable to locate file: %s" % tempFile
                 return
             print '\tComputing plots'
             s = time.clock()
             # this gives the ability to change the pre-computed names
             timeStep = frameSet.simStepSize
             if (frameSet.version[0] == '1'):
                 timeStep = self.timeStep
             Crowd.plotFlow(tempFile,
                            frameSet.simStepSize,
                            titlePrefix=self.workName,
                            legendStr=names)
             print '\t\tdone in %.2f seconds' % (time.clock() - s)
Exemplo n.º 5
0
 def execute(self):
     '''Perform the work of the task'''
     if (self.work):
         print 'Speed analysis: %s' % (self.workName)
         print "\tAccessing scb file:", self.scbName
         frameSet = NPFrameSet(self.scbName)
         workPath = self.getWorkPath('speed')
         tempFile = os.path.join(workPath, self.workName)
         grids = Crowd.GridFileSequence(tempFile)
         if (self.work & AnalysisTask.COMPUTE):
             print "\tComputing"
             domain = makeDomain(self.domainX, self.domainY, self.cellSize)
             s = time.clock()
             grids.computeSpeeds(domain, frameSet, self.timeStep)
             print '\t\tdone in %.2f seconds' % (time.clock() - s)
         if (self.work & AnalysisTask.VIS):
             dataFile = grids.outFileName + ".speed"
             if (not os.path.exists(dataFile)):
                 print "\tCan't visualize speed - unable to locate file: %s" % dataFile
                 return
             imageName = os.path.join(workPath, '%s_speed_' % self.workName)
             s = time.clock()
             reader = Crowd.GridFileSequenceReader(dataFile)
             try:
                 colorMap = COLOR_MAPS[self.colorMapName]
             except:
                 print '\tError loading color map: "%s", loading flame instead' % (
                     self.colorMapName)
                 colorMap = COLOR_MAPS['flame']
             print '\tCreating images'
             visualizeGFS(reader, colorMap, imageName, self.outImgType, 1.0,
                          None)
             print '\t\tdone in %.2f seconds' % (time.clock() - s)
Exemplo n.º 6
0
    def execute(self):
        '''Perform the work of the task'''
        if (self.work):
            print 'Density analysis: %s' % (self.workName)
            print "\tAccessing scb file:", self.scbName
            frameSet = NPFrameSet(self.scbName)
            workPath = self.getWorkPath('density')
            tempFile = os.path.join(workPath, self.workName)
            grids = Crowd.GridFileSequence(tempFile)
            if (self.work & AnalysisTask.COMPUTE):
                print "\tComputing"
                kernel = Kernels.GaussianKernel(self.smoothParam,
                                                self.cellSize, False)
                domain = makeDomain(self.domainX, self.domainY, self.cellSize)
                sigDomain = makeDomain(self.domainX, self.domainY)
                signal = Signals.PedestrianSignal(
                    sigDomain
                )  # signal domain is the same as convolution domain

                s = time.clock()
                grids.convolveSignal(domain, kernel, signal, frameSet)
                print '\t\tdone in %.2f seconds' % (time.clock() - s)
            if (self.work & AnalysisTask.VIS):
                dataFile = grids.outFileName + ".density"
                if (not os.path.exists(dataFile)):
                    print "\tCan't visualize density - unable to locate file: %s" % dataFile
                    return
                imageName = os.path.join(workPath,
                                         '%s_density_' % self.workName)
                s = time.clock()
                reader = Crowd.GridFileSequenceReader(dataFile)
                try:
                    colorMap = COLOR_MAPS[self.colorMapName]
                except:
                    print '\tError loading color map: "%s", loading flame instead' % (
                        self.colorMapName)
                    colorMap = COLOR_MAPS['flame']
                print '\tCreating images'
                visualizeGFS(frameSet.totalFrames(), reader, colorMap,
                             imageName, self.outImgType, 1.0, None)
                print '\t\tdone in %.2f seconds' % (time.clock() - s)
Exemplo n.º 7
0
 def execute(self):
     '''Perform the work of the task'''
     if (self.work):
         print 'Fundamental diagram analysis: %s' % (self.workName)
         print "\tAccessing scb file:", self.scbName
         frameSet = NPFrameSet(self.scbName)
         names = self.rectNames
         rects = self.rects
         workPath = self.getWorkPath('fundDiag')
         tempFile = os.path.join(workPath, self.workName)
         if (self.work & AnalysisTask.COMPUTE):
             print '\tComputing'
             s = time.clock()
             Crowd.computeFundDiag(frameSet, rects, tempFile, names)
             print '\t\tdone in %.2f seconds' % (time.clock() - s)
         if (self.work & AnalysisTask.VIS):
             print '\tCreating plots'
             s = time.clock()
             Crowd.plotFundDiag(tempFile, rects, names)
             print '\t\tdone in %.2f seconds' % (time.clock() - s)