method
This commit is contained in:
parent
bf0fb6025b
commit
6fdf60f69e
@ -8,7 +8,7 @@ from IPython import embed
|
||||
# define sampling rate and data path
|
||||
sampling_rate = 40 #kHz
|
||||
data_dir = "../data"
|
||||
dataset = "2018-11-14-aa-invivo-1"
|
||||
dataset = "2018-11-14-ad-invivo-1"
|
||||
#data = ("2018-11-09-ad-invivo-1", "2018-11-09-ae-invivo-1", "2018-11-09-ag-invivo-1", "2018-11-13-aa-invivo-1",\
|
||||
# "2018-11-13-ac-invivo-1", "2018-11-13-ad-invivo-1", "2018-11-13-ah-invivo-1", "2018-11-13-ai-invivo-1", \
|
||||
# "2018-11-13-aj-invivo-1", "2018-11-13-ak-invivo-1", "2018-11-13-al-invivo-1", "2018-11-14-aa-invivo-1", \
|
||||
@ -18,28 +18,29 @@ dataset = "2018-11-14-aa-invivo-1"
|
||||
# "2018-11-20-af-invivo-1", "2018-11-20-ag-invivo-1", "2018-11-20-ah-invivo-1", "2018-11-20-ai-invivo-1")
|
||||
|
||||
# parameters for binning, smoothing and plotting
|
||||
#cut_window = 60
|
||||
cut_window = 20
|
||||
chirp_size = 14 #ms
|
||||
#cut_window_csi = 20 #ms
|
||||
#cut_window_plot = 50 #ms
|
||||
chirp_duration = 14 #ms
|
||||
neuronal_delay = 5 #ms
|
||||
chirp_start = int((-chirp_size/2+neuronal_delay+cut_window)*sampling_rate)
|
||||
chirp_end = int((chirp_size/2+neuronal_delay+cut_window)*sampling_rate)
|
||||
num_bin = 12
|
||||
chirp_start = int((-chirp_duration / 2 + neuronal_delay + cut_window * 2) * sampling_rate) #index
|
||||
chirp_end = int((chirp_duration / 2 + neuronal_delay + cut_window * 2) * sampling_rate) #index
|
||||
number_bins = 12
|
||||
window = 1 #ms
|
||||
time_axis = np.arange(-cut_window, cut_window, 1/sampling_rate) #steps
|
||||
spike_bins = np.arange(-cut_window, cut_window+1) #ms
|
||||
time_axis = np.arange(-cut_window*2, cut_window*2, 1/sampling_rate) #steps
|
||||
spike_bins = np.arange(-cut_window*2, cut_window*2) #ms
|
||||
|
||||
# read data from files
|
||||
spikes = read_chirp_spikes(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))
|
||||
#eod = read_chirp_eod(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 = map_keys(spikes)
|
||||
|
||||
# differentiate between phases
|
||||
phase_vec = np.arange(0, 1+1/num_bin, 1/num_bin)
|
||||
cut_range = np.arange(-cut_window*sampling_rate, cut_window*sampling_rate, 1)
|
||||
phase_vec = np.arange(0, 1 + 1 / number_bins, 1 / number_bins)
|
||||
cut_range = np.arange(-cut_window*2*sampling_rate, cut_window*2*sampling_rate, 1)
|
||||
|
||||
# make dictionaries for spiketimes
|
||||
df_phase_time = {}
|
||||
@ -52,14 +53,18 @@ for deltaf in df_map.keys():
|
||||
df_phase_time[deltaf] = {}
|
||||
df_phase_binary[deltaf] = {}
|
||||
for rep in df_map[deltaf]:
|
||||
chirp_size = int(rep[-1].strip('Hz'))
|
||||
#print(chirp_size)
|
||||
if chirp_size == 150:
|
||||
continue
|
||||
for phase in spikes[rep]:
|
||||
for idx in np.arange(num_bin):
|
||||
for idx in np.arange(number_bins):
|
||||
# check the phase
|
||||
if phase[1] > phase_vec[idx] and phase[1] < phase_vec[idx+1]:
|
||||
|
||||
# get spikes between 50 ms before and after the chirp
|
||||
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 > -cut_window*2) & (spikes_to_cut < cut_window*2)]
|
||||
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
|
||||
@ -80,27 +85,32 @@ csi_rates = {}
|
||||
for df in df_phase_time.keys():
|
||||
csi_trains[df] = []
|
||||
csi_rates[df] = []
|
||||
beat_duration = int(abs(1/df*1000)) #ms
|
||||
beat_duration = int(abs(1/df*1000)*sampling_rate) #steps
|
||||
beat_window = 0
|
||||
while beat_window+beat_duration <= cut_window:
|
||||
# beat window is at most 20 ms long, multiples of beat_duration
|
||||
while beat_window+beat_duration <= cut_window*sampling_rate:
|
||||
beat_window = beat_window+beat_duration
|
||||
for phase in df_phase_time[df].keys():
|
||||
|
||||
# csi calculation
|
||||
# trains for synchronity and rate
|
||||
|
||||
# trains for synchrony and rate
|
||||
trials_binary = df_phase_binary[df][phase]
|
||||
|
||||
train_chirp = []
|
||||
train_beat = []
|
||||
spikerate_chirp = np.zeros(len(trials_binary))
|
||||
spikerate_beat = np.zeros(len(trials_binary))
|
||||
#csi_spikerate = []
|
||||
for i, trial in enumerate(trials_binary):
|
||||
smoothed_trial = smooth(trial, window, 1/sampling_rate)
|
||||
train_chirp.append(smoothed_trial[chirp_start:chirp_end])
|
||||
train_beat.append(smoothed_trial[chirp_start-beat_window:chirp_start])
|
||||
spikerate_chirp[i] = np.mean(smoothed_trial[chirp_start:chirp_end])
|
||||
spikerate_beat[i] = np.mean(smoothed_trial[chirp_start-beat_window:chirp_start])
|
||||
#std_chirp = np.std(smoothed_trial[chirp_start:chirp_end])
|
||||
#std_beat = np.std(smoothed_trial[chirp_start-beat_window:chirp_start])
|
||||
#csi = (std_chirp - std_beat)/(std_chirp + std_beat)
|
||||
#csi_spikerate.append(csi)
|
||||
|
||||
std_chirp = np.std(np.mean(train_chirp, axis=0))
|
||||
std_beat = np.std(np.mean(train_beat, axis=0))
|
||||
csi_spikerate = (std_chirp - std_beat) / (std_chirp + std_beat)
|
||||
|
||||
rcs = []
|
||||
rbs = []
|
||||
@ -116,20 +126,12 @@ for df in df_phase_time.keys():
|
||||
|
||||
r_train_chirp = np.mean(rcs)
|
||||
r_train_beat = np.mean(rbs)
|
||||
embed()
|
||||
exit()
|
||||
|
||||
csi_train = (r_train_chirp - r_train_beat) / (r_train_chirp + r_train_beat)
|
||||
csi_rate = (np.std(spikerate_chirp) - np.std(spikerate_beat)) / (np.std(spikerate_chirp) + np.std(spikerate_beat))
|
||||
|
||||
# add the csi to the dictionaries with the correct df and phase
|
||||
#csi_trains[df][phase] = csi_train
|
||||
#csi_rates[df][phase] = csi_rate
|
||||
|
||||
csi_trains[df].append(csi_train)
|
||||
csi_rates[df].append(csi_rate)
|
||||
|
||||
#csi_trains[df].append(abs(csi_train))
|
||||
#csi_rates[df].append(abs(csi_rate))
|
||||
csi_rates[df].append(np.mean(csi_spikerate))
|
||||
|
||||
'''
|
||||
# plot
|
||||
@ -173,3 +175,13 @@ ax.plot(np.arange(-1, len(csi_trains.keys())+1), np.zeros(len(csi_trains.keys())
|
||||
#ax.set_xticklabels(sorted(csi_trains.keys()))
|
||||
fig.tight_layout()
|
||||
plt.show()
|
||||
|
||||
# spikerate_chirp = np.zeros(len(trials_binary))
|
||||
# spikerate_beat = np.zeros(len(trials_binary))
|
||||
# csi_trains[df][phase] = csi_train
|
||||
# csi_rates[df][phase] = csi_rate
|
||||
# csi_trains[df].append(abs(csi_train))
|
||||
# csi_rates[df].append(abs(csi_rate))
|
||||
#csi_rate = (np.std(spikerate_chirp) - np.std(spikerate_beat)) / (np.std(spikerate_chirp) + np.std(spikerate_beat))
|
||||
# spikerate_chirp[i] = np.mean(smoothed_trial[chirp_start:chirp_end])
|
||||
# spikerate_beat[i] = np.mean(smoothed_trial[chirp_start-beat_window:chirp_start])
|
47
code/stimulus_chirp.py
Normal file
47
code/stimulus_chirp.py
Normal file
@ -0,0 +1,47 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
stimulusrate = 500. # the eod frequency of the fake fish
|
||||
currentchirptimes = [0.1]
|
||||
chirpwidth = 0.05 # ms
|
||||
chirpsize = 100.
|
||||
chirpampl = 0.02
|
||||
chirpkurtosis = 1.
|
||||
p = 0.
|
||||
stepsize = 0.00001
|
||||
|
||||
time = np.arange(0.0, 0.2, stepsize)
|
||||
signal = np.zeros(time.shape)
|
||||
ampl = np.ones(time.shape)
|
||||
freq = np.ones(time.shape)
|
||||
|
||||
ck = 0
|
||||
csig = 0.5 * chirpwidth / np.power(2.0*np.log(10.0), 0.5/chirpkurtosis)
|
||||
|
||||
for k, t in enumerate(time):
|
||||
a = 1.
|
||||
f = stimulusrate
|
||||
if ck < len(currentchirptimes):
|
||||
if np.abs(t - currentchirptimes[ck]) < 2.0 * chirpwidth:
|
||||
x = t - currentchirptimes[ck]
|
||||
g = np.exp(-0.5 * (x/csig)**2)
|
||||
f = chirpsize * g + stimulusrate
|
||||
a *= 1.0 - chirpampl * g
|
||||
elif t > currentchirptimes[ck] + 2.0 * chirpwidth:
|
||||
ck += 1
|
||||
freq[k] = f
|
||||
ampl[k] = a
|
||||
p += f * stepsize
|
||||
signal[k] = a * np.sin(6.28318530717959 * p)
|
||||
|
||||
fig = plt.figure()
|
||||
ax1 = fig.add_subplot(211)
|
||||
ax2 = fig.add_subplot(212)
|
||||
|
||||
ax1.plot(time, signal)
|
||||
ax2.plot(time, freq)
|
||||
|
||||
ax1.set_ylabel("fake fish field [rel]")
|
||||
ax2.set_xlabel("time [s]")
|
||||
ax2.set_ylabel("frequency [Hz]")
|
||||
plt.show()
|
Loading…
Reference in New Issue
Block a user