示例#1
0
def plot_cutout(timepoints, cutout):
    num_electrodes = np.shape(cutout)[1]
    lw = 0.5
    for i in range(num_electrodes):
        plt.subplot(num_electrodes, 1, i+1)
        plt.plot(timepoints*1000, cutout[:,i] / 1000, linewidth = lw, color = 'grey')
        MP_plot.prettify_axes(plt.gca())
示例#2
0
def plot_spikes(spike_times, time_range = []):
    """ This function is called by plot_spikes_feed_times, and plot_spikes_heat_times
        to plot all the spikes nicely
        
    Arguments:
        spike_times: timestamps of spikes in units of seconds
        time_range: range to be displayed, in units of seconds
            -useful to avoid phototagging spikes after behaviour
        """
    
    # if there was no specific time_range, it will go from 0 to max
    if len(time_range) == 0:
        time_range = [0, int(spike_times[0].max(0))]
        
    spike_hist = []
    binwidth = 5 # in seconds
    bins = np.array(range(time_range[0], time_range[1], binwidth))
    colorj = ['g', 'b', 'k', 'r']
    
    fig = plt.figure( figsize = [12, 6])
    ax = fig.add_subplot(1,1,1)
    for i, curspikes in enumerate( spike_times):
        temp, nothing = np.histogram(curspikes, bins=bins)
        spike_hist.append(temp)
        ax.plot(bins[:-1] / 60, spike_hist[i]/ (bins[1]-bins[0]), label = 'Neuron ' + str(i),
                 linewidth = math.ceil((i+3 )/ len(colorj)), color = colorj[i%len(colorj)])
    
    plt.legend(frameon = False)
    plt.xlabel('Time (min)', fontsize = 18)
    plt.ylabel('Firing Rate', fontsize = 18)
    plt.show()
    
    MP_plot.prettify_axes(ax)  
    plt.xlim(time_range[0]/60, time_range[1]/60)
    return ax, spike_hist
示例#3
0
def compare_truth_pyfnnd(ca_data, learn_theta=(0, 1, 1, 1, 0), tau=0.6):
    '''
    '''
    from fit_neuron.evaluate import spkd_lib as spkd

    n_best, c_best, LL, theta_best = pyfnnd.deconvolve(
        ca_data.df_f.reshape(-1, 1).T,
        dt=0.0166,
        verbosity=1,
        learn_theta=learn_theta,  #tau = tau,
        spikes_tol=1E-5,
        params_tol=1E-5)

    resamp_spikes = MP_analy.downsample_spike_train(ca_data.spike_train,
                                                    ca_data.spike_time,
                                                    ca_data.fluor_time)
    resamp_spikes[resamp_spikes > 1] = 1
    n_best = np.roll(n_best, -1)

    pyfnnd.plotting.plot_fit(
        ca_data.df_f.reshape(-1, 1).T, n_best, c_best, theta_best, 0.0166)

    #    from sklearn.metrics import roc_curve, auc
    #    fpr, tpr, thresholds = roc_curve(resamp_spikes, n_best, pos_label = 1)
    #    my_auc = auc(fpr, tpr)

    #    plt.figure()
    #    plt.plot(fpr, tpr)
    #    plt.xlabel('False Positive Rate', fontsize = 18)
    #    plt.ylabel('True Positive Rate', fontsize = 18)
    #    plt.title('AUC = ' + str(my_auc))

    thresholds = np.arange(0.01, 1, 0.01)
    true_spk_times = ca_data.spike_time[ca_data.spike_train > 0.5]
    max_dist = 2 * len(true_spk_times)  # maximum distance for victor purpura
    vp = max_dist * np.ones(99)  # victor-purpura
    vp_cost = 5

    for i, thresh in enumerate(thresholds):
        if np.sum(
                n_best > thresh
        ) > max_dist:  # is you have a lot of bad spikes, calculating vp can be long
            continue
        else:
            vp[i] = spkd.victor_purpura_dist(
                ca_data.fluor_time[n_best > thresh], true_spk_times, vp_cost)

    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    plt.plot(thresholds, 2 * vp / max_dist)
    plt.xlabel('Threshold', fontsize=18)
    plt.ylabel('Normalized VP distance ', fontsize=18)
    plt.title('Minimum distance: ' + str(min(2 * vp / max_dist)))
    MP_plot.prettify_axes(ax)

    example_spikes = threshold_spike_prob(n_best, 0.07)
    ca_data.plot_calcium_spikes()  # makes a new figure
    plt.plot(ca_data.fluor_time, example_spikes + 0.5)

    return np.min(2 * vp / max_dist)
