05.10
This commit is contained in:
@@ -7,7 +7,7 @@ from matplotlib.mlab import specgram
|
||||
import os
|
||||
from jar_functions import gain_curve_fit
|
||||
|
||||
identifier = ['2018lepto1', '2018lepto4', '2018lepto5', '2018lepto76']
|
||||
identifier = ['2020lepto06']
|
||||
|
||||
tau = []
|
||||
f_c = []
|
||||
@@ -42,7 +42,7 @@ for ID in identifier:
|
||||
ax.set_ylabel('gain [Hz/(mV/cm)]')
|
||||
ax.set_xlabel('envelope_frequency [Hz]')
|
||||
ax.set_title('gaincurve %s' %ID)
|
||||
plt.legend()
|
||||
plt.legend(loc = 'lower left')
|
||||
plt.show()
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ from jar_functions import gain_curve_fit
|
||||
def take_second(elem): # function for taking the names out of files
|
||||
return elem[1]
|
||||
|
||||
identifier = ['2018lepto1']
|
||||
identifier = ['2018lepto98']
|
||||
for ident in identifier:
|
||||
|
||||
predict = []
|
||||
@@ -35,16 +35,16 @@ for ident in identifier:
|
||||
currf = None
|
||||
idxlist = []
|
||||
|
||||
data = sorted(np.load('%s files.npy' %ident), key = take_second) # list with filenames in it
|
||||
data = sorted(np.load('5Hz_%s files.npy' %ident), key = take_second) # list with filenames in it
|
||||
|
||||
for i, d in enumerate(data):
|
||||
dd = list(d)
|
||||
if dd[1] == '0.005':
|
||||
jar = np.load('%s.npy' %dd) # load data for every file name
|
||||
if dd[1] == '0.5':
|
||||
jar = np.load('5Hz_%s.npy' %dd) # load data for every file name
|
||||
jm = jar - np.mean(jar) # low-pass filtering by subtracting mean
|
||||
print(dd)
|
||||
|
||||
time = np.load('%s time.npy' %dd) # time file
|
||||
time = np.load('5Hz_%s time.npy' %dd) # time file
|
||||
dt = time[1] - time[0]
|
||||
|
||||
n = int(1/float(d[1])/dt)
|
||||
@@ -54,10 +54,11 @@ for ident in identifier:
|
||||
sinv, sinc = curve_fit(sin_response, time, jm - cutf, [float(d[1]), 2, 0.5]) # fitting
|
||||
print('frequency, phaseshift, amplitude:', sinv)
|
||||
p = sinv[1]
|
||||
A = np.sqrt(sinv[2] ** 2)
|
||||
f = float(d[1])
|
||||
if sinv[2] < 0:
|
||||
A = sinv[2]
|
||||
if A < 0:
|
||||
p = p + np.pi
|
||||
A = -A
|
||||
f = float(d[1])
|
||||
phaseshift.append(p)
|
||||
gain.append(A)
|
||||
if f not in amfreq:
|
||||
@@ -66,7 +67,7 @@ for ident in identifier:
|
||||
# jar trace
|
||||
plt.plot(time, jar, color = 'C0')
|
||||
#plt.hlines(y=np.min(jar) - 2, xmin=0, xmax=400, lw=2.5, color='r', label='stimulus duration')
|
||||
plt.title('JAR trace 2018lepto1, AM-frequency:%sHz' % float(d[1]))
|
||||
plt.title('JAR trace 2018lepto98, AM-frequency:%sHz, deltaf = -5Hz' % float(d[1]))
|
||||
plt.xlabel('time[s]')
|
||||
plt.ylabel('frequency[Hz]')
|
||||
plt.show()
|
||||
@@ -81,7 +82,7 @@ for ident in identifier:
|
||||
# filter by running average
|
||||
plt.plot(time, jm, color = 'C0', label = 'JAR: subtracted by mean')
|
||||
plt.plot(time, jm - cutf, color = 'darkorange', label = 'JAR: subtracted by mean and step response')
|
||||
plt.title('JAR trace spectogram 2018lepto1: subtraction of mean and step response')
|
||||
plt.title('JAR trace spectogram 2018lepto98: subtraction of mean and step response, deltaf = -5Hz')
|
||||
plt.xlabel('time[s]')
|
||||
plt.ylabel('frequency[Hz]')
|
||||
plt.legend()
|
||||
@@ -89,96 +90,12 @@ for ident in identifier:
|
||||
|
||||
# jar trace and fit
|
||||
plt.plot(time, jm - cutf, color = 'darkorange', label = 'JAR: subtracted by mean and step response')
|
||||
phase_gain = [(((sinv[1] % (2 * np.pi)) * 360) / (2 * np.pi)), sinv[2]]
|
||||
phase_gain = [(((p % (2 * np.pi)) * 360) / (2 * np.pi)), A]
|
||||
|
||||
plt.plot(time, sin_response(time, *sinv), color = 'limegreen', label='fit: phaseshift=%.2f°, gain=%.2f[Hz/(mV/cm)]' % tuple(phase_gain))
|
||||
plt.title('JAR trace spectogram 2018lepto1 with fit')
|
||||
plt.title('JAR trace spectogram 2018lepto98 with fit, deltaf = -5Hz')
|
||||
plt.xlabel('time[s]')
|
||||
plt.ylabel('frequency[Hz]')
|
||||
plt.legend()
|
||||
plt.show()
|
||||
|
||||
# root mean square
|
||||
RMS = np.sqrt(np.mean(((jm - cutf) - sin_response(cutt, sinv[0], sinv[1], sinv[2]))**2))
|
||||
thresh = A / np.sqrt(2)
|
||||
|
||||
# mean over same amfreqs for phase and gain
|
||||
if currf is None or currf == d[1]:
|
||||
currf = d[1]
|
||||
idxlist.append(i)
|
||||
|
||||
else: # currf != f
|
||||
meanf = [] # lists to make mean of
|
||||
meanp = []
|
||||
meanrms = []
|
||||
meanthresh = []
|
||||
for x in idxlist:
|
||||
meanf.append(gain[x])
|
||||
meanp.append(phaseshift[x])
|
||||
meanrms.append(RMS)
|
||||
meanthresh.append(thresh)
|
||||
meanedf = np.mean(meanf)
|
||||
meanedp = np.mean(meanp)
|
||||
meanedrms = np.mean(meanrms)
|
||||
meanedthresh = np.mean(meanthresh)
|
||||
|
||||
mgain.append(meanedf)
|
||||
mphaseshift.append(meanedp)
|
||||
rootmeansquare.append(meanedrms)
|
||||
threshold.append(meanedthresh)
|
||||
currf = d[1] # set back for next loop
|
||||
idxlist = [i]
|
||||
meanf = []
|
||||
meanp = []
|
||||
meanrms = []
|
||||
meanthresh = []
|
||||
for y in idxlist:
|
||||
meanf.append(gain[y])
|
||||
meanp.append(phaseshift[y])
|
||||
meanrms.append(RMS)
|
||||
meanthresh.append(thresh)
|
||||
meanedf = np.mean(meanf)
|
||||
meanedp = np.mean(meanp)
|
||||
meanedrms = np.mean(meanrms)
|
||||
meanedthresh = np.mean(meanthresh)
|
||||
|
||||
mgain.append(meanedf)
|
||||
mphaseshift.append(meanedp)
|
||||
rootmeansquare.append(meanedrms)
|
||||
threshold.append(meanedthresh)
|
||||
|
||||
# as arrays
|
||||
mgain_arr = np.array(mgain)
|
||||
mphaseshift_arr = np.array(mphaseshift)
|
||||
amfreq_arr = np.array(amfreq)
|
||||
rootmeansquare_arr = np.array(rootmeansquare)
|
||||
threshold_arr = np.array(threshold)
|
||||
|
||||
# condition needed to be fulfilled: RMS < threshold or RMS < mean(RMS)
|
||||
idx_arr = (rootmeansquare_arr < threshold_arr) | (rootmeansquare_arr < np.mean(rootmeansquare_arr))
|
||||
|
||||
fig = plt.figure()
|
||||
ax0 = fig.add_subplot(2, 1, 1)
|
||||
ax0.plot(amfreq_arr[idx_arr], mgain_arr[idx_arr], 'o')
|
||||
ax0.set_yscale('log')
|
||||
ax0.set_xscale('log')
|
||||
ax0.set_title('%s' % data[0][0])
|
||||
ax0.set_ylabel('gain [Hz/(mV/cm)]')
|
||||
ax0.set_xlabel('envelope_frequency [Hz]')
|
||||
#plt.savefig('%s gain' % data[0][0])
|
||||
|
||||
ax1 = fig.add_subplot(2, 1, 2, sharex = ax0)
|
||||
ax1.plot(amfreq, threshold, 'o-', label = 'threshold', color = 'b')
|
||||
ax1.set_xscale('log')
|
||||
ax1.plot(amfreq, rootmeansquare, 'o-', label = 'RMS', color ='orange')
|
||||
ax1.set_xscale('log')
|
||||
ax1.set_xlabel('envelope_frequency [Hz]')
|
||||
ax1.set_ylabel('RMS [Hz]')
|
||||
plt.legend()
|
||||
pylab.show()
|
||||
|
||||
#np.save('phaseshift_%s' % ident, mphaseshift_arr[idx_arr])
|
||||
#np.save('gain_%s' %ident, mgain_arr[idx_arr])
|
||||
#np.save('amf_%s' %ident, amfreq_arr[idx_arr])
|
||||
|
||||
embed()
|
||||
embed()
|
||||
|
||||
@@ -17,7 +17,7 @@ from jar_functions import gain_curve_fit
|
||||
def take_second(elem): # function for taking the names out of files
|
||||
return elem[1]
|
||||
|
||||
identifier = ['2018lepto1']
|
||||
identifier = ['2019lepto03']
|
||||
for ident in identifier:
|
||||
|
||||
predict = []
|
||||
@@ -35,16 +35,16 @@ for ident in identifier:
|
||||
currf = None
|
||||
idxlist = []
|
||||
|
||||
data = sorted(np.load('%s files.npy' %ident), key = take_second) # list with filenames in it
|
||||
data = sorted(np.load('5Hz_%s files.npy' %ident), key = take_second) # list with filenames in it
|
||||
|
||||
for i, d in enumerate(data):
|
||||
dd = list(d)
|
||||
|
||||
jar = np.load('%s.npy' %dd) # load data for every file name
|
||||
jar = np.load('5Hz_%s.npy' %dd) # load data for every file name
|
||||
jm = jar - np.mean(jar) # low-pass filtering by subtracting mean
|
||||
print(dd)
|
||||
|
||||
time = np.load('%s time.npy' %dd) # time file
|
||||
time = np.load('5Hz_%s time.npy' %dd) # time file
|
||||
dt = time[1] - time[0]
|
||||
|
||||
n = int(1/float(d[1])/dt)
|
||||
@@ -127,7 +127,7 @@ for ident in identifier:
|
||||
ax0.plot(amfreq_arr[idx_arr], mgain_arr[idx_arr], 'o')
|
||||
ax0.set_yscale('log')
|
||||
ax0.set_xscale('log')
|
||||
ax0.set_title('gaincurve 2018lepto1')
|
||||
ax0.set_title('gaincurve 2019lepto03, deltaf = -5Hz')
|
||||
ax0.set_ylabel('gain [Hz/(mV/cm)]')
|
||||
ax0.set_xlabel('envelope_frequency [Hz]')
|
||||
#plt.savefig('%s gain' % data[0][0])
|
||||
|
||||
@@ -7,17 +7,17 @@ from jar_functions import gain_curve_fit
|
||||
from jar_functions import avgNestedLists
|
||||
|
||||
|
||||
identifier = ['2018lepto1',
|
||||
'2018lepto4',
|
||||
'2018lepto5',
|
||||
'2018lepto76',
|
||||
identifier = [#'2018lepto1',
|
||||
#'2018lepto4',
|
||||
#'2018lepto5',
|
||||
#'2018lepto76',
|
||||
'2018lepto98',
|
||||
'2019lepto03',
|
||||
'2019lepto24',
|
||||
'2019lepto27',
|
||||
'2019lepto30',
|
||||
'2020lepto04',
|
||||
'2020lepto06',
|
||||
#'2019lepto03',
|
||||
#'2019lepto24',
|
||||
#'2019lepto27',
|
||||
#'2019lepto30',
|
||||
#'2020lepto04',
|
||||
#'2020lepto06',
|
||||
'2020lepto16',
|
||||
'2020lepto19',
|
||||
'2020lepto20'
|
||||
@@ -28,14 +28,14 @@ amf = [0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1]
|
||||
all = []
|
||||
|
||||
for ident in identifier:
|
||||
data = np.load('gain_%s.npy' %ident)
|
||||
data = np.load('5Hz_gain_%s.npy' %ident)
|
||||
all.append(data)
|
||||
|
||||
av = avgNestedLists(all)
|
||||
|
||||
fig = plt.figure()
|
||||
ax = fig.add_subplot(111)
|
||||
ax.plot(amf, av, 'o')
|
||||
ax.plot(amf, av, 'o', c = 'C0', label = 'gain')
|
||||
|
||||
#plt.show()
|
||||
|
||||
@@ -45,8 +45,8 @@ fit = []
|
||||
fit_amf = []
|
||||
for ID in identifier:
|
||||
print(ID)
|
||||
amf = np.load('amf_%s.npy' %ID)
|
||||
gain = np.load('gain_%s.npy' %ID)
|
||||
amf = np.load('5Hz_amf_%s.npy' %ID)
|
||||
gain = np.load('5Hz_gain_%s.npy' %ID)
|
||||
|
||||
sinv, sinc = curve_fit(gain_curve_fit, amf, gain)
|
||||
#print('tau:', sinv[0])
|
||||
@@ -56,17 +56,19 @@ for ID in identifier:
|
||||
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])
|
||||
|
||||
#for ff ,f in enumerate(fit):
|
||||
# ax.plot(fit_amf[ff], fit[ff])
|
||||
ax.set_xscale('log')
|
||||
ax.set_yscale('log')
|
||||
ax.set_title('gaincurve_average_allfish')
|
||||
ax.set_title('gain average all fish, deltaf: -5Hz')
|
||||
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', label = 'cutoff frequencies')
|
||||
ax.legend()
|
||||
#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()
|
||||
|
||||
|
||||
@@ -9,19 +9,19 @@ import matplotlib as mpl
|
||||
from matplotlib import cm
|
||||
|
||||
identifier_uniform = ['2018lepto1',
|
||||
# '2018lepto4',
|
||||
# '2018lepto5',
|
||||
#'2018lepto76',
|
||||
#'2018lepto4',
|
||||
'2018lepto5',
|
||||
'2018lepto76',
|
||||
'2018lepto98',
|
||||
# '2019lepto03',
|
||||
#'2019lepto03',
|
||||
'2019lepto24',
|
||||
#'2019lepto27',
|
||||
# '2019lepto30',
|
||||
'2020lepto04',
|
||||
# '2020lepto06',
|
||||
# '2020lepto16',
|
||||
'2020lepto19',
|
||||
# '2020lepto20'
|
||||
#'2019lepto30',
|
||||
#'2020lepto04',
|
||||
'2020lepto06',
|
||||
#'2020lepto16',
|
||||
#'2020lepto19',
|
||||
#'2020lepto20'
|
||||
]
|
||||
identifier = ['2018lepto1',
|
||||
'2018lepto4',
|
||||
@@ -32,10 +32,10 @@ identifier = ['2018lepto1',
|
||||
'2019lepto24',
|
||||
'2019lepto27',
|
||||
'2019lepto30',
|
||||
'2020lepto04',
|
||||
#'2020lepto04',
|
||||
'2020lepto06',
|
||||
'2020lepto16',
|
||||
'2020lepto19',
|
||||
#'2020lepto19',
|
||||
'2020lepto20'
|
||||
]
|
||||
|
||||
@@ -56,15 +56,15 @@ new_av = avgNestedLists(new_all)
|
||||
|
||||
fig = plt.figure()
|
||||
ax = fig.add_subplot(111)
|
||||
#ax.plot(amf, av, 'o', color = 'orange', label = 'normal')
|
||||
ax.plot(amf, new_av, 'o', label = 'uniformed')
|
||||
"""
|
||||
ax.plot(amf, av, 'o', color = 'darkorange', label = 'normal')
|
||||
ax.plot(amf, new_av, 'o', label = 'uniform')
|
||||
|
||||
tau = []
|
||||
f_c = []
|
||||
fit = []
|
||||
fit_amf = []
|
||||
for ID in identifier:
|
||||
#print(ID)
|
||||
print(ID)
|
||||
amf = np.load('amf_%s.npy' %ID)
|
||||
gain = np.load('gain_%s.npy' %ID)
|
||||
|
||||
@@ -72,47 +72,46 @@ for ID in identifier:
|
||||
#print('tau:', sinv[0])
|
||||
tau.append(sinv[0])
|
||||
f_cutoff = abs(1 / (2*np.pi*sinv[0]))
|
||||
#print('f_cutoff:', f_cutoff)
|
||||
print('f_cutoff:', f_cutoff)
|
||||
f_c.append(f_cutoff)
|
||||
fit.append(gain_curve_fit(amf, *sinv))
|
||||
fit_amf.append(amf)
|
||||
"""
|
||||
|
||||
# uniformed: 2018lepto5, 2018lepto1, 2018lepto76, 2018lepto98, 2020lepto06, 2019lepto24, 2020lepto4
|
||||
|
||||
tau_uniform = []
|
||||
f_c_uniform = []
|
||||
fit_uniform = []
|
||||
fit_amf_uniform = []
|
||||
for ID in identifier_uniform:
|
||||
#print(ID)
|
||||
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)
|
||||
#print('tau:', sinv[0])
|
||||
print('tau:', sinv[0])
|
||||
tau_uniform.append(sinv[0])
|
||||
f_cutoff = abs(1 / (2*np.pi*sinv[0]))
|
||||
#print('f_cutoff:', f_cutoff)
|
||||
print('f_cutoff:', f_cutoff)
|
||||
f_c_uniform.append(f_cutoff)
|
||||
fit_uniform.append(gain_curve_fit(amf, *sinv))
|
||||
fit_amf_uniform.append(amf)
|
||||
|
||||
colors_uniform = plt.cm.flag(np.linspace(0.2,0.8,len(fit_uniform)))
|
||||
#colors = plt.cm.flag(np.linspace(0.2,0.8,len(fit)))
|
||||
colors = plt.cm.flag(np.linspace(0,1,len(fit_uniform)))
|
||||
|
||||
# for ff ,f in enumerate(fit):
|
||||
# ax.plot(fit_amf[ff], fit[ff],color = colors[ff])
|
||||
# ax.axvline(x=f_c[ff], ymin=0, ymax=5, ls = '-', alpha = 0.5, color= colors[ff])#colors_uniform[ff])
|
||||
|
||||
for ff, f in enumerate(fit_uniform):
|
||||
ax.plot(fit_amf_uniform[ff], fit_uniform[ff], color = colorss[ff]) #colors_uniform[ff])
|
||||
ax.axvline(x=f_c_uniform[ff], ymin=0, ymax=5, ls = '-', alpha = 0.5, color= colorss[ff])#colors_uniform[ff])
|
||||
#for ff ,f in enumerate(fit_uniform):
|
||||
# ax.plot(fit_amf_uniform[ff], fit_uniform[ff],color = colorss[ff])
|
||||
# ax.axvline(x=f_c_uniform[ff], ymin=0, ymax=5, ls = '-', alpha = 0.5, color= colorss[ff])#colors_uniform[ff])
|
||||
|
||||
ax.set_xscale('log')
|
||||
ax.set_yscale('log')
|
||||
ax.set_title('gaincurve_average_allfish')
|
||||
ax.set_title('gain average all fish uniform')
|
||||
ax.set_ylabel('gain [Hz/(mV/cm)]')
|
||||
ax.set_xlabel('envelope_frequency [Hz]')
|
||||
ax.set_ylim(0.0008, )
|
||||
ax.legend()
|
||||
ax.plot(f_c, np.full(len(identifier), 0.0015), 'o', alpha = 0.5, c = 'darkorange', label = 'normal cutoff frequencies')
|
||||
ax.plot(f_c_uniform, np.full(len(identifier_uniform), 0.002), 'o', alpha = 0.5, c = 'C0', label = 'uniform cutoff frequencies')
|
||||
ax.legend(loc = 'center left')
|
||||
|
||||
plt.show()
|
||||
embed()
|
||||
|
||||
Reference in New Issue
Block a user