Skip to content

Commit

Permalink
Removed option to layout VEP with 4 boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
lawhead committed Dec 8, 2023
1 parent 8cf0ce7 commit 8e58b5b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 75 deletions.
4 changes: 2 additions & 2 deletions bcipy/display/demo/components/demo_layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import sys
import time
from typing import Optional, Callable, List, Tuple, Union
from typing import Callable, List, Optional, Tuple, Union

from psychopy import visual
from psychopy.visual.circle import Circle
Expand Down Expand Up @@ -132,7 +132,7 @@ def demo_vep(win: visual.Window):
layout = centered(width_pct=0.9, height_pct=0.9)
layout.parent = win

box_config = BoxConfiguration(layout, num_boxes=4, height_pct=0.28)
box_config = BoxConfiguration(layout, height_pct=0.28)
size = box_config.box_size
positions = box_config.positions

Expand Down
3 changes: 1 addition & 2 deletions bcipy/display/demo/vep/demo_calibration_vep.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
)

task_text = ['1/3', '2/3', '3/3']
num_boxes = 6

window_parameters = {
'full_screen': False,
Expand Down Expand Up @@ -56,7 +55,7 @@
]

layout = centered(width_pct=0.95, height_pct=0.80)
box_config = BoxConfiguration(layout, num_boxes=num_boxes, height_pct=0.30)
box_config = BoxConfiguration(layout, height_pct=0.30)

experiment_clock = Clock()
len_stimuli = 10
Expand Down
22 changes: 6 additions & 16 deletions bcipy/display/paradigm/vep/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from itertools import cycle
from math import sqrt
from typing import List, NamedTuple, Optional, Tuple
from typing import List, NamedTuple, Tuple

from bcipy.display.components.layout import (Layout, above, below, left_of,
right_of)
Expand Down Expand Up @@ -89,11 +89,11 @@ def checkerboard(squares: int, colors: Tuple[str, str], center: Tuple[float,
class BoxConfiguration():
"""Computes box size and positions for a VEP display.
In this configuration, there is one row on top and one on the bottom.
In this configuration, there are 6 areas configured with one row of 3 on top
and one row on the bottom.
Parameters
----------
num_boxes - number of boxes; currently supports 4 or 6.
layout - defines the boundaries within a Window in which the text areas
will be placed
spacing_pct - used to specify spacing between boxes within a row.
Expand All @@ -102,30 +102,25 @@ class BoxConfiguration():

def __init__(self,
layout: Layout,
num_boxes: int,
spacing_pct: Optional[float] = None,
spacing_pct: float = 0.05,
height_pct: float = 0.25):
self.layout = layout
self.num_boxes = num_boxes
self.height_pct = height_pct
self.validate()

default_spacing = {4: 0.1, 6: 0.05}
if not spacing_pct:
spacing_pct = default_spacing[num_boxes]
self.spacing_pct = spacing_pct
self._num_boxes = 6
self._row_count = 2

def validate(self):
"""Validate invariants"""
assert self.num_boxes == 4 or self.num_boxes == 6, 'Number of boxes must be 4 or 6'
assert self.height_pct <= 0.5, "Rows can't take more than 50% of the height"

def _box_size(self, validate: bool = True) -> Tuple[float, float]:
"""Computes the size of each box"""
if validate:
self.validate()
number_per_row = self.num_boxes / self._row_count
number_per_row = self._num_boxes / self._row_count

# left and right boxes go to the edges, with a space between each box
spaces_per_row = number_per_row - 1
Expand Down Expand Up @@ -165,18 +160,13 @@ def positions(self) -> List[Tuple]:
left = right_of(layout.left, width / 2)
right = left_of(layout.right, width / 2)

if self.num_boxes == 4:
return [(left, top), (right, top), (left, bottom), (right, bottom)]

middle = layout.horizontal_middle
return [(left, top), (middle, top), (right, top), (left, bottom),
(middle, bottom), (right, bottom)]

@property
def names(self) -> List[str]:
"""Box names for each position."""
if self.num_boxes == 4:
return ['LEFT_TOP', 'RIGHT_TOP', 'LEFT_BOTTOM', 'RIGHT_BOTTOM']
return [
'LEFT_TOP', 'MIDDLE_TOP', 'RIGHT_TOP', 'LEFT_BOTTOM',
'MIDDLE_BOTTOM', 'RIGHT_BOTTOM'
Expand Down
52 changes: 0 additions & 52 deletions bcipy/display/tests/vep/test_vep_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,44 +61,10 @@ def test_checkerboard_inverse(self):

self.assertEqual(square.inverse_color(colors), 'green')

def test_4_box_config_defaults(self):
"""Test box configuration"""
full_window = Layout()
config = BoxConfiguration(layout=full_window,
num_boxes=4,
height_pct=0.25,
spacing_pct=0.1)
width, height = config.box_size
window_width, window_height = full_window.size

self.assertEqual(window_width, 2.0)
self.assertEqual(window_height, 2.0)
self.assertEqual(
width,
0.9,
msg="Box width should be half of the remaining width after accounting for the spacing."
)
self.assertEqual(
height,
0.5,
msg="Box height should be height_pct of the window height")

positions = config.positions
self.assertEqual(len(positions), 4)
self.assertTrue((-0.55, 0.75) in positions,
msg="A box should be positioned at the top left")
self.assertTrue((0.55, 0.75) in positions,
msg="A box should be positioned at the top right")
self.assertTrue((-0.55, -0.75) in positions,
msg="A box should be positioned at the bottom left")
self.assertTrue((0.55, -0.75) in positions,
msg="A box should be positioned at the bottom right")

def test_6_box_config_defaults(self):
"""Test box configuration"""
full_window = Layout()
config = BoxConfiguration(layout=full_window,
num_boxes=6,
height_pct=0.25,
spacing_pct=0.05)
self.assertEqual(
Expand All @@ -110,21 +76,3 @@ def test_6_box_config_defaults(self):
self.assertEqual(len([box for box in positions if box[0] == 0.0]),
2,
msg="Two boxes should be positioned in the middle")

def test_other_box_config(self):
"""Test supported number of boxes"""
full_window = Layout()
with self.assertRaises(AssertionError):
BoxConfiguration(layout=full_window,
num_boxes=2,
height_pct=0.25,
spacing_pct=0.05)

def test_height_pct_validation(self):
"""Test validations"""
full_window = Layout()
with self.assertRaises(AssertionError):
BoxConfiguration(layout=full_window,
num_boxes=4,
height_pct=0.6,
spacing_pct=0.1)
5 changes: 2 additions & 3 deletions bcipy/task/paradigm/vep/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,7 @@ def init_calibration_display(parameters: Parameters,
experiment_clock,
symbol_set,
timing,
colors,
num_boxes=6):
colors):
"""Initialize the display"""
info = InformationProperties(
info_color=[parameters['info_color']],
Expand All @@ -227,7 +226,7 @@ def init_calibration_display(parameters: Parameters,
)

layout = centered(width_pct=0.95, height_pct=0.80)
box_config = BoxConfiguration(layout, num_boxes=num_boxes, height_pct=0.30)
box_config = BoxConfiguration(layout, height_pct=0.30)

stim_props = VEPStimuliProperties(stim_font=parameters['font'],
stim_pos=box_config.positions,
Expand Down

0 comments on commit 8e58b5b

Please sign in to comment.