63 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			63 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
import matplotlib.pyplot as plt
 | 
						|
import numpy as np
 | 
						|
from read_chirp_data import *
 | 
						|
from read_baseline_data import *
 | 
						|
from utility import *
 | 
						|
from IPython import embed
 | 
						|
 | 
						|
# define data path and important parameters
 | 
						|
data_dir = "../data"
 | 
						|
sampling_rate = 40 #kHz
 | 
						|
cut_window = 100
 | 
						|
cut_range = np.arange(-cut_window * sampling_rate, 0, 1)
 | 
						|
window = 1
 | 
						|
#dataset = "2018-11-13-ad-invivo-1"
 | 
						|
#dataset = "2018-11-13-aj-invivo-1"
 | 
						|
#dataset = "2018-11-13-ak-invivo-1" #al
 | 
						|
#dataset = "2018-11-14-ad-invivo-1"
 | 
						|
dataset = "2018-11-20-af-invivo-1"
 | 
						|
 | 
						|
base_spikes = read_baseline_spikes(os.path.join(data_dir, dataset))
 | 
						|
base_spikes = base_spikes[1000:2000]
 | 
						|
spikerate = len(base_spikes) / base_spikes[-1]
 | 
						|
print(spikerate)
 | 
						|
 | 
						|
# read spikes during chirp stimulation
 | 
						|
spikes = read_chirp_spikes(os.path.join(data_dir, dataset))
 | 
						|
df_map = map_keys(spikes)
 | 
						|
 | 
						|
rates = {}
 | 
						|
# iterate over df
 | 
						|
for deltaf in df_map.keys():
 | 
						|
    rates[deltaf] = {}
 | 
						|
    beat_duration = int(abs(1 / deltaf) * 1000)
 | 
						|
    beat_window = 0
 | 
						|
    while beat_window + beat_duration <= cut_window/2:
 | 
						|
        beat_window = beat_window + beat_duration
 | 
						|
    for x, repetition in enumerate(df_map[deltaf]):
 | 
						|
        for phase in spikes[repetition]:
 | 
						|
            # get spikes some ms before the chirp first chirp
 | 
						|
            spikes_to_cut = np.asarray(spikes[repetition][phase])
 | 
						|
            spikes_cut = spikes_to_cut[(spikes_to_cut > -cut_window) & (spikes_to_cut < 0)]
 | 
						|
            spikes_idx = np.round(spikes_cut * sampling_rate)
 | 
						|
            # also save as binary, 0 no spike, 1 spike
 | 
						|
            binary_spikes = np.isin(cut_range, spikes_idx) * 1
 | 
						|
            smoothed_data = smooth(binary_spikes, window, 1 / sampling_rate)
 | 
						|
            #train = smoothed_data[window*sampling_rate:beat_window*sampling_rate+window*sampling_rate]
 | 
						|
            modulation = np.std(smoothed_data)
 | 
						|
            rates[deltaf][x] = modulation
 | 
						|
            break
 | 
						|
 | 
						|
fig, ax = plt.subplots()
 | 
						|
for i, df in enumerate(sorted(rates.keys())):
 | 
						|
    for j, rep in enumerate(rates[df].keys()):
 | 
						|
        if j == 15:
 | 
						|
            farbe = 'royalblue'
 | 
						|
            gro = 18
 | 
						|
        else:
 | 
						|
            farbe = 'k'
 | 
						|
            gro = 12
 | 
						|
        ax.plot(df, rates[df][rep], marker='o', color=farbe, ms=gro)
 | 
						|
fig.tight_layout()
 | 
						|
plt.show()
 |