106 lines
2.6 KiB
Python
106 lines
2.6 KiB
Python
import matplotlib.pyplot as plt
|
|
import numpy as np
|
|
import pylab
|
|
from IPython import embed
|
|
from scipy.optimize import curve_fit
|
|
from jar_functions import gain_curve_fit
|
|
from jar_functions import avgNestedLists
|
|
|
|
|
|
identifier = ['2018lepto1',
|
|
'2018lepto4',
|
|
'2018lepto5',
|
|
'2018lepto76',
|
|
'2018lepto98',
|
|
'2019lepto03',
|
|
'2019lepto24',
|
|
'2019lepto27',
|
|
'2019lepto30',
|
|
'2020lepto04',
|
|
'2020lepto06',
|
|
'2020lepto16',
|
|
'2020lepto19',
|
|
'2020lepto20'
|
|
]
|
|
|
|
amf = [0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1]
|
|
|
|
custom_f = np.logspace(-2, -1, 10)
|
|
custom_alpha = np.logspace(1.5, 1, 10)
|
|
c_gain = []
|
|
custom_tau = abs(1 / (2 * np.pi * custom_f))
|
|
for t, a in zip(custom_tau, custom_alpha):
|
|
custom_gain = []
|
|
for am in amf:
|
|
custom_g = gain_curve_fit(am, t, a)
|
|
custom_gain.append(custom_g)
|
|
c_gain.append(custom_gain)
|
|
fig = plt.figure()
|
|
ax = fig.add_subplot(111)
|
|
ax.set_xscale('log')
|
|
ax.set_yscale('log')
|
|
for cc, c in enumerate(c_gain):
|
|
ax.plot(amf, c)
|
|
ax.axvline(x=custom_f[cc], ymin=0, ymax=5, alpha=0.8) # colors_uniform[ff])
|
|
|
|
plt.show()
|
|
|
|
mean = avgNestedLists(c_gain)
|
|
fig = plt.figure()
|
|
ax = fig.add_subplot(111)
|
|
ax.set_xscale('log')
|
|
ax.set_yscale('log')
|
|
ax.plot(amf, mean)
|
|
plt.show()
|
|
|
|
all = []
|
|
|
|
for ident in identifier:
|
|
data = np.load('gain_%s.npy' %ident)
|
|
all.append(data)
|
|
|
|
av = avgNestedLists(all)
|
|
embed()
|
|
|
|
fig = plt.figure(figsize=(8.27,11.69/2))
|
|
ax = fig.add_subplot(111)
|
|
ax.plot(amf, av, 'o', c = 'C0', label = 'gain')
|
|
|
|
#plt.show()
|
|
|
|
tau = []
|
|
f_c = []
|
|
fit = []
|
|
fit_amf = []
|
|
for ID in identifier:
|
|
print(ID)
|
|
amf = np.load('amf_%s.npy' %ID)
|
|
gain = np.load('gain_%s.npy' %ID)
|
|
|
|
sinv, sinc = curve_fit(gain_curve_fit, amf, gain, [2, 3])
|
|
#print('tau:', sinv[0])
|
|
tau.append(sinv[0])
|
|
f_cutoff = abs(1 / (2*np.pi*sinv[0]))
|
|
print('f_cutoff:', f_cutoff)
|
|
f_c.append(f_cutoff)
|
|
fit.append(gain_curve_fit(amf, *sinv))
|
|
fit_amf.append(amf)
|
|
col = plt.cm.magma(np.linspace(0,0.8,len(fit)))
|
|
for ff ,f in enumerate(fit):
|
|
ax.plot(fit_amf[ff], fit[ff], c = col[ff])
|
|
ax.axvline(x=f_c[ff], ymin=0, ymax=5, alpha=0.8, c = col[ff]) # colors_uniform[ff])
|
|
|
|
ax.set_xscale('log')
|
|
ax.set_yscale('log')
|
|
ax.set_title('gain average all fish')
|
|
ax.set_ylabel('gain [Hz/(mV/cm)]')
|
|
ax.set_xlabel('envelope_frequency [Hz]')
|
|
ax.set_ylim(0.0008, )
|
|
#ax.plot(f_c, np.full(len(identifier), 0.0015), 'o', alpha = 0.5, c = 'darkorange', label = 'cutoff frequencies')
|
|
ax.legend(loc = 'center left')
|
|
|
|
plt.show()
|
|
|
|
embed()
|
|
|