Commit 58a4e3fe authored by Lukas Wolf's avatar Lukas Wolf
Browse files

functionality for fix-sac-fix task

parent 3907aa57
......@@ -152,11 +152,6 @@ def get_sacc_data(verbose=True):
start_time = int(event[1])
end_time = int(event[4])
sac_x_end = event[6]
sac_y_end = event[7]
# extract optional information from sEEG.event
# extract the EEG data from sEEG.data
x_datapoint = np.array(data[start_time:end_time])
x_len, y_len = x_datapoint.shape
......@@ -173,6 +168,9 @@ def get_sacc_data(verbose=True):
else:
raise Exception("Choose a valid padding scheme in config.py")
# Extract the label as saccade endposition
sac_x_end = event[6]
sac_y_end = event[7]
y_datapoint = np.array([sac_x_end, sac_y_end])
# Append to X and y
......@@ -319,7 +317,145 @@ def get_fix_sacc_fix_data(verbose=True):
"""
Returns X, y for the gaze regression task with EEG data X only from triplets of fixation-saccade-fixation
"""
pass
L_saccade = 'L_saccade'
L_fixation = 'L_fixation'
#L_blink = 'L_blink'
R_saccade = 'R_saccade'
R_fixation = 'R_fixation'
#R_blink = 'R_blink'
fixations = [L_fixation, R_fixation]
saccades = [L_saccade, R_saccade]
# Loop over all directories in /data/full_data and extract and concat the events from all people
rootdir = './data/full_data' # modify it if necessary
x_list = []
y_list = []
for subdir, dirs, files in os.walk(rootdir):
for file in files:
# Get the correct path to the current file
path = os.path.join(subdir, file)
events = load_sEEG_events(path) # access event i via events[i]
data = load_sEEG_data(path)
# We now look for fixation-sacade-fixation triplets without blinks or other actions inbetween
# Extract X and y from sEEG.data and sEEG.events
for i in range(len(events)):
first_event = events[i]
first_event_name = first_event[0][0] # dereference the event name, e.g. 'L_saccade'
if first_event_name not in fixations:
continue # we first want a saccade
# We found a fixation as first event, now look for a following saccade
second_event = events[i + 1]
second_event_name = second_event[0][0]
if second_event_name not in saccades:
continue
# We found a following saccade, now look for a following fixation again
third_event = events[i + 2]
third_event_name = third_event[0][0]
if third_event_name not in fixations:
continue
# We finally found a triplet (segment) without interferences of blinks or pushing buttons
fixation1 = first_event
saccade = second_event
fixation2 = third_event
# Pad the first fixation
fixation1_start_time = int(fixation1[1])
fixation1_end_time = int(fixation1[4])
fixation1_datapoint = np.array(data[fixation1_start_time:fixation1_end_time])
x_len_fix1, y_len_fix1 = fixation1_datapoint.shape
if x_len_fix1 < config['min_duration'] or x_len_fix1 > config['max_duration']:
continue
fixation1_padding_size = config['max_duration'] - x_len_fix1
if config['padding'] == 'zero':
fixation1_datapoint = np.pad(fixation1_datapoint, pad_width=((0,fixation1_padding_size),(0,0)))
elif config['padding'] == 'repeat':
fixation1_datapoint = np.pad(fixation1_datapoint, pad_width=((0,fixation1_padding_size),(0,0)), mode='reflect')
else:
raise Exception("Choose a valid padding scheme in config.py")
# Pad the saccade
saccade_start_time = int(saccade[1])
saccade_end_time = int(saccade[4])
saccade_datapoint = np.array(data[saccade_start_time:saccade_end_time])
x_len_sac, y_len_sac = saccade_datapoint.shape
if x_len_sac < 10 or x_len_sac > 100:
continue
saccade_padding_size = 100 - x_len_sac
if config['padding'] == 'zero':
saccade_datapoint = np.pad(saccade_datapoint, pad_width=((0,saccade_padding_size),(0,0)))
elif config['padding'] == 'repeat':
saccade_datapoint = np.pad(saccade_datapoint, pad_width=((0,saccade_padding_size),(0,0)), mode='reflect')
else:
raise Exception("Choose a valid padding scheme in config.py")
# Pad the second fixation
fixation2_start_time = int(fixation2[1])
fixation2_end_time = int(fixation2[4])
fixation2_datapoint = np.array(data[fixation2_start_time:fixation2_end_time])
x_len_fix2, y_len_fix2 = fixation2_datapoint.shape
if x_len_fix2 < config['min_duration'] or x_len_fix2 > config['max_duration']:
continue
fixation2_padding_size = config['max_duration'] - x_len_fix2
if config['padding'] == 'zero':
fixation2_datapoint = np.pad(fixation2_datapoint, pad_width=((0,fixation2_padding_size),(0,0)))
elif config['padding'] == 'repeat':
fixation2_datapoint = np.pad(fixation2_datapoint, pad_width=((0,fixation2_padding_size),(0,0)), mode='reflect')
else:
raise Exception("Choose a valid padding scheme in config.py")
# Stack the fixation, saccade and fixation as one datapoint
x_datapoint = np.concatenate((fixation1_datapoint, saccade_datapoint), axis=0)
x_datapoint = np.concatenate((x_datapoint, fixation2_datapoint), axis=0)
# Extract the difference vector of labels of the two fixations
fix1_avg_x = fixation1[11]
fix1_avg_y = fixation1[12]
fix2_avg_x = fixation2[11]
fix2_avg_y = fixation2[12]
dx = fix2_avg_x - fix1_avg_x
dy = fix2_avg_y - fix1_avg_y
y_datapoint = np.array([dx, dy])
# Append to X and y
x_list.append([x_datapoint])
y_list.append([y_datapoint])
X = np.asarray(x_list)
y = np.asarray(y_list)
if verbose:
logging.info("y training loaded.")
logging.info(y.shape)
logging.info("X training loaded.")
logging.info(X.shape)
X_reshaped = np.transpose(X, (0,2,3,1))
# Cut off the last 4 columns (time, x, y, pupil size)
X_reshaped = X_reshaped[:,:,:129,:]
y_reshaped = np.transpose(y, (0,2,1,3,4))
if verbose:
logging.info("Settings the shapes")
logging.info(X_reshaped.shape)
logging.info(y_reshaped.shape)
return X_reshaped, y_reshaped
def load_sEEG_events(abs_dir_path):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment