Skip to content

Commit

Permalink
Working on code review for PR gammapy#299 (CubeBackgroundModel class).
Browse files Browse the repository at this point in the history
  • Loading branch information
mapazarr authored and JonathanDHarris committed Sep 19, 2015
1 parent c59322f commit 4953229
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 131 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -52,6 +52,8 @@ Pull requests
- Remove gammapy.shower package [#291] (Christoph Deil)
- Add EffectiveAreaTable exporter to EffectiveAreaTable2D [#276] (Johannes King)
- Add interface to HESS FitSpectrum JSON output [#296] (Christoph Deil)
- Remove gammapy.shower package [#291] (Christoph Deil)
- Add cube background model class [#299] (Manuel Paz Arribas)

.. _gammapy_0p2_release:

Expand Down
47 changes: 2 additions & 45 deletions docs/background/index.rst
Expand Up @@ -20,58 +20,15 @@ and Section 7.4 "Acceptance determination and predicted background"
in [Naurois2012]_ describe mostly the same methods as [Berge2007]_,
except for the "2D acceptance model" described in Section 7.4.3.

The backgrund models implemented in Gammapy are documented in :ref:`bg_models`.

Getting Started
===============

TODO

Hello World.

.. _bg_models:

Background Models
=================

The naming of the models in this section follows the convention from
:ref:`dataformats_overview`.

.. _background_3D:

BACKGROUND_3D
-------------

`BACKGROUND_3D` is a background rate 3D cube (X, Y, energy) in
units of per energy, per time, per solid angle. `X` and `Y` are
given in detector coordinates `(DETX, DETY)`, a.k.a.
`nominal system`. This is a tangential system to the instrument
during observations.

The `~CubeBackgroundModel` is used as container class for this model.
It has methods to read, write and operate the 3D cubes.

For the moment, only I/O and visualization methods are implemented.
A test file is located in the `~gammapy-extra` repository
(`bg_cube_model_test.fits <https://github.com/gammapy/gammapy-extra/blob/master/test_datasets/background/bg_cube_model_test.fits>`_).
The file comes originally from the `~GammaLib` repository but has
been slightly modified.

TODO: the scripts produce some white canvases that I need to remove!

An example script of how to read/write the files and perform some
simple plots is given in the `examples` directory:

.. plot:: ../examples/plot_background_model.py
:include-source:

More complex plots can be easily produced with a few lines of code:
TODO: mosaic/stack plots examples!!!

.. plot:: background/plot_bgcube_images_mosaic.py
:include-source:

.. plot:: background/plot_bgcube_spectra_stack.py
:include-source:

Reference/API
=============

Expand Down
13 changes: 4 additions & 9 deletions examples/plot_background_model.py
Expand Up @@ -6,20 +6,15 @@
from gammapy.background import CubeBackgroundModel
from gammapy import datasets

# read
filename = '../test_datasets/background/bg_cube_model_test.fits'
filename = datasets.get_path(filename, location='remote')
filename = datasets.get_path('../test_datasets/background/bg_cube_model_test.fits',
location='remote')
bg_model = CubeBackgroundModel.read(filename, format='table')

# plot
bg_model.plot_image(energy=Quantity(2., 'TeV'))
bg_model.plot_spectrum(det=Angle([0., 0.], 'degree'))

# write
outname = 'cube_background_model'
bg_model.write('{}_bin_table.fits'.format(outname), format='table',
write_kwargs=dict(clobber=True))
bg_model.write('{}_image.fits'.format(outname), format='image',
write_kwargs=dict(clobber=True))
bg_model.write('{}_bin_table.fits'.format(outname), format='table', clobber=True)
bg_model.write('{}_image.fits'.format(outname), format='image', clobber=True)

plt.show()

0 comments on commit 4953229

Please sign in to comment.