Beispiel #1
0
 def __init__(self):
     sys.path.append(os.path.dirname(__file__))
     from asdk import DM
     super(MirrorControllerPython,self).__init__()        
     self.mirror_id = ccfg.mirror_id
     #self.dm = DM(os.path.join(ccfg.dm_directory,self.mirror_id))
     self.dm = DM(self.mirror_id)
     
     n_actuators_queried = int( self.dm.Get('NBOfActuator') )
     try:
         assert n_actuators_queried==ccfg.mirror_n_actuators
     except AssertionError as ae:
         print 'Number of actuator disagreement.'
     self.command[:] = 0.0 # this doesn't really matter
Beispiel #2
0
    def __init__(self,):
        self.seri_num = "BOL115"
        self.alpao   = DM(self.seri_num)
        self.nba     = int(alpao.Get('NBOfActuator'))
        self.alpao.Send([0.] * nbAct)  # init the DM: zeroes everywhere
        self.dms     = 11              # DM size
        dms = self.dms
        xdm, ydm     = np.meshgrid(np.arange(dms)-dms/2, np.arange(dms)-dms/2)
        self.xdm     = xdm.T.astype('float32')
        self.ydm     = ydm.T.astype('float32')
        self.dmmask  = np.ones((dms, dms), dtype=np.int) # corner mask
        self.dmmask[np.abs(self.xdm) + np.abs(self.ydm) > 7] = 0.0
        self.flat_mask = self.dmmask.flatten()

        self.nch   = 8 # number of DM channels
        self.dmd0  = np.zeros((dms,dms), dtype=np.float32)
        self.cntrs = np.zeros(self.nch+1) - 1 # shared mem counters for channels

        for ii in range(self.nch):
            exec "disp%d = shm(fname='/tmp/dmdisp%d.im.shm', data=self.dmd0, verbose=False)" % (ii,ii)
Beispiel #3
0
    def __init__(self,parent=None):
        super(scope, self).__init__()
        self.delay = 0.02 # delay in loops (StackExt)
        self.handleA = None
        self.handleB = None
        self.QUIT = False
        self.stackparams = {'Date/Time':0,'X':0,'Y':0,'Z1':0,'Z2':0,'Zstep':0,'Exposure(s)':0,'CCD Temperature':0,'Pixel Size(nm)':89,'CCD setting':'','User':''}
        # camera
        self.ccd = pyAndor_P271_slm.ccd()
        self.ccd.CoolerON()
        self.ccd.SetCoolerMode(COOLER_MODE)
        self.ccd.SetTemperature(TEMPERATURE_SETPOINT)
        self.data = N.zeros(self.ccd.image_size, dtype=N.uint16)
        # piezo
        self.zst = zstage.zstage()
        self.zst.setPositionf(50)
        self.zpos = 0
        # Filter wheel
        self.fw = filterWheel.filter_wheel()
        # deformable mirror
        self.serialName = 'BAX228'
        self.dm = DM( self.serialName )
        self.nbAct = int( self.dm.Get('NBOfActuator') )
#        self.values = [0.] * self.nbAct
#        self.dm.Send( self.values )
        with open(FLAT_FILE, "r") as file:
            self.dmfile = eval(file.readline())
        if (all(i <= 1.0 for i in self.dmfile)):
            self.dm.Send(self.dmfile)
        else:
            raise Exception(' Error: push value greater than 1.0 ')
        #motorized polarizer
        print('Initializing Polarizer')
        self.pol = mp2.A8MRU()
        self.pol.MotorOn()
        self.pol.setSpeed(1000,1)
        self.pol_array = N.array([50.,20.,-10.]) #3D
        print(self.pol.getState())
        # priorxy
        self.prior = priorxyP27.prior()
        self.xpos = 0
        self.ypos = 0
        self.prior.limits=[-10000, 10000, -10000, 10000]
        # qxga
        qx.initiate()
        qx.open_usb_port()
        #Coherent 647 laser
        try:
            self.ll647 = Coherent_P33.obis('COM16')
            self.ll647.SetLaserOn()
            self.ll647.SetDigitalModMode()
        except:
            self.ll647 = None
            print('647nm Laser not on') #raise Exception('647nm Laser not on')
        #set save path        
        t=time.localtime()
        self.is_videomode = False
        dpth=str(int(t[0]*1e4+t[1]*1e2+t[2]))+'_'+getuser()
        self.path=os.path.join(datapath,dpth)
        try:
            os.mkdir(self.path)
        except:
            print('Directory already exists')
        # defaults
        self.coord=(200,400,200,400)
        self.Name='default'
        ###
        self.Name = 'default'
        self.coordVal = self.ccd.GetImageCoordinates()
        self.old_Cval = self.ccd.GetImageCoordinates()
        self.normal_mode = False
Beispiel #4
0
class scope(QThread):

    def __init__(self,parent=None):
        super(scope, self).__init__()
        self.delay = 0.02 # delay in loops (StackExt)
        self.handleA = None
        self.handleB = None
        self.QUIT = False
        self.stackparams = {'Date/Time':0,'X':0,'Y':0,'Z1':0,'Z2':0,'Zstep':0,'Exposure(s)':0,'CCD Temperature':0,'Pixel Size(nm)':89,'CCD setting':'','User':''}
        # camera
        self.ccd = pyAndor_P271_slm.ccd()
        self.ccd.CoolerON()
        self.ccd.SetCoolerMode(COOLER_MODE)
        self.ccd.SetTemperature(TEMPERATURE_SETPOINT)
        self.data = N.zeros(self.ccd.image_size, dtype=N.uint16)
        # piezo
        self.zst = zstage.zstage()
        self.zst.setPositionf(50)
        self.zpos = 0
        # Filter wheel
        self.fw = filterWheel.filter_wheel()
        # deformable mirror
        self.serialName = 'BAX228'
        self.dm = DM( self.serialName )
        self.nbAct = int( self.dm.Get('NBOfActuator') )
