26.08
This commit is contained in:
parent
4a58f1382f
commit
21d613222c
@ -107,8 +107,6 @@ def mean_noise_cut(frequencies, time, n):
|
|||||||
if k == 0:
|
if k == 0:
|
||||||
cutf[:kkk] = f
|
cutf[:kkk] = f
|
||||||
cutf[kkk] = f
|
cutf[kkk] = f
|
||||||
#t = time[kk]
|
|
||||||
#cutt[kkk] = t
|
|
||||||
cutf[kkk:] = f
|
cutf[kkk:] = f
|
||||||
return cutf
|
return cutf
|
||||||
|
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 308 KiB |
@ -10,26 +10,41 @@ from jar_functions import mean_noise_cut
|
|||||||
def take_second(elem): # function for taking the names out of files
|
def take_second(elem): # function for taking the names out of files
|
||||||
return elem[1]
|
return elem[1]
|
||||||
|
|
||||||
predict = []
|
identifier = ['2018lepto1',
|
||||||
|
'2018lepto4',
|
||||||
rootmeansquare = []
|
'2018lepto5',
|
||||||
threshold = []
|
'2018lepto76',
|
||||||
|
'2018lepto98',
|
||||||
gain = []
|
'2019lepto03',
|
||||||
mgain = []
|
'2019lepto24',
|
||||||
phaseshift = []
|
'2019lepto27',
|
||||||
mphaseshift = []
|
'2019lepto30',
|
||||||
amfreq = []
|
'2020lepto04',
|
||||||
amf = [0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1]
|
'2020lepto06',
|
||||||
|
'2020lepto16',
|
||||||
currf = None
|
'2020lepto19',
|
||||||
idxlist = []
|
'2020lepto20'
|
||||||
|
]
|
||||||
identifier = '2020lepto06'
|
for ident in identifier:
|
||||||
|
|
||||||
data = sorted(np.load('%s files.npy' %identifier), key = take_second) # list with filenames in it
|
predict = []
|
||||||
|
|
||||||
for i, d in enumerate(data):
|
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)
|
dd = list(d)
|
||||||
jar = np.load('%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
|
jm = jar - np.mean(jar) # low-pass filtering by subtracting mean
|
||||||
@ -41,34 +56,30 @@ for i, d in enumerate(data):
|
|||||||
n = int(1/float(d[1])/dt)
|
n = int(1/float(d[1])/dt)
|
||||||
cutf = mean_noise_cut(jm, time, n = n)
|
cutf = mean_noise_cut(jm, time, n = n)
|
||||||
cutt = time
|
cutt = time
|
||||||
plt.plot(time, jm-cutf, label='cut amfreq')
|
# plt.plot(time, jm-cutf, label='cut amfreq')
|
||||||
plt.plot(time, jm, label='spec')
|
# plt.plot(time, jm, label='spec')
|
||||||
#plt.legend()
|
# plt.legend()
|
||||||
#plt.show()
|
# plt.show()
|
||||||
|
|
||||||
b, a = signal.butter(4, (float(d[1])) / (0.5/dt), 'high', analog=True) # high pass filtering so our fit gets a bit better
|
sinv, sinc = curve_fit(sin_response, time, jm - cutf, [float(d[1]), 2, 0.5]) # fitting
|
||||||
y = signal.filtfilt(b, a, jm)
|
|
||||||
#plt.plot(time, y)
|
|
||||||
#plt.plot(time, jm)
|
|
||||||
|
|
||||||
sinv, sinc = curve_fit(sin_response, time, y, [float(d[1]), 2, 0.5]) # fitting
|
|
||||||
print('frequency, phaseshift, amplitude:', sinv)
|
print('frequency, phaseshift, amplitude:', sinv)
|
||||||
p = np.sqrt(sinv[1]**2)
|
p = np.sqrt(sinv[1]**2)
|
||||||
A = np.sqrt(sinv[2] ** 2)
|
A = np.sqrt(sinv[2] ** 2)
|
||||||
f = float(d[1])
|
f = float(d[1])
|
||||||
phaseshift.append(p)
|
phaseshift.append(p)
|
||||||
gain.append(A)
|
gain.append(A)
|
||||||
|
if f not in amfreq:
|
||||||
amfreq.append(f)
|
amfreq.append(f)
|
||||||
'''
|
|
||||||
# root mean square
|
# root mean square
|
||||||
RMS = np.sqrt(np.mean((cutf_arr - sin_response(cutt_arr, sinv[0], sinv[1], sinv[2]))**2))
|
RMS = np.sqrt(np.mean(((jm - cutf) - sin_response(cutt, sinv[0], sinv[1], sinv[2]))**2))
|
||||||
rootmeansquare.append(RMS)
|
|
||||||
thresh = A / np.sqrt(2)
|
thresh = A / np.sqrt(2)
|
||||||
threshold.append(thresh)
|
|
||||||
'''
|
# plt.plot(time, sin_response(time, *sinv), label='fit: f=%f, p=%.2f, A=%.2f' % tuple(sinv))
|
||||||
plt.plot(time, sin_response(time, *sinv), label='fit: f=%f, p=%.2f, A=%.2f' % tuple(sinv))
|
# plt.legend()
|
||||||
plt.legend()
|
# plt.show()
|
||||||
plt.show()
|
|
||||||
# mean over same amfreqs for phase and gain
|
# mean over same amfreqs for phase and gain
|
||||||
if currf is None or currf == d[1]:
|
if currf is None or currf == d[1]:
|
||||||
currf = d[1]
|
currf = d[1]
|
||||||
@ -77,51 +88,80 @@ for i, d in enumerate(data):
|
|||||||
else: # currf != f
|
else: # currf != f
|
||||||
meanf = [] # lists to make mean of
|
meanf = [] # lists to make mean of
|
||||||
meanp = []
|
meanp = []
|
||||||
|
meanrms = []
|
||||||
|
meanthresh = []
|
||||||
for x in idxlist:
|
for x in idxlist:
|
||||||
meanf.append(gain[x])
|
meanf.append(gain[x])
|
||||||
meanp.append(phaseshift[x])
|
meanp.append(phaseshift[x])
|
||||||
|
meanrms.append(RMS)
|
||||||
|
meanthresh.append(thresh)
|
||||||
meanedf = np.mean(meanf)
|
meanedf = np.mean(meanf)
|
||||||
meanedp = np.mean(meanp)
|
meanedp = np.mean(meanp)
|
||||||
|
meanedrms = np.mean(meanrms)
|
||||||
|
meanedthresh = np.mean(meanthresh)
|
||||||
mgain.append(meanedf)
|
mgain.append(meanedf)
|
||||||
mphaseshift.append(meanedp)
|
mphaseshift.append(meanedp)
|
||||||
|
rootmeansquare.append(meanedrms)
|
||||||
|
threshold.append(meanedthresh)
|
||||||
currf = d[1] # set back for next loop
|
currf = d[1] # set back for next loop
|
||||||
idxlist = [i]
|
idxlist = [i]
|
||||||
meanf = []
|
meanf = []
|
||||||
meanp = []
|
meanp = []
|
||||||
for y in idxlist:
|
meanrms = []
|
||||||
|
meanthresh = []
|
||||||
|
for y in idxlist:
|
||||||
meanf.append(gain[y])
|
meanf.append(gain[y])
|
||||||
meanp.append(phaseshift[y])
|
meanp.append(phaseshift[y])
|
||||||
meanedf = np.mean(meanf)
|
meanrms.append(RMS)
|
||||||
meanedp = np.mean(meanp)
|
meanthresh.append(thresh)
|
||||||
mgain.append(meanedf)
|
meanedf = np.mean(meanf)
|
||||||
mphaseshift.append(meanedp)
|
meanedp = np.mean(meanp)
|
||||||
|
meanedrms = np.mean(meanrms)
|
||||||
|
meanedthresh = np.mean(meanthresh)
|
||||||
|
mgain.append(meanedf)
|
||||||
|
mphaseshift.append(meanedp)
|
||||||
|
rootmeansquare.append(meanedrms)
|
||||||
|
threshold.append(meanedthresh)
|
||||||
|
|
||||||
# predict of gain
|
# predict of gain
|
||||||
for f in amf:
|
for f in amf:
|
||||||
G = np.max(mgain) / np.sqrt(1 + (2*((np.pi*f*3.14)**2)))
|
G = np.max(mgain) / np.sqrt(1 + (2*((np.pi*f*3.14)**2)))
|
||||||
predict.append(G)
|
predict.append(G)
|
||||||
|
|
||||||
fig = plt.figure()
|
fig = plt.figure()
|
||||||
ax = fig.add_subplot(1, 1, 1)
|
ax0 = fig.add_subplot(2, 1, 1)
|
||||||
ax.plot(amf, mgain, 'o')
|
ax0.plot(amfreq, mgain(RMS<threshold), 'o')
|
||||||
#ax.plot(amf, predict)
|
#ax0.plot(amf, predict)
|
||||||
ax.set_yscale('log')
|
ax0.set_yscale('log')
|
||||||
ax.set_xscale('log')
|
ax0.set_xscale('log')
|
||||||
ax.set_title('%s' % data[0][0])
|
ax0.set_title('%s' % data[0][0])
|
||||||
ax.set_ylabel('gain [Hz/(mV/cm)]')
|
ax0.set_ylabel('gain [Hz/(mV/cm)]')
|
||||||
ax.set_xlabel('envelope_frequency [Hz]')
|
ax0.set_xlabel('envelope_frequency [Hz]')
|
||||||
#plt.savefig('%s gain' % data[0][0])
|
#plt.savefig('%s gain' % data[0][0])
|
||||||
pylab.show()
|
|
||||||
|
ax1 = fig.add_subplot(2, 1, 2, sharex = ax0)
|
||||||
plt.plot(threshold, label = 'threshold')
|
ax1.plot(amfreq, threshold, 'o-', label = 'threshold', color = 'b')
|
||||||
plt.plot(rootmeansquare, label = 'RMS')
|
ax1.set_xscale('log')
|
||||||
plt.legend()
|
ax1.plot(amfreq, rootmeansquare, 'o-', label = 'RMS', color = 'orange')
|
||||||
plt.show()
|
ax1.set_xscale('log')
|
||||||
|
ax1.set_xlabel('envelope_frequency [Hz]')
|
||||||
|
ax1.set_ylabel('RMS')
|
||||||
|
plt.legend()
|
||||||
|
pylab.show()
|
||||||
|
|
||||||
embed()
|
embed()
|
||||||
|
|
||||||
# phase in degree
|
# zu eigenmannia: jeden fisch mit amplituden von max und min von modulationstiefe und evtl 1 oder 2 dazwischen
|
||||||
# Q10 / conductivity
|
# und dann für die am frequenzen von apteronotus für 15Hz delta f messen
|
||||||
# AM-frequency / envelope-frequency scale title?
|
|
||||||
|
# mit zu hohem RMS rauskicken: gain/rms < ... (?)
|
||||||
|
# gain kurven als array abspeichern
|
||||||
|
# daten von natalie zu eigenmannia mit + / - delta f anschauen ob unterschiede
|
||||||
|
# unterschiedliche nffts auf anderem rechner laufen lassen evtl um unterschiede zu sehen?
|
||||||
|
|
||||||
|
|
||||||
# einfach passendes n verwenden um AM-beats rauszufiltern? ...Menge Datenpunkte zu gering
|
# long term: extra datei mit script drin um fertige daten darzustellen, den code hier als datenverarbeitung allein verwenden
|
||||||
|
# darstellung: specgram --> rausgezogene jarspur darüber --> filterung --> fit und daten zusammen dargestellt, das ganze für verschiedene frequenzen
|
||||||
|
# liste mit eigenschaften der fische (dominanz/größe) und messvariablen (temp/conductivity) machen um diese plotten zu können
|
||||||
|
|
||||||
|
# phase in degree
|
@ -21,18 +21,7 @@ from jar_functions import average
|
|||||||
from jar_functions import import_data
|
from jar_functions import import_data
|
||||||
from jar_functions import import_amfreq
|
from jar_functions import import_amfreq
|
||||||
|
|
||||||
base_path = 'D:\\jar_project\\JAR\\sin\\2020lepto04'
|
base_path = 'D:\\jar_project\\JAR\\sin\\2019lepto03'
|
||||||
|
|
||||||
datasets = ['2020-07-22-ab',
|
|
||||||
'2020-07-22-ac',
|
|
||||||
'2020-07-22-ad',
|
|
||||||
'2020-07-22-ae',
|
|
||||||
'2020-07-22-af',
|
|
||||||
'2020-07-22-ag',
|
|
||||||
'2020-07-23-ab',
|
|
||||||
'2020-07-23-ac',
|
|
||||||
'2020-07-23-ad',
|
|
||||||
'2020-07-23-ae']
|
|
||||||
|
|
||||||
time_all = []
|
time_all = []
|
||||||
freq_all = []
|
freq_all = []
|
||||||
@ -41,23 +30,25 @@ amfrequencies = []
|
|||||||
gains = []
|
gains = []
|
||||||
files = []
|
files = []
|
||||||
|
|
||||||
ID = []
|
for idx, dataset in enumerate(os.listdir(base_path)):
|
||||||
|
if dataset == 'prerecordings':
|
||||||
for idx, dataset in enumerate(datasets):
|
continue
|
||||||
datapath = os.path.join(base_path, dataset, '%s.nix' % dataset)
|
datapath = os.path.join(base_path, dataset, '%s.nix' % dataset)
|
||||||
print(datapath)
|
print(datapath)
|
||||||
|
|
||||||
data, pre_data, dt = import_data(datapath)
|
data, pre_data, dt = import_data(datapath)
|
||||||
|
|
||||||
nfft = 2**17
|
nfft = 2**17
|
||||||
|
|
||||||
for d, dat in enumerate(data):
|
for d, dat in enumerate(data):
|
||||||
file_name = []
|
if len(dat) == 1:
|
||||||
|
continue
|
||||||
|
|
||||||
for infodataset in datasets:
|
file_name = []
|
||||||
infodataset = os.path.join(base_path, infodataset, 'info.dat')
|
ID = []
|
||||||
|
|
||||||
i = parse_infodataset(infodataset)
|
# identifier for file_name
|
||||||
|
infodatapath = os.path.join(base_path, dataset, 'info.dat')
|
||||||
|
i = parse_infodataset(infodatapath)
|
||||||
identifier = i[0]
|
identifier = i[0]
|
||||||
if not identifier[1:-2] in ID:
|
if not identifier[1:-2] in ID:
|
||||||
ID.append(identifier[1:-1])
|
ID.append(identifier[1:-1])
|
||||||
@ -109,6 +100,8 @@ for idx, dataset in enumerate(datasets):
|
|||||||
|
|
||||||
# save filenames for this fish
|
# save filenames for this fish
|
||||||
np.save('%s files' %ID[0], files)
|
np.save('%s files' %ID[0], files)
|
||||||
|
print(ID)
|
||||||
embed()
|
embed()
|
||||||
|
|
||||||
# running average over on AM-period?
|
# running average over on AM-period?
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user