ephys-link 1.3.3__py3-none-any.whl → 2.0.0__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.
Files changed (42) hide show
  1. ephys_link/__about__.py +1 -1
  2. ephys_link/__main__.py +51 -105
  3. ephys_link/back_end/__init__.py +0 -0
  4. ephys_link/back_end/platform_handler.py +315 -0
  5. ephys_link/back_end/server.py +274 -0
  6. ephys_link/bindings/__init__.py +0 -0
  7. ephys_link/bindings/fake_binding.py +84 -0
  8. ephys_link/bindings/mpm_binding.py +315 -0
  9. ephys_link/bindings/ump_4_binding.py +157 -0
  10. ephys_link/front_end/__init__.py +0 -0
  11. ephys_link/front_end/cli.py +104 -0
  12. ephys_link/front_end/gui.py +204 -0
  13. ephys_link/utils/__init__.py +0 -0
  14. ephys_link/utils/base_binding.py +176 -0
  15. ephys_link/utils/console.py +127 -0
  16. ephys_link/utils/constants.py +23 -0
  17. ephys_link/utils/converters.py +86 -0
  18. ephys_link/utils/startup.py +65 -0
  19. ephys_link-2.0.0.dist-info/METADATA +91 -0
  20. ephys_link-2.0.0.dist-info/RECORD +25 -0
  21. {ephys_link-1.3.3.dist-info → ephys_link-2.0.0.dist-info}/WHEEL +1 -1
  22. {ephys_link-1.3.3.dist-info → ephys_link-2.0.0.dist-info}/licenses/LICENSE +674 -674
  23. ephys_link/common.py +0 -49
  24. ephys_link/emergency_stop.py +0 -67
  25. ephys_link/gui.py +0 -217
  26. ephys_link/platform_handler.py +0 -465
  27. ephys_link/platform_manipulator.py +0 -35
  28. ephys_link/platforms/__init__.py +0 -5
  29. ephys_link/platforms/new_scale_handler.py +0 -141
  30. ephys_link/platforms/new_scale_manipulator.py +0 -312
  31. ephys_link/platforms/new_scale_pathfinder_handler.py +0 -235
  32. ephys_link/platforms/sensapex_handler.py +0 -151
  33. ephys_link/platforms/sensapex_manipulator.py +0 -227
  34. ephys_link/platforms/ump3_handler.py +0 -57
  35. ephys_link/platforms/ump3_manipulator.py +0 -147
  36. ephys_link/resources/CP210xManufacturing.dll +0 -0
  37. ephys_link/resources/NstMotorCtrl.dll +0 -0
  38. ephys_link/resources/SiUSBXp.dll +0 -0
  39. ephys_link/server.py +0 -508
  40. ephys_link-1.3.3.dist-info/METADATA +0 -164
  41. ephys_link-1.3.3.dist-info/RECORD +0 -26
  42. {ephys_link-1.3.3.dist-info → ephys_link-2.0.0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,127 @@
1
+ """Console class for printing messages to the console.
2
+
3
+ Configure the console to print error and debug messages.
4
+
5
+ Usage:
6
+ Create a Console object and call the appropriate method to print messages.
7
+ """
8
+
9
+ from logging import DEBUG, ERROR, INFO, basicConfig, getLogger
10
+ from typing import final
11
+
12
+ from rich.logging import RichHandler
13
+ from rich.traceback import install
14
+
15
+
16
+ @final
17
+ class Console:
18
+ def __init__(self, *, enable_debug: bool) -> None:
19
+ """Initialize console properties.
20
+
21
+ Args:
22
+ enable_debug: Enable debug mode.
23
+ """
24
+ # Repeat message fields.
25
+ self._last_message = (0, "", "")
26
+ self._repeat_counter = 0
27
+
28
+ # Config logger.
29
+ basicConfig(
30
+ format="%(message)s",
31
+ datefmt="[%I:%M:%S %p]",
32
+ handlers=[RichHandler(rich_tracebacks=True, markup=True)],
33
+ )
34
+ self._log = getLogger("rich")
35
+ self._log.setLevel(DEBUG if enable_debug else INFO)
36
+
37
+ # Install Rich traceback.
38
+ _ = install()
39
+
40
+ def debug_print(self, label: str, msg: str) -> None:
41
+ """Print a debug message to the console.
42
+
43
+ Args:
44
+ label: Label for the debug message.
45
+ msg: Debug message to print.
46
+ """
47
+ self._repeatable_log(DEBUG, f"[b green]{label}", f"[green]{msg}")
48
+
49
+ def info_print(self, label: str, msg: str) -> None:
50
+ """Print info to console.
51
+
52
+ Args:
53
+ label: Label for the message.
54
+ msg: Message to print.
55
+ """
56
+ self._repeatable_log(INFO, f"[b blue]{label}", msg)
57
+
58
+ def error_print(self, label: str, msg: str) -> None:
59
+ """Print an error message to the console.
60
+
61
+ Args:
62
+ label: Label for the error message.
63
+ msg: Error message to print.
64
+ """
65
+ self._repeatable_log(ERROR, f"[b red]{label}", f"[red]{msg}")
66
+
67
+ def critical_print(self, msg: str) -> None:
68
+ """Print a critical message to the console.
69
+
70
+ Args:
71
+ msg: Critical message to print.
72
+ """
73
+ self._log.critical(f"[b i red]{msg}")
74
+
75
+ @staticmethod
76
+ def pretty_exception(exception: Exception) -> str:
77
+ """Pretty print an exception.
78
+
79
+ Args:
80
+ exception: Exception to pretty print.
81
+
82
+ Returns:
83
+ Pretty printed exception.
84
+ """
85
+ return f"{type(exception).__name__}: {exception}"
86
+
87
+ def exception_error_print(self, label: str, exception: Exception) -> None:
88
+ """Print an error message with exception details to the console.
89
+
90
+ Args:
91
+ label: Label for the error message.
92
+ exception: Exception to print.
93
+ """
94
+ self._log.exception(f"[b magenta]{label}:[/] [magenta]{Console.pretty_exception(exception)}")
95
+
96
+ # Helper methods.
97
+ def _repeatable_log(self, log_type: int, label: str, message: str) -> None:
98
+ """Add a row to the output table.
99
+
100
+ Args:
101
+ log_type: Type of log.
102
+ label: Label for the message.
103
+ message: Message.
104
+ """
105
+
106
+ # Compute if this is a repeated message.
107
+ message_set = (log_type, label, message)
108
+ if message_set == self._last_message:
109
+ # Handle repeat.
110
+ self._repeat_counter += 1
111
+
112
+ # Add an ellipsis row for first repeat.
113
+ if self._repeat_counter == 1:
114
+ self._log.log(log_type, "...")
115
+ else:
116
+ # Handle novel message.
117
+ if self._repeat_counter > 0:
118
+ # Complete previous repeat.
119
+ self._log.log(
120
+ self._last_message[0],
121
+ f"{self._last_message[1]}:[/] {self._last_message[2]}[/] x {self._repeat_counter}",
122
+ )
123
+ self._repeat_counter = 0
124
+
125
+ # Log new message.
126
+ self._log.log(log_type, f"{label}:[/] {message}")
127
+ self._last_message = message_set
@@ -0,0 +1,23 @@
1
+ """Globally accessible constants"""
2
+
3
+ from os.path import abspath, dirname, join
4
+
5
+ # Ephys Link ASCII.
6
+ ASCII = r"""
7
+ ______ _ _ _ _
8
+ | ____| | | | | (_) | |
9
+ | |__ _ __ | |__ _ _ ___ | | _ _ __ | | __
10
+ | __| | '_ \| '_ \| | | / __| | | | | '_ \| |/ /
11
+ | |____| |_) | | | | |_| \__ \ | |____| | | | | <
12
+ |______| .__/|_| |_|\__, |___/ |______|_|_| |_|_|\_\
13
+ | | __/ |
14
+ |_| |___/
15
+ """
16
+
17
+ # Absolute path to the resource folder.
18
+ PACKAGE_DIRECTORY = dirname(dirname(abspath(__file__)))
19
+ RESOURCES_DIRECTORY = join(PACKAGE_DIRECTORY, "resources")
20
+ BINDINGS_DIRECTORY = join(PACKAGE_DIRECTORY, "bindings")
21
+
22
+ # Ephys Link Port
23
+ PORT = 3000
@@ -0,0 +1,86 @@
1
+ """Commonly used conversion functions."""
2
+
3
+ from vbl_aquarium.models.unity import Vector4
4
+
5
+
6
+ def scalar_mm_to_um(mm: float) -> float:
7
+ """Convert scalar values of millimeters to micrometers.
8
+
9
+ Args:
10
+ mm: Scalar value in millimeters.
11
+
12
+ Returns:
13
+ Scalar value in micrometers.
14
+ """
15
+ return mm * 1_000
16
+
17
+
18
+ def vector_mm_to_um(mm: Vector4) -> Vector4:
19
+ """Convert vector values of millimeters to micrometers.
20
+
21
+ Args:
22
+ mm: Vector in millimeters.
23
+
24
+ Returns:
25
+ Vector in micrometers.
26
+ """
27
+ return mm * 1_000
28
+
29
+
30
+ def um_to_mm(um: Vector4) -> Vector4:
31
+ """Convert micrometers to millimeters.
32
+
33
+ Args:
34
+ um: Length in micrometers.
35
+
36
+ Returns:
37
+ Length in millimeters.
38
+ """
39
+ return um / 1_000
40
+
41
+
42
+ def vector4_to_array(vector4: Vector4) -> list[float]:
43
+ """Convert a [Vector4][vbl_aquarium.models.unity.Vector4] to a list of floats.
44
+
45
+ Args:
46
+ vector4: [Vector4][vbl_aquarium.models.unity.Vector4] to convert.
47
+
48
+ Returns:
49
+ List of floats.
50
+ """
51
+ return [vector4.x, vector4.y, vector4.z, vector4.w]
52
+
53
+
54
+ def list_to_vector4(float_list: list[float | int]) -> Vector4:
55
+ """Convert a list of floats to a [Vector4][vbl_aquarium.models.unity.Vector4].
56
+
57
+ Args:
58
+ float_list: List of floats.
59
+
60
+ Returns:
61
+ First four elements of the list as a Vector4 padded with zeros if necessary.
62
+ """
63
+
64
+ def get_element(this_array: list[float | int], index: int) -> float:
65
+ """Safely get an element from an array.
66
+
67
+ Return 0 if the index is out of bounds.
68
+
69
+ Args:
70
+ this_array: Array to get the element from.
71
+ index: Index to get.
72
+
73
+ Returns:
74
+ Element at the index or 0 if the index is out of bounds.
75
+ """
76
+ try:
77
+ return this_array[index]
78
+ except IndexError:
79
+ return 0.0
80
+
81
+ return Vector4(
82
+ x=get_element(float_list, 0),
83
+ y=get_element(float_list, 1),
84
+ z=get_element(float_list, 2),
85
+ w=get_element(float_list, 3),
86
+ )
@@ -0,0 +1,65 @@
1
+ """Program startup helper functions."""
2
+
3
+ from importlib import import_module
4
+ from inspect import getmembers, isclass
5
+ from pkgutil import iter_modules
6
+
7
+ from packaging.version import parse
8
+ from requests import ConnectionError, ConnectTimeout, get
9
+
10
+ from ephys_link.__about__ import __version__
11
+ from ephys_link.utils.base_binding import BaseBinding
12
+ from ephys_link.utils.console import Console
13
+ from ephys_link.utils.constants import ASCII, BINDINGS_DIRECTORY
14
+
15
+
16
+ def preamble() -> None:
17
+ """Print the server startup preamble."""
18
+ print(ASCII) # noqa: T201
19
+ print(__version__) # noqa: T201
20
+ print() # noqa: T201
21
+ print("This is the Ephys Link server window.") # noqa: T201
22
+ print("You may safely leave it running in the background.") # noqa: T201
23
+ print("To stop it, close this window or press CTRL + Pause/Break.") # noqa: T201
24
+ print() # noqa: T201
25
+
26
+
27
+ def check_for_updates(console: Console) -> None:
28
+ """Check for updates to the Ephys Link.
29
+
30
+ Args:
31
+ console: Console instance for printing messages.
32
+ """
33
+ try:
34
+ response = get("https://api.github.com/repos/VirtualBrainLab/ephys-link/tags", timeout=10)
35
+ latest_version = str(response.json()[0]["name"]) # pyright: ignore [reportAny]
36
+ if parse(latest_version) > parse(__version__):
37
+ console.critical_print(f"Update available: {latest_version} (current: {__version__})")
38
+ console.critical_print("Download at: https://github.com/VirtualBrainLab/ephys-link/releases/latest")
39
+ except (ConnectionError, ConnectTimeout):
40
+ console.error_print(
41
+ "UPDATE", "Unable to check for updates. Ignore updates or use the the -i flag to disable checks.\n"
42
+ )
43
+
44
+
45
+ def get_bindings() -> list[type[BaseBinding]]:
46
+ """Get all binding classes from the bindings directory.
47
+
48
+ Returns:
49
+ List of binding classes.
50
+ """
51
+ return [
52
+ binding_type
53
+ for module in iter_modules([BINDINGS_DIRECTORY])
54
+ for _, binding_type in getmembers(import_module(f"ephys_link.bindings.{module.name}"), isclass)
55
+ if issubclass(binding_type, BaseBinding) and binding_type != BaseBinding
56
+ ]
57
+
58
+
59
+ def get_binding_display_to_cli_name() -> dict[str, str]:
60
+ """Get mapping of display to CLI option names of the available platform bindings.
61
+
62
+ Returns:
63
+ Dictionary of platform binding display name to CLI option name.
64
+ """
65
+ return {binding_type.get_display_name(): binding_type.get_cli_name() for binding_type in get_bindings()}
@@ -0,0 +1,91 @@
1
+ Metadata-Version: 2.4
2
+ Name: ephys-link
3
+ Version: 2.0.0
4
+ Summary: A Python Socket.IO server that allows any Socket.IO-compliant application to communicate with manipulators used in electrophysiology experiments.
5
+ Project-URL: Documentation, https://virtualbrainlab.org/ephys_link/installation_and_use.html
6
+ Project-URL: Issues, https://github.com/VirtualBrainLab/ephys-link/issues
7
+ Project-URL: Source, https://github.com/VirtualBrainLab/ephys-link
8
+ Author-email: Kenneth Yang <kjy5@uw.edu>
9
+ Maintainer-email: Kenneth Yang <kjy5@uw.edu>
10
+ License-Expression: GPL-3.0-only
11
+ License-File: LICENSE
12
+ Keywords: electrophysiology,ephys,manipulator,neuroscience,neurotech,new-scale,sensapex,socket-io,virtualbrainlab
13
+ Classifier: Intended Audience :: End Users/Desktop
14
+ Classifier: Intended Audience :: Healthcare Industry
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
17
+ Classifier: Operating System :: Microsoft :: Windows
18
+ Classifier: Programming Language :: Python
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Programming Language :: Python :: Implementation :: CPython
25
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
26
+ Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
27
+ Requires-Python: <3.14,>=3.10
28
+ Requires-Dist: aiohttp==3.11.12
29
+ Requires-Dist: colorama==0.4.6
30
+ Requires-Dist: keyboard==0.13.5
31
+ Requires-Dist: packaging==24.2
32
+ Requires-Dist: platformdirs==4.3.6
33
+ Requires-Dist: pyserial==3.5
34
+ Requires-Dist: python-socketio[asyncio-client]==5.12.1
35
+ Requires-Dist: requests==2.32.3
36
+ Requires-Dist: rich==13.9.4
37
+ Requires-Dist: sensapex==1.400.3
38
+ Requires-Dist: vbl-aquarium==1.0.0
39
+ Description-Content-Type: text/markdown
40
+
41
+ # Electrophysiology Manipulator Link
42
+
43
+ [![PyPI version](https://badge.fury.io/py/ephys-link.svg)](https://badge.fury.io/py/ephys-link)
44
+ [![Deploy Documentation](https://github.com/VirtualBrainLab/ephys-link/actions/workflows/deploy-docs.yml/badge.svg)](https://github.com/VirtualBrainLab/ephys-link/actions/workflows/deploy-docs.yml)
45
+ [![Pydantic v2](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v2.json)](https://pydantic.dev)
46
+ [![Hatch project](https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg)](https://github.com/pypa/hatch)
47
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
48
+ [![Checked with pyright](https://microsoft.github.io/pyright/img/pyright_badge.svg)](https://microsoft.github.io/pyright/)
49
+
50
+ <!-- [![Build](https://github.com/VirtualBrainLab/ephys-link/actions/workflows/build.yml/badge.svg)](https://github.com/VirtualBrainLab/ephys-link/actions/workflows/build.yml) -->
51
+
52
+ The [Electrophysiology Manipulator Link](https://github.com/VirtualBrainLab/ephys-link)
53
+ (or Ephys Link for short) is a Python [Socket.IO](https://socket.io/docs/v4/#what-socketio-is) server that allows any
54
+ Socket.IO-compliant application (such
55
+ as [Pinpoint][Pinpoint])
56
+ to communicate with manipulators used in electrophysiology experiments.
57
+
58
+ <img width="100%" src="https://github.com/VirtualBrainLab/ephys-link/assets/82800265/0c7c60b1-0926-4697-a461-221554f82de1" alt="Manipulator and probe in pinpoint moving in sync">
59
+
60
+ # Installation
61
+
62
+ ## Launch from Pinpoint (Recommended)
63
+
64
+ Pinpoint comes bundled with the correct version of Ephys Link. If you are using Pinpoint on the same computer your
65
+ manipulators are connected to, you can launch the server from within Pinpoint. Follow the instructions in
66
+ the [Pinpoint documentation](https://virtualbrainlab.org/pinpoint/tutorials/tutorial_ephys_link.html#configure-and-launch-ephys-link).
67
+
68
+ ## Install as Standalone Executable
69
+
70
+ 1. Download the latest standalone executable or zip from
71
+ the [releases page](https://github.com/VirtualBrainLab/ephys-link/releases/latest).
72
+ 2. Double-click the executable file to start.
73
+
74
+ # Documentation and More Information
75
+
76
+ Complete documentation including how to add manipulators and API usage can be
77
+ found on [Ephys Link's Documentation Website][docs].
78
+
79
+ # Citing
80
+
81
+ If this project is used as part of a research project you should cite
82
+ the [Pinpoint repository](https://github.com/VirtualBrainLab/Pinpoint). Please email
83
+ Dan ([dbirman@uw.edu](mailto:dbirman@uw.edu)) if you have questions.
84
+
85
+ Please reach out to Kenneth ([kjy5@uw.edu](mailto:kjy5@uw.edu)) for questions
86
+ about the Electrophysiology Manipulator Link server. Bugs may be reported
87
+ through the issues tab.
88
+
89
+ [Pinpoint]: https://github.com/VirtualBrainLab/Pinpoint
90
+
91
+ [docs]: https://ephys-link.virtualbrainlab.org
@@ -0,0 +1,25 @@
1
+ ephys_link/__about__.py,sha256=HLJc82fZ6h65qdEwfCWx0U1_51VFQHVHv3kddt9t2Yk,23
2
+ ephys_link/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ ephys_link/__main__.py,sha256=sbFdC6KJjTfXDgRraU_fmGRPcF4I1Ur9PRDiD86dkRI,1449
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
6
+ ephys_link/back_end/server.py,sha256=mb3K3pXSO-gHaSj1CGJ0v3CSOW5YCi-p0EOKoySRzKQ,10322
7
+ ephys_link/bindings/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ ephys_link/bindings/fake_binding.py,sha256=VCmKZha113kiHSmOZzKLfbaa8iXobefJFQPI3eCzuZE,2343
9
+ ephys_link/bindings/mpm_binding.py,sha256=UdrWXiz16zJ7PSQBnYNtpTXs_1chbE_v1tvzeP7PrPk,10681
10
+ ephys_link/bindings/ump_4_binding.py,sha256=zwAUo2wYBGq3NKa0zxdb5Jh_FMBAhf5yHdfKBP3m4dk,5407
11
+ ephys_link/front_end/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
+ ephys_link/front_end/cli.py,sha256=isIJs_sZbz7VbNvLgi-HyDlE-TyKD12auDhMTxAkWQU,3099
13
+ ephys_link/front_end/gui.py,sha256=MDcrTS_Xz9bopAgamh4HknqRC10W8E6eOS3Kss_2ZKQ,6864
14
+ ephys_link/resources/libum.dll,sha256=YaD4dwiSNohx-XxHjx2eQWPOBEVvUIXARvx37e_yqNw,316316
15
+ ephys_link/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
+ ephys_link/utils/base_binding.py,sha256=9ScaIXLwhAgHP4jLIG5LUf1AYjF_Jmf0nRH606_mXEQ,5399
17
+ ephys_link/utils/console.py,sha256=52SYvXv_7Fx8QDL3RMFQoggQ1n5W93Yu5aU7uuJQgfg,3904
18
+ ephys_link/utils/constants.py,sha256=10hiJfaWIrOmL-QLApimQMz2wQhViysB8KjOQZokwLQ,748
19
+ ephys_link/utils/converters.py,sha256=ZdVmIX-LHCwM__F0SpjN_mfNGGetr1U97xvHd0hf8T0,2038
20
+ ephys_link/utils/startup.py,sha256=W2_fMMYA90McKS9gPNWQO24NS6zp7aYWobunyMd5mC0,2565
21
+ ephys_link-2.0.0.dist-info/METADATA,sha256=oEUdHYJA2luw0snpl44xK8iJx6kk6nG41t6ItJN6v7M,4835
22
+ ephys_link-2.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
23
+ ephys_link-2.0.0.dist-info/entry_points.txt,sha256=o8wV3AdnJ9o47vg9ymKxPNVq9pMdPq8UZHE_iyAJx-k,124
24
+ ephys_link-2.0.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
25
+ ephys_link-2.0.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.24.2
2
+ Generator: hatchling 1.27.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any