Esempio n. 1
0
def make_psf_mapcube(skydir, psf, outfile, npix=500, cdelt=0.01, rebin=1):
    energies = psf.energies
    nebin = len(energies)

    k = utils.make_psf_kernel(psf, npix * rebin, cdelt / rebin)

    if rebin > 1:
        k = utils.rebin_map(k, nebin, npix, rebin)
    w = wcs_utils.create_wcs(skydir, cdelt=cdelt,
                             crpix=npix / 2. + 0.5, naxis=3)

    w.wcs.crpix[2] = 1
    w.wcs.crval[2] = 10 ** energies[0]
    w.wcs.cdelt[2] = energies[1] - energies[0]
    w.wcs.ctype[2] = 'Energy'

    ecol = fits.Column(name='Energy', format='D', array=10 ** energies)
    hdu_energies = fits.BinTableHDU.from_columns([ecol], name='ENERGIES')

    hdu_image = fits.PrimaryHDU(np.zeros((nebin, npix, npix)),
                                header=w.to_header())

    hdu_image.data[...] = k

    hdu_image.header['CUNIT3'] = 'MeV'

    with fits.HDUList([hdu_image, hdu_energies]) as hdulist:
        hdulist.writeto(outfile, overwrite=True)
Esempio n. 2
0
def make_psf_mapcube(skydir, psf, outfile, npix=500, cdelt=0.01, rebin=1):
    energies = psf.energies
    nebin = len(energies)

    k = utils.make_psf_kernel(psf, npix * rebin, cdelt / rebin)

    if rebin > 1:
        k = utils.rebin_map(k, nebin, npix, rebin)
    w = wcs_utils.create_wcs(skydir,
                             cdelt=cdelt,
                             crpix=npix / 2. + 0.5,
                             naxis=3)

    w.wcs.crpix[2] = 1
    w.wcs.crval[2] = 10**energies[0]
    w.wcs.cdelt[2] = energies[1] - energies[0]
    w.wcs.ctype[2] = 'Energy'

    ecol = fits.Column(name='Energy', format='D', array=10**energies)
    hdu_energies = fits.BinTableHDU.from_columns([ecol], name='ENERGIES')

    hdu_image = fits.PrimaryHDU(np.zeros((nebin, npix, npix)),
                                header=w.to_header())

    hdu_image.data[...] = k

    hdu_image.header['CUNIT3'] = 'MeV'

    with fits.HDUList([hdu_image, hdu_energies]) as hdulist:
        hdulist.writeto(outfile, overwrite=True)
Esempio n. 3
0
def make_srcmap(skydir,
                psf,
                spatial_model,
                sigma,
                npix=500,
                xpix=0.0,
                ypix=0.0,
                cdelt=0.01,
                rebin=1,
                psf_scale_fn=None):
    """Compute the source map for a given spatial model.

    Parameters
    ----------

    skydir : `~astropy.coordinates.SkyCoord`

    psf : `~fermipy.irfs.PSFModel`

    spatial_model : str
        Spatial model.

    sigma : float
        Spatial size parameter for extended models.
        
    xpix : float
        Source position in pixel coordinates in X dimension.

    ypix : float
        Source position in pixel coordinates in Y dimension.

    rebin : int    
        Factor by which the original map will be oversampled in the
        spatial dimension when computing the model.

    psf_scale_fn : callable        
        Function that evaluates the PSF scaling function.
        Argument is energy in MeV.

    """

    energies = psf.energies
    nebin = len(energies)

    if spatial_model == 'GaussianSource' or spatial_model == 'RadialGaussian':
        k = utils.make_cgauss_kernel(psf, sigma, npix * rebin, cdelt / rebin,
                                     xpix * rebin, ypix * rebin, psf_scale_fn)
    elif spatial_model == 'DiskSource' or spatial_model == 'RadialDisk':
        k = utils.make_cdisk_kernel(psf, sigma, npix * rebin, cdelt / rebin,
                                    xpix * rebin, ypix * rebin, psf_scale_fn)
    elif spatial_model == 'PSFSource' or spatial_model == 'PointSource':
        k = utils.make_psf_kernel(psf, npix * rebin, cdelt / rebin,
                                  xpix * rebin, ypix * rebin, psf_scale_fn)
    else:
        raise Exception('Unrecognized spatial model: %s' % spatial_model)

    if rebin > 1:
        k = utils.rebin_map(k, nebin, npix, rebin)

    k *= psf.exp[:, np.newaxis, np.newaxis] * np.radians(cdelt)**2

    return k