93 lines
3.6 KiB
Python
93 lines
3.6 KiB
Python
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
|
|
f = open(dataset_name, 'r') #open data we gave in
|
|
lines = f.readlines() #read data
|
|
f.close() #?
|
|
|
|
# metadata lists for every loop
|
|
eodfs = []
|
|
deltafs = []
|
|
stimulusfs = []
|
|
|
|
# data itself
|
|
times = []
|
|
frequencies = []
|
|
amplitudes = []
|
|
|
|
# temporary lists with data we put in the lists above
|
|
time = []
|
|
ampl = []
|
|
freq = []
|
|
|
|
for i in range(len(lines)):
|
|
l = lines[i].strip() #all lines of textdata, exclude all empty lines (empty () default for spacebar)
|
|
if "#" in l and "EODf" in l: #if line starts with # EODf:
|
|
eodfs.append(float(l.split(':')[-1].strip()[:-2])) #append: line splitted by ':' the 2nd part ([-1],
|
|
if "#" in l and "Delta f" in l: #which got striped so we sure there is no space at the end,
|
|
deltafs.append(float(l.split(':')[-1].strip()[:-2])) #from that all expect the last two signs (Hz unit)
|
|
if "#" in l and "StimulusFrequency" in l: #this for different metadata in different lists
|
|
stimulusfs.append(float(l.split(':')[-1].strip()[:-2]))
|
|
|
|
if '#Key' in l:
|
|
if len(time) != 0: #therefore empty in the first round
|
|
times.append(time) #2nd loop means time != 0, so we put the times/amplitudes/frequencies to
|
|
amplitudes.append(ampl) #the data of the first loop
|
|
frequencies.append(freq)
|
|
|
|
time = [] #temporary lists to overwrite the lists with the same name we made before
|
|
ampl = [] #so they are empty again
|
|
freq = []
|
|
|
|
if len(l) > 0 and l[0] is not '#': #line not empty and doesnt start with #
|
|
temporary = list(map(float, l.split())) #temporary list where we got 3 index splitted by spacebar, map to find them
|
|
time.append(temporary[0]) #temporary lists with the data at that place, respectively
|
|
freq.append(temporary[1])
|
|
ampl.append(temporary[2])
|
|
|
|
times.append(time) #append data from one list to another
|
|
amplitudes.append(ampl) #these append the data from the first loop to the final lists, because we overwrite them (?)
|
|
frequencies.append(freq)
|
|
|
|
return times, frequencies, amplitudes, eodfs, deltafs, stimulusfs #output of the function
|
|
|
|
|
|
def mean_noise_cut(frequencies, time, n):
|
|
cutf = []
|
|
cutt = []
|
|
for k in np.arange(0, len(time), n):
|
|
f = frequencies[k:k+n]
|
|
t = time[k]
|
|
mean = np.mean(f)
|
|
cutf.append(mean)
|
|
cutt.append(t)
|
|
return cutf, cutt
|
|
|
|
def step_response(t, a1, a2, tau1, tau2):
|
|
r_step = a1*(1 - np.exp(-t/tau1)) + a2*(1- np.exp(-t/tau2))
|
|
return r_step
|
|
# plotten mit manual values for a1, ...
|
|
# auch mal a1 oder a2 auf Null setzen.
|
|
|
|
|
|
|
|
def normalized_JAR(frequencies, time, onset=0, offset=100):
|
|
|
|
onset_point = onset - 10
|
|
offset_point = offset - 10
|
|
embed()
|
|
base_eod = []
|
|
step_eod = []
|
|
|
|
np.mean(f[(time >= onset_point) & time < onset])
|
|
for i in range(len(frequencies)):
|
|
if time < onset and time > onset_point:
|
|
|
|
base_eod.append(frequencies[i])
|
|
|
|
if time[i] < offset and time[i] > offset_range:
|
|
step_eod.append(frequencies[i])
|