from Smilei import *

S = Smilei(".", verbose=False)

ncel = [int(i) for i in S._ncels]

# SCALARS RELATED TO MIN/MAX OF FIELDS
for field in [
        "Ex", "Ey", "Ez", "Bx_m", "By_m", "Bz_m", "Jx", "Jy", "Jz", "Rho"
]:
    if field in ["Ex", "Rho"]:
        precision = 0.25
    else:
        precision = 0.025
    Validate("Minimum of scalar " + field,
             S.Scalar(field + "Min").getData()[-1], precision)
    Validate("Maximum of scalar " + field,
             S.Scalar(field + "Max").getData()[-1], precision)

    MinLoc = np.unravel_index(int(S.Scalar(field + "MinCell").getData()[-1]),
                              ncel)
    MaxLoc = np.unravel_index(int(S.Scalar(field + "MaxCell").getData()[-1]),
                              ncel)
    Validate("Location of minimum of scalar " + field, MinLoc, 10)
    Validate("Location of maximum of scalar " + field, MaxLoc, 10)

# FIELD DIAGNOSTICS
fields = [
    "Ex", "Ey", "Ez", "Bx", "By", "Bz", "Bx_m", "By_m", "Bz_m", "Jx", "Jy",
    "Jz", "Rho", "Jx_test0", "Jy_test0", "Jz_test0", "Rho_test0"
]
# Open results

res_Boris = Smilei("./tst3d_cir_plane_wave_Boris")
res_Vay = Smilei("./tst3d_cir_plane_wave_Vay")
res_HC = Smilei("./tst3d_cir_plane_wave_HC")

# ________________________________________________
# Parameters

#a0 = res_Boris.namelist.LaserGaussian3D[0].a0
a0 = 2.

# _________________________________________
# Scalar

Ukin = res_Boris.Scalar("Ukin").get()
Ukin_Vay = res_Vay.Scalar("Ukin").get()
Ukin_HC = res_HC.Scalar("Ukin").get()

fig = plt.figure(figsize=(12, 6))
gs = gridspec.GridSpec(2, 2)
ax = plt.subplot(gs[:, :])

#print scalar_HC["times"],scalar_HC["data"]

#Ukin["data"] = np.array(Ukin["data"])/(192.*1e-8)
#Ukin_Vay["data"] = np.array(Ukin_Vay["data"])/(192.*1e-8)
#Ukin_HC["data"] = np.array(Ukin_HC["data"])/(192.*1e-8)

ax.plot(Ukin["times"],
        Ukin["data"],