diff --git a/bcipy/display/paradigm/vep/codes.py b/bcipy/display/paradigm/vep/codes.py index 41e75699c..14b9fdeee 100644 --- a/bcipy/display/paradigm/vep/codes.py +++ b/bcipy/display/paradigm/vep/codes.py @@ -63,3 +63,16 @@ def ssvep_to_code(refresh_rate: int = 60, flicker_rate: int = 10) -> List[int]: t = 1 - t return codes + + +def round_refresh_rate(rate: float) -> int: + """Round the given display rate to the nearest 10s value. + + >>> round_refresh_rate(59.12) + 60 + >>> round_refresh_rate(61.538) + 60 + >>> round_refresh_rate(121.23) + 120 + """ + return int(round(rate, -1)) diff --git a/bcipy/display/paradigm/vep/display.py b/bcipy/display/paradigm/vep/display.py index 5e7cfed65..6f7c3bba4 100644 --- a/bcipy/display/paradigm/vep/display.py +++ b/bcipy/display/paradigm/vep/display.py @@ -11,7 +11,8 @@ from bcipy.display.components.layout import scaled_size from bcipy.display.components.task_bar import TaskBar from bcipy.display.paradigm.matrix.layout import symbol_positions -from bcipy.display.paradigm.vep.codes import create_vep_codes +from bcipy.display.paradigm.vep.codes import (create_vep_codes, + round_refresh_rate) from bcipy.display.paradigm.vep.layout import BoxConfiguration, animation_path from bcipy.display.paradigm.vep.vep_stim import VEPStim from bcipy.helpers.clock import Clock @@ -52,7 +53,7 @@ def __init__(self, frame_rate = self.window.getActualFrameRate() assert frame_rate, 'An accurate window frame rate could not be established' self.window_size = self.window.size # [w, h] - self.refresh_rate = round(frame_rate) + self.refresh_rate = round_refresh_rate(frame_rate) self.logger = logging.getLogger(__name__) # number of VEP text areas diff --git a/bcipy/display/tests/vep/test_codes.py b/bcipy/display/tests/vep/test_codes.py index 56f399796..cd0584dbb 100644 --- a/bcipy/display/tests/vep/test_codes.py +++ b/bcipy/display/tests/vep/test_codes.py @@ -1,6 +1,6 @@ import unittest -from bcipy.display.paradigm.vep.codes import ssvep_to_code +from bcipy.display.paradigm.vep.codes import round_refresh_rate, ssvep_to_code from bcipy.helpers.exceptions import BciPyCoreException @@ -61,6 +61,12 @@ def test_insufficient_flicker_rate(self): with self.assertRaises(BciPyCoreException): ssvep_to_code(refresh_rate, flicker_rate) + def test_round_rate(self): + """Test rounding the refresh rate""" + self.assertEqual(60, round_refresh_rate(59.12)) + self.assertEqual(60, round_refresh_rate(61.538)) + self.assertEqual(120, round_refresh_rate(121.23)) + if __name__ == '__main__': unittest.main() diff --git a/bcipy/task/paradigm/vep/calibration.py b/bcipy/task/paradigm/vep/calibration.py index 94945c753..29030bbe6 100644 --- a/bcipy/task/paradigm/vep/calibration.py +++ b/bcipy/task/paradigm/vep/calibration.py @@ -8,7 +8,7 @@ from bcipy.display import InformationProperties, VEPStimuliProperties from bcipy.display.components.layout import centered from bcipy.display.components.task_bar import CalibrationTaskBar -from bcipy.display.paradigm.vep.codes import ssvep_to_code +from bcipy.display.paradigm.vep.codes import round_refresh_rate, ssvep_to_code from bcipy.display.paradigm.vep.display import VEPDisplay from bcipy.display.paradigm.vep.layout import BoxConfiguration from bcipy.helpers.clock import Clock @@ -242,9 +242,12 @@ def init_calibration_display(parameters: Parameters, colors=[parameters['task_color']], font=parameters['font'], height=parameters['task_height']) - flicker_rates = parameters['vep_flicker_rates'] + + # create codes from configuration + flicker_rates = parameters['vep_flicker_rates'].split(',') + rate = round_refresh_rate(window.getActualFrameRate()) codes = [ - ssvep_to_code(refresh_rate=60, flicker_rate=hz) + ssvep_to_code(refresh_rate=rate, flicker_rate=int(hz)) for hz in flicker_rates ] return VEPDisplay(window,