ephys-link 2.0.2__py3-none-any.whl → 2.1.0b1__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 CHANGED
@@ -1 +1 @@
1
- __version__ = "2.0.2"
1
+ __version__ = "2.1.0b1"
@@ -70,10 +70,22 @@ class PlatformHandler:
70
70
  Returns:
71
71
  Bindings for the specified platform type.
72
72
  """
73
+
74
+ # What the user supplied.
75
+ selected_type = options.type
76
+
73
77
  for binding_type in get_bindings():
74
78
  binding_cli_name = binding_type.get_cli_name()
75
79
 
76
- if binding_cli_name == options.type:
80
+ # Notify deprecation of "ump-4" and "ump-3" CLI options and fix.
81
+ if selected_type in ("ump-4", "ump-3"):
82
+ self._console.error_print(
83
+ "DEPRECATION",
84
+ f"CLI option '{selected_type}' is deprecated and will be removed in v3.0.0. Use 'ump' instead.",
85
+ )
86
+ selected_type = "ump"
87
+
88
+ if binding_cli_name == selected_type:
77
89
  # Pass in HTTP port for Pathfinder MPM.
78
90
  if binding_cli_name == "pathfinder-mpm":
79
91
  return MPMBinding(options.mpm_port)
@@ -0,0 +1,235 @@
1
+ """Bindings for Sensapex uMp platform.
2
+
3
+ Usage: Instantiate UmpBindings to interact with Sensapex uMp-4 and uMp-3 manipulators.
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 UmpBinding(BaseBinding):
25
+ """Bindings for uMp platform"""
26
+
27
+ # Number of axes for uMp-3.
28
+ UMP_3_NUM_AXES = 3
29
+
30
+ def __init__(self) -> None:
31
+ """Initialize uMp bindings."""
32
+
33
+ # Establish connection to Sensapex API (exit if connection fails).
34
+ UMP.set_library_path(RESOURCES_DIRECTORY)
35
+ self._ump: UMP = UMP.get_ump() # pyright: ignore [reportUnknownMemberType]
36
+
37
+ # Compute axis count, assumed as the first device. 0 if no devices are connected.
38
+ device_ids = list(map(str, self._ump.list_devices()))
39
+ self.axis_count: int = 0 if len(device_ids) == 0 else self._get_device(device_ids[0]).n_axes()
40
+
41
+ @staticmethod
42
+ @override
43
+ def get_display_name() -> str:
44
+ return "Sensapex uMp"
45
+
46
+ @staticmethod
47
+ @override
48
+ def get_cli_name() -> str:
49
+ return "ump"
50
+
51
+ @override
52
+ async def get_manipulators(self) -> list[str]:
53
+ device_ids = list(map(str, self._ump.list_devices()))
54
+
55
+ # Currently only supports using uMp-4 XOR uMp-3. Throw error if both are connected.
56
+ if any(self._get_device(device_id).n_axes() != self.axis_count for device_id in device_ids): # pyright: ignore [reportUnknownArgumentType]
57
+ msg = "uMp-4 and uMp-3 cannot be used at the same time."
58
+ raise RuntimeError(msg)
59
+
60
+ return device_ids
61
+
62
+ @override
63
+ async def get_axes_count(self) -> int:
64
+ return self.axis_count
65
+
66
+ @override
67
+ def get_dimensions(self) -> Vector4:
68
+ return Vector4(x=20, y=20, z=20, w=20)
69
+
70
+ @override
71
+ async def get_position(self, manipulator_id: str) -> Vector4:
72
+ # Get the position list from the device.
73
+ position = self._get_device(manipulator_id).get_pos(1) # pyright: ignore [reportUnknownMemberType]
74
+
75
+ # Copy x-coordinate into depth for uMp-3.
76
+ return um_to_mm(list_to_vector4([*position, position[0]] if self._is_ump_3() else position))
77
+
78
+ @override
79
+ async def get_angles(self, manipulator_id: str) -> NoReturn:
80
+ """uMp does not support getting angles so raise an error.
81
+
82
+ Raises:
83
+ AttributeError: uMp does not support getting angles.
84
+ """
85
+ error_message = "uMp does not support getting angles"
86
+ raise AttributeError(error_message)
87
+
88
+ @override
89
+ async def get_shank_count(self, manipulator_id: str) -> NoReturn:
90
+ """uMp does not support getting shank count so raise an error.
91
+
92
+ Raises:
93
+ AttributeError: uMp does not support getting shank count.
94
+ """
95
+ error_message = "uMp does not support getting shank count"
96
+ raise AttributeError(error_message)
97
+
98
+ @staticmethod
99
+ @override
100
+ def get_movement_tolerance() -> float:
101
+ return 0.001
102
+
103
+ @override
104
+ async def set_position(self, manipulator_id: str, position: Vector4, speed: float) -> Vector4:
105
+ # Convert position to micrometers array.
106
+ target_position_um = vector4_to_array(vector_mm_to_um(position))
107
+
108
+ # Request movement (clip 4th axis for uMp-3).
109
+ movement = self._get_device(
110
+ manipulator_id
111
+ ).goto_pos( # pyright: ignore [reportUnknownMemberType]
112
+ target_position_um[: self.UMP_3_NUM_AXES] if self._is_ump_3() else target_position_um,
113
+ scalar_mm_to_um(speed),
114
+ )
115
+
116
+ # Wait for movement to finish.
117
+ _ = await get_running_loop().run_in_executor(None, movement.finished_event.wait, None)
118
+
119
+ # Handle interrupted movement.
120
+ if movement.interrupted:
121
+ error_message = f"Manipulator {manipulator_id} interrupted: {movement.interrupt_reason}" # pyright: ignore [reportUnknownMemberType]
122
+ raise RuntimeError(error_message)
123
+
124
+ # Handle empty end position.
125
+ if movement.last_pos is None or len(movement.last_pos) == 0: # pyright: ignore [reportUnknownMemberType, reportUnknownArgumentType]
126
+ error_message = f"Manipulator {manipulator_id} did not reach target position"
127
+ raise RuntimeError(error_message)
128
+
129
+ return um_to_mm(
130
+ list_to_vector4([*movement.last_pos, movement.last_pos[0]] if self._is_ump_3() else list(movement.last_pos)) # pyright: ignore [reportUnknownArgumentType, reportUnknownMemberType]
131
+ )
132
+
133
+ @override
134
+ async def set_depth(self, manipulator_id: str, depth: float, speed: float) -> float:
135
+ # Augment current position with depth.
136
+ current_position = await self.get_position(manipulator_id)
137
+ new_platform_position = current_position.model_copy(update={"x" if self._is_ump_3() else "w": depth})
138
+
139
+ # Make the movement.
140
+ final_platform_position = await self.set_position(manipulator_id, new_platform_position, speed)
141
+
142
+ # Return the final depth.
143
+ return float(final_platform_position.w)
144
+
145
+ @override
146
+ async def stop(self, manipulator_id: str) -> None:
147
+ self._get_device(manipulator_id).stop()
148
+
149
+ @override
150
+ def platform_space_to_unified_space(self, platform_space: Vector4) -> Vector4:
151
+ """
152
+ For uMp-3:
153
+ unified <- platform
154
+ +x <- +y
155
+ +y <- -x
156
+ +z <- -z
157
+ +d <- +d
158
+
159
+ For uMp-4:
160
+ unified <- platform
161
+ +x <- +y
162
+ +y <- -z
163
+ +z <- +x
164
+ +d <- +d
165
+ """
166
+
167
+ return (
168
+ Vector4(
169
+ x=platform_space.y,
170
+ y=self.get_dimensions().x - platform_space.x,
171
+ z=self.get_dimensions().z - platform_space.z,
172
+ w=platform_space.w,
173
+ )
174
+ if self._is_ump_3()
175
+ else Vector4(
176
+ x=platform_space.y,
177
+ y=self.get_dimensions().z - platform_space.z,
178
+ z=platform_space.x,
179
+ w=platform_space.w,
180
+ )
181
+ )
182
+
183
+ @override
184
+ def unified_space_to_platform_space(self, unified_space: Vector4) -> Vector4:
185
+ """
186
+ For uMp-3:
187
+ platform <- unified
188
+ +x <- -y
189
+ +y <- +x
190
+ +z <- -z
191
+ +d <- +d
192
+
193
+ For uMp-4:
194
+ platform <- unified
195
+ +x <- +z
196
+ +y <- +x
197
+ +z <- -y
198
+ +d <- +d
199
+ """
200
+
201
+ return (
202
+ Vector4(
203
+ x=self.get_dimensions().y - unified_space.y,
204
+ y=unified_space.x,
205
+ z=self.get_dimensions().z - unified_space.z,
206
+ w=unified_space.w,
207
+ )
208
+ if self._is_ump_3()
209
+ else Vector4(
210
+ x=unified_space.z,
211
+ y=unified_space.x,
212
+ z=self.get_dimensions().y - unified_space.y,
213
+ w=unified_space.w,
214
+ )
215
+ )
216
+
217
+ # Helper methods.
218
+ def _get_device(self, manipulator_id: str) -> SensapexDevice:
219
+ """Returns the Sensapex device object for the given manipulator ID.
220
+
221
+ Args:
222
+ manipulator_id: Manipulator ID.
223
+ Returns:
224
+ Sensapex device object.
225
+ """
226
+
227
+ return self._ump.get_device(int(manipulator_id)) # pyright: ignore [reportUnknownMemberType]
228
+
229
+ def _is_ump_3(self) -> bool:
230
+ """Check if the current device is uMp-3.
231
+
232
+ Returns:
233
+ True if the device is uMp-3, False otherwise.
234
+ """
235
+ return self.axis_count == self.UMP_3_NUM_AXES
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ephys-link
3
- Version: 2.0.2
3
+ Version: 2.1.0b1
4
4
  Summary: A Python Socket.IO server that allows any Socket.IO-compliant application to communicate with manipulators used in electrophysiology experiments.
