Пример #1
0
def plot_sim_vs_real(simulated_voltage_dict=[],
                     bio_voltage_dict=[],
                     input_current_dict=[],
                     plot_nan_as_spike=True,
                     fig_dir="./",
                     file_ext=".png"):
    """
    Plots the simulated voltage traces against the actual voltage traces and
    saves the result as .eps file.

    :param bio_voltage_dict: dictionary, values of which are arrays of voltage traces
    :param input_voltage_dict: dictionary of input current injections, values of which are arrays of input stimuli
    :param simulated_voltage_dict: dictionary. values of which are lists of arrays of monte carlo simulated voltage traces
    :param fig_dir: directory into which figures will be plotted
    :keyword nan_as_spike: do we draw spiking lines where the traces are nan?
    :type nan_as_spike: bool
    :keyword file_ext: file extension of plotting results
    :type file_ext: str

    .. note::
        It is assumed that the keys of the dictionary inputs correspond to each
        other.
    """

    for key in input_current_dict.keys():

        input_current = input_current_dict[key]
        membrane_voltage = bio_voltage_dict[key]
        membrane_voltage_sim_list = simulated_voltage_dict[key]

        for (cur_rep,
             membrane_voltage_sim) in enumerate(membrane_voltage_sim_list):

            pylab.figure(figsize=(20, 12), dpi=200)
            data_len = len(membrane_voltage)
            x = np.array(range(0, data_len))
            y1 = membrane_voltage
            y2 = membrane_voltage_sim
            y3 = input_current

            subplot_top = pylab.subplot(211)
            pylab.title(key)
            pylab.plot(x,
                       y1,
                       color="blue",
                       linewidth=1.0,
                       linestyle="-",
                       label="Membrane voltage")
            pylab.plot(x,
                       y2,
                       color="green",
                       linewidth=1.0,
                       linestyle="-",
                       label="Simulated voltage")
            subplot_top.legend()

            if plot_nan_as_spike:
                spike_ind_sim = spk_from_sim([membrane_voltage_sim])[0]
            else:
                spike_ind_sim = []

            [
                pylab.axvline(x=cur_ind, linestyle=':', color='green')
                for cur_ind in spike_ind_sim
            ]
            pylab.ylim((-80, -20))
            pylab.xlim((0, len(x)))
            ticks = np.arange(x.min(), x.max(), 1000)
            labels = 0.1 * np.array(range(ticks.size))
            pylab.xticks(ticks, labels)
            pylab.xlabel('Time (s)')
            pylab.ylabel('Voltage (mV)')

            #gamma = spkd_lib.gamma_factor(spike_ind_sim,spike_ind_raw,0.005)
            #gamma_str = r"$\Gamma =" + str(gamma) + "$"

            subplot_low = pylab.subplot(212)
            pylab.plot(x,
                       y3,
                       color="black",
                       linewidth=1.0,
                       linestyle="-",
                       label="Input current")
            subplot_low.legend()
            pylab.xlim((0, len(x)))
            ticks = np.arange(x.min(), x.max(), 1000)
            labels = 0.1 * np.array(range(ticks.size))
            pylab.xticks(ticks, labels)
            pylab.xlabel('Time (s)')
            pylab.ylabel('Current (A)')

            file_str = os.path.splitext(key)[0] + "_rep" + str(
                cur_rep) + file_ext
            file_path = os.path.join(fig_dir, file_str)
            pylab.savefig(file_path)
            pylab.close()
            print "New plot: " + file_path
Пример #2
0
def plot_sim_vs_real(simulated_voltage_dict=[],
                     bio_voltage_dict=[],
                     input_current_dict=[],
                     plot_nan_as_spike=True,
                     fig_dir="./",
                     file_ext=".png"):
    """
    Plots the simulated voltage traces against the actual voltage traces and
    saves the result as .eps file.

    :param bio_voltage_dict: dictionary, values of which are arrays of voltage traces
    :param input_voltage_dict: dictionary of input current injections, values of which are arrays of input stimuli
    :param simulated_voltage_dict: dictionary. values of which are lists of arrays of monte carlo simulated voltage traces
    :param fig_dir: directory into which figures will be plotted
    :keyword nan_as_spike: do we draw spiking lines where the traces are nan?
    :type nan_as_spike: bool
    :keyword file_ext: file extension of plotting results
    :type file_ext: str

    .. note::
        It is assumed that the keys of the dictionary inputs correspond to each
        other.
    """

    for key in input_current_dict.keys():

        input_current = input_current_dict[key]
        membrane_voltage = bio_voltage_dict[key]
        membrane_voltage_sim_list = simulated_voltage_dict[key]

        for (cur_rep,membrane_voltage_sim) in enumerate(membrane_voltage_sim_list):

            pylab.figure(figsize=(20,12), dpi=200)
            data_len = len(membrane_voltage)
            x = np.array(range(0,data_len))
            y1 = membrane_voltage
            y2 = membrane_voltage_sim
            y3 = input_current

            subplot_top = pylab.subplot(211)
            pylab.title(key)
            pylab.plot(x, y1, color="blue", linewidth=1.0, linestyle="-", label="Membrane voltage")
            pylab.plot(x, y2, color="green", linewidth=1.0, linestyle="-", label="Simulated voltage")
            subplot_top.legend()

            if plot_nan_as_spike:
                spike_ind_sim = spk_from_sim([membrane_voltage_sim])[0]
            else:
                spike_ind_sim = []

            [pylab.axvline(x=cur_ind,linestyle = ':',color='green') for cur_ind in spike_ind_sim]
            pylab.ylim( (-80,-20) )
            pylab.xlim( (0,len(x)) )
            ticks = np.arange(x.min(), x.max(), 1000)
            labels = 0.1*np.array(range(ticks.size))
            pylab.xticks(ticks,labels)
            pylab.xlabel('Time (s)')
            pylab.ylabel('Voltage (mV)')

            #gamma = spkd_lib.gamma_factor(spike_ind_sim,spike_ind_raw,0.005)
            #gamma_str = r"$\Gamma =" + str(gamma) + "$"

            subplot_low = pylab.subplot(212)
            pylab.plot(x, y3, color="black", linewidth=1.0, linestyle="-",label="Input current")
            subplot_low.legend()
            pylab.xlim( (0,len(x)) )
            ticks = np.arange(x.min(), x.max(), 1000)
            labels = 0.1*np.array(range(ticks.size))
            pylab.xticks(ticks,labels)
            pylab.xlabel('Time (s)')
            pylab.ylabel('Current (A)')

            file_str = os.path.splitext(key)[0] + "_rep" + str(cur_rep) + file_ext
            file_path = os.path.join(fig_dir,file_str)
            pylab.savefig(file_path)
            pylab.close()
            print "New plot: " + file_path
