imswitchclient 0.1.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.
@@ -0,0 +1,13 @@
1
+ =======
2
+ Credits
3
+ =======
4
+
5
+ Development Lead
6
+ ----------------
7
+
8
+ * Benedict Diederich <benedictdied@gmail.com>
9
+
10
+ Contributors
11
+ ------------
12
+
13
+ None yet. Why not be the first?
@@ -0,0 +1,128 @@
1
+ .. highlight:: shell
2
+
3
+ ============
4
+ Contributing
5
+ ============
6
+
7
+ Contributions are welcome, and they are greatly appreciated! Every little bit
8
+ helps, and credit will always be given.
9
+
10
+ You can contribute in many ways:
11
+
12
+ Types of Contributions
13
+ ----------------------
14
+
15
+ Report Bugs
16
+ ~~~~~~~~~~~
17
+
18
+ Report bugs at https://github.com/beniroquai/imswitchclient/issues.
19
+
20
+ If you are reporting a bug, please include:
21
+
22
+ * Your operating system name and version.
23
+ * Any details about your local setup that might be helpful in troubleshooting.
24
+ * Detailed steps to reproduce the bug.
25
+
26
+ Fix Bugs
27
+ ~~~~~~~~
28
+
29
+ Look through the GitHub issues for bugs. Anything tagged with "bug" and "help
30
+ wanted" is open to whoever wants to implement it.
31
+
32
+ Implement Features
33
+ ~~~~~~~~~~~~~~~~~~
34
+
35
+ Look through the GitHub issues for features. Anything tagged with "enhancement"
36
+ and "help wanted" is open to whoever wants to implement it.
37
+
38
+ Write Documentation
39
+ ~~~~~~~~~~~~~~~~~~~
40
+
41
+ ImSwitchClient could always use more documentation, whether as part of the
42
+ official ImSwitchClient docs, in docstrings, or even on the web in blog posts,
43
+ articles, and such.
44
+
45
+ Submit Feedback
46
+ ~~~~~~~~~~~~~~~
47
+
48
+ The best way to send feedback is to file an issue at https://github.com/beniroquai/imswitchclient/issues.
49
+
50
+ If you are proposing a feature:
51
+
52
+ * Explain in detail how it would work.
53
+ * Keep the scope as narrow as possible, to make it easier to implement.
54
+ * Remember that this is a volunteer-driven project, and that contributions
55
+ are welcome :)
56
+
57
+ Get Started!
58
+ ------------
59
+
60
+ Ready to contribute? Here's how to set up `imswitchclient` for local development.
61
+
62
+ 1. Fork the `imswitchclient` repo on GitHub.
63
+ 2. Clone your fork locally::
64
+
65
+ $ git clone git@github.com:your_name_here/imswitchclient.git
66
+
67
+ 3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development::
68
+
69
+ $ mkvirtualenv imswitchclient
70
+ $ cd imswitchclient/
71
+ $ python setup.py develop
72
+
73
+ 4. Create a branch for local development::
74
+
75
+ $ git checkout -b name-of-your-bugfix-or-feature
76
+
77
+ Now you can make your changes locally.
78
+
79
+ 5. When you're done making changes, check that your changes pass flake8 and the
80
+ tests, including testing other Python versions with tox::
81
+
82
+ $ flake8 imswitchclient tests
83
+ $ python setup.py test or pytest
84
+ $ tox
85
+
86
+ To get flake8 and tox, just pip install them into your virtualenv.
87
+
88
+ 6. Commit your changes and push your branch to GitHub::
89
+
90
+ $ git add .
91
+ $ git commit -m "Your detailed description of your changes."
92
+ $ git push origin name-of-your-bugfix-or-feature
93
+
94
+ 7. Submit a pull request through the GitHub website.
95
+
96
+ Pull Request Guidelines
97
+ -----------------------
98
+
99
+ Before you submit a pull request, check that it meets these guidelines:
100
+
101
+ 1. The pull request should include tests.
102
+ 2. If the pull request adds functionality, the docs should be updated. Put
103
+ your new functionality into a function with a docstring, and add the
104
+ feature to the list in README.rst.
105
+ 3. The pull request should work for Python 3.5, 3.6, 3.7 and 3.8, and for PyPy. Check
106
+ https://travis-ci.com/beniroquai/imswitchclient/pull_requests
107
+ and make sure that the tests pass for all supported Python versions.
108
+
109
+ Tips
110
+ ----
111
+
112
+ To run a subset of tests::
113
+
114
+
115
+ $ python -m unittest tests.test_imswitchclient
116
+
117
+ Deploying
118
+ ---------
119
+
120
+ A reminder for the maintainers on how to deploy.
121
+ Make sure all your changes are committed (including an entry in HISTORY.rst).
122
+ Then run::
123
+
124
+ $ bump2version patch # possible: major / minor / patch
125
+ $ git push
126
+ $ git push --tags
127
+
128
+ Travis will then deploy to PyPI if tests pass.
@@ -0,0 +1,8 @@
1
+ =======
2
+ History
3
+ =======
4
+
5
+ 0.1.0 (2023-07-03)
6
+ ------------------
7
+
8
+ * First release on PyPI.
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023, Benedict Diederich
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.
22
+
@@ -0,0 +1,11 @@
1
+ include AUTHORS.rst
2
+ include CONTRIBUTING.rst
3
+ include HISTORY.rst
4
+ include LICENSE
5
+ include README.rst
6
+
7
+ recursive-include tests *
8
+ recursive-exclude * __pycache__
9
+ recursive-exclude * *.py[co]
10
+
11
+ recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif
@@ -0,0 +1,72 @@
1
+ Metadata-Version: 2.1
2
+ Name: imswitchclient
3
+ Version: 0.1.0
4
+ Summary: This is a package that connects ImSwitch's REST API to the rest of the world (e.g. jupyter lab)
5
+ Home-page: https://github.com/beniroquai/imswitchclient
6
+ Author: Benedict Diederich
7
+ Author-email: benedictdied@gmail.com
8
+ License: MIT license
9
+ Keywords: imswitchclient
10
+ Classifier: Development Status :: 2 - Pre-Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Natural Language :: English
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.6
16
+ Classifier: Programming Language :: Python :: 3.7
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Requires-Python: >=3.6
19
+ License-File: LICENSE
20
+ License-File: AUTHORS.rst
21
+
22
+ ==============
23
+ ImSwitchClient
24
+ ==============
25
+
26
+
27
+ .. image:: https://img.shields.io/pypi/v/imswitchclient.svg
28
+ :target: https://pypi.python.org/pypi/imswitchclient
29
+
30
+ .. image:: https://img.shields.io/travis/beniroquai/imswitchclient.svg
31
+ :target: https://travis-ci.com/beniroquai/imswitchclient
32
+
33
+ .. image:: https://readthedocs.org/projects/imswitchclient/badge/?version=latest
34
+ :target: https://imswitchclient.readthedocs.io/en/latest/?version=latest
35
+ :alt: Documentation Status
36
+
37
+
38
+ .. image:: https://pyup.io/repos/github/beniroquai/imswitchclient/shield.svg
39
+ :target: https://pyup.io/repos/github/beniroquai/imswitchclient/
40
+ :alt: Updates
41
+
42
+
43
+
44
+ This is a package that connects ImSwitch's REST API to the rest of the world (e.g. jupyter lab)
45
+
46
+
47
+ * Free software: MIT license
48
+ * Documentation: https://imswitchclient.readthedocs.io.
49
+
50
+
51
+ Features
52
+ --------
53
+
54
+ * TODO
55
+
56
+ Credits
57
+ -------
58
+
59
+ This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.
60
+
61
+ .. _Cookiecutter: https://github.com/audreyr/cookiecutter
62
+ .. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage
63
+
64
+
65
+ =======
66
+ History
67
+ =======
68
+
69
+ 0.1.0 (2023-07-03)
70
+ ------------------
71
+
72
+ * First release on PyPI.
@@ -0,0 +1,41 @@
1
+ ==============
2
+ ImSwitchClient
3
+ ==============
4
+
5
+
6
+ .. image:: https://img.shields.io/pypi/v/imswitchclient.svg
7
+ :target: https://pypi.python.org/pypi/imswitchclient
8
+
9
+ .. image:: https://img.shields.io/travis/beniroquai/imswitchclient.svg
10
+ :target: https://travis-ci.com/beniroquai/imswitchclient
11
+
12
+ .. image:: https://readthedocs.org/projects/imswitchclient/badge/?version=latest
13
+ :target: https://imswitchclient.readthedocs.io/en/latest/?version=latest
14
+ :alt: Documentation Status
15
+
16
+
17
+ .. image:: https://pyup.io/repos/github/beniroquai/imswitchclient/shield.svg
18
+ :target: https://pyup.io/repos/github/beniroquai/imswitchclient/
19
+ :alt: Updates
20
+
21
+
22
+
23
+ This is a package that connects ImSwitch's REST API to the rest of the world (e.g. jupyter lab)
24
+
25
+
26
+ * Free software: MIT license
27
+ * Documentation: https://imswitchclient.readthedocs.io.
28
+
29
+
30
+ Features
31
+ --------
32
+
33
+ * TODO
34
+
35
+ Credits
36
+ -------
37
+
38
+ This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.
39
+
40
+ .. _Cookiecutter: https://github.com/audreyr/cookiecutter
41
+ .. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage
@@ -0,0 +1,20 @@
1
+ # Minimal makefile for Sphinx documentation
2
+ #
3
+
4
+ # You can set these variables from the command line.
5
+ SPHINXOPTS =
6
+ SPHINXBUILD = python -msphinx
7
+ SPHINXPROJ = imswitchclient
8
+ SOURCEDIR = .
9
+ BUILDDIR = _build
10
+
11
+ # Put it first so that "make" without argument is like "make help".
12
+ help:
13
+ @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14
+
15
+ .PHONY: help Makefile
16
+
17
+ # Catch-all target: route all unknown targets to Sphinx using the new
18
+ # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19
+ %: Makefile
20
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@@ -0,0 +1 @@
1
+ .. include:: ../AUTHORS.rst
@@ -0,0 +1,162 @@
1
+ #!/usr/bin/env python
2
+ #
3
+ # imswitchclient documentation build configuration file, created by
4
+ # sphinx-quickstart on Fri Jun 9 13:47:02 2017.
5
+ #
6
+ # This file is execfile()d with the current directory set to its
7
+ # containing dir.
8
+ #
9
+ # Note that not all possible configuration values are present in this
10
+ # autogenerated file.
11
+ #
12
+ # All configuration values have a default; values that are commented out
13
+ # serve to show the default.
14
+
15
+ # If extensions (or modules to document with autodoc) are in another
16
+ # directory, add these directories to sys.path here. If the directory is
17
+ # relative to the documentation root, use os.path.abspath to make it
18
+ # absolute, like shown here.
19
+ #
20
+ import os
21
+ import sys
22
+ sys.path.insert(0, os.path.abspath('..'))
23
+
24
+ import imswitchclient
25
+
26
+ # -- General configuration ---------------------------------------------
27
+
28
+ # If your documentation needs a minimal Sphinx version, state it here.
29
+ #
30
+ # needs_sphinx = '1.0'
31
+
32
+ # Add any Sphinx extension module names here, as strings. They can be
33
+ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
34
+ extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
35
+
36
+ # Add any paths that contain templates here, relative to this directory.
37
+ templates_path = ['_templates']
38
+
39
+ # The suffix(es) of source filenames.
40
+ # You can specify multiple suffix as a list of string:
41
+ #
42
+ # source_suffix = ['.rst', '.md']
43
+ source_suffix = '.rst'
44
+
45
+ # The master toctree document.
46
+ master_doc = 'index'
47
+
48
+ # General information about the project.
49
+ project = 'ImSwitchClient'
50
+ copyright = "2023, Benedict Diederich"
51
+ author = "Benedict Diederich"
52
+
53
+ # The version info for the project you're documenting, acts as replacement
54
+ # for |version| and |release|, also used in various other places throughout
55
+ # the built documents.
56
+ #
57
+ # The short X.Y version.
58
+ version = imswitchclient.__version__
59
+ # The full version, including alpha/beta/rc tags.
60
+ release = imswitchclient.__version__
61
+
62
+ # The language for content autogenerated by Sphinx. Refer to documentation
63
+ # for a list of supported languages.
64
+ #
65
+ # This is also used if you do content translation via gettext catalogs.
66
+ # Usually you set "language" from the command line for these cases.
67
+ language = None
68
+
69
+ # List of patterns, relative to source directory, that match files and
70
+ # directories to ignore when looking for source files.
71
+ # This patterns also effect to html_static_path and html_extra_path
72
+ exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
73
+
74
+ # The name of the Pygments (syntax highlighting) style to use.
75
+ pygments_style = 'sphinx'
76
+
77
+ # If true, `todo` and `todoList` produce output, else they produce nothing.
78
+ todo_include_todos = False
79
+
80
+
81
+ # -- Options for HTML output -------------------------------------------
82
+
83
+ # The theme to use for HTML and HTML Help pages. See the documentation for
84
+ # a list of builtin themes.
85
+ #
86
+ html_theme = 'alabaster'
87
+
88
+ # Theme options are theme-specific and customize the look and feel of a
89
+ # theme further. For a list of options available for each theme, see the
90
+ # documentation.
91
+ #
92
+ # html_theme_options = {}
93
+
94
+ # Add any paths that contain custom static files (such as style sheets) here,
95
+ # relative to this directory. They are copied after the builtin static files,
96
+ # so a file named "default.css" will overwrite the builtin "default.css".
97
+ html_static_path = ['_static']
98
+
99
+
100
+ # -- Options for HTMLHelp output ---------------------------------------
101
+
102
+ # Output file base name for HTML help builder.
103
+ htmlhelp_basename = 'imswitchclientdoc'
104
+
105
+
106
+ # -- Options for LaTeX output ------------------------------------------
107
+
108
+ latex_elements = {
109
+ # The paper size ('letterpaper' or 'a4paper').
110
+ #
111
+ # 'papersize': 'letterpaper',
112
+
113
+ # The font size ('10pt', '11pt' or '12pt').
114
+ #
115
+ # 'pointsize': '10pt',
116
+
117
+ # Additional stuff for the LaTeX preamble.
118
+ #
119
+ # 'preamble': '',
120
+
121
+ # Latex figure (float) alignment
122
+ #
123
+ # 'figure_align': 'htbp',
124
+ }
125
+
126
+ # Grouping the document tree into LaTeX files. List of tuples
127
+ # (source start file, target name, title, author, documentclass
128
+ # [howto, manual, or own class]).
129
+ latex_documents = [
130
+ (master_doc, 'imswitchclient.tex',
131
+ 'ImSwitchClient Documentation',
132
+ 'Benedict Diederich', 'manual'),
133
+ ]
134
+
135
+
136
+ # -- Options for manual page output ------------------------------------
137
+
138
+ # One entry per manual page. List of tuples
139
+ # (source start file, name, description, authors, manual section).
140
+ man_pages = [
141
+ (master_doc, 'imswitchclient',
142
+ 'ImSwitchClient Documentation',
143
+ [author], 1)
144
+ ]
145
+
146
+
147
+ # -- Options for Texinfo output ----------------------------------------
148
+
149
+ # Grouping the document tree into Texinfo files. List of tuples
150
+ # (source start file, target name, title, author,
151
+ # dir menu entry, description, category)
152
+ texinfo_documents = [
153
+ (master_doc, 'imswitchclient',
154
+ 'ImSwitchClient Documentation',
155
+ author,
156
+ 'imswitchclient',
157
+ 'One line description of project.',
158
+ 'Miscellaneous'),
159
+ ]
160
+
161
+
162
+
@@ -0,0 +1 @@
1
+ .. include:: ../CONTRIBUTING.rst
@@ -0,0 +1 @@
1
+ .. include:: ../HISTORY.rst
@@ -0,0 +1,20 @@
1
+ Welcome to ImSwitchClient's documentation!
2
+ ======================================
3
+
4
+ .. toctree::
5
+ :maxdepth: 2
6
+ :caption: Contents:
7
+
8
+ readme
9
+ installation
10
+ usage
11
+ modules
12
+ contributing
13
+ authors
14
+ history
15
+
16
+ Indices and tables
17
+ ==================
18
+ * :ref:`genindex`
19
+ * :ref:`modindex`
20
+ * :ref:`search`
@@ -0,0 +1,51 @@
1
+ .. highlight:: shell
2
+
3
+ ============
4
+ Installation
5
+ ============
6
+
7
+
8
+ Stable release
9
+ --------------
10
+
11
+ To install ImSwitchClient, run this command in your terminal:
12
+
13
+ .. code-block:: console
14
+
15
+ $ pip install imswitchclient
16
+
17
+ This is the preferred method to install ImSwitchClient, as it will always install the most recent stable release.
18
+
19
+ If you don't have `pip`_ installed, this `Python installation guide`_ can guide
20
+ you through the process.
21
+
22
+ .. _pip: https://pip.pypa.io
23
+ .. _Python installation guide: http://docs.python-guide.org/en/latest/starting/installation/
24
+
25
+
26
+ From sources
27
+ ------------
28
+
29
+ The sources for ImSwitchClient can be downloaded from the `Github repo`_.
30
+
31
+ You can either clone the public repository:
32
+
33
+ .. code-block:: console
34
+
35
+ $ git clone git://github.com/beniroquai/imswitchclient
36
+
37
+ Or download the `tarball`_:
38
+
39
+ .. code-block:: console
40
+
41
+ $ curl -OJL https://github.com/beniroquai/imswitchclient/tarball/master
42
+
43
+ Once you have a copy of the source, you can install it with:
44
+
45
+ .. code-block:: console
46
+
47
+ $ python setup.py install
48
+
49
+
50
+ .. _Github repo: https://github.com/beniroquai/imswitchclient
51
+ .. _tarball: https://github.com/beniroquai/imswitchclient/tarball/master
@@ -0,0 +1,36 @@
1
+ @ECHO OFF
2
+
3
+ pushd %~dp0
4
+
5
+ REM Command file for Sphinx documentation
6
+
7
+ if "%SPHINXBUILD%" == "" (
8
+ set SPHINXBUILD=python -msphinx
9
+ )
10
+ set SOURCEDIR=.
11
+ set BUILDDIR=_build
12
+ set SPHINXPROJ=imswitchclient
13
+
14
+ if "%1" == "" goto help
15
+
16
+ %SPHINXBUILD% >NUL 2>NUL
17
+ if errorlevel 9009 (
18
+ echo.
19
+ echo.The Sphinx module was not found. Make sure you have Sphinx installed,
20
+ echo.then set the SPHINXBUILD environment variable to point to the full
21
+ echo.path of the 'sphinx-build' executable. Alternatively you may add the
22
+ echo.Sphinx directory to PATH.
23
+ echo.
24
+ echo.If you don't have Sphinx installed, grab it from
25
+ echo.http://sphinx-doc.org/
26
+ exit /b 1
27
+ )
28
+
29
+ %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
30
+ goto end
31
+
32
+ :help
33
+ %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
34
+
35
+ :end
36
+ popd
@@ -0,0 +1 @@
1
+ .. include:: ../README.rst
@@ -0,0 +1,7 @@
1
+ =====
2
+ Usage
3
+ =====
4
+
5
+ To use ImSwitchClient in a project::
6
+
7
+ import imswitchclient
@@ -0,0 +1,105 @@
1
+ import requests
2
+ import json
3
+ import time
4
+ import io
5
+ import PIL.Image
6
+ import numpy as np
7
+ import logging
8
+ import zeroconf
9
+ import os
10
+
11
+
12
+ class ImSwitchClient(object):
13
+ def __init__(self, host="localhost", port=8000):
14
+ self.host = host
15
+ self.port = port
16
+ self.get_json(self.base_uri+"/openapi.json")
17
+ logging.info(f"Connecting to microscope {self.host}:{self.port}")
18
+
19
+ @property
20
+ def base_uri(self):
21
+ return f"http://{self.host}:{self.port}"
22
+
23
+ def get_json(self, path, payload={}, headers={}):
24
+ """Perform an HTTP GET request and return the JSON response"""
25
+ if not path.startswith("http"):
26
+ path = self.base_uri + path
27
+ r = requests.get(path, params=payload, headers=headers)
28
+ r.raise_for_status()
29
+ return r.json()
30
+
31
+ def post_json(self, path, payload={}, headers={}, wait_on_task="auto"):
32
+ """Make an HTTP POST request and return the JSON response"""
33
+ if not path.startswith("http"):
34
+ path = self.base_uri + path
35
+ r = requests.post(path, json=payload, headers=headers)
36
+ r.raise_for_status()
37
+ r = r.json()
38
+ return r
39
+
40
+ def move_positioner(self, positioner_name, axis, dist, is_absolute=True, is_blocking=True):
41
+ url = f"{self.base_uri}/PositionerController/movePositioner"
42
+ payload = {
43
+ 'positionerName': positioner_name,
44
+ 'axis': axis,
45
+ 'dist': dist,
46
+ 'isAbsolute': is_absolute,
47
+ 'isBlocking': is_blocking
48
+ }
49
+ #headers = {'accept': 'application/json'}
50
+
51
+ response = self.get_json(url, payload=payload)
52
+ return response
53
+
54
+ def snap_numpy_to_fastapi(self):
55
+ url = f"{self.base_uri}/RecordingController/snapNumpyToFastAPI"
56
+ headers = {'accept': 'application/json'}
57
+
58
+ response = requests.get(url, headers=headers)
59
+ response.raise_for_status()
60
+ content_type = response.headers.get('content-type')
61
+ if content_type == 'image/png':
62
+ image_data = response.content
63
+ image = PIL.Image.open(io.BytesIO(image_data))
64
+ return np.array(image)
65
+ else:
66
+ raise ValueError("Unexpected response content-type. Expected 'image/png'.")
67
+
68
+ def get_positioner_names(self):
69
+ url = f"{self.base_uri}/PositionerController/getPositionerNames"
70
+ headers = {'accept': 'application/json'}
71
+
72
+ response = self.get_json(url, headers=headers)
73
+ return response
74
+
75
+
76
+
77
+ def task_href(t):
78
+ """Extract the endpoint address from a task dictionary"""
79
+ return t["links"]["self"]["href"]
80
+
81
+ def is_a_task(t):
82
+ """Return true if a parsed JSON return value represents a task"""
83
+ self_href = task_href(t)
84
+ try:
85
+ return ("/api/v2/tasks/" in self_href or "/api/v2/actions/" in self_href)
86
+ except:
87
+ return False
88
+
89
+ def poll_task(task):
90
+ """Poll a task until it finishes, and return the return value"""
91
+ assert is_a_task(task), ("poll_task must be called with a "
92
+ "parsed JSON representation of a task")
93
+ log_n = 0
94
+ while task["status"] in ACTION_RUNNING_KEYWORDS:
95
+ r = requests.get(task_href(task))
96
+ r.raise_for_status()
97
+ task = r.json()
98
+ while len(task["log"]) > log_n:
99
+ d = task["log"][log_n]
100
+ logging.log(d["levelno"], d["message"])
101
+ log_n += 1
102
+ for output_key in ACTION_OUTPUT_KEYS:
103
+ if output_key in task:
104
+ return task[output_key]
105
+ return None
@@ -0,0 +1,6 @@
1
+ """Top-level package for ImSwitchClient."""
2
+ from imswitchclient import ImSwitchClient
3
+
4
+ __author__ = """Benedict Diederich"""
5
+ __email__ = 'benedictdied@gmail.com'
6
+ __version__ = "v0.0.0"#'0.1.0'
@@ -0,0 +1,78 @@
1
+ import requests
2
+ import json
3
+ import time
4
+ import io
5
+ import PIL.Image
6
+ import numpy as np
7
+ import logging
8
+ import zeroconf
9
+ import os
10
+
11
+
12
+ class ImSwitchClient(object):
13
+ def __init__(self, host="localhost", port=8000):
14
+ self.host = host
15
+ self.port = port
16
+ self.get_json(self.base_uri)
17
+ logging.info(f"Connecting to microscope {self.host}:{self.port}")
18
+
19
+ @property
20
+ def base_uri(self):
21
+ return f"http://{self.host}:{self.port}/api/v2"
22
+
23
+ def get_json(self, path):
24
+ """Perform an HTTP GET request and return the JSON response"""
25
+ if not path.startswith("http"):
26
+ path = self.base_uri + path
27
+ r = requests.get(path)
28
+ r.raise_for_status()
29
+ return r.json()
30
+
31
+ def post_json(self, path, payload={}, wait_on_task="auto"):
32
+ """Make an HTTP POST request and return the JSON response"""
33
+ if not path.startswith("http"):
34
+ path = self.base_uri + path
35
+ r = requests.post(path, json=payload)
36
+ r.raise_for_status()
37
+ r = r.json()
38
+ if wait_on_task == "auto":
39
+ wait_on_task = is_a_task(r)
40
+ if wait_on_task:
41
+ return poll_task(r)
42
+ else:
43
+ return r
44
+
45
+ def move_positioner(self, positioner_name, axis, dist, is_absolute=True, is_blocking=True):
46
+ url = f"{self.base_uri}/PositionerController/movePositioner"
47
+ params = {
48
+ 'positionerName': positioner_name,
49
+ 'axis': axis,
50
+ 'dist': dist,
51
+ 'isAbsolute': is_absolute,
52
+ 'isBlocking': is_blocking
53
+ }
54
+ headers = {'accept': 'application/json'}
55
+
56
+ response = self.get_json(url, params=params, headers=headers)
57
+ return response
58
+
59
+ def snap_numpy_to_fastapi(self):
60
+ url = f"{self.base_uri}/RecordingController/snapNumpyToFastAPI"
61
+ headers = {'accept': 'application/json'}
62
+
63
+ response = requests.get(url, headers=headers)
64
+ response.raise_for_status()
65
+ content_type = response.headers.get('content-type')
66
+ if content_type == 'image/png':
67
+ image_data = response.content
68
+ image = PIL.Image.open(io.BytesIO(image_data))
69
+ return np.array(image)
70
+ else:
71
+ raise ValueError("Unexpected response content-type. Expected 'image/png'.")
72
+
73
+ def get_positioner_names(self):
74
+ url = f"{self.base_uri}/PositionerController/getPositionerNames"
75
+ headers = {'accept': 'application/json'}
76
+
77
+ response = self.get_json(url, headers=headers)
78
+ return response
@@ -0,0 +1,72 @@
1
+ Metadata-Version: 2.1
2
+ Name: imswitchclient
3
+ Version: 0.1.0
4
+ Summary: This is a package that connects ImSwitch's REST API to the rest of the world (e.g. jupyter lab)
5
+ Home-page: https://github.com/beniroquai/imswitchclient
6
+ Author: Benedict Diederich
7
+ Author-email: benedictdied@gmail.com
8
+ License: MIT license
9
+ Keywords: imswitchclient
10
+ Classifier: Development Status :: 2 - Pre-Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Natural Language :: English
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.6
16
+ Classifier: Programming Language :: Python :: 3.7
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Requires-Python: >=3.6
19
+ License-File: LICENSE
20
+ License-File: AUTHORS.rst
21
+
22
+ ==============
23
+ ImSwitchClient
24
+ ==============
25
+
26
+
27
+ .. image:: https://img.shields.io/pypi/v/imswitchclient.svg
28
+ :target: https://pypi.python.org/pypi/imswitchclient
29
+
30
+ .. image:: https://img.shields.io/travis/beniroquai/imswitchclient.svg
31
+ :target: https://travis-ci.com/beniroquai/imswitchclient
32
+
33
+ .. image:: https://readthedocs.org/projects/imswitchclient/badge/?version=latest
34
+ :target: https://imswitchclient.readthedocs.io/en/latest/?version=latest
35
+ :alt: Documentation Status
36
+
37
+
38
+ .. image:: https://pyup.io/repos/github/beniroquai/imswitchclient/shield.svg
39
+ :target: https://pyup.io/repos/github/beniroquai/imswitchclient/
40
+ :alt: Updates
41
+
42
+
43
+
44
+ This is a package that connects ImSwitch's REST API to the rest of the world (e.g. jupyter lab)
45
+
46
+
47
+ * Free software: MIT license
48
+ * Documentation: https://imswitchclient.readthedocs.io.
49
+
50
+
51
+ Features
52
+ --------
53
+
54
+ * TODO
55
+
56
+ Credits
57
+ -------
58
+
59
+ This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.
60
+
61
+ .. _Cookiecutter: https://github.com/audreyr/cookiecutter
62
+ .. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage
63
+
64
+
65
+ =======
66
+ History
67
+ =======
68
+
69
+ 0.1.0 (2023-07-03)
70
+ ------------------
71
+
72
+ * First release on PyPI.
@@ -0,0 +1,28 @@
1
+ AUTHORS.rst
2
+ CONTRIBUTING.rst
3
+ HISTORY.rst
4
+ LICENSE
5
+ MANIFEST.in
6
+ README.rst
7
+ setup.cfg
8
+ setup.py
9
+ docs/Makefile
10
+ docs/authors.rst
11
+ docs/conf.py
12
+ docs/contributing.rst
13
+ docs/history.rst
14
+ docs/index.rst
15
+ docs/installation.rst
16
+ docs/make.bat
17
+ docs/readme.rst
18
+ docs/usage.rst
19
+ imswitchclient/ImSwitchClient.py
20
+ imswitchclient/__init__.py
21
+ imswitchclient/client.py
22
+ imswitchclient.egg-info/PKG-INFO
23
+ imswitchclient.egg-info/SOURCES.txt
24
+ imswitchclient.egg-info/dependency_links.txt
25
+ imswitchclient.egg-info/not-zip-safe
26
+ imswitchclient.egg-info/top_level.txt
27
+ tests/__init__.py
28
+ tests/test_imswitchclient.py
@@ -0,0 +1 @@
1
+ imswitchclient
@@ -0,0 +1,23 @@
1
+ [bumpversion]
2
+ current_version = 0.1.0
3
+ commit = True
4
+ tag = True
5
+
6
+ [bumpversion:file:setup.py]
7
+ search = version='{current_version}'
8
+ replace = version='{new_version}'
9
+
10
+ [bumpversion:file:imswitchclient/__init__.py]
11
+ search = __version__ = "v0.0.0"#'{current_version}'
12
+ replace = __version__ = "v0.0.0"#'{new_version}'
13
+
14
+ [bdist_wheel]
15
+ universal = 1
16
+
17
+ [flake8]
18
+ exclude = docs
19
+
20
+ [egg_info]
21
+ tag_build =
22
+ tag_date = 0
23
+
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env python
2
+
3
+ """The setup script."""
4
+
5
+ from setuptools import setup, find_packages
6
+
7
+ with open('README.rst') as readme_file:
8
+ readme = readme_file.read()
9
+
10
+ with open('HISTORY.rst') as history_file:
11
+ history = history_file.read()
12
+
13
+ requirements = [ ]
14
+
15
+ test_requirements = [ ]
16
+
17
+ setup(
18
+ author="Benedict Diederich",
19
+ author_email='benedictdied@gmail.com',
20
+ python_requires='>=3.6',
21
+ classifiers=[
22
+ 'Development Status :: 2 - Pre-Alpha',
23
+ 'Intended Audience :: Developers',
24
+ 'License :: OSI Approved :: MIT License',
25
+ 'Natural Language :: English',
26
+ 'Programming Language :: Python :: 3',
27
+ 'Programming Language :: Python :: 3.6',
28
+ 'Programming Language :: Python :: 3.7',
29
+ 'Programming Language :: Python :: 3.8',
30
+ ],
31
+ description="This is a package that connects ImSwitch's REST API to the rest of the world (e.g. jupyter lab)",
32
+ install_requires=requirements,
33
+ license="MIT license",
34
+ long_description=readme + '\n\n' + history,
35
+ include_package_data=True,
36
+ keywords='imswitchclient',
37
+ name='imswitchclient',
38
+ packages=find_packages(include=['imswitchclient', 'imswitchclient.*']),
39
+ test_suite='tests',
40
+ tests_require=test_requirements,
41
+ url='https://github.com/beniroquai/imswitchclient',
42
+ version='0.1.0',
43
+ zip_safe=False,
44
+ )
@@ -0,0 +1 @@
1
+ """Unit test package for imswitchclient."""
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env python
2
+
3
+ """Tests for `imswitchclient` package."""
4
+
5
+
6
+ import unittest
7
+
8
+ from imswitchclient import imswitchclient
9
+
10
+
11
+ class TestImswitchclient(unittest.TestCase):
12
+ """Tests for `imswitchclient` package."""
13
+
14
+ def setUp(self):
15
+ """Set up test fixtures, if any."""
16
+
17
+ def tearDown(self):
18
+ """Tear down test fixtures, if any."""
19
+
20
+ def test_000_something(self):
21
+ """Test something."""