示例#4
0
def plot_inhib_data(phototag_data):
    """ Plot inhibitory metrics for cells """
    
    fig = plt.figure(figsize = [6, 5])
    ax = fig.add_subplot(1,1,1)
    plt.plot(2 / phototag_data.mean_pre_isi, phototag_data.inhib_latency * 1000, 'o') # divide by 2 because the isi yields TWICE the expected spike rate due to how I define it above
    plt.plot(0, 0)
    
    plt.xlabel('Firing rate (Hz)' )
    plt.ylabel('Inhibitory latency (ms)' )
    MP_plot.prettify_axes(ax)
示例#5
0
def plot_inhib_data(phototag_data):
    """ Plot inhibitory metrics for cells """
    
    fig = plt.figure(figsize = [6, 5])
    ax = fig.add_subplot(1,1,1)
    plt.plot(2 / phototag_data.mean_pre_isi, phototag_data.inhib_latency * 1000, 'o') # divide by 2 because the isi yields TWICE the expected spike rate due to how I define it above
    plt.plot(0, 0)
    
    plt.xlabel('Firing rate (Hz)' )
    plt.ylabel('Inhibitory latency (ms)' )
    MP_plot.prettify_axes(ax)
    def plot_calcium_spikes(self):
        fig = plt.figure()
        ax = fig.add_subplot(1,1,1)

        plt.plot(self.fluor_time, self.df_f)
        resampled_spikes = MP_analy.downsample_spike_train(self.spike_train, self.spike_time, self.fluor_time)
        plt.plot(self.fluor_time, resampled_spikes - 0.5)

        plt.xlabel( 'Time (s)', fontsize = 18)
        plt.ylabel('DF / F // spike probability', fontsize = 18)

        MP_plot.prettify_axes(ax)
示例#7
0
    def plot_calcium_spikes(self):
        fig = plt.figure()
        ax = fig.add_subplot(1, 1, 1)

        plt.plot(self.fluor_time, self.df_f)
        resampled_spikes = MP_analy.downsample_spike_train(
            self.spike_train, self.spike_time, self.fluor_time)
        plt.plot(self.fluor_time, resampled_spikes - 0.5)

        plt.xlabel('Time (s)', fontsize=18)
        plt.ylabel('DF / F // spike probability', fontsize=18)

        MP_plot.prettify_axes(ax)
def compare_truth_pyfnnd( ca_data, learn_theta = (0, 1, 1, 1, 0), tau = 0.6 ):
    from fit_neuron.evaluate import spkd_lib as spkd
    
    n_best, c_best, LL, theta_best = pyfnnd.deconvolve( ca_data.df_f.reshape(-1, 1).T, 
        dt=0.0166, verbosity=1, learn_theta=learn_theta, #tau = tau,
        spikes_tol=1E-5, params_tol=1E-5 )
        
    resamp_spikes = MP_analy.downsample_spike_train(ca_data.spike_train, ca_data.spike_time, ca_data.fluor_time)
    resamp_spikes[resamp_spikes > 1 ] = 1
    n_best = np.roll(n_best, -1)
    
    pyfnnd.plotting.plot_fit(ca_data.df_f.reshape(-1, 1).T, n_best, c_best, theta_best, 0.0166)

#    from sklearn.metrics import roc_curve, auc
#    fpr, tpr, thresholds = roc_curve(resamp_spikes, n_best, pos_label = 1)
#    my_auc = auc(fpr, tpr)

