Merge branch 'master' of https://whale.am28.uni-tuebingen.de/git/jgrewe/gp_neurobio
This commit is contained in:
commit
da8f7237af
@ -1,5 +1,7 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import os
|
import os
|
||||||
|
import nixio as nix
|
||||||
|
from IPython import embed
|
||||||
|
|
||||||
|
|
||||||
def read_chirp_spikes(dataset):
|
def read_chirp_spikes(dataset):
|
||||||
@ -85,10 +87,37 @@ def read_chirp_times(dataset):
|
|||||||
return chirp_times
|
return chirp_times
|
||||||
|
|
||||||
|
|
||||||
|
def read_chirp_stimulus(dataset):
|
||||||
|
base = dataset.split(os.path.sep)[-1] + ".nix"
|
||||||
|
nix_file = nix.File.open(os.path.join(dataset, base), nix.FileMode.ReadOnly)
|
||||||
|
b = nix_file.blocks[0]
|
||||||
|
data = {}
|
||||||
|
for t in b.tags:
|
||||||
|
if "Chirps" in t.name:
|
||||||
|
stims = []
|
||||||
|
index = int(t.name.split("_")[-1])
|
||||||
|
df = t.metadata["RePro-Info"]["settings"]["deltaf"]
|
||||||
|
cs = t.metadata["RePro-Info"]["settings"]["chirpsize"]
|
||||||
|
stim_da = t.references["GlobalEFieldStimulus"]
|
||||||
|
si = stim_da.dimensions[0].sampling_interval
|
||||||
|
for mt in b.multi_tags:
|
||||||
|
if mt.positions[0] >= t.position[0] and \
|
||||||
|
mt.positions[0] < (t.position[0] + t.extent[0]):
|
||||||
|
break
|
||||||
|
for i in range(len(mt.positions)):
|
||||||
|
start_index = int(mt.positions[i] / si)
|
||||||
|
end_index = int((mt.positions[i] + mt.extents[i]) / si) - 1
|
||||||
|
stim = stim_da[start_index:end_index]
|
||||||
|
time = stim_da.dimensions[0].axis(len(stim)) + mt.positions[i]
|
||||||
|
stims.append((time, stim))
|
||||||
|
data[(index, df, cs)] = stims
|
||||||
|
nix_file.close()
|
||||||
|
return data
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
data_dir = "../data"
|
data_dir = "../data"
|
||||||
dataset = "2018-11-09-ad-invivo-1"
|
dataset = "2018-11-20-ad-invivo-1"
|
||||||
spikes = load_chirp_spikes(os.path.join(data_dir, dataset))
|
#spikes = load_chirp_spikes(os.path.join(data_dir, dataset))
|
||||||
chirp_times = load_chirp_times(os.path.join(data_dir, dataset))
|
#chirp_times = load_chirp_times(os.path.join(data_dir, dataset))
|
||||||
chirp_eod = load_chirp_eod(os.path.join(data_dir, dataset))
|
#chirp_eod = load_chirp_eod(os.path.join(data_dir, dataset))
|
||||||
|
stim = read_chirp_stimulus(os.path.join(data_dir, dataset))
|
||||||
|
@ -4,14 +4,21 @@ from read_chirp_data import *
|
|||||||
from utility import *
|
from utility import *
|
||||||
from IPython import embed
|
from IPython import embed
|
||||||
|
|
||||||
|
# define sampling rate and data path
|
||||||
sampling_rate = 40 #kHz
|
sampling_rate = 40 #kHz
|
||||||
data_dir = "../data"
|
data_dir = "../data"
|
||||||
dataset = "2018-11-09-ad-invivo-1"
|
dataset = "2018-11-09-ad-invivo-1"
|
||||||
|
# parameters for binning, smoothing and plotting
|
||||||
|
num_bin = 12
|
||||||
|
window = sampling_rate
|
||||||
|
time_axis = np.arange(-50, 50, 1/sampling_rate)
|
||||||
|
|
||||||
|
# read data from files
|
||||||
spikes = read_chirp_spikes(os.path.join(data_dir, dataset))
|
spikes = read_chirp_spikes(os.path.join(data_dir, dataset))
|
||||||
eod = read_chirp_eod(os.path.join(data_dir, dataset))
|
eod = read_chirp_eod(os.path.join(data_dir, dataset))
|
||||||
chirp_times = read_chirp_times(os.path.join(data_dir, dataset))
|
chirp_times = read_chirp_times(os.path.join(data_dir, dataset))
|
||||||
|
|
||||||
|
# make a delta f map for the quite more complicated keys
|
||||||
df_map = {}
|
df_map = {}
|
||||||
for k in spikes.keys():
|
for k in spikes.keys():
|
||||||
df = k[1]
|
df = k[1]
|
||||||
@ -20,61 +27,55 @@ for k in spikes.keys():
|
|||||||
else:
|
else:
|
||||||
df_map[df] = [k]
|
df_map[df] = [k]
|
||||||
|
|
||||||
# make phases together, 12 phases
|
# differentiate between phases
|
||||||
phase_vec = np.arange(0, 1+1/12, 1/12)
|
phase_vec = np.arange(0, 1+1/num_bin, 1/num_bin)
|
||||||
cut_range = np.arange(-50*sampling_rate, 50*sampling_rate, 1)
|
cut_range = np.arange(-50*sampling_rate, 50*sampling_rate, 1)
|
||||||
|
|
||||||
|
# make dictionaries for spiketimes
|
||||||
df_phase_time = {}
|
df_phase_time = {}
|
||||||
df_phase_binary = {}
|
df_phase_binary = {}
|
||||||
|
|
||||||
|
# iterate over delta f, repetition, phases and a single chirp
|
||||||
for deltaf in df_map.keys():
|
for deltaf in df_map.keys():
|
||||||
df_phase_time[deltaf] = {}
|
df_phase_time[deltaf] = {}
|
||||||
df_phase_binary[deltaf] = {}
|
df_phase_binary[deltaf] = {}
|
||||||
for rep in df_map[deltaf]:
|
for rep in df_map[deltaf]:
|
||||||
for phase in spikes[rep]:
|
for phase in spikes[rep]:
|
||||||
#print(phase)
|
for idx in np.arange(num_bin):
|
||||||
for idx in range(len(phase_vec)-1):
|
# check the phase
|
||||||
if phase[1] > phase_vec[idx] and phase[1] < phase_vec[idx+1]:
|
if phase[1] > phase_vec[idx] and phase[1] < phase_vec[idx+1]:
|
||||||
|
|
||||||
|
# get spikes between 50 ms befor and after the chirp
|
||||||
spikes_to_cut = np.asarray(spikes[rep][phase])
|
spikes_to_cut = np.asarray(spikes[rep][phase])
|
||||||
spikes_cut = spikes_to_cut[(spikes_to_cut > -50) & (spikes_to_cut < 50)]
|
spikes_cut = spikes_to_cut[(spikes_to_cut > -50) & (spikes_to_cut < 50)]
|
||||||
spikes_idx = np.round(spikes_cut*sampling_rate)
|
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
|
binary_spikes = np.isin(cut_range, spikes_idx)*1
|
||||||
|
|
||||||
if phase_vec[idx] in df_phase_time[deltaf].keys():
|
# add the spikes to the dictionaries with the correct df and phase
|
||||||
df_phase_time[deltaf][phase_vec[idx]].append(spikes[rep][phase])
|
if idx in df_phase_time[deltaf].keys():
|
||||||
df_phase_binary[deltaf][phase_vec[idx]] = np.vstack((df_phase_binary[deltaf][phase_vec[idx]], binary_spikes))
|
df_phase_time[deltaf][idx].append(spikes_cut)
|
||||||
|
df_phase_binary[deltaf][idx] = np.vstack((df_phase_binary[deltaf][idx], binary_spikes))
|
||||||
else:
|
else:
|
||||||
df_phase_time[deltaf][phase_vec[idx]] = [spikes[rep][phase]]
|
df_phase_time[deltaf][idx] = [spikes_cut]
|
||||||
df_phase_binary[deltaf][phase_vec[idx]] = binary_spikes
|
df_phase_binary[deltaf][idx] = binary_spikes
|
||||||
|
|
||||||
|
# for plotting iterate over delta f and phases
|
||||||
|
for df in df_phase_time.keys():
|
||||||
|
for phase in df_phase_time[df].keys():
|
||||||
|
plot_trials = df_phase_time[df][phase]
|
||||||
|
plot_trials_binary = np.mean(df_phase_binary[df][phase], axis=0)
|
||||||
|
|
||||||
plot_trials = df_phase_binary['-50Hz'][0.0]
|
smoothed_spikes = smooth(plot_trials_binary, window)
|
||||||
#hist_data = plt.hist(plot_trials)
|
|
||||||
#ax.plot(hist_data[1][:-1], hist_data[0])
|
|
||||||
|
|
||||||
fig, ax = plt.subplots()
|
fig, ax = plt.subplots(2, 1)
|
||||||
for i, trial in enumerate(plot_trials):
|
for i, trial in enumerate(plot_trials):
|
||||||
embed()
|
ax[0].scatter(trial, np.ones(len(trial))+i, marker='|', color='k')
|
||||||
exit()
|
ax[1].plot(time_axis, smoothed_spikes)
|
||||||
trial[trial == 0] = np.nan
|
|
||||||
ax.scatter(np.ones(len(trial)), trial, marker='|', color='k', size=12)
|
|
||||||
plt.show()
|
|
||||||
|
|
||||||
|
ax[0].set_title(df)
|
||||||
|
ax[0].set_ylabel('repetition', fontsize=12)
|
||||||
|
|
||||||
#mu = 1
|
ax[1].set_xlabel('time [ms]', fontsize=12)
|
||||||
#sigma = 1
|
ax[1].set_ylabel('firing rate [?]', fontsize=12)
|
||||||
#time_gauss = np.arange(-4, 4, 1)
|
plt.show()
|
||||||
#gauss = gaussian(time_gauss, mu, sigma)
|
|
||||||
# spikes during time vec (00010000001)?
|
|
||||||
|
|
||||||
#smoothed_spikes = np.convolve(plot_spikes, gauss, 'same')
|
|
||||||
#window = np.mean(np.diff(plot_spikes))
|
|
||||||
#time_vec = np.arange(plot_spikes[0], plot_spikes[-1]+window, window)
|
|
||||||
|
|
||||||
#ax.plot(time_vec, smoothed_spikes)
|
|
||||||
|
|
||||||
#embed()
|
|
||||||
#exit()
|
|
||||||
#hist_data = plt.hist(plot_spikes, bins=np.arange(-200, 400, 20))
|
|
||||||
#ax.plot(hist_data[1][:-1], hist_data[0])
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
from IPython import embed
|
||||||
|
|
||||||
|
|
||||||
def zero_crossing(eod, time):
|
def zero_crossing(eod, time):
|
||||||
@ -23,6 +24,17 @@ def gaussian(x, mu, sig):
|
|||||||
y = np.exp(-np.power(x - mu, 2.) / (2 * np.power(sig, 2.)))
|
y = np.exp(-np.power(x - mu, 2.) / (2 * np.power(sig, 2.)))
|
||||||
return y
|
return y
|
||||||
|
|
||||||
|
|
||||||
|
def smooth(data, window):
|
||||||
|
mu = 1
|
||||||
|
sigma = window
|
||||||
|
time_gauss = np.arange(-4 * sigma, 4 * sigma, 1)
|
||||||
|
gauss = gaussian(time_gauss, mu, sigma)
|
||||||
|
gauss_norm = gauss/(np.sum(gauss)/len(gauss))
|
||||||
|
smoothed_data = np.convolve(data, gauss_norm, 'same')
|
||||||
|
return smoothed_data
|
||||||
|
|
||||||
|
|
||||||
def map_keys(input):
|
def map_keys(input):
|
||||||
df_map = {}
|
df_map = {}
|
||||||
for k in input.keys():
|
for k in input.keys():
|
||||||
|
Loading…
Reference in New Issue
Block a user