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

Update color of targets and center #279

Merged
merged 8 commits into from
Nov 19, 2024
Merged
17 changes: 15 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 @@ -281,6 +282,11 @@ def _do_target(
mouse_pos = tm.cursor.pos
stop_waiting_time = 0.0
stop_target_time = 0.0
tm.green_target_index = (
tm.green_target_index
if tm.green_target_index == trial["num_targets"]
else None
)
ZoeJacky marked this conversation as resolved.
Show resolved Hide resolved
if trial["fixed_target_intervals"]:
num_completed_targets = len(trial_data.to_target_timestamps)
stop_waiting_time = (num_completed_targets + 1) * trial[
Expand All @@ -292,6 +298,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 +318,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 +418,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 @@ -55,6 +55,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
Loading