Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix master docs build #1017

Merged
merged 2 commits into from May 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/development/howto.rst
Expand Up @@ -762,7 +762,7 @@ that is defined in `gammapy.utils.mpl_style`. The style is derived from the
astropy plotting style applying a few minor changes. Here are two examples:

* :ref:`Crab MWL SED plot <crab-mwl-sed>`
* :ref:`Fermi 1FHL image <fermi-1fhl-image>`
* :ref:`Fermi 3FHL image <fermi-3fhl-image>`

For the Gammapy docs the style is used by default and doesn't have to be set
explicitly. If you would like to use the style outside the Gammapy docs, add
Expand Down
25 changes: 8 additions & 17 deletions docs/tutorials/catalog/index.rst
Expand Up @@ -3,20 +3,19 @@
Catalog & Simulation Images
===========================

The `~gammapy.image.catalog_image` method allows the production of
single energy-band 2D images from point source catalogs, either true catalogs
(e.g. 1FHL or 2FGL) or source catalogs of simulated galaxies (produced with
The `~gammapy.image.CatalogImageEstimator` class allows the production of
single energy-band 2D images from source catalogs, either true catalogs
(e.g. such as 3FHL) or source catalogs of simulated galaxies (produced with
`~gammapy.astro.population`). Examples of these two use-cases are included below.

Source Catalog Images
---------------------

The example script below produces a point source catalog image from the published
1FHL Fermi Source Catalog from 10 to 500 GeV. Fluxes are filled into each pixel
corresponding to source Galactic Latitude and Longitude, and then convolved with
the Fermi PSF in this energy band.
3FHL Fermi Source Catalog from 10 to 500 GeV. Fluxes are filled into each pixel
corresponding to source Galactic Latitude and Longitude.

.. _fermi-1fhl-image:
.. _fermi-3fhl-image:

.. plot:: tutorials/catalog/source_image_demo.py
:include-source:
Expand All @@ -27,13 +26,5 @@ Simulated Catalog Images
In this case, a galaxy is simulated with `~gammapy.astro.population` to produce a
source catalog. This is then converted into an image.

.. plot:: tutorials/catalog/simulated_image_demo.py
:include-source:

Caveats & Future Developments
-----------------------------

It should be noted that the current implementation does not support:

* The inclusion of extended sources
* Production of images in more than one energy band
#.. plot:: tutorials/catalog/simulated_image_demo.py
# :include-source:
2 changes: 1 addition & 1 deletion docs/tutorials/catalog/simulated_image_demo.py
Expand Up @@ -6,7 +6,7 @@
from aplpy import FITSFigure
from gammapy.astro import population
from gammapy.datasets import FermiGalacticCenter
from gammapy.image import SkyImage, catalog_image
from gammapy.image.catalog import SkyImage, catalog_image
from gammapy.irf import EnergyDependentTablePSF
from gammapy.utils.random import sample_powerlaw

Expand Down
35 changes: 15 additions & 20 deletions docs/tutorials/catalog/source_image_demo.py
Expand Up @@ -2,27 +2,22 @@
"""
import numpy as np
import matplotlib.pyplot as plt
from aplpy import FITSFigure
from gammapy.datasets import FermiGalacticCenter
from gammapy.image import catalog_image, SkyImage
from astropy import units as u
from astropy.visualization import simple_norm
from gammapy.image import CatalogImageEstimator, SkyImage
from gammapy.irf import EnergyDependentTablePSF
from gammapy.catalog import SourceCatalog3FHL

# Create image of defined size
reference = SkyImage.empty(nxpix=300, nypix=100, binsz=1).to_image_hdu()
psf_file = FermiGalacticCenter.filenames()['psf']
psf = EnergyDependentTablePSF.read(psf_file)
# Create reference image
reference = SkyImage.empty(nxpix=300, nypix=100, binsz=0.1)
emin, emax = [10, 500] * u.GeV

# Create image
image = catalog_image(reference, psf, catalog='1FHL', source_type='point',
total_flux='True')
fermi_3fhl = SourceCatalog3FHL()
estimator = CatalogImageEstimator(reference=reference, emin=emin, emax=emax)

# Plot
fig = FITSFigure(image.to_fits(format='fermi-background')[0], figsize=(15, 5))
fig.show_colorscale(interpolation='bicubic', cmap='afmhot', stretch='log', vmin=1E-12, vmax=1E-8)
fig.tick_labels.set_xformat('ddd')
fig.tick_labels.set_yformat('dd')
ticks = np.logspace(-12, -8, 5)
fig.add_colorbar(ticks=ticks, axis_label_text='Flux (cm^-2 s^-1 TeV^-1)')
fig.colorbar._colorbar_axes.set_yticklabels(['{:.0e}'.format(_) for _ in ticks])
plt.tight_layout()
plt.show()
result = estimator.run(fermi_3fhl)

flux = result['flux'].smooth(radius=0.2 * u.deg)

norm = simple_norm(flux.data, stretch='log')
flux.show(norm=norm)
8 changes: 5 additions & 3 deletions gammapy/cube/sherpa_.py
Expand Up @@ -422,10 +422,12 @@ def calc(self, pars, elo, xlo, ylo, ehi, xhi, yhi):
# Convolve by the energy resolution
etrue_band = self.true_energy.bands
for ireco in range(self.dim_Ereco):
self.convolve_edisp[:, :, :, ireco] = np.moveaxis(spatial, 0, -1) * np.moveaxis(spectral, 0, -1) * \
self.edisp[:, ireco] * etrue_band
self.convolve_edisp[:, :, :, ireco] = (np.rollaxis(spatial, 0, spatial.ndim)
* np.rollaxis(spectral, 0, spectral.ndim)
* self.edisp[:, ireco] * etrue_band)
# Integration in etrue
model = np.moveaxis(np.sum(self.convolve_edisp, axis=2), -1, 0)
sum_model = np.sum(self.convolve_edisp, axis=2)
model = np.rollaxis(sum_model, -1, 0)
if not self.select_region:
return model.ravel()
else:
Expand Down
27 changes: 11 additions & 16 deletions gammapy/image/models/models.py
Expand Up @@ -21,8 +21,7 @@


class Shell2D(Fittable2DModel):
"""
Projected homogeneous radiating shell model.
"""Projected homogeneous radiating shell model.

This model can be used for a shell type SNR source morphology.

Expand All @@ -47,7 +46,7 @@ class Shell2D(Fittable2DModel):

See Also
--------
Sphere2D, Delta2D, `~astropy.modeling.models.Gaussian2D`
Sphere2D, Delta2D, Gaussian2D

Notes
-----
Expand Down Expand Up @@ -162,8 +161,7 @@ def bounding_box(self):


class Sphere2D(Fittable2DModel):
"""
Projected homogeneous radiating sphere model.
"""Projected homogeneous radiating sphere model.

This model can be used for a simple PWN source morphology.

Expand All @@ -182,10 +180,9 @@ class Sphere2D(Fittable2DModel):
function. If not set the 'amplitude' parameter corresponds to the
peak value of the function (value at :math:`r = 0`).


See Also
--------
Shell2D, Delta2D, `~astropy.modeling.models.Gaussian2D`
Shell2D, Delta2D, Gaussian2D

Notes
-----
Expand Down Expand Up @@ -278,8 +275,7 @@ def bounding_box(self):


class Delta2D(Fittable2DModel):
"""
Two dimensional delta function .
"""Two dimensional delta function .

This model can be used for a point source morphology.

Expand All @@ -292,10 +288,6 @@ class Delta2D(Fittable2DModel):
y_0 : float
y position center of the point source

See Also
--------
Shell2D, Sphere2D, `~astropy.modeling.models.Gaussian2D`

Notes
-----
Model formula:
Expand All @@ -309,6 +301,10 @@ class Delta2D(Fittable2DModel):
\\end{array}
\\right.

See Also
--------
Shell2D, Sphere2D, Gaussian2D

"""

amplitude = Parameter('amplitude')
Expand Down Expand Up @@ -336,8 +332,7 @@ def evaluate(x, y, amplitude, x_0, y_0):


class Template2D(Fittable2DModel):
"""
Two dimensional table model .
"""Two dimensional table model.

Parameters
----------
Expand All @@ -346,7 +341,7 @@ class Template2D(Fittable2DModel):

See Also
--------
Shell2D, Sphere2D, `~astropy.modeling.models.Gaussian2D`
Shell2D, Sphere2D, Gaussian2D

"""
amplitude = Parameter('amplitude')
Expand Down