psychopy-pyomotion 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. psychopy_pyomotion-1.0.0/LICENSE +21 -0
  2. psychopy_pyomotion-1.0.0/PKG-INFO +363 -0
  3. psychopy_pyomotion-1.0.0/README.md +334 -0
  4. psychopy_pyomotion-1.0.0/psychopy_pyomotion/__init__.py +8 -0
  5. psychopy_pyomotion-1.0.0/psychopy_pyomotion/assets/placeholder_walker.trc +133 -0
  6. psychopy_pyomotion-1.0.0/psychopy_pyomotion/components/PyoMotion/__init__.py +750 -0
  7. psychopy_pyomotion-1.0.0/psychopy_pyomotion/components/PyoMotion/classic/PyoMotion.png +0 -0
  8. psychopy_pyomotion-1.0.0/psychopy_pyomotion/components/PyoMotion/classic/PyoMotion@2x.png +0 -0
  9. psychopy_pyomotion-1.0.0/psychopy_pyomotion/components/PyoMotion/ctrls.py +409 -0
  10. psychopy_pyomotion-1.0.0/psychopy_pyomotion/components/PyoMotion/dark/PyoMotion.png +0 -0
  11. psychopy_pyomotion-1.0.0/psychopy_pyomotion/components/PyoMotion/dark/PyoMotion@2x.png +0 -0
  12. psychopy_pyomotion-1.0.0/psychopy_pyomotion/components/PyoMotion/light/PyoMotion.png +0 -0
  13. psychopy_pyomotion-1.0.0/psychopy_pyomotion/components/PyoMotion/light/PyoMotion@2x.png +0 -0
  14. psychopy_pyomotion-1.0.0/psychopy_pyomotion/components/__init__.py +15 -0
  15. psychopy_pyomotion-1.0.0/psychopy_pyomotion/conditions.py +38 -0
  16. psychopy_pyomotion-1.0.0/psychopy_pyomotion/parsers/__init__.py +112 -0
  17. psychopy_pyomotion-1.0.0/psychopy_pyomotion/parsers/base_parser.py +72 -0
  18. psychopy_pyomotion-1.0.0/psychopy_pyomotion/parsers/bvh_parser.py +206 -0
  19. psychopy_pyomotion-1.0.0/psychopy_pyomotion/parsers/c3d_parser.py +114 -0
  20. psychopy_pyomotion-1.0.0/psychopy_pyomotion/parsers/import_settings.py +157 -0
  21. psychopy_pyomotion-1.0.0/psychopy_pyomotion/parsers/trc_parser.py +143 -0
  22. psychopy_pyomotion-1.0.0/psychopy_pyomotion/parsers/txt_parser.py +80 -0
  23. psychopy_pyomotion-1.0.0/psychopy_pyomotion/preview/__init__.py +14 -0
  24. psychopy_pyomotion-1.0.0/psychopy_pyomotion/preview/canvas.py +178 -0
  25. psychopy_pyomotion-1.0.0/psychopy_pyomotion/preview/external.py +122 -0
  26. psychopy_pyomotion-1.0.0/psychopy_pyomotion/preview/info.py +219 -0
  27. psychopy_pyomotion-1.0.0/psychopy_pyomotion/preview/panel.py +1127 -0
  28. psychopy_pyomotion-1.0.0/psychopy_pyomotion/preview/scene.py +249 -0
  29. psychopy_pyomotion-1.0.0/psychopy_pyomotion/preview/source.py +143 -0
  30. psychopy_pyomotion-1.0.0/psychopy_pyomotion/preview/values.py +156 -0
  31. psychopy_pyomotion-1.0.0/psychopy_pyomotion/preview/window.py +132 -0
  32. psychopy_pyomotion-1.0.0/psychopy_pyomotion/runtime.py +1075 -0
  33. psychopy_pyomotion-1.0.0/psychopy_pyomotion/utils/__init__.py +10 -0
  34. psychopy_pyomotion-1.0.0/psychopy_pyomotion/utils/markers.py +66 -0
  35. psychopy_pyomotion-1.0.0/psychopy_pyomotion/utils/missing.py +70 -0
  36. psychopy_pyomotion-1.0.0/psychopy_pyomotion/utils/projection.py +98 -0
  37. psychopy_pyomotion-1.0.0/psychopy_pyomotion/utils/scramble.py +180 -0
  38. psychopy_pyomotion-1.0.0/psychopy_pyomotion/validation.py +332 -0
  39. psychopy_pyomotion-1.0.0/psychopy_pyomotion.egg-info/PKG-INFO +363 -0
  40. psychopy_pyomotion-1.0.0/psychopy_pyomotion.egg-info/SOURCES.txt +62 -0
  41. psychopy_pyomotion-1.0.0/psychopy_pyomotion.egg-info/dependency_links.txt +1 -0
  42. psychopy_pyomotion-1.0.0/psychopy_pyomotion.egg-info/entry_points.txt +2 -0
  43. psychopy_pyomotion-1.0.0/psychopy_pyomotion.egg-info/requires.txt +6 -0
  44. psychopy_pyomotion-1.0.0/psychopy_pyomotion.egg-info/top_level.txt +1 -0
  45. psychopy_pyomotion-1.0.0/pyproject.toml +60 -0
  46. psychopy_pyomotion-1.0.0/setup.cfg +4 -0
  47. psychopy_pyomotion-1.0.0/tests/test_component.py +390 -0
  48. psychopy_pyomotion-1.0.0/tests/test_conditions.py +32 -0
  49. psychopy_pyomotion-1.0.0/tests/test_dialog.py +666 -0
  50. psychopy_pyomotion-1.0.0/tests/test_entry_points.py +29 -0
  51. psychopy_pyomotion-1.0.0/tests/test_import_and_missing.py +218 -0
  52. psychopy_pyomotion-1.0.0/tests/test_markers.py +30 -0
  53. psychopy_pyomotion-1.0.0/tests/test_packaging.py +125 -0
  54. psychopy_pyomotion-1.0.0/tests/test_parsers.py +492 -0
  55. psychopy_pyomotion-1.0.0/tests/test_preview_external.py +56 -0
  56. psychopy_pyomotion-1.0.0/tests/test_preview_geometry.py +187 -0
  57. psychopy_pyomotion-1.0.0/tests/test_preview_info.py +97 -0
  58. psychopy_pyomotion-1.0.0/tests/test_preview_source.py +93 -0
  59. psychopy_pyomotion-1.0.0/tests/test_preview_values.py +94 -0
  60. psychopy_pyomotion-1.0.0/tests/test_runtime.py +807 -0
  61. psychopy_pyomotion-1.0.0/tests/test_samples.py +42 -0
  62. psychopy_pyomotion-1.0.0/tests/test_scramble.py +175 -0
  63. psychopy_pyomotion-1.0.0/tests/test_validation.py +225 -0
  64. psychopy_pyomotion-1.0.0/tests/test_version.py +21 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ulasdilek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,363 @@
