Skip to content

Commit

Permalink
Merge pull request #1960 from pupil-labs/no-ref-data-crash
Browse files Browse the repository at this point in the history
Prevent Capture from crashing during calibration when there is no reference data
  • Loading branch information
papr committed Jul 7, 2020
2 parents 643b7b1 + a2d617e commit a3139f5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
27 changes: 22 additions & 5 deletions pupil_src/shared_modules/gaze_mapping/gazer_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ class NotEnoughDataError(CalibrationError):
message = "Not sufficient data available."


class NotEnoughPupilDataError(NotEnoughDataError):
message = "Not sufficient pupil data available."


class NotEnoughReferenceDataError(NotEnoughDataError):
message = "Not sufficient reference data available."


class FitDidNotConvergeError(CalibrationError):
message = "Model fit did not converge."

Expand Down Expand Up @@ -194,18 +202,25 @@ def __init__(
self._announce_calibration_setup(calib_data=calib_data)
try:
self.fit_on_calib_data(calib_data)
except CalibrationError:
except CalibrationError as err:
if raise_calibration_error:
raise # Let offline calibration handle this one!
logger.error("Calibration Failed!")
self.alive = False
self._announce_calibration_failure(reason=CalibrationError.__name__)
self._announce_calibration_failure(reason=err.message)
except Exception as err:
import traceback

self._announce_calibration_failure(reason=err.__class__.__name__)
logger.debug(traceback.format_exc())
raise CalibrationError() from err
if raise_calibration_error:
raise CalibrationError() from err # Let offline calibration handle this one!
logger.error("Calibration Failed!")
self.alive = False
try:
reason = err.args[0]
except (AttributeError, IndexError):
reason = err.__class__.__name__
self._announce_calibration_failure(reason=reason)
else:
self._announce_calibration_success()
self._announce_calibration_result(params=self.get_params())
Expand Down Expand Up @@ -257,7 +272,9 @@ def fit_on_calib_data(self, calib_data):
pupil_data, self.g_pool.min_calibration_confidence
)
if not pupil_data:
raise NotEnoughDataError
raise NotEnoughPupilDataError
if not ref_data:
raise NotEnoughReferenceDataError
# match pupil to reference data (left, right, and binocular)
matches = self.match_pupil_to_ref(pupil_data, ref_data)
if matches.binocular[0]:
Expand Down
4 changes: 2 additions & 2 deletions pupil_src/shared_modules/gaze_mapping/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def _filter_pupil_list_by_confidence(pupil_list, threshold):


def _match_data_batch(pupil_list, ref_list):
assert pupil_list
assert ref_list
assert pupil_list, "No pupil data to match"
assert ref_list, "No reference data to match"
pupil0 = [p for p in pupil_list if p["id"] == 0]
pupil1 = [p for p in pupil_list if p["id"] == 1]

Expand Down

0 comments on commit a3139f5

Please sign in to comment.