Exemplo n.º 1
0
    def _pupil(self, F, r, theta):
        from PYME.misc import zernike
        ang = 0
        for i, c in self.zernikeCoeffs.items():
            ang = ang + c * zernike.zernike(i, r, theta)

        return F * np.exp(-1j * ang)
Exemplo n.º 2
0
def GenSAPRIPSF(zs, dx=5, strength=1.0, SA=0, X=None, Y=None, lamb=700, n=1.51, NA = 1.47):
    from PYME.misc import zernike
    Xk = X.ctypes.data
    if not Xk in fps.keys():
        fpset = GenWidefieldAP(dx, X, Y, lamb=lamb, n=n, NA = NA)
        fps[Xk] = fpset
    else:
        fpset = fps[Xk]
    X, Y, R, FP, F, u, v = fpset #GenWidefieldAP(dx, X, Y)
    r = R/R[abs(F)>0].max()

    F = F * exp(-1j*sign(X)*10*strength*v)
    
    theta = angle(X + 1j*Y)
    
                
    ang = SA*zernike.zernike(8, r, theta)
            
    F = F*exp(-1j*ang)
    #clf()
    #imshow(angle(F))

    ps = concatenate([FP.propagate(F, z)[:,:,None] for z in zs], 2)

    return abs(ps**2)
Exemplo n.º 3
0
def GenZernikeDAPSF(zs,
                    zernikeCoeffs={},
                    field_x=0,
                    field_y=0,
                    apertureNA=1.5,
                    apertureZGradient=0,
                    **kwargs):
    from PYME.misc import zernike

    X, Y, R, FP, F, u, v = clipped_widefield_pupil_and_propagator(
        field_x=field_x,
        field_y=field_y,
        apertureNA=apertureNA,
        apertureZGradient=apertureZGradient,
        **kwargs)

    theta = np.angle(X + 1j * Y)
    r = R / R[abs(F) > 0].max()

    ang = 0

    for i, c in zernikeCoeffs.items():
        ang = ang + c * zernike.zernike(i, r, theta)

    F = F * np.exp(-1j * ang)

    return PSF_from_pupil_and_propagator(X,
                                         Y,
                                         R,
                                         FP,
                                         u,
                                         v,
                                         pupil=F,
                                         zs=zs,
                                         **kwargs)
Exemplo n.º 4
0
def GenSAAstigPSF(zs, dx=5, strength=1.0, SA=0, X=None, Y=None, lamb=700, n=1.51, NA = 1.47):
    from PYME.misc import zernike
    if X == None:
        Xk = 'none'
    else:
        Xk = X.ctypes.data
    if not Xk in fps.keys():
        fpset = GenWidefieldAP(dx, X, Y, lamb=lamb, n=n, NA = NA)
        X, Y, R, FP, F, u, v = fpset
        r = R/R[abs(F)>0].max()
        theta = angle(X + 1j*Y)
        
        z8 = zernike.zernike(8, r, theta)
        a_s = (v**2 - 0.5*R**2)
        
        fps[Xk] = (fpset, z8, a_s)
    else:
        fpset, z8, a_s = fps[Xk]
        X, Y, R, FP, F, u, v = fpset #GenWidefieldAP(dx, X, Y)
    

    #F = F * exp(-1j*(strength*a_s + SA*z8))
    pf = -(strength*a_s + SA*z8)
    F = F *(cos(pf) + j*sin(pf))
    
    #clf()
    #imshow(angle(F))

    ps = concatenate([FP.propagate(F, z)[:,:,None] for z in zs], 2)

    return abs(ps**2)