5
5
  Project-URL: Documentation, https://virtualbrainlab.org/ephys_link/installation_and_use.html
6
6
  Project-URL: Issues, https://github.com/VirtualBrainLab/ephys-link/issues
@@ -28,7 +28,7 @@ Requires-Dist: keyboard==0.13.5
28
28
  Requires-Dist: packaging==24.2
29
29
  Requires-Dist: platformdirs==4.3.7
30
30
  Requires-Dist: pyserial==3.5
31
- Requires-Dist: python-socketio[asyncio-client]==5.12.1
31
+ Requires-Dist: python-socketio[asyncio-client]==5.13.0
32
32
  Requires-Dist: requests==2.32.3
33
33
  Requires-Dist: rich==14.0.0
34
34
  Requires-Dist: sensapex==1.400.3
@@ -1,13 +1,13 @@
1
- ephys_link/__about__.py,sha256=tATvJM5shAzfspHYjdVwpV2w3-gDA119NlEYi5X2lFY,22
1
+ ephys_link/__about__.py,sha256=ioFei0HyRaKlvpUBHHnq0pLx8kyDkQUelt4_vkwvk20,24
2
2
  ephys_link/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  ephys_link/__main__.py,sha256=sbFdC6KJjTfXDgRraU_fmGRPcF4I1Ur9PRDiD86dkRI,1449
