Skip to content

Commit

Permalink
Merge pull request #228 from ssciwr/fix_224_pre_target_delay
Browse files Browse the repository at this point in the history
Separate delays before outer and central targets
  • Loading branch information
lkeegan committed Jun 26, 2023
2 parents 56e5122 + 9e2d877 commit 81b3394
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 46 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

## [1.0.0] - 2023-06-26

First official release.

Changelog format based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
3 changes: 2 additions & 1 deletion benchmarks/profile_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

experiment = Experiment()
experiment.trial_list[0]["weight"] = 3
experiment.trial_list[0]["inter_target_duration"] = 0
experiment.trial_list[0]["pre_target_delay"] = 0.0
experiment.trial_list[0]["pre_central_target_delay"] = 0.0
experiment.trial_list[0]["post_block_display_results"] = False
task = MotorTask(experiment)
with cProfile.Profile() as pr:
Expand Down
Binary file modified docs/notebooks/example.psydat
Binary file not shown.
Binary file modified docs/quickstart/images/trial-screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion docs/reference/trial-conditions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ the screen height (i.e. a line of length 1.0 in these units would extend from th
* Central target display duration (secs)
* How long each central target should be displayed for
* Default: ``5.0``
* Delay between targets (secs)
* Delay before target display (secs)
* The delay before each outer target is displayed
* Default: ``0.0``
* Delay before central target display (secs)
* The delay before each central target is displayed
* Default: ``0.0``
* Distance to targets (screen height fraction)
* The distance from the centre of the screen to the outer targets
* Default: ``0.4``
Expand Down
2 changes: 1 addition & 1 deletion src/vstt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"__version__",
]