Пример #3
0
def plot_spk_performance_metrics(bio_voltage_dict,
                                 simulated_voltage_dict,
                                 fig_dir="./",
                                 file_ext=".png",
                                 dt=0.0001):
    """
    Plots spike distance metrics for the data provided.  Metrics used are the gamma coincidence factor,
    the Schreiber similarity, and the van Rossum distance.  Each is plotted as a function of the
    smoothness parameter for that particular metric.  The spike times are extracted
    from the voltage traces using :func:`fit_neuron.data.extract_spikes.spk_from_sim`
    and :func:`fit_neuron.data.extract_spikes.spk_from_bio`.

    :param bio_voltage_dict: recorded voltage traces, indexed by a file ID
    :type bio_voltage_dict: dict
    :param simulated_voltage_dict: simulated voltage traces, indexed by a file ID
    :type simulated_voltage_dict: dict
    :keyword fig_dir: directory where the plots will be saved
    :keyword file_ext: file extension
    :keyword dt: time step interval

    .. note::
        The keys of bio_voltage_dict and simulated_voltage_dict must match.
        In addition, there may be multiple simulations for a single file ID,
        but there should be a single recorded voltage trace for a file ID.
    """

    for key in bio_voltage_dict.keys():
        membrane_voltage = bio_voltage_dict[key]
        membrane_voltage_sim_list = list(simulated_voltage_dict[key])

        for (cur_rep,
             membrane_voltage_sim) in enumerate(membrane_voltage_sim_list):
            key_id = os.path.splitext(key)[0]
            end_ext = "_" + key_id + "_rep" + str(cur_rep) + file_ext
            sim_spk_times = dt * spk_from_sim([membrane_voltage_sim])[0]
            bio_spk_times = dt * spk_from_bio([membrane_voltage])[0]

            # --------- VAN ROSSUM -------------
            powers = np.arange(-5, 5, 0.25)
            van_rossum_i = [math.pow(10, power) for power in powers]
            # as tc increases, the spikes get smoothed more and more so distance will decrease
            van_rossum_d = [
                spkd_lib.van_rossum_dist(bio_spk_times,
                                         sim_spk_times,
                                         tc=t_cur) for t_cur in van_rossum_i
            ]
            pylab.semilogx(van_rossum_i, van_rossum_d)
            file_str = "van_rossum_dist" + end_ext
            file_path = os.path.join(fig_dir, file_str)
            pylab.grid()
            pylab.xlabel(r'$\tau_r$')
            pylab.ylabel('van Rossum distance')
            pylab.savefig(file_path)
            print "New plot: " + file_path
            pylab.close()

            # --------- GAMMA FACTOR ----------------
            gamma_factor_i = np.arange(0.0, 0.01, 0.00005)
            gamma_factor_d = [
                spkd_lib.gamma_factor(sim_spk_times,
                                      bio_spk_times,
                                      delta=cur_delta)
                for cur_delta in gamma_factor_i
            ]
            pylab.plot(gamma_factor_i, gamma_factor_d)
            pylab.xlabel(r'$\Delta t$')
            pylab.ylabel('Gamma coincidence factor')

            if max(gamma_factor_d) > 0:
                pylab.ylim((-0.01, 1.01))

            pylab.grid()
            file_str = "gamma_factor" + end_ext
            file_path = os.path.join(fig_dir, file_str)
            pylab.savefig(file_path)
            print "New plot: " + file_path
            pylab.close()

            # ---------- SCHREIBER SIMILARITY ----------
            powers = np.arange(-5, 5, 0.25)
            schreiber_i = [math.pow(10, power) for power in powers]
            schreiber_d = [
                spkd_lib.schreiber_sim(sim_spk_times,
                                       bio_spk_times,
                                       sigma=cur_sigma)
                for cur_sigma in schreiber_i
            ]
            pylab.semilogx(schreiber_i, schreiber_d)
            pylab.xlabel(r'$\sigma$ (bandwidth of Gaussian kernel)')
            pylab.ylabel('Schreiber similarity')

            if max(gamma_factor_d) > 0:
                pylab.ylim((-0.01, 1.01))

            pylab.grid()
            file_str = "schreiber_similarity" + end_ext
            file_path = os.path.join(fig_dir, file_str)
            pylab.savefig(file_path)
            print "New plot: " + file_path
            pylab.close()
            '''
Пример #4
0
def plot_spk_performance_metrics(bio_voltage_dict,simulated_voltage_dict,fig_dir="./",file_ext=".png",dt=0.0001):
    """
    Plots spike distance metrics for the data provided.  Metrics used are the gamma coincidence factor,
    the Schreiber similarity, and the van Rossum distance.  Each is plotted as a function of the
    smoothness parameter for that particular metric.  The spike times are extracted
    from the voltage traces using :func:`fit_neuron.data.extract_spikes.spk_from_sim`
    and :func:`fit_neuron.data.extract_spikes.spk_from_bio`.

    :param bio_voltage_dict: recorded voltage traces, indexed by a file ID
    :type bio_voltage_dict: dict
    :param simulated_voltage_dict: simulated voltage traces, indexed by a file ID
    :type simulated_voltage_dict: dict
    :keyword fig_dir: directory where the plots will be saved
    :keyword file_ext: file extension
    :keyword dt: time step interval

    .. note::
        The keys of bio_voltage_dict and simulated_voltage_dict must match.
        In addition, there may be multiple simulations for a single file ID,
        but there should be a single recorded voltage trace for a file ID.
    """

    for key in bio_voltage_dict.keys():
        membrane_voltage = bio_voltage_dict[key]
        membrane_voltage_sim_list = list(simulated_voltage_dict[key])

        for (cur_rep,membrane_voltage_sim) in enumerate(membrane_voltage_sim_list):
            key_id = os.path.splitext(key)[0]
            end_ext = "_" + key_id + "_rep" + str(cur_rep) + file_ext
            sim_spk_times = dt * spk_from_sim([membrane_voltage_sim])[0]
            bio_spk_times = dt * spk_from_bio([membrane_voltage])[0]

            # --------- VAN ROSSUM -------------
            powers = np.arange(-5,5,0.25)
            van_rossum_i = [math.pow(10,power) for power in powers]
            # as tc increases, the spikes get smoothed more and more so distance will decrease
            van_rossum_d = [spkd_lib.van_rossum_dist(bio_spk_times,sim_spk_times,tc=t_cur) for t_cur in van_rossum_i]
            pylab.semilogx(van_rossum_i, van_rossum_d)
            file_str = "van_rossum_dist" + end_ext
            file_path = os.path.join(fig_dir,file_str)
            pylab.grid()
            pylab.xlabel(r'$\tau_r$')
            pylab.ylabel('van Rossum distance')
            pylab.savefig(file_path)
            print "New plot: " + file_path
            pylab.close()

            # --------- GAMMA FACTOR ----------------
            gamma_factor_i = np.arange(0.0,0.01,0.00005)
            gamma_factor_d = [spkd_lib.gamma_factor(sim_spk_times,bio_spk_times,delta=cur_delta) for cur_delta in gamma_factor_i]
            pylab.plot(gamma_factor_i,gamma_factor_d)
            pylab.xlabel(r'$\Delta t$')
            pylab.ylabel('Gamma coincidence factor')

            if max(gamma_factor_d) > 0:
                pylab.ylim( (-0.01,1.01) )

            pylab.grid()
            file_str = "gamma_factor" + end_ext
            file_path = os.path.join(fig_dir,file_str)
            pylab.savefig(file_path)
            print "New plot: " + file_path
            pylab.close()

            # ---------- SCHREIBER SIMILARITY ----------
            powers = np.arange(-5,5,0.25)
            schreiber_i = [math.pow(10,power) for power in powers]
            schreiber_d = [spkd_lib.schreiber_sim(sim_spk_times,bio_spk_times,sigma=cur_sigma) for cur_sigma in schreiber_i]
            pylab.semilogx(schreiber_i,schreiber_d)
            pylab.xlabel(r'$\sigma$ (bandwidth of Gaussian kernel)')
            pylab.ylabel('Schreiber similarity')

            if max(gamma_factor_d) > 0:
                pylab.ylim( (-0.01,1.01) )

            pylab.grid()
            file_str = "schreiber_similarity" + end_ext
            file_path = os.path.join(fig_dir,file_str)
            pylab.savefig(file_path)
            print "New plot: " + file_path
            pylab.close()

            '''