Exemplo n.º 1
0
def _analyze_trackings(simName, multiSim, skillNames, trackRuns, multiDir,
                       tag_filters):
    try:
        dirName = os.path.join(multiDir, simName)
        paramFile = os.path.join(dirName, "simParams.conf")
        print("Sim:", simName)
        simParams = ParamUtils.ReadSimulationParams(paramFile)
        tagFile = os.path.join(dirName, simParams['simTagFile'])

        if os.path.exists(tagFile):
            simTags = ParamUtils.ReadConfigFile(tagFile)
        else:
            simTags = None

        analysis = AnalyzeTrackings(simName,
                                    simParams,
                                    skillNames,
                                    trackRuns=trackRuns,
                                    path=multiDir,
                                    tag_filters=tag_filters)
        analysis = analysis.insertaxis(axis=1, label=simName)
    except Exception as err:
        print(err)
        raise err

    # (Skills x Sims x TrackRuns)
    return analysis
Exemplo n.º 2
0
def AnalyzeTrackings(simName,
                     simParams,
                     skillNames,
                     trackRuns,
                     path='.',
                     tag_filters=None):
    dirName = os.path.join(path, simName)
    trackFile = os.path.join(dirName, simParams['noisyTrackFile'])

    tagFile = os.path.join(dirName, simParams['simTagFile'])
    simTags = ParamUtils.ReadSimTagFile(tagFile)
    keeperIDs = ParamUtils.process_tag_filters(simTags, tag_filters)

    (true_tracks, true_falarms) = FilterMHTTracks(*ReadTracks(trackFile))
    lastFrame = (max(trk['frameNums'][-1]
                     for trk in (true_tracks + true_falarms))
                 if len(true_tracks) + len(true_falarms) > 0 else 0)
    true_AssocSegs, trackIndices = CreateSegments(true_tracks,
                                                  retindices=True,
                                                  lastFrame=lastFrame)
    # TODO: need to filter trackIndices as well!
    true_AssocSegs = FilterSegments(keeperIDs, true_AssocSegs)

    true_FAlarmSegs, falarmIndices = CreateSegments(true_falarms,
                                                    retindices=True,
                                                    lastFrame=lastFrame)
    true_FAlarmSegs = FilterSegments(keeperIDs, true_FAlarmSegs)

    # Initializing the analysis data, which will hold a table of analysis
    # results for this simulation
    analysis = np.empty((len(skillNames), len(trackRuns)))
    labels = [skillNames, trackRuns]

    for trackerIndex, tracker in enumerate(trackRuns):
        obvFilename = os.path.join(dirName,
                                   simParams['result_file'] + "_" + tracker)
        (obvTracks, obvFAlarms) = FilterMHTTracks(*ReadTracks(obvFilename))
        trk_segs = CreateSegments(obvTracks + obvFAlarms, lastFrame=lastFrame)
        trk_segs = FilterSegments(keeperIDs, trk_segs)
        truthTable = MakeContingency(true_AssocSegs + true_FAlarmSegs,
                                     trk_segs)

        #print("Margin Sums: %d" % (len(truthTable['assocs_Correct']) +
        #                           len(truthTable['assocs_Wrong']) +
        #                           len(truthTable['falarms_Wrong']) +
        #                           len(truthTable['falarms_Correct'])))

        for skillIndex, skill in enumerate(skillNames):
            analysis[skillIndex, trackerIndex] = Analyzers.skillcalcs[skill](
                tracks=obvTracks,
                falarms=obvFAlarms,
                truthTable=truthTable,
                true_tracks=true_tracks,
                true_falarms=true_falarms,
                track_indices=trackIndices,
                falarm_indices=falarmIndices)
    # (Skills x TrackRuns)
    return larry(analysis, labels)
Exemplo n.º 3
0
def _prepare_and_down(simName, skipCnt, multiSim, multiDir, newDir):
    try:
        dirName = os.path.join(multiDir, simName)
        simParams = ParamUtils.ReadSimulationParams(
            os.path.join(dirName, 'simParams.conf'))
        volData = ReadCorners(os.path.join(dirName,
                                           simParams['inputDataFile']),
                              path=dirName)['volume_data']
        origTrackData = FilterMHTTracks(
            *ReadTracks(os.path.join(dirName, simParams['simTrackFile'])))
        noisyTrackData = FilterMHTTracks(
            *ReadTracks(os.path.join(dirName, simParams['noisyTrackFile'])))

        DownsampleTracks(skipCnt,
                         simName,
                         simName,
                         simParams,
                         origTrackData,
                         noisyTrackData,
                         volData,
                         path=newDir)

        print("Sim:", simName)
    except Exception as err:
        print(err)
        raise err
Exemplo n.º 4
0
def MultiSimulation(multiParams, simConfs, globalSimParams, path='.') :

    # Seed the PRNG
    random.seed(multiParams['globalSeed'])

    multiDir = os.path.join(path, multiParams['simName'])

    # Create the multi-sim directory
    if (not os.path.exists(multiDir)) :
        os.makedirs(multiDir)

    ParamUtils.Save_MultiSim_Params(os.path.join(multiDir, "MultiSim.ini"),
                                    multiParams)

    # Get the seeds that will be used for each sub-simulation
    theSimSeeds = random.random_integers(9999999, size=multiParams['simCnt'])

    p = Pool()
    
    for index, seed in enumerate(theSimSeeds) :
        p.apply_async(_produce_sim, (index, seed, simConfs,
                                     globalSimParams.copy(),
                                     multiDir))
    p.close()
    p.join()
Exemplo n.º 5
0
def main(args):
    from ZigZag.ListRuns import ExpandTrackRuns

    dirName = os.path.join(args.directory, args.simName)
    simFile = os.path.join(dirName, "simParams.conf")
    simParams = ParamUtils.ReadSimulationParams(simFile)

    trackConfs = ParamUtils.LoadTrackerParams(args.trackconfs)
    trackRuns = ExpandTrackRuns(trackConfs.keys(), args.trackRuns)
    trackrunConfs = dict([(runName, trackConfs[runName])
                          for runName in trackRuns])

    SingleTracking(simFile,
                   args.simName,
                   simParams,
                   trackrunConfs,
                   path=args.directory)
