Exemple #1
0
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)