Skip to content

Commit 75e575a

Browse files
committed
docs: update StimUnit examples
1 parent 28932af commit 75e575a

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

docs/tutorials/build_trialunit.md

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ With `StimUnit`, you can create complex trial structures using a clean, chainabl
3030

3131
| Purpose | Method | Example |
3232
|---------|--------|--------|
33-
| Initialize | `StimUnit(win, label, trigger)` | `trial = StimUnit(win, "cue", trigger)` |
33+
| Initialize | `StimUnit(label, win, kb, triggersender=sender)` | `trial = StimUnit("cue", win, kb, triggersender=sender)` |
3434
| Add stimuli | `.add_stim(stim)` | `trial.add_stim(fixation)` |
3535
| Register start hook | `.on_start(fn)` | `@trial.on_start()` |
3636
| Register response hook | `.on_response(keys, fn)` | `@trial.on_response(['left', 'right'])` |
@@ -40,7 +40,7 @@ With `StimUnit`, you can create complex trial structures using a clean, chainabl
4040
| Set auto-close keys | `.close_on(keys)` | `trial.close_on('space')` |
4141
| Simple display | `.show(duration)` | `trial.show(1.0)` |
4242
| Response capture | `.capture_response(keys)` | `trial.capture_response(['left', 'right'])` |
43-
| Full trial control | `.run()` | `trial.run(frame_based=True)` |
43+
| Full trial control | `.run()` | `trial.run()` |
4444
| Pause for input | `.wait_and_continue(keys)` | `trial.wait_and_continue(['space'])` |
4545
| Update state | `.set_state(**kwargs)` | `trial.set_state(correct=True)` |
4646
| Get state | `.state` or `.to_dict()` | `data = trial.to_dict()` |
@@ -61,15 +61,10 @@ win = visual.Window(size=[1024, 768], color="black", units="deg")
6161
kb = Keyboard()
6262

6363
# Create a trigger sender (mock mode for testing)
64-
trigger = TriggerSender(mock=True)
64+
sender = TriggerSender(mock=True)
6565

6666
# Initialize a trial unit
67-
trial = StimUnit(
68-
win=win, # PsychoPy window
69-
unit_label="cue", # Label for this trial (used in state keys)
70-
triggersender=trigger, # Optional trigger sender
71-
keyboard=kb # Optional keyboard (auto-created if None)
72-
)
67+
trial = StimUnit("cue", win, kb, triggersender=sender)
7368
```
7469

7570
For real EEG/MEG experiments, you would use a real trigger function:
@@ -253,7 +248,6 @@ trial.add_stim(fixation, target) \
253248

254249
# Run the trial
255250
trial.run(
256-
frame_based=True, # Use frame counting for timing
257251
terminate_on_response=True # Stop drawing after response
258252
)
259253

@@ -340,7 +334,7 @@ import random
340334
# Setup
341335
win = visual.Window(size=[1024, 768], color="black", units="deg")
342336
kb = Keyboard()
343-
trigger = TriggerSender(mock=True)
337+
sender = TriggerSender(mock=True)
344338

345339
# Create stimuli
346340
fixation = visual.TextStim(win, text="+", height=1.0, color="white")
@@ -366,7 +360,7 @@ def run_trial(condition):
366360
target_trigger = 12
367361

368362
# Create trial unit
369-
trial = StimUnit(win, "choice", trigger, kb)
363+
trial = StimUnit("choice", win, kb, triggersender=sender)
370364

371365
# Register response handler
372366
@trial.on_response(["left", "right"])
@@ -383,7 +377,7 @@ def run_trial(condition):
383377
unit.add_stim(feedback_incorrect)
384378

385379
# Show fixation
386-
fixation_trial = StimUnit(win, "fixation", trigger, kb)
380+
fixation_trial = StimUnit("fixation", win, kb, triggersender=sender)
387381
fixation_trial.add_stim(fixation).show(
388382
duration=(0.8, 1.2), # Jittered duration
389383
onset_trigger=10
@@ -421,7 +415,7 @@ for i, condition in enumerate(conditions):
421415
core.wait(0.5) # Inter-trial interval
422416

423417
# Show completion message
424-
end_trial = StimUnit(win, "end", trigger, kb)
418+
end_trial = StimUnit("end", win, kb, triggersender=sender)
425419
end_text = visual.TextStim(
426420
win,
427421
text="Experiment complete. Thank you!",
@@ -493,23 +487,23 @@ You can create complex trial structures by nesting `StimUnit` instances:
493487
```python
494488
def run_complex_trial():
495489
# Fixation phase
496-
fix_unit = StimUnit(win, "fixation", trigger)
490+
fix_unit = StimUnit("fixation", win, kb, triggersender=sender)
497491
fix_unit.add_stim(fixation).show(duration=0.5, onset_trigger=1)
498492

499493
# Cue phase
500-
cue_unit = StimUnit(win, "cue", trigger)
494+
cue_unit = StimUnit("cue", win, kb, triggersender=sender)
501495
cue_unit.add_stim(cue).show(duration=0.8, onset_trigger=2)
502496

503497
# Target phase with response
504-
target_unit = StimUnit(win, "target", trigger)
498+
target_unit = StimUnit("target", win, kb, triggersender=sender)
505499
target_unit.add_stim(target).capture_response(
506500
keys=["left", "right"],
507501
duration=2.0,
508502
onset_trigger=3
509503
)
510504

511505
# Feedback phase
512-
feedback_unit = StimUnit(win, "feedback", trigger)
506+
feedback_unit = StimUnit("feedback", win, kb, triggersender=sender)
513507
if target_unit.state.get("correct", False):
514508
feedback_unit.add_stim(feedback_correct)
515509
else:

docs/tutorials/getting_started.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ trial = StimUnit("trial_1", win, kb, triggersender=sender)
243243
trial \
244244
.add_stim(fixation, target) \
245245
.on_start(lambda unit: unit.send_trigger(triggers["fix_onset"])) \
246-
.show_stim(fixation, duration=0.5) \
247-
.show_stim(target, duration=1.0, trigger=triggers["target_onset"]) \
246+
.show(fixation, duration=0.5) \
247+
.show(target, duration=1.0, trigger=triggers["target_onset"]) \
248248
.capture_response(
249249
keys=["left", "right"],
250250
duration=2.0,
@@ -257,7 +257,7 @@ trial \
257257
correct_keys=["left"],
258258
) \
259259
.on_end(lambda unit: print(f"Response: {unit.state}")) \
260-
.run(frame_based=True)
260+
.run()
261261

262262
# Access trial results
263263
print(f"RT: {trial.state.get('rt')}")
@@ -303,8 +303,8 @@ def run_trial(condition, trial_idx, block):
303303
# Run trial (simplified)
304304
trial \
305305
.add_stim(fixation, target) \
306-
.show_stim(fixation, duration=0.5) \
307-
.show_stim(target, duration=1.0) \
306+
.show(fixation, duration=0.5) \
307+
.show(target, duration=1.0) \
308308
.capture_response(keys=settings.key_list, duration=2.0) \
309309
.run()
310310

0 commit comments

Comments
 (0)