In [1]:
import yaml
import matplotlib.pyplot
import numpy as np
from astropy.table import Table, join
from haloanalysis.sed import SED
from haloanalysis.utils import load_source_rows
from ebltable.tau_from_model import OptDepth
from fermipy.spectrum import PLExpCutoff
from collections import OrderedDict
from haloanalysis import model
import matplotlib.patches as mpatches
from os import path

In [2]:
%matplotlib inline

In [29]:
cfile = '../config/igmf_analysis/test.yaml'
cfile = '../config/igmf_analysis/elmag_1e1.yaml'
#cfile = '../config/igmf_analysis/analytic_1e7.yaml'
#cfile = '../config/igmf_analysis/elmag_1e4.yaml'
cfile = '../config/igmf_analysis/elmag_1e7.yaml'

In [30]:
config = yaml.load(open(cfile))

In [31]:
outfile = path.join(config['outdir'],'fit_igmf_th_jet{0[th_jet]:.0f}_tmax{0[tmax]:.0e}_lp_{0[kind]:s}_combined.fits'.format(config))

In [32]:
if config['int_spec'] == 'PLExpCutOff':
    fint = sp.PLExpCutoff  # intrinsic spectrum
elif config['int_spec'] == 'LogParabolaExpCutoff':
    fint = model.LogParabolaExpCutoff  # intrinsic spectrum
scale = 1e3

Load the results


In [33]:
results = Table.read(outfile)
tab_sed_tev = Table.read(config['cat_tev'])

tables = [Table.read(config['cat'],'CATALOG'),
    Table.read(config['cat'],'LIKELIHOOD'),
    Table.read(config['cat'],'SED')]
tab_casc = join(tables[0],tables[1])
tab_casc = join(tab_casc,tables[2])

tab_pars = Table.read(config['cat'],hdu='SCAN_PARS')
tab_ebounds = Table.read(config['cat'],hdu='EBOUNDS')

In [34]:
results


