Example #1
0
    def showData(self,
                 axes=[],
                 lw=2,
                 onMap=True,
                 bins=100,
                 showVel=False,
                 centered=True,
                 showCenter=False):
        """Shows basic stats histograms and movement trajectories of all data sets.
	
		.. note:: Creates new figure if axes is not specified.
		
		Keyword Args:
			ax (matplotlib.axes): Axes.
			bins (int): Number of bins.
		
		Returns:
			list: List of modified axes.
		"""

        # Create axes if not specified
        if len(axes) != 6:
            fig, axes = pm.makeSubplot([3, 2])

        if onMap:
            ax = pm.drawMap(axes[0])
        self.plotLonLatTraj(ax=ax, onMap=onMap, lw=lw)
        self.plotCartTraj(ax=axes[1],
                          showVel=showVel,
                          centered=centered,
                          showCenter=showCenter)
        self.showStats(axes=axes[2:])

        return axes
Example #2
0
	def showClustersOnTracks(self,ax=None,centered=True,nbouts=3,showCenter=False):
		
		"""Plots all trajectory of gps data colorized by kmeans-clustered groups.
		
		Keyword Args:
			ax (matplotlib.axes): Axes to plot in.
			nbouts (int): Number of bouts to cluster data in.
			centered (bool): Show centered coordinates.
			center (list): Center of plot.
			showCenter (bool): Display center.
		
		Returns:
			matplotlib.axes: Modified axes.
		
		"""
		
		# Create axes if necessary
		if ax==None:
			fig,axes=pm.makeSubplot([1,1])
			ax=axes[0]
		
		#self.performKMeans(nbouts=nbouts)
		labels=self.kMeansLabels
		print labels
		colors=pm.getColors(len(np.unique(labels)))
		
		for i,w in enumerate(self.windows):
			w.plotCartTraj(ax=ax,vel=[],showVel=False,centered=centered,color=colors[labels[i]],center=[0,0,0],showCenter=showCenter)
Example #3
0
	def plotClusters(self,ax=None,var='dta',showLabels=False,cpick='jet',alg='kMeans',nbouts=3):
		
		"""Shows scatter plot of gps data binned in windows.
		
		If algorithm is 'kMeans', performs additional kMeans and labels windows by bout.
		
		``var`` defines which variables are shown on x/y/z-axis in the order they are specified. 
		
			* 'd': distances
			* 't': deltaT
			* 'a': angles
			* 'v': velocities
			
		Keyword Args:
			ax (matplotlib.axes): Axes to plot in.
			var (str): Define which variables are plotted.
			showLabels (bool): Show labels.
			cpick (str): Colormap used for coloring.
			alg (str): Algorithm used for clustering.
			nbouts (int): Number of bouts to cluster data in.
			
		Returns:
			matplotlib.axes: Modified axes.
			
		"""
		
		idxs=[]
		
		# Figure out what to plot
		if 'd' in var:
			idxs.append(0)
		if 't' in var:
			idxs.append(1)
		if 'v' in var:
			idxs.append(2)
		if 'a' in var:
			idxs.append(3)
		
		# Cluster
		if alg=='none':
			labels=np.zeros(np.shape(self.stats)[0])
		if alg=='kMeans':
			self.performKMeans(nbouts=nbouts)
			labels=self.kMeansLabels
		
		# Create axes if necessary
		if ax==None:
			fig,axes=pm.makeSubplot([1,1],proj=['3d'])
			ax=axes[0]
		
		# Plot
		pm.labeledScatter(self.stats[:,idxs[0]],self.stats[:,idxs[1]],self.stats[:,idxs[2]],labels,ax=ax,cmap=cpick)
		
		# Labels
		ax.set_xlabel(var[0])
		ax.set_ylabel(var[1])
		ax.set_zlabel(var[2])
		ax.get_figure().canvas.draw()
		
		return ax
Example #4
0
    def showClusters(self, axes=None):

        # Get number of window sets
        N = len(self.Windows)

        # Compute number of plots displayed
        Nx = int(np.ceil(N / 2.))
        Ny = int(np.floor(N / 2.))

        # Show scatter plot for each window set
        proj = N * ['3d']
        fig, axes = pm.makeSubplot([Nx, Ny], proj=proj)
        for i, w in enumerate(self.Windows):
            w.plotClusters(ax=axes[i], var='dta')

        # Show labeled trajectories for each set
        fig, axes = pm.makeSubplot([Nx, Ny])
        for i, w in enumerate(self.Windows):
            w.showClustersOnTracks(ax=axes[i])
Example #5
0
    def showStats(self, axes=[], bins=100):
        """Creates four histograms showing overall movement stats of all dataset.
	
		.. note:: Creates new figure if axes is not specified.
		
		Keyword Args:
			ax (matplotlib.axes): Axes.
			bins (int): Number of bins.
		
		Returns:
			list: List of modified axes.
		"""

        # Create axes if not specified
        if len(axes) != 4:
            fig, axes = pm.makeSubplot([2, 2])

        self.plotDHist(ax=axes[0], bins=bins)
        self.plotVHist(ax=axes[1], bins=bins)
        self.plotAnglesHist(ax=axes[2], bins=bins)
        self.plotDeltaTHist(ax=axes[3], bins=bins)

        return axes
    w.showClustersOnTracks()

    raw_input()

#for ID in g.IDs:

#g.data[ID].cleanUpData()

#g.data[ID].showAllPlots()

#stats_module.
raw_input()

# Create figure
fig, axes = pm.makeSubplot([2, 2])

# Draw map
m = pm.drawMap(axes[0])

# Plot location of sable island
#pm.plotSquareAroundCoordinate(m,sable,1)

# Plot trajectories into basemap
for ID in g.IDs:
    g.data[ID].plotLonLatTraj(m)

# Plot trajectories in cartesian coordinates
for ID in g.IDs:
    g.data[ID].plotCartTraj(axes[1])