Exemplo n.º 5
0
def GenZernikeDonutPSF(zs, zernikeCoeffs={}, spiral_amp=1.0, **kwargs):
    from PYME.misc import zernike
    X, Y, R, FP, F, u, v = widefield_pupil_and_propagator(**kwargs)
    kwargs.pop('X', None)
    kwargs.pop('Y', None)

    theta = np.angle(X + 1j * Y)
    r = R / R[abs(F) > 0].max()

    ang = 0

    for i, c in zernikeCoeffs.items():
        ang = ang + c * zernike.zernike(i, r, theta)

    ang = ang + spiral_amp * theta

    F = F * np.exp(-1j * ang)

    return PSF_from_pupil_and_propagator(X,
                                         Y,
                                         R,
                                         FP,
                                         u,
                                         v,
                                         pupil=F,
                                         zs=zs,
                                         **kwargs)
Exemplo n.º 6
0
def GenSAPSF(zs, strength=1.0, **kwargs):
    from PYME.misc import zernike
    X, Y, R, FP, F, u, v = widefield_pupil_and_propagator(**kwargs)
    
    r = R/R[abs(F)>0].max()
    theta = np.angle(X + 1j*Y)
    
    z8 = zernike.zernike(8, r, theta)

    F = F * np.exp(-1j*strength*z8)
    
    return PSF_from_pupil_and_propagator(X, Y, R, FP, u, v, pupil=F, zs=zs, **kwargs)
Exemplo n.º 7
0
def GenSAAstigPSF(zs, strength=1.0, SA=0, **kwargs):
    from PYME.misc import zernike
    X, Y, R, FP, F, u, v = widefield_pupil_and_propagator(**kwargs)
    
    r = R/R[abs(F)>0].max()
    theta = np.angle(X + 1j*Y)
    
    z8 = zernike.zernike(8, r, theta)
    a_s = (v**2 - 0.5*R**2)
    
    pf = -(strength*a_s + SA*z8)
    F = F *(np.cos(pf) + j*np.sin(pf))

    return PSF_from_pupil_and_propagator(X, Y, R, FP, u, v, pupil=F, zs=zs, **kwargs)
Exemplo n.º 8
0
def GenZernikeDAPSF(zs, dx = 5, X=None, Y=None, zernikeCoeffs = {}, lamb=700, n=1.51, NA = 1.47, ns=1.51,field_x=0, field_y=0, apertureNA=1.5, apertureZGradient = 0, apodizisation=None, vect=True):
    from PYME.misc import zernike, snells
    X, Y, R, FP, F, u, v = GenWidefieldAPA(dx, X = X, Y=Y, lamb=lamb, n = n, NA = NA, field_x=field_x, field_y=field_y, apertureNA=apertureNA, apertureZGradient = apertureZGradient, apodizisation=apodizisation)
    
    theta = angle(X + 1j*Y)
    r = R/R[abs(F)>0].max()
    
    if ns == n:
        T = 1.0*F
    else:
        #find angles    
        t_t = np.minimum(r*arcsin(NA/n), np.pi/2)
        
        #corresponding angle in sample with mismatch
        t_i = snells.theta_t(t_t, n, ns)
        
        #Transmission at interface (average of S and P)
        T = 0.5*(snells.Ts(t_i, ns, n) + snells.Tp(t_i, ns, n))
        #concentration of high angle rays:
        T = T*F/(n*np.cos(t_t)/np.sqrt(ns*2 - (n*np.sin(t_t))**2))
    
    
    
    #imshow(T*(-t_i + snells.theta_t(t_t+.001, n, ns)))
    #imshow(F)
    #colorbar()
    #figure()
    #imshow(T, clim=(.8, 1.2))
    #colorbar()
    #figure()
    #imshow(T*(-t_i + snells.theta_t(t_t+.01, n, ns)))
    #imshow(t_i - t_t)
    
    ang = 0
    
    for i, c in zernikeCoeffs.items():
        ang = ang + c*zernike.zernike(i, r, theta)
        
    #clf()
    #imshow(angle(exp(1j*ang)))
        
    F = T*exp(-1j*ang)
        
    #figure()
    #imshow(angle(F))
        
    if vect:
        return PsfFromPupilVectFP(X,Y,R, FP, u,v, n, F, zs)
    else:
        return PsfFromPupilFP(X,Y,R, FP, u,v, n, F, zs)
