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
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
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))
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)
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
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)
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)
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'
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)
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()
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)
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()