Exemple #1
0
def plot_rhythm(g, sigma, PLOT=False):
    """
    calculate the frequency and plot the histogram of
    activity and filtered activety
    """

    len_g = len(g)
    len_sigma = len(sigma)
    freq = np.zeros((len_g, len_sigma))

    for i in range(len_g):
        for j in range(len_sigma):
            subname = str("%.3f-%.3f" % (g[i], sigma[j]))

            fname = str("spk-%s.npz" % subname)
            pop = np.load("npz/" + fname)

            if PLOT:
                fig0, ax = pl.subplots(2, figsize=(8, 5))
                pl.subplots_adjust(hspace=.4)

            ts = pop['ts']
            gids = pop['gids']
            if len(ts):

                t_bins, heights = lib.calculate_histogram(
                    ts, gids, hist_binwidth)

                filtered = lib.filter_gaussian(heights, fwhm)
                # filtered = lib.filter_bandpass(heights, fs, 2, 1000, 5)

                f, P = welch(filtered, fs=fs, nperseg=nperseg)
                freq[i, j] = f[np.argmax(P)]

                if PLOT:
                    lib.plot_rhythms_from_file(t_bins, heights, filtered,
                                               ax[0], xlim)

                    lib.plot_power_spectrum(f, P, ax[1])

            if PLOT:
                pl.savefig('fig/r-' + subname + ".png")
                pl.close()
Exemple #2
0
def plot_activity(fname, fwhm, ax):

    number = 10
    cmap = pl.get_cmap('afmhot')
    colors = [cmap(i) for i in np.linspace(0, 1, number)]

    # fname = str("spk-%s.npz" % subname)
    pop = np.load("npz/" + fname)

    ts = pop['ts']
    gids = pop['gids']
    if len(ts) > 3:
        tmp = lib.calculate_spike_synchrony(ts, gids)
        R = 0 if ((tmp > 1) or (tmp < 0)) else tmp
        R = int(round(R, 1) * 10)

        t_bins, heights = lib.calculate_histogram(ts, gids, hist_binwidth)
        filtered = lib.filter_gaussian(heights, fwhm)

        # ax1.tick_params(axis='y', labelcolor='royalblue')
        ax.plot(t_bins, filtered, lw=2, c=colors[R])
    else:
        print "empty plot for %s" % fname