SETUP


In [3]:
import time
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
%matplotlib inline

Autosipper


In [2]:
# config directory 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


Initializing stage...
Out[2]:
hardware deck
transform [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, ... [[-1, 0, 0], [0, 1, 0], [0, 0, -1], [0, 0, 93]]
position_table None None

In [3]:
from config import gui
gui.stage_control(autosipper.XY, autosipper.Z)


(0.0,)

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

In [66]:
from config import utils as ut
platemap = ut.generate_position_table((8,8),(9,9),93.5)
platemap[]


Out[66]:
n s r c name x y z
0 0 0 0 0 A01 0.0 0.0 93.5
1 1 1 0 1 A02 9.0 0.0 93.5
2 2 2 0 2 A03 18.0 0.0 93.5
3 3 3 0 3 A04 27.0 0.0 93.5
4 4 4 0 4 A05 36.0 0.0 93.5
5 5 5 0 5 A06 45.0 0.0 93.5
6 6 6 0 6 A07 54.0 0.0 93.5
7 7 7 0 7 A08 63.0 0.0 93.5
8 8 15 1 0 B01 0.0 9.0 93.5
9 9 14 1 1 B02 9.0 9.0 93.5
10 10 13 1 2 B03 18.0 9.0 93.5
11 11 12 1 3 B04 27.0 9.0 93.5
12 12 11 1 4 B05 36.0 9.0 93.5
13 13 10 1 5 B06 45.0 9.0 93.5
14 14 9 1 6 B07 54.0 9.0 93.5
15 15 8 1 7 B08 63.0 9.0 93.5
16 16 16 2 0 C01 0.0 18.0 93.5
17 17 17 2 1 C02 9.0 18.0 93.5
18 18 18 2 2 C03 18.0 18.0 93.5
19 19 19 2 3 C04 27.0 18.0 93.5
20 20 20 2 4 C05 36.0 18.0 93.5
21 21 21 2 5 C06 45.0 18.0 93.5
22 22 22 2 6 C07 54.0 18.0 93.5
23 23 23 2 7 C08 63.0 18.0 93.5
24 24 31 3 0 D01 0.0 27.0 93.5
25 25 30 3 1 D02 9.0 27.0 93.5
26 26 29 3 2 D03 18.0 27.0 93.5
27 27 28 3 3 D04 27.0 27.0 93.5
28 28 27 3 4 D05 36.0 27.0 93.5
29 29 26 3 5 D06 45.0 27.0 93.5
... ... ... ... ... ... ... ... ...
34 34 34 4 2 E03 18.0 36.0 93.5
35 35 35 4 3 E04 27.0 36.0 93.5
36 36 36 4 4 E05 36.0 36.0 93.5
37 37 37 4 5 E06 45.0 36.0 93.5
38 38 38 4 6 E07 54.0 36.0 93.5
39 39 39 4 7 E08 63.0 36.0 93.5
40 40 47 5 0 F01 0.0 45.0 93.5
41 41 46 5 1 F02 9.0 45.0 93.5
42 42 45 5 2 F03 18.0 45.0 93.5
43 43 44 5 3 F04 27.0 45.0 93.5
44 44 43 5 4 F05 36.0 45.0 93.5
45 45 42 5 5 F06 45.0 45.0 93.5
46 46 41 5 6 F07 54.0 45.0 93.5
47 47 40 5 7 F08 63.0 45.0 93.5
48 48 48 6 0 G01 0.0 54.0 93.5
49 49 49 6 1 G02 9.0 54.0 93.5
50 50 50 6 2 G03 18.0 54.0 93.5
51 51 51 6 3 G04 27.0 54.0 93.5
52 52 52 6 4 G05 36.0 54.0 93.5
53 53 53 6 5 G06 45.0 54.0 93.5
54 54 54 6 6 G07 54.0 54.0 93.5
55 55 55 6 7 G08 63.0 54.0 93.5
56 56 63 7 0 H01 0.0 63.0 93.5
57 57 62 7 1 H02 9.0 63.0 93.5
58 58 61 7 2 H03 18.0 63.0 93.5
59 59 60 7 3 H04 27.0 63.0 93.5
60 60 59 7 4 H05 36.0 63.0 93.5
61 61 58 7 5 H06 45.0 63.0 93.5
62 62 57 7 6 H07 54.0 63.0 93.5
63 63 56 7 7 H08 63.0 63.0 93.5

64 rows × 8 columns


In [ ]:
ut.lookup(platemap)

Manifold


In [55]:
from config import Manifold

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


Out[55]:
valve name
0 0 inlet_out
2 2 inlet_in
8 8 chip_out
9 9 N
10 10 B1
11 11 S1
12 12 S2
13 13 B2
14 14 chip_in

In [247]:
def valve_states():
    tmp = []
    for i in [2,0,14,8]:
        status = 'x'
        if manifold.read_valve(i):
            status = 'o'
        tmp.append([status, manifold.valvemap.name.iloc[i]])
    return pd.DataFrame(tmp)

In [255]:
tmp = []
for i in range(16):
    status = 'x'
    if manifold.read_valve(i):
        status = 'o'
    name = manifold.valvemap.name.iloc[i]
    tmp.append([status, name])
pd.DataFrame(tmp).replace(np.nan, '')


Out[255]:
0 1
0 o inlet_out
1 x
2 o inlet_in
3 x
4 x
5 x
6 x
7 x
8 x chip_out
9 x N
10 o B1
11 o S1
12 o S2
13 o B2
14 x chip_in
15 x

In [240]:
name = 'inlet_in'
v = manifold.valvemap['valve'][manifold.valvemap.name==name]

In [236]:
v=14

In [234]:
manifold.depressurize(v)

In [241]:
manifold.pressurize(v)

In [54]:
manifold.exit()

Micromanager


In [1]:
# !!!! 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 [2]:
core.setProperty("Spectra", "White_Enable", "0")

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

TEST

4.5 psi, 25 psi valves


In [253]:
log = []

In [254]:
autosipper.Z.move(93.5)
manifold.depressurize(2)
manifold.depressurize(0)
log.append([time.ctime(time.time()), 'open inlet_in, inlet_out'])
valve_states()


Out[254]:
0 1
0 o inlet_in
1 o inlet_out
2 x chip_in
3 x chip_out

In [256]:
text = 'fluorescence observed'
log.append([time.ctime(time.time()), text])

In [258]:
text = 'CLOSE inlet_out'
manifold.pressurize(0)
log.append([time.ctime(time.time()), text])

text = 'OPEN chip_in, chip_out'
manifold.depressurize(14)
manifold.depressurize(8)
log.append([time.ctime(time.time()), text])

valve_states()


Out[258]:
0 1
0 o inlet_in
1 x inlet_out
2 o chip_in
3 o chip_out

In [259]:
text = 'fill'
log.append([time.ctime(time.time()), text])
manifold.pressurize(8)
#closed all

In [265]:
autosipper.Z.move(93.5)
manifold.depressurize(2)
manifold.depressurize(0)
log.append([time.ctime(time.time()), 'open inlet_in, inlet_out'])
valve_states()


Out[265]:
0 1
0 o inlet_in
1 o inlet_out
2 x chip_in
3 x chip_out

In [267]:
text = 'fluorescence removed'
log.append([time.ctime(time.time()), text])

In [269]:
text = 'CLOSE inlet_out'
manifold.pressurize(0)
log.append([time.ctime(time.time()), text])

text = 'OPEN chip_in, chip_out'
manifold.depressurize(14)
manifold.depressurize(8)
log.append([time.ctime(time.time()), text])

valve_states()


Out[269]:
0 1
0 o inlet_in
1 x inlet_out
2 o chip_in
3 o chip_out

In [271]:
text = 'flush'
log.append([time.ctime(time.time()), text])
manifold.pressurize(8)

In [273]:
for i in [2,0,14,8]:
    manifold.pressurize(i)

ACQUISITION


In [272]:
log


Out[272]:
[['Wed May 17 16:03:01 2017', 'open inlet_in, inlet_out'],
 ['Wed May 17 16:10:00 2017', 'fluorescence observed'],
 ['Wed May 17 16:15:41 2017', 'CLOSE inlet_out'],
 ['Wed May 17 16:15:41 2017', 'OPEN chip_in, chip_out'],
 ['Wed May 17 16:18:20 2017', 'fill'],
 ['Wed May 17 16:44:40 2017', 'open inlet_in, inlet_out'],
 ['Wed May 17 16:54:24 2017', 'fluorescence removed'],
 ['Wed May 17 16:55:53 2017', 'CLOSE inlet_out'],
 ['Wed May 17 16:55:53 2017', 'OPEN chip_in, chip_out'],
 ['Wed May 17 16:59:20 2017', 'flush']]

In [3]:
core.setConfig('Channel','2_BF')

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

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



In [8]:
position_list = ut.load_mm_positionlist("C:/Users/fordycelab/Desktop/D1_cjm.pos")
position_list


Out[8]:
r c name x y
0 0 0 1-Pos_000_000 -16212.71272 -19875.62168
1 0 1 1-Pos_001_000 -13894.29480 -19875.62168
2 0 2 1-Pos_002_000 -11575.87688 -19875.62168
3 0 3 1-Pos_003_000 -9257.45896 -19875.62168
4 0 4 1-Pos_004_000 -6939.04104 -19875.62168
5 0 5 1-Pos_005_000 -4620.62312 -19875.62168
6 0 6 1-Pos_006_000 -2302.20520 -19875.62168
7 0 7 1-Pos_007_000 16.21272 -19875.62168
8 1 7 1-Pos_007_001 16.21272 -17557.20376
9 1 6 1-Pos_006_001 -2302.20520 -17557.20376
10 1 5 1-Pos_005_001 -4620.62312 -17557.20376
11 1 4 1-Pos_004_001 -6939.04104 -17557.20376
12 1 3 1-Pos_003_001 -9257.45896 -17557.20376
13 1 2 1-Pos_002_001 -11575.87688 -17557.20376
14 1 1 1-Pos_001_001 -13894.29480 -17557.20376
15 1 0 1-Pos_000_001 -16212.71272 -17557.20376
16 2 0 1-Pos_000_002 -16212.71272 -15238.78584
17 2 1 1-Pos_001_002 -13894.29480 -15238.78584
18 2 2 1-Pos_002_002 -11575.87688 -15238.78584
19 2 3 1-Pos_003_002 -9257.45896 -15238.78584
20 2 4 1-Pos_004_002 -6939.04104 -15238.78584
21 2 5 1-Pos_005_002 -4620.62312 -15238.78584
22 2 6 1-Pos_006_002 -2302.20520 -15238.78584
23 2 7 1-Pos_007_002 16.21272 -15238.78584
24 3 7 1-Pos_007_003 16.21272 -12920.36792
25 3 6 1-Pos_006_003 -2302.20520 -12920.36792
26 3 5 1-Pos_005_003 -4620.62312 -12920.36792
27 3 4 1-Pos_004_003 -6939.04104 -12920.36792
28 3 3 1-Pos_003_003 -9257.45896 -12920.36792
29 3 2 1-Pos_002_003 -11575.87688 -12920.36792
... ... ... ... ... ...
42 5 5 1-Pos_005_005 -4620.62312 -8283.53208
43 5 4 1-Pos_004_005 -6939.04104 -8283.53208
44 5 3 1-Pos_003_005 -9257.45896 -8283.53208
45 5 2 1-Pos_002_005 -11575.87688 -8283.53208
46 5 1 1-Pos_001_005 -13894.29480 -8283.53208
47 5 0 1-Pos_000_005 -16212.71272 -8283.53208
48 6 0 1-Pos_000_006 -16212.71272 -5965.11416
49 6 1 1-Pos_001_006 -13894.29480 -5965.11416
50 6 2 1-Pos_002_006 -11575.87688 -5965.11416
51 6 3 1-Pos_003_006 -9257.45896 -5965.11416
52 6 4 1-Pos_004_006 -6939.04104 -5965.11416
53 6 5 1-Pos_005_006 -4620.62312 -5965.11416
54 6 6 1-Pos_006_006 -2302.20520 -5965.11416
55 6 7 1-Pos_007_006 16.21272 -5965.11416
56 7 7 1-Pos_007_007 16.21272 -3646.69624
57 7 6 1-Pos_006_007 -2302.20520 -3646.69624
58 7 5 1-Pos_005_007 -4620.62312 -3646.69624
59 7 4 1-Pos_004_007 -6939.04104 -3646.69624
60 7 3 1-Pos_003_007 -9257.45896 -3646.69624
61 7 2 1-Pos_002_007 -11575.87688 -3646.69624
62 7 1 1-Pos_001_007 -13894.29480 -3646.69624
63 7 0 1-Pos_000_007 -16212.71272 -3646.69624
64 8 0 1-Pos_000_008 -16212.71272 -1328.27832
65 8 1 1-Pos_001_008 -13894.29480 -1328.27832
66 8 2 1-Pos_002_008 -11575.87688 -1328.27832
67 8 3 1-Pos_003_008 -9257.45896 -1328.27832
68 8 4 1-Pos_004_008 -6939.04104 -1328.27832
69 8 5 1-Pos_005_008 -4620.62312 -1328.27832
70 8 6 1-Pos_006_008 -2302.20520 -1328.27832
71 8 7 1-Pos_007_008 16.21272 -1328.27832

72 rows × 5 columns


In [18]:
def acquire():
    for i in xrange(len(position_list)):
        si = str(i)
        x,y = position_list[['x','y']].iloc[i]
        core.setXYPosition(x,y)
        core.waitForDevice(core.getXYStageDevice())
        logadd(log, 'moved '+si)
        
        core.snapImage()
#         core.waitForDevice(core.getCameraDevice())
        logadd(log, 'snapped '+si)
        
        img = core.getImage()
        logadd(log, 'got image '+si)
        
        image = Image.fromarray(img)
        image.save('images/images_{}.tif'.format(i))
        logadd(log, 'saved image '+si)
    
    x,y = position_list[['x','y']].iloc[0]
    core.setXYPosition(x,y)
    core.waitForDevice(core.getXYStageDevice())
    logadd(log, 'moved '+ str(0))
        
def logadd(log,st):
    log.append([time.ctime(time.time()), st])
    print log[-1]

In [ ]:
# Auto
core.setAutoShutter(True) # default
core.snapImage()

# Manual
core.setAutoShutter(False) # disable auto shutter
core.setProperty("Shutter", "State", "1")
core.waitForDevice("Shutter")
core.snapImage()
core.setProperty("Shutter", "State", "0")

MM Get info


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

Video


In [5]:
import cv2
from IPython import display
import numpy as np
from ipywidgets import widgets
import time

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

In [ ]:
cv2.WND

In [6]:
# video with button (CV2)
live = widgets.Button(description='Live')
close = widgets.Button(description='Close')
display.display(widgets.HBox([live, close]))
 
def on_live_clicked(b):
    display.clear_output(wait=True)
    print 'LIVE'
    core.startContinuousSequenceAcquisition(1000) # time overridden by exposure
    time.sleep(.2)
    cv2.namedWindow('Video', cv2.WINDOW_NORMAL)
    cv2.setWindowProperty('Video', cv2.WND_PROP_ASPECT_RATIO, cv2.WINDOW_KEEPRATIO)
    cv2.resizeWindow('Video', 500,500)
    img = np.zeros((500,500))
    print 'To stop, click window + press ESC'
    while(1):
        time.sleep(.015)
        if core.getRemainingImageCount() > 0:
            img = core.getLastImage()
        cv2.imshow('Video',img)
        k = cv2.waitKey(30)
        if k==27: # ESC key; may need 255 mask?
            break
    print 'STOPPED'
    core.stopSequenceAcquisition()

def on_close_clicked(b):
    if core.isSequenceRunning():
        core.stopSequenceAcquisition()
    cv2.destroyWindow('Video')
        
live.on_click(on_live_clicked)
close.on_click(on_close_clicked)


LIVE
To stop, click window + press ESC
STOPPED

In [23]:
# video with button (CV2)
# serial snap image
live = widgets.Button(description='Live')
close = widgets.Button(description='Close')
display.display(widgets.HBox([live, close]))
 
def on_live_clicked(b):
    display.clear_output(wait=True)
    print 'LIVE'
    cv2.namedWindow('Video', cv2.WINDOW_NORMAL)
    cv2.setWindowProperty('Video', cv2.WND_PROP_ASPECT_RATIO, cv2.WINDOW_KEEPRATIO)
    cv2.resizeWindow('Video', 500,500)
    img = np.zeros((500,500))
    print 'To stop, click window + press ESC'
    while(1):
        core.snapImage()
        time.sleep(.05)
        img = core.getImage()
        cv2.imshow('Video',img)
        k = cv2.waitKey(30)
        if k==27: # ESC key; may need 255 mask?
            break
    print 'STOPPED'

def on_close_clicked(b):
    if core.isSequenceRunning():
        core.stopSequenceAcquisition()
    cv2.destroyWindow('Video')
        
live.on_click(on_live_clicked)
close.on_click(on_close_clicked)


LIVE
To stop, click window + press ESC
STOPPED

In [20]:
cv2.destroyAllWindows()

SNAP CV2


In [59]:
# snap (CV2)
snap = widgets.Button(description='Snap')
close2 = widgets.Button(description='Close')
display.display(widgets.HBox([snap, close2]))
                
def on_snap_clicked(b):
    cv2.destroyWindow('Snap')
    cv2.namedWindow('Snap',cv2.WINDOW_NORMAL)
    cv2.resizeWindow('Snap', 500,500)
    cv2.setWindowProperty('Snap', cv2.WND_PROP_ASPECT_RATIO, cv2.WINDOW_KEEPRATIO)
    core.snapImage()
    time.sleep(.1)
    img = core.getImage()
    cv2.imshow('Snap',img)
    k = cv2.waitKey(30)
    
def on_close2_clicked(b):
    cv2.destroyWindow('Snap')
        
snap.on_click(on_snap_clicked)
close2.on_click(on_close2_clicked)

EXIT


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


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-2-4643479af5c5> in <module>()
      1 # autosipper.exit()
----> 2 manifold.exit()
      3 core.unloadAllDevices()
      4 core.reset()
      5 print 'closed'

NameError: name 'manifold' is not defined

In [ ]: