Exemple #1
0
    def __init__(self, pwndata, fitdir, webdir):

        self.fitdir = expandvars(fitdir)
        self.webdir = expandvars(webdir)

        self.relpath = os.path.relpath(self.fitdir, self.webdir)

        if not os.path.exists(self.webdir): os.makedirs(self.webdir)

        self.loader = PWNResultsLoader(pwndata, self.fitdir)

        self.pwnlist = self.loader.get_pwnlist()

        self.formatter = TableFormatter(self.loader)
Exemple #2
0
    def __init__(self,
                 pwndata,
                 fitdir,
                 webdir):

        self.fitdir=expandvars(fitdir)
        self.webdir=expandvars(webdir)

        self.relpath=os.path.relpath(self.fitdir, self.webdir)

        if not os.path.exists(self.webdir): os.makedirs(self.webdir)

        self.loader = PWNResultsLoader(pwndata, self.fitdir)

        self.pwnlist=self.loader.get_pwnlist()

        self.formatter = TableFormatter(self.loader)
Exemple #3
0
import numpy as np

from lande.fermi.pipeline.pwncat2.interp.classify import PWNManualClassifier,PWNClassifierException
from lande.fermi.pipeline.pwncat2.interp.loader import PWNResultsLoader

loader = PWNResultsLoader(
    pwndata="$pwndata/pwncat2_data_lande.yaml",
    fitdir="$pwnpipeline/v36/analysis"
)
print loader.pwndata
print loader.fitdir

pwnlist = loader.get_pwnlist()

classifier=PWNManualClassifier(
    loader=loader, 
    pwn_classification='$pwnclassify/manual_classifications.yaml'
)

npsr = 0
psrs = []

npsr_confused = 0
psrs_confused = []

npwn = 0
pwne = []

ndetect = 0

nconfused = 0
def spatial_spectral_table(pwndata, 
                           phase_shift, 
                           fitdir, savedir, pwn_classification, filebase, table_type,
                           bigfile_filename):
    assert table_type == 'latex'

    format=PWNFormatter(table_type=table_type, precision=2)

    loader = PWNResultsLoader(
        pwndata=pwndata,
        fitdir=fitdir,
        phase_shift=phase_shift
        )

    classifier = PWNManualClassifier(loader=loader, pwn_classification=pwn_classification)

    table = OrderedDefaultDict(list)

    psr_name='PSR'
    classification_name = 'Type'
    ts_point_name=r'$\tspoint$'
    ts_ext_name=r'$\tsext$'
    ts_cutoff_name = r'$\tscutoff$'
    ts_altdiff_name = r'$\tsaltdiff$'
    eflux_name = r'Energy Flux'
    index_name = r'$\Gamma$'
    cutoff_name = r'$\Ecutoff$'

    pwnlist = loader.get_pwnlist()
    #pwnlist = pwnlist[10:20]

    pcl = PulsarCatalogLoader(bigfile_filename=bigfile_filename)

    young = [ psr for psr in pwnlist if 'm' not in pcl.get_pulsar_classification(psr.replace('PSRJ','J'))]
    msps = [ psr for psr in pwnlist if 'm' in pcl.get_pulsar_classification(psr.replace('PSRJ','J'))]
    print 'young',young
    print 'msps',msps

    sorted_pwnlist = young + msps

    first_msp_index = None

    for pwn in sorted_pwnlist:
        print pwn

        try:
            r = classifier.get_results(pwn)

            if r['source_class'] == 'Upper_Limit': 
                continue

            if first_msp_index is None and pwn in msps:
                first_msp_index = len(table[psr_name])

            table[psr_name].append(format.pwn(pwn))
            table[classification_name].append(r['abbreviated_source_class'])

            def david_format_ts(x):
                if x >= 100:
                    return format.value(x,precision=0) + '.'
                else:
                    return format.value(x,precision=1)

            table[ts_point_name].append(david_format_ts(r['ts_point']))
            table[ts_ext_name].append(david_format_ts(r['ts_ext']))
            table[ts_cutoff_name].append(david_format_ts(r['ts_cutoff']))
            table[ts_altdiff_name].append(david_format_ts(r['ts_altdiff']) if r['ts_altdiff'] is not None else format.nodata)

            def david_format_flux(x, y):
                if x >= 10:
                    return format.error(x,y, precision=1)
                else:
                    return  format.error(x,y, precision=2)

            table[eflux_name].append(david_format_flux(r['energy_flux']/1e-11,r['energy_flux_err']/1e-11))
            if r['spectral_model'] in ['PowerLaw','PLSuperExpCutoff']:
                table[index_name].append(format.error(r['index'],r['index_err']))
            elif pwn == 'PSRJ0534+2200':
                table[index_name].append(r'\tablenotemark{a}')
            elif pwn == 'PSRJ0835-4510':
                table[index_name].append(r'\tablenotemark{b}')
            else:
                table[index_name].append(format.nodata)

            if r['spectral_model'] == 'PLSuperExpCutoff':
                table[cutoff_name].append(format.error(r['cutoff']/1e3,r['cutoff_err']/1e3, precision=2))
            else:
                table[cutoff_name].append(format.nodata)

        except PWNClassifierException, ex:
            print 'Skipping %s: %s' % (pwn,ex)
            table[psr_name].append(format.pwn(pwn))
            table[classification_name].append('None')
            table[ts_point_name].append('None')
            table[ts_ext_name].append('None')
            table[ts_cutoff_name].append('None')
            table[eflux_name].append('None')
            table[index_name].append('None')
            table[cutoff_name].append('None')
Exemple #5
0
def auxiliary_table(pwndata, 
                    phase_shift, 
                    fitdir, filename, pwn_classification):

    loader = PWNResultsLoader(
        pwndata=pwndata,
        fitdir=fitdir,
        phase_shift=phase_shift
        )

    classifier = PWNManualClassifier(loader=loader, pwn_classification=pwn_classification)

    pwnlist = loader.get_pwnlist()

    npwn = len(pwnlist)

    table=atpy.Table(name='Off_Peak')


    def add_float(name, **kwargs):
        table.add_empty_column(name, np.dtype('float32'), shape=npwn, **kwargs)
        table[name][:]=np.nan
        return name

    def add_int(name, **kwargs):
        table.add_empty_column(name, np.dtype('uint32'), shape=npwn, **kwargs)
        table[name][:]=np.nan
        return name

    def add_vector_float(name, size, *args, **kwargs):
        table.add_empty_column(name, np.dtype('float32'), shape=(npwn, size), **kwargs)
        table[name][:]=np.nan
        return name

    def add_vector_int(name, size, *args, **kwargs):
        table.add_empty_column(name, np.dtype('uint32'), shape=(npwn, size), **kwargs)
        table[name][:]=np.nan
        return name

    def add_string(name, width, *args, **kwargs):
        table.add_empty_column(name, np.dtype((str, width)), shape=npwn, *args, **kwargs)
        return name

    maxwidth=max([len(i) for i in pwnlist])
    psr_name=add_string('PSR', maxwidth)

    len_class = max(map(len,PWNClassifier.abbreviated_source_class_mapper.values()))
    classification_name=add_string('Classification_OP', len_class)


    # Phase Stuff
    off_peak_min_name=add_float('Min_Phase_OP')
    off_peak_max_name=add_float('Max_Phase_OP')
    second_off_peak_min_name=add_float('Min_2_Phase_OP')
    second_off_peak_max_name=add_float('Max_2_Phase_OP')

    # Significance stuff
    ts_point_name=add_float('TS_point_OP')
    ts_ext_name=add_float('TS_ext_OP')
    ts_cutoff_name=add_float('TS_cutoff_OP')
    ts_altdiff_name = add_float(r'TS_altdiff_OP')
    ts_var_name=add_float('TS_var_OP')

    # Spectral Stuff

    len_spectral = max(map(len,PWNClassifier.allowed_spectral_models))
    spectral_model_name=add_string('Spectral_Model_OP', len_spectral)

    energy_units = 'MeV'
    energy_flux_units = 'erg/cm^2/s'
    flux_units = 'ph/cm^2/s'
    prefactor_units = 'ph/cm^2/s/erg'

    flux_name = add_float('Flux_OP', unit=flux_units)
    flux_err_name = add_float('Unc_Flux_OP', unit=flux_units)

    energy_flux_name = add_float('EFlux_OP', unit=energy_flux_units)
    energy_flux_err_name = add_float('Unc_EFlux_OP', unit=energy_flux_units)


    prefactor_name = add_float('Prefactor_OP', unit=prefactor_units)
    prefactor_err_name = add_float('Unc_Prefactor_OP', unit=prefactor_units)

    normalization_name = add_float('Normalization_OP')
    normalization_err_name = add_float('Unc_Normalization_OP')


    scale_name = add_float('Scale_OP', unit=energy_units)

    index_name = add_float('Index_OP')
    index_err_name = add_float('Unc_Index_OP')

    cutoff_name = add_float('Energy_Cutoff_OP', unit=energy_units)
    cutoff_err_name = add_float('Unc_Energy_Cutoff_OP', unit=energy_units)

    # Spatial Stuff

    len_spatial = max(map(len,PWNClassifier.allowed_spatial_models))
    spatial_model_name=add_string('Spatial_Model_OP',len_spatial)

    ra_name = add_float('RAJ2000_OP', unit='deg')
    dec_name = add_float('DECJ2000_OP', unit='deg')

    glon_name = add_float('GLON_OP', unit='deg')
    glat_name = add_float('GLAT_OP', unit='deg')

    poserr_name = add_float('Unc_Position_OP', unit='deg')

    extension_name = add_float('Extension_OP', unit='deg')
    extension_err_name = add_float('Unc_Extension_OP', unit='deg')

    powerlaw_flux_upper_limit_name = add_float('PowerLaw_Flux_UL_OP')
    powerlaw_energy_flux_upper_limit_name =add_float('PowerLaw_EFlux_UL_OP')

    cutoff_flux_upper_limit_name = add_float('Cutoff_Flux_UL_OP')
    cutoff_energy_flux_upper_limit_name =add_float('Cutoff_EFlux_UL_OP')

    sed_size=14
    sed_lower_energy_name = add_vector_float('SED_Lower_Energy_OP', size=sed_size, unit=energy_units)
    sed_upper_energy_name = add_vector_float('SED_Upper_Energy_OP', size=sed_size, unit=energy_units)
    sed_middle_energy_name = add_vector_float('SED_Center_Energy_OP', size=sed_size, unit=energy_units)

    sed_ts_name = add_vector_float('SED_TS_OP', size=sed_size)

    sed_prefactor_name = add_vector_float('SED_Prefactor_OP', size=sed_size, unit='ph*cm**-2*s**-1*erg**-1')
    sed_prefactor_lower_err_name = add_vector_float('SED_Neg_Unc_Prefactor_OP', size=sed_size, unit='ph*cm**-2*s**-1*erg**-1')
    sed_prefactor_upper_err_name = add_vector_float('SED_Pos_Unc_Prefactor_OP', size=sed_size, unit='ph*cm**-2*s**-1*erg**-1')
    sed_prefactor_upper_limit_name = add_vector_float('SED_Prefactor_UL_OP', size=sed_size, unit='ph*cm**-2*s**-1*erg**-1')

    for i,pwn in enumerate(pwnlist):
        print pwn

        try:
            r = classifier.get_results(pwn)
        except PWNClassifierException:
            print 'Skipping %s' % pwn
            continue

        phase=r['shifted_phase']

        table[psr_name][i]=pwn.replace('PSRJ','J')

        source_class = r['source_class']
        table[classification_name][i] = r['abbreviated_source_class']

        assert source_class in PWNClassifier.allowed_source_class

        if phase.is_continuous():
            a,b = phase.tolist(dense=True)
            table[off_peak_min_name][i]=a
            table[off_peak_max_name][i]=b
        else:
            ranges = phase.split_ranges()
            assert len(ranges) == 2
            a,b = ranges[0].tolist(dense=True)
            table[off_peak_min_name][i]=a
            table[off_peak_max_name][i]=b
            a,b = ranges[1].tolist(dense=True)
            table[second_off_peak_min_name][i]=a
            table[second_off_peak_max_name][i]=b

        # likelihood stuff
        ts_point = r['ts_point']
        table[ts_point_name][i]=ts_point

        if source_class in ['Confused', 'Pulsar', 'Pulsar_Confused', 'PWN']:
            table[ts_ext_name][i]=r['ts_ext']
            table[ts_cutoff_name][i]=r['ts_cutoff']
        elif source_class == 'Upper_Limit':
            pass
        else:
            raise Exception("...")

        if source_class in ['Pulsar','Pulsar_Confused']:
            table[ts_altdiff_name][i]=r['ts_altdiff']
        elif source_class in ['Confused', 'PWN', 'Upper_Limit']:
            pass
        else:
            raise Exception("...")

        table[ts_var_name][i]=r['ts_var']

        # spectral stuff

        spectral_model = r['spectral_model']
        if not type(spectral_model) == str and np.isnan(spectral_model):
            spectral_model = 'NULL'

        table[spectral_model_name][i]= spectral_model

        table[energy_flux_name][i] = r['energy_flux']
        table[energy_flux_err_name][i] = r['energy_flux_err']

        table[flux_name][i]=r['flux']
        table[flux_err_name][i]=r['flux_err']

        table[prefactor_name][i]=r['prefactor']
        table[prefactor_err_name][i]=r['prefactor_err']

        table[normalization_name][i]=r['normalization']
        table[normalization_err_name][i]=r['normalization_err']

        table[index_name][i]=r['index']
        table[index_err_name][i]=r['index_err']

        table[scale_name][i]=r['model_scale']

        table[cutoff_name][i]=r['cutoff']
        table[cutoff_err_name][i]=r['cutoff_err']

        # spatial stuff

        spatial_model = r['spatial_model']
        if not type(spatial_model) == str and np.isnan(spatial_model):
            spatial_model = 'NULL'
        table[spatial_model_name][i] = spatial_model

        table[ra_name][i] = r['ra']
        table[dec_name][i] = r['dec']

        table[glon_name][i] = r['glon']
        table[glat_name][i] = r['glat']

        table[poserr_name][i] = r['poserr']

        table[extension_name][i] = r['extension']
        table[extension_err_name][i] = r['extension_err']

        # Add powerlaw upper limit
        table[powerlaw_flux_upper_limit_name][i] = r['powerlaw_flux_upper_limit']
        table[powerlaw_energy_flux_upper_limit_name][i] = r['powerlaw_energy_flux_upper_limit']

        # Add cutoff upper limit
        table[cutoff_flux_upper_limit_name][i] = r['cutoff_flux_upper_limit']
        table[cutoff_energy_flux_upper_limit_name][i] = r['cutoff_energy_flux_upper_limit']

        # Add SED results


        table[sed_lower_energy_name] = r['sed_lower_energy'] 
        table[sed_upper_energy_name] = r['sed_upper_energy'] 
        table[sed_middle_energy_name] = r['sed_middle_energy'] 

        table[sed_ts_name][i] = r['sed_ts'] 

        table[sed_prefactor_name][i] = r['sed_prefactor'] 
        table[sed_prefactor_lower_err_name][i] = r['sed_prefactor_lower_err'] 
        table[sed_prefactor_upper_err_name][i] = r['sed_prefactor_upper_err'] 
        table[sed_prefactor_upper_limit_name][i] = r['sed_prefactor_upper_limit'] 

    table.write(expandvars(filename), overwrite=True)
        
def auxiliary_table(pwndata, 
                    phase_shift, 
                    fitdir, filename, pwn_classification):

    loader = PWNResultsLoader(
        pwndata=pwndata,
        fitdir=fitdir,
        phase_shift=phase_shift
        )

    classifier = PWNManualClassifier(loader=loader, pwn_classification=pwn_classification)

    pwnlist = loader.get_pwnlist()

    npwn = len(pwnlist)

    table=atpy.Table(name='Off_Peak')


    def add_float(name, **kwargs):
        table.add_empty_column(name, np.dtype('float32'), shape=npwn, **kwargs)
        table[name][:]=np.nan
        return name

    def add_int(name, **kwargs):
        table.add_empty_column(name, np.dtype('uint32'), shape=npwn, **kwargs)
        table[name][:]=np.nan
        return name

    def add_vector_float(name, size, *args, **kwargs):
        table.add_empty_column(name, np.dtype('float32'), shape=(npwn, size), **kwargs)
        table[name][:]=np.nan
        return name

    def add_vector_int(name, size, *args, **kwargs):
        table.add_empty_column(name, np.dtype('uint32'), shape=(npwn, size), **kwargs)
        table[name][:]=np.nan
        return name

    def add_string(name, width, *args, **kwargs):
        table.add_empty_column(name, np.dtype((str, width)), shape=npwn, *args, **kwargs)
        return name

    maxwidth=max([len(i) for i in pwnlist])
    psr_name=add_string('PSR', maxwidth)

    len_class = max(map(len,PWNClassifier.abbreviated_source_class_mapper.values()))
    classification_name=add_string('Classification_OP', len_class)


    # Phase Stuff
    off_peak_min_name=add_float('Min_Phase_OP')
    off_peak_max_name=add_float('Max_Phase_OP')
    second_off_peak_min_name=add_float('Min_2_Phase_OP')
    second_off_peak_max_name=add_float('Max_2_Phase_OP')

    # Significance stuff
    ts_point_name=add_float('TS_point_OP')
    ts_ext_name=add_float('TS_ext_OP')
    ts_cutoff_name=add_float('TS_cutoff_OP')
    ts_altdiff_name = add_float(r'TS_altdiff_OP')
    ts_var_name=add_float('TS_var_OP')

    # Spectral Stuff

    len_spectral = max(map(len,PWNClassifier.allowed_spectral_models))
    spectral_model_name=add_string('Spectral_Model_OP', len_spectral)

    energy_units = 'MeV'
    energy_flux_units = 'erg/cm^2/s'
    flux_units = 'ph/cm^2/s'
    prefactor_units = 'ph/cm^2/s/erg'

    flux_name = add_float('Flux_OP', unit=flux_units)
    flux_err_name = add_float('Unc_Flux_OP', unit=flux_units)

    energy_flux_name = add_float('EFlux_OP', unit=energy_flux_units)
    energy_flux_err_name = add_float('Unc_EFlux_OP', unit=energy_flux_units)


    prefactor_name = add_float('Prefactor_OP', unit=prefactor_units)
    prefactor_err_name = add_float('Unc_Prefactor_OP', unit=prefactor_units)

    normalization_name = add_float('Normalization_OP')
    normalization_err_name = add_float('Unc_Normalization_OP')


    scale_name = add_float('Scale_OP', unit=energy_units)

    index_name = add_float('Index_OP')
    index_err_name = add_float('Unc_Index_OP')

    cutoff_name = add_float('Energy_Cutoff_OP', unit=energy_units)
    cutoff_err_name = add_float('Unc_Energy_Cutoff_OP', unit=energy_units)

    # Spatial Stuff

    len_spatial = max(map(len,PWNClassifier.allowed_spatial_models))
    spatial_model_name=add_string('Spatial_Model_OP',len_spatial)

    ra_name = add_float('RAJ2000_OP', unit='deg')
    dec_name = add_float('DECJ2000_OP', unit='deg')

    glon_name = add_float('GLON_OP', unit='deg')
    glat_name = add_float('GLAT_OP', unit='deg')

    poserr_name = add_float('Unc_Position_OP', unit='deg')

    extension_name = add_float('Extension_OP', unit='deg')
    extension_err_name = add_float('Unc_Extension_OP', unit='deg')

    powerlaw_flux_upper_limit_name = add_float('PowerLaw_Flux_UL_OP')
    powerlaw_energy_flux_upper_limit_name =add_float('PowerLaw_EFlux_UL_OP')

    cutoff_flux_upper_limit_name = add_float('Cutoff_Flux_UL_OP')
    cutoff_energy_flux_upper_limit_name =add_float('Cutoff_EFlux_UL_OP')

    sed_size=14
    sed_lower_energy_name = add_vector_float('SED_Lower_Energy_OP', size=sed_size, unit=energy_units)
    sed_upper_energy_name = add_vector_float('SED_Upper_Energy_OP', size=sed_size, unit=energy_units)
    sed_middle_energy_name = add_vector_float('SED_Center_Energy_OP', size=sed_size, unit=energy_units)

    sed_ts_name = add_vector_float('SED_TS_OP', size=sed_size)

    sed_prefactor_name = add_vector_float('SED_Prefactor_OP', size=sed_size, unit='ph*cm**-2*s**-1*erg**-1')
    sed_prefactor_lower_err_name = add_vector_float('SED_Neg_Unc_Prefactor_OP', size=sed_size, unit='ph*cm**-2*s**-1*erg**-1')
    sed_prefactor_upper_err_name = add_vector_float('SED_Pos_Unc_Prefactor_OP', size=sed_size, unit='ph*cm**-2*s**-1*erg**-1')
    sed_prefactor_upper_limit_name = add_vector_float('SED_Prefactor_UL_OP', size=sed_size, unit='ph*cm**-2*s**-1*erg**-1')

    for i,pwn in enumerate(pwnlist):
        print pwn

        try:
            r = classifier.get_results(pwn)
        except PWNClassifierException:
            print 'Skipping %s' % pwn
            continue

        phase=r['shifted_phase']

        table[psr_name][i]=pwn.replace('PSRJ','J')

        source_class = r['source_class']
        table[classification_name][i] = r['abbreviated_source_class']

        assert source_class in PWNClassifier.allowed_source_class

        if phase.is_continuous():
            a,b = phase.tolist(dense=True)
            table[off_peak_min_name][i]=a
            table[off_peak_max_name][i]=b
        else:
            ranges = phase.split_ranges()
            assert len(ranges) == 2
            a,b = ranges[0].tolist(dense=True)
            table[off_peak_min_name][i]=a
            table[off_peak_max_name][i]=b
            a,b = ranges[1].tolist(dense=True)
            table[second_off_peak_min_name][i]=a
            table[second_off_peak_max_name][i]=b

        # likelihood stuff
        ts_point = r['ts_point']
        table[ts_point_name][i]=ts_point

        if source_class in ['Confused', 'Pulsar', 'Pulsar_Confused', 'PWN']:
            table[ts_ext_name][i]=r['ts_ext']
            table[ts_cutoff_name][i]=r['ts_cutoff']
        elif source_class == 'Upper_Limit':
            pass
        else:
            raise Exception("...")

        if source_class in ['Pulsar','Pulsar_Confused']:
            table[ts_altdiff_name][i]=r['ts_altdiff']
        elif source_class in ['Confused', 'PWN', 'Upper_Limit']:
            pass
        else:
            raise Exception("...")

        table[ts_var_name][i]=r['ts_var']

        # spectral stuff

        spectral_model = r['spectral_model']
        if not type(spectral_model) == str and np.isnan(spectral_model):
            spectral_model = 'NULL'

        table[spectral_model_name][i]= spectral_model

        table[energy_flux_name][i] = r['energy_flux']
        table[energy_flux_err_name][i] = r['energy_flux_err']

        table[flux_name][i]=r['flux']
        table[flux_err_name][i]=r['flux_err']

        table[prefactor_name][i]=r['prefactor']
        table[prefactor_err_name][i]=r['prefactor_err']

        table[normalization_name][i]=r['normalization']
        table[normalization_err_name][i]=r['normalization_err']

        table[index_name][i]=r['index']
        table[index_err_name][i]=r['index_err']

        table[scale_name][i]=r['model_scale']

        table[cutoff_name][i]=r['cutoff']
        table[cutoff_err_name][i]=r['cutoff_err']

        # spatial stuff

        spatial_model = r['spatial_model']
        if not type(spatial_model) == str and np.isnan(spatial_model):
            spatial_model = 'NULL'
        table[spatial_model_name][i] = spatial_model

        table[ra_name][i] = r['ra']
        table[dec_name][i] = r['dec']

        table[glon_name][i] = r['glon']
        table[glat_name][i] = r['glat']

        table[poserr_name][i] = r['poserr']

        table[extension_name][i] = r['extension']
        table[extension_err_name][i] = r['extension_err']

        # Add powerlaw upper limit
        table[powerlaw_flux_upper_limit_name][i] = r['powerlaw_flux_upper_limit']
        table[powerlaw_energy_flux_upper_limit_name][i] = r['powerlaw_energy_flux_upper_limit']

        # Add cutoff upper limit
        table[cutoff_flux_upper_limit_name][i] = r['cutoff_flux_upper_limit']
        table[cutoff_energy_flux_upper_limit_name][i] = r['cutoff_energy_flux_upper_limit']

        # Add SED results


        table[sed_lower_energy_name] = r['sed_lower_energy'] 
        table[sed_upper_energy_name] = r['sed_upper_energy'] 
        table[sed_middle_energy_name] = r['sed_middle_energy'] 

        table[sed_ts_name][i] = r['sed_ts'] 

        table[sed_prefactor_name][i] = r['sed_prefactor'] 
        table[sed_prefactor_lower_err_name][i] = r['sed_prefactor_lower_err'] 
        table[sed_prefactor_upper_err_name][i] = r['sed_prefactor_upper_err'] 
        table[sed_prefactor_upper_limit_name][i] = r['sed_prefactor_upper_limit'] 

    table.write(expandvars(filename), overwrite=True)
Exemple #7
0
class WebsiteBuilder(object):
    def __init__(self, pwndata, fitdir, webdir):

        self.fitdir = expandvars(fitdir)
        self.webdir = expandvars(webdir)

        self.relpath = os.path.relpath(self.fitdir, self.webdir)

        if not os.path.exists(self.webdir): os.makedirs(self.webdir)

        self.loader = PWNResultsLoader(pwndata, self.fitdir)

        self.pwnlist = self.loader.get_pwnlist()

        self.formatter = TableFormatter(self.loader)

    def build(self):
        self.build_main_website()
        self.build_all_pages()

    def build_all_pages(self):
        for pwn in self.pwnlist:
            self.build_each_page(pwn)

    def build_main_website(self):
        print 'Building Main Webpage'

        index_t2t = []
        index_t2t.append('PWNCatalog+\n\n')
        t = self.formatter.format(self.pwnlist)
        index_t2t.append(str(t))
        t2t(index_t2t, join(self.webdir, 'index.t2t'))

    def build_each_page(self, pwn):
        print 'Building webpage for %s' % pwn
        index_t2t = []
        index_t2t.append(pwn + '\n\n')
        index_t2t.append('([back index.html])')
        t = self.formatter.format([pwn])
        index_t2t.append(str(t))
        index_t2t.append('')
        index_t2t.append('[Analysis Folder %s/%s]\n' % (self.relpath, pwn))
        index_t2t.append('[log (pointlike) %s/%s/log_run_%s.txt]\n' %
                         (self.relpath, pwn, pwn))

        index_t2t.append(
            'pointlike results: [(at_pulsar) %s/%s/results_%s_pointlike_at_pulsar.yaml] [(point) %s/%s/results_%s_pointlike_point.yaml] [(extended) %s/%s/results_%s_pointlike_extended.yaml] \n'
            % (self.relpath, pwn, pwn, self.relpath, pwn, pwn, self.relpath,
               pwn, pwn))
        index_t2t.append(
            'gtlike results: [(at_pulsar) %s/%s/results_%s_gtlike_at_pulsar.yaml] [(point) %s/%s/results_%s_gtlike_point.yaml] [(extended) %s/%s/results_%s_gtlike_extended.yaml] \n'
            % (self.relpath, pwn, pwn, self.relpath, pwn, pwn, self.relpath,
               pwn, pwn))

        get_plot_table = lambda *args: index_t2t.append('|| ' + ' | '.join(
            ['[%s/%s/plots/%s]' % (self.relpath, pwn, i)
             for i in args]) + ' |\n\n')
        get_sed_table = lambda *args: index_t2t.append('|| ' + ' | '.join(
            ['[%s/%s/seds/%s]' % (self.relpath, pwn, i)
             for i in args]) + ' |\n\n')

        title = lambda i: index_t2t.append('\n\n== %s ==' % i)

        title('Phase Info')
        get_plot_table('phaseogram_%s.png' % (pwn),
                       'phase_vs_time_%s.png' % (pwn))

        all = ['at_pulsar', 'point', 'extended']

        title('Big Residual TS map')
        get_plot_table(
            *['tsmap_residual_%s_%s_10deg.png' % (i, pwn) for i in all])

        index_t2t.append(
            '[tsmap_residual_%s_%s_10deg.fits %s/%s/data/tsmap_residual_%s_%s_10deg.fits]'
            % (pwn, 'at_pulsar', self.relpath, pwn, 'at_pulsar', pwn))

        title('SED gtlike (4bpd)')
        get_sed_table(*['sed_gtlike_4bpd_%s_%s.png' % (i, pwn) for i in all])

        title('Combined gtlike')
        get_plot_table(
            *['combined_gtlike_spectra_%s_%s.png' % (i, pwn) for i in all])

        title('Combined pointlike')
        get_plot_table(
            *['combined_pointlike_spectra_%s_%s.png' % (i, pwn) for i in all])

        title('gtlike Cutoff test')
        get_plot_table(*[
            'test_cutoff_gtlike_%s_%s.png' % (i, pwn)
            for i in ['at_pulsar', 'point']
        ])

        title('pointlike Cutoff test')
        get_plot_table(*[
            'test_cutoff_pointlike_%s_%s.png' % (i, pwn)
            for i in ['at_pulsar', 'point']
        ])

        title('Source TS Maps')
        get_plot_table(
            *['tsmap_source_%s_%s_5deg.png' % (i, pwn) for i in all])
        get_plot_table(
            *['band_tsmap_source_%s_%s_5deg.png' % (i, pwn) for i in all])

        title('Residual TS Maps')
        get_plot_table(
            *['tsmap_residual_%s_%s_5deg.png' % (i, pwn) for i in all])
        get_plot_table(
            *['band_tsmap_residual_%s_%s_5deg.png' % (i, pwn) for i in all])

        title('New Source TS Maps')
        get_plot_table(
            *['tsmap_newsrc_%s_%s_5deg.png' % (i, pwn) for i in all])
        get_plot_table(
            *['band_tsmap_newsrc_%s_%s_5deg.png' % (i, pwn) for i in all])

        title('at_pulsar Smoothed Counts Diffuse Subtracted (0.1)')
        get_plot_table(
            *['sources_%s_%s_5deg_0.1deg.png' % (i, pwn) for i in all])
        get_plot_table(
            *['band_sources_%s_%s_5deg_0.1deg.png' % (i, pwn) for i in all])

        title('Smoothed Counts BG Source Subtracted (0.1)')
        get_plot_table(
            *['source_%s_%s_5deg_0.1deg.png' % (i, pwn) for i in all])

        title('Band Smoothed Counts BG Source Subtracted (0.1)')
        get_plot_table(
            *['band_source_%s_%s_5deg_0.1deg.png' % (i, pwn) for i in all])

        title('gtlike SED')
        get_sed_table(*['sed_gtlike_1bpd_%s_%s.png' % (i, pwn) for i in all])
        get_sed_table(*['sed_gtlike_2bpd_%s_%s.png' % (i, pwn) for i in all])

        title('Pointlike SEDs')
        get_sed_table(
            *['sed_pointlike_4bpd_%s_%s.png' % (i, pwn) for i in all])

        title('Extra: Source TS Maps (10 deg)')
        get_plot_table(
            *['tsmap_source_%s_%s_10deg.png' % (i, pwn) for i in all])
        get_plot_table(
            *['band_tsmap_source_%s_%s_10deg.png' % (i, pwn) for i in all])

        title('Extra: Residual TS Maps')
        get_plot_table(
            *['tsmap_residual_%s_%s_10deg.png' % (i, pwn) for i in all])
        get_plot_table(
            *['band_tsmap_residual_%s_%s_10deg.png' % (i, pwn) for i in all])

        title('Extra: New Source TS Maps (10 deg)')
        get_plot_table(
            *['tsmap_newsrc_%s_%s_10deg.png' % (i, pwn) for i in all])
        get_plot_table(
            *['band_tsmap_newsrc_%s_%s_10deg.png' % (i, pwn) for i in all])

        title('Extra: Smoothed Counts (0.25deg)')
        get_plot_table(*['source_0.25_%s_%s_5deg.png' % (i, pwn) for i in all])

        title('Extra: Smoothed Counts (0.25deg)')
        get_plot_table(
            *['sources_0.25_%s_%s_5deg.png' % (i, pwn) for i in all])

        title('Extra: Band Smoothed Counts (0.25)')
        get_plot_table(
            *['band_source_%s_%s_5deg_0.25deg.png' % (i, pwn) for i in all])
        get_plot_table(
            *['band_sources_%s_%s_5deg_0.25deg.png' % (i, pwn) for i in all])

        title('Counts (0.1)')
        get_plot_table(
            *['counts_residual_%s_%s_5deg_0.1deg.png' % (i, pwn) for i in all])

        get_plot_table(
            *['counts_source_%s_%s_5deg_0.1deg.png' % (i, pwn) for i in all])

        title('Extra: Counts (0.25)')
        get_plot_table(
            *['counts_source_%s_%s_5deg_0.25deg.png' % (i, pwn) for i in all])
        get_plot_table(
            *
            ['counts_residual_%s_%s_5deg_0.25deg.png' % (i, pwn) for i in all])

        t2t(index_t2t, join(self.webdir, '%s.t2t' % pwn))