4
4
  ephys_link/back_end/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- ephys_link/back_end/platform_handler.py,sha256=PSlBa2_jM073uaF3MvCd-_a7XXEeTfn5KXJ7aPEwMVk,12149
5
+ ephys_link/back_end/platform_handler.py,sha256=gdiO6d0L-DWWLEJOL6eP6685tOC6otffmhfIBtPjhq0,12604
6
6
  ephys_link/back_end/server.py,sha256=mb3K3pXSO-gHaSj1CGJ0v3CSOW5YCi-p0EOKoySRzKQ,10322
7
7
  ephys_link/bindings/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  ephys_link/bindings/fake_binding.py,sha256=PI7zYv-SjWsGFEs_FVu5Z5l9gykIqG3C7pQISdbwdoY,2357
9
9
  ephys_link/bindings/mpm_binding.py,sha256=vn7IKqdiZ6_MX91zomqDXX08ONHwVVgWncRuJTxJpOM,10872
10
- ephys_link/bindings/ump_4_binding.py,sha256=NTewhryjJYDDGYXHMiFRICfGBPJqrdStKOMB87dftiY,5421
10
+ ephys_link/bindings/ump_binding.py,sha256=HeFMA_6P9WqZDy_hVRGWmwEDmDoMlt8w8xCWHIc6S-o,7974
11
11
  ephys_link/front_end/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  ephys_link/front_end/cli.py,sha256=isIJs_sZbz7VbNvLgi-HyDlE-TyKD12auDhMTxAkWQU,3099
13
13
  ephys_link/front_end/gui.py,sha256=MDcrTS_Xz9bopAgamh4HknqRC10W8E6eOS3Kss_2ZKQ,6864
@@ -18,8 +18,8 @@ ephys_link/utils/console.py,sha256=52SYvXv_7Fx8QDL3RMFQoggQ1n5W93Yu5aU7uuJQgfg,3
18
18
  ephys_link/utils/constants.py,sha256=1aML7zBNTM5onVSf6NDrYIR33VJy-dIHd1lFORVBGbM,725
19
19
  ephys_link/utils/converters.py,sha256=ZdVmIX-LHCwM__F0SpjN_mfNGGetr1U97xvHd0hf8T0,2038
