def create(cls, skydir, ltc, event_class, event_types, energies, cth_bins=None, ndtheta=500, use_edisp=False, fn=None, nbin=64): """Create a PSFModel object. This class can be used to evaluate the exposure-weighted PSF for a source with a given observing profile and energy distribution. Parameters ---------- skydir : `~astropy.coordinates.SkyCoord` ltc : `~fermipy.irfs.LTCube` energies : `~numpy.ndarray` Grid of energies at which the PSF will be pre-computed. cth_bins : `~numpy.ndarray` Bin edges in cosine of the inclination angle. use_edisp : bool Generate the PSF model accounting for the influence of energy dispersion. fn : `~fermipy.spectrum.SpectralFunction` Model for the spectral energy distribution of the source. """ if isinstance(event_types, int): event_types = bitmask_to_bits(event_types) if fn is None: fn = spectrum.PowerLaw([1E-13, -2.0]) dtheta = np.logspace(-4, 1.75, ndtheta) dtheta = np.insert(dtheta, 0, [0]) log_energies = np.log10(energies) egy_bins = 10**utils.center_to_edge(log_energies) if cth_bins is None: cth_bins = np.array([0.2, 1.0]) if use_edisp: psf = create_wtd_psf(skydir, ltc, event_class, event_types, dtheta, egy_bins, cth_bins, fn, nbin=nbin) wts = calc_counts_edisp(skydir, ltc, event_class, event_types, egy_bins, cth_bins, fn, nbin=nbin) else: psf = create_avg_psf(skydir, ltc, event_class, event_types, dtheta, energies, cth_bins) wts = calc_counts(skydir, ltc, event_class, event_types, egy_bins, cth_bins, fn) exp = calc_exp(skydir, ltc, event_class, event_types, energies, cth_bins) return cls(dtheta, energies, cth_bins, np.squeeze(exp), np.squeeze(psf), np.squeeze(wts))
def create(skydir, ltc, event_class, event_types, energies, cth_bins=None, ndtheta=500, use_edisp=False, fn=None, nbin=64): """Create a PSFModel object. This class can be used to evaluate the exposure-weighted PSF for a source with a given observing profile and energy distribution. Parameters ---------- skydir : `~astropy.coordinates.SkyCoord` ltc : `~fermipy.irfs.LTCube` energies : `~numpy.ndarray` Grid of energies at which the PSF will be pre-computed. cth_bins : `~numpy.ndarray` Bin edges in cosine of the inclination angle. use_edisp : bool Generate the PSF model accounting for the influence of energy dispersion. fn : `~fermipy.spectrum.SpectralFunction` Model for the spectral energy distribution of the source. """ if isinstance(event_types, int): event_types = bitmask_to_bits(event_types) if fn is None: fn = spectrum.PowerLaw([1E-13, -2.0]) dtheta = np.logspace(-4, 1.75, ndtheta) dtheta = np.insert(dtheta, 0, [0]) log_energies = np.log10(energies) egy_bins = 10**utils.center_to_edge(log_energies) if cth_bins is None: cth_bins = np.array([0.2, 1.0]) if use_edisp: psf = create_wtd_psf(skydir, ltc, event_class, event_types, dtheta, egy_bins, cth_bins, fn, nbin=nbin) wts = calc_counts_edisp(skydir, ltc, event_class, event_types, egy_bins, cth_bins, fn, nbin=nbin) else: psf = create_avg_psf(skydir, ltc, event_class, event_types, dtheta, energies, cth_bins) wts = calc_counts(skydir, ltc, event_class, event_types, egy_bins, cth_bins, fn) exp = calc_exp(skydir, ltc, event_class, event_types, energies, cth_bins) return PSFModel(dtheta, energies, cth_bins, np.squeeze(exp), np.squeeze(psf), np.squeeze(wts))
def find_and_read_ebins(hdulist): """ Reads and returns the energy bin edges. This works for both the CASE where the energies are in the ENERGIES HDU and the case where they are in the EBOUND HDU """ from fermipy import utils ebins = None if 'ENERGIES' in hdulist: hdu = hdulist['ENERGIES'] ectr = hdu.data.field(hdu.columns[0].name) ebins = np.exp(utils.center_to_edge(np.log(ectr))) elif 'EBOUNDS' in hdulist: hdu = hdulist['EBOUNDS'] emin = hdu.data.field('E_MIN') / 1E3 emax = hdu.data.field('E_MAX') / 1E3 ebins = np.append(emin, emax[-1]) return ebins
def find_and_read_ebins(hdulist): """ Reads and returns the energy bin edges. This works for both the CASE where the energies are in the ENERGIES HDU and the case where they are in the EBOUND HDU """ from fermipy import utils ebins = None if 'ENERGIES' in hdulist: hdu = hdulist['ENERGIES'] ectr = hdu.data.field(hdu.columns[0].name) ebins = np.exp(utils.center_to_edge(np.log(ectr))) elif 'EBOUNDS' in hdulist: hdu = hdulist['EBOUNDS'] emin = hdu.data.field('E_MIN') / 1E3 emax = hdu.data.field('E_MAX') / 1E3 ebins = np.append(emin, emax[-1]) return ebins
def create_from_fits(fitsfile, **kwargs): hdu = kwargs.get('hdu', 0) hdulist = fits.open(fitsfile) header = hdulist[hdu].header data = hdulist[hdu].data header = fits.Header.fromstring(header.tostring()) wcs = WCS(header) ebins = None if 'ENERGIES' in hdulist: tab = Table.read(fitsfile, 'ENERGIES') ectr = np.array(tab.columns[0]) ebins = np.exp(utils.center_to_edge(np.log(ectr))) elif 'EBOUNDS' in hdulist: tab = Table.read(fitsfile, 'EBOUNDS') emin = np.array(tab['E_MIN']) / 1E3 emax = np.array(tab['E_MAX']) / 1E3 ebins = np.append(emin, emax[-1]) return Map(data, wcs, ebins)
def create_from_fits(cls, fitsfile, **kwargs): hdu = kwargs.get('hdu', 0) with fits.open(fitsfile) as hdulist: header = hdulist[hdu].header data = hdulist[hdu].data header = fits.Header.fromstring(header.tostring()) wcs = WCS(header) ebins = None if 'ENERGIES' in hdulist: tab = Table.read(fitsfile, 'ENERGIES') ectr = np.array(tab.columns[0]) ebins = np.exp(utils.center_to_edge(np.log(ectr))) elif 'EBOUNDS' in hdulist: tab = Table.read(fitsfile, 'EBOUNDS') emin = np.array(tab['E_MIN']) / 1E3 emax = np.array(tab['E_MAX']) / 1E3 ebins = np.append(emin, emax[-1]) return cls(data, wcs, ebins)