def wavefront(rays, Nx, Ny, method='cubic', polar=False): """ Interpolate the beam slopes and then integrate the wavefront. Rays assumed to be in the XY plane. """ #Interpolate slopes to regular grid y, dx, dy = interpolateVec(rays, 5, Nx, Ny, method=method, polar=polar) x, dx, dy = interpolateVec(rays, 4, Nx, Ny, method=method, polar=polar) #Prepare arrays for integration #Reconstruct requires nans be replaced by 100 #Fortran functions require arrays to be packed in #fortran contiguous mode x = man.padRect(x) y = man.padRect(y) phase = np.zeros(np.shape(x), order='F') phase[np.isnan(x)] = 100. x[np.isnan(x)] = 100. y[np.isnan(y)] = 100. y = np.array(y, order='F') x = np.array(x, order='F') #Reconstruct and remove border phase = reconstruct.reconstruct(y, x, 1e-12, dx, phase) phase[phase == 100] = np.nan x[x == 100] = np.nan y[y == 100] = np.nan return phase[1:-1, 1:-1], x[1:-1, 1:-1], y[1:-1, 1:-1]
def shift_image(img, xshift, yshift): ysize, xsize = shape(img) buffer_ind = max([xshift, yshift]) expand_img = man.padRect(img, buffer_ind) shift_img = expand_img[buffer_ind - yshift:buffer_ind + ysize - yshift, buffer_ind - xshift:buffer_ind + xsize - xshift] shift_img[isnan(shift_img)] = 0.0 return shift_img
def littrow(): """ Trace rectangular beam into OPG in Littrow. 400 nm groove period 8.4 m groove convergence """ #Set up beam rays = sources.rectArray(50., 50., 1e2) #Trace to Littrow and diffract tran.transform(rays, 0, 0, 0, 0, 52.28 * np.pi / 180, 0) surf.flat(rays) tran.transform(rays, 0, 8400., 0, 0, 0, 0) tran.radgrat(rays, 400. / 8400., 1, 632.8) #Steer out beam tilt tran.steerX(rays) tran.steerY(rays) #Bring rays to common plane surf.flat(rays) #Interpolate slopes to regular grid y, dx, dy = anal.interpolateVec(rays, 5, 200, 200) x, dx, dy = anal.interpolateVec(rays, 4, 200, 200) #Prepare arrays for integration #Reconstruct requires nans be replaced by 100 #Fortran functions require arrays to be packed in #fortran contiguous mode x = man.padRect(x) y = man.padRect(y) phase = np.zeros(np.shape(x), order='F') phase[np.isnan(x)] = 100. x[np.isnan(x)] = 100. y[np.isnan(y)] = 100. y = np.array(y, order='F') x = np.array(x, order='F') #Reconstruct and remove border phase = reconstruct.reconstruct(x, y, 1e-12, dx, phase) phase[phase == 100] = np.nan x[x == 100] = np.nan y[y == 100] = np.nan return man.stripnans(phase), man.stripnans(x), man.stripnans(y)
def make_aligned_images(measimg, simimg, final_size=[400, 200, 200, 200], offset=18): simimg = flipud(simimg) simimg_padded = man.padRect(simimg, 1300) simimg_padded[isnan(simimg_padded)] = 0.0 meas_profile_x, meas_profile_y = sum(measimg, axis=0), sum(measimg, axis=1) meas_xCoM, meas_yCoM = get_CoM_img(measimg) sim_xCoM, sim_yCoM = get_CoM_img(simimg_padded) #pdb.set_trace() meas_xCoM, meas_yCoM, sim_xCoM, sim_yCoM = int(meas_xCoM), int( meas_yCoM), int(sim_xCoM), int(sim_yCoM) - offset cut_meas_img = measimg[meas_yCoM - final_size[0]:meas_yCoM + final_size[1], meas_xCoM - final_size[2]:meas_xCoM + final_size[3]] cut_sim_img = simimg_padded[sim_yCoM - final_size[0]:sim_yCoM + final_size[1], sim_xCoM - final_size[2]:sim_xCoM + final_size[3]] return rot90(cut_meas_img), rot90(cut_sim_img)