Exemplo n.º 1
0
def SaveState(paramFile, params, volumeFile, volume, origTrackFile,
              filtTrackFile, tracks, falarms, polygonfile, polygons):
    # Do I need to update the Params?
    volume['volume_data'] = SortVolume(volume['volume_data'])
    TrackFileUtils.SaveCorners(volumeFile,
                               volume['corner_filestem'],
                               volume['volume_data'],
                               path=os.path.dirname(volumeFile))
    ParamUtils.SaveConfigFile(paramFile, params)
    TrackFileUtils.SaveTracks(origTrackFile, tracks, falarms)
    TrackFileUtils.SaveTracks(filtTrackFile, tracks, falarms)

    # TODO: Save polygons in a better format
    dump(polygons, open(polygonfile, 'wb'))
Exemplo n.º 2
0
def SCIT_Track(trackRun, simParams, trackParams, returnResults=True, path='.'):

    dirName = path
    cornerInfo = TrackFileUtils.ReadCorners(os.path.join(
        dirName, simParams['inputDataFile']),
                                            path=dirName)
    if simParams['frameCnt'] <= 1:
        raise Exception("Not enough frames for tracking: %d" %
                        simParams['frameCnt'])

    lasttime = _load_times(simParams, cornerInfo['volume_data'])

    import scit

    speedThresh = float(trackParams['speedThresh'])
    framesBack = int(trackParams['framesBack'])
    default_dir = float(trackParams['default_dir'])
    default_spd = float(trackParams['default_spd'])

    stateHist = []
    strmTracks = []
    infoTracks = []

    strmAdap = {
        'spdThresh': speedThresh,
        'framesBack': framesBack,
        'default_dir': default_dir,
        'default_spd': default_spd,
        'max_timestep': 15.0
    }

    frameOffset = cornerInfo['volume_data'][0]['frameNum']

    for aVol in cornerInfo['volume_data']:
        currtime = aVol['volTime']
        tDelta = currtime - lasttime
        lasttime = currtime
        scit.TrackStep_SCIT(strmAdap, stateHist, strmTracks, infoTracks, aVol,
                            tDelta, frameOffset)

    scit.EndTracks(stateHist, strmTracks)

    falarms = []
    TrackUtils.CleanupTracks(strmTracks, falarms)
    TrackFileUtils.SaveTracks(
        os.path.join(dirName, simParams['result_file'] + "_" + trackRun),
        strmTracks, falarms)

    if returnResults:
        return strmTracks, falarms
Exemplo n.º 3
0
def track_wrap(f):
    def perform_tracking(trackRun,
                         simParams,
                         trackParams,
                         returnResults=True,
                         path='.'):
        dirName = path
        cornerInfo = TrackFileUtils.ReadCorners(os.path.join(
            dirName, simParams['inputDataFile']),
                                                path=dirName)

    if len(cornerInfo['volume_data']) <= 1:
        raise Exception("Not enough frames for tracking: %d" %
                        len(cornerInfo['volume_data']))

    lasttime = _load_times(simParams, cornerInfo['volume_data'])

    tracks, falarms = f(trackParams, lasttime)

    TrackUtils.CleanupTracks(tracks, falarms)
    TrackFileUtils.SaveTracks(
        os.path.join(dirName, simParams['result_file'] + "_" + trackRun),
        tracks, falarms)

    if returnResults:
        return tracks, falarms
Exemplo n.º 4
0
def MHT_Track(trackRun, simParams, trackParams, returnResults=True, path='.'):
    import mht
    progDir = "~/Programs/mht_tracking/tracking/"
    dirName = path
    # Popping off the ParamFile key so that the rest of the available
    # configs can be used for making the MHT parameter file.
    paramFile, paramName = tempfile.mkstemp(text=True)
    # Don't need it open, just pass the name along.
    os.close(paramFile)

    # Temporary popping...
    trackParams.pop("algorithm")

    mht.SaveMHTParams(paramName, trackParams)
    resultFile = os.path.join(dirName,
                              simParams['result_file'] + '_' + trackRun)

    retcode = mht.track(resultFile, paramName,
                        os.path.join(dirName, simParams['inputDataFile']),
                        dirName)

    if retcode != 0:
        raise Exception("MHT Tracker failed! ResultFile: %s ParamFile: %s" %
                        (resultFile, paramName))

    os.remove(paramName)

    if returnResults:
        tracks = TrackFileUtils.ReadTracks(resultFile)
        return TrackUtils.FilterMHTTracks(*tracks)
Exemplo n.º 5
0
 def perform_tracking(trackRun,
                      simParams,
                      trackParams,
                      returnResults=True,
                      path='.'):
     dirName = path
     cornerInfo = TrackFileUtils.ReadCorners(os.path.join(
         dirName, simParams['inputDataFile']),
                                             path=dirName)
