Beispiel #1
0
def image_derived(infile,
                  outfile,
                  theta,
                  is_off_correlated,
                  overwrite):
    """Make derived maps for a given set of basic maps.

    TODO: describe
    """
    from astropy.io import fits
    from gammapy.background import Maps

    log.info('Reading {0}'.format(infile))
    hdus = fits.open(infile)
    maps = Maps(hdus, theta=theta,
                is_off_correlated=is_off_correlated)
    log.info('Computing derived maps')
    maps.make_derived_maps()
    log.info('Writing {0}'.format(outfile))
    maps.writeto(outfile, clobber=overwrite)
def derived_images(infile,
                   outfile,
                   theta,
                   is_off_correlated,
                   overwrite):
    """Make derived maps for a given set of basic maps.

    TODO: describe
    """
    import logging
    logging.basicConfig(level=logging.DEBUG, format='%(levelname)s - %(message)s')
    from astropy.io import fits
    from gammapy.background import Maps

    logging.info('Reading {0}'.format(infile))
    hdus = fits.open(infile)
    maps = Maps(hdus, theta=theta,
                is_off_correlated=is_off_correlated)
    logging.info('Computing derived maps')
    maps.make_derived_maps()
    logging.info('Writing {0}'.format(outfile))
    maps.writeto(outfile, clobber=overwrite)
Beispiel #3
0
def derived_images(infile, outfile, theta, is_off_correlated, overwrite):
    """Make derived maps for a given set of basic maps.

    TODO: describe
    """
    from astropy.io import fits
    from gammapy.background import Maps

    log.info('Reading {0}'.format(infile))
    hdus = fits.open(infile)
    maps = Maps(hdus, theta=theta, is_off_correlated=is_off_correlated)
    log.info('Computing derived maps')
    maps.make_derived_maps()
    log.info('Writing {0}'.format(outfile))
    maps.writeto(outfile, clobber=overwrite)
* The background is estimated from a ring around each pixel.
* The significance is computed using the Li & Ma formula
  for the counts within a circle around each pixel.
* An iterative scheme is used to define an exclusion mask of
  pixels that shouldn't be used for background estimation.
"""
import numpy as np
from astropy.io import fits
from gammapy.data import fermi_galactic_center
from gammapy.image import threshold, binary_dilation_circle
from gammapy.background import Maps, ring_correlate_off_maps

input_file = fermi_galactic_center()['counts']
hdu_list = fits.open(input_file)
binsz = hdu_list[-1].header['CDELT2']
maps = Maps(hdu_list, theta=0.3)

for iteration in range(3):
    print('Iteration: {0}'.format(iteration))
    ring_correlate_off_maps(maps, r_in=0.5, r_out=0.8)
    significance = maps.significance.data
    #exclusion = threshold(significance, threshold=5)
    exclusion = np.where(significance > 4, 0, 1).astype(int)
    exclusion = binary_dilation_circle(exclusion, radius=0.4 * binsz)
    maps['exclusion'].data = exclusion

maps.make_derived_maps()
output_file = 'fermi_all_gc.fits'
print('Writing file: {0}'.format(output_file))
maps.writeto(output_file, clobber=True)
* The significance is computed using the Li & Ma formula
  for the counts within a circle around each pixel.
* An iterative scheme is used to define an exclusion mask of
  pixels that shouldn't be used for background estimation.
"""
# TODO: Fix this script and include images in the docs!
__doctest_skip__ = ['*']
import numpy as np
from astropy.io import fits
from gammapy.datasets import FermiGalacticCenter
from gammapy.image import threshold, binary_dilation_circle
from gammapy.background import Maps, ring_correlate_off_maps

counts = FermiGalacticCenter.counts()
binsz = counts.header['CDELT2']
maps = Maps([counts], theta=0.3)

for iteration in range(3):
    print('Iteration: {0}'.format(iteration))
    ring_correlate_off_maps(maps, r_in=0.5, r_out=0.8)
    significance = maps.significance.data
    # exclusion = threshold(significance, threshold=5)
    exclusion = np.where(significance > 4, 0, 1).astype(int)
    exclusion = binary_dilation_circle(exclusion, radius=0.4 * binsz)
    maps['exclusion'].data = exclusion.astype(np.uint8)

maps.make_derived_maps()
output_file = 'fermi_all_gc.fits'
print('Writing file: {0}'.format(output_file))
maps.writeto(output_file, clobber=True)