def main(args): import os.path # for os.path import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import AxesGrid inputDataFiles = [] titles = [] simTagFiles = [] if args.simName is not None: dirName = os.path.join(args.directory, args.simName) simParams = ParamUtils.ReadSimulationParams( os.path.join(dirName, "simParams.conf")) inputDataFiles.append(os.path.join(dirName, simParams['inputDataFile'])) titles.append(args.simName) simTagFiles.append(os.path.join(dirName, simParams['simTagFile'])) # Add on any files specified at the command-line inputDataFiles += args.inputDataFiles titles += args.inputDataFiles if args.simTagFiles is not None: simTagFiles += args.simTagFiles if len(inputDataFiles) == 0: print "WARNING: No inputDataFiles given or found!" if len(titles) != len(inputDataFiles): raise ValueError("The number of TITLEs does not match the" " number of INPUTFILEs.") if len(simTagFiles) < len(inputDataFiles): # Not an error, just simply append None simTagFiles.append([None] * (len(inputDataFiles) - len(simTagFiles))) 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(inputDataFiles)) if args.figsize is None: args.figsize = plt.figaspect(float(args.layout[0]) / args.layout[1]) cornerVolumes = [ ReadCorners(inFileName, os.path.dirname(inFileName))['volume_data'] for inFileName in inputDataFiles ] multiTags = [(ReadSimTagFile(fname) if fname is not None else None) for fname in simTagFiles] for vols, simTags in zip(cornerVolumes, multiTags): keeperIDs = process_tag_filters(simTags, args.filters) if keeperIDs is None: continue for vol in vols: vol['stormCells'] = FilterTrack(vol['stormCells'], cornerIDs=keeperIDs) if args.statLonLat is not None: for vols in cornerVolumes: for vol in vols: CoordinateTransform(vol['stormCells'], args.statLonLat[0], args.statLonLat[1]) theFig = plt.figure(figsize=args.figsize) grid = AxesGrid(theFig, 111, nrows_ncols=args.layout, share_all=True, axes_pad=0.32) # A list to hold the CircleCollection arrays, it will have length # of max(tLims) - min(tLims) + 1 allCorners = None if args.trackFile is not None: (tracks, falarms) = FilterMHTTracks(*ReadTracks(args.trackFile)) if args.statLonLat is not None: CoordinateTransform(tracks + falarms, args.statLonLat[0], args.statLonLat[1]) (xLims, yLims, frameLims) = DomainFromTracks(tracks + falarms) else: volumes = [] for aVol in cornerVolumes: volumes.extend(aVol) (xLims, yLims, tLims, frameLims) = DomainFromVolumes(volumes) showMap = (args.statLonLat is not None and args.displayMap) if showMap: bmap = Basemap(projection='cyl', resolution='l', suppress_ticks=False, llcrnrlat=yLims[0], llcrnrlon=xLims[0], urcrnrlat=yLims[1], urcrnrlon=xLims[1]) startFrame = args.startFrame endFrame = args.endFrame tail = args.tail if startFrame is None: startFrame = frameLims[0] if endFrame is None: endFrame = frameLims[1] if tail is None: tail = 0 # A common event_source for synchronizing all the animations theTimer = None # Make the corners big big = False if args.radarFile is not None and args.statLonLat is not None: if endFrame - frameLims[0] >= len(args.radarFile): # Not enough radar files, so truncate the tracks. endFrame = (len(args.radarFile) + frameLims[0]) - 1 files = args.radarFile[startFrame - frameLims[0]:(endFrame + 1) - frameLims[0]] radAnim = RadarAnim(theFig, files) theTimer = radAnim.event_source for ax in grid: radAnim.add_axes(ax, alpha=0.6, zorder=0) # Radar images make it difficult to see corners, so make 'em big big = True else: radAnim = None theAnim = CornerAnimation(theFig, endFrame - startFrame + 1, tail=tail, interval=250, blit=False, event_source=theTimer, fade=args.fade) for (index, volData) in enumerate(cornerVolumes): curAxis = grid[index] if showMap: PlotMapLayers(bmap, mapLayers, curAxis, zorder=0.1) volFrames = [frameVol['frameNum'] for frameVol in volData] startIdx = volFrames.index(startFrame) endIdx = volFrames.index(endFrame) volTimes = [frameVol['volTime'] for frameVol in volData] startT = volTimes[startIdx] endT = volTimes[endIdx] corners = PlotCorners(volData, (startT, endT), axis=curAxis, big=big) #curAxis.set_aspect("equal", 'datalim') #curAxis.set_aspect("equal") curAxis.set_title(titles[index]) if not showMap: curAxis.set_xlabel("X") curAxis.set_ylabel("Y") else: curAxis.set_xlabel("Longitude") curAxis.set_ylabel("Latitude") theAnim.AddCornerVolume(corners) 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] theAnim.save(args.saveImgFile, extra_anim=radAnim) if args.doShow: plt.show()
def MakeTrackPlots(grid, trackData, titles, showMap, endFrame=None, tail=None, fade=False, multiTags=None, tag_filters=None): """ *grid* axes_grid object *trackData* a list of the lists of tracks *titles* titles for each subplot *showMap* boolean indicating whether to plot a map layer *endFrame* Display tracks as of *frame* number. Default: last *tail* How many frames to include prior to *frame* to display Default: all *fade* Whether or not to 'fade' old tracks """ if multiTags is None: multiTags = [None] * len(trackData) stackedTracks = [] for aTracker in trackData: stackedTracks += aTracker[0] + aTracker[1] # TODO: gotta make this get the time limits! (xLims, yLims, frameLims) = DomainFromTracks(stackedTracks) if endFrame is None: endFrame = frameLims[1] if tail is None: tail = endFrame - frameLims[0] startFrame = endFrame - tail if showMap: bmap = Basemap(projection='cyl', resolution='i', suppress_ticks=False, llcrnrlat=yLims[0], llcrnrlon=xLims[0], urcrnrlat=yLims[1], urcrnrlon=xLims[1]) for ax, (tracks, falarms), title, simTags in zip(grid, trackData, titles, multiTags): if showMap: PlotMapLayers(bmap, mapLayers, ax) ax.set_xlabel("Longitude") ax.set_ylabel("Latitude") else: ax.set_xlabel("X") ax.set_ylabel("Y") if simTags is not None: keeperIDs = process_tag_filters(simTags, tag_filters) 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=ax, fade=fade) ax.set_title(title)
def MakeTrackPlots( grid, trackData, titles, showMap, endFrame=None, tail=None, fade=False, multiTags=None, tag_filters=None ): """ *grid* axes_grid object *trackData* a list of the lists of tracks *titles* titles for each subplot *showMap* boolean indicating whether to plot a map layer *endFrame* Display tracks as of *frame* number. Default: last *tail* How many frames to include prior to *frame* to display Default: all *fade* Whether or not to 'fade' old tracks """ if multiTags is None: multiTags = [None] * len(trackData) stackedTracks = [] for aTracker in trackData: stackedTracks += aTracker[0] + aTracker[1] # TODO: gotta make this get the time limits! (xLims, yLims, frameLims) = DomainFromTracks(stackedTracks) if endFrame is None: endFrame = frameLims[1] if tail is None: tail = endFrame - frameLims[0] startFrame = endFrame - tail if showMap: bmap = Basemap( projection="cyl", resolution="i", suppress_ticks=False, llcrnrlat=yLims[0], llcrnrlon=xLims[0], urcrnrlat=yLims[1], urcrnrlon=xLims[1], ) for ax, (tracks, falarms), title, simTags in zip(grid, trackData, titles, multiTags): if showMap: PlotMapLayers(bmap, mapLayers, ax) ax.set_xlabel("Longitude") ax.set_ylabel("Latitude") else: ax.set_xlabel("X") ax.set_ylabel("Y") if simTags is not None: keeperIDs = process_tag_filters(simTags, tag_filters) 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=ax, fade=fade) ax.set_title(title)
def MakeCornerPlots(fig, grid, cornerVolumes, titles, showMap=False, showRadar=False, startFrame=None, endFrame=None, tail=None, radarFiles=None, fade=False, multiTags=None, tag_filters=None) : if multiTags is None : multiTags = [None] * len(cornerVolumes) volumes = [] for volData in cornerVolumes : volumes.extend(volData) # the info in frameLims is completely useless because we # can't assume that each cornerVolumes has the same frame reference. xLims, yLims, tLims, frameLims = DomainFromVolumes(volumes) if startFrame is None : startFrame = frameLims[0] if endFrame is None : endFrame = frameLims[1] if tail is None : tail = 0 # A common event_source for synchronizing all the animations theTimer = None if showRadar : if endFrame - frameLims[0] >= len(radarFiles) : # Not enough radar files, so truncate the tracks. endFrame = (len(radarFiles) + frameLims[0]) - 1 files = radarFiles[startFrame - frameLims[0]:(endFrame + 1) - frameLims[0]] radAnim = RadarAnim(fig, files) theTimer = radAnim.event_source for ax in grid : radAnim.add_axes(ax, alpha=0.6, zorder=0) else : radAnim = None if showMap : bmap = Basemap(projection='cyl', resolution='l', suppress_ticks=False, llcrnrlat=yLims[0], llcrnrlon=xLims[0], urcrnrlat=yLims[1], urcrnrlon=xLims[1]) theAnim = CornerAnimation(fig, endFrame - startFrame + 1, tail=tail, interval=250, blit=False, event_source=theTimer, fade=fade) for ax, volData, title, simTags in zip(grid, cornerVolumes, titles, multiTags) : if showMap : PlotMapLayers(bmap, mapLayers, ax, zorder=0.1) ax.set_xlabel("Longitude") ax.set_ylabel("Latitude") else : ax.set_xlabel("X") ax.set_ylabel("Y") keeperIDs = process_tag_filters(simTags, tag_filters) if keeperIDs is not None : for frameVol in volData : frameVol['stormCells'] = FilterTrack(frameVol['stormCells'], cornerIDs=keeperIDs) # TODO: Need to figure out a better way to handle this for # volume data that do not have the same number of frames volFrames = [frameVol['frameNum'] for frameVol in volData] startIdx = volFrames.index(startFrame) endIdx = volFrames.index(endFrame) volTimes = [frameVol['volTime'] for frameVol in volData] startT = volTimes[startIdx] endT = volTimes[endIdx] # big=showRadar because radar maps make it difficult to see regular # corners. corners = PlotCorners(volData, (startT, endT), axis=ax, big=showRadar) ax.set_title(title) theAnim.AddCornerVolume(corners) return theAnim, radAnim
def MakeComparePlots(grid, trackData, truthData, titles, showMap, endFrame=None, tail=None, fade=False, multiTags=None, tag_filters=None) : true_AssocSegs = None true_FAlarmSegs = None frameLims = None if multiTags is None : multiTags = [None] * len(trackData) for ax, aTracker, truth, title, simTags in zip(grid, trackData, truthData, titles, multiTags) : this_endFrame = endFrame this_tail = tail # Will return None if either simTags or filters are None keeperIDs = process_tag_filters(simTags, tag_filters) # Either only do this for the first pass through, # or do it for all passes # In other words, if no frameLims is given, then use the frameLimits # for each truthkData dataset. # Or, if there are multiple truthData datasets, then regardless of # whether frameLims was specified, calculate the frame limits each time if frameLims is None or len(truthData) > 1 : true_AssocSegs = CreateSegments(truth[0]) true_FAlarmSegs = CreateSegments(truth[1]) if keeperIDs is not None : true_AssocSegs = FilterSegments(keeperIDs, true_AssocSegs) true_FAlarmSegs = FilterSegments(keeperIDs, true_FAlarmSegs) # TODO: gotta make this get the time limits! xLims, yLims, frameLims = DomainFromTracks(true_AssocSegs, true_FAlarmSegs) if showMap : bmap = Basemap(projection='cyl', resolution='i', suppress_ticks=False, llcrnrlat=yLims[0], llcrnrlon=xLims[0], urcrnrlat=yLims[1], urcrnrlon=xLims[1]) PlotMapLayers(bmap, mapLayers, ax) if this_endFrame is None : this_endFrame = frameLims[1] if this_tail is None : this_tail = this_endFrame - frameLims[0] this_startFrame = this_endFrame - this_tail trackAssocSegs = CreateSegments(aTracker[0]) trackFAlarmSegs = CreateSegments(aTracker[1]) if keeperIDs is not None : trackAssocSegs = FilterSegments(keeperIDs, trackAssocSegs) trackFAlarmSegs = FilterSegments(keeperIDs, trackFAlarmSegs) truthtable = CompareSegments(true_AssocSegs, true_FAlarmSegs, trackAssocSegs, trackFAlarmSegs) PlotSegments(truthtable, (this_startFrame, this_endFrame), axis=ax, fade=fade) ax.set_title(title) if not showMap : ax.set_xlabel("X") ax.set_ylabel("Y") else : ax.set_xlabel("Longitude") ax.set_ylabel("Latitude")
def main(args) : import os.path # for os.path import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import AxesGrid inputDataFiles = [] titles = [] simTagFiles = [] if args.simName is not None : dirName = os.path.join(args.directory, args.simName) simParams = ParamUtils.ReadSimulationParams(os.path.join(dirName, "simParams.conf")) inputDataFiles.append(os.path.join(dirName, simParams['inputDataFile'])) titles.append(args.simName) simTagFiles.append(os.path.join(dirName, simParams['simTagFile'])) # Add on any files specified at the command-line inputDataFiles += args.inputDataFiles titles += args.inputDataFiles if args.simTagFiles is not None : simTagFiles += args.simTagFiles if len(inputDataFiles) == 0 : print "WARNING: No inputDataFiles given or found!" if len(titles) != len(inputDataFiles) : raise ValueError("The number of TITLEs does not match the" " number of INPUTFILEs.") if len(simTagFiles) < len(inputDataFiles) : # Not an error, just simply append None simTagFiles.append([None] * (len(inputDataFiles) - len(simTagFiles))) 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(inputDataFiles)) if args.figsize is None : args.figsize = plt.figaspect(float(args.layout[0]) / args.layout[1]) cornerVolumes = [ReadCorners(inFileName, os.path.dirname(inFileName))['volume_data'] for inFileName in inputDataFiles] multiTags = [(ReadSimTagFile(fname) if fname is not None else None) for fname in simTagFiles] for vols, simTags in zip(cornerVolumes, multiTags) : keeperIDs = process_tag_filters(simTags, args.filters) if keeperIDs is None : continue for vol in vols : vol['stormCells'] = FilterTrack(vol['stormCells'], cornerIDs=keeperIDs) if args.statLonLat is not None : for vols in cornerVolumes : for vol in vols : CoordinateTransform(vol['stormCells'], args.statLonLat[0], args.statLonLat[1]) theFig = plt.figure(figsize=args.figsize) grid = AxesGrid(theFig, 111, nrows_ncols=args.layout, share_all=True, axes_pad=0.32) # A list to hold the CircleCollection arrays, it will have length # of max(tLims) - min(tLims) + 1 allCorners = None if args.trackFile is not None : (tracks, falarms) = FilterMHTTracks(*ReadTracks(args.trackFile)) if args.statLonLat is not None : CoordinateTransform(tracks + falarms, args.statLonLat[0], args.statLonLat[1]) (xLims, yLims, frameLims) = DomainFromTracks(tracks + falarms) else : volumes = [] for aVol in cornerVolumes : volumes.extend(aVol) (xLims, yLims, tLims, frameLims) = DomainFromVolumes(volumes) showMap = (args.statLonLat is not None and args.displayMap) if showMap : bmap = Basemap(projection='cyl', resolution='l', suppress_ticks=False, llcrnrlat=yLims[0], llcrnrlon=xLims[0], urcrnrlat=yLims[1], urcrnrlon=xLims[1]) startFrame = args.startFrame endFrame = args.endFrame tail = args.tail if startFrame is None : startFrame = frameLims[0] if endFrame is None : endFrame = frameLims[1] if tail is None : tail = 0 # A common event_source for synchronizing all the animations theTimer = None # Make the corners big big = False if args.radarFile is not None and args.statLonLat is not None : if endFrame - frameLims[0] >= len(args.radarFile) : # Not enough radar files, so truncate the tracks. endFrame = (len(args.radarFile) + frameLims[0]) - 1 files = args.radarFile[startFrame - frameLims[0]:(endFrame + 1) - frameLims[0]] radAnim = RadarAnim(theFig, files) theTimer = radAnim.event_source for ax in grid : radAnim.add_axes(ax, alpha=0.6, zorder=0) # Radar images make it difficult to see corners, so make 'em big big = True else : radAnim = None theAnim = CornerAnimation(theFig, endFrame - startFrame + 1, tail=tail, interval=250, blit=False, event_source=theTimer, fade=args.fade) for (index, volData) in enumerate(cornerVolumes) : curAxis = grid[index] if showMap : PlotMapLayers(bmap, mapLayers, curAxis, zorder=0.1) volFrames = [frameVol['frameNum'] for frameVol in volData] startIdx = volFrames.index(startFrame) endIdx = volFrames.index(endFrame) volTimes = [frameVol['volTime'] for frameVol in volData] startT = volTimes[startIdx] endT = volTimes[endIdx] corners = PlotCorners(volData, (startT, endT), axis=curAxis, big=big) #curAxis.set_aspect("equal", 'datalim') #curAxis.set_aspect("equal") curAxis.set_title(titles[index]) if not showMap : curAxis.set_xlabel("X") curAxis.set_ylabel("Y") else : curAxis.set_xlabel("Longitude") curAxis.set_ylabel("Latitude") theAnim.AddCornerVolume(corners) 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] theAnim.save(args.saveImgFile, extra_anim=radAnim) if args.doShow : plt.show()
def MakeComparePlots(grid, trackData, truthData, titles, showMap, endFrame=None, tail=None, fade=False, multiTags=None, tag_filters=None): true_AssocSegs = None true_FAlarmSegs = None frameLims = None if multiTags is None: multiTags = [None] * len(trackData) for ax, aTracker, truth, title, simTags in zip(grid, trackData, truthData, titles, multiTags): this_endFrame = endFrame this_tail = tail # Will return None if either simTags or filters are None keeperIDs = process_tag_filters(simTags, tag_filters) # Either only do this for the first pass through, # or do it for all passes # In other words, if no frameLims is given, then use the frameLimits # for each truthkData dataset. # Or, if there are multiple truthData datasets, then regardless of # whether frameLims was specified, calculate the frame limits each time if frameLims is None or len(truthData) > 1: true_AssocSegs = CreateSegments(truth[0]) true_FAlarmSegs = CreateSegments(truth[1]) if keeperIDs is not None: true_AssocSegs = FilterSegments(keeperIDs, true_AssocSegs) true_FAlarmSegs = FilterSegments(keeperIDs, true_FAlarmSegs) # TODO: gotta make this get the time limits! xLims, yLims, frameLims = DomainFromTracks(true_AssocSegs, true_FAlarmSegs) if showMap: bmap = Basemap(projection='cyl', resolution='i', suppress_ticks=False, llcrnrlat=yLims[0], llcrnrlon=xLims[0], urcrnrlat=yLims[1], urcrnrlon=xLims[1]) PlotMapLayers(bmap, mapLayers, ax) if this_endFrame is None: this_endFrame = frameLims[1] if this_tail is None: this_tail = this_endFrame - frameLims[0] this_startFrame = this_endFrame - this_tail trackAssocSegs = CreateSegments(aTracker[0]) trackFAlarmSegs = CreateSegments(aTracker[1]) if keeperIDs is not None: trackAssocSegs = FilterSegments(keeperIDs, trackAssocSegs) trackFAlarmSegs = FilterSegments(keeperIDs, trackFAlarmSegs) truthtable = CompareSegments(true_AssocSegs, true_FAlarmSegs, trackAssocSegs, trackFAlarmSegs) PlotSegments(truthtable, (this_startFrame, this_endFrame), axis=ax, fade=fade) ax.set_title(title) if not showMap: ax.set_xlabel("X") ax.set_ylabel("Y") else: ax.set_xlabel("Longitude") ax.set_ylabel("Latitude")