This commit is contained in:
xaver
2020-09-29 20:27:26 +02:00
parent f444071283
commit 90d9b19d9a
9 changed files with 619 additions and 111 deletions

View File

@@ -10,8 +10,8 @@ from jar_functions import mean_noise_cut_eigen
base_path = 'D:\\jar_project\\JAR\\sin'
identifier = ['2018lepto1',
'2018lepto4',
identifier = [#'2018lepto1',
#'2018lepto4',
'2018lepto5',
'2018lepto76',
'2018lepto98',
@@ -62,4 +62,4 @@ for ID in identifier:
print(ID)
print(base_eod)
embed()
embed()

View File

@@ -0,0 +1,50 @@
import matplotlib.pyplot as plt
import numpy as np
import pylab
from IPython import embed
from scipy.optimize import curve_fit
from matplotlib.mlab import specgram
import os
from jar_functions import gain_curve_fit
identifier = ['2018lepto1', '2018lepto4', '2018lepto5', '2018lepto76']
tau = []
f_c = []
for ID in identifier:
predict = []
print(ID)
amf = np.load('amf_%s.npy' %ID)
gain = np.load('gain_%s.npy' %ID)
print(gain)
sinv, sinc = curve_fit(gain_curve_fit, amf, gain)
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)
# predict of gain
for f in amf:
G = np.max(gain) / np.sqrt(1 + (2 * ((np.pi * f * sinv[0]) ** 2)))
predict.append(G)
print(np.max(gain))
fig = plt.figure()
ax = fig.add_subplot()
ax.plot(amf, gain,'o' , label = 'gain')
ax.plot(amf, predict, label = 'fit')
ax.axvline(x=f_cutoff, ymin=0, ymax=5, ls='-', alpha=0.5, label = 'cutoff frequency')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_ylabel('gain [Hz/(mV/cm)]')
ax.set_xlabel('envelope_frequency [Hz]')
ax.set_title('gaincurve %s' %ID)
plt.legend()
plt.show()
#np.save('f_c', f_c)
#np.save('tau', tau)

View File

@@ -0,0 +1,184 @@
import matplotlib.pyplot as plt
import numpy as np
import pylab
from IPython import embed
from scipy.optimize import curve_fit
from matplotlib.mlab import specgram
import os
from jar_functions import import_data
from jar_functions import import_amfreq
from scipy.optimize import curve_fit
from jar_functions import sin_response
from jar_functions import mean_noise_cut
from jar_functions import gain_curve_fit
def take_second(elem): # function for taking the names out of files
return elem[1]
identifier = ['2018lepto1']
for ident in identifier:
predict = []
rootmeansquare = []
threshold = []
gain = []
mgain = []
phaseshift = []
mphaseshift = []
amfreq = []
amf = [0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1]
currf = None
idxlist = []
data = sorted(np.load('%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
jm = jar - np.mean(jar) # low-pass filtering by subtracting mean
print(dd)
time = np.load('%s time.npy' %dd) # time file
dt = time[1] - time[0]
n = int(1/float(d[1])/dt)
cutf = mean_noise_cut(jm, n = n)
cutt = time
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:
p = p + np.pi
phaseshift.append(p)
gain.append(A)
if f not in amfreq:
amfreq.append(f)
# 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.xlabel('time[s]')
plt.ylabel('frequency[Hz]')
plt.show()
# low pass filter by mean subtraction
# plt.plot(time, jm)
# plt.title('JAR trace: filtered by mean subtraction')
# plt.xlabel('time[s]')
# plt.ylabel('frequency[Hz]')
# plt.show()
# 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.xlabel('time[s]')
plt.ylabel('frequency[Hz]')
plt.legend()
plt.show()
# 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]]
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.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()

View File

@@ -0,0 +1,149 @@
import matplotlib.pyplot as plt
import numpy as np
import pylab
from IPython import embed
from scipy.optimize import curve_fit
from matplotlib.mlab import specgram
import os
from jar_functions import import_data
from jar_functions import import_amfreq
from scipy.optimize import curve_fit
from jar_functions import sin_response
from jar_functions import mean_noise_cut
from jar_functions import gain_curve_fit
def take_second(elem): # function for taking the names out of files
return elem[1]
identifier = ['2018lepto1']
for ident in identifier:
predict = []
rootmeansquare = []
threshold = []
gain = []
mgain = []
phaseshift = []
mphaseshift = []
amfreq = []
amf = [0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1]
currf = None
idxlist = []
data = sorted(np.load('%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
jm = jar - np.mean(jar) # low-pass filtering by subtracting mean
print(dd)
time = np.load('%s time.npy' %dd) # time file
dt = time[1] - time[0]
n = int(1/float(d[1])/dt)
cutf = mean_noise_cut(jm, n = n)
cutt = time
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:
p = p + np.pi
phaseshift.append(p)
gain.append(A)
if f not in amfreq:
amfreq.append(f)
# 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('gaincurve 2018lepto1')
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()

View File

@@ -7,43 +7,28 @@ 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',
'2019lepto24',
'2019lepto27',
'2019lepto30',
'2020lepto04',
'2020lepto06',
'2020lepto16',
'2020lepto19',
'2020lepto20'
]
tau = []
f_c = []
for ID in identifier:
print(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])
tau.append(sinv[0])
f_cutoff = abs(1 / (2*np.pi*sinv[0]))
print('f_cutoff:', f_cutoff)
f_c.append(f_cutoff)
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('5Hz_gain_%s.npy' %ident)
data = np.load('gain_%s.npy' %ident)
all.append(data)
av = avgNestedLists(all)
@@ -51,14 +36,39 @@ av = avgNestedLists(all)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(amf, av, 'o')
#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)
#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)
#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_5Hz')
ax.set_title('gaincurve_average_allfish')
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.plot(f_c, np.full(len(identifier), 0.0015), 'o', label = 'cutoff frequencies')
ax.legend()
plt.show()
embed()

View File

@@ -5,7 +5,8 @@ from IPython import embed
from scipy.optimize import curve_fit
from jar_functions import gain_curve_fit
from jar_functions import avgNestedLists
import matplotlib as mpl
from matplotlib import cm
identifier_uniform = ['2018lepto1',
# '2018lepto4',
@@ -38,35 +39,9 @@ identifier = ['2018lepto1',
'2020lepto20'
]
tau = []
f_c = []
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)
#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)
tau_uniform = []
f_c_uniform = []
for ID in identifier_uniform:
#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])
tau_uniform.append(sinv[0])
f_cutoff = abs(1 / (2*np.pi*sinv[0]))
#print('f_cutoff:', f_cutoff)
f_c_uniform.append(f_cutoff)
amf = [0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1]
#colors = ['dimgray', 'dimgrey', 'gray', 'grey', 'darkgray', 'darkgrey', 'silver', 'lightgray', 'lightgrey', 'gainsboro', 'whitesmoke']
colorss = ['g', 'b', 'r', 'y', 'c', 'm', 'k']
all = []
new_all = []
for ident in identifier:
@@ -78,19 +53,65 @@ for ident in identifier_uniform:
av = avgNestedLists(all)
new_av = avgNestedLists(new_all)
lim = 0.001
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(amf, av, 'o', color = 'orange', label = 'normal')
ax.plot(amf, new_av, 'o', color = 'blue', label = 'uniformed')
#ax.plot(amf, av, 'o', color = 'orange', label = 'normal')
ax.plot(amf, new_av, 'o', label = 'uniformed')
"""
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)
#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)
"""
tau_uniform = []
f_c_uniform = []
fit_uniform = []
fit_amf_uniform = []
for ID in identifier_uniform:
#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])
tau_uniform.append(sinv[0])
f_cutoff = abs(1 / (2*np.pi*sinv[0]))
#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)))
# 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])
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_title('gaincurve_average_allfish')
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', color = 'orange', label = 'all cutoff frequencies')
ax.plot(f_c_uniform, np.full((len(identifier_uniform)), 0.001), 'o', color = 'blue', label = 'uniformed cutoff frequencies')
ax.legend()
plt.show()