08.07 analysis step_stimulus not perfect, but works
This commit is contained in:
parent
85a4b51680
commit
f80f6b7583
@ -73,7 +73,7 @@ def parse_infodataset(dataset_name):
|
|||||||
identifier.append((l.split(':')[-1].strip()[1:12]))
|
identifier.append((l.split(':')[-1].strip()[1:12]))
|
||||||
return identifier
|
return identifier
|
||||||
|
|
||||||
def mean_loops(start, stop, timespan, frequencies, time):
|
def mean_traces(start, stop, timespan, frequencies, time):
|
||||||
minimumt = min(len(time[0]), len(time[1]))
|
minimumt = min(len(time[0]), len(time[1]))
|
||||||
# new time with wished timespan because it varies for different loops
|
# new time with wished timespan because it varies for different loops
|
||||||
tnew = np.arange(start, stop, timespan / minimumt) # 3rd input is stepspacing:
|
tnew = np.arange(start, stop, timespan / minimumt) # 3rd input is stepspacing:
|
||||||
@ -139,6 +139,13 @@ def JAR_eod(frequencies, time, offset_point):
|
|||||||
|
|
||||||
return jar_eod
|
return jar_eod
|
||||||
|
|
||||||
|
def sort_values(values):
|
||||||
|
a = values[:2]
|
||||||
|
tau = np.array(sorted(values[2:], reverse=False))
|
||||||
|
values = np.array([a, tau])
|
||||||
|
values_flat = values.flatten()
|
||||||
|
return values_flat
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,10 +7,11 @@ from IPython import embed
|
|||||||
from scipy.optimize import curve_fit
|
from scipy.optimize import curve_fit
|
||||||
from jar_functions import parse_dataset
|
from jar_functions import parse_dataset
|
||||||
from jar_functions import parse_infodataset
|
from jar_functions import parse_infodataset
|
||||||
from jar_functions import mean_loops
|
from jar_functions import mean_traces
|
||||||
from jar_functions import mean_noise_cut
|
from jar_functions import mean_noise_cut
|
||||||
from jar_functions import norm_function
|
from jar_functions import norm_function
|
||||||
from jar_functions import step_response
|
from jar_functions import step_response
|
||||||
|
from jar_functions import sort_values
|
||||||
|
|
||||||
#nicht: 19-aa, 22-ae, 22-ad (?)
|
#nicht: 19-aa, 22-ae, 22-ad (?)
|
||||||
datasets = [#(os.path.join('D:\\jar_project\\JAR\\2020-06-19-aa\\beats-eod.dat')), #-5Hz delta f, horrible fit
|
datasets = [#(os.path.join('D:\\jar_project\\JAR\\2020-06-19-aa\\beats-eod.dat')), #-5Hz delta f, horrible fit
|
||||||
@ -31,9 +32,6 @@ infodatasets = [(os.path.join('D:\\jar_project\\JAR\\2020-06-22-ac\\info.dat')),
|
|||||||
time_all = []
|
time_all = []
|
||||||
freq_all = []
|
freq_all = []
|
||||||
|
|
||||||
constant_factors = []
|
|
||||||
time_constants = []
|
|
||||||
|
|
||||||
ID = []
|
ID = []
|
||||||
|
|
||||||
for infodataset in infodatasets:
|
for infodataset in infodatasets:
|
||||||
@ -48,9 +46,9 @@ for dataset in datasets:
|
|||||||
dm = np.mean(duration)
|
dm = np.mean(duration)
|
||||||
pm = np.mean(pause)
|
pm = np.mean(pause)
|
||||||
timespan = dm + pm
|
timespan = dm + pm
|
||||||
start = -10
|
start = (time[0][0] + time[1][0]) / 2
|
||||||
stop = 200
|
stop = (time[0][-1] + time[1][-1]) / 2
|
||||||
mf , tnew = mean_loops(start, stop, timespan, frequency, time)
|
mf , tnew = mean_traces(start, stop, timespan, frequency, time) # maybe fixed timespan/sampling rate
|
||||||
|
|
||||||
#for i in range(len(mf)):
|
#for i in range(len(mf)):
|
||||||
|
|
||||||
@ -64,34 +62,40 @@ for dataset in datasets:
|
|||||||
freq_all.append(norm.tolist())
|
freq_all.append(norm.tolist())
|
||||||
time_all.append(ct_arr)
|
time_all.append(ct_arr)
|
||||||
|
|
||||||
plt.plot(ct_arr, norm) #, label='fish=%s' % ID)
|
plt.plot(ct_arr, norm, color = 'grey', label='fish=%s' % ID)
|
||||||
|
|
||||||
|
# fit function
|
||||||
|
sv, sc = curve_fit(step_response, ct_arr[ct_arr < dm], norm[ct_arr < dm]) #step_values and step_cov
|
||||||
|
|
||||||
|
# sorted a and tau
|
||||||
|
values = sort_values(sv)
|
||||||
|
|
||||||
|
'''
|
||||||
|
plt.plot(ct_arr[ct_arr < 100], step_response(ct_arr, *sv)[ct_arr < 100], color='orange',
|
||||||
|
label='fit: a1=%.2f, a2=%.2f, tau1=%.2f, tau2=%.2f' % tuple(values))
|
||||||
|
'''
|
||||||
|
|
||||||
|
print('fish: a1, a2, tau1, tau2', values)
|
||||||
|
|
||||||
sv, sc = curve_fit(step_response, ct_arr[ct_arr < dm], norm[ct_arr < dm], maxfev = 2000) #step_values and step_cov
|
# average over all fish
|
||||||
|
mf_all , tnew_all = mean_traces(start, stop, timespan, freq_all, time_all)
|
||||||
|
|
||||||
a = sv[:2]
|
plt.plot(tnew_all, mf_all, color = 'b', label = 'average', ls = 'dashed')
|
||||||
tau = np.array(sorted(sv[2:], reverse=False))
|
|
||||||
values = np.array([a, tau])
|
|
||||||
values_flat = values.flatten()
|
|
||||||
|
|
||||||
plt.plot(ct_arr [ct_arr < 100], step_response(ct_arr, *sv)[ct_arr < 100], label='fit: a1=%.2f, a2=%.2f, tau1=%.2f, tau2=%.2f' % tuple(values_flat))
|
# fit for average
|
||||||
|
sv_all, sc_all = curve_fit(step_response, tnew_all[tnew_all < dm], mf_all[tnew_all < dm]) #step_values and step_cov
|
||||||
|
|
||||||
print('a1, a2, tau1, tau2', values_flat)
|
values_all = sort_values(sv_all)
|
||||||
constant_factors.append(a)
|
|
||||||
time_constants.append(tau)
|
|
||||||
fr = []
|
|
||||||
for j in freq_all:
|
|
||||||
fr.append(freq_all[j])
|
|
||||||
embed()
|
|
||||||
minimumf_all = min(len(freq_all[j]))
|
|
||||||
f_all = freq_all[j][:minimumf_all]
|
|
||||||
print(freq_all[0])
|
|
||||||
print(len((freq_all[j])))
|
|
||||||
|
|
||||||
#f_all_arr = np.array([f0_all], [f1_all])
|
plt.plot(tnew_all[tnew_all < 100], step_response(tnew_all, *sv_all)[tnew_all < 100], color='orange',
|
||||||
#f_mean_all = np.mean(freq_all, axis = 0)
|
label='average_fit: a1=%.2f, a2=%.2f, tau1=%.2f, tau2=%.2f' % tuple(values_all))
|
||||||
#t_mean_all = np.mean(time_all, axis = 0)
|
|
||||||
|
print('average: a1, a2, tau1, tau2', values_all)
|
||||||
|
|
||||||
|
const_line = plt.axhline(y = 0.632)
|
||||||
|
stimulus_duration = plt.hlines(y = -0.25, xmin = 0, xmax = 100, color = 'r', label = 'stimulus_duration')
|
||||||
|
base_line = plt.axhline(y = 0, color = 'black', ls = 'dotted', linewidth = '1')
|
||||||
|
|
||||||
const_line = plt.axhline(y=0.632)
|
|
||||||
plt.xlim([-10,220])
|
plt.xlim([-10,220])
|
||||||
plt.xlabel('time [s]')
|
plt.xlabel('time [s]')
|
||||||
plt.ylabel('rel. JAR magnitude')
|
plt.ylabel('rel. JAR magnitude')
|
||||||
@ -101,9 +105,8 @@ plt.legend(loc = 'lower right')
|
|||||||
plt.show()
|
plt.show()
|
||||||
embed()
|
embed()
|
||||||
|
|
||||||
|
# Fragen:
|
||||||
# alle daten einlesen durch große for schleife (auch average über alle fische?)
|
# wie offset point wenn nicht start bei 0 sec? über zeitdatenpunkt? oder einfach immer bei 0 onset..?
|
||||||
# für einzelne fische fit kontrollieren
|
|
||||||
|
|
||||||
# Fragen: wie offset point wenn nicht start bei 0 sec? über zeitdatenpunkt?
|
|
||||||
# wie zip ich ID liste mit plot (für eine for schleife) zusammen?
|
# wie zip ich ID liste mit plot (für eine for schleife) zusammen?
|
||||||
|
# welche Stimulusintesität?
|
||||||
|
# start/stop/timespan ok?
|
Loading…
Reference in New Issue
Block a user