コード例 #1
0
"""Plot cube background model and store it in fits.

The 'image' format file can be viewed with ds9.
"""
import matplotlib.pyplot as plt
from astropy.units import Quantity
from astropy.coordinates import Angle
from gammapy.background import Cube
from gammapy import datasets

filename = datasets.get_path('../test_datasets/background/bg_cube_model_test.fits',
                             location='remote')
bg_cube_model = Cube.read(filename, format='table', scheme='bg_cube')

bg_cube_model.plot_image(energy=Quantity(2., 'TeV'))
bg_cube_model.plot_spectrum(coord=Angle([0., 0.], 'degree'))

outname = 'cube_background_model'
bg_cube_model.write('{}_bin_table.fits'.format(outname), format='table', clobber=True)
bg_cube_model.write('{}_image.fits'.format(outname), format='image', clobber=True)

plt.show()
コード例 #2
0
from gammapy.background import IterativeKernelBackgroundEstimator, GammaImages
from gammapy.irf import EnergyDependentTablePSF
from gammapy.image import make_empty_image, catalog_image, binary_disk, cube_to_image, solid_angle

# *** PREPARATION ***

# Parameters

CORRELATION_RADIUS = 10 # Pixels
SIGNIFICANCE_THRESHOLD = 5 # Sigma
MASK_DILATION_RADIUS = 10 # Pixels

psf_file = datasets.FermiGalacticCenter.psf()

# Load/create example model images.
filename = datasets.get_path('source_diffuse_separation/galactic_simulations/fermi_counts.fits',
                         location='remote')

# *** LOADING INPUT ***

# Counts must be provided as an ImageHDU
counts = fits.open(filename)[0].data
header = fits.open(filename)[0].header
images = GammaImages(counts=counts, header=header)

source_kernel = binary_disk(CORRELATION_RADIUS)

background_kernel = np.ones((10, 100))

# *** ITERATOR ***

ibe = IterativeKernelBackgroundEstimator(images=images,
コード例 #3
0
from gammapy.irf import EnergyDependentTablePSF
from gammapy.image import make_empty_image, catalog_image, binary_disk, cube_to_image, solid_angle

# *** PREPARATION ***

# Parameters

CORRELATION_RADIUS = 10  # Pixels
SIGNIFICANCE_THRESHOLD = 5  # Sigma
MASK_DILATION_RADIUS = 10  # Pixels

psf_file = datasets.FermiGalacticCenter.psf()

# Load/create example model images.
filename = datasets.get_path(
    'source_diffuse_separation/galactic_simulations/fermi_counts.fits',
    location='remote')

# *** LOADING INPUT ***

# Counts must be provided as an ImageHDU
counts = fits.open(filename)[0].data
header = fits.open(filename)[0].header
images = GammaImages(counts=counts, header=header)

source_kernel = binary_disk(CORRELATION_RADIUS)

background_kernel = np.ones((10, 100))

# *** ITERATOR ***
コード例 #4
0
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
from astropy.units import Quantity
from astropy.coordinates import Angle
from gammapy.background import Cube
from gammapy import datasets

filename = datasets.get_path(
    '../test_datasets/background/bg_cube_model_test1.fits', location='remote')
bg_cube_model = Cube.read(filename, format='table', scheme='bg_cube')

fig, axes = plt.subplots(nrows=1, ncols=3)
fig.set_size_inches(16, 5., forward=True)

# plot images
bg_cube_model.plot_image(energy=Quantity(0.5, 'TeV'),
                         ax=axes[0],
                         style_kwargs=dict(norm=LogNorm()))
bg_cube_model.plot_image(energy=Quantity(50., 'TeV'),
                         ax=axes[1],
                         style_kwargs=dict(norm=LogNorm()))

# plot spectra
bg_cube_model.plot_spectrum(coord=Angle([0., 0.], 'degree'),
                            ax=axes[2],
                            style_kwargs=dict(label='(0, 0) deg'))
bg_cube_model.plot_spectrum(coord=Angle([2., 2.], 'degree'),
                            ax=axes[2],
                            style_kwargs=dict(label='(2, 2) deg'))
axes[2].set_title('')
axes[2].legend()
コード例 #5
0
"""Eventlist coordinate check.
"""
from gammapy.data import EventListDataset
from gammapy.datasets import get_path


filename = get_path('hess/run_0023037_hard_eventlist.fits.gz')
event_list = EventListDataset.read(filename)
print(event_list.info)
event_list.check()

"""
TODO: figure out the origin of this offset:
ALT / AZ not consistent with RA / DEC. Max separation: 823.3407076612169 arcsec
"""
コード例 #6
0
"""Eventlist coordinate check.
"""
from gammapy.data import EventListDataset
from gammapy.datasets import get_path

filename = get_path('hess/run_0023037_hard_eventlist.fits.gz')
event_list = EventListDataset.read(filename)
print(event_list.info)
event_list.check()
"""
TODO: figure out the origin of this offset:
ALT / AZ not consistent with RA / DEC. Max separation: 823.3407076612169 arcsec
"""