30.06
This commit is contained in:
parent
c3c92fd42d
commit
77534d6e4a
@ -1,5 +1,6 @@
|
||||
import os #compability with windows
|
||||
from IPython import embed
|
||||
import numpy as np
|
||||
|
||||
def parse_dataset(dataset_name):
|
||||
assert(os.path.exists(dataset_name)) #see if data exists
|
||||
@ -57,16 +58,26 @@ def parse_dataset(dataset_name):
|
||||
|
||||
|
||||
|
||||
def noise_reduce(dataset_name):
|
||||
def noise_reduce(dataset_name, n):
|
||||
assert (os.path.exists(dataset_name)) # see if data exists
|
||||
f = open(dataset_name, 'r') # open data we gave in
|
||||
lines = f.readlines() # read data
|
||||
f.close()
|
||||
|
||||
n = 10
|
||||
#len of frequencies is 10 time shorter than before, so worked?
|
||||
#put in frequencies instead of dataset?
|
||||
#2nd loop cut frequencies by this function?
|
||||
cutf = []
|
||||
for i in np.arange(0, len(dataset_name), n): #dataset_name sollte Frequenzen sein?
|
||||
mean = np.mean(dataset_name[i:i+n]) #sollte nach i+n weitergehen?
|
||||
frequencies = []
|
||||
for i in range(len(lines)):
|
||||
l = lines[i].strip()
|
||||
|
||||
if len(l) > 0 and l[0] is not '#':
|
||||
temporary = list(map(float, l.split()))
|
||||
frequencies.append(temporary[1])
|
||||
|
||||
for k in np.arange(0, len(frequencies), n): # sollte nach k+n weitergehen?
|
||||
f = frequencies[k:k+n]
|
||||
mean = np.mean(f)
|
||||
cutf.append(mean)
|
||||
|
||||
return cutf
|
11
scratch.py
11
scratch.py
@ -1,5 +1,9 @@
|
||||
import os
|
||||
import numpy as np
|
||||
from IPython import embed
|
||||
from jar_functions import noise_reduce
|
||||
|
||||
datasets = [(os.path.join('D:\\jar_project\\JAR\\2020-06-22-ac\\beats-eod.dat'))]
|
||||
|
||||
"""
|
||||
#second_try scratch
|
||||
@ -19,6 +23,8 @@ for f in frequency:
|
||||
|
||||
# mean_f = np.mean(x) for x in zip(freqeuncies1, frequencies2)
|
||||
"""
|
||||
|
||||
'''
|
||||
g = [1, 2]
|
||||
|
||||
h = [3, 4]
|
||||
@ -30,4 +36,7 @@ mean1 = np.mean(z, axis=1)
|
||||
|
||||
print(mean0)
|
||||
print(mean1)
|
||||
|
||||
'''
|
||||
for dataset in datasets:
|
||||
cf = noise_reduce(dataset, 10)
|
||||
embed()
|
@ -26,6 +26,7 @@ timespan = 210
|
||||
for dataset in datasets:
|
||||
#input of the function
|
||||
t, f, a, e, d, s= parse_dataset(dataset)
|
||||
cf = noise_reduce(dataset, n = 10)
|
||||
|
||||
'times'
|
||||
# same for time in both loops
|
||||
@ -49,12 +50,11 @@ for dataset in datasets:
|
||||
# interpolation
|
||||
f1new = np.interp(tnew, t1, f1)
|
||||
|
||||
#new array with frequencies of both loops as two lists put together as an array
|
||||
#new array with frequencies of both loops as two lists put together
|
||||
frequency = np.array([[f0new], [f1new]])
|
||||
#making a mean over both loops with the axis 0 (=averaged in y direction, axis=1 would be over x axis)
|
||||
mf = np.mean(frequency, axis=0).T #.T as transition (1,0) -> (0,1)
|
||||
|
||||
|
||||
#other variant for transition by reshaping in needed dimension
|
||||
mfreshape = np.reshape(mf, (minimumf, 1)) #as ploting is using the first dimension, number of datapoints has to be in the first
|
||||
treshape = np.reshape(tnew, (minimumf, 1))
|
||||
@ -67,18 +67,28 @@ for dataset in datasets:
|
||||
stimulusf.append(s)
|
||||
amplitude.append(a)
|
||||
|
||||
frequency_mean.append(mfreshape)
|
||||
time.append(treshape)
|
||||
frequency_mean.append(mf)
|
||||
time.append(tnew)
|
||||
|
||||
|
||||
cutfreq = noise_reduce(mfreshape)
|
||||
embed()
|
||||
|
||||
'''
|
||||
'controll of interpolation'
|
||||
fig=plt.figure()
|
||||
ax=fig.add_subplot(1,1,1)
|
||||
|
||||
ax.plot(tnew, mf, c = 'r', marker = 'o', ls = 'solid', label = 'new')
|
||||
ax.plot(t0, f0, c = 'b', marker = '+', ls = '-', label = 'loop_0')
|
||||
ax.plot(t1, f1, c= 'g', marker = '+', ls = '-', label = 'loop_1')
|
||||
plt.legend(loc = 'best')
|
||||
#plt.plot(tnew, mf, marker = 'r-o', label = new, t0, f0, marker = 'b-+', label = loop_0, t1, f1, marker = 'g-+', label = loop_1)
|
||||
plt.show()
|
||||
'''
|
||||
|
||||
#plotting
|
||||
'plotting'
|
||||
'''why does append put in a 3rd dimension? plt.plot(time, frequency_mean) '''
|
||||
|
||||
plt.plot(treshape, mfreshape)
|
||||
plt.plot(tnew, mf)
|
||||
plt.xlim([-10,200])
|
||||
#plt.ylim([400, 1000])
|
||||
plt.xlabel('time [s]')
|
||||
|
Loading…
Reference in New Issue
Block a user