In [2]:
from IPython import display
from ipywidgets import widgets

In [3]:
from config import ASI_Controller, Motor
Z = Motor('config/motor.yaml')
XY = ASI_Controller('config/asi_controller.yaml')
print(XY.where_xy())


Initializing stage...
(0.0012, -0.001)

In [ ]:
Z.move_relative(5)

In [ ]:
overload = 999.9

XY.move_xy(-overload, -overload)
xmin, ymin = XY.where_xy()
print 'xmin: {} ymin: {}'.format(xmin, ymin)

XY.move_xy(overload, overload)
xmax, ymax = XY.where_xy()
print 'xmax: {} ymax: {}'.format(xmax, ymax)

ranges_xy = (xmax - xmin, ymax - ymin)
print 'range: ', ranges_xy

In [3]:
# icons are from "font-awesome"
x_minus = widgets.Button(
    description='',
    disabled=False,
    button_style='primary',
    icon = 'fa-arrow-left',
    width = '50px')
def xminus(b):
    XY.r_xy(-xy_slider.value,0)
    display.clear_output()
    print(XY.where_xy())
x_minus.on_click(xminus)

x_plus = widgets.Button(
    description='',
    disabled=False,
    button_style='primary',
    icon = 'fa-arrow-right',
    width = '50px')
def xplus(b):
    XY.r_xy(xy_slider.value,0)
    display.clear_output()
    print(XY.where_xy())
x_plus.on_click(xplus)

y_minus = widgets.Button(
    description='',
    disabled=False,
    button_style='primary', 
    icon='fa-arrow-up',
    width = '50px')
def yminus(b):
    XY.r_xy(0, -xy_slider.value)
    display.clear_output()
    print(XY.where_xy())
y_minus.on_click(yminus)

y_plus = widgets.Button(
    description='',
    disabled=False,
    button_style='primary',
    icon = 'fa-arrow-down',
    width = '50px')
def yplus(b):
    XY.r_xy(0, xy_slider.value)
    display.clear_output()
    print(XY.where_xy())
y_plus.on_click(yplus)


xy_home = widgets.Button(
    description='',
    disabled=False,
    button_style='primary',
    icon = 'fa-home',
    width = '50px')
def xyhome(b):
    Z.home()
    XY.move_xy(0,0)
    display.clear_output()
    print(XY.where_xy())
xy_home.on_click(xyhome)

xy_slider = widgets.FloatSlider(description='[mm]', min=.05, max=10,step=.05, orientation='vertical', height='150px')
def xystep(change):
    xy_step = change['new']
xy_slider.observe(xystep, names='value')

xy_cluster = widgets.HBox([ xy_slider, widgets.VBox([ widgets.HBox([x_minus,x_plus,xy_home]), widgets.HBox([y_minus, y_plus]) ]) ])


z_minus = widgets.Button(
    description='',
    disabled=False,
    button_style='primary',
    icon = 'fa-arrow-up')
def zminus(b):
    Z.move_relative(-z_slider.value)
    display.clear_output()
    print(Z.where())
z_minus.on_click(zminus)

z_plus = widgets.Button(
    description='',
    disabled=False,
    button_style='primary',
    icon = 'fa-arrow-down')
def zplus(b):
    Z.move_relative(z_slider.value)
    display.clear_output()
    print(Z.where())
z_plus.on_click(zplus)

z_home = widgets.Button(
    description='',
    disabled=False,
    button_style='primary',
    icon = 'fa-home',
    width = '50px')
def zhome(b):
    Z.home()
    display.clear_output()
    print(Z.where())
z_home.on_click(zhome)

z_slider = widgets.FloatSlider(description='[mm]', min=.05, max=10,step=.05, orientation='vertical', height='150px')
def zstep(change):
    z_step = change['new']
z_slider.observe(zstep, names='value')

z_cluster = widgets.VBox([ widgets.HBox([ z_slider, widgets.VBox([z_minus, z_plus]), z_home]) ])


x_pos = widgets.Text(
    value='0',
    placeholder='Type something',
    description='X:',
    disabled=False,
    width='150px')
def xpos(sender):
    xcurr,ycurr = XY.where_xy()
    XY.move_xy(sender.value,ycurr)
