Skip to content

Commit

Permalink
Fixed issues with refresh rates
Browse files Browse the repository at this point in the history
  • Loading branch information
lawhead committed Nov 21, 2023
1 parent 0418f64 commit 6e9f344
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
13 changes: 13 additions & 0 deletions bcipy/display/paradigm/vep/codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
5 changes: 3 additions & 2 deletions bcipy/display/paradigm/vep/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion bcipy/display/tests/vep/test_codes.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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()
9 changes: 6 additions & 3 deletions bcipy/task/paradigm/vep/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 6e9f344

Please sign in to comment.