jar_project/second_try.py
2020-07-03 13:27:21 +02:00

93 lines
2.5 KiB
Python

import matplotlib.pyplot as plt
import os
import glob
import IPython
import numpy as np
from IPython import embed
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
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)
minimumt = min(len(t[0]), len(t[1]))
# new time with wished timespan because it varies for different loops
tnew = np.arange(start, stop, timespan / minimumt) # 3rd input is stepspacing:
# in case complete measuring time devided by total number of datapoints
# interpolation
f0 = np.interp(tnew, t[0], f[0])
f1 = np.interp(tnew, t[1], f[1])
#new array with frequencies of both loops as two lists put together
frequency = np.array([f0, f1])
#making a mean over both loops with the axis 0 (=averaged in y direction, axis=1 would be over x axis)
mf = np.mean(frequency, axis=0)
#appending data
eodf.append(e)
deltaf.append(d)
stimulusf.append(s)
amplitude.append(a)
frequency_mean.append(mf)
time.append(tnew)
"""
for a in [0, 1, 2]:
for b in [0, 1, 2]:
r_step = step_response(t = ct_arr, a1 = a, a2 = b, tau1 = 30, tau2 = 60)
"""
for i in range(len(frequency_mean)):
for n in [100, 500, 1000]:
cf, ct = mean_noise_cut(frequency_mean[i], time[i], n=n)
ct_arr = np.array(ct)
cf_arr = np.array(cf)
base = base_eod(cf_arr, ct_arr, onset_point = 0)
ground = cf_arr - base
jar = JAR_eod(ground, ct_arr, offset_point = 100)
norm = ground / jar
plt.plot(ct_arr, norm, label='n=%d' % n)
for n in [1480]:
cf, ct = mean_noise_cut(frequency_mean[i], time[i], n=n)
ct_arr = np.array(ct)
cf_arr = np.array(cf)
r_step = step_response(t=ct_arr + 10, a1=0.55, a2=0.89, tau1=11.2, tau2= 280)
plt.plot(r_step, label='fit: n=%d' % n)
'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()
plt.show()
embed()
# Zeitkonstante: von sec. 0 bis 63%? relative JAR