76 lines
2.1 KiB
Python
76 lines
2.1 KiB
Python
import matplotlib.pyplot as plt
|
|
import os
|
|
import glob
|
|
import IPython
|
|
import numpy as np
|
|
from IPython import embed
|
|
from scipy.optimize import curve_fit
|
|
from jar_functions import parse_dataset
|
|
from jar_functions import mean_noise_cut
|
|
from jar_functions import step_response
|
|
from jar_functions import JAR_eod
|
|
from jar_functions import base_eod
|
|
from jar_functions import mean_loops
|
|
from jar_functions import norm_function
|
|
|
|
|
|
datasets = [(os.path.join('D:\\jar_project\\JAR\\2020-06-22-ac\\beats-eod.dat'))]
|
|
|
|
eodf = []
|
|
deltaf = []
|
|
stimulusf = []
|
|
|
|
time = []
|
|
frequency_mean= []
|
|
amplitude = []
|
|
|
|
start = -10
|
|
stop = 200
|
|
timespan = 210
|
|
|
|
for dataset in datasets:
|
|
#input of the function
|
|
t, f, a, e, d, s = parse_dataset(dataset)
|
|
mf , tnew = mean_loops(start, stop, timespan, f, t)
|
|
embed()
|
|
|
|
for i in range(len(mf)):
|
|
for n in [500, 1000, 1500]:
|
|
cf, ct = mean_noise_cut(mf[i], time[i], n=n)
|
|
|
|
cf_arr = np.array(cf)
|
|
ct_arr = np.array(ct)
|
|
|
|
norm = norm_function(cf_arr, ct_arr, onset_point = 0, offset_point = 100)
|
|
|
|
plt.plot(ct_arr, norm, label='n=%d' % n)
|
|
|
|
#r_step = step_response(t=ct_arr, a1=0.58, a2=0.47, tau1=11.7, tau2=60)
|
|
|
|
#plt.plot(ct_arr[ct_arr < 100], r_step[ct_arr < 100], label='fit: n=%d' % n)
|
|
|
|
step_values, step_cov = curve_fit(step_response, ct_arr[ct_arr < 100], norm [ct_arr < 100])
|
|
|
|
plt.plot(ct_arr [ct_arr < 100], step_response(ct_arr, *step_values)[ct_arr < 100], 'r-', label='fit: a1=%.2f, a2=%.2f, tau1=%.2f, tau2=%.2f' % tuple(step_values))
|
|
print(step_values)
|
|
const_line = plt.axhline(y=0.632)
|
|
|
|
'plotting'
|
|
plt.xlim([-10,220])
|
|
#plt.ylim([400, 1000])
|
|
plt.xlabel('time [s]')
|
|
plt.ylabel('rel. JAR magnitude')
|
|
#plt.title('fit_function(a1=0)')
|
|
#plt.savefig('fit_function(a1=0)')
|
|
plt.legend(loc = 'lower right')
|
|
plt.show()
|
|
embed()
|
|
|
|
# noch mehr in funktionen reinhauen (quasi nur noch plotting und funktionen einlesen)
|
|
# zeitkonstanten nach groß und klein sortieren
|
|
# onset dauer auslesen
|
|
# ID aus info.dat auslesen
|
|
# alle daten einlesen durch große for schleife (auch average über alle fische?)
|
|
# für einzelne fische fit kontrollieren
|
|
|