This commit is contained in:
xaver
2020-10-19 12:29:04 +02:00
parent d231c75806
commit b53890c7fc
11 changed files with 311 additions and 64 deletions

View File

@@ -7,11 +7,12 @@ from jar_functions import get_time_zeros
from jar_functions import parse_dataset
from jar_functions import mean_traces
from jar_functions import mean_noise_cut_eigen
from jar_functions import adjust_eodf
base_path = 'D:\\jar_project\\JAR\\sin'
identifier = [#'2018lepto1',
#'2018lepto4',
identifier = ['2018lepto1',
'2018lepto4',
'2018lepto5',
'2018lepto76',
'2018lepto98',
@@ -25,6 +26,7 @@ identifier = [#'2018lepto1',
'2020lepto19',
'2020lepto20'
]
eod = []
for ID in identifier:
base = []
@@ -56,10 +58,19 @@ for ID in identifier:
ff = np.mean(f)
base.append(ff)
plt.plot(ct, cf)
plt.show()
#plt.plot(ct, cf)
#plt.show()
base_eod = np.mean(base)
print(ID)
print(base_eod)
eod.append(base_eod)
embed()
temp = np.load('temperature.npy')
eod_temp = zip(eod, temp)
Q10_eod = []
for et in eod_temp:
Q10 = adjust_eodf(et[0], et[1])
Q10_eod.append(Q10)
embed()

View File

@@ -7,7 +7,7 @@ from matplotlib.mlab import specgram
import os
from jar_functions import gain_curve_fit
identifier = ['2020lepto06']
identifier = ['2020lepto19']
tau = []
f_c = []
@@ -19,7 +19,7 @@ for ID in identifier:
gain = np.load('gain_%s.npy' %ID)
print(gain)
sinv, sinc = curve_fit(gain_curve_fit, amf, gain)
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]))
@@ -35,8 +35,8 @@ for ID in identifier:
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.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)]')

View File

@@ -14,6 +14,8 @@ from jar_functions import sin_response
from jar_functions import mean_noise_cut
from jar_functions import gain_curve_fit
plt.rcParams.update({'font.size': 12})
def take_second(elem): # function for taking the names out of files
return elem[1]
@@ -35,16 +37,16 @@ for ident in identifier:
currf = None
idxlist = []
data = sorted(np.load('5Hz_%s files.npy' %ident), key = take_second) # list with filenames in it
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.5':
jar = np.load('5Hz_%s.npy' %dd) # load data for every file name
if dd[1] == '0.05':
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('5Hz_%s time.npy' %dd) # time file
time = np.load('%s time.npy' %dd) # time file
dt = time[1] - time[0]
n = int(1/float(d[1])/dt)
@@ -67,7 +69,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 2018lepto98, AM-frequency:%sHz, deltaf = -5Hz' % float(d[1]))
plt.title('JAR trace 2018lepto98, AM-frequency: %sHz' % float(d[1]))
plt.xlabel('time[s]')
plt.ylabel('frequency[Hz]')
plt.show()
@@ -80,22 +82,29 @@ for ident in identifier:
# 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 2018lepto98: subtraction of mean and step response, deltaf = -5Hz')
plt.xlabel('time[s]')
plt.ylabel('frequency[Hz]')
plt.legend()
plt.show()
fig = plt.figure(figsize = (8,14))
fig.suptitle('JAR trace spectogram 2018lepto98:\n subtraction of mean and running average')
ax = fig.add_subplot(211)
ax.plot(time, jm, color = 'C0', label = '1)')
ax.plot(time, jm - cutf, color = 'darkorange', label = '2)')
ax.set_ylabel('frequency[Hz]')
ax.set_ylim(-10.5, 10.5)
ax.axes.xaxis.set_ticklabels([])
plt.legend(loc='upper right')
plt.text(-0.1, 1.05, "A)", fontweight=550, transform=ax.transAxes)
# jar trace and fit
plt.plot(time, jm - cutf, color = 'darkorange', label = 'JAR: subtracted by mean and step response')
ax1 = fig.add_subplot(212)
ax1.plot(time, jm - cutf, color = 'darkorange', label = '2)')
phase_gain = [(((p % (2 * np.pi)) * 360) / (2 * np.pi)), A]
print(phase_gain)
ax1.plot(time, sin_response(time, *sinv), color = 'forestgreen', label='3)')
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 2018lepto98 with fit, deltaf = -5Hz')
plt.xlabel('time[s]')
plt.ylabel('frequency[Hz]')
plt.legend()
ax1.set_xlabel('time[s]')
ax1.set_ylabel('frequency[Hz]')
ax1.set_ylim(-10.5,10.5)
plt.legend(loc = 'upper right')
plt.text(-0.1, 1.05, "B)", fontweight=550, transform=ax1.transAxes)
plt.show()
plt.savefig('test_fig.png')
embed()

View File

