ephys-link 2.0.0b5__py3-none-any.whl → 2.0.0b9__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.
- ephys_link/__about__.py +1 -1
- ephys_link/__main__.py +51 -43
- ephys_link/back_end/platform_handler.py +315 -305
- ephys_link/back_end/server.py +274 -202
- ephys_link/bindings/{fake_bindings.py → fake_binding.py} +84 -59
- ephys_link/bindings/{mpm_bindings.py → mpm_binding.py} +315 -278
- ephys_link/bindings/{ump_4_bindings.py → ump_4_binding.py} +157 -131
- ephys_link/front_end/cli.py +104 -98
- ephys_link/front_end/gui.py +204 -215
- ephys_link/{util/base_bindings.py → utils/base_binding.py} +176 -148
- ephys_link/{util → utils}/console.py +127 -130
- ephys_link/utils/constants.py +23 -0
- ephys_link/utils/converters.py +86 -0
- ephys_link/utils/startup.py +65 -0
- ephys_link-2.0.0b9.dist-info/METADATA +91 -0
- ephys_link-2.0.0b9.dist-info/RECORD +25 -0
- {ephys_link-2.0.0b5.dist-info → ephys_link-2.0.0b9.dist-info}/WHEEL +1 -1
- {ephys_link-2.0.0b5.dist-info → ephys_link-2.0.0b9.dist-info}/licenses/LICENSE +674 -674
- ephys_link/resources/CP210xManufacturing.dll +0 -0
- ephys_link/resources/NstMotorCtrl.dll +0 -0
- ephys_link/resources/SiUSBXp.dll +0 -0
- ephys_link/util/common.py +0 -120
- ephys_link-2.0.0b5.dist-info/METADATA +0 -166
- ephys_link-2.0.0b5.dist-info/RECORD +0 -26
- /ephys_link/{util → utils}/__init__.py +0 -0
- {ephys_link-2.0.0b5.dist-info → ephys_link-2.0.0b9.dist-info}/entry_points.txt +0 -0
|
@@ -1,131 +1,157 @@
|
|
|
1
|
-
"""Bindings for Sensapex uMp-4 platform.
|
|
2
|
-
|
|
3
|
-
Usage: Instantiate Ump4Bindings to interact with the Sensapex uMp-4 platform.
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
from asyncio import get_running_loop
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
from
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
from ephys_link.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def
|
|
42
|
-
return
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
async def
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
#
|
|
103
|
-
#
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
#
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
1
|
+
"""Bindings for Sensapex uMp-4 platform.
|
|
2
|
+
|
|
3
|
+
Usage: Instantiate Ump4Bindings to interact with the Sensapex uMp-4 platform.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from asyncio import get_running_loop
|
|
7
|
+
from typing import NoReturn, final, override
|
|
8
|
+
|
|
9
|
+
from sensapex import UMP, SensapexDevice # pyright: ignore [reportMissingTypeStubs]
|
|
10
|
+
from vbl_aquarium.models.unity import Vector4
|
|
11
|
+
|
|
12
|
+
from ephys_link.utils.base_binding import BaseBinding
|
|
13
|
+
from ephys_link.utils.constants import RESOURCES_DIRECTORY
|
|
14
|
+
from ephys_link.utils.converters import (
|
|
15
|
+
list_to_vector4,
|
|
16
|
+
scalar_mm_to_um,
|
|
17
|
+
um_to_mm,
|
|
18
|
+
vector4_to_array,
|
|
19
|
+
vector_mm_to_um,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@final
|
|
24
|
+
class Ump4Binding(BaseBinding):
|
|
25
|
+
"""Bindings for UMP-4 platform"""
|
|
26
|
+
|
|
27
|
+
def __init__(self) -> None:
|
|
28
|
+
"""Initialize UMP-4 bindings."""
|
|
29
|
+
|
|
30
|
+
# Establish connection to Sensapex API (exit if connection fails).
|
|
31
|
+
UMP.set_library_path(RESOURCES_DIRECTORY)
|
|
32
|
+
self._ump = UMP.get_ump() # pyright: ignore [reportUnknownMemberType]
|
|
33
|
+
|
|
34
|
+
@staticmethod
|
|
35
|
+
@override
|
|
36
|
+
def get_display_name() -> str:
|
|
37
|
+
return "Sensapex uMp-4"
|
|
38
|
+
|
|
39
|
+
@staticmethod
|
|
40
|
+
@override
|
|
41
|
+
def get_cli_name() -> str:
|
|
42
|
+
return "ump-4"
|
|
43
|
+
|
|
44
|
+
@override
|
|
45
|
+
async def get_manipulators(self) -> list[str]:
|
|
46
|
+
return list(map(str, self._ump.list_devices()))
|
|
47
|
+
|
|
48
|
+
@override
|
|
49
|
+
async def get_axes_count(self) -> int:
|
|
50
|
+
return 4
|
|
51
|
+
|
|
52
|
+
@override
|
|
53
|
+
def get_dimensions(self) -> Vector4:
|
|
54
|
+
return Vector4(x=20, y=20, z=20, w=20)
|
|
55
|
+
|
|
56
|
+
@override
|
|
57
|
+
async def get_position(self, manipulator_id: str) -> Vector4:
|
|
58
|
+
return um_to_mm(list_to_vector4(self._get_device(manipulator_id).get_pos(1))) # pyright: ignore [reportUnknownMemberType]
|
|
59
|
+
|
|
60
|
+
@override
|
|
61
|
+
async def get_angles(self, manipulator_id: str) -> NoReturn:
|
|
62
|
+
"""uMp-4 does not support getting angles so raise an error.
|
|
63
|
+
|
|
64
|
+
Raises:
|
|
65
|
+
AttributeError: uMp-4 does not support getting angles.
|
|
66
|
+
"""
|
|
67
|
+
error_message = "UMP-4 does not support getting angles"
|
|
68
|
+
raise AttributeError(error_message)
|
|
69
|
+
|
|
70
|
+
@override
|
|
71
|
+
async def get_shank_count(self, manipulator_id: str) -> NoReturn:
|
|
72
|
+
"""uMp-4 does not support getting shank count so raise an error.
|
|
73
|
+
|
|
74
|
+
Raises:
|
|
75
|
+
AttributeError: uMp-4 does not support getting shank count.
|
|
76
|
+
"""
|
|
77
|
+
error_message = "UMP-4 does not support getting shank count"
|
|
78
|
+
raise AttributeError(error_message)
|
|
79
|
+
|
|
80
|
+
@override
|
|
81
|
+
def get_movement_tolerance(self) -> float:
|
|
82
|
+
return 0.001
|
|
83
|
+
|
|
84
|
+
@override
|
|
85
|
+
async def set_position(self, manipulator_id: str, position: Vector4, speed: float) -> Vector4:
|
|
86
|
+
# Convert position to micrometers.
|
|
87
|
+
target_position_um = vector_mm_to_um(position)
|
|
88
|
+
|
|
89
|
+
# Request movement.
|
|
90
|
+
movement = self._get_device(manipulator_id).goto_pos( # pyright: ignore [reportUnknownMemberType]
|
|
91
|
+
vector4_to_array(target_position_um), scalar_mm_to_um(speed)
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
# Wait for movement to finish.
|
|
95
|
+
_ = await get_running_loop().run_in_executor(None, movement.finished_event.wait, None)
|
|
96
|
+
|
|
97
|
+
# Handle interrupted movement.
|
|
98
|
+
if movement.interrupted:
|
|
99
|
+
error_message = f"Manipulator {manipulator_id} interrupted: {movement.interrupt_reason}" # pyright: ignore [reportUnknownMemberType]
|
|
100
|
+
raise RuntimeError(error_message)
|
|
101
|
+
|
|
102
|
+
# Handle empty end position.
|
|
103
|
+
if not movement.last_pos: # pyright: ignore [reportUnknownMemberType]
|
|
104
|
+
error_message = f"Manipulator {manipulator_id} did not reach target position"
|
|
105
|
+
raise RuntimeError(error_message)
|
|
106
|
+
|
|
107
|
+
return um_to_mm(list_to_vector4(movement.last_pos)) # pyright: ignore [reportArgumentType, reportUnknownMemberType]
|
|
108
|
+
|
|
109
|
+
@override
|
|
110
|
+
async def set_depth(self, manipulator_id: str, depth: float, speed: float) -> float:
|
|
111
|
+
# Augment current position with depth.
|
|
112
|
+
current_position = await self.get_position(manipulator_id)
|
|
113
|
+
new_platform_position = current_position.model_copy(update={"w": depth})
|
|
114
|
+
|
|
115
|
+
# Make the movement.
|
|
116
|
+
final_platform_position = await self.set_position(manipulator_id, new_platform_position, speed)
|
|
117
|
+
|
|
118
|
+
# Return the final depth.
|
|
119
|
+
return float(final_platform_position.w)
|
|
120
|
+
|
|
121
|
+
@override
|
|
122
|
+
async def stop(self, manipulator_id: str) -> None:
|
|
123
|
+
self._get_device(manipulator_id).stop()
|
|
124
|
+
|
|
125
|
+
@override
|
|
126
|
+
def platform_space_to_unified_space(self, platform_space: Vector4) -> Vector4:
|
|
127
|
+
# unified <- platform
|
|
128
|
+
# +x <- +y
|
|
129
|
+
# +y <- -z
|
|
130
|
+
# +z <- +x
|
|
131
|
+
# +d <- +d
|
|
132
|
+
|
|
133
|
+
return Vector4(
|
|
134
|
+
x=platform_space.y,
|
|
135
|
+
y=self.get_dimensions().z - platform_space.z,
|
|
136
|
+
z=platform_space.x,
|
|
137
|
+
w=platform_space.w,
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
@override
|
|
141
|
+
def unified_space_to_platform_space(self, unified_space: Vector4) -> Vector4:
|
|
142
|
+
# platform <- unified
|
|
143
|
+
# +x <- +z
|
|
144
|
+
# +y <- +x
|
|
145
|
+
# +z <- -y
|
|
146
|
+
# +d <- +d
|
|
147
|
+
|
|
148
|
+
return Vector4(
|
|
149
|
+
x=unified_space.z,
|
|
150
|
+
y=unified_space.x,
|
|
151
|
+
z=self.get_dimensions().z - unified_space.y,
|
|
152
|
+
w=unified_space.w,
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
# Helper methods.
|
|
156
|
+
def _get_device(self, manipulator_id: str) -> SensapexDevice:
|
|
157
|
+
return self._ump.get_device(int(manipulator_id)) # pyright: ignore [reportUnknownMemberType]
|
ephys_link/front_end/cli.py
CHANGED
|
@@ -1,98 +1,104 @@
|
|
|
1
|
-
"""Command-line interface for the Electrophysiology Manipulator Link.
|
|
2
|
-
|
|
3
|
-
Usage:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
action="store_true",
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"-
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"-
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
"-
|
|
86
|
-
"
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
1
|
+
"""Command-line interface for the Electrophysiology Manipulator Link.
|
|
2
|
+
|
|
3
|
+
Usage:
|
|
4
|
+
Instantiate CLI and call `parse_args()` to get the parsed arguments.
|
|
5
|
+
|
|
6
|
+
```python
|
|
7
|
+
CLI().parse_args()
|
|
8
|
+
```
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from argparse import ArgumentParser
|
|
12
|
+
from typing import final
|
|
13
|
+
|
|
14
|
+
from vbl_aquarium.models.ephys_link import EphysLinkOptions
|
|
15
|
+
|
|
16
|
+
from ephys_link.__about__ import __version__ as version
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@final
|
|
20
|
+
class CLI:
|
|
21
|
+
"""Command-line interface for the Electrophysiology Manipulator Link.
|
|
22
|
+
|
|
23
|
+
Configures the CLI parser and options.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(self) -> None:
|
|
27
|
+
"""Initialize CLI parser."""
|
|
28
|
+
|
|
29
|
+
self._parser = ArgumentParser(
|
|
30
|
+
description="Electrophysiology Manipulator Link: a Socket.IO interface for manipulators in electrophysiology experiments.",
|
|
31
|
+
prog="python -m ephys-link",
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
_ = self._parser.add_argument(
|
|
35
|
+
"-b", "--background", dest="background", action="store_true", help="Skip configuration window."
|
|
36
|
+
)
|
|
37
|
+
_ = self._parser.add_argument(
|
|
38
|
+
"-i",
|
|
39
|
+
"--ignore-updates",
|
|
40
|
+
dest="ignore_updates",
|
|
41
|
+
action="store_true",
|
|
42
|
+
help="Skip (ignore) checking for updates.",
|
|
43
|
+
)
|
|
44
|
+
_ = self._parser.add_argument(
|
|
45
|
+
"-t",
|
|
46
|
+
"--type",
|
|
47
|
+
type=str,
|
|
48
|
+
dest="type",
|
|
49
|
+
default="ump-4",
|
|
50
|
+
help='Manipulator type (i.e. "ump-4", "pathfinder-mpm", "fake"). Default: "ump-4".',
|
|
51
|
+
)
|
|
52
|
+
_ = self._parser.add_argument(
|
|
53
|
+
"-d",
|
|
54
|
+
"--debug",
|
|
55
|
+
dest="debug",
|
|
56
|
+
action="store_true",
|
|
57
|
+
help="Enable debug mode.",
|
|
58
|
+
)
|
|
59
|
+
_ = self._parser.add_argument(
|
|
60
|
+
"-p",
|
|
61
|
+
"--use-proxy",
|
|
62
|
+
dest="use_proxy",
|
|
63
|
+
action="store_true",
|
|
64
|
+
help="Enable proxy mode.",
|
|
65
|
+
)
|
|
66
|
+
_ = self._parser.add_argument(
|
|
67
|
+
"-a",
|
|
68
|
+
"--proxy-address",
|
|
69
|
+
type=str,
|
|
70
|
+
default="proxy2.virtualbrainlab.org",
|
|
71
|
+
dest="proxy_address",
|
|
72
|
+
help="Proxy IP address.",
|
|
73
|
+
)
|
|
74
|
+
_ = self._parser.add_argument(
|
|
75
|
+
"--mpm-port",
|
|
76
|
+
type=int,
|
|
77
|
+
default=8080,
|
|
78
|
+
dest="mpm_port",
|
|
79
|
+
help="Port New Scale Pathfinder MPM's server is on. Default: 8080.",
|
|
80
|
+
)
|
|
81
|
+
_ = self._parser.add_argument(
|
|
82
|
+
"-s",
|
|
83
|
+
"--serial",
|
|
84
|
+
type=str,
|
|
85
|
+
default="no-e-stop",
|
|
86
|
+
dest="serial",
|
|
87
|
+
nargs="?",
|
|
88
|
+
help="Emergency stop serial port (i.e. COM3). Default: disables emergency stop.",
|
|
89
|
+
)
|
|
90
|
+
_ = self._parser.add_argument(
|
|
91
|
+
"-v",
|
|
92
|
+
"--version",
|
|
93
|
+
action="version",
|
|
94
|
+
version=f"Electrophysiology Manipulator Link v{version}",
|
|
95
|
+
help="Print version and exit.",
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
def parse_args(self) -> EphysLinkOptions:
|
|
99
|
+
"""Parse arguments and return them
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
Parsed arguments
|
|
103
|
+
"""
|
|
104
|
+
return EphysLinkOptions(**vars(self._parser.parse_args())) # pyright: ignore [reportAny]
|