#        self.values = [0.] * self.nbAct
#        self.dm.Send( self.values )
        with open(FLAT_FILE, "r") as file:
            self.dmfile = eval(file.readline())
        if (all(i <= 1.0 for i in self.dmfile)):
            self.dm.Send(self.dmfile)
        else:
            raise Exception(' Error: push value greater than 1.0 ')
        #motorized polarizer
        print('Initializing Polarizer')
        self.pol = mp2.A8MRU()
        self.pol.MotorOn()
        self.pol.setSpeed(1000,1)
        self.pol_array = N.array([50.,20.,-10.]) #3D
        print(self.pol.getState())
        # priorxy
        self.prior = priorxyP27.prior()
        self.xpos = 0
        self.ypos = 0
        self.prior.limits=[-10000, 10000, -10000, 10000]
        # qxga
        qx.initiate()
        qx.open_usb_port()
        #Coherent 647 laser
        try:
            self.ll647 = Coherent_P33.obis('COM16')
            self.ll647.SetLaserOn()
            self.ll647.SetDigitalModMode()
        except:
            self.ll647 = None
            print('647nm Laser not on') #raise Exception('647nm Laser not on')
        #set save path        
        t=time.localtime()
        self.is_videomode = False
        dpth=str(int(t[0]*1e4+t[1]*1e2+t[2]))+'_'+getuser()
        self.path=os.path.join(datapath,dpth)
        try:
            os.mkdir(self.path)
        except:
            print('Directory already exists')
        # defaults
        self.coord=(200,400,200,400)
        self.Name='default'
        ###
        self.Name = 'default'
        self.coordVal = self.ccd.GetImageCoordinates()
        self.old_Cval = self.ccd.GetImageCoordinates()
        self.normal_mode = False
          
    def __del__(self):
        if (self.handleA != None):
            daq.CCDTrig_close(self.handleA,self.handleB)
        x = self.dm.Reset()
        if (x==0):
            print('DM Reset')
        else:
            print('DM cannot reset')
        qx.close()
#        self.dm.close()
#    
    def get_img(self):
        daq.CCDTrig_run(self.handleA,self.handleB)
        self.ccd.WaitForNewData()
        self.data[:,:] = self.ccd.images
        
    def open_Acq(self,exposure=0.1,emgain=200,laser=False,Rlaser=False,cntLaser=False,LED12=1,FTM=False,conv=False,ccd=True,trig=1,regen=False):
        # setup camera
        self.ccd.SetTriggerMode(trig) #0:internal, 1:External
        self.ccd.SetShutterMode(2) #auto
        self.ccd.SetReadMode(4) #image
        self.ccd.SetADChannel(0) # 14-bit channel
        self.ccd.SetOutputAmplifier(int(conv))
        self.ccd.SetHSSpeed(0)
        self.ccd.SetEMCCDGain(emgain)
        if FTM: # Frame transfer mode
            self.ccd.SetExposureTime(0)
            self.ccd.SetFrameTransferMode(1)
            self.ccd.SetAcquisitionMode(7) # run until abort
        else:
            self.ccd.SetExposureTime(exposure)
            self.ccd.SetFrameTransferMode(0)
            self.ccd.SetAcquisitionMode(5) # run until abort
        q,w,e = self.ccd.GetAcquisitionTimings()
        # setup triggers
        if not self.handleA == None:
            daq.CCDTrig_close(self.handleA,self.handleB)
        if cntLaser:
            digsig = self.getTiming3(FREQ,1e3*exposure,1e3*exposure,1,laser,Rlaser,LED=LED12,CCD=ccd)
        elif regen:
            digsig = self.getTiming2(FREQ,1e3*exposure,1e3*exposure,1,laser,Rlaser,LED=LED12,CCD=ccd)
        else:
            digsig = self.getTiming(FREQ,1e3*exposure,1e3*exposure,1,laser,Rlaser,LED=LED12,CCD=ccd)
        b = daq.CCDTrig_open(FREQ,digsig)
        self.handleA = b[0]
        self.handleB = b[1]
        xs = self.ccd.image_size[0]
        ys = self.ccd.image_size[1]
        self.data = N.zeros((xs,ys), dtype=N.uint16)
        self.ccd.SetShutterMode(1)
        self.ccd.Acquire()
        #self.slm.SLM_on()
        print(q,w,e)
        return (q,w,e)
    
    def close_Acq(self):        
        self.ccd.AbortAcquisition()
        self.ccd.SetShutterMode(2)
        return True
        
    def run(self):
        self.is_videomode = True
        if (self.normal_mode==True):
            while (self.is_videomode):
                self.get_img()
                self.emit(SIGNAL('update'))
        else:
            while (self.is_videomode):
                #self.slm.show_next_patt()
#                psz = qx.getordernum()
                psz =15
                phs = int(psz/3)
                for m in range(3):
                    self.pol.MoveAbs(self.pol_array[m])
                    time.sleep(0.02)
                    for n in range(phs):
                        qx.selecteorder(m*phs+n)
                        qx.activate()
                        self.get_img()
                        self.emit(SIGNAL('update'))
                        qx.deactivate()
        self.ccd.AbortAcquisition()
        self.ccd.SetShutterMode(2)
        #self.slm.SLM_off()
        
############## External ######################################################

    def StackExt(self,start,stop,step=0.2,verbose=True):
        init_loc=self.zst.getPosition()
        no = int((stop-start)/step)+1
        pos = start
        xs = self.ccd.image_size[0]
        ys = self.ccd.image_size[1]
        self.data = N.zeros((no,xs,ys), N.uint16)
        self.ccd.SetShutterMode(1)
        q = self.ccd.Acquire()
        time.sleep(0.2) # was 0.05
        for p in range(no):
            self.zst.setPositionf(pos)
            daq.CCDTrig_run(self.handleA,self.handleB)
            q = self.ccd.WaitForNewData()
            print(p,q)
            self.data[p] = self.ccd.images
            pos += step
            time.sleep(self.delay)
        self.ccd.AbortAcquisition()
        self.ccd.SetShutterMode(2)
        if verbose:
            T.imshow(self.data, vmin=self.data.min(), vmax=self.data.max())
        cur_pos = self.prior.getPosition()
        self.stackTags(cur_pos[0],cur_pos[1],start,stop,step,function='Z-Stack')
        self.zst.setPositionf(init_loc)
        return True
        
    def Stack_Patterns(self,start,stop,step=0.2, verbose=True):
        rots = self.pol_array
        no = int((stop-start)/step)+1
        pos = start
        xs = self.ccd.image_size[0]
        ys = self.ccd.image_size[1]
