Skip to content

Commit

Permalink
Update color of targets and center (#279)
Browse files Browse the repository at this point in the history
* lighthen the circle color and change target's color to green when it's reached

* turn the reached target into green until the next target is highlighted

* the code needs to be updated

* release the mouese after it reached the target

* set turn_target_to_green_when_reached to False in default;pass tm.green_target_index to function update_target_colors instead of tm;add turn_target_to_green_when_reached:False to the test_import_trial()

* remove convoluted code

* remove the annotated code and fix error in test code

* fix ImportError when importing wxPython

---------

Co-authored-by: 李双双 <[email protected]>
Co-authored-by: ZoeLi0525 <[email protected]>
  • Loading branch information
3 people authored Nov 19, 2024
1 parent 8a014de commit 29a1065
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ build:
- mesa-utils
# system sound driver for sounddevice
- libportaudio2
# Required for libsecret-1.so.0, fixes ImportError when importing wxPython
- libsecret-1-dev
jobs:
pre_install:
# install attrdict as this may be used in wxPython setup.py
Expand Down
12 changes: 10 additions & 2 deletions src/vstt/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def __init__(self, win: Window, trial: vstt.vtypes.Trial):
self.first_target_of_condition_shown = False
self.most_recent_target_display_time = 0.0
self.final_target_display_time_previous_trial = 0.0
self.green_target_index: int | None = None

def cursor_path_add_vertex(
self, vertex: tuple[float, float], clear_existing: bool = False
Expand Down Expand Up @@ -292,6 +293,7 @@ def _do_target(
is_central_target = target_index == trial["num_targets"]
mouse_times = []
mouse_positions = []

# current target is not yet displayed
if not is_central_target:
if trial["automove_cursor_to_center"]:
Expand All @@ -311,10 +313,13 @@ def _do_target(
pre_target_delay += trial["pre_first_target_extra_delay"]
tm.first_target_of_condition_shown = True
stop_waiting_time = t0 + pre_target_delay
if stop_waiting_time > t0:
if stop_waiting_time >= t0:
if trial["hide_target_when_reached"]:
vis.update_target_colors(
tm.targets, trial["show_inactive_targets"], None
tm.targets,
trial["show_inactive_targets"],
None,
tm.green_target_index,
)
if trial["show_target_labels"] and tm.target_labels is not None:
vis.update_target_label_colors(
Expand Down Expand Up @@ -408,6 +413,9 @@ def _do_target(
dist_correct <= target_size
and tm.clock.getTime() + minimum_window_for_flip < stop_target_time
)
# When the target is reached, turn the color to green
if success and trial["turn_target_to_green_when_reached"]:
tm.green_target_index = target_index
if is_central_target:
trial_data.to_center_success.append(success)
else:
Expand Down
2 changes: 2 additions & 0 deletions src/vstt/trial.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def default_trial() -> Trial:
"target_indices": "0 1 2 3 4 5 6 7",
"add_central_target": True,
"hide_target_when_reached": True,
"turn_target_to_green_when_reached": False,
"show_target_labels": False,
"target_labels": "0 1 2 3 4 5 6 7",
"fixed_target_intervals": False,
Expand Down Expand Up @@ -73,6 +74,7 @@ def trial_labels() -> dict:
"target_indices": "Target indices",
"add_central_target": "Add a central target",
"hide_target_when_reached": "Hide target when reached",
"turn_target_to_green_when_reached": "Turn target to green when reached",
"show_target_labels": "Display target labels",
"target_labels": "Target labels",
"fixed_target_intervals": "Fixed target display intervals",
Expand Down
16 changes: 10 additions & 6 deletions src/vstt/vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,21 @@ def make_target_labels(


def update_target_colors(
targets: ElementArrayStim, show_inactive_targets: bool, index: int | None = None
targets: ElementArrayStim,
show_inactive_targets: bool,
index: int | None = None,
green_target_index: int | None = None,
) -> None:
inactive_rgb = 0.0
if show_inactive_targets:
inactive_rgb = 0.1
inactive_rgb = 0.9
c = np.array([[inactive_rgb, inactive_rgb, inactive_rgb]] * targets.nElements)
if index is not None:
# make specified target red
c[index][0] = 1
c[index][1] = -1
c[index][2] = -1
# Set specified target to red
c[index] = [1, -1, -1]
if green_target_index is not None:
# Set specified target to green
c[green_target_index] = [-1, 1, -1]
targets.setColors(c, colorSpace="rgb")


Expand Down
1 change: 1 addition & 0 deletions src/vstt/vtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Trial(TypedDict):
target_indices: str
add_central_target: bool
hide_target_when_reached: bool
turn_target_to_green_when_reached: bool
show_target_labels: bool
target_labels: str
fixed_target_intervals: bool
Expand Down
1 change: 1 addition & 0 deletions tests/test_trial.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def test_import_trial() -> None:
"add_central_target": True,
"show_target_labels": False,
"hide_target_when_reached": True,
"turn_target_to_green_when_reached": False,
"target_labels": "0 1 2 3 4 5",
"fixed_target_intervals": False,
"target_duration": 3,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_update_target_colors(
window: Window, n_targets: int, add_central_target: bool
) -> None:
for show_inactive_targets, inactive_color in [
(True, (0.1, 0.1, 0.1)),
(True, (0.9, 0.9, 0.9)),
(False, (0, 0, 0)),
]:
red = (1.0, -1.0, -1.0)
Expand Down

0 comments on commit 29a1065

Please sign in to comment.