Example #1
0
def plot_zernike_wfe(indices_coeffs):
    '''
    Quickly plots a sum of given Zernike polynomial terms.

            Parameters:
                    indices_coeffs (list): List containing tuples of the kind (j, coeff), where j is the Zernike poylnomial index according to Noll's convention

            Returns:
                    -
    '''
    
    x = np.arange(-1, 1, 0.05)
    y = np.arange(-1, 1, 0.05)
    wfe_img = np.zeros((len(x), len(y)))
    
    for counterx, elx in enumerate(x):
        for countery, ely in enumerate(y):
            
            # perform transformation to polar coordinates
            rho = np.sqrt(elx**2+ely**2)
            theta = np.arctan2(ely, elx)
            
            # calculate image
            if rho <= 1:
                wfe_img[counterx][countery] = float(wfe(indices_coeffs, rho, theta, 1))
            
    # plot image
    plt.imshow(wfe_img)
    plt.colorbar()
    plt.title("Aberrated Wavefront")
    plt.xlabel("x")
    plt.ylabel("y")
    plt.xticks([0, len(x)/2, len(x)-1], [-1, 0, 1])
    plt.yticks([0, len(y)/2, len(y)-1], [-1, 0, 1])
    plt.show()
Example #2
0
def aperture(D=1., lam=1, a0=1., list_wfe=None, n=100):
    '''
    Returns a numpy array containing a circular aperture, possibly including wavefront aberrations.

            Parameters:
                    D (float): Aperture diameter in meters
                    lam (int): Wavelength in meters
                    a0 (float): Initial amplitude
                    list_wfe(list): List describing the wavefront error
                    n (int): Number to specify shape of array, i. e. n x n

            Returns:
                    (array): Complex array containing a circular aperture of diameter D
    '''

    # create 1-dimensional x and y arrays
    i = np.arange(1, n)
    x = i - n / 2
    y = n / 2 - i

    # convert to 2-dimensional arrays
    X = x[:, np.newaxis]
    Y = y[np.newaxis, :]

    # define radius
    R = D / 2

    # define ideal aperture
    aperture = a0 * (X**2 + Y**2 < R**2).astype(complex)

    # add wavefront error if a list of terms is given
    if list_wfe is not None:
        for counterx, elx in enumerate(x):
            for countery, ely in enumerate(y):
                aperture[countery, counterx] *= np.exp(-2 * np.pi * 1j * float(
                    wfe(list_wfe, np.sqrt(elx**2 + ely**2), np.arctan2(
                        ely, elx), R)) / lam)

    return aperture
Example #3
0
# # solve for roots, i. e. real part of amplitude a0
# a0_real = fsolve(func, 1)[0]

# # define full complex amplitude a0
# a0_ab = a0_real + a0_imag*1j
'''amplitude normalization common'''
for counterx, elx in enumerate(x):
    for countery, ely in enumerate(y):

        # perform transformation to polar coordinates
        ra = np.sqrt(elx**2 + ely**2)
        the = np.arctan2(ely, elx)

        # specify wavefront error
        wfe_gen = float(wfe(list_wfe, ra, the, D1_2))

        # define aprture 1
        aperture1_id_norm[counterx][countery] = 1 * np.heaviside(
            D1_2 - ra, 1) * np.heaviside(ra, 1)
        aperture1_ab_norm[counterx][countery] = 1 * np.heaviside(
            D1_2 - ra, 1) * np.heaviside(ra, 1) * np.exp(
                -2 * np.pi * 1j * wfe_gen / lam)

# normalize this amplitude to unit intensity
aperture1_common = aperture1_id_norm + aperture1_ab_norm
amplitude_temp = np.sum(aperture1_common)

# choose initial amplitude imaginary part because of degeneracy
a0_imag = amplitude_temp.imag
    e_diff = np.zeros((len(x), len(y)), dtype=complex)

    coeff = get_coeff_from_rms(rms, list_wfe)

    for index in range(len(list_wfe)):
        list_wfe[index] += (coeff, )
    '''amplitude normalization common'''
    for counterx, elx in enumerate(x):
        for countery, ely in enumerate(y):

            # perform transformation to polar coordinates
            ra = np.sqrt(elx**2 + ely**2)
            the = np.arctan2(ely, elx)

            # specify wavefront error
            wfe_gen = float(wfe(list_wfe, ra, the, D1_2))

            # define aprture 1
            aperture1_id_norm[counterx][countery] = 1 * np.heaviside(
                D1_2 - ra, 1) * np.heaviside(ra, 1)
            aperture1_ab_norm[counterx][countery] = 1 * np.heaviside(
                D1_2 - ra, 1) * np.heaviside(ra, 1) * np.exp(
                    -2 * np.pi * 1j * wfe_gen / lam)

    # normalize this amplitude to unit intensity
    aperture1_common = aperture1_id_norm + aperture1_ab_norm
    amplitude_temp = np.sum(aperture1_common)

    # choose initial amplitude imaginary part because of degeneracy
    a0_imag = amplitude_temp.imag