This is a package that connects ImSwitch's REST API to the rest of the world (e.g. jupyter lab)
Project description
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.
Try on GOOGLE COLAB:
Hit this link and test:
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:
pip install imswitchclient
Getting Started
Initializing the Client
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
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
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
# Take a snapshot
image = client.recordingManager.snapNumpyToFastAPI()
plt.imshow(image)
plt.show()
Setting Live View
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
License
This project is licensed under the MIT License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file imswitchclient-0.1.4.tar.gz.
File metadata
- Download URL: imswitchclient-0.1.4.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a10d4f8238df09e2f6b2c01b428e145d9bfcfbe11bb2f36701cddbad75471b0b
|
|
| MD5 |
68e79f2b7b06414499272779f852b3fe
|
|
| BLAKE2b-256 |
fa4368cd12f4a01319d43af033066ed0b53b0055b6f9316ac987d294651f54a5
|
File details
Details for the file imswitchclient-0.1.4-py2.py3-none-any.whl.
File metadata
- Download URL: imswitchclient-0.1.4-py2.py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2230eff6778dbe7c5f4dc101337dd0bd99297537a8e2a7fc91fe1545e94cecd7
|
|
| MD5 |
1a18b7dc348bbc271e09ab411bfce617
|
|
| BLAKE2b-256 |
04a5d60d660e0e098fc5cef2e45bc0d22a9ff48c2e5d4d05c6e1c349750176a8
|