1
+ Metadata-Version: 2.4
2
+ Name: psychopy-pyomotion
3
+ Version: 1.0.0
4
+ Summary: PyoMotion: a Biological Motion component for PsychoPy Builder that plays point-light stimuli from motion-capture data
5
+ Author-email: ulasdilek <ulas.dilek@bilkent.edu.tr>
6
+ License-Expression: MIT
7
+ Project-URL: homepage, https://github.com/ulasdilek/psychopy-pyomotion
8
+ Project-URL: documentation, https://github.com/ulasdilek/psychopy-pyomotion#readme
9
+ Project-URL: repository, https://github.com/ulasdilek/psychopy-pyomotion
10
+ Project-URL: issues, https://github.com/ulasdilek/psychopy-pyomotion/issues
11
+ Project-URL: changelog, https://github.com/ulasdilek/psychopy-pyomotion/blob/main/CHANGELOG.md
12
+ Keywords: psychopy,plugin,motion capture,biological motion,point-light
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Topic :: Scientific/Engineering
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: numpy
24
+ Requires-Dist: c3d<0.7,>=0.6.0
25
+ Provides-Extra: tests
26
+ Requires-Dist: psychopy>=2025.2; extra == "tests"
27
+ Requires-Dist: pytest; extra == "tests"
28
+ Dynamic: license-file
29
+
30
+ # PyoMotion
31
+
32
+ A [PsychoPy](https://www.psychopy.org/) Builder plugin for presenting point-light biological motion stimuli from motion-capture (MoCap) data.
33
+
34
+ PyoMotion loads MoCap recordings, applies optional scrambling, and renders each marker as a point on screen — frame by frame, synchronised to the monitor refresh. It is designed for cognitive and perceptual experiments where you want to show or manipulate biological motion.
35
+
36
+ ---
37
+
38
+ ## Installation
39
+
40
+ **Requirements:** PsychoPy **2025.2 or later** (tested with the standalone app 2025.2.4 and PsychoPy 2026.2), Python 3.10 or later. Installing the plugin also installs `numpy` and [`c3d`](https://pypi.org/project/c3d/); PsychoPy itself is not installed by the plugin, which goes into PsychoPy's own Python.
41
+
42
+ Install it into PsychoPy's own Python, in one of these ways:
43
+
44
+ - **Plugins & Packages Manager:** in PsychoPy, open **Tools → Plugins & Packages Manager → Packages**, search for `psychopy-pyomotion` and install it, then restart PsychoPy.
45
+ - **pip**, with PsychoPy's Python (in a terminal where `python` is PsychoPy's interpreter):
46
+
47
+ ```bash
48
+ python -m pip install psychopy-pyomotion
49
+ ```
50
+
51
+ - **From a wheel file** (`psychopy_pyomotion-<version>-py3-none-any.whl`, e.g. from a GitHub release): **Packages → Install from file**, then restart PsychoPy.
52
+
53
+ The plugin is called **PyoMotion** (installed as `psychopy-pyomotion`, imported as `psychopy_pyomotion`); its component, **Biological Motion**, appears under **Stimuli** in the Builder Components panel.
54
+
55
+ **Local experiments only:** the component targets PsychoPy (Python). There is no PsychoJS version, so experiments that use it can't run online (e.g. on Pavlovia).
56
+
57
+ ### Notes for reviewers
58
+
59
+ Two parts of the plugin go beyond a typical Builder component:
60
+
61
+ - **The dialog side panel hooks into Builder's dialog code.** When the component dialog opens, a custom control for *MoCap data* ([`components/PyoMotion/ctrls.py`](https://github.com/ulasdilek/psychopy-pyomotion/blob/main/psychopy_pyomotion/components/PyoMotion/ctrls.py)) schedules [`preview/panel.py`](https://github.com/ulasdilek/psychopy-pyomotion/blob/main/psychopy_pyomotion/preview/panel.py) to insert an information and preview panel next to the parameter tabs (by restructuring the dialog's sizer). If that fails, it adds a *Preview* tab instead; if that fails too, the dialog stays as in stock PsychoPy. Failures are logged at DEBUG and never raise. The panel only reads the dialog's controls; it never writes the component's parameters. The custom controls register only when wx is loaded and work with both module paths (`psychopy_app` in 2026.2, `psychopy.app` in 2025.2).
62
+ - **The *PsychoPy window* button starts a separate Python process** ([`preview/external.py`](https://github.com/ulasdilek/psychopy-pyomotion/blob/main/psychopy_pyomotion/preview/external.py)): it runs PsychoPy's own interpreter on a short script that opens a window and plays the preview with the experiment's code, so the exact rendering can be checked without blocking Builder. The process is ended when the dialog closes.
63
+
64
+ ### Supported file formats
65
+
66
+ | Format | Extension | Notes |
67
+ |--------|-----------|-------|
68
+ | C3D | `.c3d` | Source convention: Z-up, mm → normalised to Y-up, metres |
69
+ | TRC | `.trc` | Motion Analysis / OpenSim marker file; units and frame rate from its header; Y up assumed |
70
+ | BioMotion toolbox data3d | `.txt` | **Only** this format: the MATLAB BioMotion toolbox's own text files. No names, units or rate in the file (see below) |
71
+ | BVH | `.bvh` | Joint positions by forward kinematics (rotations in each joint's channel order); no units in the file, cm assumed; frame rate from `Frame Time`; end sites are not markers |
72
+
73
+ All formats are converted to **Y-up, metres** before rendering (see [Coordinate System](#coordinate-system)). CSV and TSV are not supported: they come in too many layouts; export TRC or C3D instead. In PyoMotion, `.txt` always means BioMotion toolbox data3d; any other `.txt` file is refused (a BVH file saved as `.txt` must be renamed to `.bvh`).
74
+
75
+ ---
76
+
77
+ ## Quick Start
78
+
79
+ 1. Open PsychoPy Builder and create a new experiment.
80
+ 2. Add a **Biological Motion** component to a Routine (under **Stimuli**).
81
+ 3. In the **Basic** tab, set **MoCap data** to the path of your recording file.
82
+ 4. Set the component's **Start** and **Stop** times as usual.
83
+ 5. Run the experiment — the point-light animation plays inside the Routine window.
84
+
85
+ ---
86
+
87
+ ## Component Parameters
88
+
89
+ ### Basic
90
+
91
+ | Parameter | Default | Description |
92
+ |-----------|---------|-------------|
93
+ | **MoCap data** | *(empty)* | Path to the MoCap file. Accepts C3D, TRC, BVH and BioMotion toolbox data3d (`.txt`); the format is detected from the file extension, and the browse dialog only lists these extensions. Can be *set every repeat* (e.g. `$trial_file` from a conditions file) to play a different file each Routine; the file played is saved as `<name>.file`. With a plain `$column`, every file in that column of the surrounding Loop's conditions is loaded and checked at Begin Experiment (nothing loads during a trial). If the files can't be worked out (an expression such as `$'dir/' + name`, no Loop, unreadable conditions), a warning is logged and each file loads when its first trial starts. |
94
+ | **First frame** | `0` | First MoCap frame to play (0-based). |
95
+ | **Stop frame** | *(empty = end)* | Frame to stop before (0-based, exclusive, like a Python slice). E.g. MATLAB `28:312` = first frame `27`, stop frame `312`. |
96
+ | **File units** | `from file` | Units of the positions in the file(s): `mm`, `cm`, `m`, `in`. `from file` = what the file states (C3D `POINT:UNITS`), else the format's default (BVH: cm). With Auto scale on, units only matter for absolute sizes (Scale off, Scramble area). |
97
+ | **Vertical axis** | `from file` | The file's up axis, `Y` or `Z`. `from file` = the format's convention (C3D: Z; BVH: Y). Z-up data is turned Y-up by swapping Y and Z, as the BioMotion toolbox does. |
98
+ | **Frame rate (Hz)** | *(empty = from file)* | The recording's frame rate, if the file's is wrong or missing. |
99
+
100
+ Whenever a value is not stated by the file and is assumed instead, the dialog shows an orange note (OK stays enabled), and the information panel marks each value as *from file*, *set*, *format* or *assumed*.
101
+
102
+ ### Layout
103
+
104
+ All spatial values use the component's **Spatial units**.
105
+
106
+ | Parameter | Default | Description |
107
+ |-----------|---------|-------------|
108
+ | **Spatial units** | `from exp settings` | Units for scale, starting coord and marker size: `cm`, `pix`, `height` (or the experiment's units). Scale is *units per millimetre* of MoCap data (e.g. `pix`: px/mm); starting coord and marker size are in the unit itself. Visual-degree units are not offered (they depend on the monitor size and viewing distance), nor is `norm` (its x and y units differ on a non-square window, which would stretch the figure). If `from exp settings` resolves to visual degrees, the dialog shows a warning (OK stays enabled) and the experiment logs one at Begin Experiment. |
109
+ | **Anchor** | `center` | Where the figure sits before scale / position / rotation. `none` = coordinates as recorded; `center` = centre of the selected markers' bounding box at the origin (the figure still travels); `center, no travel` = centred and walks in place (horizontal travel removed every frame). Rotation and mirroring (negative Scale) act about this centre. Noise markers use the same (anchored) area. Fixed for the experiment; to change it per Routine call `<name>.setAnchor('center')` from a Code component (Begin Routine). |
110
+ | **Auto scale** | all files | Fits the figure to a share of the window height (*Fit height*). **all files**: the tallest frame over all the files sets one scale, so relative sizes between files are kept. **per file**: each file's tallest frame (files of different heights end up equally tall). **off**: use the Scale below as units per mm. |
111
+ | **Fit height** | `0.5` | Auto scale only: the share of the window height that the tallest frame fills (`0.5` = half, `1` = the full height). Empty = `0.5`. Disabled when Auto scale is off. |
112
+ | **Scale [x, y, z]** | *(empty)* | One number or `[x, y, z]`. **Auto scale off**: spatial units **per millimetre** of MoCap data (e.g. `0.05` with `pix` = 0.05 px/mm, as in the MATLAB BioMotion toolbox); required. **Auto scale on**: a multiplier on the automatic scale (empty or `1` = unchanged, `2` = twice as big). **Negative values mirror the figure** along that axis: `x = -1` flips left-right, `[1, -1, 1]` flips upside down, `[1, 1, -1]` flips front-back (depth; only visible after rotating). Mirroring is about the figure's centre when Anchor is not `none`. Can be *set every repeat* (e.g. `$mirror` from a conditions file: `1` / `-1`) to counterbalance direction. |
113
+ | **Starting coord [x, y, z]** | `(0, 0, 0)` | Translation offset in spatial units, applied after scaling and rotation. |
114
+ | **Rotation [pitch, roll, yaw]** | `(0, 0, 0)` | Rotation in degrees applied before orthographic projection. Unbounded. |
115
+
116
+ ### Appearance
117
+
118
+ | Parameter | Default | Description |
119
+ |-----------|---------|-------------|
120
+ | **Per-condition marker selection** | `False` | False: one *Marker selection* for every file; every selected marker must be in all of them. True: *Marker selection* can be *set every repeat* (e.g. `$markers` from a conditions file; names and / or indices, empty cell = all), and every marker selected for a trial must be in its file. Auto scale and Anchor then use **all** markers, so the figure keeps its size and place when the selection changes. The selection of each trial is saved as `<name>.markers`. |
121
+ | **Marker selection** | *(empty = all)* | Comma-separated markers to render, each either a **name** (label) or an **index counted from 0**, e.g. `liu:RSHO, 3, 7`. A name wins over an index if both match. Empty renders all markers. Indices can point to different markers in different files; use names across files. |
122
+ | **Marker color** | `(1, 1, 1)` (white) | Global RGB colour for all markers (PsychoPy `[-1, 1]` range). |
123
+ | **Specific marker color** | *(empty)* | Per-marker colour overrides. One per line: `MarkerName = R, G, B`. Values are in [-1, 1]. The dialog rejects malformed lines (OK is disabled until fixed); unknown names log a warning at run time and use the global colour. |
124
+ | **Opacity** | `1` | Marker opacity. `0` = fully transparent, `1` = fully opaque. |
125
+ | **Marker size** | *(empty = auto)* | Marker diameter in spatial units. Empty = 1% of the window height. |
126
+ | **Marker shape** | `circle` | Shape of each marker: `circle`, `square`, or `cross`. |
127
+ | **Missing data** | `don't draw` | Markers without a position in a frame (gaps in the recording): `don't draw` leaves them out; `interpolate` fills each gap linearly between the marker's recorded positions before and after it (a gap at the start or end holds the nearest recorded position; a marker never recorded is not drawn); `draw at position` draws them at *Missing position*. Can be *set every repeat* (type `$` and a variable). Gaps never count towards Auto scale, Anchor or the scramble box. |
128
+ | **Missing position [x, y]** | `(0, 0)` | Screen position, in spatial units, for missing markers with `draw at position` (whatever the figure's position, scale and rotation). Enabled only for that option. |
129
+
130
+ #### Per-marker colour example
131
+
132
+ ```
133
+ Head = 1.0, -1.0, -1.0
134
+ LHand = -1.0, 1.0, -1.0
135
+ RHand = -1.0, -1.0, 1.0
136
+ ```
137
+
138
+ ### Playback
139
+
140
+ Playback follows real elapsed time (the predicted screen-flip time when *Sync timing with screen refresh* is on), so dropped frames don't slow the animation down.
141
+
142
+ | Parameter | Default | Description |
143
+ |-----------|---------|-------------|
144
+ | **Loop playback** | `False` | Restart the animation from the first frame when it finishes. Without looping, the component finishes when the animation ends. |
145
+ | **Stop with Routine** | `True` | Restart the animation at every Routine. If unchecked, playback resumes where the previous Routine left off. |
146
+ | **Speed** | `1.0` | Playback speed multiplier. `2.0` = twice as fast, `0.5` = half speed. Must be greater than 0 (checked in the dialog and, for variables and scripts, at run time). |
147
+ | **Spatial scramble** | `0` | Amount of spatial scrambling `[0–1]`. `0` = none, `1` = full scramble. |
148
+ | **Scramble area [w, h]** | *(empty)* | Box for spatial scrambling, in spatial units: `[width, height]` or `[width, height, depth]`. Each marker starts at a random point in the box (centred on the figure's first-frame centre) and keeps its own motion, as in the BioMotion toolbox (`ScrambleWidth`, `ScrambleHeight`, `ScrambleDepth`; depth defaults to the motion's depth). Empty = the default scramble below. Can be *set every repeat*. |
149
+ | **Temporal scramble** | `False` | Cut the played frames into time segments and play them in a random order. The three settings below are greyed out while it is `False`. |
150
+ | **Time segments** | `10` | Number of segments, from 2 to the number of played frames. If the frames don't divide evenly, some segments are one frame longer; the dialog says so, and every frame still plays exactly once. |
151
+ | **Shuffle each marker separately** | `False` | False: all markers share one order, so every pose is intact and only the order of poses changes. True: each marker gets its own order. |
152
+ | **Allow unchanged order** | `False` | True: a random order may be the original one. False: it is drawn again until it differs. |
153
+ | **Noise marker count** | `0` | Number of random noise markers rendered alongside the animation. |
154
+
155
+ Scale, starting coord, rotation, marker colour, opacity, marker size and speed can be *set every repeat* or *set every frame*; spatial scramble, scramble area, the four temporal scramble settings and noise marker count can be *set every repeat*. The True / False settings are drop-downs that also accept a variable name (e.g. a conditions column holding True / False or 1 / 0).
156
+
157
+ **Drawing order.** Like PsychoPy's own visual components, the markers are drawn at each screen flip in Component order: a Component lower in the Routine is drawn on top. To show a fixation cross over the walker, put the Text Component below PyoMotion; to draw the markers over it, put it above.
158
+
159
+ #### Scrambling and reproducibility
160
+
161
+ Scrambling is re-drawn at the start of every Routine. PsychoPy has no experiment-wide random seed, so PyoMotion draws its seed from NumPy's global random state at Begin Experiment: call `np.random.seed(n)` in a Begin Experiment code component (placed before PyoMotion) to make scrambling and noise markers reproducible. Each Routine's seed is saved to the data file as `<name>.seed`.
162
+
163
+ - **Spatial scramble** — Each marker's trajectory is displaced by a random vector drawn from the bounding box of all marker positions. The displacement magnitude is linearly scaled by the `amount` parameter (`1.0` moves each marker by up to one full bounding-box width). The relative motion of each marker is preserved exactly.
164
+ - **Spatial scramble with a Scramble area** — Each marker's starting point is moved to a random point in the given box (centred on the figure's first-frame centre), and the marker then follows its own recorded motion from there, as in the BioMotion toolbox. The figure's travel is kept; only the spatial layout is lost.
165
+ - **Temporal scramble** — The played frames (after First / Stop frame) are cut into *Time segments* of equal length, or lengths differing by one frame, and whole segments are reordered. Marker positions are moved in time exactly as recorded, travel included: with a travelling figure and one shared order the figure jumps between places at segment boundaries; with separate orders the markers spread over the path travelled, also under *Anchor: center, no travel*.
166
+
167
+ ### Data
168
+
169
+ PyoMotion uses PsychoPy's standard **Save onset/offset times** and **Sync timing with screen refresh** options (both on by default).
170
+
171
+ ---
172
+
173
+ ## MoCap information and preview (in the dialog)
174
+
175
+ The Biological Motion component's dialog has a side panel next to its tabs. It stays visible on every tab and updates about 0.2 s after you stop typing.
176
+
177
+ - **Information.** File name, format, size, frames, frame rate and duration, the played range (First / Stop frame) and how many markers are drawn, the figure height, and missing data. A list shows every marker with its index and name; tick the markers to draw and *Marker selection* is filled in for you (keeping its order; all ticked = empty = all markers). A ⚠ next to a marker means it is outside the window in the frame shown; this follows playback and the slider. With several files the list shows the markers they all share.
178
+ - **Preview.** One frame of the animation as it will appear in the experiment. It uses the experiment window's size (or the screen's, when full-screen), units and background colour, and draws the markers with their colour, opacity, size and shape. The marker positions come from the same code the experiment runs, so they match exactly. Markers outside the window are clipped, as in the experiment. Scramble and noise are re-drawn after every change, as in a new trial.
179
+ - **Several files.** When *MoCap data* is a `$column` set every repeat and the Loop's conditions list several files, a table shows each file with its frames, rate, markers, figure height and status. **Select a file in the table to preview it** (the first one that exists is shown at first). It is drawn with the values of the preview condition (below), and, with *Auto scale: all files*, at the scale all the files share. The information above the table and the ⚠ flags are for that file. The marker list holds the markers all the files share; a marker's index is shown only if it is the same in every file, and an orange note says so when some are hidden. With *Per-condition marker selection*, the list instead holds the selected file's markers with its indices, ticked as the preview condition selects them; the ticks can't be changed when the selection comes from a variable.
180
+ - **Files chosen by code.** If the files can't be worked out (an expression such as `$'dir/' + name`, or no such column), the preview shows a **placeholder walker**: one gait cycle of CMU walk 07_11, with the 14 joints of a typical point-light walker. Marker selection applies to it by name; indices are ignored, because they count the real files' markers.
181
+ - **Preview condition.** When the Routine is in a Loop with conditions, this selects the conditions row the preview uses. With several files, the file table follows it: choosing a row selects that row's file, and selecting a file moves to a row that uses it (keeping the current row if it already does). Tick **only for selected file** to step through just the selected file's rows. With nested Loops it steps through the Loop that names the files (otherwise the innermost one), using the first row of the others.
182
+ - **Variables.** A value such as `$scale_x` or `[scale_x, 0.25, scale_x]` is taken from the preview condition. Anything else that is code (for example a variable set in a Code component) uses the parameter's default, and the panel lists which ones did.
183
+ - **Controls.**
184
+ - **▶ Play**: plays the animation in real time at the set Speed. It follows *Loop playback*, so without looping it stops after the last frame, as in the experiment.
185
+ - **The slider**: picks a frame.
186
+ - **PsychoPy window**: opens these settings in a real PsychoPy window, rendered exactly as in the experiment, in a separate process (Space play/pause, R restart, N new draw, Esc close).
187
+ - **Hide**: folds the panel away.
188
+ - **Checks against the file.** Once the file(s) have loaded, a First/Stop frame outside a file disables OK with a message naming the file. A selected marker that is missing from any file (with *Per-condition marker selection*: from the file of the condition that selects it) also disables OK. A specific-colour name that isn't in the file gives a warning only.
189
+
190
+ Cancel discards everything, including markers ticked in the list. The preview doesn't change the experiment or its generated code.
191
+
192
+ *Placeholder data: CMU Graphics Lab Motion Capture Database, mocap.cs.cmu.edu (subject 7, trial 11).*
193
+
194
+ ---
195
+
196
+ ## TRC File Format
197
+
198
+ TRC is the marker format of Motion Analysis and OpenSim. PyoMotion reads the common "PathFileType 4" layout, tab-, comma- or space-delimited:
199
+
200
+ ```
201
+ PathFileType 4 (X/Y/Z) walk.trc
202
+ DataRate CameraRate NumFrames NumMarkers Units OrigDataRate OrigDataStartFrame OrigNumFrames
203
+ 60.00 60.00 151 41 mm 60.00 1 151
204
+ Frame# Time R.ASIS L.ASIS ...
205
+ X1 Y1 Z1 X2 Y2 Z2 ...
206
+
207
+ 1 0.000 617.2 1055.3 170.8 639.6 1044.3 -88.9 ...
208
+ ```
209
+
210
+ - The frame rate comes from `DataRate`, the units from `Units`.
211
+ - TRC doesn't say which axis is up: **Y** is assumed (OpenSim's convention) and the dialog notes it; set *Vertical axis* to `Z` for Z-up files.
212
+ - Empty fields and `NaN` are missing samples (see *Missing data*).
213
+ - If the header's frame or marker count disagrees with the data, the data is used and the dialog says so.
214
+
215
+ `psychopy_pyomotion.parsers.trc_parser.write_trc(path, names, frames, rate, units)` writes such a file from an array, e.g. to convert data from another tool.
216
+
217
+ ---
218
+
219
+ ## BioMotion Toolbox data3d (`.txt`)
220
+
221
+ For labs moving from the MATLAB [BioMotion toolbox](https://jov.arvojournals.org/article.aspx?articleid=2121531) (van Boxtel & Lu, 2013), PyoMotion reads the toolbox's own text format, the one `BioMotion.SaveData3D` writes and `BioMotion('file.txt')` reads by default. `.txt` means this format and nothing else.
222
+
223
+ - **Layout:** a number matrix, one column per marker and three rows per frame (x, y, z of frame 1, then frame 2, ...), separated by spaces or tabs. y is up. `NaN` is a missing sample.
224
+ - **Marker names:** the file has none, so the markers are named `J1` ... `Jn`, after the toolbox's 1-based joint numbers.
225
+ - **Units and frame rate:** the file states neither. PyoMotion assumes **mm** (the toolbox keeps C3D data in mm) and **120 Hz**, and says so in the dialog. Set *File units* and *Frame rate* to the right values; units only matter for absolute sizes, the frame rate sets the playback speed.
226
+
227
+ Toolbox settings in PyoMotion:
228
+
229
+ | BioMotion toolbox | PyoMotion |
230
+ |---|---|
231
+ | `'SelectJoints', [2 3 4]` (1-based) | *Marker selection* `J2, J3, J4` (names), or `1, 2, 3` (0-based indices) |
232
+ | `'SelectFrames', 28:312` (1-based, inclusive) | *First frame* `27`, *Stop frame* `312` (0-based, stop exclusive) |
233
+ | `'Anchor', 'none'` | *Anchor* `none` |
234
+ | one frame per loop iteration, `SecondsBetweenFrames` | *Frame rate* and *Speed* (playback follows real time) |
235
+
236
+ A folder given to `preload` (scripts) now also loads the `.txt` files in it.
237
+
238
+ ---
239
+
240
+ ## Advanced Usage
241
+
242
+ ### Controlling the stimulus from Python code
243
+
244
+ The generated experiment code creates a `PyoMotionStim` instance. In a Code component you can access it directly:
245
+
246
+ ```python
247
+ # In a Code component (e.g. "Each Frame" tab)
248
+ # Check if the animation has finished
249
+ if myStim.is_finished:
250
+ continueRoutine = False
251
+
252
+ # Get current 2D positions (shape: n_markers × 2)
253
+ pos = myStim.get_frame_positions_2d()
254
+ ```
255
+
256
+ ### Using PyoMotionStim standalone (outside Builder)
257
+
258
+ ```python
259
+ from psychopy import core
260
+ from psychopy_pyomotion.runtime import PyoMotionStim
261
+
262
+ stim = PyoMotionStim(
263
+ win=win,
264
+ name="walker",
265
+ mocap_path="data/walker01.c3d",
266
+ loop=True,
267
+ speed=1.0,
268
+ spatial_scramble_amount=0.0,
269
+ )
270
+ stim.load(seed=42)
271
+
272
+ # At start of each trial
273
+ stim.begin_routine()
274
+
275
+ clock = core.Clock()
276
+ while not stim.is_finished:
277
+ stim.update(clock.getTime()) # advances by real elapsed time
278
+ stim.draw() # or stim.setAutoDraw(True) once
279
+ win.flip()
280
+ ```
281
+
282
+ ### Registering a custom parser
283
+
284
+ ```python
285
+ from psychopy_pyomotion.parsers import register_parser
286
+ from psychopy_pyomotion.parsers.base_parser import BaseMoCapParser
287
+ from psychopy_pyomotion.parsers.import_settings import RawData
288
+ import numpy as np
289
+
290
+ class MyParser(BaseMoCapParser):
291
+ supported_extensions = ["myformat"] # lower case, without the dot
292
+ format_name = "My format"
293
+
294
+ def read(self, filepath) -> RawData:
295
+ # ... load your format here: positions as stored, NaN = missing ...
296
+ positions = np.zeros((n_frames, n_markers, 3))
297
+ return RawData(format="My format", positions=positions, marker_names=[...],
298
+ frame_rate=120.0, units="mm", vertical_axis="Z")
299
+
300
+ register_parser(MyParser())
301
+ ```
302
+
303
+ ---
304
+
305
+ ## Coordinate System
306
+
307
+ All data is converted at load time to **Y up** (vertical axis is Y) and **metres**:
308
+
309
+ | Format | Axis | Unit |
310
+ |--------|------|------|
311
+ | C3D | Z-up → Y-up by swapping Y and Z, as the BioMotion toolbox does | mm → m |
312
+ | BVH | Y-up | cm → m (assumed) |
313
+ | TRC | Y-up (assumed; *Vertical axis* to change it) | from the header (`Units`) |
314
+
315
+ Swapping two axes turns a right-handed system into a left-handed one, so C3D depth (Z) has the opposite sign of a right-handed Y-up system. This matches the BioMotion toolbox and only shows when the figure is rotated in depth (pitch or yaw); the V3 SRS lists it as an open question. Orthographic projection discards Z to produce 2D screen coordinates.
316
+
317
+ ---
318
+
319
+ ## Known Limitations
320
+
321
+ - The in-dialog preview is drawn with wx from the experiment's own positions. Marker edges and anti-aliasing can differ slightly from PsychoPy's rendering; use the **PsychoPy window** button for an exact check. Other Components of the Routine (e.g. a fixation cross) are not shown in the preview.
322
+ - Depth cues are not available — the display is always orthographic.
323
+ - No PsychoJS (online) version.
324
+ - BVH files state no units and cm is assumed; check *File units* if absolute sizes matter. CMU's BVH conversions differ: some are close to cm, while the 2010 conversion (`sample_data/07_11.bvh`) uses CMU's unit of about 5.64 cm, which none of the *File units* choices matches; use *Auto scale*, or allow for it in *Scale*.
325
+
326
+ ---
327
+
328
+ ## Troubleshooting
329
+
330
+ **Plugin does not appear in Builder** — Ensure both PsychoPy and `psychopy-pyomotion` are installed in the same Python environment and that PsychoPy has been restarted after installation.
331
+
332
+ **`No module named 'psychtoolbox'` warning** — This is a harmless PsychoPy warning; it falls back to its built-in `event` module for keyboard handling.
333
+
334
+ **`markers not found` error** — Each entry in **Marker selection** must be a marker name that exactly matches the file (case-sensitive) or an index from 0 to the number of markers − 1. The error lists every marker with its index. Leave the field empty to render all markers.
335
+
336
+ **Animation does not start** — Check that the **Start** time and the Routine duration are set correctly. If **Stop** is left empty, the animation plays to its end (with *Loop playback*, until the Routine ends).
337
+
338
+ ---
339
+
340
+ ## Development
341
+
342
+ ```bash
343
+ # Create and activate venv (Python 3.11)
344
+ python3.11 -m venv --system-site-packages .venv && source .venv/bin/activate
345
+
346
+ # Install in editable mode with test dependencies (quotes for zsh)
347
+ pip install -e '.[tests]'
348
+
349
+ # Build the sdist and wheel into dist/
350
+ python -m build
351
+
352
+ # Run all tests
353
+ pytest
354
+
355
+ # Run a single test
356
+ pytest tests/test_parsers.py::TestTRCParser::test_opensim_layout
357
+ ```
358
+
359
+ ---
360
+
361
+ ## License
362
+
363
+ MIT, see [LICENSE](https://github.com/ulasdilek/psychopy-pyomotion/blob/main/LICENSE). Changes are listed in [CHANGELOG.md](https://github.com/ulasdilek/psychopy-pyomotion/blob/main/CHANGELOG.md). The sample data and the placeholder walker are from the [CMU Graphics Lab Motion Capture Database](http://mocap.cs.cmu.edu).