You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tutorials/build_stimunit.md
+40-30Lines changed: 40 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,16 @@
1
-
# StimUnit: Modular Trial Controller
1
+
# StimUnit: Modular Stimulus & Response Handler
2
2
3
3
## Overview
4
4
5
-
`StimUnit` is a versatile, trial-level controller for PsychoPy experiments. It bundles everything you need for one trial into a single, chainable object:
5
+
`StimUnit` is a versatile, stimulus-level controller for PsychoPy experiments. It bundles everything you need for one trial into a single, chainable object:
6
6
7
7
-**Stimulus presentation**: Draw multiple visual or audio stimuli together with sub-frame accuracy.
8
8
-**Response collection**: Detect keyboard events and record reaction times effortlessly.
9
9
-**Timing control**: Opt for frame-based (refresh-locked) or clock-based timing based on your needs.
10
10
-**State management**: Store all trial-related data in a centralized internal dictionary.
11
11
-**Event hooks**: Plug in custom callbacks at start, response, timeout, and end stages.
12
12
13
-
By using `StimUnit`, your experiment code becomes more modular, readable, and maintainable.
13
+
By using `StimUnit`, your trial logic (typically defined in `src/run_trial.py`) becomes more modular, readable, and maintainable.
14
14
15
15
## Key Features
16
16
@@ -40,7 +40,8 @@ By using `StimUnit`, your experiment code becomes more modular, readable, and ma
The `.show()` method is the core display function in `StimUnit`. It handles precise timing, drawing, optional audio playback, and state logging—all in one call. Use it when you want to present stimuli without requiring responses.
169
+
The `show()` method is the core display function in `StimUnit`. It handles precise timing, drawing, optional audio playback, and state logging—all in one call. Use it when you want to present stimuli without requiring responses.
170
170
171
171
172
172
**Key Features of `show()`**
@@ -212,7 +212,6 @@ Use this method when you need standalone stimulus presentation without response
212
212
The following examples demonstrate how to use `.show()` for fixed, jittered, and audio-driven durations. Assume `unit` is an initialized `StimUnit` and `stim_bank` contains your stimuli.
213
213
214
214
```python
215
-
216
215
# 1. Fixed duration – shows text for exactly 1.0 second
217
216
unit.add_stim(stim_bank.get('fixation'))\
218
217
.show(duration=1.0)
@@ -276,7 +275,6 @@ final_score = sum(trial.get("feedback_delta", 0) for trial in all_data)
@@ -751,9 +749,21 @@ When you call `get_state()`, it first looks for the exact key, then for the pref
751
749
```
752
750
753
751
#### Logging State Internally with `.log_unit()`
754
-
- Writes all key–value pairs in `unit.state` to PsychoPy’s log via `logging.data`.
755
-
- Automatically called at the end of `unit.run()`, so you normally don't need to invoke it yourself.
756
752
753
+
`log_unit()` writes every key–value pair in `unit.state` to the log score in `data/*.log`. It uses PsychoPy’s `logging.data()`, which by default appends timestamped entries to the experiment log file or console.
754
+
It's automatically invoked within the `StimUnit` class, so you usually don’t need to call it manually.
755
+
756
+
757
+
**What gets logged?** All entries currently in `unit.state`, including:
0 commit comments