07.07
This commit is contained in:
parent
e91b648b5c
commit
85a4b51680
@ -13,6 +13,7 @@ def parse_dataset(dataset_name):
|
|||||||
deltafs = []
|
deltafs = []
|
||||||
stimulusfs = []
|
stimulusfs = []
|
||||||
duration = []
|
duration = []
|
||||||
|
pause = []
|
||||||
|
|
||||||
# data itself
|
# data itself
|
||||||
times = []
|
times = []
|
||||||
@ -34,6 +35,8 @@ def parse_dataset(dataset_name):
|
|||||||
stimulusfs.append(float(l.split(':')[-1].strip()[:-2]))
|
stimulusfs.append(float(l.split(':')[-1].strip()[:-2]))
|
||||||
if "#" in l and "Duration" in l:
|
if "#" in l and "Duration" in l:
|
||||||
duration.append(float(l.split(':')[-1].strip()[:-3]))
|
duration.append(float(l.split(':')[-1].strip()[:-3]))
|
||||||
|
if "#" in l and "Pause" in l:
|
||||||
|
pause.append(float(l.split(':')[-1].strip()[:-3]))
|
||||||
|
|
||||||
if '#Key' in l:
|
if '#Key' in l:
|
||||||
if len(time) != 0: #therefore empty in the first round
|
if len(time) != 0: #therefore empty in the first round
|
||||||
@ -55,7 +58,7 @@ def parse_dataset(dataset_name):
|
|||||||
amplitudes.append(ampl) #these append the data from the first loop to the final lists, because we overwrite them (?)
|
amplitudes.append(ampl) #these append the data from the first loop to the final lists, because we overwrite them (?)
|
||||||
frequencies.append(freq)
|
frequencies.append(freq)
|
||||||
|
|
||||||
return frequencies, times, amplitudes, eodfs, deltafs, stimulusfs, duration #output of the function
|
return frequencies, times, amplitudes, eodfs, deltafs, stimulusfs, duration, pause #output of the function
|
||||||
|
|
||||||
def parse_infodataset(dataset_name):
|
def parse_infodataset(dataset_name):
|
||||||
assert(os.path.exists(dataset_name)) #see if data exists
|
assert(os.path.exists(dataset_name)) #see if data exists
|
||||||
@ -90,13 +93,11 @@ def mean_loops(start, stop, timespan, frequencies, time):
|
|||||||
def mean_noise_cut(frequencies, time, n):
|
def mean_noise_cut(frequencies, time, n):
|
||||||
cutf = []
|
cutf = []
|
||||||
cutt = []
|
cutt = []
|
||||||
|
|
||||||
for k in np.arange(0, len(frequencies), n):
|
for k in np.arange(0, len(frequencies), n):
|
||||||
t = time[k]
|
t = time[k]
|
||||||
f = np.mean(frequencies[k:k+n])
|
f = np.mean(frequencies[k:k+n])
|
||||||
cutf.append(f)
|
cutf.append(f)
|
||||||
cutt.append(t)
|
cutt.append(t)
|
||||||
|
|
||||||
return cutf, cutt
|
return cutf, cutt
|
||||||
|
|
||||||
|
|
||||||
@ -109,11 +110,11 @@ def norm_function(cf_arr, ct_arr, onset_point, offset_point):
|
|||||||
onset_end = onset_point - 10
|
onset_end = onset_point - 10
|
||||||
offset_start = offset_point - 10
|
offset_start = offset_point - 10
|
||||||
|
|
||||||
base = np.mean(cf_arr[(ct_arr >= onset_end) & (ct_arr < onset_point)])
|
base = np.median(cf_arr[(ct_arr >= onset_end) & (ct_arr < onset_point)])
|
||||||
|
|
||||||
ground = cf_arr - base
|
ground = cf_arr - base
|
||||||
|
|
||||||
jar = np.mean(ground[(ct_arr >= offset_start) & (ct_arr < offset_point)])
|
jar = np.median(ground[(ct_arr >= offset_start) & (ct_arr < offset_point)])
|
||||||
|
|
||||||
norm = ground / jar
|
norm = ground / jar
|
||||||
return norm
|
return norm
|
||||||
@ -123,7 +124,7 @@ def base_eod(frequencies, time, onset_point):
|
|||||||
|
|
||||||
onset_end = onset_point - 10
|
onset_end = onset_point - 10
|
||||||
|
|
||||||
base = np.mean(frequencies[(time >= onset_end) & (time < onset_point)])
|
base = np.median(frequencies[(time >= onset_end) & (time < onset_point)])
|
||||||
base_eod.append(base)
|
base_eod.append(base)
|
||||||
return base_eod
|
return base_eod
|
||||||
|
|
||||||
@ -133,7 +134,7 @@ def JAR_eod(frequencies, time, offset_point):
|
|||||||
|
|
||||||
offset_start = offset_point - 10
|
offset_start = offset_point - 10
|
||||||
|
|
||||||
jar = np.mean(frequencies[(time >= offset_start) & (time < offset_point)])
|
jar = np.median(frequencies[(time >= offset_start) & (time < offset_point)])
|
||||||
jar_eod.append(jar)
|
jar_eod.append(jar)
|
||||||
|
|
||||||
return jar_eod
|
return jar_eod
|
||||||
|
@ -12,53 +12,84 @@ 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
|
||||||
|
|
||||||
datasets = [(os.path.join('D:\\jar_project\\JAR\\2020-06-22-ab\\beats-eod.dat')),
|
#nicht: 19-aa, 22-ae, 22-ad (?)
|
||||||
(os.path.join('D:\\jar_project\\JAR\\2020-06-22-ac\\beats-eod.dat'))]
|
datasets = [#(os.path.join('D:\\jar_project\\JAR\\2020-06-19-aa\\beats-eod.dat')), #-5Hz delta f, horrible fit
|
||||||
infodatasets = [(os.path.join('D:\\jar_project\\JAR\\2020-06-22-ac\\info.dat'))]
|
#(os.path.join('D:\\jar_project\\JAR\\2020-06-19-ab\\beats-eod.dat')), #-5Hz delta f, bad fit
|
||||||
|
#(os.path.join('D:\\jar_project\\JAR\\2020-06-22-aa\\beats-eod.dat')), #-5Hz delta f, bad fit
|
||||||
|
#(os.path.join('D:\\jar_project\\JAR\\2020-06-22-ab\\beats-eod.dat')), #-5Hz delta f, bad fit
|
||||||
|
(os.path.join('D:\\jar_project\\JAR\\2020-06-22-ac\\beats-eod.dat')), #-15Hz delta f, good fit
|
||||||
|
#(os.path.join('D:\\jar_project\\JAR\\2020-06-22-ad\\beats-eod.dat')), #-15Hz delta f, horrible fit
|
||||||
|
#(os.path.join('D:\\jar_project\\JAR\\2020-06-22-ae\\beats-eod.dat')), #-15Hz delta f, maxfev way to high so horrible
|
||||||
|
(os.path.join('D:\\jar_project\\JAR\\2020-06-22-af\\beats-eod.dat'))] #-15Hz delta f, good fit
|
||||||
|
|
||||||
|
#np.array(sorted(glob.glob('D:\\jar_project\\JAR\\2020*\\beats-eod.dat')))
|
||||||
|
|
||||||
time = []
|
infodatasets = [(os.path.join('D:\\jar_project\\JAR\\2020-06-22-ac\\info.dat')),
|
||||||
frequency_mean = []
|
(os.path.join('D:\\jar_project\\JAR\\2020-06-22-af\\info.dat'))]
|
||||||
|
|
||||||
|
|
||||||
|
time_all = []
|
||||||
|
freq_all = []
|
||||||
|
|
||||||
constant_factors = []
|
constant_factors = []
|
||||||
time_constants = []
|
time_constants = []
|
||||||
|
|
||||||
start = -10
|
ID = []
|
||||||
stop = 200
|
|
||||||
timespan = 210
|
|
||||||
for infodataset in infodatasets:
|
for infodataset in infodatasets:
|
||||||
i= parse_infodataset(infodataset)
|
i = parse_infodataset(infodataset)
|
||||||
identifier = i[0]
|
identifier = i[0]
|
||||||
|
ID.append(identifier)
|
||||||
|
|
||||||
|
|
||||||
for dataset in datasets:
|
for dataset in datasets:
|
||||||
#input of the function
|
#input of the function
|
||||||
frequency, time, amplitude, eodf, deltaf, stimulusf, duration = parse_dataset(dataset)
|
frequency, time, amplitude, eodf, deltaf, stimulusf, duration, pause = parse_dataset(dataset)
|
||||||
mf , tnew = mean_loops(start, stop, timespan, frequency, time)
|
|
||||||
dm = np.mean(duration)
|
dm = np.mean(duration)
|
||||||
frequency_mean.append(mf)
|
pm = np.mean(pause)
|
||||||
time.append(tnew)
|
timespan = dm + pm
|
||||||
|
start = -10
|
||||||
|
stop = 200
|
||||||
|
mf , tnew = mean_loops(start, stop, timespan, frequency, time)
|
||||||
|
|
||||||
|
#for i in range(len(mf)):
|
||||||
|
|
||||||
for i in range(len(frequency_mean)):
|
cf, ct = mean_noise_cut(mf, tnew, n=1250)
|
||||||
cf, ct = mean_noise_cut(frequency_mean[i], time[i], n=1000)
|
|
||||||
|
|
||||||
cf_arr = np.array(cf)
|
cf_arr = np.array(cf)
|
||||||
ct_arr = np.array(ct)
|
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
|
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)
|
freq_all.append(norm.tolist())
|
||||||
|
time_all.append(ct_arr)
|
||||||
|
|
||||||
|
plt.plot(ct_arr, norm) #, label='fish=%s' % ID)
|
||||||
|
|
||||||
|
sv, sc = curve_fit(step_response, ct_arr[ct_arr < dm], norm[ct_arr < dm], maxfev = 2000) #step_values and step_cov
|
||||||
|
|
||||||
sv, sc = curve_fit(step_response, ct_arr[ct_arr < 100], norm[ct_arr < 100]) #step_values and step_cov
|
|
||||||
a = sv[:2]
|
a = sv[:2]
|
||||||
tau = np.array(sorted(sv[2:], reverse=False))
|
tau = np.array(sorted(sv[2:], reverse=False))
|
||||||
values = np.array([a, tau])
|
values = np.array([a, tau])
|
||||||
values_flat = values.flatten()
|
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))
|
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))
|
||||||
|
|
||||||
print('a1, a2, tau1, tau2', values_flat)
|
print('a1, a2, tau1, tau2', values_flat)
|
||||||
constant_factors.append(a)
|
constant_factors.append(a)
|
||||||
time_constants.append(tau)
|
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])
|
||||||
|
#f_mean_all = np.mean(freq_all, axis = 0)
|
||||||
|
#t_mean_all = np.mean(time_all, axis = 0)
|
||||||
|
|
||||||
const_line = plt.axhline(y=0.632)
|
const_line = plt.axhline(y=0.632)
|
||||||
plt.xlim([-10,220])
|
plt.xlim([-10,220])
|
||||||
@ -74,6 +105,5 @@ embed()
|
|||||||
# alle daten einlesen durch große for schleife (auch average über alle fische?)
|
# alle daten einlesen durch große for schleife (auch average über alle fische?)
|
||||||
# für einzelne fische fit kontrollieren
|
# für einzelne fische fit kontrollieren
|
||||||
|
|
||||||
#Fragen: wie offset point wenn nicht start bei 0 sec?
|
# Fragen: wie offset point wenn nicht start bei 0 sec? über zeitdatenpunkt?
|
||||||
#wie a1, tau1,.. ohne array? (funkt wegen dimensionen wenn ichs nochmal in liste appende)
|
# wie zip ich ID liste mit plot (für eine for schleife) zusammen?
|
||||||
|
|
Loading…
Reference in New Issue
Block a user