x_pos.on_submit(xpos)

y_pos = widgets.Text(
    value='0',
    placeholder='Type something',
    description='Y:',
    disabled=False,
    width='150px')
def ypos(sender):
    xcurr,ycurr = XY.where_xy()
    XY.move_xy(xcurr, sender.value)
y_pos.on_submit(ypos)

z_pos = widgets.Text(
    value='0',
    placeholder='Type something',
    description='Z:',
    disabled=False,
    width='150px')
def zpos(sender):
    Z.move(float(sender.value))
z_pos.on_submit(zpos)

line = widgets.Label(value="$---------------------------------------$",disabled=False)

widgets.VBox([ widgets.HBox([x_pos, y_pos, z_pos]), line, widgets.HBox([xy_cluster, z_cluster]) ])


 
# TODO: GO button
# TODO: convert Z.move() input to float in .py file
# TODO: GUI class



In [7]:



Out[7]:
<config.gui.GUI instance at 0x104ea3878>

In [1]:
stri = 'A01	-2.3985	32.4159	93.4\nA02	-11.3985	32.4159	93.4\nA03	-20.3985	32.4159	93.4\nA04	-29.3985	32.4159	93.4\nA05	-38.3985	32.4159	93.4\nA06	-47.3985	32.4159	93.4\nA07	-56.3985	32.4159	93.4\nA08	-65.3985	32.4159	93.4\nA09	-74.3985	32.4159	93.4\nA10	-83.3985	32.4159	93.4\nB01	-2.3985	41.4159	93.4\nB02	-11.3985	41.4159	93.4\nB03	-20.3985	41.4159	93.4\nB04	-29.3985	41.4159	93.4\nB05	-38.3985	41.4159	93.4\nB06	-47.3985	41.4159	93.4\nB07	-56.3985	41.4159	93.4\nB08	-65.3985	41.4159	93.4\nB09	-74.3985	41.4159	93.4\nB10	-83.3985	41.4159	93.4\nB11	-92.3985	41.4159	93.4'
locs = {}
for lin in stri.splitlines():
    tem = lin.split('\t')
    locs[tem[0]] = map(float, tem[1:])
locs


Out[1]:
{'A01': [-2.3985, 32.4159, 93.4],
 'A02': [-11.3985, 32.4159, 93.4],
 'A03': [-20.3985, 32.4159, 93.4],
 'A04': [-29.3985, 32.4159, 93.4],
 'A05': [-38.3985, 32.4159, 93.4],
 'A06': [-47.3985, 32.4159, 93.4],
 'A07': [-56.3985, 32.4159, 93.4],
 'A08': [-65.3985, 32.4159, 93.4],
 'A09': [-74.3985, 32.4159, 93.4],
 'A10': [-83.3985, 32.4159, 93.4],
 'B01': [-2.3985, 41.4159, 93.4],
 'B02': [-11.3985, 41.4159, 93.4],
 'B03': [-20.3985, 41.4159, 93.4],
 'B04': [-29.3985, 41.4159, 93.4],
 'B05': [-38.3985, 41.4159, 93.4],
 'B06': [-47.3985, 41.4159, 93.4],
 'B07': [-56.3985, 41.4159, 93.4],
 'B08': [-65.3985, 41.4159, 93.4],
 'B09': [-74.3985, 41.4159, 93.4],
 'B10': [-83.3985, 41.4159, 93.4],
 'B11': [-92.3985, 41.4159, 93.4]}

In [120]:
[['Sat Apr 29 16:39:09 2017', 'AT A01'],
 ['Sat Apr 29 16:39:40 2017', 'OPEN tree in + out'],
 ['Sat Apr 29 17:04:23 2017', 'CLOSE tree out; OPEN chip in + out'],
 ['Sat Apr 29 17:16:19 2017', 'AT wash'],
 ['Sat Apr 29 17:17:46 2017', 'AT A02'],
 ['Sat Apr 29 17:19:17 2017', 'OPEN tree in + out'],
 ['Sat Apr 29 17:41:34 2017', 'CLOSE tree out; OPEN chip in + out'],
 ['Sat Apr 29 17:50:44 2017', 'CLOSE chip out + in; CLOSE tree in'],
 ['Sat Apr 29 17:51:40 2017', 'AT wash'],
 ['Sat Apr 29 17:52:12 2017', 'AT A03'],
 ['Sat Apr 29 17:53:44 2017', 'OPEN tree in + out'],
 ['Sat Apr 29 18:16:05 2017', 'CLOSE tree out; OPEN chip in + out'],
 ['Sat Apr 29 18:19:51 2017', 'CLOSE chip out + in; CLOSE tree in'],
 ['Sat Apr 29 18:20:04 2017', 'AT wash'],
 ['Sat Apr 29 18:20:26 2017', 'AT A04'],
 ['Sat Apr 29 18:20:50 2017', 'OPEN tree in + out']]


Out[120]:
'Sat Apr 29 17:01:29 2017'

In [143]:
# 16:39:40 to 16:56:43
# log = []
log


Out[143]:
[['Sat Apr 29 16:39:09 2017', 'AT A01'],
 ['Sat Apr 29 16:39:40 2017', 'OPEN tree in + out'],
 ['Sat Apr 29 17:04:23 2017', 'CLOSE tree out; OPEN chip in + out'],
 ['Sat Apr 29 17:16:19 2017', 'AT wash'],
 ['Sat Apr 29 17:17:46 2017', 'AT A02'],
 ['Sat Apr 29 17:19:17 2017', 'OPEN tree in + out'],
 ['Sat Apr 29 17:41:34 2017', 'CLOSE tree out; OPEN chip in + out'],
 ['Sat Apr 29 17:50:44 2017', 'CLOSE chip out + in; CLOSE tree in'],
 ['Sat Apr 29 17:51:40 2017', 'AT wash'],
 ['Sat Apr 29 17:52:12 2017', 'AT A03'],
 ['Sat Apr 29 17:53:44 2017', 'OPEN tree in + out'],
 ['Sat Apr 29 18:16:05 2017', 'CLOSE tree out; OPEN chip in + out'],
 ['Sat Apr 29 18:19:51 2017', 'CLOSE chip out + in; CLOSE tree in'],
 ['Sat Apr 29 18:20:04 2017', 'AT wash'],
 ['Sat Apr 29 18:20:26 2017', 'AT A04'],
 ['Sat Apr 29 18:20:50 2017', 'OPEN tree in + out'],
 ['Sat Apr 29 18:44:00 2017', 'CLOSE tree out; OPEN chip in + out'],
 ['Sat Apr 29 18:47:07 2017', 'CLOSE chip out + in; CLOSE tree in'],
 ['Sat Apr 29 18:47:22 2017', 'AT wash']]

Loop


In [136]:
# WELL
# all valves closed
st = 'A01'

x1,y1,z1 = locs[st]

Z.move(42)
XY.move_xy(x1,y1)
Z.move(z1)
log.append([time.ctime(time.time()), 'AT '+st])

In [137]:
# ACQUIRE 120 frames 11000 ms
# OPEN Hep_1 + W_1 (tree in + out)
log.append([time.ctime(time.time()), 'OPEN tree in + out'])

# flow 20 min (fill tube + tree)

In [139]:
# ACQUIRE 120 frames  5000 ms
# CLOSE W_1 (tree out); OPEN in_1 + out_1 (chip in + out)
log.append([time.ctime(time.time()), 'CLOSE tree out; OPEN chip in + out'])

# flow 10 min (fill chip)

In [140]:
# CLOSE out_1 + in_1 (chip out + in); CLOSE Hep_1 (tree in)
log.append([time.ctime(time.time()), 'CLOSE chip out + in; CLOSE tree in'])

# incubate... WASH in meantime

In [141]:
# WASH
Z.move(42)
XY.move_xy(-8.9473,1.0592)
Z.move(62)
log.append([time.ctime(time.time()), 'AT wash'])

In [ ]:

SETUP


In [96]:
import time
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

Autosipper


In [ ]:
# config director must have "__init__.py" file
# from the 'config' directory, import the following classes:
from config import Motor, ASI_Controller, Autosipper
from config import utils as ut

autosipper = Autosipper(Motor('config/motor.yaml'), ASI_Controller('config/asi_controller.yaml'))
autosipper.coord_frames