Out[34]:
<Table length=15>
nameSOURCE_FULLassocredshiftdloglike [17,17]loglike_comp [17,17,3]prim_tev_emin [1,1,25]prim_tev_ectr [1,1,25]prim_tev_emax [1,1,25]prim_tev_flux [17,17,25]prim_flux [17,17,20]casc_flux [17,17,20]casc_r68 [17,17,20]src_fit_pars [17,17,4]lcoh [17,1]igmf [1,17]halo_flux_ul [17,17,20]
str32str32str32str32float64float64float64float64float64float64float64float64float64float64float64float64float64
FHES J0232.8+20181ES0229+200_HESS_2005-20061ES 0229+2000.14-52.4291880159 .. -0.073362816672643.0441571345 .. -0.0230796361639493951.031046 .. nan598414.0 .. nan724969.263932 .. nan5.21320336638e-13 .. nan3.76250813366e-11 .. 1.28981988646e-122.10734684736e-10 .. 1.03697378612e-132.3122023126e-05 .. 0.234729315341.41667473265e-13 .. 999999751.008-4.0 .. 4.0-20.0 .. -12.01e-09 .. 5.1709202429e-12
FHES J0232.8+20181ES0229+200_VERITAS_2009-20121ES 0229+2000.14-32.8397349181 .. -0.056250586473331.3096611613 .. -0.0490786933406240229.062234 .. nan291000.0 .. nan352501.063828 .. nan1.46578207052e-12 .. nan4.50536064095e-11 .. 1.15689306991e-121.71817042491e-10 .. 7.02452319081e-142.31218215653e-05 .. 0.2405250755921.70591384611e-13 .. 999999999.993-4.0 .. 4.0-20.0 .. -12.01e-09 .. 5.1709202429e-12
FHES J0349.3-11591ES0347-121_HESS_2006-09-121ES 0347-1210.188-38.489450837 .. -0.14441115937524.3413014946 .. 0.111372099802250013.914993 .. nan302900.0 .. nan366973.214281 .. nan1.80853173154e-12 .. nan4.51052179592e-11 .. 1.50506944735e-121.38199080581e-10 .. 9.04216918742e-142.31213648512e-05 .. 0.210026524311.68417613892e-13 .. 1000000000.0-4.0 .. 4.0-20.0 .. -12.01.95639834352e-11 .. 3.87203878181e-12
FHES J0416.8+01051ES0414+009_VERITAS_2008-20111ES 0414+0090.2870.0579794000216 .. 8.86085746288e-0618.6604851398 .. -0.0886644351306198130.5877 .. nan232800.0 .. nan273535.957417 .. nan4.81479409714e-13 .. nan1.51155396066e-10 .. 2.38942470698e-132.11818795052e-12 .. 2.16637590685e-262.31231080986e-05 .. 0.1722652632865.91109362752e-13 .. 195190.253001-4.0 .. 4.0-20.0 .. -12.01e-09 .. 5.47890117959e-12
FHES J0416.8+01051ES0414+009_HESS_2005-20091ES 0414+0090.287-2.01595323748 .. -0.00034536347166620.1379297559 .. -0.10643830592147864.478694 .. nan170300.0 .. nan196139.669623 .. nan1.77409858214e-12 .. nan1.51325382464e-10 .. 7.43752023997e-137.10459473875e-11 .. 2.95605080373e-152.31218470734e-05 .. 0.169424164425.90026397781e-13 .. 6024791.11912-4.0 .. 4.0-20.0 .. -12.01e-09 .. 6.90551352016e-12
FHES J1010.2-31191RXSJ101015.9-311909_HESS_2006-21RXS J101015.9-3119090.143-1.1139314105 .. 1.32158925794e-0511.2423538385 .. -0.055933297664195151.310157 .. nan277810.0 .. nan395479.774325 .. nan2.42054553036e-12 .. nan1.07426524824e-10 .. 1.00723142879e-124.5783869666e-11 .. 1.055063945e-162.31210923683e-05 .. 0.6938604918854.01441299731e-13 .. 2570838.59983-4.0 .. 4.0-20.0 .. -12.01.64467617799e-11 .. 7.75259748863e-12
FHES J1103.6-23291ES1101-232_HESS_2004-20051ES 1101-2320.186-47.950579597 .. -0.024803187950346.8762850516 .. -0.187297995379222788.607478 .. nan257254.0 .. nan297051.187963 .. nan1.98451557587e-12 .. nan6.65739473351e-11 .. 1.78480587438e-121.75894846566e-10 .. 1.07638689202e-132.31208530392e-05 .. 0.2124116025982.50444922758e-13 .. 352439884.641-4.0 .. 4.0-20.0 .. -12.01e-09 .. 5.1709202429e-12
FHES J1221.3+30101ES1218+304_VERITAS_2008-2009PG 1218+3040.182-94.3858654712 .. 0.012999348772622.1115739009 .. -0.229615650308173779.7141 .. nan199526.0 .. nan229086.719829 .. nan9.6696027233e-12 .. nan5.27458748693e-10 .. 6.21626767265e-128.15173633023e-10 .. 5.2711714242e-142.31220187201e-05 .. 0.2446458810511.97629389311e-12 .. 313754321.521-4.0 .. 4.0-20.0 .. -12.03.91710149081e-11 .. 1.23155060329e-11
FHES J1221.3+30101ES1218+304_VERITAS_2007PG 1218+3040.182-32.5776962354 .. 0.097078825334738.2489070036 .. -0.191315282858156925.161068 .. nan186506.0 .. nan221662.911156 .. nan1.23955816782e-11 .. nan5.40196886912e-10 .. 5.62236308402e-125.00659542622e-10 .. 9.45638905159e-152.31212137227e-05 .. 0.3113055447262.01791982802e-12 .. 8992404.04008-4.0 .. 4.0-20.0 .. -12.03.91710149081e-11 .. 9.77124153535e-12
FHES J1315.0-42361ES1312-423_HESS_2004-2010MS 13121-42210.105-3.77784658146 .. 0.0003994155542273.78355932318 .. -0.0964154804175270308.914191 .. nan366000.0 .. nan495566.342683 .. nan1.0704495797e-12 .. nan4.94224900959e-11 .. 7.77655879694e-134.64059734671e-11 .. 5.58809418964e-162.31254087461e-05 .. 0.8548234126051.84588803429e-13 .. 4789600.73822-4.0 .. 4.0-20.0 .. -12.07.40195999692e-11 .. 9.77124153535e-12
FHES J1428.5+4240H1426+428_HEGRA_1999_2000H 1426+4280.129-38.5075046034 .. -0.46151503279759.5878530665 .. 0.351657527953566253.691593 .. nan780000.0 .. nan1074430.08149 .. nan2.1383541001e-13 .. nan9.78912316243e-11 .. 3.81385096045e-121.91801727302e-11 .. 3.20590242268e-132.31357268363e-05 .. 0.2706721969873.67379692449e-13 .. 991610364.109-4.0 .. 4.0-20.0 .. -12.01e-09 .. 2.89942285388e-12
FHES J1428.5+4240H1426+428_HEGRA_2002H 1426+4280.129-25.0160291161 .. -0.097965935651639.9080501193 .. 0.0191966534976566253.691593 .. nan780000.0 .. nan1074430.08149 .. nan5.3290306289e-13 .. nan1.09672970399e-10 .. 2.1617073372e-127.28888792792e-11 .. 6.8609754952e-142.3127885353e-05 .. 0.3092149969224.17276499499e-13 .. 123529381.252-4.0 .. 4.0-20.0 .. -12.01e-09 .. 3.25508859984e-12
FHES J2359.1-3038H2356-309_HESS_2006H 2356-3090.165-2.47260273602 .. 2.6925025054e-073.57875072313 .. -0.13088580146189818.003423 .. nan253205.0 .. nan337759.173887 .. nan1.82963915314e-12 .. nan1.12478452782e-10 .. 8.34883613073e-135.0546415571e-11 .. 5.88931963968e-162.31208249008e-05 .. 0.4969638103094.38571324144e-13 .. 3044898.77746-4.0 .. 4.0-20.0 .. -12.01e-09 .. 5.80522551609e-12
FHES J2359.1-3038H2356-309_HESS_2005H 2356-3090.165-9.92026552136 .. -0.010252285891327.6993558821 .. -0.137908532772197999.750647 .. nan228712.0 .. nan264188.105152 .. nan1.17651960069e-12 .. nan1.0778253832e-10 .. 9.12966965939e-138.16729949799e-11 .. 2.19810843583e-142.31210050636e-05 .. 0.2574796784514.19205755745e-13 .. 999999999.999-4.0 .. 4.0-20.0 .. -12.01e-09 .. 5.80522551609e-12
FHES J2359.1-3038H2356-309_HESS_2004H 2356-3090.165-20.6621715744 .. -0.039424342751628.7755527431 .. -0.110749963091198032.226132 .. nan228749.0 .. nan264230.25193 .. nan1.74031984064e-12 .. nan9.36921330528e-11 .. 1.3351024046e-121.26705787881e-10 .. 4.77058997401e-142.31209484776e-05 .. 0.2527683083793.59163441752e-13 .. 905689290.71-4.0 .. 4.0-20.0 .. -12.01e-09 .. 5.80522551609e-12

