コード例 #1
0
ファイル: plotting.py プロジェクト: rhayman/ephysiopy
 def makeSpeedVsHeadDirectionPlot(self, spk_times: np.array,
                                  ax: matplotlib.axes = None,
                                  **kwargs) -> matplotlib.axes:
     self.initialise()
     spk_times_in_pos_samples = self.getSpikePosIndices(spk_times)
     idx = np.array(spk_times_in_pos_samples, dtype=int)
     if np.ma.is_masked(self.speed):
         w = self.speed.mask
         w = np.array(~w, dtype=int)
     else:
         w = np.bincount(idx, minlength=self.speed.shape[0])
     dir_bins = np.arange(0, 360, 6)
     spd_bins = np.arange(0, 30, 1)
     h = np.histogram2d(
         self.dir, self.speed, [dir_bins, spd_bins], weights=w)
     from ephysiopy.common.utils import blurImage
     im = blurImage(h[0], 5, ftype='gaussian')
     im = np.ma.MaskedArray(im)
     # mask low rates...
     im = np.ma.masked_where(im <= 1, im)
     # ... and where less than 0.5% of data is accounted for
     x, y = np.meshgrid(dir_bins, spd_bins)
     vmax = np.max(np.ravel(im))
     if ax is None:
         fig = plt.figure()
         ax = fig.add_subplot(111)
     ax.pcolormesh(x, y, im.T, cmap=plt.cm.get_cmap("jet"),
                   edgecolors='face',
                   vmax=vmax, shading='auto')
     plt.xticks([90, 180, 270], fontweight='normal', size=6)
     plt.yticks([10, 20], fontweight='normal', size=6)
     return ax
コード例 #2
0
ファイル: plotting.py プロジェクト: rhayman/ephysiopy
 def makeRateMap(self, spk_times: np.array,
                 ax: matplotlib.axes = None) -> matplotlib.axes:
     self.initialise()
     spk_times_in_pos_samples = self.getSpikePosIndices(spk_times)
     spk_weights = np.bincount(
         spk_times_in_pos_samples, minlength=self.npos)
     rmap = self.RateMapMaker.getMap(spk_weights)
     ratemap = np.ma.MaskedArray(rmap[0], np.isnan(rmap[0]), copy=True)
     x, y = np.meshgrid(rmap[1][1][0:-1], rmap[1][0][0:-1])
     vmax = np.nanmax(np.ravel(ratemap))
     if ax is None:
         fig = plt.figure()
         ax = fig.add_subplot(111)
     ax.pcolormesh(
         x, y, ratemap, cmap=plt.cm.get_cmap("jet"), edgecolors='face',
         vmax=vmax, shading='auto')
     ax.set_aspect('equal')
     return ax
コード例 #3
0
ファイル: plotting.py プロジェクト: rhayman/ephysiopy
    def show_SAC(self, A: np.array, inDict: dict,
                 ax: matplotlib.axes = None, **kwargs) -> matplotlib.axes:
        """
        Displays the result of performing a spatial autocorrelation (SAC)
        on a grid cell.

        Uses the dictionary containing measures of the grid cell SAC to
        make a pretty picture

        Parameters
        ----------
        A : array_like
            The spatial autocorrelogram
        inDict : dict
            The dictionary calculated in getmeasures
        ax : matplotlib.axes._subplots.AxesSubplot, optional
            If given the plot will get drawn in these axes. Default None

        Returns
        -------
        fig : matplotlib.Figure instance
            The Figure on which the SAC is shown

        See Also
        --------
        ephysiopy.common.binning.RateMap.autoCorr2D()
        ephysiopy.common.ephys_generic.FieldCalcs.getMeaures()
        """
        if ax is None:
            fig = plt.figure()
            ax = fig.add_subplot(111)
        Am = A.copy()
        Am[~inDict['dist_to_centre']] = np.nan
        Am = np.ma.masked_invalid(np.atleast_2d(Am))
        x, y = np.meshgrid(
            np.arange(0, np.shape(A)[1]),
            np.arange(0, np.shape(A)[0]))
        vmax = np.nanmax(np.ravel(A))
        ax.pcolormesh(
            x, y, A, cmap=plt.cm.get_cmap("gray_r"),
            edgecolors='face', vmax=vmax, shading='auto')
        import copy
        cmap = copy.copy(plt.cm.get_cmap("jet"))
        cmap.set_bad('w', 0)
        ax.pcolormesh(
            x, y, Am, cmap=cmap,
            edgecolors='face', vmax=vmax, shading='auto')
        # horizontal green line at 3 o'clock
        _y = (np.shape(A)[0]/2, np.shape(A)[0]/2)
        _x = (np.shape(A)[1]/2, np.shape(A)[0])
        ax.plot(_x, _y, c='g')
        mag = inDict['scale'] * 0.5
        th = np.linspace(0, inDict['orientation'], 50)
        from ephysiopy.common.utils import rect
        [x, y] = rect(mag, th, deg=1)
        # angle subtended by orientation
        ax.plot(
            x + (inDict['dist_to_centre'].shape[1] / 2),
                (inDict['dist_to_centre'].shape[0] / 2) - y, 'r', **kwargs)
        # plot lines from centre to peaks above middle
        for p in inDict['closest_peak_coords']:
            if p[0] <= inDict['dist_to_centre'].shape[0] / 2:
                ax.plot(
                    (inDict['dist_to_centre'].shape[1]/2, p[1]),
                    (inDict['dist_to_centre'].shape[0] / 2, p[0]), 'k', **kwargs)
        ax.invert_yaxis()
        all_ax = ax.axes
        all_ax.set_aspect('equal')
        all_ax.set_xlim((0.5, inDict['dist_to_centre'].shape[1]-1.5))
        all_ax.set_ylim((inDict['dist_to_centre'].shape[0]-.5, -.5))
        return ax