<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 SETUP
Step1:  Autosipper
Step2:  Manifold
Step3:  Micromanager
Step4:  Preset
Step5:  first attempt above
Step6:  EXIT
<ASSISTANT_TASK:>
Python Code:
import time
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import os
from config import utils as ut
%matplotlib inline
Explanation: SETUP
End of explanation
# config directory must have "__init__.py" file
# from the 'config' directory, import the following classes:
from config import Motor, ASI_Controller, Autosipper
autosipper = Autosipper(Motor('config/motor.yaml'), ASI_Controller('config/asi_controller.yaml'))
autosipper.coord_frames
from config import gui
gui.stage_control(autosipper.XY, autosipper.Z)
platemap = ut.generate_position_table((8,12),(9,9),95.0)
platemap['x'] = -platemap['x'] - 1.8792
platemap['y'] = platemap['y'] + 32.45
platemap.loc[platemap.shape[0]] = [96, 99, 99, 99, 'W01', -8.2492, 1.1709, 68.3999]
platemap.loc[platemap.shape[0]] = [97, 99, 99, 99, 'W02', -36.9737, 1.1709, 68.3999]
platemap['contents'] = ["" for i in range(len(platemap['name']))]
for i in range(10):
    platemap['contents'].iloc[36+i] = "conc"+str(i)
autosipper.coord_frames.hardware.position_table = platemap
platemap
autosipper.go_to('hardware', 'name', 'B01')
Explanation: Autosipper
End of explanation
from config import Manifold
from config.gui import manifold_control
manifold = Manifold('192.168.1.3', 'config/valvemaps/valvemap.csv', 512)
manifold.valvemap[manifold.valvemap.name>0]
manifold_control(manifold)
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)
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, '')
name = 'inlet_in'
v = manifold.valvemap['valve'][manifold.valvemap.name==name]
v=14
manifold.depressurize(v)
manifold.pressurize(v)
manifold.exit()
Explanation: Manifold
End of explanation
# !!!! Also must have MM folder on system PATH
# mm_version = 'C:\Micro-Manager-1.4'
# cfg = 'C:\Micro-Manager-1.4\SetupNumber2_01282017.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)
Explanation: Micromanager
End of explanation
core.setProperty(core.getCameraDevice(), "Exposure", 125)
core.setConfig('Channel','4_eGFP')
core.setProperty(core.getCameraDevice(), "Binning", "3x3")
position_list = ut.load_mm_positionlist("Z:/Data/Setup 2/Arjun/170609_FlippedMITOMI/170609_mwm.pos")
position_list
# ONE ACQUISITION / SCAN
def scan(channel, exposure, washtype, plate_n):
    core.setConfig('Channel', channel)
    core.setProperty(core.getCameraDevice(), "Exposure", exposure)
    time.sleep(.2)
    
    timestamp = time.strftime("%Y%m%d-%H%M%S", time.localtime())
    rootdirectory = "Z:/Data/Setup 2/Arjun/170609_FlippedMITOMI/"
    solution = autosipper.coord_frames.hardware.position_table.contents.iloc[plate_n]
    scandirectory = '{}_{}_{}_{}_{}'.format(timestamp, solution, washtype, channel, exposure)
    os.makedirs(rootdirectory+scandirectory)
    
    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())
        
        core.snapImage()
        img = core.getImage()
        image = Image.fromarray(img)
        
        timestamp = time.strftime("%Y%m%d-%H%M%S", time.localtime())
        positionname = position_list['name'].iloc[i]
        image.save('{}/{}_{}.tif'.format(rootdirectory+scandirectory, timestamp, positionname))
    x,y = position_list[['x','y']].iloc[0]
    core.setXYPosition(x,y)
    core.waitForDevice(core.getXYStageDevice())
def get_valve(name):
    return ut.lookup(manifold.valvemap,'name',name,'valve',0)[0]
