Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent Capture from crashing during calibration when there is no reference data #1960

Merged
merged 5 commits into from
Jul 7, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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