def ao_optimize(om,
                dm,
                mf,
                modes=N.arange(4, 11, 1),
                amprange=N.arange(-0.12, 0.12, 0.02),
                S=None,
                gain=50,
                blaser=False,
                rlaser=True,
                LED=1):
    center = om.zst.getPosition()
    results = []
    results.append(('Mode', 'Amp', 'Metric'))
    dm.Send(cmd_best)
    dt = N.zeros(amprange.shape)
    om.open_Acq(exposure=0.1,
                emgain=gain,
                laser=blaser,
                Rlaser=rlaser,
                cntLaser=False,
                LED12=LED,
                FTM=False,
                conv=0,
                ccd=True,
                trig=1,
                regen=False)
    om.get_img()
    for mode in modes:
        for k, amp in enumerate(amprange):
            print(k, amp)
            phiin = amp * zernike.Zm(mode, rad=17, orig=None, Nx=33)  # was 28
            # set mirror with new dm shape
            dmarr = 0.5 * N.dot(S, phiin.reshape(33 * 33))
            cmd = [0.] * 69
            for i in range(69):
                cmd[i] = dmarr[i] + cmd_best[i]
            if (all(i <= 1.0 for i in cmd)):
                dm.Send(cmd)
            else:
                raise Exception(' Error: push value greater than 1.0 ')
            time.sleep(0.02)
            om.zst.setPositionf(center)
            om.get_img()
            dt[k] = mf(om.data)  # metric is peak intensity
            results.append((mode, amp, dt[k]))
        pmax = peak(amprange, dt)
        zmv[mode] += pmax
        print('setting mode %d at value of %f' % (mode, pmax))
        phiin = pmax * zernike.Zm(mode, rad=17, orig=None, Nx=33)  # was 28
        # set mirror with new dm shape
        dmarr = 0.5 * N.dot(S, phiin.reshape(33 * 33))
        for i in range(69):
            cmd_best[i] = cmd_best[i] + dmarr[i]
    if (all(i <= 1.0 for i in cmd_best)):
        dm.Send(cmd_best)
    else:
        raise Exception(' Error: push value greater than 1.0 ')
    om.ccd.AbortAcquisition()
    om.ccd.SetShutterMode(2)
    return results, cmd_best
def testSm(mode):
    S = Sm.S
    phiin = zernike.Zm(mode, rad=17, orig=None, Nx=33)  # was 28
    # set mirror with new dm shape
    dmarr = 0.5 * N.dot(S, phiin.reshape(33 * 33))
    phiout = N.dot(Sm.R, dmarr).reshape(33 * 33)
    return phiout
def setZernikeMode(om, dm, mode, amp, S):
    phiin = amp * zernike.Zm(mode, rad=17, orig=None, Nx=33)  # was 28
    # set mirror with new dm shape
    dmarr = 0.5 * N.dot(S, phiin.reshape(33 * 33))
    for i in range(69):
        cmd_best[i] = dmarr[i] + cmd_best[i]
    if (all(i <= 1.0 for i in dmarr)):
        dm.Send(cmd_best)
    else:
        raise Exception(' Error: push value greater than 1.0 ')
    return cmd_best
示例#4
0
 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 setZernike(om, dm, mode, amp, S):
    phiin = N.zeros((33, 33))
    cmd = [0.] * 69
    for j, m in enumerate(mode):
        phiin += amp[j] * zernike.Zm(m, rad=17, orig=None, Nx=33)


#    phiin = amp*zernike.Zm(mode,rad=17, orig=None,Nx=33) # was 28
# set mirror with new dm shape
    dmarr = 0.5 * N.dot(S, phiin.reshape(33 * 33))
    for i in range(69):
        cmd[i] = dmarr[i] + cmd_best[i]
    if (all(i <= 1.0 for i in dmarr)):
        dm.Send(cmd)
        print('PushDM_DONE')
    else:
        raise Exception(' Error: push value greater than 1.0 ')
    return cmd_best
示例#6
0
 def getaberr(self):
     wl = self.wl
     na = self.na
     n2 = 1.512
     dp = 1 / (self.nx * self.dx)
     radius = (na / wl) / dp
     ## prepare for focus mode
     x = N.arange(-self.nx / 2, self.nx / 2, 1)
     X, Y = N.meshgrid(x, x)
     rho = N.sqrt(X**2 + Y**2) / radius
     msk = (rho <= 1.0).astype(N.float64)
     self.defoc = msk * (2 * pi) * (n2 /
                                    wl) * N.sqrt(1 -
                                                 (na * msk * rho / n2)**2)
     #########################
     #msk = U.shift(U.discArray((self.nx,self.nx),radius))/(pi*radius**2)
     msk = U.shift(U.discArray(
         (self.nx, self.nx), radius)) / N.sqrt(pi * radius**2) / self.nx
     phi = N.zeros((self.nx, self.nx))
     for m in range(1, self.nzarr):
         phi = phi + self.zarr[m] * Z.Zm(m, radius, [0, 0], self.nx)
     self.wf = msk * N.exp(1j * phi).astype(N.complex64)