In [ ]:
# add/determine deck info
autosipper.coord_frames.deck.position_table = ut.read_delim_pd('config/position_tables/deck')

# check deck alignment
# CLEAR DECK OF OBSTRUCTIONS!!
autosipper.go_to('deck', ['name'],'align')

In [ ]:
# add plate

Manifold


In [ ]:
from config import Manifold

manifold = Manifold('192.168.1.3', 'config/valvemaps/valvemap.csv', 512)
manifold.valvemap[manifold.valvemap.name>0]

Micromanager


In [ ]:
# !!!! Also must have MM folder on system PATH
# mm_version = 'C:\Micro-Manager-1.4'
# cfg = 'C:\Micro-Manager-1.4\SetupNumber2_05102016.cfg'
mm_version = 'C:\Program Files\Micro-Manager-2.0beta'
cfg = 'C:\Program Files\Micro-Manager-2.0beta\Setup2_20170413.cfg'

import sys
sys.path.insert(0, mm_version) # make it so python can find MMCorePy
import MMCorePy

from PIL import Image

core = MMCorePy.CMMCore()
core.loadSystemConfiguration(cfg)
core.setProperty("Spectra", "White_Enable", "1")
core.waitForDevice("Spectra")

core.setProperty("Cam Andor_Zyla4.2", "Sensitivity/DynamicRange", "16-bit (low noise & high well capacity)") # NEED TO SET CAMERA TO 16 BIT (ceiling 12 BIT = 4096)

In [ ]:
# core.initializeCircularBuffer()
# core.setCircularBufferMemoryFootprint(4096) # MiB

Preset: 1_PBP
ConfigGroup,Channel,1_PBP,TIFilterBlock1,Label,1-PBP

Preset: 2_BF
ConfigGroup,Channel,2_BF,TIFilterBlock1,Label,2-BF

Preset: 3_DAPI
ConfigGroup,Channel,3_DAPI,TIFilterBlock1,Label,3-DAPI

Preset: 4_eGFP
ConfigGroup,Channel,4_eGFP,TIFilterBlock1,Label,4-GFP

Preset: 5_Cy5
ConfigGroup,Channel,5_Cy5,TIFilterBlock1,Label,5-Cy5

Preset: 6_AttoPhos
ConfigGroup,Channel,6_AttoPhos,TIFilterBlock1,Label,6-AttoPhos

EXPERIMENT


In [ ]:
core.setConfig('Channel','1_PBP')

In [ ]:
core.setProperty(core.getCameraDevice(), "Exposure", 300)

In [ ]:
core.snapImage()
img = core.getImage()
plt.imshow(img,cmap='gray')
image = Image.fromarray(img)
image.save('TESTIMAGE.tif')

In [ ]:
for i in range(5):
    x = core.getXPosition()
    y = core.getYPosition()
    core.setXYPosition(x-1500,y)
    core.waitForDevice(core.getXYStageDevice())
    
    core.snapImage()
    img = core.getImage()
    image = Image.fromarray(img)
    image.save('images/images_{}.tif'.format(i))

MM Get info


In [ ]:
core.getFocusDevice()
core.getCameraDevice()
core.XYStageDevice()
core.getDevicePropertyNames(core.getCameraDevice())

Video


In [ ]:
# cv2.startWindowThread()
cv2.namedWindow('Video')
cv2.imshow('Video',img)
cv2.waitKey(0)

In [ ]:
cv2.destroyAllWindows()
core.stopSequenceAcquisition()

In [ ]:
import cv2
cv2.namedWindow('Video')
core.startContinuousSequenceAcquisition(1)
while True:
    img = core.getLastImage()
    if core.getRemainingImageCount() > 0:
#         img = core.popNextImage()
        img = core.getLastImage()
        cv2.imshow('Video', img)
        cv2.waitkey(0)
    else:
        print('No frame')
    if cv2.waitKey(20) >= 0:
        break
cv2.destroyAllWindows()
core.stopSequenceAcquisition()
# core.reset()

EXIT


In [ ]:
autosipper.exit()
manifold.exit()
core.unloadAllDevices()
core.reset()
print 'closed'