#        psz = qx.getordernum()
        psz = 15
        phs = int(psz/3)
        self.data = N.zeros((psz*no,xs,ys), dtype=N.uint16)
#        self.slm.SLM_on()
        self.ccd.SetShutterMode(1)
        q = self.ccd.Acquire()
        time.sleep(0.1) # was 0.2,  changed 20141114
        for p in range(no):
            self.zst.setPositionf(pos)
            for w in range(3):
                self.pol.MoveAbs(rots[w])
                time.sleep(0.4)
                for m in range(phs):
                    #self.pr.setVoltage(rots[m])
                    qx.selecteorder(phs*w+m)
                    qx.activate()
                    time.sleep(0.02)
                    #print self.pr.getVoltage()
                    #self.dmd.set_image(patt)
                    #self.slm.show_next_patt()
                    #self.slm.show_patt(m)
                    daq.CCDTrig_run(self.handleA,self.handleB)
                    q = self.ccd.WaitForNewData()
                    print (p,q)
                    self.data[psz*p + 5*w + m] = self.ccd.images
                    qx.deactivate()
#                    time.sleep(0.02)
            pos += step
        self.ccd.AbortAcquisition()
        self.ccd.SetShutterMode(2)
#        self.slm.SLM_off()
        #self.pr.setVoltage(0.0)
        if verbose:
            T.imshow(self.data, vmin=self.data.min(), vmax=self.data.max())
        cur_pos = self.zst.getPosition()
        self.stackTags(cur_pos,start,stop,step,function='Z-Stack patterns')
        return True
        
    def Stack_Sectioning(self,start,stop,step=0.2, verbose=True):
        no = int((stop-start)/step)+1
        pos = start
        xs = self.ccd.image_size[0]
        ys = self.ccd.image_size[1]
#        psz = qx.getordernum()
        psz = 3
        self.data = N.zeros((psz*no,xs,ys), dtype=N.uint16)
        self.ccd.SetShutterMode(1)
        q = self.ccd.Acquire()
        self.pol.MoveAbs(0)
        time.sleep(0.4)
        for p in range(no):
            self.zst.setPositionf(pos)
            for m in range(psz):
                qx.selecteorder(15+m)
                qx.activate()
                time.sleep(0.02)
                daq.CCDTrig_run(self.handleA,self.handleB)
                q = self.ccd.WaitForNewData()
                print (p,q)
                self.data[psz*p + m] = self.ccd.images
                qx.deactivate()
                time.sleep(0.02)
            pos += step
        self.ccd.AbortAcquisition()
        self.ccd.SetShutterMode(2)
        if verbose:
            T.imshow(self.data, vmin=self.data.min(), vmax=self.data.max())
        cur_pos = self.zst.getPosition()
        self.stackTags(cur_pos,start,stop,step,function='Z-Stack patterns')
        return True

    def Image_Patterns(self, angle=0, no=200, pol=0, verbose=True):
        pos = self.zst.getPosition()
        xs = self.ccd.image_size[0]
        ys = self.ccd.image_size[1]
#        psz = self.slm.ni
        psz = 5
        self.data = N.zeros((psz*no,xs,ys), dtype=N.uint16)
#        self.slm.SLM_on()
        self.ccd.SetShutterMode(1)
        q = self.ccd.Acquire()
        time.sleep(0.01) # was 0.2,  changed 20141114
        self.zst.setPositionf(pos)
        for p in range(no):  
            for m in range(angle*5,psz+angle*5):
                #self.pr.setVoltage(rots[m])
                self.pol.MoveAbs(pol)
                qx.selecteorder(m)
                qx.activate()
                #time.sleep(.50)
                #print self.pr.getVoltage()
                #self.dmd.set_image(patt)
                #self.slm.show_next_patt()
#                self.slm.show_patt(m)
                daq.CCDTrig_run(self.handleA,self.handleB)
                q = self.ccd.WaitForNewData()
                print (p,q)
                self.data[psz*p+m%5] = self.ccd.images
                qx.deactivate()
                time.sleep(self.delay)
        self.ccd.AbortAcquisition()
        self.ccd.SetShutterMode(2)
#        self.slm.SLM_off()
        #self.pr.setVoltage(0.0)
        if verbose:
            T.imshow(self.data, vmin=self.data.min(), vmax=self.data.max())
        cur_pos = self.prior.getPosition()
        self.stackTags(cur_pos[0],cur_pos[1],function='Z-Stack patterns')
        return True
        
    def si_2d_pattern(self,start,stop,step=0.2, verbose=True):
        rots = self.pol_array
        no = int((stop-start)/step)+1
        pos = start
        xs = self.ccd.image_size[0]
        ys = self.ccd.image_size[1]
#        psz = qx.getordernum()
        psz = 9
        phs = int(psz/3)
        self.data = N.zeros((psz*no,xs,ys), dtype=N.uint16)
#        self.slm.SLM_on()
        self.ccd.SetShutterMode(1)
        q = self.ccd.Acquire()
        time.sleep(0.1) # was 0.2,  changed 20141114
        for p in range(no):
            self.zst.setPositionf(pos)
            for w in range(3):
                self.pol.MoveAbs(rots[w])
                time.sleep(0.8)
                for m in range(phs):
                    #self.pr.setVoltage(rots[m])
                    qx.selecteorder(19+phs*w+m)
                    qx.activate()
                    time.sleep(0.02)
                    #print self.pr.getVoltage()
                    #self.dmd.set_image(patt)
                    #self.slm.show_next_patt()
                    #self.slm.show_patt(m)
                    daq.CCDTrig_run(self.handleA,self.handleB)
                    q = self.ccd.WaitForNewData()
                    print (p,q)
                    self.data[psz*p + 5*w + m] = self.ccd.images
                    qx.deactivate()
#                    time.sleep(0.02)
            pos += step
        self.ccd.AbortAcquisition()
        self.ccd.SetShutterMode(2)
#        self.slm.SLM_off()
        #self.pr.setVoltage(0.0)
        if verbose:
            T.imshow(self.data, vmin=self.data.min(), vmax=self.data.max())
        cur_pos = self.zst.getPosition()
        self.stackTags(cur_pos,start,stop,step,function='Z-Stack patterns')
        return True        
        
    def setlaserpower(self,power):
        self.ll647.SetPowerLevel(power)
        out = self.ll647.GetPower()
        return out
    
    def singleSnapExt(self,verbose=True):
        xs = self.ccd.image_size[0]
        ys = self.ccd.image_size[1]
        self.data = N.zeros((xs,ys), dtype=N.uint16)
        self.ccd.SetShutterMode(1)
        self.ccd.Acquire()
        time.sleep(0.2) # was 0.05
        daq.CCDTrig_run(self.handleA,self.handleB)
        self.ccd.WaitForNewData()
        self.data[:,:] = self.ccd.images
        self.ccd.AbortAcquisition()
        self.ccd.SetShutterMode(2)
        if verbose:
            T.imshow(self.data, vmin=self.data.min(), vmax=self.data.max())
        cur_pos = self.prior.getPosition()
        self.stackTags(cur_pos[0],cur_pos[1],self.zst.getPosition(),0,0,function='Single snap')
        return True
        
    def setCCD_Conv_ext(self,exposure=0.100,laser=False,Rlaser=False,LED12=1):
        self.is_videMode = False
        # setup camera
        self.ccd.SetTriggerMode(1) #0: internal
        self.ccd.SetShutterMode(2) #0: auto
        self.ccd.SetFrameTransferMode(0)
        self.ccd.SetAcquisitionMode(5) # run until abort
        self.ccd.SetReadMode(4) #image
        self.ccd.SetADChannel(0) # 14-bit channel
        # this sets camera to 1.8us vs speed, and 3MHz readout which doesn't have a lot of pattern
        # to get rid of patterns entirely in conventional mode, go to 1Mhz readout
        self.ccd.SetVSSpeed(3)
        self.ccd.SetHSSpeed(0)
        self.ccd.SetOutputAmplifier(1)
        self.ccd.SetExposureTime(exposure)
        q,w,e = self.ccd.GetAcquisitionTimings()
        # setup triggers
        if not self.handleA == None:
            daq.CCDTrig_close(self.handleA,self.handleB)
        digsig = self.getTiming(FREQ,1e3*exposure,1e3*exposure,1,laser,Rlaser,LED=LED12)
        b = daq.CCDTrig_open(FREQ,digsig)
        self.handleA = b[0]
        self.handleB = b[1]
        return (q,w,e)

    def setCCD_EM_ext(self,exposure=0.1,emgain=200,laser=False,Rlaser=False,LED12=1):
        self.is_videMode = False
        # setup camera
        self.ccd.SetTriggerMode(1) #0:internal, 1:External
        self.ccd.SetShutterMode(2) #0: auto
        self.ccd.SetFrameTransferMode(0)
        self.ccd.SetAcquisitionMode(5) # run until abort
        self.ccd.SetReadMode(4) #image
        self.ccd.SetADChannel(0) # 14-bit channel
        self.ccd.SetOutputAmplifier(0)
        self.ccd.SetHSSpeed(0)
        self.ccd.SetEMCCDGain(emgain)
        self.ccd.SetExposureTime(exposure)
        q,w,e = self.ccd.GetAcquisitionTimings()
        # setup triggers
        if not self.handleA.value == 0:
            daq.CCDTrig_close(self.handleA,self.handleB)
        digsig = self.getTiming(FREQ,1e3*exposure,1e3*exposure,1,laser,Rlaser,LED=LED12)
        b = daq.CCDTrig_open(FREQ,digsig)
        self.handleA = b[0]
        self.handleB = b[1]
        return (q,w,e)
        
    def getTiming(self,freq,exposure,pulse,delay,laser=False,Rlaser=False,LED=1,CCD=True):
        ''' frequency is in Hertz, exposure and delay are in ms
            bit 1: CCD Trigger
            bit 2: LED pulse
            bit 3: Laser shutter
            bit 4: Red Laser
            bit 5: LED 1/2'''
        # laser shutter is active
        count = int(1.1*(exposure+delay)*0.001*freq)
        td = int(delay*0.001*freq)
        texp = int(exposure*0.001*freq)
        tpulse = int(pulse*0.001*freq)
        trigpulse = int(0.004*freq)
        p = range(count)
        laser_arr = N.zeros(count)
        led_arr = N.zeros(count)
        Rlaser_arr = N.zeros(count)
        if LED==1:
            LED12_arr = N.zeros(count)
        else:
            LED12_arr = N.ones(count)
        if laser:
            laser_arr = N.array([(i>td) & (i<(td+texp)) for i in p])
        elif Rlaser:
            Rlaser_arr = N.array([(i>td) & (i<(td+texp)) for i in p])
        else:
            led_arr = N.array([(i>td) & (i<(td+tpulse)) for i in p])
        if (CCD):
            ccdtrig = N.array([(i<=(trigpulse)) for i in p])
        else:
            ccdtrig = N.array([(0) for i in p])
        #out = N.add(N.add(1.*ccdtrig,2.*lha),4.*shutt2).astype(N.int)
##        out = (ccdtrig+2*led+4*laser).astype(N.int)
        out = (ccdtrig+2*led_arr+4*laser_arr+8*Rlaser_arr+16*LED12_arr).astype(N.int)
        return out
    
    def getTiming2(self,freq,exposure,pulse,delay,laser=False,Rlaser=False,LED=2,CCD=True):
        ''' Regen with every pulse with LED           
            exposure time is for laser, followed by pulse time that is for LED.
            '''
        # laser shutter is active
        count = int(1.1*(exposure+pulse+2*delay)*0.001*freq)
        td = int(delay*0.001*freq)
        texp = int(exposure*0.001*freq)
        tpulse = int(pulse*0.001*freq)
        trigpulse = int(0.004*freq)
        p = range(count)
        laser_arr = N.zeros(count)
        led_arr = N.zeros(count)
        Rlaser_arr = N.zeros(count)
        if LED==1:
            LED12_arr = N.zeros(count)
        else:
            LED12_arr = N.ones(count)
        if laser:
            laser_arr = N.array([(i>td) & (i<(td+texp)) for i in p])
        elif Rlaser:
            Rlaser_arr = N.array([(i>td) & (i<(td+texp)) for i in p])
        else:
            led_arr = N.array([(i>(2*td+texp)) & (i<(2*td+texp+tpulse)) for i in p])
        if (CCD):
            ccdtrig = N.array([(i<=(trigpulse)) for i in p])
        else:
            ccdtrig = N.array([(0) for i in p])
        out = (ccdtrig+2*led_arr+4*laser_arr+8*Rlaser_arr+16*LED12_arr).astype(N.int)
        return out

    def getTiming3(self,freq,exposure,pulse,delay,laser=False,Rlaser=False,LED=1,CCD=True):
##    def getTiming(self,freq,exposure,pulse,delay,laser=False):
        ''' frequency is in Hertz, exposure and delay are in ms
            bit 1: CCD Trigger
            bit 2: LED pulse
            bit 3: Laser shutter Contineous
            bit 4: Red Laser contineous
            bit 5: LED 1/2'''
        # laser shutter is active
        count = int(1.1*(exposure+delay)*0.001*freq)
        td = int(delay*0.001*freq)
        texp = int(exposure*0.001*freq)
        tpulse = int(pulse*0.001*freq)
        trigpulse = int(0.004*freq)
        p = range(count)
        led_arr = N.zeros(count)
        ccdtrig = N.zeros(count)
        laser_arr = N.zeros(count)
        Rlaser_arr = N.zeros(count)
        LED12_arr = N.ones(count)
        if LED==1:
            LED12_arr = N.zeros(count)
        if laser:
            laser_arr = N.ones(count)
        if Rlaser:
            Rlaser_arr = N.ones(count)
        if not (laser | Rlaser):
#            led_arr = N.array([(i>td) & (i<(td+tpulse)) for i in p])
            led_arr = N.ones(count)
        if (CCD):
            ccdtrig = N.array([(i<=(trigpulse)) for i in p])
        out = (ccdtrig+2*led_arr+4*laser_arr+8*Rlaser_arr+16*LED12_arr).astype(N.int)
        return out
        
####### Internal Trigger ###################################################
      
    def setCCD_Conv_Int(self,exposure=0.100):
        self.ccd.SetAcquisitionMode(1) # single exposure
        self.ccd.SetOutputAmplifier(1)
        self.ccd.SetTriggerMode(0) #0: internal
        self.ccd.SetShutterMode(2) #0: auto
        self.ccd.SetExposureTime(exposure)
        q = self.ccd.GetAcquisitionTimings()
        return q
        
    def StackInt(self,start,stop,step=0.2):
        no = int((stop-start)/step)+1
        pos = start
        xs = self.ccd.image_size[0]
        ys = self.ccd.image_size[1]
        self.data = N.zeros((no,xs,ys), dtype=N.uint16)
        self.ccd.SetShutterMode(1)
        for p in range(no):
            self.zst.setPositionf(pos)
            q = self.ccd.Acquire()
            q = self.ccd.WaitForNewData()
            q = self.ccd.AbortAcquisition()
            self.data[p] = self.ccd.images
            pos += step
        self.ccd.AbortAcquisition()
        self.ccd.SetShutterMode(2)
        cur_pos = self.prior.getPosition()
        self.stackTags(cur_pos[0],cur_pos[1],start,stop,step,function='Z-Stack')
        T.imshow(self.data, vmin=self.data.min(), vmax=self.data.max())
        return True
        
###########################################################################
        
    def saveTifA(self,slideName='',comments='',Upload=False):
        t=time.localtime()
        x = N.array([1e4,1e2,1])
        t1 = int((t[0:3]*x).sum())
        t2 = int((t[3:6]*x).sum())
        if slideName=='':
            slideName=self.Name
        else:
            self.Name=slideName
        self.stackparams['Comments']=comments
        self.stackparams['Slide Name']=slideName
        fn = "%s-%s_%s_%s" %(t1,t2,slideName,comments)
        fn1 = os.path.join(self.path,fn+'.tif')
        fn2 = os.path.join(self.path,fn+'_ps.txt')
        T.imsave(fn1,self.data)
        self._SaveText(fn2)
        return fn
        
    def saveTiff(self,comments='',fn=None,Upload=False):
        if fn==None:
            return None
        t = fn.partition('.')
        fn1 = t[0]+'.tif'
        fn2 = t[0]+'_ps.txt'
        T.imsave(fn1,self.data)
        if comments:
            self.stackparams['Comments']=comments
        self._SaveText(fn2)
        return fn
        
    def _SaveText(self,fn=None):
        if fn==None:
            return False
        s = []
        for parts in self.stackparams:
            s.append('%s : %s \n' % (parts, self.stackparams[parts]))
        s.sort()
        fid = open(fn,'w')
        fid.writelines(s)
        fid.close()
        return True

    def stackTags(self,xx,yy,z1,z2,zs,function='',ps=89):
        '''Date/Time,X,Y,Z1,Z2,Zstep,Exposure(s),CCD Temperature,
        Pixel Size(nm),CCD setting',User
        '''
        self.stackparams.clear()
        self.stackparams['00 function']=function
        self.stackparams['01 Date/Time']=time.asctime()
        self.stackparams['05 X']=xx
        self.stackparams['06 Y']=yy
        self.stackparams['07 Z1']=z1
        self.stackparams['08 Z2']=z2
        self.stackparams['09 Zstep']=zs
        self.stackparams['02 Exposure(s)']=self.ccd.GetExposureTime()
        self.stackparams['03 CCD Temperature']=self.ccd.GetTemperature()
        self.stackparams['10 User']=getuser()
        self.stackparams['11 Coordinates']=self.ccd.GetImageCoordinates()
        self.stackparams['12 Pixel size']=ps
        ccdsett=self.ccd.SettingsString()
        i=13
        for item in ccdsett.splitlines():
            try:
                csi,csv=item.split(':')
                ncsi=str(i)+' '+csi
                self.stackparams[ncsi]=csv
            except:
                csi=0
            i+=1
        return True
            
    def setCoord(self,xs,xe,ys,ye):
        '''val=(xs,xe,ys,ye)'''
        oxs,oxe,oys,oye = self.coordVal
        self.old_Cval = (oxs,oxe,oys,oye)
        self.coordVal=(xs,xe,ys,ye)
        q=self.ccd.SetImageCoordinates(self.coordVal)
        return q
        
    def setCoord2(self,xs,ys,nn):
        '''Gets one corner (xs,ys) to make (nn x nn) image size'''
        oxs,oxe,oys,oye = self.coordVal
        self.old_Cval = (oxs,oxe,oys,oye)
        self.coordVal=(xs,xs+nn-1,ys,ys+nn-1)
        q=self.ccd.SetImageCoordinates(self.coordVal)
        return q
        
    def reSetCoord(self,mode = 0):
        '''mode 0: Full CCD:(1,512,1,512)
           mode 1: return to previous coordinates: old_Cval        
        '''
        if mode==0:
            xs,xe,ys,ye = (1,512,1,512)
        elif mode==1:
            xs,xe,ys,ye = self.old_Cval
        return self.setCoord(xs,xe,ys,ye)
Beispiel #5
0
class ALPAO_DM():
    # -------------------------------------------------------------------------
    def __init__(self,):
        self.seri_num = "BOL115"
        self.alpao   = DM(self.seri_num)
        self.nba     = int(alpao.Get('NBOfActuator'))
        self.alpao.Send([0.] * nbAct)  # init the DM: zeroes everywhere
        self.dms     = 11              # DM size
        dms = self.dms
        xdm, ydm     = np.meshgrid(np.arange(dms)-dms/2, np.arange(dms)-dms/2)
        self.xdm     = xdm.T.astype('float32')
        self.ydm     = ydm.T.astype('float32')
        self.dmmask  = np.ones((dms, dms), dtype=np.int) # corner mask
        self.dmmask[np.abs(self.xdm) + np.abs(self.ydm) > 7] = 0.0
        self.flat_mask = self.dmmask.flatten()

        self.nch   = 8 # number of DM channels
        self.dmd0  = np.zeros((dms,dms), dtype=np.float32)
        self.cntrs = np.zeros(self.nch+1) - 1 # shared mem counters for channels

        for ii in range(self.nch):
            exec "disp%d = shm(fname='/tmp/dmdisp%d.im.shm', data=self.dmd0, verbose=False)" % (ii,ii)

    # -------------------------------------------------------------------------
    def map2dm(self, cmap):
        ''' --------------------------------------------
        Sends a 2D command to the DM, using the mapping
        knowledge provided by the flat_mask array.
        -------------------------------------------- ''' 
        temp   = cmap.flatten()
        values = [0.0] * self.nba # data to be uploaded to the DM
        
        jj = 0
        for ii in xrange(cmap.size):
            if not np.isnan(self.flat_mask[ii]):
                values[jj] = temp[i]
                jj += 1
        self.alpao.Send(values)

    # -------------------------------------------------------------------------
    def reset(self, chn=0):
        ''' ----------------------------------------------
        Reset one or (default) all channels of the DM.
        ---------------------------------------------- '''
        if chn == 0: # send the flat-map!
            try:
                data = np.loadtxt('/home/ciaodev/.config/ciao/zygo_flat.txt')
                disp0.set_data(list2map2D(data))
            except:
                disp0.set_data(self.dmd0)
        else:
            try:
                exec 'self.dmdisp%d.set_data(self.dmd0)' % 
            except:
                print("error reset channel #%d" % (chn))

    # -------------------------------------------------------------------------
    def quit(self, chn=None):

    # -------------------------------------------------------------------------
    def quit(self, chn=None):
        self.alpao.Reset()
        sys.exit()

# =============================================================================
# =============================================================================

if __name__ == "__main__":
    mydm = ALPAO_DM()
