pbl-exp 0.1__py3-none-any.whl

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.
PBL/exp/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ from .pupil_labs import get_pupil_labs_device, send_event_to_pupil_labs
2
+
3
+ __all__ = ["get_pupil_labs_device", "send_event_to_pupil_labs"]
PBL/exp/eyelink.py ADDED
File without changes
PBL/exp/psychopy.py ADDED
File without changes
PBL/exp/pupil_labs.py ADDED
@@ -0,0 +1,99 @@
1
+ import sys
2
+ from time import time_ns
3
+
4
+ from psychopy import gui, logging
5
+ from pupil_labs.realtime_api.simple import Device, discover_devices
6
+
7
+
8
+ def get_pupil_labs_device(search_duration_seconds=5.0):
9
+ """
10
+ Get the Pupil Labs device and its time offset.
11
+
12
+ Parameters
13
+ ----------
14
+ search_duration_seconds : float
15
+ Duration to search for Pupil Labs devices.
16
+
17
+ Returns
18
+ -------
19
+ device : object or None
20
+ The connected Pupil Labs device, or None if not used.
21
+ median_offset_ns : int or None
22
+ The estimated median time offset of the device in nanoseconds, or None if not used.
23
+
24
+ Raises
25
+ ------
26
+ RuntimeError
27
+ If no Pupil Labs device is found when one is expected.
28
+ """
29
+ # Get whether to use the Pupil Labs Eye Tracker
30
+ dlg = gui.Dlg(title="Pupil Labs Eye Tracker")
31
+ dlg.addField("Use Pupil Labs eye tracker?", False, choices=[True, False])
32
+ dlg_data = dlg.show()
33
+ sys.exit() if not dlg.OK else None
34
+ record_pl = dlg_data[0]
35
+
36
+ if record_pl:
37
+ devices = discover_devices(search_duration_seconds=search_duration_seconds)
38
+ if not devices:
39
+ dlg = gui.Dlg(title="No Pupil Labs device found")
40
+ dlg.addText("No Pupil Labs device found. Check your connection.")
41
+ dlg.show()
42
+ raise RuntimeError("No Pupil Labs device found.")
43
+ elif len(devices) == 1:
44
+ device = devices[0]
45
+ dlg = gui.Dlg(title="Pupil Labs configuration")
46
+ dlg.addText(f"Using the only Pupil Labs device found at {device.address}")
47
+ dlg.show()
48
+ else:
49
+ ip_addresses = [device.address for device in devices]
50
+ dlg = gui.Dlg(title="Pupil Labs configuration")
51
+ dlg.addText("Multiple Pupil Labs devices found.")
52
+ dlg.addField("Select the device to use:", choices=ip_addresses)
53
+ dlg.show()
54
+ selected_ip = dlg.data[0]
55
+ for d in devices:
56
+ if d.address == selected_ip:
57
+ device = d
58
+ else:
59
+ d.close()
60
+ logging.info(f"Connected to Pupil Labs device at {device.address}")
61
+
62
+ median_offset_ns = round(
63
+ device.estimate_time_offset().time_offset_ms.median * 1_000_000
64
+ )
65
+ offset_std = round(device.estimate_time_offset().time_offset_ms.std * 1_000_000)
66
+ logging.info(
67
+ f"Estimated Pupil Labs device time offset (ns) = {median_offset_ns} ± {offset_std} (median ± std)"
68
+ )
69
+
70
+ return device, median_offset_ns
71
+ else:
72
+ return None, None
73
+
74
+
75
+ def send_event_to_pupil_labs(device: Device, event_string: str, clock_offset_ns: int):
76
+ """
77
+ Send an event to the Pupil Labs device with a timestamp.
78
+
79
+ Parameters
80
+ ----------
81
+ device : Device
82
+ The connected Pupil Labs device.
83
+ event_string : str
84
+ The event description to send.
85
+ clock_offset_ns : int
86
+ The clock offset in nanoseconds to adjust the event timestamp.
87
+ """
88
+ if device is not None:
89
+ device.send_event(
90
+ event_string,
91
+ event_timestamp_unix_ns=int(time_ns() - clock_offset_ns),
92
+ )
93
+
94
+
95
+ if __name__ == "__main__":
96
+ logging.console.setLevel(logging.INFO)
97
+ device, offset_ns = get_pupil_labs_device()
98
+ if device is not None:
99
+ device.close()
@@ -0,0 +1,15 @@
1
+ Metadata-Version: 2.4
2
+ Name: pbl-exp
3
+ Version: 0.1
4
+ Summary: Helper functions for running experiments at the Predictive Brain Lab (Bochum)
5
+ Author-email: Qian Chu <qianchu99@gmail.com>
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: psychopy
10
+ Requires-Dist: pupil-labs-realtime-api
11
+ Requires-Dist: sr-research-pylink
12
+ Dynamic: license-file
13
+
14
+ # pbl-exp
15
+
@@ -0,0 +1,9 @@
1
+ PBL/exp/__init__.py,sha256=kUAinEwPe-XFXPUMiNUIiMQ2Mcnim6LoUg6WF2fEuH4,137
2
+ PBL/exp/eyelink.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ PBL/exp/psychopy.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ PBL/exp/pupil_labs.py,sha256=TVYulqy7w3gNqxdIa21qF5GKh8M2VFo_X3_4n5WMu2Q,3338
5
+ pbl_exp-0.1.dist-info/licenses/LICENSE,sha256=Kp1DPQGh36k51G0yLkCg_spVbXzIi66A3FbmfEfylaE,1065
6
+ pbl_exp-0.1.dist-info/METADATA,sha256=tLv5m3rbfCI7BiLCcixtLGYz3ZhpPAfaHLMpulZqRnc,398
7
+ pbl_exp-0.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
8
+ pbl_exp-0.1.dist-info/top_level.txt,sha256=f91EmcvJrGR9OWvloABxrRykiMkHNcZhxeBj-bTK06c,4
9
+ pbl_exp-0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Qian Chu
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 @@
1
+ PBL