コード例 #1
0
ファイル: fermi_skyimages.py プロジェクト: jjlk/gammapy-extra
def background_skyimage_2fhl(counts):
	log.info('Computing background map.')
	images = GammaImages(counts.data, header=counts.wcs.to_header())

	source_kernel = Tophat2DKernel(5)
	source_kernel.normalize('peak')

	background_kernel = Ring2DKernel(20, 20)
	background_kernel.normalize('peak')

	ikbe = IKBE(
	    images=images,
	    source_kernel=source_kernel.array,
	    background_kernel=background_kernel.array,
	    significance_threshold=5,
	    mask_dilation_radius=3,
	)

	mask_data, background_data = ikbe.run()

	mask = SkyMap.empty_like(counts)
	mask.data = mask_data

	background = SkyMap.empty_like(counts)
	background.data = background_data
	return mask, background
コード例 #2
0
def background_skyimage_2fhl(counts):
    log.info('Computing background map.')
    images = GammaImages(counts.data, header=counts.wcs.to_header())

    source_kernel = Tophat2DKernel(5)
    source_kernel.normalize('peak')

    background_kernel = Ring2DKernel(20, 20)
    background_kernel.normalize('peak')

    ikbe = IKBE(
        images=images,
        source_kernel=source_kernel.array,
        background_kernel=background_kernel.array,
        significance_threshold=5,
        mask_dilation_radius=3,
    )

    mask_data, background_data = ikbe.run()

    mask = SkyMap.empty_like(counts)
    mask.data = mask_data

    background = SkyMap.empty_like(counts)
    background.data = background_data
    return mask, background
コード例 #3
0
def make_background_image():
    """Estimate background image.

    See the `IterativeKernelBackgroundEstimator` tutorial and
    documentation how it works, or the SciNeGHe 2014 proceeding
    by Ellis Owen et al.
    """
    radius = Angle(0.2, 'deg')
    r_in = Angle(0.3, 'deg')
    r_out = Angle(0.7, 'deg')
    significance_threshold = 5
    mask_dilation_radius = Angle(0.1, 'deg')
    max_iterations = 3

    hdu = fits.open(COUNTS_IMAGE)['COUNTS']
    binsz = hdu.header['CDELT2']
    images = GammaImages(counts=hdu.data, header=hdu.header)

    # TODO: we should have utility functions to initialise
    # kernels with angles so that we don't have to convert to pix here.
    source_kernel = binary_disk(radius=radius.deg / binsz)
    background_kernel = binary_ring(r_in=r_in.deg / binsz,
                                    r_out=r_out.deg / binsz)

    estimator = IterativeKernelBackgroundEstimator(
        images=images,
        source_kernel=source_kernel,
        background_kernel=background_kernel,
        significance_threshold=significance_threshold,
        mask_dilation_radius=mask_dilation_radius.deg / binsz,
    )
    print('Running background estimation ...')
    estimator.run(max_iterations=max_iterations)

    print('Writing {}'.format(MASK_IMAGE))
    estimator.mask_image_hdu.writeto(MASK_IMAGE, clobber=True)

    print('Writing {}'.format(BACKGROUND_IMAGE))
    estimator.background_image_hdu.writeto(BACKGROUND_IMAGE, clobber=True)
コード例 #4
0
def make_background_image():
    """Estimate background image.

    See the `IterativeKernelBackgroundEstimator` tutorial and
    documentation how it works, or the SciNeGHe 2014 proceeding
    by Ellis Owen et al.
    """
    radius = Angle(0.2, 'deg')
    r_in = Angle(0.3, 'deg')
    r_out = Angle(0.7, 'deg')
    significance_threshold = 5
    mask_dilation_radius = Angle(0.1, 'deg')
    max_iterations = 3

    hdu = fits.open(COUNTS_IMAGE)['COUNTS']
    binsz = hdu.header['CDELT2']
    images = GammaImages(counts=hdu.data, header=hdu.header)

    # TODO: we should have utility functions to initialise
    # kernels with angles so that we don't have to convert to pix here.
    source_kernel = binary_disk(radius=radius.deg/binsz)
    background_kernel = binary_ring(r_in=r_in.deg/binsz,
                                    r_out=r_out.deg/binsz)

    estimator = IterativeKernelBackgroundEstimator(
        images=images, source_kernel=source_kernel, background_kernel=background_kernel,
        significance_threshold=significance_threshold,
        mask_dilation_radius=mask_dilation_radius.deg/binsz,
    )
    print('Running background estimation ...')
    estimator.run(max_iterations=max_iterations)

    print('Writing {}'.format(MASK_IMAGE))
    estimator.mask_image_hdu.writeto(MASK_IMAGE, clobber=True)

    print('Writing {}'.format(BACKGROUND_IMAGE))
    estimator.background_image_hdu.writeto(BACKGROUND_IMAGE, clobber=True)
