Skip to content

Commit

Permalink
Add Python Representation data options.
Browse files Browse the repository at this point in the history
This patch adds `eye0-pyrep`, `eye1-pyrep`, `gaze_x-pyrep`, and
`gaze_x-pyrep` to the options for 'data_names' in the YAML config.
This is only available if an XDF with the Python Representation is
added. Also, if no 'Primitive' data is foud, the data names with no
suffixed `-pyrep` will be set to the `diameter` option, which is the
data uncorrected for perspective.
  • Loading branch information
gmierz committed Aug 28, 2018
1 parent 0ff4ebf commit 76ab244
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pupillib/core/workers/processors/trigger_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,10 @@ def get_percent_change(trigger_data, config):
proc_trial_data = trigger_data['trials']

for trial_num, trial_info in proc_trial_data.items():
bmean = abs(trial_info['baseline_mean'])
bmean = trial_info['baseline_mean']
data = copy.deepcopy(trial_info['trial_rmbaseline']['data'])

if bmean and bmean > 0:
if bmean and bmean != 0:
pcs[trial_num] = data / bmean
else:
self.logger.send('WARNING', 'Baseline mean is 0 or undefined for a trial for name: ' + trial_info['config']['name'],
Expand Down
124 changes: 120 additions & 4 deletions pupillib/core/workers/processors/xdfloader_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ def get_primitives_column(primitive_entry, config):
col_num = config['num']
return np.asarray(primitive_entry['time_series'][:, col_num])

@transform
def get_pyrep_column(pyrep_entry, config):
val2get = config['name']
if 'num' in config:
num2get = config['num']
vals = [eval(el[0])[val2get][num2get] for el in pyrep_entry['time_series']]
else:
vals = [eval(el[0])[val2get] for el in pyrep_entry['time_series']]
return np.asarray(vals)

@transform
def get_xdf_timestamps(entry, config):
return np.asarray(list(entry['time_stamps']))

@transform
def srate(no_data, config):
data = config['data']
Expand Down Expand Up @@ -166,7 +180,7 @@ def data_name_to_function(self, data_type):
}
},
{ # Get timestamps
'fn_name': 'get_primitives_column',
'fn_name': 'get_xdf_timestamps',
'field': 'timestamps',
'config': {
'num': 2
Expand All @@ -191,7 +205,57 @@ def data_name_to_function(self, data_type):
}
},
{ # Get timestamps
'fn_name': 'get_primitives_column',
'fn_name': 'get_xdf_timestamps',
'field': 'timestamps',
'config': {
'num': 2
}
},
{ # Get sampling rate
'fn_name': 'srate',
'field': 'srate',
'config': {
'data': None,
'timestamps': None
}
},
],

'eye0-pyrep': [
{ # Get data
'fn_name': 'get_pyrep_column',
'field': 'data',
'config': {
'name': 'diameter_3d'
}
},
{ # Get timestamps
'fn_name': 'get_xdf_timestamps',
'field': 'timestamps',
'config': {
'num': 2
}
},
{ # Get sampling rate
'fn_name': 'srate',
'field': 'srate',
'config': {
'data': None,
'timestamps': None
}
},
],

'eye1-pyrep': [
{ # Get data
'fn_name': 'get_pyrep_column',
'field': 'data',
'config': {
'name': 'diameter_3d'
}
},
{ # Get timestamps
'fn_name': 'get_xdf_timestamps',
'field': 'timestamps',
'config': {
'num': 2
Expand All @@ -216,7 +280,7 @@ def data_name_to_function(self, data_type):
}
},
{ # Get timestamps
'fn_name': 'get_primitives_column',
'fn_name': 'get_xdf_timestamps',
'field': 'timestamps',
'config': {
'num': 2
Expand All @@ -241,7 +305,59 @@ def data_name_to_function(self, data_type):
}
},
{ # Get timestamps
'fn_name': 'get_primitives_column',
'fn_name': 'get_xdf_timestamps',
'field': 'timestamps',
'config': {
'num': 2
}
},
{ # Get sampling rate
'fn_name': 'srate',
'field': 'srate',
'config': {
'data': None,
'timestamps': None
}
},
],