print the best fit results


In [35]:
idL, idB = 0,0
for isource, fit_pars in enumerate(results['src_fit_pars']):
    print results['SOURCE_FULL'][isource], fit_pars[idL,idB]


1ES0229+200_HESS_2005-2006 [  1.41667473e-13  -1.56486826e+00   3.23704681e-13   5.28165652e+06]
1ES0229+200_VERITAS_2009-2012 [  1.70591385e-13  -1.60466881e+00   2.13102022e-12   4.48326717e+06]
1ES0347-121_HESS_2006-09-12 [  1.68417614e-13  -1.50000000e+00   5.99973055e-15   1.21153629e+06]
1ES0414+009_VERITAS_2008-2011 [  5.91109363e-13  -1.79610383e+00   3.30484827e-05   1.95190253e+05]
1ES0414+009_HESS_2005-2009 [  5.90026398e-13  -1.81183385e+00   4.82857114e-16   1.49564120e+06]
1RXSJ101015.9-311909_HESS_2006-2 [  4.01441300e-13  -1.50000000e+00   4.92343600e-02   2.57081235e+06]
1ES1101-232_HESS_2004-2005 [  2.50444923e-13  -1.55464608e+00   7.26632210e-09   1.51040044e+06]
1ES1218+304_VERITAS_2008-2009 [  1.97629389e-12  -1.52424231e+00   3.78640284e-02   3.13744804e+08]
1ES1218+304_VERITAS_2007 [  2.01791983e-12  -1.50047931e+00   4.50230264e-02   8.99240271e+06]
1ES1312-423_HESS_2004-2010 [  1.84588803e-13  -1.50000483e+00   3.71323826e-02   4.78958214e+06]
H1426+428_HEGRA_1999_2000 [  3.67379692e-13  -1.51571285e+00   8.85660484e-11   3.00924184e+05]
H1426+428_HEGRA_2002 [  4.17276499e-13  -1.63116814e+00   9.23329643e-15   8.33284673e+05]
H2356-309_HESS_2006 [  4.38571324e-13  -1.81248648e+00   3.05480041e-06   1.63224415e+06]
H2356-309_HESS_2005 [  4.19205756e-13  -1.79645082e+00   1.33207744e-18   2.80792074e+06]
H2356-309_HESS_2004 [  3.59163442e-13  -1.69129608e+00   3.46448212e-12   2.20812722e+06]

In [36]:
tau = OptDepth.readmodel(model = config['ebl_model'])
EMeV = np.logspace(3,8,200)

General plotting stuff


In [37]:
cp = plt.cm.afmhot
idL = 8 # coh length = 1 Mpc

Loop through sources and plot the source SEDs


In [38]:
for isource in range(results['SOURCE_FULL'].shape[0]):
    ax = plt.subplot(111)
    # select the source
    name = results['SOURCE_FULL'][isource]

    rows_sed_tev = load_source_rows(tab_sed_tev, [name], key='SOURCE_FULL')
    cat_names = [ row['3FGL_NAME'] for row in rows_sed_tev ]
    
    cat_names = np.unique(np.array(cat_names))
    rows_sed_gev = load_source_rows(tab_casc, cat_names, key='name_3fgl')
    rows_casc = load_source_rows(tab_casc, cat_names, key='name_3fgl')

    # load the source SEDs
    sed_Fermi = SED.create_from_row2(rows_sed_gev, tab_ebounds)
    sed_IACT = SED.create_from_row(rows_sed_tev)

    efct_Fermi = sed_Fermi.ectr**2/sed_Fermi.ewidth*1.602177e-06
    efct_IACT = sed_IACT.ectr**2/sed_IACT.ewidth*1.602177e-06

    # plot the SED
    sed_Fermi.plot(label = 'Fermi-LAT PS',
                   color = plt.cm.Blues_r(0.2),
                   mec =  plt.cm.Blues_r(0.2),
                   zorder = 5)
    sed_IACT.plot(label = 'IACT PS', 
                   color = plt.cm.Blues_r(0.5),
                   mec =  plt.cm.Blues_r(0.5),
                   marker = 's', zorder = 5)

    for j,i in enumerate(([0,8,10,12,14,16])): # B field models
    
        icol = j/(6. + 4.) + 0.2
        if not isource: print icol
        plt.plot(sed_Fermi.ectr/1E6, 
             efct_Fermi*results['casc_flux'][isource][idL,i],
             label='$B = 10^{{{0:.1f}}}$ G'.format(
             results['igmf'][isource,0,i]),          
             color = cp(icol),
            lw = 1.5, ls = '-',
            )  
    
        # intrinsic spectrum
        fplot = fint(results['src_fit_pars'][isource,idL,i], scale = scale)
        plt.plot(EMeV / 1e6,
            fplot.e2dfde(EMeV)*1.602177e-06 * \
            np.exp(-1. * tau.opt_depth(results['redshift'][isource], EMeV / 1e6)),
            color = cp(icol),
            ls = '--', lw = 1)

        # Halo Flux UL
        if not i:
            plt.errorbar(sed_Fermi.ectr/1E6,
               results['halo_flux_ul'][isource,idL,i]*efct_Fermi,
               ls = 'none',
               marker = 'v', 
               color = '0.7',
               mec = '0.7',
               uplims = True, zorder = -1, lw = 2,
               alpha = 1.,
               label = 'Halo UL for $B = 10^{{{0:.1f}}}$ G'.format(
                     results['igmf'][isource,0,i]) if not i else ''
               )

    title = '{0:s}; '.format(name.split('_')[0])
    title += '$\lambda = 10^{{{0:.0f}}}\,$Mpc'.format(results['lcoh'][isource,idL,0])
    title += ', $t_\mathrm{{max}} = 10^{0:.0f}$ yrs, $\\theta_\mathrm{{jet}} = {1:.1f}^\circ$'.format(
        np.log10(config['tmax']), config['th_jet'])
    
    #title += '\n{0:s}'.format(" ".join(name.split('_')))

    fname = 'sed_{0:s}_idL{1:n}_tmax{2[tmax]:.0e}_thj{2[th_jet]:.0f}_{2[kind]:s}'.format(name, idL, config)

    plt.legend(loc = 'lower center', fontsize = 'x-small', ncol = 3,
          title = title, fancybox = True, framealpha = 0.9)
    plt.gca().get_legend().get_title().set_fontsize('x-small')

    plt.gca().set_xscale('log')
    plt.gca().set_yscale('log')
    plt.gca().set_ylim(1e-14,3e-11)
    plt.gca().set_xlim(1e-3,1e1)
    plt.xlabel('Energy (TeV)')
    plt.ylabel('$E^2 dN/dE\,(\mathrm{erg}\,\mathrm{s}^{-1}\mathrm{cm}^{-2})$')

    plt.savefig('./plots/' + fname + '.png', format = 'png', dpi = 200)
    plt.savefig('./plots/' + fname + '.pdf', format = 'pdf')
    plt.close()
    print isource, fname


0.2
0.3
0.4
0.5
0.6
0.7
0 sed_1ES0229+200_HESS_2005-2006_idL8_tmax1e+07_thj6_elmag
1 sed_1ES0229+200_VERITAS_2009-2012_idL8_tmax1e+07_thj6_elmag
2 sed_1ES0347-121_HESS_2006-09-12_idL8_tmax1e+07_thj6_elmag
3 sed_1ES0414+009_VERITAS_2008-2011_idL8_tmax1e+07_thj6_elmag
4 sed_1ES0414+009_HESS_2005-2009_idL8_tmax1e+07_thj6_elmag
5 sed_1RXSJ101015.9-311909_HESS_2006-2_idL8_tmax1e+07_thj6_elmag
6 sed_1ES1101-232_HESS_2004-2005_idL8_tmax1e+07_thj6_elmag
7 sed_1ES1218+304_VERITAS_2008-2009_idL8_tmax1e+07_thj6_elmag
8 sed_1ES1218+304_VERITAS_2007_idL8_tmax1e+07_thj6_elmag
9 sed_1ES1312-423_HESS_2004-2010_idL8_tmax1e+07_thj6_elmag
10 sed_H1426+428_HEGRA_1999_2000_idL8_tmax1e+07_thj6_elmag
11 sed_H1426+428_HEGRA_2002_idL8_tmax1e+07_thj6_elmag
12 sed_H2356-309_HESS_2006_idL8_tmax1e+07_thj6_elmag
13 sed_H2356-309_HESS_2005_idL8_tmax1e+07_thj6_elmag
14 sed_H2356-309_HESS_2004_idL8_tmax1e+07_thj6_elmag

Likelihood plots


In [13]:
isource = 0

In [14]:
from myplot.funcs import *

In [15]:
cmap = plt.cm.afmhot

Get the bin boundaries


In [16]:
igmf = results['igmf'][isource]*np.ones(results['dloglike'][isource].shape)
lcoh = results['lcoh'][isource]*np.ones(results['dloglike'][isource].shape)
dl =  results['lcoh'][isource][1] - results['lcoh'][isource][0] 
lcoh_edges = np.linspace(results['lcoh'][isource][0] - dl[0] / 2.,
                       results['lcoh'][isource][-1] + dl[0] / 2.,
                        results['lcoh'][isource].shape[0] + 1)