Exemplo n.º 6
0
def main(args):

    simParams = ParamUtils.ParamsFromOptions(args)

    simConfFiles = args.simConfFiles if args.simConfFiles is not None else \
                                ["InitModels.conf", "MotionModels.conf",
                                 "GenModels.conf", "NoiseModels.conf",
                                 "SimModels.conf"]

    simConfs = ParamUtils.LoadSimulatorConf(simConfFiles)

    print "Sim Name:", args.simName
    print "The Seed:", simParams['seed']

    theSimulation = SingleSimulation(simConfs, **simParams)

    SaveSimulation(theSimulation, simParams, simConfs, path=args.directory)
Exemplo n.º 7
0
def main(args) :
    if args.simCnt <= 0 :
        parser.error("ERROR: Invalid N value: %d" % (args.simCnt))

    simParams = ParamUtils.ParamsFromOptions(args, args.multiSim)

    simConfFiles = args.simConfFiles if args.simConfFiles is not None else \
                                        ["InitModels.conf", "MotionModels.conf",
                                         "GenModels.conf", "NoiseModels.conf",
                                         "SimModels.conf"]

    simConfs = ParamUtils.LoadSimulatorConf(simConfFiles)

    multiParams = dict(simCnt=args.simCnt,
                       globalSeed=simParams['seed'],
                       simName=args.multiSim)

    MultiSimulation(multiParams, simConfs, simParams, path=args.directory)
Exemplo n.º 8
0
def main(args):
    multiDir = os.path.join(args.directory, args.multiSim)
    paramFile = os.path.join(multiDir, "MultiSim.ini")
    multiParams = ParamUtils.Read_MultiSim_Params(paramFile)

    Multi_DownsampleTracks(multiParams,
                           args.skipCnt,
                           args.multiSim,
                           args.newName,
                           path=args.directory)
Exemplo n.º 9
0
def CommonTrackRuns(simNames, dirName='.'):
    allTrackRuns = []

    for simName in simNames:
        simParams = ParamUtils.ReadSimulationParams(
            os.path.join(dirName, simName, "simParams.conf"))
        allTrackRuns.append(set(simParams['trackers']))

    # Get the intersection of all the sets of trackRuns in each simulation
    return list(set.intersection(*allTrackRuns))
Exemplo n.º 10
0
def main(args):
    from ZigZag.ListRuns import ExpandTrackRuns
    trackConfs = ParamUtils.LoadTrackerParams(args.trackconfs)

    trackRuns = ExpandTrackRuns(trackConfs.keys(), args.trackRuns)

    trackrunConfs = dict([(runName, trackConfs[runName])
                          for runName in trackRuns])

    MultiTrack(args.multiSim, trackrunConfs, path=args.directory)
Exemplo n.º 11
0
def AnalyzeTrackings(simName, simParams, skillNames, trackRuns, path='.',
                     tag_filters=None) :
    dirName = os.path.join(path, simName)
    trackFile = os.path.join(dirName, simParams['noisyTrackFile'])

    tagFile = os.path.join(dirName, simParams['simTagFile'])
    simTags = ParamUtils.ReadSimTagFile(tagFile)
    keeperIDs = ParamUtils.process_tag_filters(simTags, tag_filters)

    (true_tracks, true_falarms) = FilterMHTTracks(*ReadTracks(trackFile))
    lastFrame = (max(trk['frameNums'][-1] for trk in
                    (true_tracks + true_falarms)) if
                 len(true_tracks) + len(true_falarms) > 0 else 0)
    true_AssocSegs, trackIndices = CreateSegments(true_tracks,
                                                  retindices=True,
                                                  lastFrame=lastFrame)
    # TODO: need to filter trackIndices as well!
    true_AssocSegs = FilterSegments(keeperIDs, true_AssocSegs)

    true_FAlarmSegs, falarmIndices = CreateSegments(true_falarms,
                                                    retindices=True,
                                                    lastFrame=lastFrame)
    true_FAlarmSegs = FilterSegments(keeperIDs, true_FAlarmSegs)

    # Initializing the analysis data, which will hold a table of analysis
    # results for this simulation
    analysis = np.empty((len(skillNames),
                         len(trackRuns)))
    labels = [skillNames, trackRuns]
    
    for trackerIndex, tracker in enumerate(trackRuns) :
        obvFilename = os.path.join(dirName, simParams['result_file'] +
                                            "_" + tracker)
        (obvTracks, obvFAlarms) = FilterMHTTracks(*ReadTracks(obvFilename))
        trk_segs = CreateSegments(obvTracks + obvFAlarms, lastFrame=lastFrame)
        trk_segs = FilterSegments(keeperIDs, trk_segs)
        truthTable = MakeContingency(true_AssocSegs + true_FAlarmSegs, trk_segs)

        #print "Margin Sums: %d" % (len(truthTable['assocs_Correct']) +
        #                           len(truthTable['assocs_Wrong']) +
        #                           len(truthTable['falarms_Wrong']) +
        #                           len(truthTable['falarms_Correct']))

        for skillIndex, skill in enumerate(skillNames) :
            analysis[skillIndex,
                     trackerIndex] = Analyzers.skillcalcs[skill](
                                       tracks=obvTracks, falarms=obvFAlarms,
                                       truthTable=truthTable,
                                       true_tracks=true_tracks,
                                       true_falarms=true_falarms,
                                       track_indices=trackIndices,
                                       falarm_indices=falarmIndices)
    # (Skills x TrackRuns)
    return larry(analysis, labels)
Exemplo n.º 12
0
def SaveSimulation(theSimulation,
                   simParams,
                   simConfs,
                   automake=True,
                   autoreplace=True,
                   path='.'):

    # Use '' in os.path.join() to make the directory name explicity
    # have a path separator at the end of the name for testing
    # by os.path.exists().
    simDir = os.path.join(path, simParams['simName'], '')
    # Create the simulation directory.
    if (not os.path.exists(simDir)):
        if automake:
            os.makedirs(simDir)
        else:
            raise ValueError("%s does not exist and automake==False"
                             " in SaveSimulation()" % simDir)
    else:
        if not autoreplace:
            raise ValueError("%s already exists and autoreplace==False"
                             " in SaveSimulation()" % simDir)

    ParamUtils.SaveSimulationParams(simDir + "simParams.conf", simParams)
    SaveTracks(os.path.join(simDir, simParams['simTrackFile']),
               theSimulation['true_tracks'], theSimulation['true_falarms'])
    SaveTracks(os.path.join(simDir, simParams['noisyTrackFile']),
               theSimulation['noisy_tracks'], theSimulation['noisy_falarms'])
    SaveCorners(os.path.join(simDir, simParams['inputDataFile']),
                simParams['corner_file'],
                theSimulation['noisy_volumes'],
                path=simDir)
    ParamUtils.SaveConfigFile(os.path.join(simDir, simParams['simConfFile']),
                              simConfs)

    res = theSimulation['trackTags'].pop('ids', [])
    assert len(res) == 0, "The base tag list shouldn't have anything!"

    ParamUtils.SaveConfigFile(os.path.join(simDir, simParams['simTagFile']),
                              theSimulation['trackTags'])
Exemplo n.º 13
0
def SingleTracking(simFile, simName, simParams, trackConfs, path='.'):
    #simParams['trackers'] = trackConfs.keys()
    simDir = os.path.join(path, simName, '')

    storedConfFile = os.path.join(simDir, simParams['trackerparams'])
    if not os.path.exists(storedConfFile):
        # Initialize an empty config file
        ParamUtils.SaveConfigFile(storedConfFile, {})

    # Now load that one file
    storedTrackConfs = ParamUtils.LoadTrackerParams([storedConfFile])

    for trackRun in trackConfs:
        tracker = trackConfs[trackRun]['algorithm']
        # This is where the tracking is performed!
        # Trackers.trackerList is a dictionary of Tracker objects
        Trackers.trackerList[tracker](trackRun,
                                      simParams.copy(),
                                      trackConfs[trackRun].copy(),
                                      returnResults=False,
                                      path=simDir)

        # We want this simulation to know which trackers they used,
        # so we will update the file after each successful tracking operation.
        # Note that we still want an ordered, unique list, henced the use of
        # set() and .sort()
        simParams['trackers'].append(trackRun)
        tempHold = list(set(simParams['trackers']))
        tempHold.sort()
        simParams['trackers'] = tempHold

        # TODO: We could use some sort of 'with' clause here to restore
        #       the original file if something goes wrong here.
        ParamUtils.SaveSimulationParams(simFile, simParams)

        # Add these tracker configurations to the sim's global
        # tracker configuration file for record-keeping
        storedTrackConfs[trackRun] = trackConfs[trackRun].copy()
        ParamUtils.SaveConfigFile(storedConfFile, storedTrackConfs)
Exemplo n.º 14
0
def main(args) :
    simNames = args.simNames if not args.isMulti else MultiSims2Sims(args.simNames, args.directory)

    trackers = CommonTrackRuns(simNames, args.directory)
    trackRuns = ExpandTrackRuns(trackers, args.trackRuns)

    if not args.listfiles :
        for aRun in trackRuns :
            print(aRun)
    else :
        for simName in simNames :
            simParams = ParamUtils.ReadSimulationParams(os.path.join(args.directory, simName, 'simParams.conf'))
            for aRun in trackRuns :
                print os.path.join(args.directory, simName, simParams['result_file'] + '_' + aRun)
Exemplo n.º 15
0
def _prepare_and_track(simName, trackConfs, multiDir):
    try:
        print "Sim:", simName
        paramFile = os.path.join(multiDir, simName, "simParams.conf")
        simParams = ParamUtils.ReadSimulationParams(paramFile)

        SingleTracking(paramFile,
                       simName,
                       simParams,
                       trackConfs,
                       path=multiDir)
    except Exception as err:
        print err
        raise err
Exemplo n.º 16
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.º 17
0
def RenameRuns(simName, old, new, trackRuns, dirName='.'):
    """
    For *trackRuns* in *simName*, replace the *old* portion with *new*.

    This over-writes existing trackruns and does a bit of house-keeping
    in situations where the old run is incomplete while the existing new
    run has extra files. Also takes care of the simulation param file and
    the stored tracker configuration file, if it exists.
    """
    simDir = os.path.join(dirName, simName)
    simFile = os.path.join(simDir, "simParams.conf")
    storedConfFile = os.path.join(simDir, simParams['trackerparams'])

    simParams = ParamUtils.ReadSimulationParams(simFile)

    if not os.path.exists(storedConfFile):
        # Initialize an empty config file
        ParamUtils.SaveConfigFile(storedConfFile, {})

    # Now load that one file
    trackerConfs = ParamUtils.LoadTrackerParams([storedConfFile])

    for oldRun in trackRuns:
        newRun = oldRun.replace(old, new)

        RenameRun(simName,
                  simParams,
                  trackerConfs,
                  oldRun,
                  newRun,
                  dirName=dirName)

        # TODO: We could use some sort of 'with' clause here to restore
        #       the original file if something goes wrong here.
        ParamUtils.SaveSimulationParams(simFile, simParams)
        ParamUtils.SaveConfigFile(storedConfFile, trackerConfs)
Exemplo n.º 18
0
def main(args) :
    dirName = os.path.join(args.directory, args.simName)
    simParams = ParamUtils.ReadSimulationParams(os.path.join(dirName, 'simParams.conf'))
    volData = ReadCorners(os.path.join(dirName, simParams['inputDataFile']),
                          path=dirName)['volume_data']

    if args.doTracks :
        origTrackData = FilterMHTTracks(*ReadTracks(os.path.join(dirName, simParams['simTrackFile'])))
        noisyTrackData = FilterMHTTracks(*ReadTracks(os.path.join(dirName, simParams['noisyTrackFile'])))

        DownsampleTracks(args.skipCnt, args.simName, args.newName, simParams, volData,
                         origTrackData, noisyTrackData, path=args.directory)
    else :
        DownsampleCorners(args.skipCnt, args.simName, args.newName, simParams,
                          volData, path=args.directory)
Exemplo n.º 19
0
def _save_downsample(simParams,
                     newName,
                     newVols,
                     newFrames,
                     newTimes,
                     path='.'):
    simParams['frameCnt'] = len(newFrames)
    simParams['tLims'] = (min(newTimes), max(newTimes))
    simParams['simName'] = newName
    simParams['trackers'] = []
    if simParams['times'] is not None:
        simParams['times'] = newTimes

    ParamUtils.SaveSimulationParams(os.path.join(path, 'simParams.conf'),
                                    simParams)
    SaveCorners(os.path.join(path, simParams['inputDataFile']),
                simParams['corner_file'],
                newVols,
                path=path)
Exemplo n.º 20
0
def main(args):
    dirName = os.path.join(args.directory, args.simName)
    paramFile = os.path.join(dirName, "simParams.conf")
    simParams = ParamUtils.ReadSimulationParams(paramFile)

    # We only want to process the trackers as specified by the user
    trackRuns = ExpandTrackRuns(simParams['trackers'], args.trackRuns)

    analysis = AnalyzeTrackings(args.simName,
                                simParams,
                                args.skillNames,
                                trackRuns=trackRuns,
                                path=args.directory,
                                tag_filters=args.filters)

    analysis = analysis.insertaxis(axis=1, label=args.simName)
    for skill in args.skillNames:
        DisplaySkillScores(analysis.lix[[skill]], skill)
        print '\n\n'
Exemplo n.º 21
0
def Multi_DownsampleTracks(multiParams, skipCnt, multiSim, newMulti, path='.'):
    simNames = Sims_of_MultiSim(multiSim, path)

    multiDir = os.path.join(path, multiSim)
    newDir = os.path.join(path, newMulti)

    # TODO: Improve this to actually fully resolve these to completely prevent over-writing.
    if multiDir == newDir:
        raise ValueError(
            "The new downsampled directory is the same as the current!")

    p = Pool()

    for simName in simNames:
        p.apply_async(_prepare_and_down,
                      (simName, skipCnt, multiSim, multiDir, newDir))

    p.close()
    p.join()

    multiParams['simName'] = newMulti
    ParamUtils.Save_MultiSim_Params(os.path.join(newDir, "MultiSim.ini"),
                                    multiParams)
Exemplo n.º 22
0
def main(args) :
    import os.path
    import glob				# for globbing
    import matplotlib.pyplot as plt
    from mpl_toolkits.axes_grid1 import AxesGrid

    if args.bw_mode :
        BW_mode()       # from TrackPlot module

    # FIXME: Currently, the code allows for trackFiles to be listed as well
    #        as providing a simulation (which trackfiles are automatically
    #        grabbed). Both situations can not be handled right now, though.
    trackFiles = []
    trackTitles = []

    if args.simName is not None :
        dirName = os.path.join(args.directory, args.simName)
        simParams = ParamUtils.ReadSimulationParams(os.path.join(dirName,
                                                    "simParams.conf"))

        if args.trackRuns is not None :
            simParams['trackers'] = ExpandTrackRuns(simParams['trackers'],
                                                    args.trackRuns)

        trackFiles = [os.path.join(dirName, simParams['result_file'] +
                                            '_' + aTracker)
                      for aTracker in simParams['trackers']]
        if args.trackTitles is None :
            trackTitles = simParams['trackers']
        else :
            trackTitles = args.trackTitles

        if args.truthTrackFile is None :
            args.truthTrackFile = os.path.join(dirName,
                                               simParams['noisyTrackFile'])

        if args.simTagFile is None :
            args.simTagFile = os.path.join(dirName, simParams['simTagFile'])

    trackFiles += args.trackFiles

    if args.trackTitles is None :
        trackTitles += args.trackFiles
    else :
        trackTitles += args.trackTitles

    if len(trackFiles) == 0 : print "WARNING: No trackFiles given or found!"

    if len(trackTitles) != len(trackFiles) :
        raise ValueError("The number of TITLEs do not match the"
                         " number of TRACKFILEs.")

    if args.statName is not None and args.statLonLat is None :
        statData = ByName(args.statName)[0]
        args.statLonLat = (statData['LON'], statData['LAT'])

    if args.layout is None :
        args.layout = (1, len(trackFiles))

    if args.figsize is None :
        args.figsize = plt.figaspect(float(args.layout[0]) / args.layout[1])

    trackerData = [FilterMHTTracks(*ReadTracks(trackFile)) for
                   trackFile in trackFiles]

    keeperIDs = None

    if args.simTagFile is not None :
        simTags = ParamUtils.ReadSimTagFile(args.simTagFile)
        keeperIDs = ParamUtils.process_tag_filters(simTags, args.filters)

    if args.statLonLat is not None :
        for aTracker in trackerData :
            CoordinateTransform(aTracker[0] + aTracker[1],
                                args.statLonLat[0],
                                args.statLonLat[1])


    theFig = plt.figure(figsize=args.figsize)
    grid = AxesGrid(theFig, 111, nrows_ncols=args.layout, aspect=False,
                            share_all=True, axes_pad=0.35)


    if args.truthTrackFile is not None :
        (true_tracks,
         true_falarms) = FilterMHTTracks(*ReadTracks(args.truthTrackFile))

        if args.statLonLat is not None :
            CoordinateTransform(true_tracks + true_falarms,
                                args.statLonLat[0],
                                args.statLonLat[1])

        true_AssocSegs = CreateSegments(true_tracks)
        true_FAlarmSegs = CreateSegments(true_falarms)

        if keeperIDs is not None :
            true_AssocSegs = FilterSegments(keeperIDs, true_AssocSegs)
            true_FAlarmSegs = FilterSegments(keeperIDs, true_FAlarmSegs)


        (xLims, yLims, frameLims) = DomainFromTracks(true_tracks + true_falarms)
    else :
        true_AssocSegs = None
        true_FAlarmSegs = None

        stackedTracks = []
        for aTracker in trackerData :
            stackedTracks += aTracker[0] + aTracker[1]
        (xLims, yLims, frameLims) = DomainFromTracks(stackedTracks)

    endFrame = args.endFrame
    tail = args.tail

    if endFrame is None :
        endFrame = frameLims[1]

    if tail is None :
        tail = endFrame - frameLims[0]

    startFrame = endFrame - tail

    showMap = (args.statLonLat is not None and args.displayMap)

    if args.radarFile is not None and args.statLonLat is not None :
        if len(args.radarFile) > 1 and args.endFrame is not None :
            args.radarFile = args.radarFile[args.endFrame]
        else :
            args.radarFile = args.radarFile[-1]

        raddata = LoadRastRadar(args.radarFile)
    else :
        raddata = None

    if showMap :
        bmap = Basemap(projection='cyl', resolution='i',
                       suppress_ticks=False,
                       llcrnrlat=yLims[0], llcrnrlon=xLims[0],
                       urcrnrlat=yLims[1], urcrnrlon=xLims[1])


    for index, (tracks, falarms) in enumerate(trackerData) :
        curAxis = grid[index]

        if raddata is not None :
            MakeReflectPPI(raddata['vals'][0], raddata['lats'], raddata['lons'],
                           meth='pcmesh', ax=curAxis, colorbar=False,
                           axis_labels=False, zorder=0, alpha=0.6)

        if showMap :
            PlotMapLayers(bmap, mapLayers, curAxis)

        if true_AssocSegs is not None and true_FAlarmSegs is not None :
            trackAssocSegs = CreateSegments(tracks)
            trackFAlarmSegs = CreateSegments(falarms)

            if keeperIDs is not None :
                trackAssocSegs = FilterSegments(keeperIDs, trackAssocSegs)
                trackFAlarmSegs = FilterSegments(keeperIDs, trackFAlarmSegs)

            truthtable = CompareSegments(true_AssocSegs, true_FAlarmSegs,
                                         trackAssocSegs, trackFAlarmSegs)
            PlotSegments(truthtable, (startFrame, endFrame), axis=curAxis,
                         fade=args.fade)
        else :
            if keeperIDs is not None :
                filtFunc = lambda trk: FilterTrack(trk, cornerIDs=keeperIDs)
                tracks = map(filtFunc, tracks)
                falarms = map(filtFunc, falarms)
                CleanupTracks(tracks, falarms)

            PlotPlainTracks(tracks, falarms,
                            startFrame, endFrame, axis=curAxis,
                            fade=args.fade)

        #curAxis.set_xlim(xLims)
        #curAxis.set_ylim(yLims)
        #curAxis.set_aspect("equal", 'datalim')
        #curAxis.set_aspect("equal")
        curAxis.set_title(trackTitles[index])
        if not showMap :
            curAxis.set_xlabel("X")
            curAxis.set_ylabel("Y")
        else :
            curAxis.set_xlabel("Longitude")
            curAxis.set_ylabel("Latitude")

    if args.xlims is not None and np.prod(grid.get_geometry()) > 0 :
        grid[0].set_xlim(args.xlims)

    if args.ylims is not None and np.prod(grid.get_geometry()) > 0 :
        grid[0].set_ylim(args.ylims)

    if args.saveImgFile is not None :
        theFig.savefig(args.saveImgFile, bbox_inches='tight')

    if args.doShow :
        plt.show()