#    plt.figure()
#    plt.plot(fpr, tpr)
#    plt.xlabel('False Positive Rate', fontsize = 18)
#    plt.ylabel('True Positive Rate', fontsize = 18)
#    plt.title('AUC = ' + str(my_auc))
    
    
    thresholds = np.arange(0.01, 1, 0.01)
    true_spk_times = ca_data.spike_time[ca_data.spike_train>0.5]
    max_dist = 2* len(true_spk_times ) # maximum distance for victor purpura
    vp = max_dist * np.ones(99) # victor-purpura
    vp_cost = 5
    
    for i, thresh in enumerate(thresholds):
        if np.sum(n_best > thresh) > max_dist: # is you have a lot of bad spikes, calculating vp can be long
            continue
        else:
            vp[i] = spkd.victor_purpura_dist(ca_data.fluor_time[n_best >thresh], true_spk_times, vp_cost)
    
    fig = plt.figure()
    ax = fig.add_subplot(1,1,1)
    plt.plot(thresholds, 2 * vp / max_dist )
    plt.xlabel('Threshold', fontsize = 18)
    plt.ylabel('Normalized VP distance ', fontsize = 18)
    plt.title('Minimum distance: ' + str(min(2 * vp / max_dist)) )
    MP_plot.prettify_axes(ax)


    example_spikes = threshold_spike_prob(n_best, 0.07)
    ca_data.plot_calcium_spikes() # makes a new figure
    plt.plot( ca_data.fluor_time, example_spikes + 0.5)
    
    return np.min(2 * vp / max_dist)
示例#9
0
def plot_spikes(spike_times, time_range=[]):
    """ This function is called by plot_spikes_feed_times, and plot_spikes_heat_times
        to plot all the spikes nicely
        
    Arguments:
        spike_times: timestamps of spikes in units of seconds
        time_range: range to be displayed, in units of seconds
            -useful to avoid phototagging spikes after behaviour
        """

    # if there was no specific time_range, it will go from 0 to max
    if len(time_range) == 0:
        time_range = [0, int(spike_times[0].max(0))]

    spike_hist = []
    binwidth = 5  # in seconds
    bins = np.array(range(time_range[0], time_range[1], binwidth))
    colorj = ['g', 'b', 'k', 'r']

    fig = plt.figure(figsize=[12, 6])
    ax = fig.add_subplot(1, 1, 1)
    for i, curspikes in enumerate(spike_times):
        temp, nothing = np.histogram(curspikes, bins=bins)
        spike_hist.append(temp)
        ax.plot(bins[:-1] / 60,
                spike_hist[i] / (bins[1] - bins[0]),
                label='Neuron ' + str(i),
                linewidth=math.ceil((i + 3) / len(colorj)),
                color=colorj[i % len(colorj)])

    plt.legend(frameon=False)
    plt.xlabel('Time (min)', fontsize=18)
    plt.ylabel('Firing Rate', fontsize=18)
    plt.show()

    MP_plot.prettify_axes(ax)
    plt.xlim(time_range[0] / 60, time_range[1] / 60)
    return ax, spike_hist
