import matplotlib
matplotlib.use('Agg')
from pylab import *
from irfpy.cena import energy
from irfpy.cena import gfactor
if __name__ == '__main__':
# Obtain the energy in electron volts, as np.array with dimension of [16]
energy_in_eV = energy.getEnergyE16()
# Table-based energy dependent g-factor.
gf0 = gfactor.GFactorH_Table()
gf0.energyDependentGfactor()
g0 = gf0.energyDependentGfactor()
# Component-aggregated energy dependent g-factor.
gf1 = gfactor.GFactorH_Component()
gf1.energyDependentGfactor()
g1 = gf1.energyDependentGfactor()
diff_percent = 100 * (g1 - g0) / g0
print(diff_percent)
# Plot to show.
fig = figure()
ax = fig.add_subplot(111)
p0 = ax.plot(energy_in_eV, g0, 'o', label='Table 3.5')
p1 = ax.plot(energy_in_eV, g1, label='Eq 3.19')
for i in range(len(diff_percent)):
if not ma.is_masked(diff_percent[i]):
ax.text(energy_in_eV[i], g0[i], ' %.1f%%' % diff_percent[i],
verticalalignment='center', rotation=-10)
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel('Energy')
ax.set_ylabel('Ene-dep-GFACTOR (G_i^H)')
ax.legend(loc='upper left')
fig.savefig('cena_ene_gfactor.png')