Exemple #1
0
def make_source_catalog():
    """Make source catalog from images.

    TODO: use other images to do measurements for the sources,
    e.g. excess, npred, flux.
    """
    significance_threshold = 7

    hdu = fits.open(TS_IMAGES)['sqrt_ts']
    header = fits.getheader(REF_IMAGE)
    wcs = WCS(header)

    print('Running find_peaks ...')
    table = find_peaks(data=hdu.data,
                       threshold=significance_threshold,
                       wcs=wcs)
    print('Number of sources detected: {}'.format(len(table)))

    # Add some useful columns
    icrs = SkyCoord(table['icrs_ra_peak'], table['icrs_dec_peak'], unit='deg')
    galactic = icrs.galactic
    table['Source_Name'] = coordinate_iau_format(icrs, ra_digits=5, prefix='J')
    table['GLON'] = galactic.l.deg
    table['GLAT'] = galactic.b.deg

    # table.show_in_browser(jsviewer=True)
    print('Writing {}'.format(SOURCE_CATALOG))
    table.write(SOURCE_CATALOG, overwrite=True)

    ds9_string = to_ds9_region(table, label='Source_Name')
    print('Writing {}'.format(SOURCE_REGIONS))
    with open(SOURCE_REGIONS, 'w') as fh:
        fh.write(ds9_string)

    # TODO: move this to `make_significance_image`.
    # At the moment the TS map output images don't have WCS info in the header
    hdu = fits.PrimaryHDU(data=hdu.data, header=header)
    print('Writing {}'.format(SIGNIFICANCE_IMAGE))
    hdu.writeto(SIGNIFICANCE_IMAGE, clobber=True)
def make_source_catalog():
    """Make source catalog from images.

    TODO: use other images to do measurements for the sources,
    e.g. excess, npred, flux.
    """
    significance_threshold = 7

    hdu = fits.open(TS_IMAGES)['sqrt_ts']
    header = fits.getheader(REF_IMAGE)
    wcs = WCS(header)

    print('Running find_peaks ...')
    table = find_peaks(data=hdu.data, threshold=significance_threshold, wcs=wcs)
    print('Number of sources detected: {}'.format(len(table)))

    # Add some useful columns
    icrs = SkyCoord(table['icrs_ra_peak'], table['icrs_dec_peak'], unit='deg')
    galactic = icrs.galactic
    table['Source_Name'] = coordinate_iau_format(icrs, ra_digits=5, prefix='J')
    table['GLON'] = galactic.l.deg
    table['GLAT'] = galactic.b.deg

    # table.show_in_browser(jsviewer=True)
    print('Writing {}'.format(SOURCE_CATALOG))
    table.write(SOURCE_CATALOG, overwrite=True)

    ds9_string = to_ds9_region(table, label='Source_Name')
    print('Writing {}'.format(SOURCE_REGIONS))
    with open(SOURCE_REGIONS, 'w') as fh:
        fh.write(ds9_string)

    # TODO: move this to `make_significance_image`.
    # At the moment the TS map output images don't have WCS info in the header
    hdu = fits.PrimaryHDU(data=hdu.data, header=header)
    print('Writing {}'.format(SIGNIFICANCE_IMAGE))
    hdu.writeto(SIGNIFICANCE_IMAGE, clobber=True)
Exemple #3
0
"""
Generate region file from the catalogs.
"""

from astropy.table import Table
from gammapy.catalog import to_ds9_region

if __name__ == '__main__':
    filenames = [
        'ATNF_v1.51.fits.gz', 'Green_2014-05.fits.gz',
        '2014PASA...31...42G_table2.fits.gz'
    ]
    radius_columns = [None, 'Dmean', 'Dmean']
    colors = ['yellow', 'cyan', 'red']

    for filename, column, color in zip(filenames, radius_columns, colors):
        catalog = Table.read(filename)
        if column == 'Dmean':
            # Convert arcmin to deg
            catalog['Dmean'] /= 120.
        outfilename = filename.replace('fits.gz', 'reg')
        print('Writing {}'.format(outfilename))
        with open(outfilename, 'w') as region_file:
            region_file.write(
                to_ds9_region(catalog,
                              radius=column,
                              label='Source_Name',
                              color=color,
                              width=2))
"""
Generate region file from the catalogs.
"""

from astropy.table import Table
from gammapy.catalog import to_ds9_region


if __name__ == '__main__':
    filenames = ['ATNF_v1.51.fits.gz', 'Green_2014-05.fits.gz',
                 '2014PASA...31...42G_table2.fits.gz']
    radius_columns = [None, 'Dmean', 'Dmean']
    colors = ['yellow', 'cyan', 'red']

    for filename, column, color in zip(filenames, radius_columns, colors):
        catalog = Table.read(filename)
        if column == 'Dmean':
            # Convert arcmin to deg
            catalog['Dmean'] /= 120.
        outfilename = filename.replace('fits.gz', 'reg')
        print('Writing {}'.format(outfilename))
        with open(outfilename, 'w') as region_file:
            region_file.write(to_ds9_region(catalog, radius=column, label='Source_Name',
                                            color=color, width=2))