Components

These scripts provide usage examples for individual components of the C-Trap.

Confocal

import bluelake as bl


print(bl.excitation.red_laser.power_level)  # get current value in %
bl.excitation.red_laser.power_level = 40  # set value in %

bl.confocal.start_scan()  # start the active configuration
# bl.confocal.start_scan("Preset name")  # OR start a specific preset

print(bl.confocal.is_scanning)  # check whether the scan is still in progress

# bl.confocal.wait()  # wait for the scan to finish
bl.confocal.abort_scan()  # OR abort the scan before it has finished

Fluidics

import bluelake as bl


# Open specific valves
bl.fluidics.open(1, 2, 3, 6)
# or
bl.fluidics.open(1, 2)

# And close valves
bl.fluidics.close(1, 2)

# Read the current pressure value
print(bl.fluidics.pressure)

# Increase/decrease the pressure by one step, just like the +/- buttons in the UI
bl.fluidics.increase_pressure()
bl.fluidics.decrease_pressure()

while bl.fluidics.pressure < 0.1:  # bar
    bl.fluidics.increase_pressure()
    bl.pause(1)  # seconds to pause -- important because pressure changes are slow

Microstage

import bluelake as bl


bl.microstage.move_to("beads")  # the waypoint name must match the name in the UI
bl.microstage.move_to("DNA", speed=2)  # optional speed in mm/s (defaults to 1 mm/s)

print(bl.microstage.position)  # read the current position

bl.microstage.move_to(x=10, y=16.5)  # move to an absolute position
bl.microstage.move_by(dx=-2, dy=3)  # move relative to the current position
bl.microstage.move_by(dx=1, dy=-5, speed=3)

Power

import bluelake as bl


# Reading values
print("Trapping laser", bl.power.trapping_laser)  # get power in %
print(f"Overall {bl.power.overall_trapping_power:.2f} %")
print(bl.power.trap1_split)
# print(bl.power.qtrap_split)
print(bl.power.bright_field_led)

# Setting values
bl.power.bright_field_led = 7  # value in %

Shutters

import bluelake as bl


bl.shutters.clear(1)  # single
bl.shutters.clear(1, 2)  # multiple

# or optionally:
bl.shutters.clear(1, delay_ms=100)  # how long the shutter is closed, default 500 ms

Timeline

import bluelake as bl


# Grab a reference to any channel. The first [] is the group name and the second [] is the
# channel name. These match exactly the channel tree in the graphical UI of Bluelake.
force_channel = bl.timeline["Force HF"]["Force 1x"]
match_score = bl.timeline["Tracking Match Score"]["Bead 1"]

# The latest ("current") value of the data on that channel
force_value = force_channel.latest_value

# The current time, according to the timeline
t0 = bl.timeline.current_time

# Do something: we pause as a placeholder for another action
bl.pause(1)  # seconds

t1 = bl.timeline.current_time

# Fetch the data for that timespan
force_data = force_channel[t0:t1].data
timestamps = force_channel[t0:t1].timestamps
print(force_data)

# Add a marker to the timeline GUI
bl.timeline.mark_begin("marker name")
try:
    # Do some work here.
    # We use a `try`/`finally` construct so that the marker gets closed even
    # if this code produces an error or the script is stopped from the UI.
    bl.pause(1)  # placeholder for actual work
finally:
    bl.timeline.mark_end()

Traps

import bluelake as bl


# Absolute movement
bl.mirror1.move_to(x=4, y=1)  # [um] matches the position in the UI
bl.mirror1.move_to(x=10)  # [um] no change on Y
bl.mirror1.move_to(x=10, speed=10)  # [um/s] defaults to 1 um/s if not specified

# Relative movement
bl.mirror1.move_by(dx=1, dy=2)  # [um] note `dx` instead of `x` above
bl.mirror1.move_by(dx=1, dy=2, speed=0)  # [um/s] 0 means maximum speed

# Movement in Z
bl.telescope12.move_to(z=-2)  # [um] # only Z for trap 1+2 Z

# Nanostage
bl.nanostage.move_to(x=1, y=20, z=15, speed=3)  # [um] full XYZ movement


def pingpong(distance_delta_um, dwell_time_ms, speed, repeat_n):
    """This will pingpong `repeat_n` times or until the script is stopped in the UI"""
    dwell_time_seconds = dwell_time_ms / 1000
    for _ in range(repeat_n):
        bl.mirror1.move_by(dx=+distance_delta_um, speed=speed)
        bl.pause(dwell_time_seconds)
        print("ping")
        # bl.reset_force() # optionally reset the force

        bl.mirror1.move_by(dx=-distance_delta_um, speed=speed)
        bl.pause(dwell_time_seconds)
        print("pong")
        # bl.reset_force() # optionally reset the force


pingpong(distance_delta_um=0.01, dwell_time_ms=50, speed=10, repeat_n=5)