Exemplo n.º 6
0
def ASCIT_Track(trackRun,
                simParams,
                trackParams,
                returnResults=True,
                path='.'):
    import ascit
    dirName = path
    cornerInfo = TrackFileUtils.ReadCorners(os.path.join(
        dirName, simParams['inputDataFile']),
                                            path=dirName)
    speedThresh = float(trackParams['speedThresh'])
    default_spd = float(trackParams['default_spd'])

    if simParams['frameCnt'] <= 1:
        raise Exception("Not enough frames for tracking: %d" %
                        simParams['frameCnt'])

    lasttime = _load_times(simParams, cornerInfo['volume_data'])

    t = ascit.ASCIT(framesBack=int(trackParams['framesBack']),
                    default_dir=float(trackParams['default_dir']))
    for aVol in cornerInfo['volume_data']:
        currtime = aVol['volTime']
        tDelta = currtime - lasttime
        t.distThresh = speedThresh * tDelta
        t._default_spd = default_spd * tDelta
        t.TrackStep(aVol, tDelta)
        lasttime = currtime

    # Tidy up tracks because there won't be any more data
    t.finalize()

    tracks = t.tracks
    falarms = []
    TrackUtils.CleanupTracks(tracks, falarms)
    TrackFileUtils.SaveTracks(
        os.path.join(dirName, simParams['result_file'] + "_" + trackRun),
        tracks, falarms)

    if returnResults:
        return tracks, falarms
Exemplo n.º 7
0
def main(args):
    dirName = os.path.join(args.path, args.scenario)

    paramFile = os.path.join(dirName, "simParams.conf")

    if os.path.exists(paramFile):
        sceneParams = ParamUtils.ReadSimulationParams(paramFile)
    else:
        sceneParams = dict()
        sceneParams.update(ParamUtils.simDefaults)
        sceneParams.update(ParamUtils.trackerDefaults)

        sceneParams.pop('seed')
        sceneParams.pop('totalTracks')
        sceneParams.pop('endTrackProb')
        sceneParams.pop('simConfFile')

        sceneParams['simName'] = args.scenario

    origTrackFile = os.path.join(dirName, sceneParams['simTrackFile'])
    filtTrackFile = os.path.join(dirName, sceneParams['noisyTrackFile'])
    volumeFile = os.path.join(dirName, sceneParams['inputDataFile'])
    volumeLoc = os.path.dirname(volumeFile)

    tracks, falarms = [], []

    if os.path.exists(origTrackFile):
        tracks, falarms = TrackFileUtils.ReadTracks(origTrackFile)

    volume = dict(frameCnt=0,
                  corner_filestem=sceneParams['corner_file'],
                  volume_data=[])
    if os.path.exists(volumeFile):
        # dictionary with "volume_data", "frameCnt", "corner_filestem"
        #    and "volume_data" contains a list of dictionaries with
        #    "volTime", "frameNum", "stormCells" where "stormCells" is
        #    a numpy array of dtype corner_dtype
        volume = TrackFileUtils.ReadCorners(volumeFile, volumeLoc)
        sceneParams['corner_file'] = volume['corner_filestem']

    # TODO: Temporary!
    # I would rather not do pickling, but I am pressed for time.
    # Plus, if I intend to make it a part of the ZigZag system,
    # then the name should be stored in the parameters file.
    polygonfile = os.path.join(dirName, "polygons.foo")
    polygons = {}

    if os.path.exists(polygonfile):
        polygons = load(open(polygonfile, 'rb'))

    do_save, state = AnalyzeRadar(volume, tracks, falarms, polygons,
                                  args.input_files)

    if do_save:
        # Create the directory if it doesn't exist already
        if not os.path.exists(dirName):
            makedirs(dirName)

        tracks, falarms, volume, polygons = state.save_features()
        volume['corner_filestem'] = sceneParams['corner_file']

        # Final save
        SaveState(paramFile, sceneParams, volumeFile, volume, origTrackFile,
                  filtTrackFile, tracks, falarms, polygonfile, polygons)
Exemplo n.º 8
0
        simParams.update(ParamUtils.simDefaults)
        simParams.update(ParamUtils.trackerDefaults)

        (xLims, yLims, tLims,
         frameLims) = TrackUtils.DomainFromVolumes(volume_data)

        simParams['xLims'] = xLims
        simParams['yLims'] = yLims
        simParams['tLims'] = tLims
        simParams['frameCnt'] = len(volume_data)

        # These parameters are irrelevant.
        simParams.pop('seed')
        simParams.pop('totalTracks')
        simParams.pop('endTrackProb')
        simParams.pop('simConfFile')
        simParams.pop('analysis_stem')

        simParams['simName'] = args.runName
        TrackFileUtils.SaveCorners(os.path.join(runLoc,
                                                simParams['inputDataFile']),
                                   simParams['corner_file'],
                                   volume_data,
                                   path=runLoc)
        ParamUtils.SaveConfigFile(os.path.join(runLoc, 'simParams.conf'),
                                  simParams)

        if args.savePolys :
            dump(polygons, open(os.path.join(runLoc, 'polygons.foo'), 'wb'))