80 lines
2.4 KiB
Python
80 lines
2.4 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 parse_infodataset
|
|
from jar_functions import mean_loops
|
|
from jar_functions import mean_noise_cut
|
|
from jar_functions import norm_function
|
|
from jar_functions import step_response
|
|
|
|
datasets = [(os.path.join('D:\\jar_project\\JAR\\2020-06-22-ab\\beats-eod.dat')),
|
|
(os.path.join('D:\\jar_project\\JAR\\2020-06-22-ac\\beats-eod.dat'))]
|
|
infodatasets = [(os.path.join('D:\\jar_project\\JAR\\2020-06-22-ac\\info.dat'))]
|
|
|
|
|
|
time = []
|
|
frequency_mean = []
|
|
|
|
constant_factors = []
|
|
time_constants = []
|
|
|
|
start = -10
|
|
stop = 200
|
|
timespan = 210
|
|
for infodataset in infodatasets:
|
|
i= parse_infodataset(infodataset)
|
|
identifier = i[0]
|
|
|
|
for dataset in datasets:
|
|
#input of the function
|
|
frequency, time, amplitude, eodf, deltaf, stimulusf, duration = parse_dataset(dataset)
|
|
mf , tnew = mean_loops(start, stop, timespan, frequency, time)
|
|
dm = np.mean(duration)
|
|
frequency_mean.append(mf)
|
|
time.append(tnew)
|
|
|
|
for i in range(len(frequency_mean)):
|
|
cf, ct = mean_noise_cut(frequency_mean[i], time[i], n=1000)
|
|
|
|
cf_arr = np.array(cf)
|
|
ct_arr = np.array(ct)
|
|
|
|
norm = norm_function(cf_arr, ct_arr, onset_point = dm - dm, offset_point = dm) #dm-dm funktioniert nur wenn onset = 0 sec
|
|
|
|
plt.plot(ct_arr, norm) #, label='n=%d' % n)
|
|
|
|
sv, sc = curve_fit(step_response, ct_arr[ct_arr < 100], norm[ct_arr < 100]) #step_values and step_cov
|
|
a = sv[:2]
|
|
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], 'r-', label='fit: a1=%.2f, a2=%.2f, tau1=%.2f, tau2=%.2f' % tuple(values_flat))
|
|
|
|
print('a1, a2, tau1, tau2', values_flat)
|
|
constant_factors.append(a)
|
|
time_constants.append(tau)
|
|
|
|
const_line = plt.axhline(y=0.632)
|
|
plt.xlim([-10,220])
|
|
plt.xlabel('time [s]')
|
|
plt.ylabel('rel. JAR magnitude')
|
|
plt.title('relative JAR')
|
|
plt.savefig('relative JAR')
|
|
plt.legend(loc = 'lower right')
|
|
plt.show()
|
|
embed()
|
|
|
|
|
|
# alle daten einlesen durch große for schleife (auch average über alle fische?)
|
|
# für einzelne fische fit kontrollieren
|
|
|
|
#Fragen: wie offset point wenn nicht start bei 0 sec?
|
|
#wie a1, tau1,.. ohne array? (funkt wegen dimensionen wenn ichs nochmal in liste appende)
|
|
|