Skip to main content

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.

PyPI Version

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

imswitchclient-0.1.3.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

imswitchclient-0.1.3-py2.py3-none-any.whl (9.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file imswitchclient-0.1.3.tar.gz.

File metadata

  • Download URL: imswitchclient-0.1.3.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for imswitchclient-0.1.3.tar.gz
Algorithm Hash digest
SHA256 e427005329525a0f4f9165f260893ca43644a6da5535726e228c0129268a2bc9
MD5 e243588a262c90e7d76a12e3e5482a2e
BLAKE2b-256 61cb650fae6ba3115d33bffe99d677ef31f146a2c546f13409bbad32454ce20b

See more details on using hashes here.

File details

Details for the file imswitchclient-0.1.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for imswitchclient-0.1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 46f1b94a0cb2b4b34e8582c16725e26a4625f27cac867f8238b722c76ab47700
MD5 9295db074f3a4e692242ababd80b3499
BLAKE2b-256 217a14c9afa893f0fda51c9a2024976124643e07b6678a7ae2e9bb05c6082000

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page