Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions aopy/data/eye.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .base import get_preprocessed_filename, load_preproc_eye_data, save_hdf, find_preproc_ids_from_day
from ..postproc import get_calibrated_eye_data

def proc_eye_day(preproc_dir, subject, date, correlation_min=0.9, dry_run=False):
def proc_eye_day(preproc_dir, subject, date, correlation_min=0.9, dry_run=False, overwrite=False):
'''
Finds files from the given subject and date with the best eye calibration and automatically
applies it to every recording on that day for that subject. If no good calibration is found,
Expand All @@ -15,8 +15,9 @@ def proc_eye_day(preproc_dir, subject, date, correlation_min=0.9, dry_run=False)
preproc_dir (str): base directory where the files live
subject (str): Subject name
date (str): Date of recording
correlation_min (float, optional): correlation below which is unacceptable
dry_run (bool, optional): if True, files will not be modified.
correlation_min (float, optional): correlation value below which is unacceptable
dry_run (bool, optional): if True, returns the task id with the best correlation but does not modify any files. Default is False
overwrite (bool, optional): if True, overwrites the existing external calibration. Default is False

Raises:
ValueError
Expand All @@ -28,7 +29,7 @@ def proc_eye_day(preproc_dir, subject, date, correlation_min=0.9, dry_run=False)
'''

# Find best calibration from the given subject and date
te_ids = find_preproc_ids_from_day(preproc_dir, subject, date, 'eye')
te_ids = np.sort(find_preproc_ids_from_day(preproc_dir, subject, date, 'eye'))
if len(te_ids) == 0:
print(f"No preprocessed files found on {date}")
return None, []
Expand All @@ -37,12 +38,12 @@ def proc_eye_day(preproc_dir, subject, date, correlation_min=0.9, dry_run=False)
best_correlation = 0
for te_id in te_ids:
eye_data, eye_metadata = load_preproc_eye_data(preproc_dir, subject, te_id, date)
if 'external_calibration' in eye_metadata and eye_metadata['external_calibration']:
if 'external_calibration' in eye_metadata and eye_metadata['external_calibration'] and not overwrite:
continue # ignore the file if it has already had another calibration applied to it
if 'correlation_coeff' not in eye_data:
continue # ignore if there isn't any calibration data
correlation = np.mean(abs(eye_data['correlation_coeff']))
print(correlation)
print(f'{te_id}: {correlation}')
if correlation > best_correlation and correlation < 1.0: # 1.0 correlations aren't valid
best_id = te_id
best_coeff = eye_data['coefficients']
Expand Down
2 changes: 1 addition & 1 deletion aopy/preproc/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def proc_eyetracking(data_dir, files, result_dir, exp_filename, result_filename,
result_dir (str): where to store the processed result
result_filename (str): what to call the preprocessed filename
debug (bool, optional): if true, prints additional debug messages
overwrite (bool, optional): whether to recalculated and overwrite existing preprocessed eyetracking data
overwrite (bool, optional): whether to recalculate and overwrite existing preprocessed eyetracking data
save_res (bool, optional): whether to save the calculated eyetracking data
**kwargs (dict, optional): keyword arguments to pass to :func:`aopy.preproc.calc_eye_calibration()`

Expand Down
Loading