def read_beam_file(file_name): """ Reads a Zemax Beam File and returns the Irradiance of the Magnetic field E """ beamData = readBeamFile(file_name) (version, (nx, ny), ispol, units, (dx, dy), (zposition_x, zposition_y), (rayleigh_x, rayleigh_y), (waist_x, waist_y), lamda, index, re, se, (x_matrix, y_matrix), (Ex_real, Ex_imag, Ey_real, Ey_imag)) = beamData E_real = np.array([Ex_real, Ey_real]) E_imag = np.array([Ex_imag, Ey_imag]) re = np.linalg.norm(E_real, axis=0) im = np.linalg.norm(E_imag, axis=0) irradiance = (re**2 + im**2).T power = np.sum(irradiance) print('Total Power: ', power) return (nx, ny), (dx, dy), irradiance, power
def read_beam_file(file_name, mode='irradiance'): """ Reads a Zemax Beam File and returns either the Irradiance or the Phase of the Magnetic field E """ beamData = readBeamFile(file_name) (version, (nx, ny), ispol, units, (dx, dy), (zposition_x, zposition_y), (rayleigh_x, rayleigh_y), (waist_x, waist_y), lamda, index, re, se, (x_matrix, y_matrix), (Ex_real, Ex_imag, Ey_real, Ey_imag)) = beamData area = (1e-3 * nx * dx) * (1e-3 * ny * dy) E = np.array([Ex_real, Ey_real, Ex_imag, Ey_imag]) E_real = np.array([Ex_real, Ey_real]) E_imag = np.array([Ex_imag, Ey_imag]) re = np.linalg.norm(E_real, axis=0) im = np.linalg.norm(E_imag, axis=0) #FIXME why are the arrays flipped? if mode == 'irradiance': irradiance = (re**2 + im**2).T power = np.sum(irradiance) print('Total Power: ', power) return (nx, ny), (dx, dy), irradiance, power if mode == 'phase': phase = np.arctan2(im, re).T return (nx, ny), (dx, dy), phase if mode == 'both': irradiance = (re**2 + im**2).T power = np.sum(irradiance) print('Total Power: ', power) phase_imag = np.arctan2(Ey_imag, Ex_imag) phase_real = np.arctan2(Ey_real, Ex_real) # phase = np.arctan2(im, re).T phase = (phase_imag - phase_real).T return (nx, ny), (dx, dy), irradiance, power, E
lamda = 0.00055 index = 1.0 receiver_eff = 0 system_eff = 0 beamfilename = directory+os.path.sep+"pikachu2.zbf" # Write the beam file writeBeamFile(beamfilename, version, n, ispol, units, d, zposition, rayleigh, waist, lamda, index, receiver_eff, system_eff, efield) print("Done writing the beam file") time.sleep(0.5) # Read the beamfile just created and display beamData = readBeamFile(beamfilename) (version, (nx, ny), ispol, units, (dx,dy), (zposition_x, zposition_y), (rayleigh_x, rayleigh_y), (waist_x, waist_y), lamda, index, receiver_eff, system_eff, (x_matrix, y_matrix), (Ex_real, Ex_imag, Ey_real, Ey_imag)) = beamData xlabels = [-nx*dx/2+x*dx for x in range(0, nx)] ylabels = [-ny*dy/2+y*dy for y in range(0, ny)] fig, ax = plt.subplots() cs = ax.contourf(xlabels, ylabels, Ex_real, cmap="Blues", alpha=0.66) ax.set_aspect('equal') ax.set_xlabel("X position (mm)") ax.set_ylabel("Y position (mm)") print("\n")