Q = 1
PQ = (2 * P + 1) * (2 * Q + 1)

# ============== build high resolution waveguide array, non-dispersive ==================
Nx = 512
Ny = 512

## ======================== run band structure calc ==========================##
kx_scan = np.linspace(1e-1, np.pi, 200) / ax
eps_tracker = []
omega_eig_store = []
omega_p = 0.72 * np.pi * 1e15
gamma = 5.5e12
for beta_x in kx_scan:
    beta_y = 0
    Kx, Ky = km.K_matrix_cubic_2D(beta_x, beta_y, ax, ay, P, Q)

    #from here, we can actually dtermine omega from our specification of kx and ky
    # omega = c0*np.sqrt(beta_x**2+beta_y**2)/L0;
    #
    # ## we can do a determination of a dispersive medium from here
    # #drude for example
    #eps_drude = 1-omega_p**2/(omega**2-cmath.sqrt(-1)*gamma*omega);
    #print(eps_drude); eps_tracker.append(eps_drude);

    epsilon = np.ones((Nx, Ny))
    halfy = int(Ny / 2)
    epsilon[halfy - 100:halfy + 100, :] = 12

    ## =============== Convolution Matrices ==============
    E_r = cm.convmat2D(epsilon, P, Q)
## =============== Convolution Matrices ==============
E_r = cm.convmat2D(A, P,Q)
print(E_r.shape)
print(type(E_r))
plt.figure();
plt.imshow(abs(E_r), cmap = 'jet');
plt.colorbar()
plt.show()

## =============== K Matrices =========================
beta_x = beta_y = 0;
plt.figure();

## check K-matrices for normal icnidence
Kx, Ky = km.K_matrix_cubic_2D(0,0, a, a, P, Q);
np.set_printoptions(precision = 3)

print(Kx.todense())
print(Ky.todense())

band_cutoff = PQ; #number of bands to plot
## ======================== run band structure calc ==========================##
kx_scan = np.linspace(-np.pi, np.pi, 500)/a;
kx_mat = np.repeat(np.expand_dims(kx_scan, axis = 1), PQ,axis = 1)

eig_store = []
for beta_x in kx_scan:
    beta_y = beta_x;
    Kx, Ky = km.K_matrix_cubic_2D(beta_x, beta_y, a, a, P, Q);
    eigenvalues, eigenvectors, A_matrix = eg.PWEM2D_TE(Kx, Ky, E_r);