def prepare_images(): # Reads in data background_file = FermiVelaRegion.filenames()['diffuse_model'] exposure_file = FermiVelaRegion.filenames()['exposure_cube'] counts_file = FermiVelaRegion.filenames()['counts_cube'] background_model = SpectralCube.read(background_file) exposure_cube = SpectralCube.read(exposure_file) # Add correct units exposure_cube.data = Quantity(exposure_cube.data.value, 'cm2 s') # Re-project background cube repro_bg_cube = background_model.reproject_to(exposure_cube) # Define energy band required for output energies = Quantity([10, 500], 'GeV') # Compute the predicted counts cube npred_cube = compute_npred_cube(repro_bg_cube, exposure_cube, energies) # Convolve with Energy-dependent Fermi LAT PSF psf = EnergyDependentTablePSF.read(FermiVelaRegion.filenames()['psf']) convolved_npred_cube = convolve_cube(npred_cube, psf, offset_max=Angle(3, 'deg')) # Counts data counts_data = fits.open(counts_file)[0].data counts_wcs = WCS(fits.open(counts_file)[0].header) counts_cube = SpectralCube(data=Quantity(counts_data, ''), wcs=counts_wcs, energy=energies) counts_cube = counts_cube.reproject_to(npred_cube) counts = counts_cube.data[0] model = convolved_npred_cube.data[0] # Load Fermi tools gtmodel background-only result gtmodel = fits.open( FermiVelaRegion.filenames()['background_image'])[0].data.astype(float) # Ratio for the two background images ratio = np.nan_to_num(model / gtmodel) # Header is required for plotting, so returned here wcs = npred_cube.wcs wcs = wcs.dropaxis(2) header = wcs.to_header() return model, gtmodel, ratio, counts, header
def prepare_images(): # Reads in data background_file = FermiVelaRegion.filenames()['diffuse_model'] exposure_file = FermiVelaRegion.filenames()['exposure_cube'] counts_file = FermiVelaRegion.filenames()['counts_cube'] background_model = SpectralCube.read(background_file) exposure_cube = SpectralCube.read(exposure_file) # Add correct units exposure_cube.data = Quantity(exposure_cube.data.value, 'cm2 s') # Re-project background cube repro_bg_cube = background_model.reproject_to(exposure_cube) # Define energy band required for output energies = Quantity([10, 500], 'GeV') # Compute the predicted counts cube npred_cube = compute_npred_cube(repro_bg_cube, exposure_cube, energies) # Convolve with Energy-dependent Fermi LAT PSF psf = EnergyDependentTablePSF.read(FermiVelaRegion.filenames()['psf']) convolved_npred_cube = convolve_cube(npred_cube, psf, offset_max=Angle(3, 'deg')) # Counts data counts_data = fits.open(counts_file)[0].data counts_wcs = WCS(fits.open(counts_file)[0].header) counts_cube = SpectralCube(data=Quantity(counts_data, ''), wcs=counts_wcs, energy=energies) counts_cube = counts_cube.reproject_to(npred_cube) counts = counts_cube.data[0] model = convolved_npred_cube.data[0] # Load Fermi tools gtmodel background-only result gtmodel = fits.open(FermiVelaRegion.filenames()['background_image'])[0].data.astype(float) # Ratio for the two background images ratio = np.nan_to_num(model / gtmodel) # Header is required for plotting, so returned here wcs = npred_cube.wcs wcs = wcs.dropaxis(2) header = wcs.to_header() return model, gtmodel, ratio, counts, header
"""Test npred model image computation. """ from astropy.units import Quantity from astropy.coordinates import Angle from gammapy.datasets import FermiGalacticCenter from gammapy.irf import EnergyDependentTablePSF from gammapy.data import (SpectralCube, compute_npred_cube, convolve_cube) filenames = FermiGalacticCenter.filenames() spectral_cube = SpectralCube.read(filenames['diffuse_model']) exposure_cube = SpectralCube.read(filenames['exposure_cube']) psf = EnergyDependentTablePSF.read(filenames['psf']) spectral_cube = spectral_cube.reproject_to(exposure_cube) energy_bounds = Quantity([10, 30, 100, 500], 'GeV') npred_cube = compute_npred_cube(spectral_cube, exposure_cube, energy_bounds) offset_max = Angle(1, 'deg') npred_cube_convolved = convolve_cube(npred_cube, psf, offset_max)