def aeff(self): """ Plot and tabulate Aeff. """ import colormaps as cmaps plt.register_cmap(name='viridis', cmap=cmaps.viridis) plt.set_cmap(cmaps.viridis) logEmin, logEmax = 2., 9. dlogE = 0.1 n_bins_E = (logEmax - logEmin) / dlogE dcz = 0.01 dOmega = 2 * pi * dcz n_bins_cz = 2 / dcz nu = self.nu nu.cz = -np.sin(nu.trueDec) w_aeff = 1 / (1e4 * np.log(10)) * nu.ow / nu.trueE / dOmega / dlogE h_aeff = hl.hist( (nu.trueE, nu.cz), w_aeff, bins=(n_bins_E, n_bins_cz), range=((10**logEmin, 10**logEmax), (-1, 1)), log=(True, False), ) misc.tex_mpl_rc(True) fig = getfig(aspect=4 / 3., width=5) ax = fig.add_subplot(111) fig.subplots_adjust(bottom=.15, left=.15) result = hl.plot2d(ax, h_aeff, cbar=True, log=True, vmin=5e-6, vmax=1e4, zmin=5e-6) result['colorbar'].set_label(r'effective area $[\text{m}^2]$') ax.set_xlabel('neutrino energy [GeV]') ax.set_ylabel(r'$\cos(\text{zenith})$') plot_dir = misc.ensure_dir('{0}/plots'.format(self.mode_dir)) savingfig(fig, plot_dir, 'aeff') bins = h_aeff.bins filename = '{}/aeff.txt'.format(plot_dir) prush('-> {} ...'.format(filename)) with open(filename, 'w') as f: pr = lambda *a, **kw: print(*a, file=f, **kw) pr('# {:>11}{:>13}{:>16}{:>16}{:>16}'.format( 'E_min[GeV]', 'E_max[GeV]', 'cos(zenith)_min', 'cos(zenith)_max', 'Aeff[m^2]')) for (Emin, Emax) in izip(bins[0][:-1], bins[0][1:]): for (czmin, czmax) in izip(bins[1][:-1], bins[1][1:]): pr('{:13.3e}{:13.3e}{:+16.2f}{:+16.2f}{:16.3e}'.format( Emin, Emax, czmin, czmax, h_aeff.get_value(1.001 * Emin, 1e-3 + czmin)))
import matplotlib as mpl mpl.use('pdf') import matplotlib.pyplot as plt import numpy as np import os import scipy.stats as stats from scipy.stats import chi2 from icecube.umdtools import cache,misc from icecube import icetray, dataclasses, histlite from skylab import statistics fitfun = statistics.delta_chi2 ##Make plots prettier misc.tex_mpl_rc() w=4 propsmall = mpl.font_manager.FontProperties (size='small') propxsmall = mpl.font_manager.FontProperties (size='x-small') ###This script imports the sensitivities from the submitter and plots them.### #picklefolder = '/data/user/brelethford/Data/SwiftBAT70m/pickle/' ## Define fcn to read in background trials previously logged ## def getBckg(datafolder): files = [cache.load(datafolder+file) for file in os.listdir(datafolder) if file.endswith('.array')] n_inj=[] nsources=[] TS=[] beta=(0.5) #For background ts TS_beta=[] #Calculated from the total TS median after we get all the TS.
def sd(self): """Plot sensitivity and discovery potential.""" misc.tex_mpl_rc() sig_info = self.sig_info fig = getfig(aspect=16 / 10., width=6) ax = fig.add_subplot(111) nfig = getfig(aspect=16 / 10., width=6) nax = nfig.add_subplot(111) rfig = getfig(aspect=16 / 10., width=6) rax = rfig.add_subplot(111) curves = {} for n_sigma in (0, 5): if n_sigma == 0: thing = 'Sensitivity' CL = 0.9 ls = '--' else: thing = 'Disc. Pot.' CL = 0.5 ls = '-' color = 'b' alpha = .8 label = r'$E^{{-2}}$ {}'.format(thing) x = bk.get_best(sig_info, n_sigma, CL, 2) sin_dec = np.array([np.cos(-k / 180. * pi) for k in sorted(x)]) curve = np.array([x[k][0] for k in sorted(x)]) ncurve = np.array([x[k][1] for k in sorted(x)]) ax.semilogy(sin_dec, curve, label=label, ls=ls, color=color, alpha=alpha, lw=2) nax.plot(sin_dec, ncurve, label=label, ls=ls, color=color, alpha=alpha, lw=2) curves[n_sigma] = sin_dec, curve x, y = np.genfromtxt('{}/etc/orig_sens.txt'.format(self.root_dir)).T label = r'$E^{{-2}}$ Sensitivity (original)'.format() ax.semilogy(x, 1e-3 * y, label=label, ls='--', color='k', alpha=.8, lw=1) rax.plot(curves[0][0], curves[0][1] / np.interp(curves[0][0], x, 1e-3 * y), ls='--', color='k', lw=1, label='Sensitivity ratio') x, y = np.genfromtxt('{}/etc/orig_disc.txt'.format(self.root_dir)).T label = r'$E^{{-2}}$ Disc. Pot. (original)'.format() ax.semilogy(x, 1e-3 * y, label=label, ls='-', color='k', alpha=.8, lw=1) rax.plot(curves[5][0], curves[5][1] / np.interp(curves[5][0], x, 1e-3 * y), ls='-', color='k', lw=1, label='Disc. Pot. ratio') ax.set_xlabel(r'$\sin(\delta)$') nax.set_xlabel(r'$\sin(\delta)$') rax.set_xlabel(r'$\sin(\delta)$') ax.set_ylabel(r'$E^2 ' '\cdot (E/100\,\mathrm{TeV})^{\gamma-2}' '\cdot dN/dE\,\,\,' '[\mathrm{TeV}\,\mathrm{cm}^{-2}\,\mathrm{s}^{-1}]$') nax.set_ylabel(r'$n_\mathrm{inj}$') nax.set_ylabel(r'ratio') ax.grid() legend = ax.legend(loc='upper right', prop=propsmall, handlelength=4, ncol=2) frame = legend.get_frame() frame.set_linewidth(0) nax.grid() legend = nax.legend(loc='upper right', prop=propsmall, handlelength=4, ncol=2) frame = legend.get_frame() frame.set_linewidth(0) rax.set_ylim(0.5, 1.5) rax.grid() legend = rax.legend(loc='best', prop=propsmall, handlelength=4, ncol=2) legend.get_frame().set_linewidth(0) fig.subplots_adjust(bottom=.14, top=.91, right=.97) nfig.subplots_adjust(bottom=.14, top=.91, right=.97) rfig.subplots_adjust(bottom=.14, top=.91, right=.97) plot_dir = misc.ensure_dir('{0}/plots'.format(self.mode_dir)) savingfig(fig, plot_dir, 'sensdisc') savingfig(nfig, plot_dir, 'sensdisc_ninj') savingfig(rfig, plot_dir, 'sensdisc_ratio')