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
def image_coordinates(infile, outfile, make_coordinate_maps, make_distance_map, overwrite): """Make maps that can be used to create profiles. The following images can be created: * LON -- Longitude coordinate * LAT -- Latitude coordinate * DIST -- Distance to mask * SOLID_ANGLE -- Solid angle """ from astropy.io import fits from gammapy.utils.fits import get_hdu from gammapy.image import SkyMap, ExclusionMask log.info('Reading {0}'.format(infile)) hdu = get_hdu(infile) out_hdus = fits.HDUList() if make_coordinate_maps: skymap = SkyMap.empty_like(hdu) log.info('Computing LON and LAT maps') lon, lat = skymap.coordinates() out_hdus.append(fits.ImageHDU(lon, hdu.header, 'LON')) out_hdus.append(fits.ImageHDU(lat, hdu.header, 'LAT')) if make_distance_map: excl = ExclusionMask.from_image_hdu(hdu) log.info('Computing DIST map') dist = excl.exclusion_distance out_hdus.append(fits.ImageHDU(dist, hdu.header, 'DIST')) log.info('Writing {0}'.format(outfile)) out_hdus.writeto(outfile, clobber=overwrite)
def image_coordinates(infile, outfile, make_coordinate_maps, make_distance_map, overwrite): """Make maps that can be used to create profiles. The following images can be created: * LON -- Longitude coordinate * LAT -- Latitude coordinate * DIST -- Distance to mask * SOLID_ANGLE -- Solid angle """ from astropy.io import fits from gammapy.utils.fits import get_hdu from gammapy.image import SkyMap, ExclusionMask log.info('Reading {0}'.format(infile)) hdu = get_hdu(infile) out_hdus = fits.HDUList() if make_coordinate_maps: skymap = SkyMap.empty_like(hdu) log.info('Computing LON and LAT maps') lon, lat = skymap.coordinates() out_hdus.append(fits.ImageHDU(lon, hdu.header, 'LON')) out_hdus.append(fits.ImageHDU(lat, hdu.header, 'LAT')) if make_distance_map: excl = ExclusionMask.read(hdu) log.info('Computing DIST map') dist = excl.exclusion_distance out_hdus.append(fits.ImageHDU(dist, hdu.header, 'DIST')) log.info('Writing {0}'.format(outfile)) out_hdus.writeto(outfile, clobber=overwrite)