from yt.mods import *
import matplotlib.pyplot as plt

# Get the first sphere

pf = load("RedshiftOutput0002")

vl=pf["RefineRegionLeftEdge"]
vr=pf["RefineRegionRightEdge"]
sv = pf.h.region((vl+vr)/2, vl, vr)
#sphere = pf.h.sphere(pf.domain_center, (.5, "1"))

# Radial profile 

#kmax=sv["H2I_kdiss"].max()
#kmin=sv["H2I_kdiss"].min() 
kmin=1.0e-13
kmax=1.0e-08

rad_profile = BinnedProfile1D(sv, 300, "H2I_kdiss", kmin, kmax, log_space=True,lazy_reader=True,end_collect=True)
rad_profile.add_fields("CellVolumeMpc",weight=None,accumulation=True)
rad_profile.add_fields("CellMassMsun",weight=None,accumulation=True)
rad_profile.write_out('H2_diss_Histogram_c.txt')
del rad_profile

#rad_profile = BinnedProfile1D(sv, 300, "Metallicity", 1e-8, 1.0, log_space=True,lazy_reader=True,end_collect=True)
#rad_profile.add_fields("CellVolumeMpc",weight=None,accumulation=True)
#rad_profile.add_fields("CellMassMsun",weight=None,accumulation=True)
#rad_profile.write_out('Metallicity_Histogram_c.txt')
#del rad_profile

#rad_profile = BinnedProfile1D(sv, 300, "TotalMetallicity", 1e-8, 1.0, log_space=True,lazy_reader=True,end_collect=True)
#rad_profile.add_fields("CellVolumeMpc",weight=None,accumulation=True)
#rad_profile.add_fields("CellMassMsun",weight=None,accumulation=True)
#rad_profile.write_out('TotalMetallicity_Histogram_c.txt')
#del rad_profile

#fig = plt.figure()
#ax = fig.add_subplot(111)

# Here we scale the velocities by 1.0e5 to get into km/s
#ax.plot(rad_profile["Radiuskpc"], rad_profile["XrayFlux"])

#ax.set_xlabel(r"$\mathrm{r\ (kpc)}$")
#ax.set_ylabel(r"$\mathrm{F_{X}\ (erg/cm^2/s)}$")
#ax.legend(["XrayFlux"])

#fig.savefig("%s_profiles.png" % pf)