dB = results['igmf'][isource][0,1] - results['igmf'][isource][0,0]

igmf_edges = np.linspace(results['igmf'][isource][0,0] - dB / 2.,
                       results['igmf'][isource][0,-1] +  dB / 2.,
                        results['igmf'][isource].shape[1] + 1)

bb,ll = np.meshgrid(igmf_edges,lcoh_edges)
print bb.shape, ll.shape


(18, 18) (18, 18)

Total $\Delta\log\mathcal{L}$


In [17]:
cp = plt.cm.inferno

Get min and max likelihoods for color scale, check which spectra don't give a limit and exclude sources that give limits that are more than 10% different from each other (from excluded area)


In [18]:
no_lim = []
max_diff = 100. # max diff allowed between limits from different spectra

exclAreas = OrderedDict()
exclAreas_fhes = OrderedDict()
combined_dl_src = OrderedDict()
for isource, name  in enumerate(results['SOURCE_FULL']):
    dl = 2. * np.min(results['dloglike'][isource])
    exclArea = np.sum(2. * results['dloglike'][isource] < -6.18) \
        / float(np.prod(results['dloglike'][isource].shape))
    if not exclArea:
        print 'No exclusion from ', name, results['name'][isource]
        no_lim.append(results['name'][isource])
    else:
        # exclude 1426 by hand
        if name.find('1426') >= 0:
            no_lim.append(results['name'][isource])
            continue
        if not results['name'][isource] in exclAreas_fhes:
            exclAreas_fhes[results['name'][isource]] = exclArea
        elif np.abs(1. - exclAreas_fhes[results['name'][isource]] / exclArea) > max_diff:
            print 'Large difference in excluded area for different spectra, removing ', name
            no_lim.append(results['name'][isource])
            continue
        
        exclAreas[name] = exclArea

        if not results['name'][isource] in combined_dl_src.keys():
            combined_dl_src[results['name'][isource]] = [name, exclArea]
        else:
            if combined_dl_src[results['name'][isource]][1] > exclArea:
                combined_dl_src[results['name'][isource]] = [name, exclArea]

# make sure you have removed all 
# unwanted sources from likelihood combination
for n in no_lim:
    combined_dl_src.pop(n, None)

minArea, maxArea = np.min(exclAreas.values()),np.max(exclAreas.values())
m = 1. / (maxArea - minArea)
b = -minArea * m


No exclusion from  1ES0414+009_VERITAS_2008-2011 FHES J0416.8+0105
No exclusion from  1ES0414+009_HESS_2005-2009 FHES J0416.8+0105
No exclusion from  1RXSJ101015.9-311909_HESS_2006-2 FHES J1010.2-3119
No exclusion from  H2356-309_HESS_2006 FHES J2359.1-3038

Make the plot for the full likelihood


In [19]:
plt.close()
fig = plt.figure(0)
ax = fig.add_subplot(111)
handles = []
for isource, name  in enumerate(results['SOURCE_FULL']):
    LL, BB = np.meshgrid(10.**results['lcoh'][isource][:,0],
                         10.**results['igmf'][isource][0,:], 
                        indexing = 'ij')
    
    dloglike = results['dloglike'][isource]
    if results['name'][isource] in no_lim: continue
    
    plt.contourf(LL,BB,2*dloglike, [-1e5,-6.18],
             colors = [cp( m * exclAreas[name] + b)],
             linestyles = ['-'],
             zorder = -(m * exclAreas[name] + b),
             alpha = 0.5
            )
            
    c = plt.contour(LL,BB,2*dloglike, [-1e5,-6.18],
             colors = [cp( m * exclAreas[name] + b - 0.05)],
             linestyles = ['--'],
             label = name
            )
    handles.append(mpatches.Patch(
                    color= cp( m * exclAreas[name] + b),
                    alpha = 0.5,
                    label = ' '.join(name.split('_'))))
    
title = '$t_\mathrm{{max}} = 10^{0:.0f}$ yrs, $\\theta_\mathrm{{jet}} = {1:.1f}^\circ$'.format(
        np.log10(config['tmax']), config['th_jet'])