scan('4_eGFP', 125, 'pre')
# PUT PINS IN ALL INPUTS
# in0 WASTE LINE
# in1 WASH LINE, 4.5 PSI
# in2 PEEK LINE, 4.5 PSI
#----------------------------------
# initialize valve states
## all inputs close
## sandwhich
# prime inlet tree (wash)
manifold.depressurize(get_valve('bBSA_2'))  ## wash open
manifold.depressurize(get_valve('Waste_2')) ## waste open
time.sleep(60*0.5)                          ## wait 0.5 min
manifold.pressurize(get_valve('Waste_2'))   ## waste close
# backflush tubing (wash)
autosipper.go_to('hardware', 'name', 'W02', zh_travel=40) ## W02 move
manifold.depressurize(get_valve('NA_2'))                  ## inlet open
time.sleep(60*11)                                         ## wait 11 min
manifold.pressurize(get_valve('NA_2'))                    ## inlet close
# fill chip (wash)
## chip_in open
## chip_out open
## wait 10 min
## chip_out close
## wait 10 min
# prime tubing (1st input)
manifold.pressurize(get_valve('Out_2'))                   # chip_out close
manifold.pressurize(get_valve('In_2'))                    # chip_in close
autosipper.go_to('hardware', 'name', 'W01', zh_travel=40)
autosipper.go_to('hardware', 'n', 36, zh_travel=40)
manifold.depressurize(get_valve('NA_2'))                  # inlet open
manifold.depressurize(get_valve('Waste_2'))               # waste open
time.sleep(60*11)                                         # filling inlet, 11 min...
manifold.pressurize(get_valve('Waste_2'))                 # waste close
Explanation: 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
ACQUISITION
End of explanation
# prime inlet tree (wash)
manifold.depressurize(get_valve('bBSA_2'))  ## wash open
manifold.depressurize(get_valve('Waste_2')) ## waste open
time.sleep(60*0.5)                          ## wait 0.5 min
manifold.pressurize(get_valve('Waste_2'))   ## waste close
# backflush tubing (wash)
autosipper.go_to('hardware', 'name', 'W02', zh_travel=40) ## W02 move
manifold.depressurize(get_valve('NA_2'))                  ## inlet open
time.sleep(60*15)                                         ## wait 15 min
manifold.pressurize(get_valve('NA_2'))                    ## inlet close
manifold.pressurize(get_valve('bBSA_2'))                  ## wash close
# prime tubing (1st input)
manifold.pressurize(get_valve('Out_2'))                   # chip_out close
manifold.pressurize(get_valve('In_2'))                    # chip_in close
autosipper.go_to('hardware', 'name', 'W01', zh_travel=40)
autosipper.go_to('hardware', 'n', 36, zh_travel=40)
manifold.depressurize(get_valve('NA_2'))                  # inlet open
manifold.depressurize(get_valve('Waste_2'))               # waste open
time.sleep(60*15)                                         # filling inlet, 15 min...
manifold.pressurize(get_valve('Waste_2'))                 # waste close
# 16,Waste_2
# 17,bBSA_2
# 18,NA_2
# 19,antibody_2
# 20,Extra1_2
# 21,Extra2_2
# 22,Protein_2
# 23,Wash_2
exposures = [1250,1250,1250,1250,1000,600,300,180,70,30]
for i,exposure in enumerate(exposures):
    plate_n = 36+i
    
    # flow on chip
    manifold.depressurize(get_valve('NA_2')) # inlet open
    manifold.depressurize(get_valve('In_2')) # chip_in open
    manifold.depressurize(get_valve('Out_2')) # chip_out open
    time.sleep(60*10) # filling chip, 10 min...
    
    # CONCURRENTLY:
    incubate_time = 60*30 # 30 min
    
    # a) incubate DNA with protein
    manifold.pressurize(get_valve('Sandwich1_2')) # sandwhiches close
    manifold.pressurize(get_valve('Sandwich2_2')) # "
    time.sleep(1) # pause
    manifold.depressurize(get_valve('Button1_2')) # buttons open
    manifold.depressurize(get_valve('Button2_2')) # "
    incubate_start = time.time()
    
    # b1) prime inlet tube with next INPUT
    manifold.pressurize(get_valve('Out_2')) # chip_out close
    manifold.pressurize(get_valve('In_2')) # chip_in close
    manifold.pressurize(get_valve('NA_2')) # inlet close
    autosipper.go_to('hardware', 'name', 'W01', zh_travel=40)
    autosipper.go_to('hardware', 'n', plate_n+1, zh_travel=40)
    manifold.depressurize(get_valve('NA_2')) # inlet open
    manifold.depressurize(get_valve('Waste_2')) # waste open
    time.sleep(60*15) # filling inlet, 15 min...
    
    manifold.pressurize(get_valve('NA_2')) # inlet close
    # b2) prime inlet tree with wash
    manifold.depressurize(get_valve('bBSA_2')) # wash open
    manifold.pressurize(get_valve('Waste_2')) # waste close
    
    for v in [19,20,21,22,23]:
        manifold.depressurize(v)
        time.sleep(.2)
        manifold.pressurize(v)
    
    manifold.depressurize(get_valve('Waste_2')) # waste open
    time.sleep(60*1)
    manifold.pressurize(get_valve('Waste_2')) # waste close
    remaining_time = incubate_time - (time.time() - incubate_start)
    time.sleep(remaining_time)    
    
    # prewash Cy5
    scan('5_Cy5', exposure, 'pre', plate_n)
    
    # wash
    manifold.pressurize(get_valve('Button1_2')) # buttons close
    manifold.pressurize(get_valve('Button2_2')) # "
    time.sleep(1) # pause
    manifold.depressurize(get_valve('Sandwich1_2')) # sandwhiches open
    manifold.depressurize(get_valve('Sandwich2_2')) # "
        
    manifold.depressurize(get_valve('In_2')) # chip_in open
    manifold.depressurize(get_valve('Out_2')) # chip_out open
    time.sleep(60*10) # washing chip, 10 min...
    
    manifold.pressurize(get_valve('Out_2')) # chip_out close
    manifold.pressurize(get_valve('In_2')) # chip_in close
    manifold.pressurize(get_valve('bBSA_2')) # wash close
    # postwash eGFP and postwash Cy5
    scan('4_eGFP', 125, 'post', plate_n)
    scan('5_Cy5', 1250, 'post', plate_n)