Beispiel #6
0
 def __init__(self):
     super(Form, self).__init__()
     uic.loadUi('Gui_FLIR.ui', self)
     self.connect(self.QuitButton, SIGNAL("clicked()"), self.shutdown)
     self.connect(self.RunButton, SIGNAL("clicked()"), self.run)
     #        self.connect(self.StopButton, SIGNAL("clicked()"), self.stop)
     self.connect(self.SaveButton, SIGNAL("clicked()"), self.Saveimg)
     self.connect(self.SaveWFButton, SIGNAL("clicked()"), self.savedmwf)
     self.connect(self.SaveZMWFButton, SIGNAL("clicked()"), self.savezmwf)
     self.connect(self.AutoScanButton, SIGNAL("clicked()"), self.autoscandm)
     self.connect(self.exposurebox, SIGNAL("returnPressed()"),
                  self.exposureupdate)
     self.connect(self.thresholdbox, SIGNAL("returnPressed()"),
                  self.thresholdupdate)
     self.connect(self.PushDMButton, SIGNAL("clicked()"), self.pushdm)
     self.connect(self.ScanZernikeModeButton, SIGNAL("clicked()"),
                  self.scanzernikemode)
     self.connect(self.LoadDMButton, SIGNAL("clicked()"), self.loaddmfile)
     self.connect(self.InitiatePushButton, SIGNAL("clicked()"),
                  self.set_baseimage)
     self.connect(self.Infl_func_pushButton, SIGNAL("clicked()"),
                  self.influencefunction)
     self.ProgressBar.setRange(0, 100)
     self.ProgressBar.setValue(0)
     self.index = 0
     #DM
     self.serialName = 'BAX228'
     self.dm = DM(self.serialName)
     self.nbAct = int(self.dm.Get('NBOfActuator'))
     self.values = [0.] * self.nbAct
     self.dm.Send(self.values)
     #Initial camera
     self.system = PySpin.System.GetInstance()
     self.cam_list = self.system.GetCameras()
     self.cam = self.cam_list[0]
     self.cam.Init()
     self.nodemap = self.cam.GetNodeMap()
     self.node_acquisition_mode = PySpin.CEnumerationPtr(
         self.nodemap.GetNode('AcquisitionMode'))
     self.node_acquisition_mode_continuous = self.node_acquisition_mode.GetEntryByName(
         'Continuous')
     self.acquisition_mode_continuous = self.node_acquisition_mode_continuous.GetValue(
     )
     self.node_acquisition_mode.SetIntValue(
         self.acquisition_mode_continuous)
     self.cam.ExposureAuto.SetValue(PySpin.ExposureAuto_Off)
     self.exposure_time_to_set = 200.0
     self.cam.ExposureTime.SetValue(self.exposure_time_to_set)
     self.cam.BeginAcquisition()
     self.image_result = self.cam.GetNextImage()
     self.img = self.image_result.GetNDArray()
     self.image = self.img.copy()
     self.baseimage = self.img.copy()
     self.image_result.Release()
     self.cam.EndAcquisition()
     self.ah = self.CCDImage.axes.imshow(self.image)
     # setup the wavefront
     self.WFS = shwfs.Wavefront_Sensor()
     self.phi = self.WFS.GetAberration2img(self.baseimage, self.baseimage)
     self.phi = self.phi * self.WFS.Zero_Mask
     self.wah = self.WFimage.axes.imshow(self.phi,
                                         interpolation='nearest',
                                         vmin=-0.8,
                                         vmax=0.8)
     self.WFimage.figure.colorbar(self.wah)
Beispiel #7
0
class Form(QDialog):
    def __init__(self):
        super(Form, self).__init__()
        uic.loadUi('Gui_FLIR.ui', self)
        self.connect(self.QuitButton, SIGNAL("clicked()"), self.shutdown)
        self.connect(self.RunButton, SIGNAL("clicked()"), self.run)
        #        self.connect(self.StopButton, SIGNAL("clicked()"), self.stop)
        self.connect(self.SaveButton, SIGNAL("clicked()"), self.Saveimg)
        self.connect(self.SaveWFButton, SIGNAL("clicked()"), self.savedmwf)
        self.connect(self.SaveZMWFButton, SIGNAL("clicked()"), self.savezmwf)
        self.connect(self.AutoScanButton, SIGNAL("clicked()"), self.autoscandm)
        self.connect(self.exposurebox, SIGNAL("returnPressed()"),
                     self.exposureupdate)
        self.connect(self.thresholdbox, SIGNAL("returnPressed()"),
                     self.thresholdupdate)
        self.connect(self.PushDMButton, SIGNAL("clicked()"), self.pushdm)
        self.connect(self.ScanZernikeModeButton, SIGNAL("clicked()"),
                     self.scanzernikemode)
        self.connect(self.LoadDMButton, SIGNAL("clicked()"), self.loaddmfile)
        self.connect(self.InitiatePushButton, SIGNAL("clicked()"),
                     self.set_baseimage)
        self.connect(self.Infl_func_pushButton, SIGNAL("clicked()"),
                     self.influencefunction)
        self.ProgressBar.setRange(0, 100)
        self.ProgressBar.setValue(0)
        self.index = 0
        #DM
        self.serialName = 'BAX228'
        self.dm = DM(self.serialName)
        self.nbAct = int(self.dm.Get('NBOfActuator'))
        self.values = [0.] * self.nbAct
        self.dm.Send(self.values)
        #Initial camera
        self.system = PySpin.System.GetInstance()
        self.cam_list = self.system.GetCameras()
        self.cam = self.cam_list[0]
        self.cam.Init()
        self.nodemap = self.cam.GetNodeMap()
        self.node_acquisition_mode = PySpin.CEnumerationPtr(
            self.nodemap.GetNode('AcquisitionMode'))
        self.node_acquisition_mode_continuous = self.node_acquisition_mode.GetEntryByName(
            'Continuous')
        self.acquisition_mode_continuous = self.node_acquisition_mode_continuous.GetValue(
        )
        self.node_acquisition_mode.SetIntValue(
            self.acquisition_mode_continuous)
        self.cam.ExposureAuto.SetValue(PySpin.ExposureAuto_Off)
        self.exposure_time_to_set = 200.0
        self.cam.ExposureTime.SetValue(self.exposure_time_to_set)
        self.cam.BeginAcquisition()
        self.image_result = self.cam.GetNextImage()
        self.img = self.image_result.GetNDArray()
        self.image = self.img.copy()
        self.baseimage = self.img.copy()
        self.image_result.Release()
        self.cam.EndAcquisition()
        self.ah = self.CCDImage.axes.imshow(self.image)
        # setup the wavefront
        self.WFS = shwfs.Wavefront_Sensor()
        self.phi = self.WFS.GetAberration2img(self.baseimage, self.baseimage)
        self.phi = self.phi * self.WFS.Zero_Mask
        self.wah = self.WFimage.axes.imshow(self.phi,
                                            interpolation='nearest',
                                            vmin=-0.8,
                                            vmax=0.8)
        self.WFimage.figure.colorbar(self.wah)

    def set_baseimage(self, ):
        self.cam.BeginAcquisition()
        self.image_result = self.cam.GetNextImage()
        self.baseimage = self.image_result.GetNDArray().copy()
        self.image_result.Release()
        self.cam.EndAcquisition()

    def run(self):
        self.cam.BeginAcquisition()
        self.image_result = self.cam.GetNextImage()
        self.image = self.image_result.GetNDArray().copy()
        self.image_result.Release()
        self.cam.EndAcquisition()
        self.imageupdate()

    def imageupdate(self):
        # update ccd image
        self.ah.set_data(self.image)
        self.CCDImage.figure.canvas.draw()
        # measure wavefront
        self.phi = self.WFS.GetAberration2img(self.baseimage, self.image)
        self.phi = self.phi * self.WFS.Zero_Mask
        self.wah.set_data(self.phi)
        self.wah.set_clim(self.phi.min(), self.phi.max())
        self.WFimage.figure.canvas.draw()
        self.ProgressBar.setValue(self.index)
        self.index = (self.index + 1) % 100

    def shutdown(self):
        x = self.dm.Reset()
        if (x == 0):
            print('DM Reset')
        else:
            print('DM cannot reset')
        del self.cam
        self.cam_list.Clear()
        self.system.ReleaseInstance()
        self.close()

    def pushdm(self):
        push = self.PushdoubleSpinBox.value()
        num = self.ActspinBox.value()
        self.values[num] = push
        self.dm.Send(self.values)
        self.values[num] = 0.
        return True

    def influencefunction(self):
        n = self.nbAct
        push = self.PushdoubleSpinBox.value()
        for i in range(n):
            self.values[i] = push
            self.dm.Send(self.values)
            self.values[i] = 0.
            self.run()
            fn = 'act_%d' % i + '_v%f.tif' % push
            tf.imsave(fn,
                      self.phi.astype(np.float32),
                      photometric='minisblack')
        return True

    def autoscandm(self):
        for i in range(self.nbAct):
            data = []
            for p in range(19):
                push = -0.9 + p * 0.1
                self.values[i] = push
                self.dm.Send(self.values)
                self.cam.BeginAcquisition()
                self.image_result = self.cam.GetNextImage()
                self.image = self.image_result.GetNDArray().copy()
                self.image_result.Release()
                self.cam.EndAcquisition()
                self.phi = self.WFS.GetAberration2img(self.baseimage,
                                                      self.image)
                self.phi = self.phi * self.WFS.Zero_Mask
                data[p] = self.phi
                self.values[i] = 0.
                time.sleep(0.1)
            fn = 'act_%d.tif' % (i)
            tf.imsave(join(fn),
                      data.astype(np.float32),
                      photometric='minisblack')
        return True

    def scanzernikemode(self):
        n = self.ZernikeModeBox.value()
        h = self.PushSpinBox.value()
        phiin = h * zernike.Zm(n, rad=17, orig=None, Nx=33)
        dmarr = 0.1 * np.dot(Sm.S, phiin.reshape(33 * 33))
        dmfile = [0.] * 69
        for i in range(69):
            dmfile[i] = dmarr[i]
        if (all(i <= 1.0 for i in dmfile)):
            self.dm.Send(dmfile)
        else:
            raise Exception(' Error: push value greater than 1.0 ')

    def loaddmfile(self):
        fns = self.dmfilebox.text()
        fn = r'%s' % fns
        with open(fn, "r") as file:
            cmd = eval(file.readline())
        if (all(i <= 1.0 for i in cmd)):
            self.dm.Send(cmd)
        else:
            raise Exception(' Error: push value greater than 1.0 ')

    def savedmwf(self):
        m = self.ActspinBox.value()
        v = self.PushdoubleSpinBox.value()
        fn = 'act_%d' % m + '_v%f.tif' % v
        tf.imsave(fn, self.phi.astype(np.float32), photometric='minisblack')

    def savezmwf(self):
        m = self.ZernikeModeBox.value()
        v = self.PushSpinBox.value()
        fn = 'zernike_mode%d' % m + '_v%f.tif' % v
        tf.imsave(fn, self.phi.astype(np.float32), photometric='minisblack')

    def Saveimg(self):
        tf.imsave('camera_image.tif',
                  self.img.astype(np.float32),
                  photometric='minisblack')
        tf.imsave('wfs_image.tif',
                  self.phi.astype(np.float32),
                  photometric='minisblack')

    def updatespacing(self):
        text = self.Spacinglinebox.text()
        self.px_spacing = float(text)

    def updateXcenter(self):
        xcenter = self.xCenterbox.text()
        self.x_center = float(xcenter)

    def updateYcenter(self):
        ycenter = self.yCenterbox.text()
        self.y_center = float(ycenter)

    def exposureupdate(self):
        exposure = self.exposurebox.text()
        exposure = int(exposure)
        self.cam.ExposureTime.SetValue(exposure)

    def thresholdupdate(self):
        threshold = self.thresholdbox.text()
        self.theshold = float(threshold)

    def high_pass_filter(self, data):
        y, x = data.shape
        data[data < self.threshold] = 0.0
        return data
Beispiel #8
0
@author: snf56384
"""

import sys
import os
#import time
import struct
''' Add '/Lib' or '/Lib64' to path '''
if (8 * struct.calcsize("P")) == 32:
    print("Use x86 libraries.")
    sys.path.append(os.path.join(os.path.dirname(__file__), 'Lib'))
else:
    print("Use x86_64 libraries.")
    sys.path.append(os.path.join(os.path.dirname(__file__), 'Lib64'))
''' Import Alpao SDK class '''
from asdk import DM

dm1 = DM("BAX111")
dm2 = DM("BAX112")

#dm1.Send( check1on2 )
#dm2.Send( -Zplot )

dm1.Reset()
dm2.Reset()

import numpy as np

signal = np.loadtxt("mirror_command.csv", delimiter=",")
dm1.Send(signal)