In [3]:
import time
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
%matplotlib inline
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
Out[2]:
In [3]:
from config import gui
gui.stage_control(autosipper.XY, autosipper.Z)
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]:
In [ ]:
ut.lookup(platemap)
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]:
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]:
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()
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
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]:
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]:
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]:
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]:
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)
In [272]:
log
Out[272]:
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]:
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")
In [ ]:
core.getFocusDevice()
core.getCameraDevice()
core.XYStageDevice()
core.getDevicePropertyNames(core.getCameraDevice())
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)
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)
In [20]:
cv2.destroyAllWindows()
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)
In [2]:
autosipper.exit()
manifold.exit()
core.unloadAllDevices()
core.reset()
print 'closed'
In [ ]: