In [3]:
%load_ext autoreload
%autoreload 2
The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload
In [4]:
import os
import pathlib
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import colors
import seaborn as sns
import re
import shutil
import pandas as pd
import scipy.stats
import quantities as pq

import exdir
import expipe
from distutils.dir_util import copy_tree
import septum_mec
import spatial_maps as sp
import head_direction.head as head
import septum_mec.analysis.data_processing as dp
import septum_mec.analysis.registration
from septum_mec.analysis.plotting import violinplot, despine
from spatial_maps.fields import (
    find_peaks, calculate_field_centers, separate_fields_by_laplace, 
    map_pass_to_unit_circle, calculate_field_centers, distance_to_edge_function, 
    compute_crossings, which_field)
from phase_precession import cl_corr
#from spike_statistics.core import permutation_resampling
import matplotlib.mlab as mlab
import scipy.signal as ss
from scipy.interpolate import interp1d
from septum_mec.analysis.plotting import regplot
from skimage import measure
from tqdm.notebook import tqdm_notebook as tqdm
tqdm.pandas()

from scipy.stats import wilcoxon
from septum_mec.analysis.statistics import load_data_frames, make_paired_tables, make_statistics_table
In [38]:
# %matplotlib widget
%matplotlib inline
In [6]:
project_path = dp.project_path()
project = expipe.get_project(project_path)
actions = project.actions

output_path = pathlib.Path("output") / "spikes-in-field-in-between"
(output_path / "statistics").mkdir(exist_ok=True, parents=True)
(output_path / "figures").mkdir(exist_ok=True, parents=True)

Load cell statistics and shuffling quantiles

In [7]:
data, labels, colors, queries = load_data_frames()
Number of sessions above threshold 194
Number of animals 4
Number of individual gridcells 139
Number of gridcell recordings 230

divide into stim not stim

In [25]:
# remove multiple measured cells
results, labels = make_paired_tables(data, ['action', 'unit_name', 'gridness'], cell_types=['gridcell'])
results = results['gridcell']
In [26]:
def make_unique_unit_df(label):
    output = pd.DataFrame()
    for (i, action_row), (j, unit_name_row) in zip(results['action'].iterrows(), results['unit_name'].iterrows()):
        assert i==j
        if action_row[label] != action_row[label]: # ugly test for nan
            continue
        output.loc[i, 'action'] = action_row[label]
        output.loc[i, 'channel_group'] = action_row.channel_group
        output.loc[i, 'unit_idnum'] = action_row.unit_idnum
        output.loc[i, 'unit_name'] = unit_name_row[label]
        output.loc[i, 'gridness'] = results['gridness'].loc[i, label]
        day = action_row[label].split('-')[1]
        output.loc[i, 'unit_day'] = f'{action_row.unit_idnum}_{day}'
    output.unit_name = output.unit_name.values.astype(int)
    output.channel_group = output.channel_group.values.astype(int)
    output.unit_idnum = output.unit_idnum.values.astype(int)
    return output
In [27]:
baseline_i = make_unique_unit_df('Baseline I')
stimulated_11 = make_unique_unit_df('11 Hz')

baseline_ii = make_unique_unit_df('Baseline II')
stimulated_30 = make_unique_unit_df('30 Hz')

print("Number of gridcells in baseline i sessions", len(baseline_i))
print("Number of gridcells in stimulated 11Hz ms sessions", len(stimulated_11))

print("Number of gridcells in baseline ii sessions", len(baseline_ii))
print("Number of gridcells in stimulated 30Hz ms sessions", len(stimulated_30))
Number of gridcells in baseline i sessions 63
Number of gridcells in stimulated 11Hz ms sessions 56
Number of gridcells in baseline ii sessions 46
Number of gridcells in stimulated 30Hz ms sessions 35
In [28]:
baseline_ids = baseline_i.unit_day.unique()
In [29]:
baseline_ids
Out[29]:
array(['8_020719', '23_200619', '30_260619', '31_260619', '32_260619',
       '45_010719', '46_010719', '47_010719', '49_010719', '56_020719',
       '57_020719', '58_020719', '78_260619', '79_260619', '96_010719',
       '106_050619', '118_010719', '121_010719', '129_020719',
       '130_020719', '132_020719', '150_260619', '168_120619',
       '174_200619', '179_290519', '185_010719', '186_010719',
       '205_260619', '214_290519', '231_050619', '232_050619',
       '233_120619', '243_260619', '250_200619', '251_200619',
       '252_200619', '253_200619', '263_260619', '265_260619',
       '278_290519', '279_290519', '304_200619', '317_290519',
       '332_060319', '338_060319', '357_220319', '358_220319',
       '359_220319', '361_010319', '362_010319', '379_150319',
       '609_120619', '613_200619', '615_290519', '616_290519',
       '655_060619', '658_120619', '661_200619', '666_290519',
       '667_290519', '715_110319', '851_060319', '932_280219'],
      dtype=object)
In [30]:
stimulated_11_sub = stimulated_11[stimulated_11.unit_day.isin(baseline_ids)]
In [31]:
baseline_ids_11 = stimulated_11_sub.unit_day.unique()
In [32]:
baseline_i_sub = baseline_i[baseline_i.unit_day.isin(baseline_ids_11)]

Plotting

In [16]:
max_speed = .5 # m/s only used for speed score
min_speed = 0.02 # m/s only used for speed score
position_sampling_rate = 100 # for interpolation
position_low_pass_frequency = 6 # for low pass filtering of position

box_size = [1.0, 1.0]
bin_size = 0.02
smoothing_low = 0.03
smoothing_high = 0.06

speed_binsize = 0.02

stim_mask = True
baseline_duration = 600
In [17]:
data_loader = dp.Data(
    position_sampling_rate=position_sampling_rate, 
    position_low_pass_frequency=position_low_pass_frequency,
    box_size=box_size, bin_size=bin_size, 
    stim_mask=stim_mask, baseline_duration=baseline_duration
)
In [18]:
def find_grid_fields(rate_map, sigma=3, seed=2.5):
    # find fields with laplace
    fields_laplace = sp.fields.separate_fields_by_dilation(rate_map, sigma=sigma, seed=seed)
    fields = fields_laplace.copy() # to be cleaned by Ismakov
    fields_areas = scipy.ndimage.measurements.sum(
        np.ones_like(fields), fields, index=np.arange(fields.max() + 1))
    fields_area = fields_areas[fields]
    fields[fields_area < 9.0] = 0

    # find fields with Ismakov-method
    fields_ismakov, radius = sp.separate_fields_by_distance(rate_map)
    fields_ismakov_real = fields_ismakov * bin_size
    approved_fields = []

    # remove fields not found by both methods
    for point in fields_ismakov:
        field_id = fields[tuple(point)]
        approved_fields.append(field_id)

    for field_id in np.arange(1, fields.max() + 1):
        if not field_id in approved_fields:
            fields[fields == field_id] = 0
            
    return fields
In [19]:
def get_data(row):
    spikes = data_loader.spike_train(row.action, row.channel_group, row.unit_name)
    rate_map = data_loader.rate_map(row.action, row.channel_group, row.unit_name, smoothing=0.04)
    pos_x, pos_y, pos_t, pos_speed = map(data_loader.tracking(row.action).get, ['x', 'y', 't', 'v'])
    stim_times = data_loader.stim_times(row.action)
    if stim_times is not None:
        stim_times = np.array(stim_times)
    spikes = np.array(spikes)
    spikes = spikes[(spikes > pos_t.min()) & (spikes < pos_t.max())]
#     sx, sy = rate_map.shape
#     dx = box_size[0] / sx
#     dy = box_size[1] / sy
#     x_bins = np.arange(0, box_size[0], dx)
#     y_bins = np.arange(0, box_size[1], dy)
#     f = interp2d(x_bins, y_bins, rate_map.T)
#     x_new = np.arange(0, box_size[0], dx / 3)
#     y_new = np.arange(0, box_size[1], dy / 3)
#     rate_map = f(x_new, y_new).T
    fields = find_grid_fields(rate_map)
    
    return spikes, pos_x, pos_y, pos_t, rate_map, fields, stim_times
In [20]:
def compute_field_spikes(row, plot=False, z1=5e-3, z2=11e-3, surrogate_fields=None):
    spikes, pos_x, pos_y, pos_t, rate_map, fields, stim_times = get_data(row)
    if surrogate_fields is not None:
        fields = surrogate_fields
#     if field_num is not None:
#         fields = np.where(fields == field_num, fields, 0)
        
    if plot:
        fig, axs = plt.subplots(1, 3, figsize=(16,9))
        axs[1].set_title(f'{row.action} {row.channel_group} {row.unit_idnum}, G={row.gridness:.3f}')
        dot_size = 10
        
    sx, sy = interp1d(pos_t, pos_x), interp1d(pos_t, pos_y)
    
    stim_spikes = []
    stim_in_field_indices = []
    # set z1 and z2 to be after the response: z1=12e3 - z2=60e3
    if stim_times is not None:
        for t in stim_times:
            idx = np.searchsorted(spikes, [t + z1, t + z2], side='right')
            tmp_spikes = spikes[idx[0]: idx[1]].tolist()
            stim_spikes.extend(tmp_spikes)
        stim_spikes_x = sx(stim_spikes)
        stim_spikes_y = sy(stim_spikes)
        stim_in_field_indices = which_field(stim_spikes_x, stim_spikes_y, fields, box_size).astype(bool)
        
#         stim_ids_ = []
#         stim_spikes_ = []
#         for i, t in enumerate(stim_times):
#             idx = np.searchsorted(spikes, [t, t + 30e-3], side='right')
#             tmp_spikes = (spikes[idx[0]: idx[1]] - t).tolist()
#             stim_ids_.extend([i] * len(tmp_spikes))
#             stim_spikes_.extend(tmp_spikes)
            
#         plt.scatter(stim_spikes_, stim_ids_, s=1)
#         plt.axvspan(z1, z2, color='r', alpha=.3)

    spikes_x = sx(spikes)
    spikes_y = sy(spikes)
    in_field_indices = which_field(spikes_x, spikes_y, fields, box_size).astype(bool)        
    
    if plot:
        axs[0].imshow(
            fields.T.astype(bool), extent=[0, box_size[0], 0, box_size[1]], 
            origin='lower', cmap=plt.cm.Greys, zorder=0)
        axs[0].scatter(
            spikes_x[in_field_indices], spikes_y[in_field_indices], 
            s=dot_size, color='r', zorder=1)
        axs[0].scatter(
            spikes_x[~in_field_indices], spikes_y[~in_field_indices], 
            s=dot_size, color='b', zorder=1)
        if stim_times is not None:
            axs[0].scatter(
                stim_spikes_x, stim_spikes_y,
                s=dot_size, color='orange', zorder=1)
        # Display the image and plot all contours found
        contours = measure.find_contours(fields, 0.0)
        axs[1].imshow(rate_map.T, extent=[0, box_size[0], 0, box_size[1]], origin='lower')

        axs[2].plot(pos_x, pos_y, color='k', alpha=.2, zorder=0)
        axs[2].scatter(
            interp1d(pos_t, pos_x)(spikes), interp1d(pos_t, pos_y)(spikes), 
            s=dot_size, zorder=1)

        for ax in axs.ravel()[1:]:
            for n, contour in enumerate(contours):
                ax.plot(
                    contour[:, 0] * bin_size, contour[:, 1] * bin_size, 
                    lw=4, color='y', zorder=3)

        for ax in axs.ravel():
            ax.axis('image')
            ax.set_xticks([])
            ax.set_yticks([])
    return fields, in_field_indices, stim_in_field_indices
In [21]:
def compute_field_spikes_in_between(row, z1_base=-5e-3, z2_base=5e-3, z1_stim=-5e-3, z2_stim=11e-3, z1_between=15e-3, z2_between=5e-3,  plot=False, surrogate_fields=None):
    '''
    Computes % of in field spikes in between stimulations.
    
    Parameters
    ----------
    z1: float
        Time in ms after the stimulation trigger to cut out non-stimulated spike trains
    z2: float
        Time in ms before the next stimulation trigger to cut out non-stimulated spike trains
    '''
    spikes, pos_x, pos_y, pos_t, rate_map, fields, stim_times = get_data(row)
    if surrogate_fields is not None:
        fields = surrogate_fields
#     if field_num is not None:
#         fields = np.where(fields == field_num, fields, 0)
        
    if plot:
        fig, axs = plt.subplots(1, 3, figsize=(16,9))
        axs[1].set_title(f'{row.action} {row.channel_group} {row.unit_idnum}, G={row.gridness:.3f}')
        dot_size = 10
        
    sx, sy = interp1d(pos_t, pos_x), interp1d(pos_t, pos_y)
    
    base_spikes = []
    base_in_filed_indices = []
    if stim_times is not None:
        for t in stim_times:
            idx = np.searchsorted(spikes, [t + z1_base, t + z2_base], side='right')
            tmp_spikes = spikes[idx[0]: idx[1]].tolist()
            base_spikes.extend(tmp_spikes)
        base_spikes_x = sx(base_spikes)
        base_spikes_y = sy(base_spikes)
        base_in_filed_indices = which_field(base_spikes_x, base_spikes_y, fields, box_size).astype(bool)
    else:
        raise Exception("To use 'in_between' the action should be a 'stimulated' action")
    
    stim_spikes = []
    stim_in_field_indices = []
    # set z1 and z2 to be after the response: z1=12e3 - z2=60e3
    for t in stim_times:
        idx = np.searchsorted(spikes, [t + z1_stim, t + z2_stim], side='right')
        tmp_spikes = spikes[idx[0]: idx[1]].tolist()
        stim_spikes.extend(tmp_spikes)
    stim_spikes_x = sx(stim_spikes)
    stim_spikes_y = sy(stim_spikes)
    stim_in_field_indices = which_field(stim_spikes_x, stim_spikes_y, fields, box_size).astype(bool)
    
    in_between_spikes = []
    in_field_indices_in_between = []
    for i, t in enumerate(stim_times[:-1]):
        idx = np.searchsorted(spikes, [t + z1_between, stim_times[i + 1] - z2_between], side='right')
        tmp_spikes = spikes[idx[0]:idx[1]].tolist()
        in_between_spikes.extend(tmp_spikes)
    in_between_spikes_x = sx(in_between_spikes)
    in_between_spikes_y = sy(in_between_spikes)
    in_between_in_field_indices = which_field(in_between_spikes_x, in_between_spikes_y, fields, box_size).astype(bool)
    
        
    if plot:
        axs[0].imshow(
            fields.T.astype(bool), extent=[0, box_size[0], 0, box_size[1]], 
            origin='lower', cmap=plt.cm.Greys, zorder=0)
        axs[0].scatter(
            base_spikes_x[base_in_filed_indices], base_spikes_y[base_in_filed_indices], 
            s=dot_size, color='r', zorder=1)
        axs[0].scatter(
            base_spikes_x[~base_in_filed_indices], base_spikes_y[~base_in_filed_indices], 
            s=dot_size, color='b', zorder=1)
        axs[0].scatter(
            in_between_spikes_x, in_between_spikes_y,
            s=dot_size // 2, color='green', zorder=1)
        axs[0].scatter(
            stim_spikes_x, stim_spikes_y,
            s=dot_size // 2, color='y', zorder=1)
        # Display the image and plot all contours found
        contours = measure.find_contours(fields, 0.0)
        axs[1].imshow(rate_map.T, extent=[0, box_size[0], 0, box_size[1]], origin='lower')

        axs[2].plot(pos_x, pos_y, color='k', alpha=.2, zorder=0)
        axs[2].scatter(
            interp1d(pos_t, pos_x)(spikes), interp1d(pos_t, pos_y)(spikes), 
            s=dot_size, zorder=1)

        for ax in axs.ravel()[1:]:
            for n, contour in enumerate(contours):
                ax.plot(
                    contour[:, 0] * bin_size, contour[:, 1] * bin_size, 
                    lw=4, color='y', zorder=3)

        for ax in axs.ravel():
            ax.axis('image')
            ax.set_xticks([])
            ax.set_yticks([])
    return fields, base_in_filed_indices, in_between_in_field_indices, stim_in_field_indices
In [22]:
def plot_stim_field_spikes(row, t1=0, t2=30, z1_base=0, z2_base=5, z1_stim=5, z2_stim=11, colors=['k','r']):
    spikes, pos_x, pos_y, pos_t, rate_map, fields, stim_times = get_data(row)
    spikes = np.array(spikes) * 1000
    pos_t = np.array(pos_t) * 1000
    stim_times = np.array(stim_times) * 1000
    
    fig, axs = plt.subplots(1, 2)
    dot_size = 2
        
    sx, sy = interp1d(pos_t, pos_x), interp1d(pos_t, pos_y)
    
    stim_spikes_base = []
    stim_spikes_base_plot = []
    stim_ids_base = []
    stim_spikes_stim = []
    stim_spikes_stim_plot = []
    stim_ids_stim = []
    stim_ids_all = []
    stim_spikes_all = []
    for i, t in enumerate(stim_times):
        idx = np.searchsorted(spikes, [t + z1_base, t + z2_base], side='right')
        tmp_spikes = spikes[idx[0]: idx[1]] - t
        stim_ids_base.extend([i] * len(tmp_spikes))
        stim_spikes_base_plot.extend(tmp_spikes)
        stim_spikes_base.extend(spikes[idx[0]: idx[1]].tolist())
        
        idx = np.searchsorted(spikes, [t + z1_stim, t + z2_stim], side='right')
        tmp_spikes = spikes[idx[0]: idx[1]] - t
        stim_ids_stim.extend([i] * len(tmp_spikes))
        stim_spikes_stim_plot.extend(tmp_spikes)
        stim_spikes_stim.extend(spikes[idx[0]: idx[1]].tolist())
        
        idx = np.searchsorted(spikes, [t + t1, t + t2], side='right')
        tmp_spikes = (spikes[idx[0]: idx[1]] - t).tolist()
        stim_ids_all.extend([i] * len(tmp_spikes))
        stim_spikes_all.extend(tmp_spikes)
    
        
    stim_spikes_base_x = sx(stim_spikes_base)
    stim_spikes_base_y = sy(stim_spikes_base)
#     stim_in_field_indices_base = which_field(
#         stim_spikes_base_x, stim_spikes_base_y, fields, box_size).astype(bool)
    
    stim_spikes_stim_x = sx(stim_spikes_stim)
    stim_spikes_stim_y = sy(stim_spikes_stim)
#     stim_in_field_indices_stim = which_field(
#         stim_spikes_stim_x, stim_spikes_stim_y, fields, box_size).astype(bool)


    axs[0].scatter(stim_spikes_all, stim_ids_all, s=dot_size, color='k', alpha=.5)
    axs[0].scatter(stim_spikes_base_plot, stim_ids_base, s=dot_size, color=colors[0], alpha=.8)
    axs[0].scatter(stim_spikes_stim_plot, stim_ids_stim, s=dot_size, color=colors[1], alpha=.8)
    
    times = np.arange(t1, t2, .1)
    from scipy.stats import gaussian_kde
    kernel = gaussian_kde(stim_spikes_all, 0.1)
    pdf = kernel(times)
    m = max(stim_ids_all)
    pdf = (pdf - pdf.min()) / (pdf - pdf.min()).max() * m
    axs[0].plot(times, pdf, 'k', lw=1)
    axs[0].set_xlim(t1, t2)
#     ax.plot(0, len(trials) * 1.1, ls='none', marker='v', color='k', markersize=5)
#     axs[0].axvspan(0, 5, color='#43a2ca', alpha=.3, zorder=-5)

    contours = measure.find_contours(fields, 0.0)

    axs[1].scatter(
        stim_spikes_base_x, stim_spikes_base_y,
        s=dot_size, color=colors[0], zorder=1, alpha=.8)
    
    axs[1].scatter(
        stim_spikes_stim_x, stim_spikes_stim_y,
        s=dot_size, color=colors[1], zorder=1, alpha=.8)

    axs[1].plot(pos_x, pos_y, color='k', alpha=.2, zorder=0)

    for n, contour in enumerate(contours):
        axs[1].plot(
            contour[:, 0] * bin_size, contour[:, 1] * bin_size, 
            lw=1, color='k', zorder=3)
    axs[0].set_aspect((t2 - t1) / len(stim_times))
    axs[1].axis('image')
    axs[1].set_xticks([])
    axs[1].set_yticks([])
    despine(axs[0])
    despine(axs[1], left=True, bottom=True)
In [23]:
def plot_stim_field_spikes_in_between(row, t1=-20, t2=100, z1_base=-5, z2_base=5, z1_stim=5, z2_stim=11, z1_between=15, z2_between=5, 
                                      colors=['k','r', 'g']):
    from scipy.stats import gaussian_kde
    spikes, pos_x, pos_y, pos_t, rate_map, fields, stim_times = get_data(row)
    spikes = np.array(spikes) * 1000
    pos_t = np.array(pos_t) * 1000
    stim_times = np.array(stim_times) * 1000
    
    fig, axs = plt.subplots(1, 2)
    dot_size = 2
        
    sx, sy = interp1d(pos_t, pos_x), interp1d(pos_t, pos_y)
    
    stim_frequency = np.round(1 / np.median(np.diff(stim_times)) * 1000)
    print(f"Stim frequency = {stim_frequency}Hz")
    
    stim_spikes_base = []
    stim_spikes_base_plot = []
    stim_ids_base = []
    stim_spikes_stim = []
    stim_spikes_stim_plot = []
    stim_spikes_between = []
    stim_spikes_between_plot = []
    stim_ids_between = []
    stim_ids_stim = []
    stim_ids_all = []
    stim_spikes_all = []
    for i, t in enumerate(stim_times):
        idx = np.searchsorted(spikes, [t + z1_base, t + z2_base], side='right')
        tmp_spikes = spikes[idx[0]: idx[1]] - t
        stim_spikes_base.extend(spikes[idx[0]: idx[1]].tolist())
        stim_ids_base.extend([i] * len(tmp_spikes))
        stim_spikes_base_plot.extend(tmp_spikes)
        
        idx = np.searchsorted(spikes, [t + z1_stim, t + z2_stim], side='right')
        tmp_spikes = spikes[idx[0]: idx[1]] - t
        stim_spikes_stim.extend(spikes[idx[0]: idx[1]].tolist())
        stim_ids_stim.extend([i] * len(tmp_spikes))
        stim_spikes_stim_plot.extend(tmp_spikes)
            
        if i < len(stim_times) - 1:
            idx = np.searchsorted(spikes, [t + z1_between, stim_times[i + 1] - z2_between], side='right')
            tmp_spikes = spikes[idx[0]:idx[1]] - t
            stim_spikes_between.extend(spikes[idx[0]: idx[1]].tolist())
            stim_ids_between.extend([i] * len(tmp_spikes))
            stim_spikes_between_plot.extend(tmp_spikes)
            
        idx = np.searchsorted(spikes, [t + t1, t + t2], side='right')
        tmp_spikes = (spikes[idx[0]: idx[1]] - t).tolist()
        stim_ids_all.extend([i] * len(tmp_spikes))
        stim_spikes_all.extend(tmp_spikes)
        
        
    stim_spikes_base_x = sx(stim_spikes_base)
    stim_spikes_base_y = sy(stim_spikes_base)
#     stim_in_field_indices_base = which_field(
#         stim_spikes_base_x, stim_spikes_base_y, fields, box_size).astype(bool)
    
    stim_spikes_stim_x = sx(stim_spikes_stim)
    stim_spikes_stim_y = sy(stim_spikes_stim)
#     stim_in_field_indices_stim = which_field(
#         stim_spikes_stim_x, stim_spikes_stim_y, fields, box_size).astype(bool)

    stim_spikes_between_x = sx(stim_spikes_between)
    stim_spikes_between_y = sy(stim_spikes_between)

    if len(stim_spikes_all) > 10:

        axs[0].scatter(stim_spikes_all, stim_ids_all, s=dot_size, color='k', alpha=.5)
        axs[0].scatter(stim_spikes_base_plot, stim_ids_base, s=dot_size, color=colors[0], alpha=.8)
        axs[0].scatter(stim_spikes_stim_plot, stim_ids_stim, s=dot_size, color=colors[1], alpha=.8)
        axs[0].scatter(stim_spikes_between_plot, stim_ids_between, s=dot_size, color=colors[2], alpha=.8)

        axs[0].axvline(0, color="r")
        axs[0].axvline(1 / stim_frequency * 1000, color="r")

        times = np.arange(t1, t2, .1)
        kernel = gaussian_kde(stim_spikes_all, 0.1)
        pdf = kernel(times)
        m = max(stim_ids_all)
        pdf = (pdf - pdf.min()) / (pdf - pdf.min()).max() * m
        axs[0].plot(times, pdf, 'gray', lw=1.5)
        axs[0].set_xlim(t1, t2)
    #     ax.plot(0, len(trials) * 1.1, ls='none', marker='v', color='k', markersize=5)
    #     axs[0].axvspan(0, 5, color='#43a2ca', alpha=.3, zorder=-5)

        contours = measure.find_contours(fields, 0.0)

        axs[1].scatter(
            stim_spikes_between_x, stim_spikes_between_y,
            s=dot_size, color=colors[2], zorder=1, alpha=.8)
        
        axs[1].scatter(
            stim_spikes_base_x, stim_spikes_base_y,
            s=dot_size, color=colors[0], zorder=1, alpha=.8)

        axs[1].scatter(
            stim_spikes_stim_x, stim_spikes_stim_y,
            s=dot_size, color=colors[1], zorder=1, alpha=.8)


        axs[1].plot(pos_x, pos_y, color='k', alpha=.2, zorder=0)

        for n, contour in enumerate(contours):
            axs[1].plot(
                contour[:, 0] * bin_size, contour[:, 1] * bin_size, 
                lw=1, color='k', zorder=3)
        axs[0].set_aspect((t2 - t1) / len(stim_times))
        axs[1].axis('image')
        axs[1].set_xticks([])
        axs[1].set_yticks([])
        despine(axs[0])
        despine(axs[1], left=True, bottom=True)
    else:
        raise Exception(f"Too few spikes in selected stimulation: {len(stim_spikes_all)}")
In [39]:
spikes, pos_x, pos_y, pos_t, rate_map, fields, stim_times = get_data(stimulated_11.sort_values('gridness', ascending=False).iloc[1])
In [40]:
fields, in_field_indices, in_between_in_field_indices, stim_in_field_indices = compute_field_spikes_in_between(stimulated_11.sort_values('gridness', ascending=False).iloc[1], 
                                                                                                               z1_base=-5e-3, z2_base=5e-3, z1_stim=5e-3, z2_stim=11e-3,
                                                                                                               z1_between=15e-3, z2_between=5e-3, plot=True)
In [55]:
_ = compute_field_spikes(stimulated_11.sort_values('gridness', ascending=False).iloc[1], plot=True) #, z1=15e-3, z2=60e-3, plot=True)
In [307]:
_ = compute_field_spikes(baseline_i.sort_values('gridness', ascending=False).iloc[18], plot=True)
Out[307]:
(array([[9, 9, 9, ..., 6, 6, 6],
        [9, 9, 9, ..., 6, 6, 6],
        [0, 0, 0, ..., 6, 6, 6],
        ...,
        [0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0]], dtype=int32),
 array([False, False, False, ..., False, False, False]),
 [])
In [207]:
iter_base = baseline_i_sub.sort_values('unit_day', ascending=False).itertuples()
iter_stim = stimulated_11_sub.sort_values('unit_day', ascending=False).itertuples()
for row_base, row_stim in zip(iter_base, iter_stim):
    fields,_,_ = compute_field_spikes(row_base, plot=True)
    compute_field_spikes(row_stim, plot=True)#, surrogate_fields=fields)
/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/ipykernel_launcher.py:9: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  if __name__ == '__main__':
In [186]:
iter_base = baseline_i_sub.sort_values('unit_day', ascending=False).itertuples()
iter_stim = stimulated_11_sub.sort_values('unit_day', ascending=False).itertuples()
for row_base, row_stim in zip(iter_base, iter_stim):
    fields,_,_ = compute_field_spikes(row_base, plot=True)
    compute_field_spikes(row_stim, plot=True)#, surrogate_fields=fields)
/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/ipykernel_launcher.py:9: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  if __name__ == '__main__':

analysis stim vs stim

In [35]:
# alessio make new one qith both 11 and 30 and the right colors plus in between period
In [41]:
plt.rc('axes', titlesize=12)
plt.rcParams.update({
    'font.size': 12, 
    'figure.figsize': (5, 2), 
    'figure.dpi': 150
})

plot_stim_field_spikes(
    stimulated_11.sort_values('gridness', ascending=False).iloc[18],
    colors=['#2166ac', '#b2182b']#['#1b9e77','#d95f02']
)
fig = plt.gcf()
figname = 'stim_field_spikes_example'
fig.savefig(
    output_path / 'figures' / f'{figname}.png', 
    bbox_inches='tight', transparent=True)
fig.savefig(
    output_path / 'figures' / f'{figname}.svg', 
    bbox_inches='tight', transparent=True)
In [42]:
ilocs = range(10)
for iloc in ilocs:
    plot_stim_field_spikes_in_between(
        stimulated_11.sort_values('gridness', ascending=False).iloc[iloc],
        colors=['#1b9e77','#d95f02', 'C0'] #['#1b9e77','#d95f02']
    )
    fig = plt.gcf()    
    figname = f'stim_field_in_between_11Hz_example_{iloc}'
    fig.savefig(
        output_path / 'figures' / f'{figname}.png', 
        bbox_inches='tight', transparent=True)
    fig.savefig(
        output_path / 'figures' / f'{figname}.svg', 
        bbox_inches='tight', transparent=True)
Stim frequency = 11.0Hz
Stim frequency = 11.0Hz
Stim frequency = 11.0Hz
Stim frequency = 11.0Hz
Stim frequency = 11.0Hz
Stim frequency = 11.0Hz
Stim frequency = 11.0Hz
Stim frequency = 11.0Hz
Stim frequency = 11.0Hz
Stim frequency = 11.0Hz
In [43]:
ilocs = range(10)

for iloc in ilocs:
    plot_stim_field_spikes_in_between(
        stimulated_30.sort_values('gridness', ascending=False).iloc[iloc], t1=-10, t2=40, z1_between=20, 
        colors=['#7570b3', '#e7298a', 'C0'] #['#1b9e77','#d95f02']
    )
    fig = plt.gcf()
    figname = f'stim_field_in_between_30Hz_example_{iloc}'
    fig.savefig(
        output_path / 'figures' / f'{figname}.png', 
        bbox_inches='tight', transparent=True)
    fig.savefig(
        output_path / 'figures' / f'{figname}.svg', 
        bbox_inches='tight', transparent=True)
Stim frequency = 30.0Hz
Stim frequency = 30.0Hz
Stim frequency = 30.0Hz
Stim frequency = 30.0Hz
Stim frequency = 30.0Hz
Stim frequency = 30.0Hz
Stim frequency = 30.0Hz
Stim frequency = 30.0Hz
Stim frequency = 30.0Hz
Stim frequency = 30.0Hz
In [44]:
output_path.absolute()
Out[44]:
PosixPath('/home/mikkel/apps/expipe-project/septum-mec/notebooks/output/spikes-in-field-in-between')
In [65]:
results_stim_stim_11 = []
z1_in_between=15e-3
z2_in_between=5e-3
z1_base=-5e3
z2_base=5e-3
z1_stim=5e-3
z2_stim=11e-3
for row_stim in stimulated_11.itertuples():
    _, base_in_field, between_in_field, stim_in_field = compute_field_spikes_in_between(
        row_stim, z1_base=z1_base, z2_base=z2_base, z1_stim=z1_stim, z2_stim=z2_stim, z1_between=z1_in_between, z2_between=z2_in_between)
    
    results_stim_stim_11.append({
        'base_in_field': 1 - base_in_field.mean(),
        'inbetween_in_field': 1 - between_in_field.mean(),
        'stim_in_field': 1 - stim_in_field.mean(),
        'entity': row_stim.action.split('-')[0],
        'unit_idnum': row_stim.unit_idnum
    })
#     break
In [66]:
results_stim_stim_11 = pd.DataFrame(results_stim_stim_11)
results_stim_stim_11
Out[66]:
base_in_field inbetween_in_field stim_in_field entity unit_idnum
0 0.538621 0.534091 0.588235 1833 13
1 0.525788 0.484036 0.532093 1833 14
2 0.307987 0.274247 0.388792 1833 32
3 0.475376 0.500275 0.555294 1833 35
4 0.226625 0.229962 0.342569 1833 47
5 0.358304 0.337209 0.441860 1833 53
6 0.255657 0.269333 0.316288 1833 55
7 0.419704 0.425436 0.463719 1833 58
8 0.246073 0.247207 0.297101 1833 59
9 0.462419 0.485837 0.580769 1833 79
10 0.754226 0.795679 0.788756 1833 89
11 0.620610 0.582074 0.646545 1833 91
12 0.520780 0.537126 0.638956 1833 96
13 0.279928 0.293626 0.332192 1833 106
14 0.237982 0.148530 0.196532 1833 108
15 0.314800 0.281582 0.369403 1833 117
16 0.438741 0.390492 0.359195 1833 121
17 0.537018 0.561271 0.601518 1833 124
18 0.623832 0.545012 0.629842 1833 128
19 0.412175 0.433796 0.488651 1833 130
20 0.319736 0.273438 0.353147 1833 134
21 0.484081 0.410069 0.541608 1833 135
22 0.541792 0.528165 0.584600 1833 144
23 0.654292 0.572727 0.682283 1833 150
24 0.273552 0.226006 0.336066 1833 168
25 0.603217 0.584929 0.633227 1833 171
26 0.346849 0.255443 0.409681 1833 202
27 0.460233 0.449492 0.528596 1833 206
28 0.529359 0.505083 0.631447 1833 231
29 0.521979 0.486736 0.578132 1833 232
30 0.551782 0.506555 0.606518 1833 233
31 0.474096 0.438948 0.512640 1833 243
32 0.326791 0.260305 0.407634 1833 244
33 0.242545 0.259574 0.323232 1833 253
34 0.511671 0.458974 0.604046 1833 254
35 0.399191 0.329412 0.417722 1833 257
36 0.466224 0.419296 0.550383 1833 301
37 0.546959 0.538363 0.583713 1833 304
38 0.551041 0.513096 0.652083 1834 329
39 0.696740 0.658054 0.739712 1834 357
40 0.640325 0.525606 0.699267 1834 358
41 0.262972 0.293651 0.391960 1834 361
42 0.775069 0.729054 0.797188 1834 364
43 0.495020 0.458097 0.576505 1834 381
44 0.729418 0.714286 0.741722 1834 482
45 0.755861 0.748811 0.782228 1834 518
46 0.634988 0.616148 0.682730 1839 611
47 0.712878 0.710668 0.744382 1839 617
48 0.425311 0.370647 0.582278 1839 629
49 0.652087 0.633155 0.691063 1839 645
50 0.584628 0.578145 0.678867 1839 655
51 0.320308 0.313225 0.413793 1839 671
52 0.690461 0.662837 0.770170 1849 684
53 0.769904 0.764277 0.727273 1849 715
54 0.549757 0.569131 0.623261 1849 724
55 0.630057 0.597189 0.686826 1849 937
In [64]:
# results_stim_stim_30 = []
# z1_in_between=20e-3
# z2_in_between=5e-3
# z1_base=-5e3
# z2_base=5e-3
# for row_stim in stimulated_30.itertuples():
#     _, _, base_in_field = compute_field_spikes(
#         row_stim, z1=z1_base, z2=z2_base)
#     _, _, stim_in_field = compute_field_spikes_in_between(
#         row_stim, z1=z1_in_between, z2=z2_in_between)
    
#     results_stim_stim_30.append({
#         'base_in_field': 1 - base_in_field.mean(),
#         'inbetween_in_field': 1 - stim_in_field.mean()
#     })
# #     break
results_stim_stim_30 = []
z1_in_between=20e-3
z2_in_between=5e-3
z1_base=-5e3
z2_base=5e-3
z1_stim=5e-3
z2_stim=11e-3
for row_stim in stimulated_30.itertuples():
    _, base_in_field, between_in_field, stim_in_field = compute_field_spikes_in_between(
        row_stim, z1_base=z1_base, z2_base=z2_base, z1_stim=z1_stim, z2_stim=z2_stim, z1_between=z1_in_between, z2_between=z2_in_between)
    
    results_stim_stim_30.append({
        'base_in_field': 1 - base_in_field.mean(),
        'inbetween_in_field': 1 - between_in_field.mean(),
        'stim_in_field': 1 - stim_in_field.mean(),
        'entity': row_stim.action.split('-')[0],
        'unit_idnum': row_stim.unit_idnum
    })
#     break
In [67]:
results_stim_stim_30 = pd.DataFrame(results_stim_stim_30)
results_stim_stim_30
Out[67]:
base_in_field inbetween_in_field stim_in_field entity unit_idnum
0 0.444846 0.477273 0.528025 1833 13
1 0.517119 0.446341 0.571429 1833 26
2 0.413481 0.377129 0.466478 1833 31
3 0.245384 0.270227 0.273570 1833 32
4 0.372436 0.348007 0.426690 1833 35
5 0.559489 0.516060 0.536465 1833 61
6 0.400501 0.369239 0.433108 1833 63
7 0.420647 0.356589 0.421569 1833 86
8 0.566436 0.553785 0.599616 1833 149
9 0.301202 0.256545 0.357735 1833 168
10 0.608701 0.572282 0.655920 1833 195
11 0.409577 0.390977 0.461538 1833 210
12 0.600784 0.680995 0.569832 1833 218
13 0.287937 0.233418 0.328277 1833 234
14 0.468192 0.392283 0.560521 1833 240
15 0.614725 0.545455 0.692541 1833 248
16 0.624741 0.484749 0.649031 1833 249
17 0.255707 0.174373 0.310062 1833 253
18 0.460454 0.349338 0.510780 1833 260
19 0.686904 0.608847 0.736201 1833 261
20 0.715673 0.679295 0.723063 1833 263
21 0.436927 0.380165 0.472362 1833 274
22 0.595814 0.490600 0.699342 1833 275
23 0.582053 0.596002 0.621489 1833 304
24 0.556384 0.545745 0.522303 1834 332
25 0.644043 0.619522 0.648464 1834 360
26 0.588004 0.570416 0.543882 1834 381
27 0.556642 0.581395 0.400000 1839 577
28 0.327512 0.228571 0.321023 1839 629
29 0.532557 0.543478 0.579110 1839 655
30 0.406227 0.310078 0.383289 1839 656
31 0.638557 0.546961 0.636975 1839 659
32 0.361515 0.273469 0.378876 1839 660
33 0.666123 0.625796 0.675090 1849 724
34 0.550607 0.466667 0.553879 1849 835
In [68]:
results_stim_stim_all = pd.concat([results_stim_stim_11, results_stim_stim_30]).reset_index()
results_stim_stim_all
Out[68]:
index base_in_field inbetween_in_field stim_in_field entity unit_idnum
0 0 0.538621 0.534091 0.588235 1833 13
1 1 0.525788 0.484036 0.532093 1833 14
2 2 0.307987 0.274247 0.388792 1833 32
3 3 0.475376 0.500275 0.555294 1833 35
4 4 0.226625 0.229962 0.342569 1833 47
... ... ... ... ... ... ...
86 30 0.406227 0.310078 0.383289 1839 656
87 31 0.638557 0.546961 0.636975 1839 659
88 32 0.361515 0.273469 0.378876 1839 660
89 33 0.666123 0.625796 0.675090 1849 724
90 34 0.550607 0.466667 0.553879 1849 835

91 rows × 6 columns

In [69]:
np.max(results_stim_stim_all.inbetween_in_field)
Out[69]:
0.7956789240234654
In [70]:
output_path
Out[70]:
PosixPath('output/spikes-in-field-in-between')
In [52]:
def violinplot2(data, xticks, colors, fontsize=15, label_rotation=45):
    pos = [i * 0.6 for i in range(len(data))]
    violins = plt.violinplot(data, pos, showmeans=True, showextrema=False)
    
    for i, b in enumerate(violins['bodies']):
        b.set_color(colors[i])
        b.set_alpha (0.8)

 

    # for i, body in enumerate(violins['cbars']):
    #     body.set_color('C{}'.format(i))

 

    for category in ['cbars', 'cmins', 'cmaxes', 'cmedians', 'cmeans']:
        if category in violins:
            violins[category].set_color(['k', 'k'])
            violins[category].set_linewidth(2.0)
    plt.xticks(pos, xticks, rotation=label_rotation, fontsize=fontsize)
    plt.yticks(fontsize=fontsize)
    plt.gca().spines['top'].set_visible(False)
    plt.gca().spines['right'].set_visible(False)
In [53]:
plt.rc('axes', titlesize=12)
plt.rcParams.update({
    'font.size': 12, 
    'figure.figsize': (3.4, 6), 
    'figure.dpi': 150
})

# fig = plt.figure()
# violinplot(
#     results_stim_stim_all.base_in_field, 
#     results_stim_stim_all.stim_in_field, 
#     results_stim_stim_all.inbetween_in_field, 
#     colors=None,
#     xticks=["Baseline  ", "Stimulated",  "  Between"],
#     test='wilcoxon'
# )
# figname = 'stim_field_between_spikes_combined_3'
# fig.savefig(
#     output_path / 'figures' / f'{figname}.png', 
#     bbox_inches='tight', transparent=True)
# fig.savefig(
#     output_path / 'figures' / f'{figname}.svg', 
#     bbox_inches='tight', transparent=True)

# 11
fig = plt.figure()
violinplot2(
    [results_stim_stim_11.base_in_field, 
    results_stim_stim_11.stim_in_field, 
    results_stim_stim_11.inbetween_in_field],
    colors=['#1b9e77','#d95f02', "C0"],
    xticks=["Pre", "Resp",  "Between"],
    label_rotation=0,
#     test='wilcoxon'
)
figname = 'stim_field_between_spikes_11_3'
fig.savefig(
    output_path / 'figures' / f'{figname}.png', 
    bbox_inches='tight', transparent=True)
fig.savefig(
    output_path / 'figures' / f'{figname}.svg', 
    bbox_inches='tight', transparent=True)
    
# 30
fig = plt.figure()
violinplot2(
    [results_stim_stim_30.base_in_field,
    results_stim_stim_30.stim_in_field, 
    results_stim_stim_30.inbetween_in_field],
    colors=['#7570b3', '#e7298a', "C0"],
    xticks=["Pre", "Resp",  "Between"],
    label_rotation=0,
#     test='wilcoxon'
)
figname = 'stim_field_between_spikes_30_3'
fig.savefig(
    output_path / 'figures' / f'{figname}.png', 
    bbox_inches='tight', transparent=True)
fig.savefig(
    output_path / 'figures' / f'{figname}.svg', 
    bbox_inches='tight', transparent=True)
    
In [54]:
output_path.absolute()
Out[54]:
PosixPath('/home/mikkel/apps/expipe-project/septum-mec/notebooks/output/spikes-in-field-in-between')
In [78]:
results_all = {
    'Combined':results_stim_stim_all,
    '11 Hz': results_stim_stim_11,
    '30 Hz': results_stim_stim_30
}
In [98]:
stat, _ = make_statistics_table(results_all, ['base_in_field', 'inbetween_in_field', 'stim_in_field'])
In [99]:
stat
Out[99]:
Combined 11 hz 30 hz
base_in_field 5.6e-01 ± 1.5e-02 (91) 5.7e-01 ± 2.1e-02 (56) 5.4e-01 ± 1.9e-02 (35)
inbetween_in_field 5.2e-01 ± 1.6e-02 (91) 5.5e-01 ± 2.1e-02 (56) 4.9e-01 ± 2.2e-02 (35)
stim_in_field 5.9e-01 ± 1.5e-02 (91) 6.3e-01 ± 1.8e-02 (56) 5.4e-01 ± 1.9e-02 (35)
LMM base_in_field - inbetween_in_field $\rho$=-3.1e-02, p=1.7e-02 $\rho$=-2.4e-02, p=1.7e-03 $\rho$=-4.4e-02, p=1.5e-01**
LMM base_in_field - stim_in_field $\rho$=3.8e-02, p=1.2e-03 $\rho$=5.8e-02, p=3.3e-11 $\rho$=3.7e-03, p=8.4e-01
LMM inbetween_in_field - stim_in_field $\rho$=7.0e-02, p=4.8e-05 $\rho$=8.2e-02, p=2.1e-18 $\rho$=5.2e-02, p=2.8e-02
In [89]:
 stat.to_latex(output_path / "statistics" / "statistics_3.tex")
stat.to_csv(output_path / "statistics" / "statistics_3.csv")

save to expipe

In [83]:
action = project.require_action("spikes-in-field-between-stimulation")
In [84]:
copy_tree(output_path, str(action.data_path()))
Out[84]:
['/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/statistics/statistics_3.csv',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/statistics/statistics.tex',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/statistics/statistics.csv',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/statistics/statistics_3.tex',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/statistics/.ipynb_checkpoints/statistics-checkpoint.csv',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz_example_5.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_between_spikes_combined.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz_example_3.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz_example_5.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz_example_2.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz_example.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_between_spikes_30.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz_example_4.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz_example_4.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz_example_9.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz_example_9.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz_example_6.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz_example_2.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz_example_7.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz_example_1.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz_example_1.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_between_spikes_11_3.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_between_spikes_30_3.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz_example_3.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz_example_3.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz_example_9.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_spikes_example.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_between_spikes_combined.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_between_spikes_30.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz_example_2.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz_example_0.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz_example_8.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz_example_2.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz_example.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz_example_0.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_between_spikes_11.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz_example_7.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz_example_6.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz_example_3.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_spikes_example.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz_example_7.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz_example_0.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz_example_5.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_between_spikes_11_3.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz_example_4.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz_example_8.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz_example.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz_example_5.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz_example_0.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz_example_1.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz_example_7.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz_example_9.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz_example_8.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz_example_1.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz_example_8.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/.ipynb_checkpoints/stim_field_between_spikes_11-checkpoint.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/.ipynb_checkpoints/stim_field_between_spikes_11_3-checkpoint.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/.ipynb_checkpoints/stim_field_between_spikes_11-checkpoint.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/.ipynb_checkpoints/stim_field_between_spikes_combined-checkpoint.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/.ipynb_checkpoints/stim_field_between_spikes_30-checkpoint.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_30Hz_example_6.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_between_spikes_30_3.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz_example.svg',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz_example_4.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_between_spikes_11.png',
 '/media/storage/expipe/septum-mec/actions/spikes-in-field-between-stimulation/data/figures/stim_field_in_between_11Hz_example_6.png']
In [85]:
septum_mec.analysis.registration.store_notebook(action, "20_spikes_in_field-between.ipynb")
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-85-cfc9a5bf132f> in <module>
----> 1 septum_mec.analysis.registration.store_notebook(action, "20_spikes_in_field-between.ipynb")

~/apps/expipe-project/septum-mec/septum_mec/analysis/registration.py in store_notebook(action, notebook_path)
      7     action.data["notebook"] = notebook_path.name
      8     notebook_output_path = action.data_path('notebook')
----> 9     shutil.copy(notebook_path, notebook_output_path)
     10     # As HTML
     11     os.system('jupyter nbconvert --to html {}'.format(notebook_path))

~/.virtualenvs/expipe/lib/python3.6/shutil.py in copy(src, dst, follow_symlinks)
    243     if os.path.isdir(dst):
    244         dst = os.path.join(dst, os.path.basename(src))
--> 245     copyfile(src, dst, follow_symlinks=follow_symlinks)
    246     copymode(src, dst, follow_symlinks=follow_symlinks)
    247     return dst

~/.virtualenvs/expipe/lib/python3.6/shutil.py in copyfile(src, dst, follow_symlinks)
    118         os.symlink(os.readlink(src), dst)
    119     else:
--> 120         with open(src, 'rb') as fsrc:
    121             with open(dst, 'wb') as fdst:
    122                 copyfileobj(fsrc, fdst)

FileNotFoundError: [Errno 2] No such file or directory: '20_spikes_in_field-between.ipynb'
In [ ]: