Beispiel #1
0
def all_energy_table(pwnlist):

    data = yaml.load(open(expandvars('$pwncode/data/pwncat2_phase_lande.yaml')))

    table = OrderedDefaultDict(list)

    psr_name='PSR'
    phase_name='Phase'
    optimal_emin_name='Optimal Emin' if confluence else r'Optimal $E_\text{min}$'
    optimal_radius_name='Optimal radius'

    for pwn in pwnlist:
        print pwn
        table[psr_name].append(format.pwn(pwn))

        phase=PhaseRange(data[pwn]['phase'])
        optimal_emin=data[pwn]['optimal_emin']
        optimal_radius=data[pwn]['optimal_radius']

        table[phase_name].append(phase.pretty_format())
        table[optimal_emin_name].append('%.2f' % optimal_emin)
        table[optimal_radius_name].append('%.2f' % optimal_radius)

    print yaml.dump(table)
    if confluence:
        write_confluence(table, filebase='phase_range')
    else:
        write_latex(table, filebase='phase_range')
def cutoff_table(pwnlist):

    table = OrderedDefaultDict(list)
    psr_name='PSR'
    ts_var_name = r'$\ts_\text{var}$' if not confluence else 'TS_var'

    t='gtlike'

    for pwn in pwnlist:

        print pwn

        table[psr_name].append(format.pwn(pwn))

        var = expandvars(join(ts_var_folder,pwn,'results_%s.yaml' % pwn))
        if exists(var): 

            v = yaml.load(open(var))

            ts_var = v['TS_var'][t]
            table[ts_var_name].append(format.value(ts_var, precision=1))
        else:
            table[ts_var_name].append(r'None')

    filebase='variability'
    if confluence:
        write_confluence(table,filebase=filebase)
    else:
        write_latex(table,filebase=filebase)
Beispiel #3
0
def cutoff_table(pwnlist):

    table = OrderedDefaultDict(list)

    psr_name = "PSR"
    flux_name = r"$F_{0.1-316}$" if not confluence else "F_(0.1-316)"
    eflux_name = r"$G_{0.1-316}$" if not confluence else "G_(0.1-316)"
    index_name = r"$\Gamma$" if not confluence else "Gamma"
    cutoff_name = r"$E_\text{cutoff}$" if not confluence else "E_cutoff"
    ts_point_name = r"$\ts_\text{point}$" if not confluence else "TS_point"
    ts_cutoff_name = r"$\ts_\text{cutoff}$" if not confluence else "TS_cutoff"

    for pwn in pwnlist:
        results = get_results(pwn)
        if results is None:
            continue

        if not results.has_key("point") or not results["point"].has_key("gtlike"):
            continue

        ts = results["point"]["gtlike"]["TS"]

        if ts < 25:
            continue

        table[psr_name].append(format.pwn(pwn))

        cutoff = results["point"]["gtlike"]["test_cutoff"]

        if cutoff != -1:

            ts_point = results["point"]["gtlike"]["TS"]

            table[ts_point_name].append(format.value(ts_point, precision=1))

            ts_cutoff = max(cutoff["TS_cutoff"], 0)
            table[ts_cutoff_name].append(format.value(ts_cutoff, precision=1))

            nodata = "" if confluence else r"\nodata"

            if ts_cutoff >= 16:

                flux = cutoff["flux_1"]["flux"]
                flux_err = cutoff["flux_1"]["flux_err"]

                eflux = cutoff["flux_1"]["eflux"]
                eflux_err = cutoff["flux_1"]["eflux_err"]
                index = -1 * cutoff["model_1"]["Index1"]
                index_err = cutoff["model_1"]["Index1_err"]
                cutoff_energy = cutoff["model_1"]["Cutoff"]
                cutoff_energy_err = cutoff["model_1"]["Cutoff_err"]

                table[flux_name].append(format.error(flux / 1e-9, flux_err / 1e-9))
                table[eflux_name].append(format.error(eflux / 1e-12, eflux_err / 1e-12))
                table[index_name].append(format.error(index, index_err))
                table[cutoff_name].append(format.error(cutoff_energy / 1000, cutoff_energy_err / 1000))
            else:
                table[flux_name].append(format.nodata)
                table[eflux_name].append(format.nodata)
                table[index_name].append(format.nodata)
                table[cutoff_name].append(format.nodata)
        else:
            table[flux_name].append("None")
            table[eflux_name].append("None")
            table[index_name].append("None")
            table[cutoff_name].append("None")
            table[ts_cutoff_name].append("None")

    filebase = "cutoff_test"

    if confluence:
        write_confluence(
            table,
            filebase=filebase,
            units={flux_name: r"(10^-9 erg cm^-2 s^-1)", eflux_name: r"(10^-12 erg cm^-2 s^-1)", cutoff_name: r"(GeV)"},
        )
    else:
        write_latex(
            table,
            filebase=filebase,
            preamble=r"\tabletypesize{\scriptsize}",
            units={
                flux_name: r"($10^{-9}$\ erg\,cm$^{-2}$\,s$^{-1}$)",
                eflux_name: r"($10^{-12}$\ erg\,cm$^{-2}$\,s$^{-1}$)",
                cutoff_name: r"(GeV)",
            },
        )
def all_energy_table(pwnlist):

    table = OrderedDefaultDict(list)

    psr_name='PSR'
    flux_name=r'$F_{0.1-316}$' if not confluence else 'F_(0.1-316)'
    energy_flux_name=r'$G_{0.1-316}$' if not confluence else 'G_(0.1-316)'
    ts_name=r'\ts' if not confluence else 'TS'
    gamma_name=r'$\Gamma$' if not confluence else 'Gamma'

    luminosity_name = r'Luminosity'

    nodata = '' if confluence else r'\nodata'

    for pwn in pwnlist:
        table[psr_name].append(format.pwn(pwn))

        results = get_results(pwn)

        if results is None: 
            table[ts_name].append('None')
            table[flux_name].append('None')
            table[gamma_name].append('None')
            table[luminosity_name].append(r'None')
        else:

            b = BestHypothesis(results)
            gtlike = b.gtlike
            pointlike = b.pointlike
            type = b.type

            ts=max(gtlike['TS'],0)
            table[ts_name].append(format.value(ts, precision=1))

            if type == 'point' or type == 'extended':

                flux=gtlike['flux']['flux']
                flux_err=gtlike['flux']['flux_err']

                eflux=gtlike['flux']['eflux']
                eflux_err=gtlike['flux']['eflux_err']

                table[flux_name].append(format.error(flux/1e-9,flux_err/1e-9))
                table[energy_flux_name].append(format.error(eflux/1e-12,eflux_err/1e-12))

                index=-1*gtlike['model']['Index']
                index_err=-1*gtlike['model']['Index_err']
                table[gamma_name].append(format.error(index,index_err))
                table[luminosity_name].append(r'None')

            else:
                if gtlike['upper_limit'] != None:
                    ul=gtlike['upper_limit']['flux']
                    eul=gtlike['upper_limit']['eflux']
                    table[flux_name].append(format.ul(ul/1e-9))
                    table[energy_flux_name].append(format.ul(eul/1e-12))
                    table[gamma_name].append(nodata)
                    table[luminosity_name].append(r'None')
                else:
                    table[flux_name].append('None')
                    table[energy_flux_name].append('None')
                    table[gamma_name].append(r'None')
                    table[luminosity_name].append(r'None')

    filebase='all_energy'

    if confluence:
        write_confluence(table,
                    filebase=filebase,
                    units={
                        flux_name:r'(10^-9 ph cm^-2 s^-1)',
                        energy_flux_name:r'(10^-12 erg cm^-2 s^-1)',
                        luminosity_name:r'(10^33 erg s^-1)',
                    })
    else:
        write_latex(table,
                    filebase=filebase,
                    units={
                        flux_name:r'($10^{-9}\ \ph\,\cm^{-2}\,\s^{-1}$)',
                        energy_flux_name:r'($10^{-12}\ \erg\,\cm^{-2}\s^{-1}$)',
                        luminosity_name:r'($10^{33}\ \erg\,\s^{-1}$)',
                    })
def each_energy_table(pwnlist):

    table = OrderedDefaultDict(list)

    psr_name='PSR'
    TS1_name = r'$\ts_{0.1-1}$' if not confluence else 'TS_(0.1-1)'
    TS2_name = r'$\ts_{1-10}$' if not confluence else 'TS_(1-10)'
    TS3_name = r'$\ts_{10-316}$' if not confluence else 'TS_(10-316)'

    flux1_name = '$F_{0.1-1}$' if not confluence else 'F_(0.1-1)'
    flux2_name = '$F_{1-10}$' if not confluence else 'F_(1-10)'
    flux3_name = '$F_{10-316}$' if not confluence else 'F_(10-316)'

    index1_name = r'$\Gamma_{0.1-1}$' if not confluence else 'Gamma_(0.1-1)'
    index2_name = r'$\Gamma_{1-10}$' if not confluence else 'Gamma_(1-10)'
    index3_name = r'$\Gamma_{10-316}$' if not confluence else 'Gamma_(10-316)'

    for pwn in pwnlist:

        results = get_results(pwn)
        table[psr_name].append(format.pwn(pwn))

        if results is None: 
            table[TS1_name].append('None')
            table[flux1_name].append('None')
            table[index1_name].append('None')

            table[TS2_name].append('None')
            table[flux2_name].append('None')
            table[index2_name].append('None')

            table[TS3_name].append('None')
            table[flux3_name].append('None')
            table[index3_name].append('None')
        else:
            print pwn

            b = BestHypothesis(results)
            gtlike = b.gtlike
            pointlike = b.pointlike
            type = b.type

            ts = gtlike['bands']['TS']
            flux = gtlike['bands']['flux']['value']
            flux_err = gtlike['bands']['flux']['error']
            ul = gtlike['bands']['flux']['upper_limit']
            index = -a(gtlike['bands']['index']['value'])
            index_err = -a(gtlike['bands']['index']['error'])

            ts = [i if i > 0 else 0 for i in ts]

            table[TS1_name].append(format.value(ts[0],precision=1))
            if ts[0] >= 25:
                table[flux1_name].append(format.error(flux[0]/1e-9,flux_err[0]/1e-9))
                table[index1_name].append(format.error(index[0], index_err[0]))
            else:
                table[flux1_name].append(format.ul(ul[0]/1e-9))
                table[index1_name].append(format.nodata)


            table[TS2_name].append(format.value(ts[1],precision=1))
            if ts[1] >= 25:
                table[flux2_name].append(format.error(flux[1]/1e-9,flux_err[1]/1e-9))
                table[index2_name].append(format.error(index[1], index_err[1]))
            else:
                table[flux2_name].append(format.ul(ul[1]/1e-9))
                table[index2_name].append(format.nodata)

            table[TS3_name].append(format.value(ts[2], precision=1))
            if ts[2] >= 25:
                table[flux3_name].append(r'$%.2f \pm %.2f$' % (flux[2]/1e-9,flux_err[2]/1e-9))
                table[index3_name].append(r'$%.2f \pm %.2f$' % (index[2], index_err[2]))
            else:
                table[flux3_name].append(format.ul(ul[2]/1e-9))
                table[index3_name].append(format.nodata)

    filebase='each_energy'
    if confluence:
        write_confluence(table,
                    filebase=filebase,
                    units={
                        flux1_name:r'(10^-9 ph cm^-2 s^-1)',
                        flux2_name:r'(10^-9 ph cm^-2 s^-1)',
                        flux3_name:r'(10^-9 ph cm^-2 s^-1)',
                    })
    else:
        write_latex(table,
                    filebase=filebase,
                    preamble=r'\tabletypesize{\scriptsize}',
                    units={
                        flux1_name:r'($10^{-9}\ \text{ph}\,\text{cm}^{-2}\,\text{s}^{-1}$)',
                        flux2_name:r'($10^{-9}\ \text{ph}\,\text{cm}^{-2}\,\text{s}^{-1}$)',
                        flux3_name:r'($10^{-9}\ \text{ph}\,\text{cm}^{-2}\,\text{s}^{-1}$)',
                    })
def localization_table(pwnlist):

    table = OrderedDefaultDict(list)

    psr_name='PSR'
    l_name='GLON'
    b_name='GLAT'
    ts_point_name =r'$\ts_\text{point}$' if not confluence else 'TS_point'
    ts_ext_name =r'\tsext' if not confluence else 'TS_ext'
    offset_name = 'Offset'
    ext_name = 'Extension'
    poserr_name = 'Pos Err'

    for pwn in pwnlist:

        results = get_results(pwn)

        print pwn

        if results is None or \
           not results.has_key('point') or \
           not results['point'].has_key('gtlike') or \
           not results['point'].has_key('pointlike') or \
           not results.has_key('extended') or \
           not results['extended'].has_key('gtlike') or \
           not results['extended'].has_key('pointlike'):
            continue
            

        at_pulsar_gtlike = results['at_pulsar']['gtlike']
        at_pulsar_pointlike = results['at_pulsar']['pointlike']
        

        point_gtlike = results['point']['gtlike']
        point_pointlike = results['point']['pointlike']
        
        extended_gtlike = results['extended']['gtlike']
        extended_pointlike = results['extended']['pointlike']

        ts_point = point_gtlike['TS']
        ts_ext = max(extended_gtlike['ts_ext'],0)

        b = BestHypothesis(results)
        gtlike = b.gtlike
        pointlike = b.pointlike
        type = b.type



        if type != 'upper_limit':

            l,b=pointlike['position']['gal']

            try:
                poserr='%.2f' % pointlike['spatial_model']['ellipse']['lsigma']
            except:
                poserr='None'

            o = np.degrees(SkyDir(*pointlike['position']['equ']).difference(SkyDir(*at_pulsar_pointlike['position']['equ'])))

            if type == 'extended':
                extension = extended_pointlike['spatial_model']['Sigma']
                extension_err = extended_pointlike['spatial_model']['Sigma_err']
                ext = format.error(extension, extension_err)

            elif type == 'point':
                extension_ul = point_pointlike['extension_upper_limit']['extension']
                ext = format.ul(extension_ul)

            table[psr_name].append(format.pwn(pwn))

            table[ts_point_name].append('%.1f' % ts_point)
            table[l_name].append('%.2f' % l)
            table[b_name].append('%.2f' % b)
            table[poserr_name].append(poserr)
            table[offset_name].append('%.2f' % o)
            table[ts_ext_name].append('%.1f' % ts_ext)
            table[ext_name].append(ext)
            
    deg = '(deg)'

    filebase='localization'
    if confluence:
        write_confluence(table,
                    filebase=filebase,
                    units={
                        l_name:deg,
                        b_name:deg,
                        offset_name:deg,
                        ext_name:deg,
                        poserr_name:deg,
                    })
    else:
        write_latex(table,
                    filebase=filebase,
                    units={
                        l_name:deg,
                        b_name:deg,
                        offset_name:deg,
                        ext_name:deg,
                        poserr_name:deg,
                    })