示例#10
0
def plot_phototag_data(phototag_data):
    """ phototagData is an MPNeuroData class; this function assumes
        This function will display various metrics for whether a cell is phototagged """
    
    font = {'family' : 'normal',
        'weight' : 'normal',
        'size'   : 18}

    matplotlib.rc('font', **font)  
    
    mask = phototag_data.good_cell_mask
    fig1 = plt.figure(figsize = [12, 9])
    ax1 = fig1.add_subplot(2,2,1)
    plt.plot(mask * phototag_data.mean_first_spike * 1000, mask * phototag_data.mean_pre_isi * 1000, 'o')
    plt.plot(~mask * phototag_data.mean_first_spike * 1000, ~mask * phototag_data.mean_pre_isi * 1000, 'sr')
    plt.plot([0, 50], [0, 50])
    plt.ylabel('Expected spike time')
    plt.xlabel('Mean first spike latency (ms)')
    MP_plot.prettify_axes(ax1)
    
    # first spike latency and jitter
    ax2 = fig1.add_subplot(2,2,2)
    plt.plot(mask * phototag_data.mean_first_spike*1000, mask * phototag_data.std_first_spike*1000, 'o')
    plt.plot(~mask * phototag_data.mean_first_spike*1000, ~mask * phototag_data.std_first_spike*1000, 'sr')
    plt.plot(0, 0)
    plt.ylabel('Jitter (ms)')
    plt.xlabel('Mean first spike latency (ms)')
    MP_plot.prettify_axes(ax2)
    
    # first spike latency vs signal detection
    ax3 = fig1.add_subplot(2,2,3)
    plt.plot(phototag_data.mean_first_spike * 1000, phototag_data.first_firing_above_mean *1000, 'o')
    #plt.plot([0, 20], [0, 30])
    plt.xlabel('Mean first spike latency (ms)')
    plt.ylabel('Latency for\n firing rate > mean + 3SD (ms)')
    MP_plot.prettify_axes(ax3)
    
    # first spike latency vs signal detection
    ax4 = fig1.add_subplot(2,2,4)
    plt.plot(mask * phototag_data.mean_first_spike * 1000, mask * phototag_data.failure_rate * 100, 'o')
    plt.plot(~mask * phototag_data.mean_first_spike * 1000, ~mask * phototag_data.failure_rate * 100, 'sr')
    plt.xlabel('Mean first spike latency (ms)')
    plt.ylabel('Failure rate (%)')
    MP_plot.prettify_axes(ax4)
示例#11
0
import numpy as np
import MPNeuro.plotting as MP_plot
import pandas as pd

SR57_data = np.array([[0.5, 0.6, 0.45, 0.55, 0.74, 0.63, 0.57],
                      [0.29, 0.29, 0.1, 0.29, 0.12, 0.03, 0.12],
                      [0.15, 0.25, 0.26, 0.43, 0.12, 0.14,
                       0.06]])  # data from Google Doc
SR57_males = SR57_data[:, 0:4]
SR57_females = SR57_data[:, 4:]
# plot indices
x = np.ones([3, 4])
x[0] = 0
x[2] = 2

fig, ax = plt.subplots()
plt.xlim([-0.5, 2.5])
SR57_line = plt.plot(x, SR57_males, color='b', linewidth=2)
SR57_line = plt.plot(x, SR57_females, color='r', linewidth=2)
plt.ylim([0, 0.75])
plt.ylabel('Food intake in 60 min. (g)', fontsize=18)
ax.xaxis.set_ticklabels([
    '',
    'Ctl',
    '',
    'SR 10mg/kg',
    '',
    'SR 20mg/kg',
])
MP_plot.prettify_axes(ax)
示例#12
0
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 07 12:03:07 2015

@author: palmiteradmin
"""
import matplotlib.pyplot as plt
import numpy as np
import MPNeuro.plotting as MP_plot
import pandas as pd

SR57_data = np.array([[0.5, 0.6, 0.45, 0.55, 0.74, 0.63, 0.57],
             [0.29, 0.29, 0.1, 0.29, 0.12, 0.03, 0.12],
             [0.15, 0.25, 0.26, 0.43, 0.12, 0.14, 0.06]]) # data from Google Doc
SR57_males = SR57_data[:, 0:4]
SR57_females = SR57_data[:, 4:]
# plot indices
x = np.ones([3, 4])
x[0] = 0
x[2] = 2

fig, ax = plt.subplots()
plt.xlim([-0.5, 2.5])
SR57_line = plt.plot(x, SR57_males, color = 'b',  linewidth = 2)
SR57_line = plt.plot(x, SR57_females, color = 'r',  linewidth = 2)
plt.ylim([0, 0.75])
plt.ylabel('Food intake in 60 min. (g)', fontsize = 18)
ax.xaxis.set_ticklabels(['', 'Ctl', '', 'SR 10mg/kg', '', 'SR 20mg/kg', ])
MP_plot.prettify_axes(ax)