4. Python examples

These examples are all shipped with the owl python package. To find them, navigate to the owl directory of your installation and look for them in the examples directory.

The examples are located inside:

/home/ramona/falcongui/lib/python3.10/site-packages/owl/examples

Synchronous acquisition

 1"""This script shows you how to acquire an image and save it to a folder
 2using the built in transmission illumination board for illumination.
 3
 4Ramona Optics, Inc.
 5Copyright 2018-2024
 6"""
 7from owl import mcam_data
 8from owl.instruments import MCAM
 9from owl.util import sys_info as owl_sys_info
10# Import the required packages
11from owl.visualize import quickview
12
13print(owl_sys_info())
14
15# Open the mcam
16mcam = MCAM(serial_number='Kestrel0101R')
17
18# 100 ms is the default exposure
19mcam.exposure = 0.1
20mcam.set_illumination_brightness(.5)
21
22dataset = mcam.acquire_full_field_of_view()
23# Save the data
24raw_data_file = mcam_data.save(dataset, 'demo')
25
26# %% View the acquired data
27quickview(dataset)
28
29# Close after the data has been viewed, and saved
30mcam.close()

Controlling Fluorescence Units Programmatically

 1"""
 2This script shows how to control the fluorescence illumination controlled
 3digitally in a script.
 4It requires owl version 0.9.30 or greater
 5
 6Copyright Ramona Optics Inc, 2019-2024. All rights reserved.
 7"""
 8from owl.instruments import MCAM
 9
10mcam = MCAM(serial_number='Kestrel0053R')
11fluorescence = mcam.fluorescence_illumination
12
13# Enable the first LED (or the only LED if only one is connected)
14fluorescence.led_selected = 0
15
16# Set to 25 percent power
17fluorescence.led_power_percentage = 25
18
19# Set to 60 percent power
20fluorescence.led_power_percentage = 60
21
22# Set to 0 percent power
23# This makes the LEDs appear off.
24# Power below 10 percent may also manifest itself as being off
25fluorescence.led_power_percentage = 0
26
27# Turn off and deselect the LEDs (safer, more proper way of turning off LEDs)
28fluorescence.clear()
29
30# Read the temperature recorded by all the temperature sensors in the system
31temperatures = fluorescence.temperatures

Z Stack acquisition with Web API

 1"""Z stack acquisition with the Ramona Optics MCAM using the web API.
 2
 3This example demonstrates how to acquire a Z stack acquisition using the MCAM web API.
 4
 5The Z stack assay allows for the acquisition of a series of images at different focal planes.
 6The assay is configured using json with the following parameters.
 7
 8The `save_location` parameter specifies the location where the data will be saved on the
 9MCAM computer or NAS (Network Attached Storage).
10
11The `metadata` parameter is a dictionary that can be used to store any additional information
12you would like to associate with the assay.
13
14The `parameters` parameter is a dictionary that contains the parameters for the assay.
15A full list of parameters can be found in the MCAM documentation.
16https://docs.ramonaoptics.com/models.html#z-stack-assay
17
18The `configuration` parameter is a string that specifies the file path to a configuration file
19generated by the MCAM software.
20This file contains the parameters for the assay and is generally stored on the MCAM computer
21or on a NAS.
22
23Ramona Optics, Inc. Copyright 2023-2024
24"""
25import requests
26
27# Change the serial number to the one provided to you by Ramona Optics
28serial_number = "Kestrel0001"
29url = "http://localhost:8800"
30
31# Connect to the MCAM device using the webAPI endpoint
32requests.post(f"{url}/v1/mcam/{serial_number}", timeout=10)
33
34# Set the MCAM device to sample loading state, which will extend the plate nest
35requests.post(
36    f"{url}/v1/mcam/{serial_number}/state",
37    json={"state": "sample_loading"},
38    timeout=10,
39)
40
41# Set the MCAM device to the acquisition state, which will insert the plate nest
42requests.post(
43    f"{url}/v1/mcam/{serial_number}/state",
44    json={"state": "acquisition"},
45    timeout=10,
46)
47
48assay_parameters = {
49    "save_location": "/MCAM_data/my_z_stack_acquisition/",
50    "metadata": {
51        "operator": "Mike Roscopy"
52    },
53    "parameters": {
54        "save_mode": "export",
55        "z_positions": [1E-3, 2E-3, 3E-3]
56    }
57}
58# Start the Z stack plate scan acquisition
59response = requests.post(
60    f"{url}/v1/mcam/{serial_number}/assay/z_stack",
61    json=assay_parameters,
62    # This assay can take more than 10 seconds if saving to slow storage
63    timeout=30,
64)
65
66# Set the MCAM device to sample loading state, which will extend the plate nest
67requests.post(
68    f"{url}/v1/mcam/{serial_number}/state",
69    json={"state": "sample_loading"},
70    timeout=10
71)
72
73# Disconnect from the MCAM device
74requests.delete(
75    f"{url}/v1/mcam/{serial_number}",
76    timeout=10
77)

Advanced Usage: Volumetric Scan with the MCAM Falcon