<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
https
Step1:  Preset
Step2:  Example
Step3:  Example
Step4:  Example
Step5:  Example
Step6:  Example
<ASSISTANT_TASK:>
Python Code:
# !!!! Also need to add MM folder to 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
import time
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
core = MMCorePy.CMMCore()
core.loadSystemConfiguration(cfg)
core.initializeCircularBuffer()
core.setCircularBufferMemoryFootprint(4096) # MiB 
core.setProperty(core.getCameraDevice(), "Exposure", 300)
core.setProperty("Spectra", "White_Enable", "1")
core.waitForDevice("Spectra")
# NEED TO SET CAMERA TO 16 BIT (ceiling 12 BIT = 4096)
core.setProperty("Cam Andor_Zyla4.2", "Sensitivity/DynamicRange", "16-bit (low noise & high well capacity)")
Explanation: Setup
https://github.com/radioxoma/micromanager-samples/blob/master/mm_live_video.py
https://micro-manager.org/wiki/Using_the_Micro-Manager_python_library#Using_Python_API
https://micro-manager.org/wiki/Micro-Manager_Programming_Guide#Other
http://micro-manager.3463995.n2.nabble.com/Cannot-add-Andor-SDK3-device-to-configuration-td7583283.html
https://sourceforge.net/p/micro-manager/mailman/message/34388695/
Main
https://micro-manager.org/wiki/Micro-Manager_Programming_Guide 
https://valelab4.ucsf.edu/~MM/doc/MMCore/html/class_c_m_m_core.html
End of explanation
core.setConfig('Channel','1_PBP')
core.snapImage()
img = core.getImage()
plt.imshow(img,cmap='gray')
image = Image.fromarray(img)
image.save('TESTIMAGE.tif')
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))
core.unloadAllDevices()
core.reset()
print 'closed'
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
End of explanation
core.getFocusDevice()
core.getCameraDevice()
core.XYStageDevice()
core.getDevicePropertyNames(core.getCameraDevice())
Explanation: Example: Get info
End of explanation
# SHUTTER
# Auto
core.setAutoShutter(True)
core.snapImage()
# Manual
core.setAutoShutter(False) # disable auto shutter
core.setProperty("Shutter", "State", "1")
core.waitForDevice("Shutter")
core.snapImage()
core.setProperty("Shutter", "State", "0")
Explanation: Example: Shutter control
End of explanation
# cv2.startWindowThread()
cv2.namedWindow('Video')
cv2.imshow('Video',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
core.stopSequenceAcquisition()
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()
Explanation: Example: Video
End of explanation
core.enableStderrLog(True)
core.enableDebugLog(True)
Explanation: Example: Logging
End of explanation
## load devices
core.loadDevice("Camera", "DemoCamera", "DCam")
core.loadDevice("Emission", "DemoCamera", "DWheel")
core.loadDevice("Excitation", "DemoCamera", "DWheel")
core.loadDevice("Dichroic", "DemoCamera", "DWheel")
core.loadDevice("Objective", "DemoCamera", "DObjective")
core.loadDevice("X", "DemoCamera", "DStage")
core.loadDevice("Y", "DemoCamera", "DStage")
core.loadDevice("Z", "DemoCamera", "DStage")
core.initializeAllDevices()
## set labels for state devices
# emission filter
core.defineStateLabel("Emission", 0, "Chroma-D460")
core.defineStateLabel("Emission", 1, "Chroma-HQ620")
core.defineStateLabel("Emission", 2, "Chroma-HQ535")
core.defineStateLabel("Emission", 3, "Chroma-HQ700")
# excitation filter
core.defineStateLabel("Excitation", 2, "Chroma-D360")
core.defineStateLabel("Excitation", 3, "Chroma-HQ480")
core.defineStateLabel("Excitation", 4, "Chroma-HQ570")
core.defineStateLabel("Excitation", 5, "Chroma-HQ620")
# excitation dichroic
core.defineStateLabel("Dichroic", 0, "400DCLP")
core.defineStateLabel("Dichroic", 1, "Q505LP")
core.defineStateLabel("Dichroic", 2, "Q585LP")
# objective
core.defineStateLabel("Objective", 1, "Nikon 10X S Fluor")
core.defineStateLabel("Objective", 3, "Nikon 20X Plan Fluor ELWD")
core.defineStateLabel("Objective", 5, "Zeiss 4X Plan Apo")
## define configurations
core.defineConfiguration("FITC", "Emission", "State", "2")
core.defineConfiguration("FITC", "Excitation", "State", "3")
core.defineConfiguration("FITC", "Dichroic", "State", "1")
core.defineConfiguration("DAPI", "Emission", "State", "1")
core.defineConfiguration("DAPI", "Excitation", "State", "2")
core.defineConfiguration("DAPI", "Dichroic", "State", "0")
core.defineConfiguration("Rhodamine", "Emission", "State", "3")
core.defineConfiguration("Rhodamine", "Excitation", "State", "4")
core.defineConfiguration("Rhodamine", "Dichroic", "State", "2")
## set initial imaging mode
core.setProperty("Camera", "Exposure", "55")
core.setProperty("Objective", "Label", "Nikon 10X S Fluor")
core.setConfiguration("DAPI")
Explanation: Example: Config, programmatic
End of explanation
<END_TASK>