def scan_zermode(om, dm, mode=10, amp=0.1, S=Sm.S, path=None, center=None):
    if path == None:
        path = om.path
    if center == None:
        center = om.zst.getPosition()


#    cmd_flat = dm.cmd #dm.read_command_file(dm.flat_file)
    cmd = [0.] * 69
    # flat
    dm.Send(cmd)
    time.sleep(0.1)
    om.StackExt(center - 3.0, center + 3.0, 0.2, verbose=False)
    filename = path + '\\stack_flat_start.tif'
    om.saveTiff(fn=filename)

    #zernike mode
    phiin = amp * zernike.Zm(mode, rad=17, orig=None, Nx=33)  # was 28
    dmarr = 0.5 * N.dot(S, phiin.reshape(33 * 33))
    for i in range(69):
        cmd[i] = dmarr[i]
    if (all(i <= 1.0 for i in dmarr)):
        dm.Send(cmd)
    else:
        raise Exception(' Error: push value greater than 1.0 ')
    time.sleep(0.1)
    om.StackExt(center - 3.0, center + 3.0, 0.2, verbose=False)
    filename = path + '\\stack_act_zernikemode_%02d.tif' % mode
    om.saveTiff(fn=filename)

    # flat
    cmd = [0.] * 69
    dm.Send(cmd)
    time.sleep(0.1)
    om.StackExt(center - 3.0, center + 3.0, 0.2, verbose=False)
    filename = path + '\\stack_flat_end.tif'
    om.saveTiff(fn=filename)
    return True
示例#8
0
def buildphiZ(phi, shape, radius):
    nx = shape[0]
    pupil = N.zeros(shape)
    for m, amp in enumerate(phi):
        pupil = pupil + amp * Z.Zm(m, radius, None, nx)
    return pupil
 def get_phi(self, gene):
     phi = N.zeros((64, 64))
     for m in range(1, self.Nz):
         phi = phi + gene[m] * zernike.Zm(m, rad=32, orig=None, Nx=64)
     return phi
def ao_optimize_pr(om, dm, S, center=None, path=None):
    ''' use phase retrieval to correct wavefront '''
    rad = 32  # radius for S matrix
    offset = 110  #125
    if path == None:
        path = om.path
    if center == None:
        center = om.zst.getPosition()
#    if S == None:
#        raise Exception('No S matrix')
# start
#    cmd_flat = dm.cmd
# take stack
    om.setCCD_EM_ext(exposure=0.1,
                     emgain=100,
                     laser=False,
                     Rlaser=False,
                     LED12=2)
    om.StackExt(center - 1.6, center + 1.6, 0.2, verbose=False)
    # do phase retrieval
    p = phaseret.mre(stack_cut(om.data))
    p.zcenter = 2.0
    p.dz = 0.2
    p.offset = offset
    p.run(64)
    if p.geterr() > 300:
        print('convergence of phase retrieval is not great')
    # determine new dm settings
    amp, phase = p.get_amp_phase()
    pylab.figure()
    pylab.imshow(phase, interpolation='nearest')
    ph0 = phase[32:96, 32:96]
    if False:
        amp0 = amp[32:96, 32:96]
        msk = (amp0 > 0)
        target = 1.0 * zernike.Zm(4, rad=30, orig=None, Nx=64)
        ph0 = (ph0 - target) * msk
        pylab.imshow(ph0, interpolation='nearest')
    dmarr = 0.5 * N.dot(S, ph0.reshape(4 * rad**2))
    #    cmd = cmd_flat - dmarr
    cmd = [0.] * 69
    for i in range(69):
        cmd[i] = dmarr[i] + cmd_best[i]
    if (all(i <= 1.0 for i in cmd)):
        dm.Send(cmd)
    else:
        raise Exception(' Error: push value greater than 1.0 ')


#    dm.set_mirror(cmd)
# take stack
#om.setCCD_Conv_ext(exposure=0.100,laser=False,Rlaser=False,LED12=1)
    om.StackExt(center - 2.0, center + 2.0, 0.2, verbose=False)
    # do phase retrieval
    p = phaseret.mre(stack_cut(om.data))
    p.zcenter = 2.0
    p.dz = 0.2
    p.offset = offset
    p.run(32)
    if p.geterr() > 300:
        print('convergence of phase retrieval is not great')
    amp, phase = p.get_amp_phase()
    pylab.figure()
    pylab.imshow(phase, interpolation='nearest')
    return (cmd, cmd_best, p)