Exemplo n.º 9
0
def GenZernikePSF(zs, zernikeCoeffs = [], **kwargs):
    from PYME.misc import zernike
    X, Y, R, FP, F, u, v = widefield_pupil_and_propagator(**kwargs)
    
    theta = np.angle(X + 1j*Y)
    r = R/R[abs(F)>0].max()
    
    ang = 0
    
    for i, c in enumerate(zernikeCoeffs):
        ang = ang + c*zernike.zernike(i, r, theta)
        
    pupil = F.astype('d')*np.exp(-1j*ang)

    return PSF_from_pupil_and_propagator(X, Y, R, FP, u, v, pupil=pupil, zs=zs, **kwargs)
Exemplo n.º 10
0
def GenSABesselPSF(zs, dx=5, rad=.95, strength=1.0, X=None, Y=None, lamb=700, n=1.51, NA = 1.47):
    from PYME.misc import zernike
    X, Y, R, FP, F, u, v = GenWidefieldAP(dx, X, Y, lamb=lamb, n=n, NA = NA)
    
    r = R/R[abs(F)>0].max()
    theta = angle(X + 1j*Y)
    
    z8 = zernike.zernike(8, r, theta)

    F = F * (r > rad)*exp(-1j*strength*z8)
    #clf()
    #imshow(angle(F))

    ps = concatenate([FP.propagate(F, z)[:,:,None] for z in zs], 2)

    return abs(ps**2)
Exemplo n.º 11
0
def GenZernikePSF(zs, dx = 5, zernikeCoeffs = []):
    from PYME.misc import zernike
    X, Y, R, FP, F, u, v = GenWidefieldAP(dx)
    
    theta = angle(X + 1j*Y)
    r = R/R[abs(F)>0].max()
    
    ang = 0
    
    for i, c in enumerate(zernikeCoeffs):
        ang = ang + c*zernike.zernike(i, r, theta)
        
    clf()
    imshow(angle(exp(1j*ang)))
        
    F = F.astype('d')*exp(-1j*ang)
        
    figure()
    imshow(angle(F))

    ps = concatenate([FP.propagate(F, z)[:,:,None] for z in zs], 2)

    return abs(ps**2)
Exemplo n.º 12
0
def GenZernikePSF(zs, dx = 5, zernikeCoeffs = []):
    from PYME.misc import zernike
    X, Y, R, FP, F = GenWidefieldAP(dx)
    
    theta = angle(X + 1j*Y)
    r = R/R[F].max()
    
    ang = 0
    
    for i, c in enumerate(zernikeCoeffs):
        ang = ang + c*zernike.zernike(i, r, theta)
        
    clf()
    imshow(angle(exp(1j*ang)))
        
    F = F.astype('d')*exp(-1j*ang)
        
    figure()
    imshow(angle(F))

    ps = concatenate([FP.propagate(F, z)[:,:,None] for z in zs], 2)

    return abs(ps**2)
