def plot_Pgg(self, EGeV, P, axis=0, plot_all=False, filename=None, plot_one=True, EcritLabel='', y0=1e-3, y1=1.1, loc=3): """ Plot the transfer function Arguments --------- EGeV: m-dim array with energies in GeV P: nxm-dim array with transfer function kwargs ------ axis: int, axis with B-field realisations (if more than one, only used if n > 1) plot_all: bool, if true, plot all realizations of transfer function plot_one: bool, if true, plot one realization of transfer function y0: float, min of y-axis of main plot y1: float, max of y-axis of main plot loc: int, location of legend """ import matplotlib.pyplot as plt fig = plt.figure() ax = plt.subplot(111) ax2 = fig.add_axes([0.2, 0.2, 0.4, 0.4]) # left bottom width height try: self.scenario.index('ICM') Ecrit = self.EcritAve() except ValueError: Ecrit = Ecrit_GeV(self.m, self.kwargs['n'], self.kwargs['B'], self.g) imin = np.argmin(np.abs(EGeV - Ecrit)) for i, a in enumerate([ax, ax2]): a.set_xscale('log') a.set_yscale('log') if len(P.shape) > 1: MedCon = median_contours(P, axis=axis) a.fill_between(EGeV, MedCon['conf_95'][0], y2=MedCon['conf_95'][1], color=plt.cm.Greens(0.8)) a.fill_between(EGeV, MedCon['conf_68'][0], y2=MedCon['conf_68'][1], color=plt.cm.Greens(0.5)) if plot_one: a.plot(EGeV, P[0], ls='-', color='0.', label='$P_{\gamma\gamma}$, one realization', lw=2) if plot_all: for i in range(1, P.shape[axis]): a.plot(EGeV, P[i], ls=':', color='0.', lw=1) ymin = ceil(np.log10(MedCon['median'][imin])) - 0.3 ymax = ceil(np.log10(MedCon['median'][imin])) else: a.plot(EGeV, P, ls='-', color='0.', label='$P_{\gamma\gamma}$') ymin = ceil(np.log10(P[imin])) - 0.3 ymax = ceil(np.log10(P[imin])) a.axvline(Ecrit, ls='--', color='0.', lw=1., label=r'$E_\mathrm{{crit}}^\mathrm{{{0:s}}}$'.format( EcritLabel)) a.plot(EGeV, np.exp(-1. * self.ebl_norm * self.tau.opt_depth_array(self.z, EGeV / 1e3)[0]), ls='-', color='red', lw=2., label=r'$\exp(-\tau)$') if not i: a.legend(loc=loc, fontsize='small') v = a.axis([EGeV[0], EGeV[-1], y0, y1]) ax.set_xlabel("Energy (GeV)") ax.set_ylabel("Photon survival probability") else: xmin = np.log10(Ecrit) - 0.5 xmax = np.log10(Ecrit) + 0.5 a.axis([10.**xmin, 10.**xmax, 10.**ymin, 10.**ymax]) if not filename == None: plt.savefig(filename + '.pdf', format='pdf') plt.savefig(filename + '.png', format='png') plt.show() return ax, ax2
Pu = np.zeros((cc.nsim, EGeV.shape[0])) Pa = np.zeros((cc.nsim, EGeV.shape[0])) # calculate the mixing, nsim > 0 only if ICM or IGM are included for i in range(cc.nsim): try: cc.scenario.index('Jet') new_angles = False except ValueError: new_angles = True # calculate the mixing for all energies. If new_angles = True, # new random angles will be generated for each random realizatioin Pt[i], Pu[i], Pa[i] = cc.calc_conversion(EGeV, new_angles=new_angles) # calculate the median and 68% and 95% confidence contours MedCon = median_contours(Pt + Pu) # plot the results plt.figure() ax = plt.subplot(111) ax.set_xscale("log") ax.set_yscale("log") # plot the contours if we are dealing with many realizations if cc.nsim > 1: plt.fill_between(EGeV, MedCon['conf_95'][0], y2=MedCon['conf_95'][1], color=plt.cm.Greens(0.8)) plt.fill_between(EGeV, MedCon['conf_68'][0],
def plot_Pgg(self, EGeV, P, axis = 0, plot_all = False, filename = None, plot_one = True, EcritLabel = '', y0 = 1e-3, y1 = 1.1, loc = 3): """ Plot the transfer function Arguments --------- EGeV: m-dim array with energies in GeV P: nxm-dim array with transfer function kwargs ------ axis: int, axis with B-field realisations (if more than one, only used if n > 1) plot_all: bool, if true, plot all realizations of transfer function plot_one: bool, if true, plot one realization of transfer function y0: float, min of y-axis of main plot y1: float, max of y-axis of main plot loc: int, location of legend """ import matplotlib.pyplot as plt fig = plt.figure() ax = plt.subplot(111) ax2 = fig.add_axes([0.2, 0.2, 0.4, 0.4]) # left bottom width height try: self.scenario.index('ICM') Ecrit = self.EcritAve() except ValueError: Ecrit = Ecrit_GeV(self.m,self.kwargs['n'],self.kwargs['B'],self.g) imin = np.argmin(np.abs(EGeV - Ecrit)) for i,a in enumerate([ax,ax2]): a.set_xscale('log') a.set_yscale('log') if len(P.shape) > 1: MedCon = median_contours(P, axis = axis) a.fill_between(EGeV,MedCon['conf_95'][0],y2 = MedCon['conf_95'][1], color = plt.cm.Greens(0.8)) a.fill_between(EGeV,MedCon['conf_68'][0],y2 = MedCon['conf_68'][1], color = plt.cm.Greens(0.5)) if plot_one: a.plot(EGeV,P[0], ls = '-', color = '0.', label = '$P_{\gamma\gamma}$, one realization', lw = 2) if plot_all: for i in range(1,P.shape[axis]): a.plot(EGeV,P[i], ls = ':', color = '0.', lw = 1) ymin = ceil(np.log10(MedCon['median'][imin])) - 0.3 ymax = ceil(np.log10(MedCon['median'][imin])) else: a.plot(EGeV,P, ls = '-', color = '0.', label = '$P_{\gamma\gamma}$') ymin = ceil(np.log10(P[imin])) - 0.3 ymax = ceil(np.log10(P[imin])) a.axvline(Ecrit, ls = '--', color = '0.',lw = 1., label = r'$E_\mathrm{{crit}}^\mathrm{{{0:s}}}$'.format(EcritLabel) ) a.plot(EGeV,np.exp(-1. * self.ebl_norm * self.tau.opt_depth_array(self.z,EGeV / 1e3)[0]), ls = '-', color = 'red', lw = 2.,label = r'$\exp(-\tau)$') if not i: a.legend(loc = loc, fontsize = 'small') v = a.axis([EGeV[0],EGeV[-1],y0,y1]) ax.set_xlabel("Energy (GeV)") ax.set_ylabel("Photon survival probability") else: xmin = np.log10(Ecrit) - 0.5 xmax = np.log10(Ecrit) + 0.5 a.axis([10.**xmin,10.**xmax,10.**ymin,10.**ymax]) if not filename == None: plt.savefig(filename + '.pdf', format = 'pdf') plt.savefig(filename + '.png', format = 'png') plt.show() return ax,ax2
Pu = np.zeros((cc.nsim,EGeV.shape[0])) Pa = np.zeros((cc.nsim,EGeV.shape[0])) # calculate the mixing, nsim > 0 only if ICM or IGM are included for i in range(cc.nsim): try: cc.scenario.index('Jet') new_angles = False except ValueError: new_angles = True # calculate the mixing for all energies. If new_angles = True, # new random angles will be generated for each random realizatioin Pt[i],Pu[i],Pa[i] = cc.calc_conversion(EGeV, new_angles = new_angles) # calculate the median and 68% and 95% confidence contours MedCon = median_contours(Pt + Pu) # plot the results plt.figure() ax = plt.subplot(111) ax.set_xscale("log") ax.set_yscale("log") # plot the contours if we are dealing with many realizations if cc.nsim > 1: plt.fill_between(EGeV,MedCon['conf_95'][0],y2 = MedCon['conf_95'][1], color = plt.cm.Greens(0.8)) plt.fill_between(EGeV,MedCon['conf_68'][0],y2 = MedCon['conf_68'][1], color = plt.cm.Greens(0.5)) plt.plot(EGeV,MedCon['median'], ls = '-', color = 'gold', label = 'median') label = 'one realization' else: label = 'w/ ALPs'