コード例 #5
0
# Background must be provided as an ImageHDU
background_data = np.ones_like(counts_data, dtype=float)
background = fits.ImageHDU(data=background_data[0], header=flux_hdu.header)
images = GammaImages(counts=counts, background=background)

source_kernel = binary_disk(CORRELATION_RADIUS).astype(float)
source_kernel /= source_kernel.sum()

background_kernel = np.ones((5, 100))
background_kernel /= background_kernel.sum()

# *** ITERATOR ***

ibe = IterativeKernelBackgroundEstimator(
    images=images,
    source_kernel=source_kernel,
    background_kernel=background_kernel,
    significance_threshold=SIGNIFICANCE_THRESHOLD,
    mask_dilation_radius=MASK_DILATION_RADIUS)

mask, new_background = ibe.run()

flux_background_data = new_background.data / exposure_spec_cube.data[0]

flux_background = fits.ImageHDU(data=flux_background_data.value,
                                header=flux_hdu.header)

filebase = raw_input('Output file base: ')

flux_background.writeto('{0}_background.fits'.format(filebase), clobber=True)
mask.writeto('{0}_mask.fits'.format(filebase), clobber=True)
コード例 #6
0
background_data = np.ones_like(counts_data, dtype=float)
background = fits.ImageHDU(data=background_data[0], header=flux_hdu.header)
images = GammaImages(counts=counts, background=background)

source_kernel = binary_disk(CORRELATION_RADIUS).astype(float)
source_kernel /= source_kernel.sum()

background_kernel = np.ones((5, 100))
background_kernel /= background_kernel.sum()

# *** ITERATOR ***

ibe = IterativeKernelBackgroundEstimator(
    images=images,
    source_kernel=source_kernel,
    background_kernel=background_kernel,
    significance_threshold=SIGNIFICANCE_THRESHOLD,
    mask_dilation_radius=MASK_DILATION_RADIUS,
)

mask, new_background = ibe.run()

flux_background_data = new_background.data / exposure_spec_cube.data[0]

flux_background = fits.ImageHDU(data=flux_background_data.value, header=flux_hdu.header)

filebase = raw_input("Output file base: ")

flux_background.writeto("{0}_background.fits".format(filebase), clobber=True)
mask.writeto("{0}_mask.fits".format(filebase), clobber=True)
コード例 #7
0
background_data=np.ones_like(counts.data, dtype=float)
background = fits.ImageHDU(data=background_data, header=counts.header)
images = GammaImages(counts=counts, background=background)

source_kernel = binary_disk(3).astype(float)
source_kernel /= source_kernel.sum()

background_kernel = np.ones((5, 50))
background_kernel /= background_kernel.sum()

# *** ITERATOR ***

ibe = IterativeKernelBackgroundEstimator(images=images,
                                         source_kernel=source_kernel,
                                         background_kernel=background_kernel,
                                         significance_threshold=4,
                                         mask_dilation_radius=3,
                                         save_intermediate_results=True
                                         )

ibe.run(filebase='TestOutput')
#n_iterations = 3
"""
# *** RUN & PLOT ***
plt.figure(figsize=(4,6))
plt.rc('text', usetex=True)
plt.rc('font', family='serif')

plt.subplot(n_iterations+3, 1, 1)
background_hdu = counts
data = counts.data[:, 700:1400]
コード例 #8
0
# *** LOADING INPUT ***

# Counts must be provided as an ImageHDU
counts = fits.open(filename)[0].data
header = fits.open(filename)[0].header
images = GammaImages(counts=counts, header=header)

source_kernel = binary_disk(CORRELATION_RADIUS)

background_kernel = np.ones((10, 100))

# *** ITERATOR ***

ibe = IterativeKernelBackgroundEstimator(images=images,
                                         source_kernel=source_kernel,
                                         background_kernel=background_kernel,
                                         significance_threshold=SIGNIFICANCE_THRESHOLD,
                                         mask_dilation_radius=MASK_DILATION_RADIUS
                                         )

n_iterations = 4

# *** RUN & PLOT ***
plt.figure(figsize=(8, 4))

for iteration in range(n_iterations):
    ibe.run_iteration()
    mask_hdu = ibe.mask_image_hdu
    mask = mask_hdu.data[:, 1400:2000]

    plt.subplot(n_iterations, 2, 2 * iteration + 1)
    background_hdu = ibe.background_image_hdu