Exemple #8
0
class WebsiteBuilder(object):
    def __init__(self,
                 pwndata,
                 fitdir,
                 webdir):

        self.fitdir=expandvars(fitdir)
        self.webdir=expandvars(webdir)

        self.relpath=os.path.relpath(self.fitdir, self.webdir)

        if not os.path.exists(self.webdir): os.makedirs(self.webdir)

        self.loader = PWNResultsLoader(pwndata, self.fitdir)

        self.pwnlist=self.loader.get_pwnlist()

        self.formatter = TableFormatter(self.loader)

    def build(self):
        self.build_main_website()
        self.build_all_pages()

    def build_all_pages(self):
        for pwn in self.pwnlist: 
            self.build_each_page(pwn)

    def build_main_website(self):
        print 'Building Main Webpage'

        index_t2t = []
        index_t2t.append('PWNCatalog+\n\n')
        t=self.formatter.format(self.pwnlist)
        index_t2t.append(str(t))
        t2t(index_t2t, join(self.webdir,'index.t2t'))

    def build_each_page(self,pwn):
        print 'Building webpage for %s' % pwn
        index_t2t = []
        index_t2t.append(pwn+'\n\n')
        index_t2t.append('([back index.html])')
        t=self.formatter.format([pwn])
        index_t2t.append(str(t))
        index_t2t.append('')
        index_t2t.append('[Analysis Folder %s/%s]\n' % (self.relpath,pwn))
        index_t2t.append('[log (pointlike) %s/%s/log_run_%s.txt]\n' % (self.relpath,pwn,pwn))

        index_t2t.append('pointlike results: [(at_pulsar) %s/%s/results_%s_pointlike_at_pulsar.yaml] [(point) %s/%s/results_%s_pointlike_point.yaml] [(extended) %s/%s/results_%s_pointlike_extended.yaml] \n' % (self.relpath,pwn,pwn,self.relpath,pwn,pwn,self.relpath,pwn,pwn))
        index_t2t.append('gtlike results: [(at_pulsar) %s/%s/results_%s_gtlike_at_pulsar.yaml] [(point) %s/%s/results_%s_gtlike_point.yaml] [(extended) %s/%s/results_%s_gtlike_extended.yaml] \n' % (self.relpath,pwn,pwn,self.relpath,pwn,pwn,self.relpath,pwn,pwn))

        get_plot_table = lambda *args: index_t2t.append('|| ' + ' | '.join(['[%s/%s/plots/%s]' % (self.relpath,pwn,i) for i in args]) + ' |\n\n')
        get_sed_table = lambda *args: index_t2t.append('|| ' + ' | '.join(['[%s/%s/seds/%s]' % (self.relpath,pwn,i) for i in args]) + ' |\n\n')

        title = lambda i: index_t2t.append('\n\n== %s ==' % i)

        title('Phase Info')
        get_plot_table('phaseogram_%s.png' % (pwn),'phase_vs_time_%s.png' % (pwn))

        all = ['at_pulsar', 'point', 'extended']

        title('Big Residual TS map')
        get_plot_table(*['tsmap_residual_%s_%s_10deg.png' % (i,pwn) for i in all])

        index_t2t.append('[tsmap_residual_%s_%s_10deg.fits %s/%s/data/tsmap_residual_%s_%s_10deg.fits]' % (pwn,'at_pulsar',self.relpath,pwn,'at_pulsar',pwn))

        title('SED gtlike (4bpd)')
        get_sed_table(*['sed_gtlike_4bpd_%s_%s.png' % (i,pwn) for i in all])

        title('Combined gtlike')
        get_plot_table(*['combined_gtlike_spectra_%s_%s.png' % (i,pwn) for i in all])

        title('Combined pointlike')
        get_plot_table(*['combined_pointlike_spectra_%s_%s.png' % (i,pwn) for i in all])

        title('gtlike Cutoff test')
        get_plot_table(*['test_cutoff_gtlike_%s_%s.png' % (i,pwn) for i in ['at_pulsar', 'point']])

        title('pointlike Cutoff test')
        get_plot_table(*['test_cutoff_pointlike_%s_%s.png' % (i,pwn) for i in ['at_pulsar', 'point']])

                
        title('Source TS Maps')
        get_plot_table(*['tsmap_source_%s_%s_5deg.png' % (i,pwn) for i in all])
        get_plot_table(*['band_tsmap_source_%s_%s_5deg.png' % (i,pwn) for i in all])

        title('Residual TS Maps')
        get_plot_table(*['tsmap_residual_%s_%s_5deg.png' % (i,pwn) for i in all])
        get_plot_table(*['band_tsmap_residual_%s_%s_5deg.png' % (i,pwn) for i in all])

        title('New Source TS Maps')
        get_plot_table(*['tsmap_newsrc_%s_%s_5deg.png' % (i,pwn) for i in all])
        get_plot_table(*['band_tsmap_newsrc_%s_%s_5deg.png' % (i,pwn) for i in all])

        title('at_pulsar Smoothed Counts Diffuse Subtracted (0.1)')
        get_plot_table(*['sources_%s_%s_5deg_0.1deg.png' % (i,pwn) for i in all])
        get_plot_table(*['band_sources_%s_%s_5deg_0.1deg.png' % (i,pwn) for i in all])

        title('Smoothed Counts BG Source Subtracted (0.1)')
        get_plot_table(*['source_%s_%s_5deg_0.1deg.png' % (i,pwn) for i in all])



        title('Band Smoothed Counts BG Source Subtracted (0.1)')
        get_plot_table(*['band_source_%s_%s_5deg_0.1deg.png' % (i,pwn) for i in all])

        title('gtlike SED')
        get_sed_table(*['sed_gtlike_1bpd_%s_%s.png' % (i,pwn) for i in all])
        get_sed_table(*['sed_gtlike_2bpd_%s_%s.png' % (i,pwn) for i in all])



        title('Pointlike SEDs')
        get_sed_table(*['sed_pointlike_4bpd_%s_%s.png' % (i,pwn) for i in all])

        title('Extra: Source TS Maps (10 deg)')
        get_plot_table(*['tsmap_source_%s_%s_10deg.png' % (i,pwn) for i in all])
        get_plot_table(*['band_tsmap_source_%s_%s_10deg.png' % (i,pwn) for i in all])

        title('Extra: Residual TS Maps')
        get_plot_table(*['tsmap_residual_%s_%s_10deg.png' % (i,pwn) for i in all])
        get_plot_table(*['band_tsmap_residual_%s_%s_10deg.png' % (i,pwn) for i in all])

        title('Extra: New Source TS Maps (10 deg)')
        get_plot_table(*['tsmap_newsrc_%s_%s_10deg.png' % (i,pwn) for i in all])
        get_plot_table(*['band_tsmap_newsrc_%s_%s_10deg.png' % (i,pwn) for i in all])


        title('Extra: Smoothed Counts (0.25deg)')
        get_plot_table(*['source_0.25_%s_%s_5deg.png' % (i,pwn) for i in all])

        title('Extra: Smoothed Counts (0.25deg)')
        get_plot_table(*['sources_0.25_%s_%s_5deg.png' % (i,pwn) for i in all])


        title('Extra: Band Smoothed Counts (0.25)')
        get_plot_table(*['band_source_%s_%s_5deg_0.25deg.png' % (i,pwn) for i in all])
        get_plot_table(*['band_sources_%s_%s_5deg_0.25deg.png' % (i,pwn) for i in all])

        title('Counts (0.1)')
        get_plot_table(*['counts_residual_%s_%s_5deg_0.1deg.png' % (i,pwn) for i in all])

        get_plot_table(*['counts_source_%s_%s_5deg_0.1deg.png' % (i,pwn) for i in all])


        title('Extra: Counts (0.25)')
        get_plot_table(*['counts_source_%s_%s_5deg_0.25deg.png' % (i,pwn) for i in all])
        get_plot_table(*['counts_residual_%s_%s_5deg_0.25deg.png' % (i,pwn) for i in all])


        t2t(index_t2t, join(self.webdir,'%s.t2t' % pwn))