__version__ = "0.31.0"
__version__ = "1.0.0"
68 changes: 36 additions & 32 deletions src/vstt/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,46 +271,50 @@ 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"]:
mouse_pos = np.array([0.0, 0.0])
self.mouse.setPos(mouse_pos)
tm.cursor.setPos(mouse_pos)
tm.cursor_path_add_vertex(mouse_pos, clear_existing=True)
if not trial["fixed_target_intervals"]:
stop_waiting_time = t0 + trial["inter_target_duration"]
if stop_waiting_time > t0:
if trial["hide_target_when_reached"]:
vis.update_target_colors(
tm.targets, trial["show_inactive_targets"], None
if not trial["fixed_target_intervals"]:
if is_central_target:
pre_target_delay = trial["pre_central_target_delay"]
else:
pre_target_delay = trial["pre_target_delay"]
stop_waiting_time = t0 + pre_target_delay
if stop_waiting_time > t0:
if trial["hide_target_when_reached"]:
vis.update_target_colors(
tm.targets, trial["show_inactive_targets"], None
)
if trial["show_target_labels"] and tm.target_labels is not None:
vis.update_target_label_colors(
tm.target_labels, trial["show_inactive_targets"], None
)
if trial["show_target_labels"] and tm.target_labels is not None:
vis.update_target_label_colors(
tm.target_labels, trial["show_inactive_targets"], None
# ensure we get at least a single flip
should_continue_waiting = True
while should_continue_waiting:
if trial["freeze_cursor_between_targets"]:
self.mouse.setPos(mouse_pos)
vis.draw_and_flip(self.win, tm.drawables, self.kb)
if not trial["freeze_cursor_between_targets"]:
if trial["use_joystick"]:
mouse_pos = tm.joystick_point_updater(
mouse_pos, (self.js.getX(), self.js.getY()) # type: ignore
)
# ensure we get at least a single flip
should_continue_waiting = True
while should_continue_waiting:
if trial["freeze_cursor_between_targets"]:
self.mouse.setPos(mouse_pos)
vis.draw_and_flip(self.win, tm.drawables, self.kb)
if not trial["freeze_cursor_between_targets"]:
if trial["use_joystick"]:
mouse_pos = tm.joystick_point_updater(
mouse_pos, (self.js.getX(), self.js.getY()) # type: ignore
)
else:
mouse_pos = tm.point_rotator(self.mouse.getPos())
mouse_times.append(tm.clock.getTime())
mouse_positions.append(mouse_pos)
if trial["show_cursor"]:
tm.cursor.setPos(mouse_pos)
if trial["show_cursor_path"]:
tm.cursor_path_add_vertex(mouse_pos)
should_continue_waiting = (
tm.clock.getTime() + minimum_window_for_flip
< stop_waiting_time
)
else:
mouse_pos = tm.point_rotator(self.mouse.getPos())
mouse_times.append(tm.clock.getTime())
mouse_positions.append(mouse_pos)
if trial["show_cursor"]:
tm.cursor.setPos(mouse_pos)
if trial["show_cursor_path"]:
tm.cursor_path_add_vertex(mouse_pos)
should_continue_waiting = (
tm.clock.getTime() + minimum_window_for_flip < stop_waiting_time
)
# display current target
t0 = tm.clock.getTime()
vis.update_target_colors(
Expand Down
9 changes: 6 additions & 3 deletions src/vstt/trial.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def default_trial() -> Trial:
"fixed_target_intervals": False,
"target_duration": 5.0,
"central_target_duration": 5.0,
"inter_target_duration": 0.0,
"pre_target_delay": 0.0,
"pre_central_target_delay": 0.0,
"target_distance": 0.4,
"target_size": 0.04,
"central_target_size": 0.02,
Expand Down Expand Up @@ -78,7 +79,8 @@ def trial_labels() -> Dict:
"fixed_target_intervals": "Fixed target display intervals",
"target_duration": "Target display duration (secs)",
"central_target_duration": "Central target display duration (secs)",
"inter_target_duration": "Delay between targets (secs)",
"pre_target_delay": "Delay before outer target display (secs)",
"pre_central_target_delay": "Delay before central target display (secs)",
"target_distance": "Distance to targets (screen height fraction)",
"target_size": "Target size (screen height fraction)",
"central_target_size": "Central target size (screen height fraction)",
Expand Down Expand Up @@ -129,7 +131,8 @@ def import_and_validate_trial(trial_or_dict: Mapping[str, Any]) -> Trial:
"condition_timeout",
"target_duration",
"central_target_duration",
"inter_target_duration",
"pre_target_delay",
"pre_central_target_delay",
"post_trial_delay",
"post_block_delay",
]:
Expand Down
3 changes: 2 additions & 1 deletion src/vstt/vtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class Trial(TypedDict):
fixed_target_intervals: bool
target_duration: float
central_target_duration: float
inter_target_duration: float
pre_target_delay: float
pre_central_target_delay: float
target_distance: float
target_size: float
central_target_size: float
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def experiment_no_results() -> Experiment:
trial0["play_sound"] = False
trial0["target_duration"] = 60.0
trial0["central_target_duration"] = 60.0
trial0["inter_target_duration"] = 0.0
trial0["pre_target_delay"] = 0.0
trial0["pre_central_target_delay"] = 0.0
trial0["post_block_display_results"] = False
trial0["post_block_delay"] = 0.1
trial1 = copy.deepcopy(trial0)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ def test_task_condition_timeout_no_user_input(window: Window) -> None:
trial1["condition_timeout"] = 4.0
trial1["num_targets"] = 1
trial1["target_duration"] = 2.1
trial1["inter_target_duration"] = 0.0
trial1["pre_target_delay"] = 0.0
trial1["pre_central_target_delay"] = 0.0
trial1["add_central_target"] = False
trial1["automove_cursor_to_center"] = False
trial1["freeze_cursor_between_targets"] = False
Expand Down
15 changes: 10 additions & 5 deletions tests/test_trial.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def test_import_trial() -> None:
"fixed_target_intervals": False,
"target_duration": 3,
"central_target_duration": 3,
"inter_target_duration": 0,
"pre_target_delay": 0,
"pre_central_target_delay": 0,
"target_distance": 0.3,
"target_size": 0.03,
"central_target_size": 0.01,
Expand Down Expand Up @@ -112,25 +113,29 @@ def test_validate_trial_durations() -> None:
# positive durations are not modified
trial["target_duration"] = 1
trial["central_target_duration"] = 1
trial["inter_target_duration"] = 0.1
trial["pre_target_delay"] = 0.1
trial["pre_central_target_delay"] = 0.087
trial["post_trial_delay"] = 0.2
trial["post_block_delay"] = 0.7
vtrial = vstt.trial.import_and_validate_trial(trial)
assert vtrial["target_duration"] == 1
assert vtrial["central_target_duration"] == 1
assert vtrial["inter_target_duration"] == 0.1
assert vtrial["pre_target_delay"] == 0.1
assert vtrial["pre_central_target_delay"] == 0.087
assert vtrial["post_trial_delay"] == 0.2
assert vtrial["post_block_delay"] == 0.7
# negative durations are cast to zero
trial["target_duration"] = -1
trial["central_target_duration"] = -0.8
trial["inter_target_duration"] = -0.1
trial["pre_target_delay"] = -0.1
trial["pre_central_target_delay"] = -0.087
trial["post_trial_delay"] = -0.2
trial["post_block_delay"] = -0.7
vtrial = vstt.trial.import_and_validate_trial(trial)
assert vtrial["target_duration"] == 0
assert vtrial["central_target_duration"] == 0
assert vtrial["inter_target_duration"] == 0
assert vtrial["pre_target_delay"] == 0
assert vtrial["pre_central_target_delay"] == 0
assert vtrial["post_trial_delay"] == 0
assert vtrial["post_block_delay"] == 0

Expand Down

0 comments on commit 81b3394

Please sign in to comment.