'gaze_x-pyrep': [
{ # Get data
'fn_name': 'get_pyrep_column',
'field': 'data',
'config': {
'name': 'norm_pos',
'num': 0
}
},
{ # Get timestamps
'fn_name': 'get_xdf_timestamps',
'field': 'timestamps',
'config': {
'num': 2
}
},
{ # Get sampling rate
'fn_name': 'srate',
'field': 'srate',
'config': {
'data': None,
'timestamps': None
}
},
],

'gaze_y-pyrep': [
{ # Get data
'fn_name': 'get_pyrep_column',
'field': 'data',
'config': {
'name': 'norm_pos',
'num': 1
}
},
{ # Get timestamps
'fn_name': 'get_xdf_timestamps',
'field': 'timestamps',
'config': {
'num': 2
Expand Down
31 changes: 23 additions & 8 deletions pupillib/pupil_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ def xdf_pupil_load(dataset, xdf_file_and_name, data_num=0):
markers_stream = None
eye0_stream = None
eye1_stream = None
eye0pyrep_stream = None
eye1pyrep_stream = None
gaze_stream = None
gazepyrep_stream = None

# Data structures are all over the place
# so these checks are necessary.
Expand All @@ -130,12 +133,19 @@ def xdf_pupil_load(dataset, xdf_file_and_name, data_num=0):
if 'info' in i:
if i['info']['name'][0] == 'Gaze Primitive Data':
gaze_stream = i
elif i['info']['name'][0] == 'Gaze Python Representation':
gazepyrep_stream = i
elif i['info']['name'][0] == 'Pupil Primitive Data - Eye 1':
eye1_stream = i
elif i['info']['name'][0] == 'Pupil Primitive Data - Eye 0':
eye0_stream = i
elif i['info']['type'][0] == 'Markers':
markers_stream = i
elif i['info']['name'][0] == 'Pupil Python Representation - Eye 1':
eye1pyrep_stream = i
elif i['info']['name'][0] == 'Pupil Python Representation - Eye 0':
eye0pyrep_stream = i

custom_data = False
for a_name in name_list:
if a_name != 'eye0' and a_name != 'eye1':
Expand All @@ -144,14 +154,21 @@ def xdf_pupil_load(dataset, xdf_file_and_name, data_num=0):
data_entries = {
'eye1': eye1_stream,
'eye0': eye0_stream,
'eye1-pyrep': eye1pyrep_stream,
'eye0-pyrep': eye0pyrep_stream,
'gaze_x': gaze_stream,
'gaze_y': gaze_stream,
'gaze_x-pyrep': gazepyrep_stream,
'gaze_y-pyrep': gazepyrep_stream,
'marks': markers_stream,

'all': {
'eye1': eye1_stream,
'eye0': eye0_stream,
'eye1-pyrep': eye1pyrep_stream,
'eye0-pyrep': eye0pyrep_stream,
'gaze': gaze_stream,
'gaze-pyrep': gazepyrep_stream,
'marks': markers_stream,
}
}
Expand Down Expand Up @@ -221,15 +238,13 @@ def recurse_new_config(old_config, res):
'eventnames': xdf_transforms['get_marker_eventnames'](markers_stream, {})
}

dataset['custom_data'] = custom_data

#print(str(type(gaze_stream['time_series'])))
#print(len(gaze_stream['time_series']))
#print(gaze_stream['time_series'][0])
# If a primitive wasn't obtained, give a 'primitive' like response
if not all_data['eye1'] and all_data['eye1-pyrep']:
all_data = [eval(el)['diameter'] for el in eye1pyrep_stream['time_series']]
if not all_data['eye0'] and all_data['eye0-pyrep']:
all_data = [eval(el)['diameter'] for el in eye0pyrep_stream['time_series']]

# print(gaze_stream['time_series'][0][0])
# tmp_dict = ast.literal_eval(gaze_stream['time_series'][0][0])
# print(tmp_dict['timestamp'])
dataset['custom_data'] = custom_data

new_dict = all_data
for entry in dataset:
Expand Down

0 comments on commit 76ab244

Please sign in to comment.