Exemplo n.º 13
0
def Gen4PiPSF(zs,phi=0, zernikeCoeffs=[{},{}], **kwargs):
    from PYME.misc import zernike
    X, Y, R, FP, pupil, u, v = widefield_pupil_and_propagator(**kwargs)
    
    dphi = phi

    kwargs.pop('X', None)
    kwargs.pop('Y', None)
    
    NA = kwargs.get('NA', 1.47)
    n = kwargs.get('n', 1.51)
    output_shape = kwargs.get('output_shape', None)
    beadsize = kwargs.get('beadsize', 0)
    vectorial = kwargs.get('vectorial', False)

    pupil = pupil * _apodization_function(R, NA, n, kwargs.get('apodization', None))
    
    if beadsize > 0:
        pupil = pupil * get_bead_pupil(X, Y, beadsize)

    theta = np.angle(X + 1j * Y)
    r = R / R[abs(pupil) > 0].max()



    ang_u = 0
    ang_l = 0
    
    zerns_upper, zerns_lower = zernikeCoeffs
    
    #print zernikeCoeffs, zerns_upper, zerns_lower

    for i, c in zerns_upper.items():
        ang_u = ang_u + c * zernike.zernike(i, r, theta)
        
    for i, c in zerns_lower.items():
        ang_l = ang_l + c * zernike.zernike(i, r, theta)
        
    pupil_upper = pupil * np.exp(-1j * ang_u)
    pupil_lower = pupil * np.exp(-1j * ang_l)
        
    #pupil_upper = pupil
    #pupil_lower = pupil

    if vectorial:
        if vectorial is True:
            #use circular pol by default
            a = 1
            b = -1j
        else:
            #vectorial is a tuple of polarization components
            a, b = vectorial
        
        phi = np.angle(u + 1j * v)
        theta = np.arcsin(np.minimum(R, 1))
    
        ct = np.cos(theta)
        st = np.sin(theta)
        cp = np.cos(phi)
        sp = np.sin(phi)
        
        psf = []
        for z in zs:
            #ax
            fac = a*(ct * cp ** 2 + sp ** 2)
            ps_u = FP.propagate(pupil_upper * fac, z)
            ps_l = FP.propagate(pupil_lower * fac, -z)*np.exp(1j*dphi)
            ps_x = ps_u + ps_l
            #p = abs(ps ** 2)
        
            #ay
            fac = a*(ct - 1) * cp * sp
            ps_u = FP.propagate(pupil_upper * fac, z)
            ps_l = FP.propagate(pupil_lower * fac, -z) * np.exp(1j * dphi)
            ps_y = ps_u + ps_l
            #p += abs(ps ** 2)
        
            #bx
            fac = b*(ct - 1) * cp * sp
            ps_u = FP.propagate(pupil_upper * fac, z)
            ps_l = FP.propagate(pupil_lower * fac, -z) * np.exp(1j * dphi)
            ps_x += (ps_u + ps_l)
            p = abs(ps_x ** 2)
        
            #by
            fac = b*(ct * sp ** 2 + cp ** 2)
            ps_u = FP.propagate(pupil_upper * fac, z)
            ps_l = FP.propagate(pupil_lower * fac, -z) * np.exp(1j * dphi)
            ps_y += (ps_u + ps_l)
            p += abs(ps_y ** 2)
        
            #az
            fac = -a*st * cp
            ps_u = FP.propagate(pupil_upper * fac, z)
            ps_l = FP.propagate(pupil_lower * fac, -z) * np.exp(1j * dphi)
            ps_z = ps_u + ps_l
            #p += abs(ps ** 2)
        
            fac = -b*(st * sp)
            ps_u = FP.propagate(pupil_upper * fac, z)
            ps_l = FP.propagate(pupil_lower * fac, -z) * np.exp(1j * dphi)
            ps_z += (ps_u + ps_l)
            p += abs(ps_z ** 2)
            
            psf.append(p[:,:,None])

        p = np.concatenate(psf, 2)
    else:
        ###########
        # Default scalar case
        ps_u = np.concatenate([FP.propagate(pupil_upper, z)[:, :, None] for z in zs], 2)
        ps_l = np.concatenate([FP.propagate(pupil_lower, -z)[:, :, None] * np.exp(1j * dphi) for z in zs], 2)
        ps = ps_u + ps_l
        p = abs(ps ** 2)
    
    if output_shape is None:
        return p
    else:
        sx = output_shape[0]
        sy = output_shape[1]
        ox = np.ceil((X.shape[0] - sx) / 2.0)
        oy = np.ceil((X.shape[1] - sy) / 2.0)
        ex = ox + sx
        ey = oy + sy

        return p[ox:ex, oy:ey, :]