Spaces:
Sleeping
Sleeping
| import astropy.units as u | |
| import pyoptica as po | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| import math | |
| import os | |
| from scipy.fft import fft2, ifft2, fftshift, ifftshift | |
| import aotools.opticalpropagation as op | |
| import scipy.special as sc | |
| import time | |
| import multiprocessing | |
| from multiprocessing import Pool | |
| from zern_generator import generate_zern_wavefront, generate_zern_wavefront_fig | |
| from scipy.ndimage import zoom | |
| fig, (ax1, ax2) = plt.subplots(2,1) | |
| #f2.show() | |
| f = 100 * 10 ** -3 # Форкусное расстояние линзы | |
| radius = 5 * 10 ** -3 # Радиус линзы | |
| span = (-(2*radius), 2*radius) | |
| lens = po.ThinLens(radius, f) | |
| z = 100 * 10 ** -3 # Расстояние | |
| wavelength = 500 * 10 ** -9 # Длина волны | |
| pixel_scale = 250 * 10 ** -4 # Размер пикселя | |
| npix = 2**9 # Размер сетки | |
| ddx = np.linspace(*span, npix) | |
| ddy = np.linspace(*span, npix) | |
| xv, yv = np.meshgrid(ddx, ddy) | |
| f2 = generate_zern_wavefront(xv, yv, [0,0,0,1,0,0], norm_radius=radius) | |
| dist_from_center = np.sqrt(xv**2 + yv**2) | |
| mask = dist_from_center <= radius | |
| f2[mask==0] = 0 | |
| f2[np.isnan(f2)] = 0 | |
| k = 2*math.pi/wavelength | |
| wf = np.zeros((npix, npix), dtype=np.complex64) | |
| wf[mask] = 1 + 0j | |
| wf += f2 * 1j | |
| wf = fftshift(fft2(wf)) | |
| phase_mul = ((np.exp(1j*k*z) * np.exp(1j*k*(xv**2 + yv**2)/(2*z)))/(1j*wavelength*z)) | |
| #wf = wf * phase_mul | |
| wf= np.abs(wf)**2 | |
| #wf = np.log10(wf) | |
| crop = 20 | |
| center = npix//2 | |
| vx = np.linspace(*span, npix) | |
| ax1.imshow(wf, extent = (*span, *span), cmap="gray") | |
| #ax2.plot(vx, wf[npix//2]) | |
| ax2.imshow(f2, extent = (*span, *span),cmap="gray") | |
| print(np.ptp(wf)) | |
| plt.show() | |
| # amp = np.array(wf.amplitude) | |
| # a = fftshift(fft2(wf.amplitude)) | |
| # a = np.abs(a)**2 | |
| # print(a) | |
| # ax.imshow(a, extent=(-npix*pixel_scale/2, npix*pixel_scale/2,-npix*pixel_scale/2, npix*pixel_scale/2)) | |
| # plt.show() | |
| # # Двойной интеграл из 4.13 | |
| # def calc_point_fourier(x,y, uxy): | |
| # res = 0 + 0j | |
| # for x0 in range(npix): | |
| # x_r = to_real(x0) | |
| # for y0 in range(npix): | |
| # y_r = to_real(y0) | |
| # res += uxy * np.exp(-1j*k*(x*x_r + y*y_r)/z) | |
| # return res | |
| # # Считает точку по 4.13 | |
| # def calc_point(x,y): | |
| # x_r = to_real(x) | |
| # y_r = to_real(y) | |
| # if y%100 == 1: | |
| # os.system('cls') | |
| # print(f"{npix*x + y}/{npix**2}") | |
| # return ((np.exp(1j*k*z) * np.exp(1j*k*(x_r**2 + y_r**2)/(2*z)))/(1j*wavelength*z)) * calc_point_fourier(x_r, y_r, amp[x][y]) | |
| # if __name__ == "__main__": | |
| # pairs = [] | |
| # for x in range(npix): | |
| # for y in range(npix): | |
| # pairs.append((x,y)) | |
| # multiprocessing.freeze_support() | |
| # with Pool(20) as p: | |
| # res = p.starmap_async(calc_point, pairs) | |
| # a = res.get() | |
| # a = np.abs(a)**2 | |
| # a = a.reshape((npix, npix)) | |
| # a /= np.max(a) | |
| # ax.imshow(a, extent=(-npix*pixel_scale/2, npix*pixel_scale/2,-npix*pixel_scale/2, npix*pixel_scale/2)) | |
| # plt.show() | |
| try: | |
| pass | |
| except KeyError: | |