def make_x_plot():
    energy_min = np.array([300])
    energy_max = np.array([1000])
    energies = np.array(_energy_lafferty_power_law(energy_min, energy_max,
                                                   SPECTRAL_INDEX))
    diff_flux = power_law_evaluate(energies, 1, SPECTRAL_INDEX, 1)
    # `True' differential & integral fluxes
    int_flux = power_law_integral_flux(diff_flux, SPECTRAL_INDEX,
                                       energies, energy_min, energy_max)
    # Put data into table
    table = Table()
    table['ENERGY_MIN'] = energy_min
    table['ENERGY_MAX'] = energy_max
    table['INT_FLUX'] = int_flux
    lafferty_array = []  
    log_array = []
    spectral_indices = np.arange(1.1, 6, 0.01)
    for spectral_index in spectral_indices:
        lafferty_flux, log_flux = get_flux_tables(table, 'power_law', None,
                                                  spectral_index)
        residuals_lafferty = ((np.log(lafferty_flux['ENERGY'])
                              - np.log(energy_min)) / (np.log(energy_max)-np.log(energy_min)))
        residuals_log = ((np.log(log_flux['ENERGY'])
                              - np.log(energy_min)) / (np.log(energy_max)-np.log(energy_min)))
        lafferty_array.append(residuals_lafferty[0])
        log_array.append(residuals_log[0])
    plt.plot(spectral_indices, lafferty_array, color='k',
             linewidth=1, ms=0, label='Lafferty Method')
    plt.plot(spectral_indices, log_array, color='r',
             linewidth=1, ms=0, label='Log Center Method')
    plt.legend()
    plt.ylabel('X position in bin')
    plt.xlabel('Guessed spectral Index')
Example #2
0
def make_x_plot():
    energy_min = np.array([300])
    energy_max = np.array([1000])
    energies = np.array(_energy_lafferty_power_law(energy_min, energy_max,
                                                   SPECTRAL_INDEX))
    diff_flux = power_law_evaluate(energies, 1, SPECTRAL_INDEX, 1)
    # `True' differential & integral fluxes
    int_flux = power_law_integral_flux(diff_flux, SPECTRAL_INDEX,
                                       energies, energy_min, energy_max)
    # Put data into table
    table = Table()
    table['ENERGY_MIN'] = energy_min
    table['ENERGY_MAX'] = energy_max
    table['INT_FLUX'] = int_flux
    lafferty_array = []
    log_array = []
    spectral_indices = np.arange(1.1, 6, 0.01)
    for spectral_index in spectral_indices:
        lafferty_flux, log_flux = get_flux_tables(table, 'power_law', None,
                                                  spectral_index)
        dlog_energy = np.log(energy_max) - np.log(energy_min)
        residuals_lafferty = np.log(lafferty_flux['ENERGY'] - np.log(energy_min)) / dlog_energy
        residuals_log = np.log(log_flux['ENERGY'] - np.log(energy_min)) / dlog_energy
        lafferty_array.append(residuals_lafferty[0])
        log_array.append(residuals_log[0])
    plt.plot(spectral_indices, lafferty_array,
             linewidth=1, ms=0, label='Lafferty Method')
    plt.plot(spectral_indices, log_array,
             linewidth=1, ms=0, label='Log Center Method')
    plt.legend()
    plt.ylabel('X position in bin')
    plt.xlabel('Guessed spectral Index')
CORRELATION_RADIUS = 3  # pix
SIGNIFICANCE_THRESHOLD = 5
MASK_DILATION_RADIUS = 0.3

psf_file = FermiGalacticCenter.filenames()['psf']
psf = EnergyDependentTablePSF.read(psf_file)

# *** LOADING INPUT ***

# Counts must be provided as a counts ImageHDU
flux_file = raw_input('Flux Map: ')
exposure_file = raw_input('Exposure Map: ')
spec_ind = input('Spectral Index (for reprojection): ')
flux_hdu = fits.open(flux_file)[1]
flux_wcs = WCS(flux_hdu.header)
energy_flux = Quantity([_energy_lafferty_power_law(10000, 500000, spec_ind)],
                       'MeV')
flux_data = np.zeros((1, 1800, 3600))
flux_data[0] = Quantity(flux_hdu.data, '')
flux_spec_cube = SpectralCube(data=flux_data, wcs=flux_wcs, energy=energy_flux)

exposure_hdu = fits.open(exposure_file)[0]
exposure_wcs = WCS(exposure_hdu.header)
energy_exp = Quantity([10000, 500000], 'MeV')
exposure_data = Quantity(exposure_hdu.data, '')
exposure_spec_cube = SpectralCube(data=exposure_data,
                                  wcs=exposure_wcs,
                                  energy=energy_exp)
exposure_spec_cube = exposure_spec_cube.reproject_to(flux_spec_cube)

counts_data = flux_spec_cube.data * exposure_spec_cube.data
CORRELATION_RADIUS = 3  # pix
SIGNIFICANCE_THRESHOLD = 5
MASK_DILATION_RADIUS = 0.3

psf_file = FermiGalacticCenter.filenames()["psf"]
psf = EnergyDependentTablePSF.read(psf_file)

# *** LOADING INPUT ***

# Counts must be provided as a counts ImageHDU
flux_file = raw_input("Flux Map: ")
exposure_file = raw_input("Exposure Map: ")
spec_ind = input("Spectral Index (for reprojection): ")
flux_hdu = fits.open(flux_file)[1]
flux_wcs = WCS(flux_hdu.header)
energy_flux = Quantity([_energy_lafferty_power_law(10000, 500000, spec_ind)], "MeV")
flux_data = np.zeros((1, 1800, 3600))
flux_data[0] = Quantity(flux_hdu.data, "")
flux_spec_cube = SpectralCube(data=flux_data, wcs=flux_wcs, energy=energy_flux)

exposure_hdu = fits.open(exposure_file)[0]
exposure_wcs = WCS(exposure_hdu.header)
energy_exp = Quantity([10000, 500000], "MeV")
exposure_data = Quantity(exposure_hdu.data, "")
exposure_spec_cube = SpectralCube(data=exposure_data, wcs=exposure_wcs, energy=energy_exp)
exposure_spec_cube = exposure_spec_cube.reproject_to(flux_spec_cube)

counts_data = flux_spec_cube.data * exposure_spec_cube.data
counts = fits.ImageHDU(data=counts_data[0], header=flux_hdu.header)
# Start with flat background estimate
# Background must be provided as an ImageHDU
from scipy.ndimage import gaussian_filter
from gammapy.image.utils import WCS
from astropy.units import Quantity
from gammapy.spectrum.flux_point import _energy_lafferty_power_law
from gammapy.irf import EnergyDependentTablePSF
from gammapy.image import make_empty_image, catalog_image, binary_disk
from gammapy.image.utils import cube_to_image, solid_angle
from gammapy.data import SpectralCube

counts_file = raw_input('Counts Map: ')
background_file = raw_input('Background Map: ')
exposure_file = raw_input('Exposure Map: ')
spec_ind = input('Spectral Index (for reprojection): ')
counts_hdu = fits.open(counts_file)[0]
counts_wcs = WCS(counts_hdu.header)
energy_counts = Quantity([_energy_lafferty_power_law(10000, 500000, spec_ind)], 'MeV')
counts_data = np.zeros((1, 1800, 3600))
counts_data[0] = Quantity(counts_hdu.data, '')
counts_spec_cube = SpectralCube(data=counts_data, wcs=counts_wcs, energy=energy_counts)

exposure_hdu = fits.open(exposure_file)[0]
exposure_wcs = WCS(exposure_hdu.header)
energy_exp = Quantity([10000, 500000], 'MeV')
exposure_data = Quantity(exposure_hdu.data, '')
exposure_spec_cube = SpectralCube(data=exposure_data, wcs=exposure_wcs, energy=energy_exp)
exposure_spec_cube = exposure_spec_cube.reproject_to(counts_spec_cube)

flux_data = counts_spec_cube.data / exposure_spec_cube.data
flux = fits.ImageHDU(data=flux_data[0], header=counts_hdu.header)

Example #6
0
from scipy.ndimage import gaussian_filter
from gammapy.image.utils import WCS
from astropy.units import Quantity
from gammapy.spectrum.flux_point import _energy_lafferty_power_law
from gammapy.irf import EnergyDependentTablePSF
from gammapy.image import make_empty_image, catalog_image, binary_disk
from gammapy.image.utils import cube_to_image, solid_angle
from gammapy.data import SpectralCube

counts_file = raw_input('Counts Map: ')
background_file = raw_input('Background Map: ')
exposure_file = raw_input('Exposure Map: ')
spec_ind = input('Spectral Index (for reprojection): ')
counts_hdu = fits.open(counts_file)[0]
counts_wcs = WCS(counts_hdu.header)
energy_counts = Quantity([_energy_lafferty_power_law(10000, 500000, spec_ind)],
                         'MeV')
counts_data = np.zeros((1, 1800, 3600))
counts_data[0] = Quantity(counts_hdu.data, '')
counts_spec_cube = SpectralCube(data=counts_data,
                                wcs=counts_wcs,
                                energy=energy_counts)

exposure_hdu = fits.open(exposure_file)[0]
exposure_wcs = WCS(exposure_hdu.header)
energy_exp = Quantity([10000, 500000], 'MeV')
exposure_data = Quantity(exposure_hdu.data, '')
exposure_spec_cube = SpectralCube(data=exposure_data,
                                  wcs=exposure_wcs,
                                  energy=energy_exp)
exposure_spec_cube = exposure_spec_cube.reproject_to(counts_spec_cube)