20
20
  ephys_link/utils/startup.py,sha256=jZVed78tuWjUuZqWVgii_zumDr87T-ikEtOFa6KTE_E,2500
21
- ephys_link-2.0.2.dist-info/METADATA,sha256=goBbmRyz6sCH8A6KRRuIz9Jo2AHT4vkkoRLNcgUvbnA,4607
22
- ephys_link-2.0.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
23
- ephys_link-2.0.2.dist-info/entry_points.txt,sha256=o8wV3AdnJ9o47vg9ymKxPNVq9pMdPq8UZHE_iyAJx-k,124
24
- ephys_link-2.0.2.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
25
- ephys_link-2.0.2.dist-info/RECORD,,
21
+ ephys_link-2.1.0b1.dist-info/METADATA,sha256=XE_kTRieGoQRBR5j1zvrl9QcmPdazuCRqUIrLG6K7eI,4609
22
+ ephys_link-2.1.0b1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
23
+ ephys_link-2.1.0b1.dist-info/entry_points.txt,sha256=o8wV3AdnJ9o47vg9ymKxPNVq9pMdPq8UZHE_iyAJx-k,124
24
+ ephys_link-2.1.0b1.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
25
+ ephys_link-2.1.0b1.dist-info/RECORD,,
@@ -1,158 +0,0 @@
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
- @staticmethod
81
- @override
82
- def get_movement_tolerance() -> float:
83
- return 0.001
84
-
85
- @override
86
- async def set_position(self, manipulator_id: str, position: Vector4, speed: float) -> Vector4:
87
- # Convert position to micrometers.
88
- target_position_um = vector_mm_to_um(position)
89
-
90
- # Request movement.
91
- movement = self._get_device(manipulator_id).goto_pos( # pyright: ignore [reportUnknownMemberType]
92
- vector4_to_array(target_position_um), scalar_mm_to_um(speed)
93
- )
94
-
95
- # Wait for movement to finish.
96
- _ = await get_running_loop().run_in_executor(None, movement.finished_event.wait, None)
97
-
98
- # Handle interrupted movement.
99
- if movement.interrupted:
100
- error_message = f"Manipulator {manipulator_id} interrupted: {movement.interrupt_reason}" # pyright: ignore [reportUnknownMemberType]
101
- raise RuntimeError(error_message)
102
-
103
- # Handle empty end position.
104
- if movement.last_pos is None or len(movement.last_pos) == 0: # pyright: ignore [reportUnknownMemberType, reportUnknownArgumentType]
105
- error_message = f"Manipulator {manipulator_id} did not reach target position"
106
- raise RuntimeError(error_message)
107
-
108
- return um_to_mm(list_to_vector4(movement.last_pos)) # pyright: ignore [reportArgumentType, reportUnknownMemberType]
109
-
110
- @override
111
- async def set_depth(self, manipulator_id: str, depth: float, speed: float) -> float:
112
- # Augment current position with depth.
113
- current_position = await self.get_position(manipulator_id)
114
- new_platform_position = current_position.model_copy(update={"w": depth})
115
-
116
- # Make the movement.
117
- final_platform_position = await self.set_position(manipulator_id, new_platform_position, speed)
118
-
119
- # Return the final depth.
120
- return float(final_platform_position.w)
121
-
122
- @override
123
- async def stop(self, manipulator_id: str) -> None:
124
- self._get_device(manipulator_id).stop()
125
-
126
- @override
127
- def platform_space_to_unified_space(self, platform_space: Vector4) -> Vector4:
128
- # unified <- platform
129
- # +x <- +y
130
- # +y <- -z
131
- # +z <- +x
132
- # +d <- +d
133
-
134
- return Vector4(
135
- x=platform_space.y,
136
- y=self.get_dimensions().z - platform_space.z,
137
- z=platform_space.x,
138
- w=platform_space.w,
139
- )
140
-
141
- @override
142
- def unified_space_to_platform_space(self, unified_space: Vector4) -> Vector4:
143
- # platform <- unified
144
- # +x <- +z
145
- # +y <- +x
146
- # +z <- -y
147
- # +d <- +d
148
-
149
- return Vector4(
150
- x=unified_space.z,
151
- y=unified_space.x,
152
- z=self.get_dimensions().z - unified_space.y,
153
- w=unified_space.w,
154
- )
155
-
156
- # Helper methods.
157
- def _get_device(self, manipulator_id: str) -> SensapexDevice:
158
- return self._ump.get_device(int(manipulator_id)) # pyright: ignore [reportUnknownMemberType]