def get_K(rho, z, alpha=<NUM_LIT:1.0>, zint=<NUM_LIT>, n2n1=<NUM_LIT>, get_hdet=False, K=<NUM_LIT:1>,<EOL>Kprefactor=None, return_Kprefactor=False, npts=<NUM_LIT:20>, **kwargs):
<EOL>if type(rho) != np.ndarray or type(z) != np.ndarray or (rho.shape != z.shape):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>pts, wts = np.polynomial.legendre.leggauss(npts)<EOL>n1n2 = <NUM_LIT:1.0>/n2n1<EOL>rr = np.ravel(rho)<EOL>zr = np.ravel(z)<EOL>cos_theta = <NUM_LIT:0.5>*(<NUM_LIT:1>-np.cos(alpha))*pts+<NUM_LIT:0.5>*(<NUM_LIT:1>+np.cos(alpha))<EOL>if Kprefactor is None:<EOL><INDENT>Kprefactor = get_Kprefactor(z, cos_theta, zint=zint,n2n1=n2n1,get_hdet=get_hdet, **kwargs)<EOL><DEDENT>if K==<NUM_LIT:1>:<EOL><INDENT>part_1 = j0(np.outer(rr,np.sqrt(<NUM_LIT:1>-cos_theta**<NUM_LIT:2>)))*np.outer(np.ones_like(rr), <NUM_LIT:0.5>*(get_taus(cos_theta,n2n1=n2n1)+get_taup(cos_theta,n2n1=n2n1)*csqrt(<NUM_LIT:1>-n1n2**<NUM_LIT:2>*(<NUM_LIT:1>-cos_theta**<NUM_LIT:2>))))<EOL>integrand = Kprefactor * part_1<EOL><DEDENT>elif K==<NUM_LIT:2>:<EOL><INDENT>part_2=j2(np.outer(rr,np.sqrt(<NUM_LIT:1>-cos_theta**<NUM_LIT:2>)))*np.outer(np.ones_like(rr),<NUM_LIT:0.5>*(get_taus(cos_theta,n2n1=n2n1)-get_taup(cos_theta,n2n1=n2n1)*csqrt(<NUM_LIT:1>-n1n2**<NUM_LIT:2>*(<NUM_LIT:1>-cos_theta**<NUM_LIT:2>))))<EOL>integrand = Kprefactor * part_2<EOL><DEDENT>elif K==<NUM_LIT:3>:<EOL><INDENT>part_3=j1(np.outer(rho,np.sqrt(<NUM_LIT:1>-cos_theta**<NUM_LIT:2>)))*np.outer(np.ones_like(rr), n1n2*get_taup(cos_theta,n2n1=n2n1)*np.sqrt(<NUM_LIT:1>-cos_theta**<NUM_LIT:2>))<EOL>integrand = Kprefactor * part_3<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>big_wts=np.outer(np.ones_like(rr), wts)<EOL>kint = (big_wts*integrand).sum(axis=<NUM_LIT:1>) * <NUM_LIT:0.5>*(<NUM_LIT:1>-np.cos(alpha))<EOL>if return_Kprefactor:<EOL><INDENT>return kint.reshape(rho.shape), Kprefactor<EOL><DEDENT>else:<EOL><INDENT>return kint.reshape(rho.shape)<EOL><DEDENT>
Calculates one of three electric field integrals.

Internal function for calculating point spread functions. Returns
one of three electric field integrals that describe the electric
field near the focus of a lens; these integrals appear in Hell's psf
calculation.

Parameters
----------
    rho : numpy.ndarray
        Rho in cylindrical coordinates, in units of 1/k.
    z : numpy.ndarray
        Z in cylindrical coordinates, in units of 1/k. `rho` and
        `z` must be the same shape

    alpha : Float, optional
        The acceptance angle of the lens, on (0,pi/2). Default is 1.
    zint : Float, optional
        The distance of the len's unaberrated focal point from the
        optical interface, in units of 1/k. Default is 100.
    n2n1 : Float, optional
        The ratio n2/n1 of the index mismatch between the sample
        (index n2) and the optical train (index n1). Must be on
        [0,inf) but should be near 1. Default is 0.95
    get_hdet : Bool, optional
        Set to True to get the detection portion of the psf; False
        to get the illumination portion of the psf. Default is True
    K : {1, 2, 3}, optional
        Which of the 3 integrals to evaluate. Default is 1
    Kprefactor : numpy.ndarray or None
        This array is calculated internally and optionally returned;
        pass it back to avoid recalculation and increase speed. Default
        is None, i.e. calculate it internally.
    return_Kprefactor : Bool, optional
        Set to True to also return the Kprefactor (parameter above)
        to speed up the calculation for the next values of K. Default
        is False
    npts : Int, optional
        The number of points to use for Gauss-Legendre quadrature of
        the integral. Default is 20, which is a good number for x,y,z
        less than 100 or so.

Returns
-------
    kint : numpy.ndarray
        The integral K_i; rho.shape numpy.array
    [, Kprefactor] : numpy.ndarray
        The prefactor that is independent of which integral is being
        calculated but does depend on the parameters; can be passed
        back to the function for speed.

Notes
-----
    npts=20 gives double precision (no difference between 20, 30, and
    doing all the integrals with scipy.quad). The integrals are only
    over the acceptance angle of the lens, so for moderate x,y,z they
    don't vary too rapidly. For x,y,z, zint large compared to 100, a
    higher npts might be necessary.