autosipper.go_to('hardware', 'n', 47, zh_travel=40) 
# prewash Cy5
scan('5_Cy5', exposure, 'pre', plate_n)
# wash
manifold.pressurize(get_valve('Button1_2')) # buttons close
manifold.pressurize(get_valve('Button2_2')) # "
time.sleep(1) # pause
manifold.depressurize(get_valve('Sandwich1_2')) # sandwhiches open
manifold.depressurize(get_valve('Sandwich2_2')) # "
manifold.depressurize(get_valve('In_2')) # chip_in open
manifold.depressurize(get_valve('Out_2')) # chip_out open
time.sleep(60*10) # washing chip, 10 min...
manifold.pressurize(get_valve('Out_2')) # chip_out close
manifold.pressurize(get_valve('In_2')) # chip_in close
manifold.pressurize(get_valve('bBSA_2')) # wash close
# postwash eGFP and postwash Cy5
scan('4_eGFP', 125, 'post', plate_n)
scan('5_Cy5', 1250, 'post', plate_n)
exposures = [1250,1250,1250,1250,1000,600,300,180,70,30]
for i, exposure in enumerate(exposures):
    if i==0:
        continue
    
    plate_n = 36+i
    
    # flow on chip
    manifold.depressurize(get_valve('NA_2')) # inlet open
    manifold.depressurize(get_valve('In_2')) # chip_in open
    manifold.depressurize(get_valve('Out_2')) # chip_out open
    time.sleep(60*10) # filling chip, 10 min...
    
    # CONCURRENTLY:
    incubate_time = 60*30 # 30 min
    
    # a) incubate DNA with protein
    manifold.pressurize(get_valve('Sandwich1_2')) # sandwhiches close
    manifold.pressurize(get_valve('Sandwich2_2')) # "
    time.sleep(1) # pause
    manifold.depressurize(get_valve('Button1_2')) # buttons open
    manifold.depressurize(get_valve('Button2_2')) # "
    incubate_start = time.time()
    
    # b1) prime inlet tube with next INPUT
    manifold.pressurize(get_valve('Out_2')) # chip_out close
    manifold.pressurize(get_valve('In_2')) # chip_in close
    manifold.pressurize(get_valve('NA_2')) # inlet close
    autosipper.go_to('hardware', 'name', 'W01', zh_travel=40)
    autosipper.go_to('hardware', 'n', plate_n+1, zh_travel=40)
    manifold.depressurize(get_valve('NA_2')) # inlet open
    manifold.depressurize(get_valve('Waste_2')) # waste open
    time.sleep(60*15) # filling inlet, 15 min...
    
    manifold.pressurize(get_valve('NA_2')) # inlet close
    # b2) prime inlet tree with wash
    manifold.depressurize(get_valve('bBSA_2')) # wash open
    manifold.pressurize(get_valve('Waste_2')) # waste close
    
    for v in [19,20,21,22,23]:
        manifold.depressurize(v)
        time.sleep(.2)
        manifold.pressurize(v)
    
    manifold.depressurize(get_valve('Waste_2')) # waste open
    time.sleep(60*1)
    manifold.pressurize(get_valve('Waste_2')) # waste close
    remaining_time = incubate_time - (time.time() - incubate_start)
    time.sleep(remaining_time)    
    
    # prewash Cy5
    scan('5_Cy5', exposure, 'pre', plate_n)
    
    # wash
    manifold.pressurize(get_valve('Button1_2')) # buttons close
    manifold.pressurize(get_valve('Button2_2')) # "
    time.sleep(1) # pause
    manifold.depressurize(get_valve('Sandwich1_2')) # sandwhiches open
    manifold.depressurize(get_valve('Sandwich2_2')) # "
        
    manifold.depressurize(get_valve('In_2')) # chip_in open
    manifold.depressurize(get_valve('Out_2')) # chip_out open
    time.sleep(60*10) # washing chip, 10 min...
    
    manifold.pressurize(get_valve('Out_2')) # chip_out close
    manifold.pressurize(get_valve('In_2')) # chip_in close
    manifold.pressurize(get_valve('bBSA_2')) # wash close
    # postwash eGFP and postwash Cy5
    scan('4_eGFP', 125, 'post', plate_n)
    scan('5_Cy5', 1250, 'post', plate_n)
Explanation: first attempt above: forgot to close wash after backflush
End of explanation
autosipper.exit()
manifold.exit()
core.unloadAllDevices()
core.reset()
print 'closed'
Explanation: EXIT
End of explanation
<END_TASK>