Exemplo n.º 23
0
def main(args):
    import os.path
    import matplotlib.pyplot as plt
    from mpl_toolkits.axes_grid1 import AxesGrid

    if args.bw_mode:
        BW_mode()  # from TrackPlot module

    # FIXME: Currently, the code allows for trackFiles to be listed as well
    #        as providing a simulation (which trackfiles are automatically
    #        grabbed). Both situations can not be handled right now, though.
    trackFiles = []
    trackTitles = []

    if args.simName is not None:
        dirName = os.path.join(args.directory, args.simName)
        simParams = ParamUtils.ReadSimulationParams(
            os.path.join(dirName, "simParams.conf"))

        if args.trackRuns is not None:
            simParams['trackers'] = ExpandTrackRuns(simParams['trackers'],
                                                    args.trackRuns)

        trackFiles = [
            os.path.join(dirName, simParams['result_file'] + '_' + aTracker)
            for aTracker in simParams['trackers']
        ]
        if args.trackTitles is None:
            trackTitles = simParams['trackers']
        else:
            trackTitles = args.trackTitles

        if args.truthTrackFile is None:
            args.truthTrackFile = os.path.join(dirName,
                                               simParams['noisyTrackFile'])

        if args.simTagFile is None:
            args.simTagFile = os.path.join(dirName, simParams['simTagFile'])

    trackFiles += args.trackFiles

    if args.trackTitles is None:
        trackTitles += args.trackFiles
    else:
        trackTitles += args.trackTitles

    if len(trackFiles) == 0: print "WARNING: No trackFiles given or found!"

    if len(trackTitles) != len(trackFiles):
        raise ValueError("The number of TITLEs do not match the"
                         " number of TRACKFILEs.")

    if args.statName is not None and args.statLonLat is None:
        statData = ByName(args.statName)[0]
        args.statLonLat = (statData['LON'], statData['LAT'])

    if args.layout is None:
        args.layout = (1, len(trackFiles))

    if args.figsize is None:
        args.figsize = plt.figaspect(float(args.layout[0]) / args.layout[1])

    polyfiles = args.polys

    trackerData = [
        FilterMHTTracks(*ReadTracks(trackFile)) for trackFile in trackFiles
    ]
    polyData = [
        _load_verts(f, tracks + falarms)
        for f, (tracks, falarms) in zip(polyfiles, trackerData)
    ]

    keeperIDs = None

    if args.simTagFile is not None:
        simTags = ParamUtils.ReadSimTagFile(args.simTagFile)
        keeperIDs = ParamUtils.process_tag_filters(simTags, args.filters)

    if args.statLonLat is not None:
        for aTracker in trackerData:
            CoordinateTransform(aTracker[0] + aTracker[1], args.statLonLat[0],
                                args.statLonLat[1])

        for polys in polyData:
            CoordinateTrans_lists(polys, args.statLonLat[0],
                                  args.statLonLat[1])

    theFig = plt.figure(figsize=args.figsize)
    grid = AxesGrid(theFig,
                    111,
                    nrows_ncols=args.layout,
                    aspect=False,
                    share_all=True,
                    axes_pad=0.35)

    if args.truthTrackFile is not None:
        (true_tracks,
         true_falarms) = FilterMHTTracks(*ReadTracks(args.truthTrackFile))

        if args.statLonLat is not None:
            CoordinateTransform(true_tracks + true_falarms, args.statLonLat[0],
                                args.statLonLat[1])

        true_AssocSegs = CreateSegments(true_tracks)
        true_FAlarmSegs = CreateSegments(true_falarms)

        if keeperIDs is not None:
            true_AssocSegs = FilterSegments(keeperIDs, true_AssocSegs)
            true_FAlarmSegs = FilterSegments(keeperIDs, true_FAlarmSegs)

        (xLims, yLims,
         frameLims) = DomainFromTracks(true_tracks + true_falarms)
    else:
        true_AssocSegs = None
        true_FAlarmSegs = None

        stackedTracks = []
        for aTracker in trackerData:
            stackedTracks += aTracker[0] + aTracker[1]
        (xLims, yLims, frameLims) = DomainFromTracks(stackedTracks)

    endFrame = args.endFrame
    tail = args.tail

    if endFrame is None:
        endFrame = frameLims[1]

    if tail is None:
        tail = endFrame - frameLims[0]

    startFrame = endFrame - tail

    showMap = (args.statLonLat is not None and args.displayMap)

    if args.radarFile is not None and args.statLonLat is not None:
        if len(args.radarFile) > 1 and args.endFrame is not None:
            args.radarFile = args.radarFile[args.endFrame]
        else:
            args.radarFile = args.radarFile[-1]

        raddata = LoadRastRadar(args.radarFile)
    else:
        raddata = None

    if showMap:
        bmap = Basemap(projection='cyl',
                       resolution='i',
                       suppress_ticks=False,
                       llcrnrlat=yLims[0],
                       llcrnrlon=xLims[0],
                       urcrnrlat=yLims[1],
                       urcrnrlon=xLims[1])

    for index, (tracks, falarms) in enumerate(trackerData):
        curAxis = grid[index]

        if raddata is not None:
            MakeReflectPPI(raddata['vals'][0],
                           raddata['lats'],
                           raddata['lons'],
                           meth='pcmesh',
                           ax=curAxis,
                           colorbar=False,
                           axis_labels=False,
                           zorder=0,
                           alpha=0.6)

        if showMap:
            PlotMapLayers(bmap, mapLayers, curAxis)

        if true_AssocSegs is not None and true_FAlarmSegs is not None:
            trackAssocSegs = CreateSegments(tracks)
            trackFAlarmSegs = CreateSegments(falarms)

            if keeperIDs is not None:
                trackAssocSegs = FilterSegments(keeperIDs, trackAssocSegs)
                trackFAlarmSegs = FilterSegments(keeperIDs, trackFAlarmSegs)

            truthtable = CompareSegments(true_AssocSegs, true_FAlarmSegs,
                                         trackAssocSegs, trackFAlarmSegs)
            PlotSegments(truthtable, (startFrame, endFrame),
                         axis=curAxis,
                         fade=args.fade)
        else:
            if keeperIDs is not None:
                filtFunc = lambda trk: FilterTrack(trk, cornerIDs=keeperIDs)
                tracks = map(filtFunc, tracks)
                falarms = map(filtFunc, falarms)
                CleanupTracks(tracks, falarms)

            PlotPlainTracks(tracks,
                            falarms,
                            startFrame,
                            endFrame,
                            axis=curAxis,
                            fade=args.fade)

        #curAxis.set_xlim(xLims)
        #curAxis.set_ylim(yLims)
        #curAxis.set_aspect("equal", 'datalim')
        #curAxis.set_aspect("equal")
        curAxis.set_title(trackTitles[index])
        if not showMap:
            curAxis.set_xlabel("X")
            curAxis.set_ylabel("Y")
        else:
            curAxis.set_xlabel("Longitude")
            curAxis.set_ylabel("Latitude")

    for ax, verts in zip(grid, polyData):
        _to_polygons(verts[endFrame:endFrame + 1], ax)

    if args.xlims is not None and np.prod(grid.get_geometry()) > 0:
        grid[0].set_xlim(args.xlims)

    if args.ylims is not None and np.prod(grid.get_geometry()) > 0:
        grid[0].set_ylim(args.ylims)

    if args.saveImgFile is not None:
        theFig.savefig(args.saveImgFile, bbox_inches='tight')

    if args.doShow:
        plt.show()
Exemplo n.º 24
0
def Sims_of_MultiSim(multiSim, dirName='.'):
    """ Build list of actual single-sim names for a multi-sim.
        Note that this does not include the multi-sim's name in the list. """
    paramFile = os.path.join(dirName, multiSim, "MultiSim.ini")
    multiSimParams = ParamUtils.Read_MultiSim_Params(paramFile)
    return ["%.3d" % index for index in xrange(int(multiSimParams['simCnt']))]
Exemplo n.º 25
0
def main(args) :
    import os.path			# for os.path.join()
    import glob				# for globbing

    if args.bw_mode :
        BW_mode()       # from TrackPlot module

    # FIXME: Currently, the code allows for trackFiles to be listed as well
    #        as providing a simulation (which trackfiles are automatically
    #        grabbed). Both situations can not be handled right now, though.
    trackFiles = []
    trackTitles = []
    polyfiles = args.polys

    if args.statName is not None and args.statLonLat is None :
        statData = ByName(args.statName)[0]
        args.statLonLat = (statData['LON'], statData['LAT'])

    if args.simName is not None :
        dirName = os.path.join(args.directory, args.simName)
        simParams = ParamUtils.ReadSimulationParams(os.path.join(dirName,
                                                    "simParams.conf"))

        if args.trackRuns is not None :
            simParams['trackers'] = ExpandTrackRuns(simParams['trackers'],
                                                    args.trackRuns)

        trackFiles = [os.path.join(dirName, simParams['result_file'] +
                                            '_' + aTracker)
                      for aTracker in simParams['trackers']]
        trackTitles = simParams['trackers']

        if args.truthTrackFile is None :
            args.truthTrackFile = os.path.join(dirName,
                                               simParams['noisyTrackFile'])

        if args.simTagFile is None :
            args.simTagFile = os.path.join(dirName,
                                           simParams['simTagFile'])

    trackFiles += args.trackFiles
    trackTitles += args.trackFiles

    if args.trackTitles is not None :
        trackTitles = args.trackTitles


    if len(trackFiles) == 0 : print "WARNING: No trackFiles given or found!"

    if args.layout is None :
        args.layout = (1, len(trackFiles))

    if args.figsize is None :
        args.figsize = plt.figaspect(float(args.layout[0]) / args.layout[1])

    if len(trackFiles) < len(polyfiles):
        raise ValueError("Can not have more polygon files than trackfiles!")

    trackerData = [FilterMHTTracks(*ReadTracks(trackFile)) for
                   trackFile in trackFiles]
    polyData = [_load_verts(f, tracks + falarms) for f, (tracks, falarms) in
                zip(polyfiles, trackerData)]

    keeperIDs = None

    if args.simTagFile is not None :
        simTags = ParamUtils.ReadSimTagFile(args.simTagFile)
        keeperIDs = ParamUtils.process_tag_filters(simTags, args.filters)

    if args.statLonLat is not None :
        for aTracker in trackerData :
            CoordinateTransform(aTracker[0] + aTracker[1],
                                args.statLonLat[0],
                                args.statLonLat[1])
        for polys in polyData:
            CoordinateTrans_lists(polys,
                                  args.statLonLat[0], args.statLonLat[1])

    theFig = plt.figure(figsize=args.figsize)
    grid = AxesGrid(theFig, 111, nrows_ncols=args.layout,# aspect=False,
                            share_all=True, axes_pad=0.45)

    if args.truthTrackFile is not None :
        (true_tracks,
         true_falarms) = FilterMHTTracks(*ReadTracks(args.truthTrackFile))

        if args.statLonLat is not None :
            CoordinateTransform(true_tracks + true_falarms,
                                args.statLonLat[0],
                                args.statLonLat[1])

        true_AssocSegs = CreateSegments(true_tracks)
        true_FAlarmSegs = CreateSegments(true_falarms)

        if keeperIDs is not None :
            true_AssocSegs = FilterSegments(keeperIDs, true_AssocSegs)
            true_FAlarmSegs = FilterSegments(keeperIDs, true_FAlarmSegs)


        (xLims, yLims, frameLims) = DomainFromTracks(true_tracks + true_falarms)
    else :
        true_AssocSegs = None
        true_FAlarmSegs = None

        stackedTracks = []
        for aTracker in trackerData :
            stackedTracks += aTracker[0] + aTracker[1]
        (xLims, yLims, frameLims) = DomainFromTracks(stackedTracks)

    startFrame = args.startFrame
    endFrame = args.endFrame
    tail = args.tail

    if startFrame is None :
        startFrame = 0

    if endFrame is None :
        endFrame = frameLims[1]

    if tail is None :
        tail = endFrame - startFrame

    # A common timer for all animations for syncing purposes.
    theTimer = None

    if args.radarFile is not None and args.statLonLat is not None :
        if endFrame >= len(args.radarFile) :
            # Not enough radar files, so truncate the tracks.
            endFrame = len(args.radarFile) - 1
        files = args.radarFile[startFrame:(endFrame + 1)]
        radAnim = RadarAnim(theFig, files)
        theTimer = radAnim.event_source
        for ax in grid :
            radAnim.add_axes(ax, alpha=0.6, zorder=0)
    else :
        radAnim = None

    showMap = (args.statLonLat is not None and args.displayMap)

    if showMap :
        bmap = Basemap(projection='cyl', resolution='i',
                       suppress_ticks=False,
                       llcrnrlat=yLims[0], llcrnrlon=xLims[0],
                       urcrnrlat=yLims[1], urcrnrlon=xLims[1])


    animator = SegAnimator(theFig, startFrame, endFrame, tail,
                           event_source=theTimer, fade=args.fade)

    for index, (tracks, falarms) in enumerate(trackerData):
        curAxis = grid[index]

        if showMap :
            PlotMapLayers(bmap, mapLayers, curAxis, zorder=0.1)

        if true_AssocSegs is not None and true_FAlarmSegs is not None :
            trackAssocSegs = CreateSegments(tracks)
            trackFAlarmSegs = CreateSegments(falarms)

            if keeperIDs is not None :
                trackAssocSegs = FilterSegments(keeperIDs, trackAssocSegs)
                trackFAlarmSegs = FilterSegments(keeperIDs, trackFAlarmSegs)

            truthtable = CompareSegments(true_AssocSegs, true_FAlarmSegs,
                                         trackAssocSegs, trackFAlarmSegs)
            l, d = Animate_Segments(truthtable, (startFrame, endFrame),
                                    axis=curAxis)
        else :
            if keeperIDs is not None :
                filtFunc = lambda trk : FilterTrack(trk, cornerIDs=keeperIDs)
                tracks = map(filtFunc, tracks)
                falarms = map(filtFunc, falarms)
                CleanupTracks(tracks, falarms)

            l, d = Animate_PlainTracks(tracks, falarms,
                                       (startFrame, endFrame), axis=curAxis)

        animator._lines.extend(l)
        animator._lineData.extend(d)

        #curAxis.set_aspect("equal", 'datalim')
        #curAxis.set_aspect("equal")
        curAxis.set_title(trackTitles[index])
        if not showMap :
            curAxis.set_xlabel("X")
            curAxis.set_ylabel("Y")
        else :
            curAxis.set_xlabel("Longitude (degrees)")
            curAxis.set_ylabel("Latitude (degrees)")

    polyAnims = []
    for ax, verts in zip(grid, polyData):
        from matplotlib.animation import ArtistAnimation
        polyAnim = ArtistAnimation(theFig,
                        _to_polygons(polys[startFrame:endFrame + 1], ax),
                        event_source=theTimer)
        polyAnims.append(polyAnim)

    if args.xlims is not None and np.prod(grid.get_geometry()) > 0 :
        grid[0].set_xlim(args.xlims)

    if args.ylims is not None and np.prod(grid.get_geometry()) > 0 :
        grid[0].set_ylim(args.ylims)

    if args.saveImgFile is not None :
        if radAnim is not None :
            radAnim = [radAnim]
        else:
            radAnim = []
        animator.save(args.saveImgFile, extra_anim=radAnim + polyAnims)

    if args.doShow :
        plt.show()
Exemplo n.º 26
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.º 27
0

if __name__ == '__main__' :
    import argparse
    from ZigZag.zigargs import AddCommandParser


    parser = argparse.ArgumentParser(description="Run and track several storm-track simulations")
    AddCommandParser('MultiSim', parser)
    """
    parser.add_argument("multiSim", type=str,
                      help="Generate Tracks for MULTISIM",
                      metavar="MULTISIM", default="NewMulti")
    parser.add_argument("simCnt", type=int,
              help="Repeat Simulation N times.",
              metavar="N", default=1)
    parser.add_argument("-d", "--dir", dest="directory",
                        help="Base directory to place MULTISIM",
                        metavar="DIRNAME", default='.')
    parser.add_argument("-c", "--conf", dest="simConfFiles",
                        nargs='+',
                        help="Configuration files for the simulation.",
                        metavar="CONFFILE", default=None)
    """
    ParamUtils.SetupParser(parser)

    args = parser.parse_args()

    main(args)

Exemplo n.º 28
0
def main(args):
    import os.path  # for os.path.join()
    import glob  # for globbing

    if args.bw_mode:
        BW_mode()  # from TrackPlot module

    # FIXME: Currently, the code allows for trackFiles to be listed as well
    #        as providing a simulation (which trackfiles are automatically
    #        grabbed). Both situations can not be handled right now, though.
    trackFiles = []
    trackTitles = []
    polyfiles = args.polys

    if args.statName is not None and args.statLonLat is None:
        statData = ByName(args.statName)[0]
        args.statLonLat = (statData['LON'], statData['LAT'])

    if args.simName is not None:
        dirName = os.path.join(args.directory, args.simName)
        simParams = ParamUtils.ReadSimulationParams(
            os.path.join(dirName, "simParams.conf"))

        if args.trackRuns is not None:
            simParams['trackers'] = ExpandTrackRuns(simParams['trackers'],
                                                    args.trackRuns)

        trackFiles = [
            os.path.join(dirName, simParams['result_file'] + '_' + aTracker)
            for aTracker in simParams['trackers']
        ]
        trackTitles = simParams['trackers']

        if args.truthTrackFile is None:
            args.truthTrackFile = os.path.join(dirName,
                                               simParams['noisyTrackFile'])

        if args.simTagFile is None:
            args.simTagFile = os.path.join(dirName, simParams['simTagFile'])

    trackFiles += args.trackFiles
    trackTitles += args.trackFiles

    if args.trackTitles is not None:
        trackTitles = args.trackTitles

    if len(trackFiles) == 0: print "WARNING: No trackFiles given or found!"

    if args.layout is None:
        args.layout = (1, len(trackFiles))

    if args.figsize is None:
        args.figsize = plt.figaspect(float(args.layout[0]) / args.layout[1])

    if len(trackFiles) < len(polyfiles):
        raise ValueError("Can not have more polygon files than trackfiles!")

    trackerData = [
        FilterMHTTracks(*ReadTracks(trackFile)) for trackFile in trackFiles
    ]
    polyData = [
        _load_verts(f, tracks + falarms)
        for f, (tracks, falarms) in zip(polyfiles, trackerData)
    ]

    keeperIDs = None

    if args.simTagFile is not None:
        simTags = ParamUtils.ReadSimTagFile(args.simTagFile)
        keeperIDs = ParamUtils.process_tag_filters(simTags, args.filters)

    if args.statLonLat is not None:
        for aTracker in trackerData:
            CoordinateTransform(aTracker[0] + aTracker[1], args.statLonLat[0],
                                args.statLonLat[1])
        for polys in polyData:
            CoordinateTrans_lists(polys, args.statLonLat[0],
                                  args.statLonLat[1])

    theFig = plt.figure(figsize=args.figsize)
    grid = AxesGrid(
        theFig,
        111,
        nrows_ncols=args.layout,  # aspect=False,
        share_all=True,
        axes_pad=0.45)

    if args.truthTrackFile is not None:
        (true_tracks,
         true_falarms) = FilterMHTTracks(*ReadTracks(args.truthTrackFile))

        if args.statLonLat is not None:
            CoordinateTransform(true_tracks + true_falarms, args.statLonLat[0],
                                args.statLonLat[1])

        true_AssocSegs = CreateSegments(true_tracks)
        true_FAlarmSegs = CreateSegments(true_falarms)

        if keeperIDs is not None:
            true_AssocSegs = FilterSegments(keeperIDs, true_AssocSegs)
            true_FAlarmSegs = FilterSegments(keeperIDs, true_FAlarmSegs)

        (xLims, yLims,
         frameLims) = DomainFromTracks(true_tracks + true_falarms)
    else:
        true_AssocSegs = None
        true_FAlarmSegs = None

        stackedTracks = []
        for aTracker in trackerData:
            stackedTracks += aTracker[0] + aTracker[1]
        (xLims, yLims, frameLims) = DomainFromTracks(stackedTracks)

    startFrame = args.startFrame
    endFrame = args.endFrame
    tail = args.tail

    if startFrame is None:
        startFrame = 0

    if endFrame is None:
        endFrame = frameLims[1]

    if tail is None:
        tail = endFrame - startFrame

    # A common timer for all animations for syncing purposes.
    theTimer = None

    if args.radarFile is not None and args.statLonLat is not None:
        if endFrame >= len(args.radarFile):
            # Not enough radar files, so truncate the tracks.
            endFrame = len(args.radarFile) - 1
        files = args.radarFile[startFrame:(endFrame + 1)]
        radAnim = RadarAnim(theFig, files)
        theTimer = radAnim.event_source
        for ax in grid:
            radAnim.add_axes(ax, alpha=0.6, zorder=0)
    else:
        radAnim = None

    showMap = (args.statLonLat is not None and args.displayMap)

    if showMap:
        bmap = Basemap(projection='cyl',
                       resolution='i',
                       suppress_ticks=False,
                       llcrnrlat=yLims[0],
                       llcrnrlon=xLims[0],
                       urcrnrlat=yLims[1],
                       urcrnrlon=xLims[1])

    animator = SegAnimator(theFig,
                           startFrame,
                           endFrame,
                           tail,
                           event_source=theTimer,
                           fade=args.fade)

    for index, (tracks, falarms) in enumerate(trackerData):
        curAxis = grid[index]

        if showMap:
            PlotMapLayers(bmap, mapLayers, curAxis, zorder=0.1)

        if true_AssocSegs is not None and true_FAlarmSegs is not None:
            trackAssocSegs = CreateSegments(tracks)
            trackFAlarmSegs = CreateSegments(falarms)

            if keeperIDs is not None:
                trackAssocSegs = FilterSegments(keeperIDs, trackAssocSegs)
                trackFAlarmSegs = FilterSegments(keeperIDs, trackFAlarmSegs)

            truthtable = CompareSegments(true_AssocSegs, true_FAlarmSegs,
                                         trackAssocSegs, trackFAlarmSegs)
            l, d = Animate_Segments(truthtable, (startFrame, endFrame),
                                    axis=curAxis)
        else:
            if keeperIDs is not None:
                filtFunc = lambda trk: FilterTrack(trk, cornerIDs=keeperIDs)
                tracks = map(filtFunc, tracks)
                falarms = map(filtFunc, falarms)
                CleanupTracks(tracks, falarms)

            l, d = Animate_PlainTracks(tracks,
                                       falarms, (startFrame, endFrame),
                                       axis=curAxis)

        animator._lines.extend(l)
        animator._lineData.extend(d)

        #curAxis.set_aspect("equal", 'datalim')
        #curAxis.set_aspect("equal")
        curAxis.set_title(trackTitles[index])
        if not showMap:
            curAxis.set_xlabel("X")
            curAxis.set_ylabel("Y")
        else:
            curAxis.set_xlabel("Longitude (degrees)")
            curAxis.set_ylabel("Latitude (degrees)")

    polyAnims = []
    for ax, verts in zip(grid, polyData):
        from matplotlib.animation import ArtistAnimation
        polyAnim = ArtistAnimation(theFig,
                                   _to_polygons(polys[startFrame:endFrame + 1],
                                                ax),
                                   event_source=theTimer)
        polyAnims.append(polyAnim)

    if args.xlims is not None and np.prod(grid.get_geometry()) > 0:
        grid[0].set_xlim(args.xlims)

    if args.ylims is not None and np.prod(grid.get_geometry()) > 0:
        grid[0].set_ylim(args.ylims)

    if args.saveImgFile is not None:
        if radAnim is not None:
            radAnim = [radAnim]
        else:
            radAnim = []
        animator.save(args.saveImgFile, extra_anim=radAnim + polyAnims)

    if args.doShow:
        plt.show()
Exemplo n.º 29
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'))