Ejemplo n.º 1
0
import numpy as np
from astropy.io import fits

fd_cube = fits.open('gll_iem_v05.fits')
energies = fd_cube[1].data

energy = gmean([10, 500]) * 1000  #GeV to MeV

energy_array = fd_cube[1].data['Energy']
index = np.searchsorted(energy_array, energy)

actual_energy = energy_array[index]
print actual_energy
from kapteyn.maputils import FITSimage
from gammapy.image.utils import cube_to_image
energy_image = cube_to_image(fd_cube[0], index)
energy_image.writeto('fermi_diffuse_slice_10_500.fits', clobber=True)
#reproject to 0.1 deg per pixel resolution
original = FITSimage('fermi_diffuse_slice_10_500.fits', hdunr=1)
reference_data = fits.open('10_500_counts.fits')[0].data
reference_header = fits.open('10_500_counts.fits')[0].header
reference = fits.ImageHDU(data=reference_data, header=reference_header)
reference.writeto('10_500_counts2.fits', clobber=True)
reference = FITSimage('10_500_counts2.fits', hdunr=1)

from utils import image_reprojection

new = image_reprojection(original, reference)
new.writetofits('fermi_diffuse_10_500_reprojected.fits', clobber=True)
out_data = np.nan_to_num(
    fits.open('fermi_diffuse_10_500_reprojected.fits')[0].data)
Ejemplo n.º 2
0
spec_ind = input('Spectral Index (for reprojection): ')
flux_hdu = fits.open(comparison_diffuse)[1]
flux_wcs = WCS(flux_hdu.header)
energy_flux = Quantity([_energy_lafferty_power_law(10000, 500000, spec_ind)],
                       'MeV')
flux_data = np.zeros((1, 103, 2001))
flux_data[0] = Quantity(flux_hdu.data, '')
flux_spec_cube = SpectralCube(data=Quantity(flux_data, '1 / (cm2 MeV s sr)'),
                              wcs=flux_wcs,
                              energy=energy_flux)

diffuse_spec_cube = SpectralCube.read(fermi_diffuse)
diffuse_spec_cube.data = Quantity(diffuse_spec_cube.data, '1 / (cm2 MeV s sr)')
fermi_diffuse_spec_cube = diffuse_spec_cube.reproject_to(flux_spec_cube)

energy_band = Quantity((10, 500), 'GeV')

a = fermi_diffuse_spec_cube.integral_flux_image(energy_band)
angles = fermi_diffuse_spec_cube.solid_angle_image
b = angles.value
c = a.data * b

diffuse = fits.ImageHDU(data=c, header=flux_hdu.header)
diffuse.writeto('diffuse_correct.fits')

ratio = flux_spec_cube.data / c

ratio_hdu = fits.ImageHDU(data=ratio.value, header=flux_hdu.header)
ratio_im_hdu = cube_to_image(ratio_hdu)
ratio_im_hdu.writeto('ratio.fits', clobber=True)
import numpy as np
from astropy.io import fits

fd_cube = fits.open('gll_iem_v05.fits')
energies = fd_cube[1].data

energy = gmean([10, 500]) * 1000 #GeV to MeV

energy_array = fd_cube[1].data['Energy']
index = np.searchsorted(energy_array, energy)

actual_energy = energy_array[index]
print actual_energy
from kapteyn.maputils import FITSimage
from gammapy.image.utils import cube_to_image
energy_image = cube_to_image(fd_cube[0], index)
energy_image.writeto('fermi_diffuse_slice_10_500.fits', clobber=True)
#reproject to 0.1 deg per pixel resolution
original = FITSimage('fermi_diffuse_slice_10_500.fits', hdunr=1)
reference_data = fits.open('10_500_counts.fits')[0].data
reference_header = fits.open('10_500_counts.fits')[0].header
reference = fits.ImageHDU(data = reference_data, header = reference_header)
reference.writeto('10_500_counts2.fits', clobber=True)
reference = FITSimage('10_500_counts2.fits', hdunr=1)

from utils import image_reprojection

new = image_reprojection(original, reference)
new.writetofits('fermi_diffuse_10_500_reprojected.fits', clobber=True)
out_data = np.nan_to_num(fits.open('fermi_diffuse_10_500_reprojected.fits')[0].data)
out_header = fits.open('fermi_diffuse_10_500_reprojected.fits')[0].header
Ejemplo n.º 4
0
fermi_diffuse = 'gll_iem_v05_rev1.fit'
comparison_diffuse = raw_input('Diffuse Model: ')

spec_ind = input('Spectral Index (for reprojection): ')
flux_hdu = fits.open(comparison_diffuse)[1]
flux_wcs = WCS(flux_hdu.header)
energy_flux = Quantity([_energy_lafferty_power_law(10000, 500000, spec_ind)], 'MeV')
flux_data = np.zeros((1, 103, 2001))
flux_data[0] = Quantity(flux_hdu.data, '')
flux_spec_cube = SpectralCube(data=Quantity(flux_data, '1 / (cm2 MeV s sr)'), wcs=flux_wcs, energy=energy_flux)

diffuse_spec_cube = SpectralCube.read(fermi_diffuse)
diffuse_spec_cube.data = Quantity(diffuse_spec_cube.data, '1 / (cm2 MeV s sr)')
fermi_diffuse_spec_cube = diffuse_spec_cube.reproject_to(flux_spec_cube)

energy_band = Quantity((10, 500), 'GeV')

a = fermi_diffuse_spec_cube.integral_flux_image(energy_band)
angles = fermi_diffuse_spec_cube.solid_angle_image
b = angles.value
c = a.data * b

diffuse = fits.ImageHDU(data=c, header=flux_hdu.header)
diffuse.writeto('diffuse_correct.fits')

ratio = flux_spec_cube.data / c

ratio_hdu = fits.ImageHDU(data=ratio.value, header=flux_hdu.header)
ratio_im_hdu = cube_to_image(ratio_hdu)
ratio_im_hdu.writeto('ratio.fits', clobber=True)