@@ -14,10 +14,12 @@ from jar_functions import sin_response
from jar_functions import mean_noise_cut
from jar_functions import gain_curve_fit
plt.rcParams.update({'font.size': 12})
def take_second(elem): # function for taking the names out of files
return elem[1]
identifier = ['2019lepto03']
identifier = ['2018lepto4']
for ident in identifier:
predict = []
@@ -35,16 +37,16 @@ for ident in identifier:
currf = None
idxlist = []
data = sorted(np.load('5Hz_%s files.npy' %ident), key = take_second) # list with filenames in it
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('5Hz_%s.npy' %dd) # load data for every file name
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('5Hz_%s time.npy' %dd) # time file
time = np.load('%s time.npy' %dd) # time file
dt = time[1] - time[0]
n = int(1/float(d[1])/dt)
@@ -122,26 +124,27 @@ for ident in identifier:
# 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()
fig = plt.figure(figsize = (8,14))
fig.suptitle('gaincurve and RMS 2018lepto4')
ax0 = fig.add_subplot(2, 1, 1)
ax0.plot(amfreq_arr[idx_arr], mgain_arr[idx_arr], 'o')
ax0.plot(amfreq_arr, mgain_arr, 'o')
ax0.set_yscale('log')
ax0.set_xscale('log')
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])
ax0.axes.xaxis.set_ticklabels([])
plt.text(-0.1, 1.05, "A)", fontweight=550, transform=ax0.transAxes)
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_xlabel('envelope frequency [Hz]')
ax1.set_ylabel('RMS [Hz]')
plt.text(-0.1, 1.05, "B)", fontweight=550, transform=ax1.transAxes)
plt.legend()
pylab.show()
#fig.savefig('test.pdf')
#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])

View File

@@ -18,20 +18,49 @@ identifier = [#'2018lepto1',
#'2019lepto30',
#'2020lepto04',
#'2020lepto06',
'2020lepto16',
#'2020lepto16',
'2020lepto19',
'2020lepto20'
#'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('5Hz_gain_%s.npy' %ident)
data = np.load('gain_%s.npy' %ident)
all.append(data)
av = avgNestedLists(all)
embed()
fig = plt.figure()
ax = fig.add_subplot(111)
@@ -45,10 +74,10 @@ fit = []
fit_amf = []
for ID in identifier:
print(ID)
amf = np.load('5Hz_amf_%s.npy' %ID)
gain = np.load('5Hz_gain_%s.npy' %ID)
amf = np.load('amf_%s.npy' %ID)
gain = np.load('gain_%s.npy' %ID)
sinv, sinc = curve_fit(gain_curve_fit, amf, gain)
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]))
@@ -63,7 +92,7 @@ for ff ,f in enumerate(fit):
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_title('gain average all fish, deltaf: -5Hz')
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, )

View File

@@ -93,6 +93,7 @@ for ID in identifier_uniform:
tau_uniform.append(sinv[0])
f_cutoff = abs(1 / (2*np.pi*sinv[0]))
print('f_cutoff:', f_cutoff)
print('alpha:', sinv[1])
f_c_uniform.append(f_cutoff)
fit_uniform.append(gain_curve_fit(amf, *sinv))
fit_amf_uniform.append(amf)

View File

@@ -0,0 +1,45 @@
from IPython import embed
import numpy as np
import matplotlib.pyplot as plt
from jar_functions import sin_response
plt.rcParams.update({'font.size': 12})
# AM model
lower = 0
upper = 200
sample = 1000
x = np.linspace(lower, upper, sample)
y1 = (sin_response(np.linspace(lower, upper, sample), 0.02, -np.pi/2, -0.75) - 1)
y2 = (sin_response(np.linspace(lower, upper, sample), 0.02, -np.pi/2, 0.75) + 1)
fig = plt.figure(figsize = (12,6))
ax = fig.add_subplot(121)
ax.plot(x, y1, c = 'red')
ax.plot(x, y2, c = 'red')
ax.fill_between(x, y1, y2)
ax.set_xlabel('time[s]')
ax.set_ylabel('amplitude')
ax.set_xlim(0,200)
ax.axes.yaxis.set_ticks([])
plt.text(-0.1, 1.05, "A)", fontweight=550, transform=ax.transAxes)
# carrier
lower = 0
upper = 10
sample = 1000
x = np.linspace(lower, upper, sample)
y1 = (sin_response(np.linspace(lower, upper, sample), 800, np.pi, -0.75) - 1)
ax1 = fig.add_subplot(122)
ax1.plot(x, y1)
ax1.axhline(y = -0.25, c = 'red', lw = 2)
ax1.axhline(y = -1.75, c = 'red', lw = 2)
ax1.set_xlabel('time[ms]')
ax1.set_xlim(0,10)
ax1.axes.get_yaxis().set_visible(False)
plt.text(-0.1, 1.05, "B)", fontweight=550, transform=ax1.transAxes)
plt.show()

View File

@@ -3,7 +3,6 @@ import numpy as np
from IPython import embed
import matplotlib.pyplot as plt
from jar_functions import parse_infodataset
from jar_functions import adjust_eodf
base_path = 'D:\\jar_project\\JAR\\sin'
@@ -36,5 +35,5 @@ for ID in identifier:
print(i)
print(np.mean(temperature))
av_temperature.append(np.mean(temperature))
np.save('temperature.npy', av_temperature)
embed()