plt.grid(True)

plt.legend(loc = 'lower left', handles = handles, fontsize = 'x-small',
          ncol = 2, title = title)
ax.get_legend().get_title().set_fontsize('small')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_ylabel('$B\,$(G)')
ax.set_xlabel('$\lambda\,$(Mpc)')


fname = 'dL_tmax{0[tmax]:.0e}_thj{0[th_jet]:.0f}_{0[kind]:s}'.format(config)
plt.savefig('./plots/' + fname + '.png', format = 'png', dpi = 200)
plt.savefig('./plots/' + fname + '.pdf', format = 'pdf')


make the plot without the IACT likelihood


In [20]:
plt.close()

fig = plt.figure(1)
ax = fig.add_subplot(111)
handles = []
for isource, name  in enumerate(results['SOURCE_FULL']):
    LL, BB = np.meshgrid(10.**results['lcoh'][isource][:,0],
                         10.**results['igmf'][isource][0,:], 
                        indexing = 'ij')
    
    dloglike = np.sum(results['loglike_comp'][isource][...,1:], axis = -1)
    dloglike = -(dloglike - np.min(dloglike))
    
    if results['name'][isource] in no_lim: continue
    
    plt.contourf(LL,BB,2*dloglike, [-1e10,-6.18],
             colors = [cp( m * exclAreas[name] + b)],
             linestyles = ['-'],
             zorder = -(m * exclAreas[name] + b),
             alpha = 0.5
            )
            
    c = plt.contour(LL,BB,2*dloglike, [-1e10,-6.18],
             colors = [cp( m * exclAreas[name] + b - 0.05)],
             linestyles = ['--'],
             label = name
            )
    handles.append(mpatches.Patch(
                    color= cp( m * exclAreas[name] + b),
                    alpha = 0.5,
                    label = ' '.join(name.split('_'))))

title = '$t_\mathrm{{max}} = 10^{0:.0f}$ yrs, $\\theta_\mathrm{{jet}} = {1:.1f}^\circ$'.format(
        np.log10(config['tmax']), config['th_jet'])

plt.grid(True)

plt.legend(loc = 'lower left', handles = handles, fontsize = 'x-small',
          ncol = 2, title = title)
ax.get_legend().get_title().set_fontsize('small')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_ylabel('$B\,$(G)')
ax.set_xlabel('$\lambda\,$(Mpc)')

fname = 'dLFermi_tmax{0[tmax]:.0e}_thj{0[th_jet]:.0f}_{0[kind]:s}'.format(config)
plt.savefig('./plots/' + fname + '.png', format = 'png', dpi = 200)
plt.savefig('./plots/' + fname + '.pdf', format = 'pdf')


Combine the likelihoods


In [21]:
combined_dL_spec = [x[0] for x in combined_dl_src.values()]

dloglike = []
for isource, name  in enumerate(results['SOURCE_FULL']):
    if not name in combined_dL_spec: continue
    dloglike.append(results['dloglike'][isource])
dloglike = np.array(dloglike).sum(axis = 0)

Plot the combined likelihood:


In [22]:
ax = plt.subplot(111)
plt.contourf(LL,BB,2*dloglike, [-1e5,-6.18],
             colors = ['0.5'],
             linestyles = ['-'],
             alpha = 0.5
            )

title = '$t_\mathrm{{max}} = 10^{0:.0f}$ yrs, $\\theta_\mathrm{{jet}} = {1:.1f}^\circ$'.format(
        np.log10(config['tmax']), config['th_jet'])
title += '\nSources:'
for c in combined_dL_spec:
    c = c.split('_')
    title += '\n{0[0]:s} {0[1]:s}'.format(c)


handles = [mpatches.Patch(
                    color= '0.5',
                    alpha = 0.5,
                    label = 'Combined 95% Exclusion')]

plt.legend(loc = 4, title = title, handles = handles)
plt.grid(True)
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_ylabel('$B\,$(G)')
ax.set_xlabel('$\lambda\,$(Mpc)')

