# ImSwitchClient Documentation
## Introduction
`ImSwitchClient` is a Python wrapper designed for interacting with the ImSwitch REST API, enabling remote control over ImSwitch functionalities, such as stage positioning, laser control, and image acquisition. This client simplifies API interactions and allows seamless integration into Python scripts and Jupyter Notebooks.
[](https://pypi.python.org/pypi/imswitchclient)
## Features
- **Remote Control**: Interface with ImSwitch through REST API endpoints.
- **Comprehensive API Access**: Easily control positioners, lasers, detectors, and imaging settings.
- **Interactive API Exploration**: Utilize the FastAPI Swagger UI at `http://localhost:8000/docs`.
- **Modular Design**: Includes managers for lasers, positioners, image acquisition, and more.
- **Open Source**: Inspired by OpenFlexure Client, freely available under the MIT license.
## Installation
You can install `ImSwitchClient` via pip:
```bash
pip install imswitchclient
```
## Getting Started
### Initializing the Client
```python
import imswitchclient.ImSwitchClient as imc
# Initialize the client
client = imc.ImSwitchClient(host="0.0.0.0", isHttps=True, port=8001)
```
### Example: Moving a Stage and Acquiring an Image
```python
import numpy as np
import matplotlib.pyplot as plt
import time
# Retrieve positioner names
positioner_names = client.positionersManager.getAllDeviceNames()
positioner_name = positioner_names[0]
# Get current position
current_positions = client.positionersManager.getPositionerPositions()[positioner_name]
initial_position = (current_positions["X"], current_positions["Y"])
# Turn on illumination
laser_name = client.lasersManager.getLaserNames()[0]
client.lasersManager.setLaserActive(laser_name, True)
client.lasersManager.setLaserValue(laser_name, 512)
# Move the stage and capture an image
def capture_image_at_position(x, y):
client.positionersManager.movePositioner(positioner_name, "X", x, is_absolute=True, is_blocking=True)
client.positionersManager.movePositioner(positioner_name, "Y", y, is_absolute=True, is_blocking=True)
last_frame = client.recordingManager.snapNumpyToFastAPI()
plt.imshow(last_frame)
plt.show()
# Example scanning
for ix in range(5):
for iy in range(5):
new_x = initial_position[0] + ix * 50
new_y = initial_position[1] + iy * 50
capture_image_at_position(new_x, new_y)
# Return stage to initial position
client.positionersManager.movePositioner(positioner_name, "X", initial_position[0], is_absolute=True, is_blocking=True)
client.positionersManager.movePositioner(positioner_name, "Y", initial_position[1], is_absolute=True, is_blocking=True)
```
### Laser Control Example
```python
laser_name = client.lasersManager.getLaserNames()[0]
client.lasersManager.setLaserActive(laser_name, True)
client.lasersManager.setLaserValue(laser_name, 800)
# Verify laser status
print(client.lasersManager.getLaserNames())
client.lasersManager.setLaserActive(laser_name, False)
```
### Recording an Image
```python
# Take a snapshot
image = client.recordingManager.snapNumpyToFastAPI()
plt.imshow(image)
plt.show()
```
### Setting Live View
```python
client.viewManager.setLiveViewActive(True)
client.viewManager.setLiveViewCrosshairVisible(True)
client.viewManager.setLiveViewGridVisible(False)
```
## API Overview
The ImSwitch API provides access to various components:
### Positioners Manager
- `getAllDeviceNames()` - Get all available positioners.
- `getPositionerPositions()` - Get current position.
- `movePositioner(name, axis, value, is_absolute, is_blocking)` - Move the stage.
- `homeAxis(name, axis, is_blocking)` - Home the positioner.
### Lasers Manager
- `getLaserNames()` - Get available lasers.
- `setLaserActive(name, status)` - Turn laser on/off.
- `setLaserValue(name, value)` - Set laser intensity.
### Recording Manager
- `snapNumpyToFastAPI()` - Capture an image.
- `startRecording()` - Begin recording.
- `stopRecording()` - Stop recording.
### View Manager
- `setLiveViewActive(status)` - Enable live view.
- `setLiveViewCrosshairVisible(status)` - Show/hide crosshair.
- `setLiveViewGridVisible(status)` - Show/hide grid.
## Contributing
Contributions are welcome! Visit the GitHub repository for details: [https://github.com/openUC2/imswitchclient](https://github.com/openUC2/imswitchclient)
## License
This project is licensed under the MIT License.
Raw data
{
"_id": null,
"home_page": "https://github.com/openuc2/imswitchclient",
"name": "imswitchclient",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "imswitchclient",
"author": "Benedict Diederich",
"author_email": "benedictdied@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/61/cb/650fae6ba3115d33bffe99d677ef31f146a2c546f13409bbad32454ce20b/imswitchclient-0.1.3.tar.gz",
"platform": null,
"description": "# ImSwitchClient Documentation\n\n## Introduction\n\n`ImSwitchClient` is a Python wrapper designed for interacting with the ImSwitch REST API, enabling remote control over ImSwitch functionalities, such as stage positioning, laser control, and image acquisition. This client simplifies API interactions and allows seamless integration into Python scripts and Jupyter Notebooks.\n\n[](https://pypi.python.org/pypi/imswitchclient)\n\n## Features\n\n- **Remote Control**: Interface with ImSwitch through REST API endpoints.\n- **Comprehensive API Access**: Easily control positioners, lasers, detectors, and imaging settings.\n- **Interactive API Exploration**: Utilize the FastAPI Swagger UI at `http://localhost:8000/docs`.\n- **Modular Design**: Includes managers for lasers, positioners, image acquisition, and more.\n- **Open Source**: Inspired by OpenFlexure Client, freely available under the MIT license.\n\n## Installation\n\nYou can install `ImSwitchClient` via pip:\n\n```bash\npip install imswitchclient\n```\n\n## Getting Started\n\n### Initializing the Client\n\n```python\nimport imswitchclient.ImSwitchClient as imc\n\n# Initialize the client\nclient = imc.ImSwitchClient(host=\"0.0.0.0\", isHttps=True, port=8001)\n```\n\n### Example: Moving a Stage and Acquiring an Image\n\n```python\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport time\n\n# Retrieve positioner names\npositioner_names = client.positionersManager.getAllDeviceNames()\npositioner_name = positioner_names[0]\n\n# Get current position\ncurrent_positions = client.positionersManager.getPositionerPositions()[positioner_name]\ninitial_position = (current_positions[\"X\"], current_positions[\"Y\"])\n\n# Turn on illumination\nlaser_name = client.lasersManager.getLaserNames()[0]\nclient.lasersManager.setLaserActive(laser_name, True)\nclient.lasersManager.setLaserValue(laser_name, 512)\n\n# Move the stage and capture an image\ndef capture_image_at_position(x, y):\n client.positionersManager.movePositioner(positioner_name, \"X\", x, is_absolute=True, is_blocking=True)\n client.positionersManager.movePositioner(positioner_name, \"Y\", y, is_absolute=True, is_blocking=True)\n last_frame = client.recordingManager.snapNumpyToFastAPI()\n plt.imshow(last_frame)\n plt.show()\n\n# Example scanning\nfor ix in range(5):\n for iy in range(5):\n new_x = initial_position[0] + ix * 50\n new_y = initial_position[1] + iy * 50\n capture_image_at_position(new_x, new_y)\n\n# Return stage to initial position\nclient.positionersManager.movePositioner(positioner_name, \"X\", initial_position[0], is_absolute=True, is_blocking=True)\nclient.positionersManager.movePositioner(positioner_name, \"Y\", initial_position[1], is_absolute=True, is_blocking=True)\n```\n\n### Laser Control Example\n\n```python\nlaser_name = client.lasersManager.getLaserNames()[0]\nclient.lasersManager.setLaserActive(laser_name, True)\nclient.lasersManager.setLaserValue(laser_name, 800)\n\n# Verify laser status\nprint(client.lasersManager.getLaserNames())\nclient.lasersManager.setLaserActive(laser_name, False)\n```\n\n### Recording an Image\n\n```python\n# Take a snapshot\nimage = client.recordingManager.snapNumpyToFastAPI()\nplt.imshow(image)\nplt.show()\n```\n\n### Setting Live View\n\n```python\nclient.viewManager.setLiveViewActive(True)\nclient.viewManager.setLiveViewCrosshairVisible(True)\nclient.viewManager.setLiveViewGridVisible(False)\n```\n\n## API Overview\n\nThe ImSwitch API provides access to various components:\n\n### Positioners Manager\n- `getAllDeviceNames()` - Get all available positioners.\n- `getPositionerPositions()` - Get current position.\n- `movePositioner(name, axis, value, is_absolute, is_blocking)` - Move the stage.\n- `homeAxis(name, axis, is_blocking)` - Home the positioner.\n\n### Lasers Manager\n- `getLaserNames()` - Get available lasers.\n- `setLaserActive(name, status)` - Turn laser on/off.\n- `setLaserValue(name, value)` - Set laser intensity.\n\n### Recording Manager\n- `snapNumpyToFastAPI()` - Capture an image.\n- `startRecording()` - Begin recording.\n- `stopRecording()` - Stop recording.\n\n### View Manager\n- `setLiveViewActive(status)` - Enable live view.\n- `setLiveViewCrosshairVisible(status)` - Show/hide crosshair.\n- `setLiveViewGridVisible(status)` - Show/hide grid.\n\n## Contributing\n\nContributions are welcome! Visit the GitHub repository for details: [https://github.com/openUC2/imswitchclient](https://github.com/openUC2/imswitchclient)\n\n## License\n\nThis project is licensed under the MIT License.\n\n",
"bugtrack_url": null,
"license": "MIT license",
"summary": "This is a package that connects ImSwitch's REST API to the rest of the world (e.g. jupyter lab)",
"version": "0.1.3",
"project_urls": {
"Homepage": "https://github.com/openuc2/imswitchclient"
},
"split_keywords": [
"imswitchclient"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "217a14c9afa893f0fda51c9a2024976124643e07b6678a7ae2e9bb05c6082000",
"md5": "9295db074f3a4e692242ababd80b3499",
"sha256": "46f1b94a0cb2b4b34e8582c16725e26a4625f27cac867f8238b722c76ab47700"
},
"downloads": -1,
"filename": "imswitchclient-0.1.3-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "9295db074f3a4e692242ababd80b3499",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=3.6",
"size": 9925,
"upload_time": "2025-02-14T15:47:54",
"upload_time_iso_8601": "2025-02-14T15:47:54.143413Z",
"url": "https://files.pythonhosted.org/packages/21/7a/14c9afa893f0fda51c9a2024976124643e07b6678a7ae2e9bb05c6082000/imswitchclient-0.1.3-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "61cb650fae6ba3115d33bffe99d677ef31f146a2c546f13409bbad32454ce20b",
"md5": "e243588a262c90e7d76a12e3e5482a2e",
"sha256": "e427005329525a0f4f9165f260893ca43644a6da5535726e228c0129268a2bc9"
},
"downloads": -1,
"filename": "imswitchclient-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "e243588a262c90e7d76a12e3e5482a2e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 11249,
"upload_time": "2025-02-14T15:47:55",
"upload_time_iso_8601": "2025-02-14T15:47:55.913076Z",
"url": "https://files.pythonhosted.org/packages/61/cb/650fae6ba3115d33bffe99d677ef31f146a2c546f13409bbad32454ce20b/imswitchclient-0.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-14 15:47:55",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "openuc2",
"github_project": "imswitchclient",
"travis_ci": true,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "imswitchclient"
}