diff --git a/jar_functions.py b/jar_functions.py index 20ee141..99b0af8 100644 --- a/jar_functions.py +++ b/jar_functions.py @@ -163,7 +163,7 @@ def average(freq_all, time_all, start, stop, timespan, dm): values_all = sort_values(sv_all) - plt.plot(tnew_all[tnew_all < 100], step_response(tnew_all, *sv_all)[tnew_all < 100], color = 'g', + plt.plot(tnew_all[tnew_all < dm], step_response(tnew_all, *sv_all)[tnew_all < dm], color = 'g', lw = 2, label='average_fit: a1=%.2f, a2=%.2f, tau1=%.2f, tau2=%.2f' % tuple(values_all)) print('average: a1, a2, tau1, tau2', values_all) diff --git a/sin_response_fit.py b/sin_response_fit.py index e2a5cd2..1c9cd69 100644 --- a/sin_response_fit.py +++ b/sin_response_fit.py @@ -9,6 +9,7 @@ from jar_functions import sin_response def take_second(elem): return elem[1] +predict = [] gain = [] mgain = [] @@ -25,12 +26,13 @@ data = sorted(np.load('files.npy'), key = take_second) for i, d in enumerate(data): dd = list(d) jar = np.load('%s.npy' %dd) + jm = jar - np.mean(jar) print(dd) time = np.load('time: %s.npy' %dd) b, a = signal.butter(4, (float(d[1]) / 2) / 10000, 'high', analog=True) - y = signal.filtfilt(b, a, jar - np.mean(jar)) + y = signal.filtfilt(b, a, jm) #plt.plot(time, y) #plt.plot(time, jar) @@ -41,12 +43,16 @@ for i, d in enumerate(data): gain.append(np.sqrt(sinv[2]**2)) amfreq.append(d[1]) + Rs = [] + for ix, t in enumerate(time): + R = (jm[ix] - sin_response(t, float(d[1]), np.sqrt(sinv[1]**2), np.sqrt(sinv[2]**2)))**2 + Rs.append(R) + sigma = sum(Rs) + rms = np.sqrt((1/len(time)) * sigma) #plt.plot(time, sin_response(time, *sinv), label='fit: f=%f, p=%.2f, A=%.2f' % tuple(sinv)) - # plt.legend() - #plt.show() - + #mean over same amfreqs for phase and gain if currf is None or currf == d[1]: currf = d[1] idxlist.append(i) @@ -74,10 +80,25 @@ meanedp = np.mean(meanp) mgain.append(meanedf) mphaseshift.append(meanedp) +for f in amf: + G = np.max(mgain) / np.sqrt(1 + (2*((np.pi*f*3.14)**2))) + predict.append(G) + + + fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax.plot(amf, mgain, 'o') +ax.plot(amf, predict) ax.set_yscale('log') +ax.set_xscale('log') +ax.set_title('2018lepto98') +ax.set_ylabel('gain [Hz/(mV/cm)]') +ax.set_xlabel('AM-frequency [Hz]') +#plt.savefig('2018lepto98_gain') pylab.show() +embed() -#betrag von A +#phase in degree +# Q10 / conductivity +# AM-frequency / envelope-frequency scale title? \ No newline at end of file diff --git a/sin_response_specto.py b/sin_response_specto.py index 8936bc8..1fbfc04 100644 --- a/sin_response_specto.py +++ b/sin_response_specto.py @@ -27,24 +27,16 @@ base_path = 'D:\\jar_project\\JAR\\sin\\2018lepto98' #dat = glob.glob('D:\\jar_project\\JAR\\2020*\\beats-eod.dat') #infodat = glob.glob('D:\\jar_project\\JAR\\2020*\\info.dat') -datasets = [#'2020-06-19-aa', #-5Hz delta f, horrible fit - #'2020-06-19-ab', #-5Hz delta f, bad fit - #'2020-06-22-aa', #-5Hz delta f, bad fit - #'2020-06-22-ab', #-5Hz delta f, bad fit - #'2020-06-22-ac', #-15Hz delta f, good fit - #'2020-06-22-ad', #-15Hz delta f, horrible fit - #'2020-06-22-ae', #-15Hz delta f, horrible fit - #'2020-06-22-af', #-15Hz delta f, good fit - '2020-07-21-al', #sin - '2020-07-21-am', - '2020-07-21-ak', - '2020-07-21-an', - '2020-07-21-ao', - '2020-07-22-ai', - '2020-07-22-aj', - '2020-07-22-ak', - '2020-07-22-al', - '2020-07-22-am', +datasets = ['2020-07-21-ak', +'2020-07-21-al', +'2020-07-21-am', +'2020-07-21-an', +'2020-07-21-ao', +'2020-07-22-ai', +'2020-07-22-aj', +'2020-07-22-ak', +'2020-07-22-al', +'2020-07-22-am', ] time_all = [] @@ -79,7 +71,7 @@ for idx, dataset in enumerate(datasets): i = parse_infodataset(infodataset) identifier = i[0] if not identifier[1:-2] in ID: - ID.append(identifier[1:-2]) + ID.append(identifier[1:-1]) file_name.append(ID[0]) amfreq = import_amfreq(datapath) @@ -120,7 +112,7 @@ for idx, dataset in enumerate(datasets): np.save('time: %s.npy' % file_name, cut_times) np.save('%s.npy' % file_name, jar4) - plt.plot(cut_times, jm, '-k') + #plt.plot(cut_times, jm, '-k') #cf, ct = mean_noise_cut(jar4, cut_times, n = int(round(len(jar4)/((times[-1] - times [0]) * amfreq)))) #plt.plot(ct, cf, '-k') diff --git a/step_response.py b/step_response.py index a08972c..5b4eebc 100644 --- a/step_response.py +++ b/step_response.py @@ -16,7 +16,7 @@ from jar_functions import step_response from jar_functions import sort_values from jar_functions import average -base_path = 'D:\\jar_project\\JAR' +base_path = 'D:\\jar_project\\JAR\\step\\step_2018lepto98' #nicht: -5Hz delta f, 19-aa, 22-ae, 22-ad (?) datasets = [#'2020-06-19-aa', #-5Hz delta f, horrible fit @@ -26,8 +26,20 @@ datasets = [#'2020-06-19-aa', #-5Hz delta f, horrible fit #'2020-06-22-ac', #-15Hz delta f, good fit #'2020-06-22-ad', #-15Hz delta f, horrible fit #'2020-06-22-ae', #-15Hz delta f, horrible fit - '2020-06-22-af' #-15Hz delta f, good fit - ] + #'2020-06-22-af', #-15Hz delta f, good fit + '2020-07-13-ad', +'2020-07-13-ae', +'2020-07-13-af', +'2020-07-13-ag', +'2020-07-13-ah', +'2020-07-13-ai', +'2020-07-13-aj', +#'2020-07-13-ak', +#'2020-07-13-al', +'2020-07-13-am', +#'2020-07-13-an', +#'2020-07-13-ao' +] #dat = glob.glob('D:\\jar_project\\JAR\\2020*\\beats-eod.dat') #infodat = glob.glob('D:\\jar_project\\JAR\\2020*\\info.dat') @@ -68,7 +80,7 @@ for idx, dataset in enumerate(datasets): freq_all.append(cf_arr) time_all.append(ct_arr) - plt.plot(ct_arr, cf_arr, color = col[idx], label='fish=%s' % datasets[idx]) + plt.plot(ct_arr, cf_arr, label='fish=%s' % datasets[idx]) #, color = col[idx] sv, sc = curve_fit(step_response, ct_arr[ct_arr < dm], cf_arr[ct_arr < dm], [1.0, 1.0, 5.0, 50.0], bounds=(0.0, np.inf)) # step_values and step_cov @@ -76,17 +88,17 @@ for idx, dataset in enumerate(datasets): values = sort_values(sv) # fit for each trace - plt.plot(ct_arr[ct_arr < dm], step_response(ct_arr[ct_arr < dm], *sv), label='fit: a1=%.2f, a2=%.2f, tau1=%.2f, tau2=%.2f' % tuple(values)) + #plt.plot(ct_arr[ct_arr < dm], step_response(ct_arr[ct_arr < dm], *sv), label='fit: a1=%.2f, a2=%.2f, tau1=%.2f, tau2=%.2f' % tuple(values)) #plt.plot(ft, step_response(ft, *sv), color='orange', label='fit: a1=%.2f, a2=%.2f, tau1=%.2f, tau2=%.2f' % tuple(values)) print('fish: a1, a2, tau1, tau2', values) -'''# average over all fish +# average over all fish mf_all, tnew_all, values_all = average(freq_all, time_all, start, stop, timespan, dm) -''' -const_line = plt.axhline(y = 0.632) + +#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') @@ -99,14 +111,5 @@ plt.legend(loc = 'lower right') plt.show() embed() -# norm vor mean_traces damit cutoff von -5 -# average über alle fische eigentlich mal nicht nötig, auslagern -# nur bei -15 Hz messen -# bei verschiedenen amplituden messen (siehe Tim) -# natalie fragen ob sie bei verschiedenen Amplituden messen kann (siehe tim) -# Fragen: -# wie offset point wenn nicht start bei 0 sec? über zeitdatenpunkt? oder einfach immer bei 0 onset..? -# wie zip ich ID liste mit plot (für eine for schleife) zusammen? -# welche Stimulusintesität? -# start/stop/timespan ok? \ No newline at end of file +# natalie fragen ob sie bei verschiedenen Amplituden messen kann (siehe tim)