fname = 'Comb_dL_tmax{0[tmax]:.0e}_thj{0[th_jet]:.0f}_{0[kind]:s}'.format(config)
plt.savefig('./plots/' + fname + '.png', format = 'png', dpi = 200)
plt.savefig('./plots/' + fname + '.pdf', format = 'pdf')



In [23]:
dloglike = results['dloglike'][isource]


#plt.pcolormesh(10**ll,10**bb,2*dloglike,
#               cmap=cmap, #edgecolors = 'skyblue', lw = 0.01,
              # vmax=0.0,vmin=int(np.min(dloglike))
#              )
#cb = plt.colorbar(label = '$2\Delta \log \mathcal{L}$')
#plt.gca().set_xlim(np.min(10.**ll),np.max(10.**ll))
#plt.gca().set_ylim(np.min(10.**bb),np.max(10.**bb))

cp = plt.cm.gnuplot
cp.set_over('1.')
BB, LL = np.meshgrid(10.**results['igmf'][isource][0,:], 10.**results['lcoh'][isource][:,0])
plot_map_countours(LL,BB,2*dloglike, [-11.83,-6.18],
                   colbarlabel = '$2\Delta \log \mathcal{L}$',
                  colmap = cp,
                  #vmin = -50, vmax = 0.,
                   vmin = np.min(2*dloglike), vmax = -6.
                   #set_under = '1.'
                  )

plt.gca().set_xscale('log')
plt.gca().set_yscale('log')
plt.gca().set_ylabel('$B\,$(G)')
plt.gca().set_xlabel('$\lambda\,$(Mpc)')

tics_out(plt.gca())


Out[23]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f45ccb533d0>

Single $\Delta\log\mathcal{L}$


In [24]:
loglike = np.rollaxis(results['loglike_comp'][isource],2)

label = ['IACT SED', '$\mathit{Fermi}$ SED', 'Cascade']

plt.figure(figsize = (6,4*3))
for i,logl in enumerate(loglike):
    ax = plt.subplot(loglike.shape[0],1,i+1)
    dl = -2.*(logl - np.min(logl))
    #dl = -logl
    plt.pcolormesh(10**ll,10**bb,
                   dl,
                   cmap=cp,
        #            edgecolors = 'skyblue', lw = 0.01,
                   vmax=int(np.max(dl)),
                   vmin=int(np.min(dl)))
    
    
    cb = plt.colorbar(label = '$2\Delta \log \mathcal{L}$')
    ax.set_ylabel('$B\,$(G)')
    ax.set_xlabel('$\lambda\,$(Mpc)')
    #ax.grid(True, color = 'skyblue')
    ax.set_xscale('log')
    ax.set_yscale('log')
    tics_out(ax)
    
    ax.set_xlim(np.min(10.**ll),np.max(10.**ll))
    ax.set_ylim(np.min(10.**bb),np.max(10.**bb))
    
    ax.annotate(label[i], xy = (0.05,0.05), xycoords = 'axes fraction', **effect)
plt.subplots_adjust(hspace = 0.3)


combine likelihoods from Fermi only


In [25]:
dloglike_fermi = np.sum(results['loglike_comp'][isource][...,1:], axis = -1)
#dloglike -= np.max(dloglike)

dloglike_fermi = -(dloglike_fermi - np.min(dloglike_fermi))

plot_map_countours(LL,BB,2*dloglike_fermi, [-11.83,-6.18],
                   colbarlabel = '$2\Delta \log \mathcal{L}$',
                  colmap = cp,
                  #vmin = -50, vmax = 0.,
                   vmin = np.min(2*dloglike_fermi), vmax = -6.
                   #set_under = '1.'
                  )

plt.gca().set_xscale('log')
plt.gca().set_yscale('log')
plt.gca().set_ylabel('$B\,$(G)')
plt.gca().set_xlabel('$\lambda\,$(Mpc)')
#plt.gca().grid(True, color = 'skyblue')
#plt.gca().set_xlim(np.min(10.**ll),np.max(10.**ll))
#plt.gca().set_ylim(np.min(10.**bb),np.max(10.**bb))

tics_out(plt.gca())


Out[25]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f45ccbc1a90>

In [ ]: