Skip to content

Instantly share code, notes, and snippets.

@cdeil
Created July 31, 2015 06:03
Show Gist options
  • Save cdeil/470f03224b4df3f53c08 to your computer and use it in GitHub Desktop.
Save cdeil/470f03224b4df3f53c08 to your computer and use it in GitHub Desktop.
This file has been truncated, but you can view the full file.
% Generated by Sphinx.
\def\sphinxdocclass{report}
\documentclass[letterpaper,10pt,english]{sphinxmanual}
\usepackage[utf8]{inputenc}
\DeclareUnicodeCharacter{00A0}{\nobreakspace}
\usepackage{cmap}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{times}
\usepackage[Bjarne]{fncychap}
\usepackage{longtable}
\usepackage{sphinx}
\usepackage{multirow}
\addto\captionsenglish{\renewcommand{\figurename}{Fig. }}
\addto\captionsenglish{\renewcommand{\tablename}{Table }}
\floatname{literal-block}{Listing }
% Use a more modern-looking monospace font
\usepackage{inconsolata}
% The enumitem package provides unlimited nesting of lists and enums.
% Sphinx may use this in the future, in which case this can be removed.
% See https://bitbucket.org/birkenfeld/sphinx/issue/777/latex-output-too-deeply-nested
\usepackage{enumitem}
\setlistdepth{15}
% In the parameters section, place a newline after the Parameters
% header. (This is stolen directly from Numpy's conf.py, since it
% affects Numpy-style docstrings).
\usepackage{expdlist}
\let\latexdescription=\description
\def\description{\latexdescription{}{} \breaklabel}
% Support the superscript Unicode numbers used by the "unicode" units
% formatter
\DeclareUnicodeCharacter{2070}{\ensuremath{^0}}
\DeclareUnicodeCharacter{00B9}{\ensuremath{^1}}
\DeclareUnicodeCharacter{00B2}{\ensuremath{^2}}
\DeclareUnicodeCharacter{00B3}{\ensuremath{^3}}
\DeclareUnicodeCharacter{2074}{\ensuremath{^4}}
\DeclareUnicodeCharacter{2075}{\ensuremath{^5}}
\DeclareUnicodeCharacter{2076}{\ensuremath{^6}}
\DeclareUnicodeCharacter{2077}{\ensuremath{^7}}
\DeclareUnicodeCharacter{2078}{\ensuremath{^8}}
\DeclareUnicodeCharacter{2079}{\ensuremath{^9}}
\DeclareUnicodeCharacter{207B}{\ensuremath{^-}}
\DeclareUnicodeCharacter{00B0}{\ensuremath{^{\circ}}}
\DeclareUnicodeCharacter{2032}{\ensuremath{^{\prime}}}
\DeclareUnicodeCharacter{2033}{\ensuremath{^{\prime\prime}}}
% Make the "warning" and "notes" sections use a sans-serif font to
% make them stand out more.
\renewenvironment{notice}[2]{
\def\py@noticetype{#1}
\csname py@noticestart@#1\endcsname
\textsf{\textbf{#2}}
}{\csname py@noticeend@\py@noticetype\endcsname}
\title{gammapy Documentation}
\date{July 30, 2015}
\release{0.3.dev1396}
\author{The Gammapy developers}
\newcommand{\sphinxlogo}{}
\renewcommand{\releasename}{Release}
\makeindex
\makeatletter
\def\PYG@reset{\let\PYG@it=\relax \let\PYG@bf=\relax%
\let\PYG@ul=\relax \let\PYG@tc=\relax%
\let\PYG@bc=\relax \let\PYG@ff=\relax}
\def\PYG@tok#1{\csname PYG@tok@#1\endcsname}
\def\PYG@toks#1+{\ifx\relax#1\empty\else%
\PYG@tok{#1}\expandafter\PYG@toks\fi}
\def\PYG@do#1{\PYG@bc{\PYG@tc{\PYG@ul{%
\PYG@it{\PYG@bf{\PYG@ff{#1}}}}}}}
\def\PYG#1#2{\PYG@reset\PYG@toks#1+\relax+\PYG@do{#2}}
\expandafter\def\csname PYG@tok@vc\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.38,0.84}{##1}}}
\expandafter\def\csname PYG@tok@nv\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.38,0.84}{##1}}}
\expandafter\def\csname PYG@tok@kn\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\expandafter\def\csname PYG@tok@kt\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.56,0.13,0.00}{##1}}}
\expandafter\def\csname PYG@tok@gu\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}}
\expandafter\def\csname PYG@tok@gr\endcsname{\def\PYG@tc##1{\textcolor[rgb]{1.00,0.00,0.00}{##1}}}
\expandafter\def\csname PYG@tok@c\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.56}{##1}}}
\expandafter\def\csname PYG@tok@s\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\expandafter\def\csname PYG@tok@mh\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.13,0.50,0.31}{##1}}}
\expandafter\def\csname PYG@tok@m\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.13,0.50,0.31}{##1}}}
\expandafter\def\csname PYG@tok@sh\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\expandafter\def\csname PYG@tok@sb\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\expandafter\def\csname PYG@tok@ni\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.84,0.33,0.22}{##1}}}
\expandafter\def\csname PYG@tok@il\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.13,0.50,0.31}{##1}}}
\expandafter\def\csname PYG@tok@kr\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\expandafter\def\csname PYG@tok@c1\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.56}{##1}}}
\expandafter\def\csname PYG@tok@go\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.20,0.20,0.20}{##1}}}
\expandafter\def\csname PYG@tok@w\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}}
\expandafter\def\csname PYG@tok@nf\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.02,0.16,0.49}{##1}}}
\expandafter\def\csname PYG@tok@ge\endcsname{\let\PYG@it=\textit}
\expandafter\def\csname PYG@tok@cm\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.56}{##1}}}
\expandafter\def\csname PYG@tok@se\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\expandafter\def\csname PYG@tok@mb\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.13,0.50,0.31}{##1}}}
\expandafter\def\csname PYG@tok@nc\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.05,0.52,0.71}{##1}}}
\expandafter\def\csname PYG@tok@err\endcsname{\def\PYG@bc##1{\setlength{\fboxsep}{0pt}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}
\expandafter\def\csname PYG@tok@sd\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\expandafter\def\csname PYG@tok@gi\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.63,0.00}{##1}}}
\expandafter\def\csname PYG@tok@vg\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.38,0.84}{##1}}}
\expandafter\def\csname PYG@tok@sx\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.78,0.36,0.04}{##1}}}
\expandafter\def\csname PYG@tok@mf\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.13,0.50,0.31}{##1}}}
\expandafter\def\csname PYG@tok@sc\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\expandafter\def\csname PYG@tok@kc\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\expandafter\def\csname PYG@tok@nl\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.13,0.44}{##1}}}
\expandafter\def\csname PYG@tok@na\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\expandafter\def\csname PYG@tok@nb\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\expandafter\def\csname PYG@tok@kp\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\expandafter\def\csname PYG@tok@kd\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\expandafter\def\csname PYG@tok@mi\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.13,0.50,0.31}{##1}}}
\expandafter\def\csname PYG@tok@nd\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.33,0.33,0.33}{##1}}}
\expandafter\def\csname PYG@tok@sr\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.14,0.33,0.53}{##1}}}
\expandafter\def\csname PYG@tok@ne\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\expandafter\def\csname PYG@tok@bp\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\expandafter\def\csname PYG@tok@vi\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.38,0.84}{##1}}}
\expandafter\def\csname PYG@tok@si\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.44,0.63,0.82}{##1}}}
\expandafter\def\csname PYG@tok@no\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.38,0.68,0.84}{##1}}}
\expandafter\def\csname PYG@tok@gd\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}}
\expandafter\def\csname PYG@tok@s1\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\expandafter\def\csname PYG@tok@ss\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.32,0.47,0.09}{##1}}}
\expandafter\def\csname PYG@tok@nt\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.02,0.16,0.45}{##1}}}
\expandafter\def\csname PYG@tok@gt\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}}
\expandafter\def\csname PYG@tok@o\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PYG@tok@mo\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.13,0.50,0.31}{##1}}}
\expandafter\def\csname PYG@tok@nn\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.05,0.52,0.71}{##1}}}
\expandafter\def\csname PYG@tok@ow\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\expandafter\def\csname PYG@tok@s2\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\expandafter\def\csname PYG@tok@gh\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}}
\expandafter\def\csname PYG@tok@cs\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.56}{##1}}\def\PYG@bc##1{\setlength{\fboxsep}{0pt}\colorbox[rgb]{1.00,0.94,0.94}{\strut ##1}}}
\expandafter\def\csname PYG@tok@gp\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.78,0.36,0.04}{##1}}}
\expandafter\def\csname PYG@tok@gs\endcsname{\let\PYG@bf=\textbf}
\expandafter\def\csname PYG@tok@k\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\expandafter\def\csname PYG@tok@cp\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\def\PYGZbs{\char`\\}
\def\PYGZus{\char`\_}
\def\PYGZob{\char`\{}
\def\PYGZcb{\char`\}}
\def\PYGZca{\char`\^}
\def\PYGZam{\char`\&}
\def\PYGZlt{\char`\<}
\def\PYGZgt{\char`\>}
\def\PYGZsh{\char`\#}
\def\PYGZpc{\char`\%}
\def\PYGZdl{\char`\$}
\def\PYGZhy{\char`\-}
\def\PYGZsq{\char`\'}
\def\PYGZdq{\char`\"}
\def\PYGZti{\char`\~}
% for compatibility with earlier versions
\def\PYGZat{@}
\def\PYGZlb{[}
\def\PYGZrb{]}
\makeatother
\renewcommand\PYGZsq{\textquotesingle}
\begin{document}
\maketitle
\tableofcontents
\phantomsection\label{index::doc}
\includegraphics{gammapy_banner.png}
\textbf{Gammapy} is an open source (BSD licensed) gamma-ray astronomy Python package.
It is an in-development \href{http://www.astropy.org/affiliated/index.html}{affiliated package} of \href{http://www.astropy.org}{Astropy}
that builds on the core \href{http://www.scipy.org/about.html}{scientific Python stack} to provide tools to simulate and analyse
the gamma-ray sky for telescopes such as \href{https://www.cta-observatory.org/}{CTA}, \href{http://www.mpi-hd.mpg.de/hfm/HESS/}{H.E.S.S.},
and \href{http://fermi.gsfc.nasa.gov/}{Fermi}.
Gammapy is a place for Python-coding gamma-ray astronomers to share their code and collaborate.
Contributions welcome!
\begin{itemize}
\item {}
Read the \href{https://gammapy.readthedocs.org/}{Gammapy documentation}.
\item {}
Ask questions on the \href{http://groups.google.com/group/gammapy}{Gammapy mailing list}.
\item {}
Request features, report bugs or contribute on the \href{https://github.com/gammapy/gammapy}{Gammapy GitHub page}.
\item {}
Check out the \href{https://www.openhub.net/p/gammapy}{Gammapy project summary on Open HUB}.
\item {}
The latest Gammapy release is version \textbf{0.2} and is available from the \href{https://pypi.python.org/pypi/gammapy}{Gammapy page on PyPI}.
\end{itemize}
\part{News}
\label{index:what-is-gammapy}\label{index:gammapy-welcome}\label{index:gammapy-news}\label{index:news}
To get notifications for Gammapy releases, join the \href{http://groups.google.com/group/gammapy}{Gammapy mailing list} or follow \href{https://twitter.com/Gammapy}{Gammapy on Twitter}.
\begin{itemize}
\item {}
May - August 2015 --- Manuel Paz Arribas GSoC 2015 on {\hyperref[background/index:module-gammapy.background]{\emph{\code{gammapy.background}}}}
(\href{https://github.com/astropy/astropy/wiki/GSoC-2015-Application-Manuel-Paz-Arribas:-Astropy:-background-modeling-for-Gammapy}{project description})
\item {}
April 20, 2015 --- Sherpa becomes an open project (\href{http://pysherpa.blogspot.de/2015/04/sherpa-becomes-open-project.html}{blog post})
... will be used more in Gammapy.
\item {}
April 13, 2015 --- Gammapy 0.2 release. See changelog: {\hyperref[changelog:gammapy-0p2-release]{\emph{\DUspan{}{0.2 (April 13, 2015)}}}}
\item {}
August 25, 2014 --- Gammapy 0.1 release. See changelog: {\hyperref[changelog:gammapy-0p1-release]{\emph{\DUspan{}{0.1 (August 25, 2014)}}}}
\end{itemize}
\part{General documentation}
\label{index:general-documentation}\label{index:gammapy-general-docs}
\chapter{Installation}
\label{install:install}\label{install:installation}\label{install::doc}
Here we provide short installation instructions for Gammapy and its dependencies
using the \href{https://pip.pypa.io/en/stable/}{pip} and \href{http://conda.pydata.org/}{conda} tools.
If you get stuck, have a look at the extensive installation instructions for Astropy
at \href{http://www.astropy.org/}{http://www.astropy.org/} or ask on the \href{http://groups.google.com/group/gammapy}{Gammapy mailing list}.
\section{Install Gammapy using pip}
\label{install:install-gammapy-using-pip}
To install the latest Gammapy \textbf{stable} version using \href{https://pip.pypa.io/en/stable/}{pip}:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }pip install gammapy
\end{Verbatim}
To install the current Gammapy \textbf{development} version using \href{https://pip.pypa.io/en/stable/}{pip}:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }pip install git+https://github.com/gammapy/gammapy.git\PYGZsh{}egg\PYG{o}{=}gammapy
\end{Verbatim}
\section{Download and install Gammapy manually}
\label{install:download-and-install-gammapy-manually}
To download the latest stable version of Gammapy, download it from
\href{https://pypi.python.org/pypi/gammapy}{https://pypi.python.org/pypi/gammapy}, if you have the
\href{http://www.gnu.org/software/wget/}{wget} tool available you can do this
from the command line:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }wget https://pypi.python.org/packages/source/g/gammapy/gammapy\PYGZhy{}0.2.tar.gz
\PYG{n+nv}{\PYGZdl{} }tar zxf gammapy\PYGZhy{}0.2.tar.gz
\PYG{n+nv}{\PYGZdl{} }\PYG{n+nb}{cd }gammapy\PYGZhy{}0.2
\end{Verbatim}
To download the latest development version of Gammapy:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }git clone https://github.com/gammapy/gammapy.git
\PYG{n+nv}{\PYGZdl{} }\PYG{n+nb}{cd }gammapy
\end{Verbatim}
Either way, you now can install, test or build the documentation:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }python setup.py install
\PYG{n+nv}{\PYGZdl{} }python setup.py \PYG{n+nb}{test}
\PYG{n+nv}{\PYGZdl{} }python setup.py build\PYGZus{}sphinx
\end{Verbatim}
Also you have easy access to the Python scripts from the tutorials and examples:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }\PYG{n+nb}{cd }docs/tutorials
\PYG{n+nv}{\PYGZdl{} }\PYG{n+nb}{cd }examples
\end{Verbatim}
If you want to contribute to Gammapy, but are not familiar with Python or
git or Astropy yet, please have a look at the
\href{http://docs.astropy.org/en/latest/\#developer-documentation}{Astropy developer documentation}.
\section{Install Gammapy and its dependencies using Conda}
\label{install:install-gammapy-and-its-dependencies-using-conda}
In the past it has often been hard to install Python packages and all their dependencies.
Not any more ... using \href{http://conda.pydata.org/}{conda} you can install Gammapy and most of its dependencies on
any Linux machine or Mac in 5 minutes (without needing root access on the machine).
Go to \href{http://conda.pydata.org/miniconda.html}{http://conda.pydata.org/miniconda.html} and download the installer for your system.
Or directly use \href{https://www.gnu.org/software/wget/}{wget} from the terminal:
For Linux:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }wget http://repo.continuum.io/miniconda/Miniconda3\PYGZhy{}latest\PYGZhy{}Linux\PYGZhy{}x86\PYGZus{}64.sh \PYGZhy{}O miniconda.sh
\end{Verbatim}
For Mac:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }wget http://repo.continuum.io/miniconda/Miniconda3\PYGZhy{}latest\PYGZhy{}MacOSX\PYGZhy{}x86\PYGZus{}64.sh \PYGZhy{}O miniconda.sh
\end{Verbatim}
Then install binary packages using \code{conda} and source packages using \code{pip} by
copy \& pasting the following lines into your terminal:
\begin{Verbatim}[commandchars=\\\{\}]
bash miniconda.sh \PYGZhy{}b \PYGZhy{}p \PYG{n+nv}{\PYGZdl{}PWD}/miniconda
\PYG{n+nb}{export }\PYG{n+nv}{PATH}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}}\PYG{n+nv}{\PYGZdl{}PWD}\PYG{l+s+s2}{/miniconda/bin:}\PYG{n+nv}{\PYGZdl{}PATH}\PYG{l+s+s2}{\PYGZdq{}}
conda config \PYGZhy{}\PYGZhy{}set always\PYGZus{}yes yes \PYGZhy{}\PYGZhy{}set changeps1 no
conda update \PYGZhy{}q conda
conda install pip scipy matplotlib scikit\PYGZhy{}image scikit\PYGZhy{}learn astropy h5py pandas
pip install reproject aplpy wcsaxes naima astroplan gwcs photutils
pip install gammapy
\end{Verbatim}
Overall \code{conda} is a great cross-platform package manager, you can quickly learn how to use
it by reading the docs here: \href{http://conda.pydata.org/docs/}{http://conda.pydata.org/docs/}
\section{Check if your Gammapy installation is OK}
\label{install:check-if-your-gammapy-installation-is-ok}
To check if Gammapy is correctly installed, start up python or ipython,
import Gammapy and run the unit tests:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }python \PYGZhy{}c \PYG{l+s+s1}{\PYGZsq{}import gammapy; gammapy.test()\PYGZsq{}}
\end{Verbatim}
To check if the Gammapy command line tools are on your \code{\$PATH} try this:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }gammapy\PYGZhy{}info \PYGZhy{}\PYGZhy{}tools
\end{Verbatim}
To check which dependencies of Gammapy you have installed:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }gammapy\PYGZhy{}info \PYGZhy{}\PYGZhy{}dependencies
\end{Verbatim}
\section{Dependencies}
\label{install:dependencies}\label{install:install-dependencies}
Gammapy works with Python 2 and 3.
More specifically, in the Python 2 series we only support Python 2.7,
and in the Python 3 series we support version 3.3 or later.
Gammapy will not work with Python 2.6 or 3.2
(see {\hyperref[development/index:development-python2and3]{\emph{\DUspan{}{Python 2 and 3 support}}}} if you care why).
\begin{notice}{note}{Note:}
The philosophy of Gammapy is to build on the existing scientific Python stack.
This means that you need to install those dependencies to use Gammapy.
We are aware that too many dependencies is an issue for deployment and maintenance.
That's why currently Gammapy only has two core dependencies --- Numpy and Astropy.
We are considering making Sherpa, Scipy, scikit-image, photutils, reproject and naima
core dependencies.
In addition there are about a dozen optional dependencies that are OK to import
from Gammapy because they are potentially useful (not all of those are
actually currently imported).
Before the Gammapy 1.0 release we will re-evaluate and clarify the Gammapy dependencies.
\end{notice}
The required core dependencies of Gammapy are:
\begin{itemize}
\item {}
\href{http://www.numpy.org/}{Numpy} - the fundamental package for scientific computing with Python
\item {}
\href{http://astropy.org}{Astropy} - the core package for Astronomy in Python
\end{itemize}
Currently optional dependencies that are being considered as core dependencies:
\begin{itemize}
\item {}
\href{http://cxc.cfa.harvard.edu/sherpa/}{Sherpa} for modeling / fitting (doesn't work with Python 3 yet)
\item {}
\href{http://scipy.org/scipylib/}{scipy library} for numerical methods
\item {}
\href{http://scikit-image.org}{scikit-image} for some image processing tasks
\item {}
\href{http://photutils.readthedocs.org}{photutils} for image photometry
\item {}
\href{http://reproject.readthedocs.org}{reproject} for image reprojection
\item {}
\href{http://naima.readthedocs.org/en/latest/}{naima} for SED modeling
\end{itemize}
Allowed optional dependencies:
\begin{itemize}
\item {}
\href{http://matplotlib.org}{matplotlib} for plotting
\item {}
\href{https://github.com/astrofrog/wcsaxes}{wcsaxes} for sky image plotting (provides a low-level API)
\item {}
\href{http://aplpy.github.io}{aplpy} for sky image plotting (provides a high-level API)
\item {}
\href{http://pandas.pydata.org}{pandas} CSV read / write; DataFrame
\item {}
\href{http://scikit-learn.org/stable/}{scikit-learn} for some data analysis tasks
\item {}
\href{http://gammalib.sourceforge.net}{GammaLib} and \href{http://cta.irap.omp.eu/ctools}{ctools} for simulating data and likelihood fitting
\item {}
\href{https://root.cern.ch/drupal/}{ROOT} and \href{http://www.rootpy.org/}{rootpy} conversion helper functions (still has some Python 3 issues)
\item {}
\href{http://code.google.com/p/image-funcut/}{imfun} for a trous wavelet decomposition
\item {}
\href{http://pythonhosted.org/uncertainties/}{uncertainties} for Gaussian error propagation
\item {}
\href{http://gwcs.readthedocs.org}{gwcs} for generalised world coordinate transformations
\item {}
\href{http://astroplan.readthedocs.org}{astroplan} for observation planning and scheduling
\item {}
\href{https://github.com/iminuit/iminuit}{iminuit} for fitting by optimization (doesn't work with Python 3 yet)
\item {}
\href{http://dan.iel.fm/emcee/current/}{emcee} for fitting by MCMC sampling
\item {}
\href{http://www.h5py.org/}{h5py} for \href{http://en.wikipedia.org/wiki/Hierarchical\_Data\_Format}{HDF5} data handling
\item {}
\href{https://pypi.python.org/pypi/PyYAML/}{PyYAML} for \href{http://en.wikipedia.org/wiki/YAML}{YAML} data handling
\item {}
\href{https://healpy.readthedocs.org/en/latest/}{healpy} for \href{http://healpix.jpl.nasa.gov/}{HEALPIX} data handling
\end{itemize}
Actually at this point we welcome experimentation, so you can use cool new technologies
to implement some functionality in Gammapy if you like, e.g.
\begin{itemize}
\item {}
\href{http://numba.pydata.org/}{Numba}
\item {}
\href{http://bokeh.pydata.org/en/latest/}{Bokeh}
\item {}
\href{http://blaze.pydata.org/en/latest/}{Blaze}
\end{itemize}
\section{How to make Astropy / Gammapy work with the CIAO Sherpa Python?}
\label{install:how-to-make-astropy-gammapy-work-with-the-ciao-sherpa-python}
Note: CIAO 4.7 (released 16 December 2014)
includes Python 2.7.6, Numpy 1.8.1, IPython 2.0.0 and no PyFITS, Scipy or Matplotlib.
Note: It looks like Sherpa installation is improving ... e.g. it's now available
as a binary install via Conda:
\href{http://cxc.harvard.edu/sherpa/contrib.html\#pysherpa}{http://cxc.harvard.edu/sherpa/contrib.html\#pysherpa}
Some parts of Gammapy use the \href{http://cxc.cfa.harvard.edu/sherpa/}{Sherpa} Python modeling / fitting package
from the \href{http://cxc.cfa.harvard.edu/ciao/}{CIAO} Chandra satellite X-ray data analysis package.
Building Sherpa and all the required libraries from source is very difficult.
You should install the binary version of CIAO as described
\href{http://cxc.cfa.harvard.edu/ciao/download}{here},
make sure you include Sherpa and exclude the Chandra CALDB.
But then the Sherpa Python and Numpy will not work with the existing
Python, Numpy, Astropy, Gammapy, ... on your system.
You have to re-install Astropy, Gammapy and any other Python packages
that you want to use in the same script as Sherpa into the CIAO Python.
Sometimes this just works, but sometimes you'll run into compilation errors
when e.g. the C extensions in \code{astropy.wcs} or \code{astropy.io.fits} are compiled.
Here's a few tricks that might help you make it work.
\begin{itemize}
\item {}
Execute the
\href{http://cxc.cfa.harvard.edu/ciao/threads/ciao\_install/index.html\#ciao\_python\_fix}{ciao-python-fix}
script after installing CIAO:
\end{itemize}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }\PYG{n+nb}{cd} \PYG{n+nv}{\PYGZdl{}CIAO\PYGZus{}DIR}
\PYG{n+nv}{\PYGZdl{} }bash bin/ciao\PYGZhy{}python\PYGZhy{}fix
\end{Verbatim}
\begin{itemize}
\item {}
Set \code{LDFLAGS} and use \code{ciaorun} before installing a Python package with C extensions:
\end{itemize}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }\PYG{n+nb}{export }\PYG{n+nv}{LDFLAGS}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}}\PYG{l+s+s2}{\PYGZhy{}L}\PYG{l+s+si}{\PYGZdl{}\PYGZob{}}\PYG{n+nv}{ASCDS\PYGZus{}INSTALL}\PYG{l+s+si}{\PYGZcb{}}\PYG{l+s+s2}{/ots/lib}\PYG{l+s+s2}{\PYGZdq{}}
\PYG{n+nv}{\PYGZdl{} }ciaorun python setup.py install
\end{Verbatim}
\begin{itemize}
\item {}
Add these folders to your \code{PATH} and \code{PYTHONPATH} so that the right command line tools or
Python packages are picked up instead of the ones in other system folders:
\end{itemize}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }\PYG{n+nb}{export }\PYG{n+nv}{PATH}\PYG{o}{=}\PYG{n+nv}{\PYGZdl{}CIAO\PYGZus{}DIR}/ots/bin:\PYG{n+nv}{\PYGZdl{}PATH}
\PYG{n+nv}{\PYGZdl{} }\PYG{n+nb}{export }\PYG{n+nv}{PYTHONPATH}\PYG{o}{=}\PYG{n+nv}{\PYGZdl{}CIAO\PYGZus{}DIR}/ots/lib/python2.7/site\PYGZhy{}packages/:\PYG{n+nv}{\PYGZdl{}PYTHONPATH}
\end{Verbatim}
\section{How to make Astropy / Gammapy work with the Fermi ScienceTools Python?}
\label{install:how-to-make-astropy-gammapy-work-with-the-fermi-sciencetools-python}
Note: \code{ScienceTools-v9r33p0-fssc-20140520} (v9r33p0, released Jun 03, 2014)
includes Python 2.7.2, Numpy 1.6.1, Scipy 0.10.1, Matplotlib 1.1.1, PyFITS 3.1.2 and no IPython.
Try installing \href{https://pip.pypa.io/en/stable/}{pip} into that Python and then:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }pip install astropy
\PYG{n+nv}{\PYGZdl{} }pip install gammapy
\end{Verbatim}
If this doesn't work (which is not uncommon, this is known to fail to compile the C extensions of Astropy
on some platforms), ask your Python-installation-savvy co-worker or on the Astropy or Gammapy mailing list.
\section{BSD or GPL license?}
\label{install:bsd-or-gpl-license}
Gammapy is BSD licensed (same license as Numpy, Scipy, Matplotlib, scikit-image, Astropy, photutils, yt, ...).
We prefer this over the GPL3 or LGPL license because it means that the packages we are most likely to
share code with have the same license, e.g. we can take a function or class and ``upstream'' it, i.e. contribute
it e.g. to Astropy or Scipy if it's generally useful.
Some optional dependencies of Gammapy (i.e. other packages like Sherpa or Gammalib or ROOT that we import in some
places) are GPL3 or LGPL licensed.
Now the GPL3 and LGPL license contains clauses that other package that copy or modify it must be released under
the same license.
We take the standpoint that Gammapy is independent from these libraries, because we don't copy or modify them.
This is a common standpoint, e.g. \code{astropy.wcs} is BSD licensed, but uses the LGPL-licensed WCSLib.
Note that if you distribute Gammapy together with one of the GPL dependencies,
the whole distribution then falls under the GPL license.
\chapter{Introduction}
\label{introduction:id1}\label{introduction::doc}\label{introduction:introduction}
\section{Show me some code!}
\label{introduction:show-me-some-code}
Gammapy gives you easy access to some frequently used methods in TeV gamma-ray astronomy from Python.
What's the statistical significance when 10 events have been observed with a known background level of 4.2
according to \phantomsection\label{introduction:id2}{\hyperref[references:lima1983]{\emph{{[}LiMa1983{]}}}}?
Call the {\hyperref[api/gammapy.stats.significance:gammapy.stats.significance]{\emph{\code{significance}}}} function:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.stats} \PYG{k+kn}{import} \PYG{n}{significance}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{significance}\PYG{p}{(}\PYG{n}{n\PYGZus{}observed}\PYG{o}{=}\PYG{l+m+mi}{10}\PYG{p}{,} \PYG{n}{mu\PYGZus{}background}\PYG{o}{=}\PYG{l+m+mf}{4.2}\PYG{p}{,} \PYG{n}{method}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{lima}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{g+go}{2.3979181291475453}
\end{Verbatim}
What's the differential gamma-ray flux and spectral index of the Crab nebula at 3 TeV
according to \phantomsection\label{introduction:id3}{\hyperref[references:meyer2010]{\emph{{[}Meyer2010{]}}}}?
Call the {\hyperref[api/gammapy.spectrum.crab_flux:gammapy.spectrum.crab_flux]{\emph{\code{crab\_flux}}}} and {\hyperref[api/gammapy.spectrum.crab_spectral_index:gammapy.spectrum.crab_spectral_index]{\emph{\code{crab\_spectral\_index}}}} functions:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.spectrum} \PYG{k+kn}{import} \PYG{n}{crab\PYGZus{}flux}\PYG{p}{,} \PYG{n}{crab\PYGZus{}spectral\PYGZus{}index}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{energy} \PYG{o}{=} \PYG{l+m+mi}{3}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{crab\PYGZus{}flux}\PYG{p}{(}\PYG{n}{energy}\PYG{p}{,} \PYG{n}{reference}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{meyer}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{g+go}{1.8993523278650278e\PYGZhy{}12}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{crab\PYGZus{}spectral\PYGZus{}index}\PYG{p}{(}\PYG{n}{energy}\PYG{p}{,} \PYG{n}{reference}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{meyer}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{g+go}{2.6763224503600429}
\end{Verbatim}
All functionality is in subpackages (e.g. {\hyperref[stats/index:module-gammapy.stats]{\emph{\code{gammapy.stats}}}} or {\hyperref[spectrum/index:module-gammapy.spectrum]{\emph{\code{gammapy.spectrum}}}}) ...
browse their docs to see if it contains the methods you want.
\section{But I don't know how to code in Python!}
\label{introduction:but-i-don-t-know-how-to-code-in-python}
Hmm ... OK.
Some of the Gammapy functionality can be called from command line tools.
But, to be honest, if you're an astronomer, you should learn to code in Python.
Start at \href{http://python4astronomers.github.io}{http://python4astronomers.github.io} or the \code{astropy} docs.
For example, if you have a counts and background model image and would like to compute
a significance image with a correlation radius of 0.1 deg:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }gammapy\PYGZhy{}make\PYGZhy{}derived\PYGZhy{}maps \PYGZhy{}\PYGZhy{}in counts.fits background.fits \PYG{l+s+se}{\PYGZbs{}}
\PYGZhy{}\PYGZhy{}meaning counts background \PYG{l+s+se}{\PYGZbs{}}
\PYGZhy{}\PYGZhy{}out significance.fits \PYG{l+s+se}{\PYGZbs{}}
\PYGZhy{}\PYGZhy{}correlation\PYGZus{}radius 0.1
\end{Verbatim}
Say you have an image that contains the
\href{http://en.wikipedia.org/wiki/Crab\_Nebula}{Crab nebula}
and want to look up the map value at the Crab position
(name lookup is done with \href{http://simbad.u-strasbg.fr/simbad/}{SIMBAD}):
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }gammapy\PYGZhy{}lookup\PYGZhy{}map\PYGZhy{}values crab\PYGZus{}image.fits \PYGZhy{}\PYGZhy{}object \PYG{l+s+s2}{\PYGZdq{}Crab\PYGZdq{}}
\end{Verbatim}
You can call \code{gammapy-tool-name -{-}help} or \code{gammapy-tool-name -h} for any tool.
A full list of available command line tools can be found in TODO: \code{tools}.
\section{Other related packages}
\label{introduction:other-related-packages}
Make sure to also check out the following packages that contain very useful functionality for gamma-ray astronomy:
\begin{itemize}
\item {}
\href{http://cxc.cfa.harvard.edu/sherpa/}{Sherpa} --- X-ray modeling and fitting package by the Chandra X-ray Center
\item {}
\href{http://gammalib.sourceforge.net}{gammalib} and \href{http://cta.irap.omp.eu/ctools/}{ctools} --- Gamma-ray data analysis library and tools by Jürgen Knödlseder
\item {}
\href{https://github.com/cta-observatory/ctapipe}{ctapipe} --- CTA Python pipeline experimental version
\item {}
\href{http://threeml.stanford.edu/}{threeml} --- the multi-missing maximum likelihood framework by Giacomo Vianello and others from Stanford
(\href{https://github.com/giacomov/3ML}{code},
\href{http://nbviewer.ipython.org/github/giacomov/3ML/blob/master/examples/090217206.ipynb}{example notebook})
\item {}
\href{https://github.com/woodmd/gammatools}{gammatools} --- Python tools for Fermi-LAT gamma-ray data analysis by Matthew Wood
\item {}
\href{https://github.com/zblz/naima}{naima} --- an SED modeling and fitting package by Victor Zabalza
\item {}
\href{https://github.com/JoachimHahn/GamERa}{GamERa} --- a C++ gamma-ray source modeling package (SED, SNR model, Galactic population model) by Joachim Hahn
\item {}
\href{https://github.com/gammapy/enrico/}{Enrico} --- helps you with your Fermi data analysis
\item {}
\href{http://voparis-cta-client.obspm.fr/}{http://voparis-cta-client.obspm.fr/} --- prototype web app for CTA data access / analysis, not open source.
\end{itemize}
Some other projects:
\begin{itemize}
\item {}
\href{https://bitbucket.org/kosack/act-analysis}{act-analysis} --- Python scripts and Makefiles for some common gamma-ray data analysis tasks by Karl Kosack
\item {}
\href{https://github.com/kialio/VHEObserverTools}{VHEObserverTools} --- tools to predict detectability at VHE by Jeremy Perkins
\item {}
\href{http://yt-project.org/doc/analyzing/analysis\_modules/photon\_simulator.html}{photon\_simulator} --- Python code to simulate X-ray observations
\end{itemize}
\section{Other useful packages}
\label{introduction:other-useful-packages}\label{introduction:photon-simulator}
In addition to the packages mentioned in the last section and at {\hyperref[install:install-dependencies]{\emph{\DUspan{}{Dependencies}}}},
here's a few other Python packages you might find useful / interesting:
\begin{itemize}
\item {}
See the list here: \href{http://www.astropy.org/affiliated/}{http://www.astropy.org/affiliated/}
\item {}
Pulsar timing package \href{https://github.com/nanograv/PINT}{PINT}
\item {}
\href{https://github.com/iminuit/iminuit}{iminuit} fitter and
\href{https://github.com/iminuit/probfit}{probfit} likelihood function builder.
\item {}
Andy strong has C++ codes (GALPROP and Galplot) for Galactic cosmic rays and emission
and source population synthesis at \href{http://www.mpe.mpg.de/~aws/propagate.html}{http://www.mpe.mpg.de/\textasciitilde{}aws/propagate.html} .
\end{itemize}
\chapter{Command line tools (\texttt{gammapy.scripts})}
\label{scripts/index:scripts}\label{scripts/index:astropy}\label{scripts/index::doc}\label{scripts/index:command-line-tools-gammapy-scripts}
\section{Introduction}
\label{scripts/index:introduction}
Currently the {\hyperref[scripts/index:module-gammapy.scripts]{\emph{\code{gammapy.scripts}}}} sub-package contains the Gammapy command line tools.
This might change though ... see the notes here:
\href{https://github.com/gammapy/gammapy/pull/230}{https://github.com/gammapy/gammapy/pull/230}
To be able to use them you have to install Gammapy:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }pip install \PYGZhy{}\PYGZhy{}user .
\end{Verbatim}
For Gammapy development we recommend you run this command so that you can edit
Gammapy and the tools and don't have to re-install after every change.
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }pip install \PYGZhy{}\PYGZhy{}user \PYGZhy{}\PYGZhy{}editable .
\end{Verbatim}
\section{Reference/API}
\label{scripts/index:reference-api}
\subsection{gammapy.scripts Package}
\label{scripts/index:gammapy-scripts-package}\label{scripts/index:module-gammapy.scripts}\index{gammapy.scripts (module)}
Gammapy command line tools.
TODO: document how this works and how users should write their own
command line tools.
\subsubsection{Functions}
\label{scripts/index:functions}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.scripts.background_cube:gammapy.scripts.background_cube]{\emph{\code{background\_cube}}}}(run\_list, exclusion\_list, ...)
&
Create background model cube from off runs.
\\
\hline
{\hyperref[api/gammapy.scripts.bin_cube:gammapy.scripts.bin_cube]{\emph{\code{bin\_cube}}}}(event\_file, reference\_file, ...)
&
Bin events into a LON-LAT-Energy cube.
\\
\hline
{\hyperref[api/gammapy.scripts.bin_image:gammapy.scripts.bin_image]{\emph{\code{bin\_image}}}}(event\_file, reference\_file, ...)
&
Bin events into an image.
\\
\hline
{\hyperref[api/gammapy.scripts.check:gammapy.scripts.check]{\emph{\code{check}}}}(package)
&
Run gammapy unit tests.
\\
\hline
{\hyperref[api/gammapy.scripts.coordinate_images:gammapy.scripts.coordinate_images]{\emph{\code{coordinate\_images}}}}(infile, outfile, ...)
&
Make maps that can be used to create profiles.
\\
\hline
{\hyperref[api/gammapy.scripts.derived_images:gammapy.scripts.derived_images]{\emph{\code{derived\_images}}}}(infile, outfile, theta, ...)
&
Make derived maps for a given set of basic maps.
\\
\hline
{\hyperref[api/gammapy.scripts.detect:gammapy.scripts.detect]{\emph{\code{detect}}}}(infile, overwrite)
&
Detect sources in images.
\\
\hline
{\hyperref[api/gammapy.scripts.find_obs:gammapy.scripts.find_obs]{\emph{\code{find\_obs}}}}(infile, outfile, x, y, pix, overwrite)
&
Select a subset of observations from a given observation list.
\\
\hline
{\hyperref[api/gammapy.scripts.image_decompose_a_trous:gammapy.scripts.image_decompose_a_trous]{\emph{\code{image\_decompose\_a\_trous}}}}(infile, outfile, ...)
&
Apply the a trous wavelet transform on a 2D image.
\\
\hline
{\hyperref[api/gammapy.scripts.info:gammapy.scripts.info]{\emph{\code{info}}}}({[}version, tools, dependencies{]})
&
Print various info on Gammapy to the console.
\\
\hline
{\hyperref[api/gammapy.scripts.irf_info:gammapy.scripts.irf_info]{\emph{\code{irf\_info}}}}(infiles, plot, thetas, energies, ...)
&
Print or plot info about instrument response function (IRF) files.
\\
\hline
{\hyperref[api/gammapy.scripts.irf_root_to_fits:gammapy.scripts.irf_root_to_fits]{\emph{\code{irf\_root\_to\_fits}}}}(irf\_root\_file, write\_output)
&
Convert CTA IRF data from ROOT to FITS format.
\\
\hline
{\hyperref[api/gammapy.scripts.iterative_source_detect:gammapy.scripts.iterative_source_detect]{\emph{\code{iterative\_source\_detect}}}}(scales, counts, ...)
&
Run an iterative multi-scale source detection.
\\
\hline
{\hyperref[api/gammapy.scripts.look_up_image:gammapy.scripts.look_up_image]{\emph{\code{look\_up\_image}}}}(infile, x, y)
&
Look up values in a map at given positions.
\\
\hline
{\hyperref[api/gammapy.scripts.model_image:gammapy.scripts.model_image]{\emph{\code{model\_image}}}}()
&
Given a catalog of sources, simulate a flux image.
\\
\hline
{\hyperref[api/gammapy.scripts.pfmap:gammapy.scripts.pfmap]{\emph{\code{pfmap}}}}(infile, skymap\_size, bin\_size, ...)
&
Create sky maps from VHE event lists.
\\
\hline
{\hyperref[api/gammapy.scripts.pfsim:gammapy.scripts.pfsim]{\emph{\code{pfsim}}}}(arf, exposure\_time, flux, rmf\_file, ...)
&
Simulates IACT eventlist using an ARF file.
\\
\hline
{\hyperref[api/gammapy.scripts.pfspec:gammapy.scripts.pfspec]{\emph{\code{pfspec}}}}(input\_file\_names, analysis\_position, ...)
&
Create spectra from VHE event lists in FITS format.
\\
\hline
{\hyperref[api/gammapy.scripts.reflected_regions:gammapy.scripts.reflected_regions]{\emph{\code{reflected\_regions}}}}(x\_on, y\_on, r\_on, x\_fov, ...)
&
Find off regions for a given on region and exclusion mask.
\\
\hline
{\hyperref[api/gammapy.scripts.residual_images:gammapy.scripts.residual_images]{\emph{\code{residual\_images}}}}(model\_file, data\_file, ...)
&
Compute source model residual images.
\\
\hline
{\hyperref[api/gammapy.scripts.root_to_fits:gammapy.scripts.root_to_fits]{\emph{\code{root\_to\_fits}}}}()
&
Convert ROOT files to FITS files (histograms and ntuples).
\\
\hline
{\hyperref[api/gammapy.scripts.run_cwt:gammapy.scripts.run_cwt]{\emph{\code{run\_cwt}}}}(infile, outfile, overwrite, ...)
&
Compute filtered image using Continuous Wavelet Transform (CWT).
\\
\hline
{\hyperref[api/gammapy.scripts.sherpa_image_like:gammapy.scripts.sherpa_image_like]{\emph{\code{sherpa\_image\_like}}}}(counts, exposure, ...)
&
Fit the morphology of a number of sources.
\\
\hline
{\hyperref[api/gammapy.scripts.sherpa_model_image:gammapy.scripts.sherpa_model_image]{\emph{\code{sherpa\_model\_image}}}}(exposure, psf, sources, ...)
&
Compute source model image with Sherpa.
\\
\hline
{\hyperref[api/gammapy.scripts.significance_image:gammapy.scripts.significance_image]{\emph{\code{significance\_image}}}}(infile, outfile, theta, ...)
&
Make correlated significance image.
\\
\hline
{\hyperref[api/gammapy.scripts.simulate_source_catalog:gammapy.scripts.simulate_source_catalog]{\emph{\code{simulate\_source\_catalog}}}}(outfile, nsources, ...)
&
Simulate a catalog of Galactic sources.
\\
\hline
{\hyperref[api/gammapy.scripts.ts_image:gammapy.scripts.ts_image]{\emph{\code{ts\_image}}}}(input\_file, output\_file, psf, ...)
&
Compute source model residual images.
\\
\hline
{\hyperref[api/gammapy.scripts.xspec:gammapy.scripts.xspec]{\emph{\code{xspec}}}}()
&
Perform various tasks with XSPEC files (PHA, ARF, RMF).
\\
\hline\end{longtable}
\paragraph{background\_cube}
\label{api/gammapy.scripts.background_cube::doc}\label{api/gammapy.scripts.background_cube:background-cube}\index{background\_cube() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.background_cube:gammapy.scripts.background_cube}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{background\_cube}}{\emph{run\_list}, \emph{exclusion\_list}, \emph{reference\_file}, \emph{out\_file}, \emph{overwrite}}{}
Create background model cube from off runs.
TODO: explain a bit.
\end{fulllineitems}
\paragraph{bin\_cube}
\label{api/gammapy.scripts.bin_cube:astropy}\label{api/gammapy.scripts.bin_cube::doc}\label{api/gammapy.scripts.bin_cube:bin-cube}\index{bin\_cube() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.bin_cube:gammapy.scripts.bin_cube}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{bin\_cube}}{\emph{event\_file}, \emph{reference\_file}, \emph{out\_file}, \emph{overwrite}}{}
Bin events into a LON-LAT-Energy cube.
\end{fulllineitems}
\paragraph{bin\_image}
\label{api/gammapy.scripts.bin_image:bin-image}\label{api/gammapy.scripts.bin_image:astropy}\label{api/gammapy.scripts.bin_image::doc}\index{bin\_image() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.bin_image:gammapy.scripts.bin_image}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{bin\_image}}{\emph{event\_file}, \emph{reference\_file}, \emph{out\_file}, \emph{overwrite}}{}
Bin events into an image.
\end{fulllineitems}
\paragraph{check}
\label{api/gammapy.scripts.check:check}\label{api/gammapy.scripts.check:astropy}\label{api/gammapy.scripts.check::doc}\index{check() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.check:gammapy.scripts.check}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{check}}{\emph{package}}{}
Run gammapy unit tests.
\end{fulllineitems}
\paragraph{coordinate\_images}
\label{api/gammapy.scripts.coordinate_images:astropy}\label{api/gammapy.scripts.coordinate_images::doc}\label{api/gammapy.scripts.coordinate_images:coordinate-images}\index{coordinate\_images() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.coordinate_images:gammapy.scripts.coordinate_images}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{coordinate\_images}}{\emph{infile}, \emph{outfile}, \emph{make\_coordinate\_maps}, \emph{make\_distance\_map}, \emph{overwrite}}{}
Make maps that can be used to create profiles.
The following images can be created:
* LON -- Longitude coordinate
* LAT -- Latitude coordinate
* DIST -- Distance to mask
* SOLID\_ANGLE -- Solid angle
\end{fulllineitems}
\paragraph{derived\_images}
\label{api/gammapy.scripts.derived_images:astropy}\label{api/gammapy.scripts.derived_images::doc}\label{api/gammapy.scripts.derived_images:derived-images}\index{derived\_images() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.derived_images:gammapy.scripts.derived_images}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{derived\_images}}{\emph{infile}, \emph{outfile}, \emph{theta}, \emph{is\_off\_correlated}, \emph{overwrite}}{}
Make derived maps for a given set of basic maps.
TODO: describe
\end{fulllineitems}
\paragraph{detect}
\label{api/gammapy.scripts.detect:detect}\label{api/gammapy.scripts.detect:astropy}\label{api/gammapy.scripts.detect::doc}\index{detect() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.detect:gammapy.scripts.detect}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{detect}}{\emph{infile}, \emph{overwrite}}{}
Detect sources in images.
TODO: explain.
\end{fulllineitems}
\paragraph{find\_obs}
\label{api/gammapy.scripts.find_obs:astropy}\label{api/gammapy.scripts.find_obs::doc}\label{api/gammapy.scripts.find_obs:find-obs}\index{find\_obs() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.find_obs:gammapy.scripts.find_obs}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{find\_obs}}{\emph{infile}, \emph{outfile}, \emph{x}, \emph{y}, \emph{pix}, \emph{overwrite}}{}
Select a subset of observations from a given observation list.
TODO: explain.
\end{fulllineitems}
\paragraph{image\_decompose\_a\_trous}
\label{api/gammapy.scripts.image_decompose_a_trous:astropy}\label{api/gammapy.scripts.image_decompose_a_trous::doc}\label{api/gammapy.scripts.image_decompose_a_trous:image-decompose-a-trous}\index{image\_decompose\_a\_trous() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.image_decompose_a_trous:gammapy.scripts.image_decompose_a_trous}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{image\_decompose\_a\_trous}}{\emph{infile}, \emph{outfile}, \emph{n\_levels}, \emph{overwrite}}{}
Apply the a trous wavelet transform on a 2D image.
This book contains an overview of methods:
\href{http://www.amazon.de/dp/3540330240}{http://www.amazon.de/dp/3540330240}
Specifically I'd like to have an a trous transform.
Here's a few references that look useful:
* \href{https://code.google.com/p/image-funcut/}{https://code.google.com/p/image-funcut/}
I'm also interested in these transforms:
* \href{http://scikit-image.org/docs/dev/api/skimage.transform.html\#pyramid-expand}{http://scikit-image.org/docs/dev/api/skimage.transform.html\#pyramid-expand}
* \href{http://scikit-image.org/docs/dev/api/skimage.transform.html\#pyramid-gaussian}{http://scikit-image.org/docs/dev/api/skimage.transform.html\#pyramid-gaussian}
* \href{http://scikit-image.org/docs/dev/api/skimage.transform.html\#pyramid-laplacian}{http://scikit-image.org/docs/dev/api/skimage.transform.html\#pyramid-laplacian}
* \href{http://scikit-image.org/docs/dev/api/skimage.transform.html\#pyramid-reduce}{http://scikit-image.org/docs/dev/api/skimage.transform.html\#pyramid-reduce}
\end{fulllineitems}
\paragraph{info}
\label{api/gammapy.scripts.info:astropy}\label{api/gammapy.scripts.info::doc}\label{api/gammapy.scripts.info:info}\index{info() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.info:gammapy.scripts.info}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{info}}{\emph{version=False}, \emph{tools=False}, \emph{dependencies=False}}{}
Print various info on Gammapy to the console.
TODO: explain.
\end{fulllineitems}
\paragraph{irf\_info}
\label{api/gammapy.scripts.irf_info:astropy}\label{api/gammapy.scripts.irf_info::doc}\label{api/gammapy.scripts.irf_info:irf-info}\index{irf\_info() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.irf_info:gammapy.scripts.irf_info}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{irf\_info}}{\emph{infiles}, \emph{plot}, \emph{thetas}, \emph{energies}, \emph{fractions}}{}
Print or plot info about instrument response function (IRF) files.
\end{fulllineitems}
\paragraph{irf\_root\_to\_fits}
\label{api/gammapy.scripts.irf_root_to_fits:astropy}\label{api/gammapy.scripts.irf_root_to_fits::doc}\label{api/gammapy.scripts.irf_root_to_fits:irf-root-to-fits}\index{irf\_root\_to\_fits() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.irf_root_to_fits:gammapy.scripts.irf_root_to_fits}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{irf\_root\_to\_fits}}{\emph{irf\_root\_file}, \emph{write\_output}}{}
Convert CTA IRF data from ROOT to FITS format.
Read input file from command line
irf\_root\_file\_name = `/Users/mraue/Stuff/work/cta/2011/fits/irf/cta/SubarrayE\_IFAE\_50hours\_20101102.root'
\end{fulllineitems}
\paragraph{iterative\_source\_detect}
\label{api/gammapy.scripts.iterative_source_detect:iterative-source-detect}\label{api/gammapy.scripts.iterative_source_detect:astropy}\label{api/gammapy.scripts.iterative_source_detect::doc}\index{iterative\_source\_detect() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.iterative_source_detect:gammapy.scripts.iterative_source_detect}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{iterative\_source\_detect}}{\emph{scales}, \emph{counts}, \emph{background}, \emph{exposure}, \emph{output\_fits}, \emph{output\_regions}, \emph{debug\_output\_folder}, \emph{overwrite}}{}
Run an iterative multi-scale source detection.
\end{fulllineitems}
\paragraph{look\_up\_image}
\label{api/gammapy.scripts.look_up_image:look-up-image}\label{api/gammapy.scripts.look_up_image:astropy}\label{api/gammapy.scripts.look_up_image::doc}\index{look\_up\_image() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.look_up_image:gammapy.scripts.look_up_image}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{look\_up\_image}}{\emph{infile}, \emph{x}, \emph{y}}{}
Look up values in a map at given positions.
\end{fulllineitems}
\paragraph{model\_image}
\label{api/gammapy.scripts.model_image:model-image}\label{api/gammapy.scripts.model_image:astropy}\label{api/gammapy.scripts.model_image::doc}\index{model\_image() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.model_image:gammapy.scripts.model_image}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{model\_image}}{}{}
Given a catalog of sources, simulate a flux image.
Inputs:
\begin{itemize}
\item {}
Source list (JSON file)
\item {}
PSF (JSON file)
\item {}
Exposure image (FITS file)
\end{itemize}
Outputs:
\begin{itemize}
\item {}
Source model flux image (FITS file)
\item {}
Source model excess image (FITS file)
\end{itemize}
\end{fulllineitems}
\paragraph{pfmap}
\label{api/gammapy.scripts.pfmap:pfmap}\label{api/gammapy.scripts.pfmap:astropy}\label{api/gammapy.scripts.pfmap::doc}\index{pfmap() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.pfmap:gammapy.scripts.pfmap}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{pfmap}}{\emph{infile}, \emph{skymap\_size}, \emph{bin\_size}, \emph{analysis\_position}, \emph{oversampling\_radius}, \emph{ring\_bg\_radii}, \emph{write\_output}, \emph{acceptance\_correction}, \emph{template\_background}, \emph{graphical\_output}, \emph{loglevel}}{}
Create sky maps from VHE event lists.
TODO: document
\end{fulllineitems}
\paragraph{pfsim}
\label{api/gammapy.scripts.pfsim:pfsim}\label{api/gammapy.scripts.pfsim:astropy}\label{api/gammapy.scripts.pfsim::doc}\index{pfsim() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.pfsim:gammapy.scripts.pfsim}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{pfsim}}{\emph{arf}, \emph{exposure\_time}, \emph{flux}, \emph{rmf\_file}, \emph{extra\_file}, \emph{output\_filename\_base}, \emph{write\_pha}, \emph{graphical\_output}, \emph{loglevel}}{}
Simulates IACT eventlist using an ARF file.
TODO: document
\end{fulllineitems}
\paragraph{pfspec}
\label{api/gammapy.scripts.pfspec:astropy}\label{api/gammapy.scripts.pfspec::doc}\label{api/gammapy.scripts.pfspec:pfspec}\index{pfspec() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.pfspec:gammapy.scripts.pfspec}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{pfspec}}{\emph{input\_file\_names}, \emph{analysis\_position}, \emph{analysis\_radius}, \emph{match\_rmf}, \emph{data\_dir}, \emph{write\_output}, \emph{graphical\_output}, \emph{loglevel}}{}
Create spectra from VHE event lists in FITS format.
prog {[}options{]} FILE {[}ARF RMF{]}
FILE can either be an indiviual .fits/.fits.gz file or a batch file.
In case it is a individual file, the ARF and RMF must also be specified.
The bankfile must contain three columns: data file, ARF, and RMF.
TODO: document
\end{fulllineitems}
\paragraph{reflected\_regions}
\label{api/gammapy.scripts.reflected_regions:reflected-regions}\label{api/gammapy.scripts.reflected_regions:astropy}\label{api/gammapy.scripts.reflected_regions::doc}\index{reflected\_regions() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.reflected_regions:gammapy.scripts.reflected_regions}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{reflected\_regions}}{\emph{x\_on}, \emph{y\_on}, \emph{r\_on}, \emph{x\_fov}, \emph{y\_fov}, \emph{r\_fov}, \emph{exclusion}, \emph{outfile}, \emph{min\_on\_distance}}{}
Find off regions for a given on region and exclusion mask.
TODO: explain a bit.
\end{fulllineitems}
\paragraph{residual\_images}
\label{api/gammapy.scripts.residual_images:astropy}\label{api/gammapy.scripts.residual_images::doc}\label{api/gammapy.scripts.residual_images:residual-images}\index{residual\_images() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.residual_images:gammapy.scripts.residual_images}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{residual\_images}}{\emph{model\_file}, \emph{data\_file}, \emph{out\_file}, \emph{thetas}, \emph{overwrite}}{}
Compute source model residual images.
The input \code{data\_file} must contain the following HDU extensions:
\begin{itemize}
\item {}
`On' -- Counts image
\item {}
`Background' -- Background image
\end{itemize}
\end{fulllineitems}
\paragraph{root\_to\_fits}
\label{api/gammapy.scripts.root_to_fits:root-to-fits}\label{api/gammapy.scripts.root_to_fits:astropy}\label{api/gammapy.scripts.root_to_fits::doc}\index{root\_to\_fits() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.root_to_fits:gammapy.scripts.root_to_fits}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{root\_to\_fits}}{}{}
Convert ROOT files to FITS files (histograms and ntuples).
TODO: explain a bit.
\end{fulllineitems}
\paragraph{run\_cwt}
\label{api/gammapy.scripts.run_cwt:astropy}\label{api/gammapy.scripts.run_cwt::doc}\label{api/gammapy.scripts.run_cwt:run-cwt}\index{run\_cwt() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.run_cwt:gammapy.scripts.run_cwt}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{run\_cwt}}{\emph{infile}, \emph{outfile}, \emph{overwrite}, \emph{min\_scale}, \emph{nscales}, \emph{scale\_step}, \emph{thresh}, \emph{detect}, \emph{niter}, \emph{convergence}}{}
Compute filtered image using Continuous Wavelet Transform (CWT).
TODO: add example and explain output.
\end{fulllineitems}
\paragraph{sherpa\_image\_like}
\label{api/gammapy.scripts.sherpa_image_like:astropy}\label{api/gammapy.scripts.sherpa_image_like::doc}\label{api/gammapy.scripts.sherpa_image_like:sherpa-image-like}\index{sherpa\_image\_like() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.sherpa_image_like:gammapy.scripts.sherpa_image_like}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{sherpa\_image\_like}}{\emph{counts}, \emph{exposure}, \emph{background}, \emph{psf}, \emph{sources}, \emph{roi}, \emph{outfile}}{}
Fit the morphology of a number of sources.
Uses initial parameters from a JSON file (for now only Gaussians).
\end{fulllineitems}
\paragraph{sherpa\_model\_image}
\label{api/gammapy.scripts.sherpa_model_image:astropy}\label{api/gammapy.scripts.sherpa_model_image::doc}\label{api/gammapy.scripts.sherpa_model_image:sherpa-model-image}\index{sherpa\_model\_image() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.sherpa_model_image:gammapy.scripts.sherpa_model_image}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{sherpa\_model\_image}}{\emph{exposure}, \emph{psf}, \emph{sources}, \emph{model\_image}, \emph{overwrite}}{}
Compute source model image with Sherpa.
Inputs:
\begin{itemize}
\item {}
Source list (JSON file)
\item {}
PSF (JSON file)
\item {}
Exposure image (FITS file)
\end{itemize}
Outputs:
\begin{itemize}
\item {}
Source model flux image (FITS file)
\item {}
Source model excess image (FITS file)
\end{itemize}
\end{fulllineitems}
\paragraph{significance\_image}
\label{api/gammapy.scripts.significance_image:significance-image}\label{api/gammapy.scripts.significance_image:astropy}\label{api/gammapy.scripts.significance_image::doc}\index{significance\_image() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.significance_image:gammapy.scripts.significance_image}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{significance\_image}}{\emph{infile}, \emph{outfile}, \emph{theta}, \emph{overwrite}}{}
Make correlated significance image.
TODO: describe
\end{fulllineitems}
\paragraph{simulate\_source\_catalog}
\label{api/gammapy.scripts.simulate_source_catalog:simulate-source-catalog}\label{api/gammapy.scripts.simulate_source_catalog:astropy}\label{api/gammapy.scripts.simulate_source_catalog::doc}\index{simulate\_source\_catalog() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.simulate_source_catalog:gammapy.scripts.simulate_source_catalog}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{simulate\_source\_catalog}}{\emph{outfile}, \emph{nsources}, \emph{max\_age}, \emph{ism\_density}, \emph{supernova\_energy}, \emph{radial\_distribution}, \emph{velocity\_distribution}, \emph{spiral\_arms}, \emph{overwrite}}{}
Simulate a catalog of Galactic sources.
\begin{quote}
Several spatial and velocity distributions are available
and each source has associated PSR, PWN und SNR parameters.
\end{quote}
Available radial distributions:
CB98 :
F06 :
L06 :
P90 :
YK04 :
YK04B :
Available velocity distributions:
H05 :
F06B : Bimodal pulsar velocity distribution - Faucher \& Kaspi (2006).
F06P : Distribution by Lyne 1982 and adopted by Paczynski and Faucher.
\end{fulllineitems}
\paragraph{ts\_image}
\label{api/gammapy.scripts.ts_image:ts-image}\label{api/gammapy.scripts.ts_image:astropy}\label{api/gammapy.scripts.ts_image::doc}\index{ts\_image() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.ts_image:gammapy.scripts.ts_image}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{ts\_image}}{\emph{input\_file}, \emph{output\_file}, \emph{psf}, \emph{model}, \emph{scales}, \emph{downsample}, \emph{residual}, \emph{morphology}, \emph{width}, \emph{overwrite}, \emph{threshold}}{}
Compute source model residual images.
The input \code{data} fits file must contain the following HDU extensions:
\begin{itemize}
\item {}
`On' -- Counts image
\item {}
`Background' -- Background image
\item {}
`Diffuse' -- Diffuse model image
\item {}
`ExpGammaMap' -- Exposure image
\end{itemize}
\end{fulllineitems}
\paragraph{xspec}
\label{api/gammapy.scripts.xspec:astropy}\label{api/gammapy.scripts.xspec::doc}\label{api/gammapy.scripts.xspec:xspec}\index{xspec() (in module gammapy.scripts)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.scripts.xspec:gammapy.scripts.xspec}\pysiglinewithargsret{\code{gammapy.scripts.}\bfcode{xspec}}{}{}
Perform various tasks with XSPEC files (PHA, ARF, RMF).
Depending on the subcommand used, a variety of tasks
are implemented for XSPEC files (PHA, ARF, RMF).
\begin{itemize}
\item {}
info : Print summary infos
\item {}
plot : Make plots
\item {}
fake : Fake some data or IRFs.
\end{itemize}
TODO: describe
\end{fulllineitems}
\chapter{Tutorials and Examples}
\label{tutorials/index:tutorials-and-examples}\label{tutorials/index:astropy}\label{tutorials/index::doc}\label{tutorials/index:tutorials}
We currently have three places for Gammapy tutorials and examples:
\begin{enumerate}
\item {}
Python scripts with Sphinx documentation in the \code{docs/tutorials} folder in the \code{gammapy} repo.
\item {}
Python scripts without inline comments only in the \code{examples} folder in the \code{gammapy} repo.
\item {}
IPython notebooks in the \code{notebooks} folder in the \code{gammapy-extra} repo.
\end{enumerate}
Each of these solutions has advantages / disadvantages, we might consolidate this in the future as
the tooling to convert between these formats improves.
\section{Python example scripts with Sphinx documentation}
\label{tutorials/index:tutorials-sphinx}\label{tutorials/index:python-example-scripts-with-sphinx-documentation}
The tutorials show some real-world usage examples of the Gammapy Python package and / or command line tools.
\subsection{Crab multi-wavelength SED}
\label{tutorials/crab_mwl_sed/index:crab-multi-wavelength-sed}\label{tutorials/crab_mwl_sed/index::doc}\label{tutorials/crab_mwl_sed/index:tutorials-crab-mwl-sed}
Here we load Crab pulsar and nebula flux points {\hyperref[api/gammapy.datasets.load_crab_flux_points:gammapy.datasets.load_crab_flux_points]{\emph{\code{gammapy.datasets.load\_crab\_flux\_points}}}}
TODO:
\begin{itemize}
\item {}
describe data and emission components
\item {}
perform fit with \code{naima}!
\end{itemize}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}Plot Crab pulsar and nebula spectral energy distribution (SED).\PYGZdq{}\PYGZdq{}\PYGZdq{}}
\PYG{k+kn}{import} \PYG{n+nn}{numpy} \PYG{k+kn}{as} \PYG{n+nn}{np}
\PYG{k+kn}{import} \PYG{n+nn}{matplotlib.pyplot} \PYG{k+kn}{as} \PYG{n+nn}{plt}
\PYG{k+kn}{import} \PYG{n+nn}{astropy.units} \PYG{k+kn}{as} \PYG{n+nn}{u}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.datasets} \PYG{k+kn}{import} \PYG{n}{load\PYGZus{}crab\PYGZus{}flux\PYGZus{}points}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.spectrum} \PYG{k+kn}{import} \PYG{n}{crab\PYGZus{}flux}
\PYG{c}{\PYGZsh{} Plot flux points}
\PYG{k}{for} \PYG{n}{component} \PYG{o+ow}{in} \PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{pulsar}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{nebula}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{:}
\PYG{n}{table} \PYG{o}{=} \PYG{n}{load\PYGZus{}crab\PYGZus{}flux\PYGZus{}points}\PYG{p}{(}\PYG{n}{component}\PYG{o}{=}\PYG{n}{component}\PYG{p}{)}
\PYG{n}{x} \PYG{o}{=} \PYG{n}{table}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{energy}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{o}{.}\PYG{n}{data}
\PYG{n}{y} \PYG{o}{=} \PYG{n}{table}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{energy\PYGZus{}flux}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{o}{.}\PYG{n}{data}
\PYG{n}{yerr\PYGZus{}lo} \PYG{o}{=} \PYG{n}{table}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{energy\PYGZus{}flux\PYGZus{}err\PYGZus{}lo}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{o}{.}\PYG{n}{data}
\PYG{n}{yerr\PYGZus{}hi} \PYG{o}{=} \PYG{n}{table}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{energy\PYGZus{}flux\PYGZus{}err\PYGZus{}hi}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{o}{.}\PYG{n}{data}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{errorbar}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,} \PYG{n}{y}\PYG{p}{,} \PYG{n}{yerr}\PYG{o}{=}\PYG{p}{(}\PYG{n}{yerr\PYGZus{}lo}\PYG{p}{,} \PYG{n}{yerr\PYGZus{}hi}\PYG{p}{)}\PYG{p}{,} \PYG{n}{fmt}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{o}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{label}\PYG{o}{=}\PYG{n}{component}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Plot SED model}
\PYG{n}{energy} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{logspace}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{p}{,} \PYG{l+m+mi}{8}\PYG{p}{,} \PYG{l+m+mi}{100}\PYG{p}{)} \PYG{o}{*} \PYG{n}{u}\PYG{o}{.}\PYG{n}{MeV}
\PYG{n}{flux} \PYG{o}{=} \PYG{n}{u}\PYG{o}{.}\PYG{n}{Quantity}\PYG{p}{(}\PYG{n}{crab\PYGZus{}flux}\PYG{p}{(}\PYG{n}{energy}\PYG{o}{.}\PYG{n}{to}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{TeV}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{o}{.}\PYG{n}{value}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{cm\PYGZca{}\PYGZhy{}2 s\PYGZca{}\PYGZhy{}1 TeV\PYGZca{}\PYGZhy{}1}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{energy\PYGZus{}flux} \PYG{o}{=} \PYG{p}{(}\PYG{n}{energy} \PYG{o}{*}\PYG{o}{*} \PYG{l+m+mi}{2} \PYG{o}{*} \PYG{n}{flux}\PYG{p}{)}\PYG{o}{.}\PYG{n}{to}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{erg cm\PYGZca{}\PYGZhy{}2 s\PYGZca{}\PYGZhy{}1}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{plot}\PYG{p}{(}\PYG{n}{energy}\PYG{o}{.}\PYG{n}{value}\PYG{p}{,} \PYG{n}{energy\PYGZus{}flux}\PYG{o}{.}\PYG{n}{value}\PYG{p}{,} \PYG{n}{label}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Meyer (2010) model}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{lw}\PYG{o}{=}\PYG{l+m+mi}{3}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{title}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Crab pulsar and nebula spectral energy distribution (SED)}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{xlim}\PYG{p}{(}\PYG{p}{(}\PYG{l+m+mf}{3e\PYGZhy{}14}\PYG{p}{,} \PYG{l+m+mf}{3e8}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{ylim}\PYG{p}{(}\PYG{p}{(}\PYG{l+m+mf}{3e\PYGZhy{}13}\PYG{p}{,} \PYG{l+m+mf}{3e\PYGZhy{}7}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{xlabel}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Energy (MeV)}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{ylabel}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{E\PYGZca{}2 dN/dE (erg cm\PYGZca{}\PYGZhy{}2 s\PYGZca{}\PYGZhy{}1)}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{legend}\PYG{p}{(}\PYG{n}{loc}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{upper center}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{ncol}\PYG{o}{=}\PYG{l+m+mi}{3}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{grid}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{loglog}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{savefig}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{crab\PYGZus{}mwl.png}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\end{Verbatim}
\includegraphics{crab_mwl_sed.pdf}
\subsection{Fermi-LAT diffuse model predicted counts image}
\label{tutorials/npred/index:tutorials-npred}\label{tutorials/npred/index:astropy}\label{tutorials/npred/index::doc}\label{tutorials/npred/index:fermi-lat-diffuse-model-predicted-counts-image}
The {\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube]{\emph{\code{SpectralCube}}}} class allows for image-based analysis in energy
bands. In particular, similar functionality to gtmodel in the Fermi Science
tools \phantomsection\label{tutorials/npred/index:id1}{\hyperref[references:fssc2013]{\emph{{[}FSSC2013{]}}}} is offered in {\hyperref[api/gammapy.data.compute_npred_cube:gammapy.data.compute_npred_cube]{\emph{\code{compute\_npred\_cube}}}}
which generates a predicted instrument PSF-convolved counts cube based on a
provided background model. Unlike the science tools, this implementation is
appropriate for use with large regions of the sky.
\subsubsection{Predicting Counts}
\label{tutorials/npred/index:predicting-counts}
The example script below computes the Fermi PSF-convolved predicted counts map
using {\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube]{\emph{\code{SpectralCube}}}}. This is then used to produce a Li \& Ma significance
image \phantomsection\label{tutorials/npred/index:id2}{\hyperref[references:lima1983]{\emph{{[}LiMa1983{]}}}}. The left image shows the significance image,
while a comparison against the significance image
produced using the Fermi Science tools is shown on the right. These results are
for the Vela region for energies between 10 and 500 GeV.
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}Runs commands to produce convolved predicted counts map in current directory.\PYGZdq{}\PYGZdq{}\PYGZdq{}}
\PYG{k+kn}{import} \PYG{n+nn}{numpy} \PYG{k+kn}{as} \PYG{n+nn}{np}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.coordinates} \PYG{k+kn}{import} \PYG{n}{Angle}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.units} \PYG{k+kn}{import} \PYG{n}{Quantity}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.io} \PYG{k+kn}{import} \PYG{n}{fits}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.wcs} \PYG{k+kn}{import} \PYG{n}{WCS}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.data} \PYG{k+kn}{import} \PYG{p}{(}\PYG{n}{SpectralCube}\PYG{p}{,}
\PYG{n}{compute\PYGZus{}npred\PYGZus{}cube}\PYG{p}{,}
\PYG{n}{convolve\PYGZus{}cube}\PYG{p}{)}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.datasets} \PYG{k+kn}{import} \PYG{n}{FermiVelaRegion}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.irf} \PYG{k+kn}{import} \PYG{n}{EnergyDependentTablePSF}
\PYG{n}{\PYGZus{}\PYGZus{}all\PYGZus{}\PYGZus{}} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{prepare\PYGZus{}images}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}
\PYG{k}{def} \PYG{n+nf}{prepare\PYGZus{}images}\PYG{p}{(}\PYG{p}{)}\PYG{p}{:}
\PYG{c}{\PYGZsh{} Reads in data}
\PYG{n}{background\PYGZus{}file} \PYG{o}{=} \PYG{n}{FermiVelaRegion}\PYG{o}{.}\PYG{n}{filenames}\PYG{p}{(}\PYG{p}{)}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{diffuse\PYGZus{}model}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}
\PYG{n}{exposure\PYGZus{}file} \PYG{o}{=} \PYG{n}{FermiVelaRegion}\PYG{o}{.}\PYG{n}{filenames}\PYG{p}{(}\PYG{p}{)}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{exposure\PYGZus{}cube}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}
\PYG{n}{counts\PYGZus{}file} \PYG{o}{=} \PYG{n}{FermiVelaRegion}\PYG{o}{.}\PYG{n}{filenames}\PYG{p}{(}\PYG{p}{)}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{counts\PYGZus{}cube}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}
\PYG{n}{background\PYGZus{}model} \PYG{o}{=} \PYG{n}{SpectralCube}\PYG{o}{.}\PYG{n}{read}\PYG{p}{(}\PYG{n}{background\PYGZus{}file}\PYG{p}{)}
\PYG{n}{exposure\PYGZus{}cube} \PYG{o}{=} \PYG{n}{SpectralCube}\PYG{o}{.}\PYG{n}{read}\PYG{p}{(}\PYG{n}{exposure\PYGZus{}file}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Add correct units}
\PYG{n}{exposure\PYGZus{}cube}\PYG{o}{.}\PYG{n}{data} \PYG{o}{=} \PYG{n}{Quantity}\PYG{p}{(}\PYG{n}{exposure\PYGZus{}cube}\PYG{o}{.}\PYG{n}{data}\PYG{o}{.}\PYG{n}{value}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{cm2 s}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Re\PYGZhy{}project background cube}
\PYG{n}{repro\PYGZus{}bg\PYGZus{}cube} \PYG{o}{=} \PYG{n}{background\PYGZus{}model}\PYG{o}{.}\PYG{n}{reproject\PYGZus{}to}\PYG{p}{(}\PYG{n}{exposure\PYGZus{}cube}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Define energy band required for output}
\PYG{n}{energies} \PYG{o}{=} \PYG{n}{Quantity}\PYG{p}{(}\PYG{p}{[}\PYG{l+m+mi}{10}\PYG{p}{,} \PYG{l+m+mi}{500}\PYG{p}{]}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{GeV}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Compute the predicted counts cube}
\PYG{n}{npred\PYGZus{}cube} \PYG{o}{=} \PYG{n}{compute\PYGZus{}npred\PYGZus{}cube}\PYG{p}{(}\PYG{n}{repro\PYGZus{}bg\PYGZus{}cube}\PYG{p}{,} \PYG{n}{exposure\PYGZus{}cube}\PYG{p}{,} \PYG{n}{energies}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Convolve with Energy\PYGZhy{}dependent Fermi LAT PSF}
\PYG{n}{psf} \PYG{o}{=} \PYG{n}{EnergyDependentTablePSF}\PYG{o}{.}\PYG{n}{read}\PYG{p}{(}\PYG{n}{FermiVelaRegion}\PYG{o}{.}\PYG{n}{filenames}\PYG{p}{(}\PYG{p}{)}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{psf}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{convolved\PYGZus{}npred\PYGZus{}cube} \PYG{o}{=} \PYG{n}{convolve\PYGZus{}cube}\PYG{p}{(}\PYG{n}{npred\PYGZus{}cube}\PYG{p}{,} \PYG{n}{psf}\PYG{p}{,}
\PYG{n}{offset\PYGZus{}max}\PYG{o}{=}\PYG{n}{Angle}\PYG{p}{(}\PYG{l+m+mi}{3}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{deg}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Counts data}
\PYG{n}{counts\PYGZus{}data} \PYG{o}{=} \PYG{n}{fits}\PYG{o}{.}\PYG{n}{open}\PYG{p}{(}\PYG{n}{counts\PYGZus{}file}\PYG{p}{)}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{o}{.}\PYG{n}{data}
\PYG{n}{counts\PYGZus{}wcs} \PYG{o}{=} \PYG{n}{WCS}\PYG{p}{(}\PYG{n}{fits}\PYG{o}{.}\PYG{n}{open}\PYG{p}{(}\PYG{n}{counts\PYGZus{}file}\PYG{p}{)}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{o}{.}\PYG{n}{header}\PYG{p}{)}
\PYG{n}{counts\PYGZus{}cube} \PYG{o}{=} \PYG{n}{SpectralCube}\PYG{p}{(}\PYG{n}{data}\PYG{o}{=}\PYG{n}{Quantity}\PYG{p}{(}\PYG{n}{counts\PYGZus{}data}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{,}
\PYG{n}{wcs}\PYG{o}{=}\PYG{n}{counts\PYGZus{}wcs}\PYG{p}{,}
\PYG{n}{energy}\PYG{o}{=}\PYG{n}{energies}\PYG{p}{)}
\PYG{n}{counts\PYGZus{}cube} \PYG{o}{=} \PYG{n}{counts\PYGZus{}cube}\PYG{o}{.}\PYG{n}{reproject\PYGZus{}to}\PYG{p}{(}\PYG{n}{npred\PYGZus{}cube}\PYG{p}{)}
\PYG{n}{counts} \PYG{o}{=} \PYG{n}{counts\PYGZus{}cube}\PYG{o}{.}\PYG{n}{data}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}
\PYG{n}{model} \PYG{o}{=} \PYG{n}{convolved\PYGZus{}npred\PYGZus{}cube}\PYG{o}{.}\PYG{n}{data}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}
\PYG{c}{\PYGZsh{} Load Fermi tools gtmodel background\PYGZhy{}only result}
\PYG{n}{gtmodel} \PYG{o}{=} \PYG{n}{fits}\PYG{o}{.}\PYG{n}{open}\PYG{p}{(}\PYG{n}{FermiVelaRegion}\PYG{o}{.}\PYG{n}{filenames}\PYG{p}{(}\PYG{p}{)}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{background\PYGZus{}image}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{)}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{o}{.}\PYG{n}{data}\PYG{o}{.}\PYG{n}{astype}\PYG{p}{(}\PYG{n+nb}{float}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Ratio for the two background images}
\PYG{n}{ratio} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{nan\PYGZus{}to\PYGZus{}num}\PYG{p}{(}\PYG{n}{model} \PYG{o}{/} \PYG{n}{gtmodel}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Header is required for plotting, so returned here}
\PYG{n}{wcs} \PYG{o}{=} \PYG{n}{npred\PYGZus{}cube}\PYG{o}{.}\PYG{n}{wcs}
\PYG{n}{wcs} \PYG{o}{=} \PYG{n}{wcs}\PYG{o}{.}\PYG{n}{dropaxis}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{p}{)}
\PYG{n}{header} \PYG{o}{=} \PYG{n}{wcs}\PYG{o}{.}\PYG{n}{to\PYGZus{}header}\PYG{p}{(}\PYG{p}{)}
\PYG{k}{return} \PYG{n}{model}\PYG{p}{,} \PYG{n}{gtmodel}\PYG{p}{,} \PYG{n}{ratio}\PYG{p}{,} \PYG{n}{counts}\PYG{p}{,} \PYG{n}{header}
\end{Verbatim}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}Runs commands to produce convolved predicted counts map in current directory.\PYGZdq{}\PYGZdq{}\PYGZdq{}}
\PYG{k+kn}{import} \PYG{n+nn}{numpy} \PYG{k+kn}{as} \PYG{n+nn}{np}
\PYG{k+kn}{import} \PYG{n+nn}{matplotlib.pyplot} \PYG{k+kn}{as} \PYG{n+nn}{plt}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.io} \PYG{k+kn}{import} \PYG{n}{fits}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.stats} \PYG{k+kn}{import} \PYG{n}{significance}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.image.utils} \PYG{k+kn}{import} \PYG{n}{disk\PYGZus{}correlate}
\PYG{k+kn}{from} \PYG{n+nn}{npred\PYGZus{}general} \PYG{k+kn}{import} \PYG{n}{prepare\PYGZus{}images}
\PYG{k+kn}{from} \PYG{n+nn}{aplpy} \PYG{k+kn}{import} \PYG{n}{FITSFigure}
\PYG{n}{model}\PYG{p}{,} \PYG{n}{gtmodel}\PYG{p}{,} \PYG{n}{ratio}\PYG{p}{,} \PYG{n}{counts}\PYG{p}{,} \PYG{n}{header} \PYG{o}{=} \PYG{n}{prepare\PYGZus{}images}\PYG{p}{(}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Top hat correlation}
\PYG{n}{correlation\PYGZus{}radius} \PYG{o}{=} \PYG{l+m+mi}{3}
\PYG{n}{correlated\PYGZus{}gtmodel} \PYG{o}{=} \PYG{n}{disk\PYGZus{}correlate}\PYG{p}{(}\PYG{n}{gtmodel}\PYG{p}{,} \PYG{n}{correlation\PYGZus{}radius}\PYG{p}{)}
\PYG{n}{correlated\PYGZus{}counts} \PYG{o}{=} \PYG{n}{disk\PYGZus{}correlate}\PYG{p}{(}\PYG{n}{counts}\PYG{p}{,} \PYG{n}{correlation\PYGZus{}radius}\PYG{p}{)}
\PYG{n}{correlated\PYGZus{}model} \PYG{o}{=} \PYG{n}{disk\PYGZus{}correlate}\PYG{p}{(}\PYG{n}{model}\PYG{p}{,} \PYG{n}{correlation\PYGZus{}radius}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Fermi significance}
\PYG{n}{fermi\PYGZus{}significance} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{nan\PYGZus{}to\PYGZus{}num}\PYG{p}{(}\PYG{n}{significance}\PYG{p}{(}\PYG{n}{correlated\PYGZus{}counts}\PYG{p}{,} \PYG{n}{gtmodel}\PYG{p}{,}
\PYG{n}{method}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{lima}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Gammapy significance}
\PYG{n}{significance} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{nan\PYGZus{}to\PYGZus{}num}\PYG{p}{(}\PYG{n}{significance}\PYG{p}{(}\PYG{n}{correlated\PYGZus{}counts}\PYG{p}{,} \PYG{n}{correlated\PYGZus{}model}\PYG{p}{,}
\PYG{n}{method}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{lima}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{titles} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Gammapy Significance}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Fermi Tools Significance}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}
\PYG{c}{\PYGZsh{} Plot}
\PYG{n}{fig} \PYG{o}{=} \PYG{n}{plt}\PYG{o}{.}\PYG{n}{figure}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{hdu1} \PYG{o}{=} \PYG{n}{fits}\PYG{o}{.}\PYG{n}{ImageHDU}\PYG{p}{(}\PYG{n}{significance}\PYG{p}{,} \PYG{n}{header}\PYG{p}{)}
\PYG{n}{f1} \PYG{o}{=} \PYG{n}{FITSFigure}\PYG{p}{(}\PYG{n}{hdu1}\PYG{p}{,} \PYG{n}{figure}\PYG{o}{=}\PYG{n}{fig}\PYG{p}{,} \PYG{n}{convention}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{wells}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{subplot}\PYG{o}{=}\PYG{p}{[}\PYG{l+m+mf}{0.15}\PYG{p}{,}\PYG{l+m+mf}{0.214}\PYG{p}{,}\PYG{l+m+mf}{0.38}\PYG{p}{,}\PYG{l+m+mf}{0.494}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{f1}\PYG{o}{.}\PYG{n}{set\PYGZus{}tick\PYGZus{}labels\PYGZus{}font}\PYG{p}{(}\PYG{n}{size}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{x\PYGZhy{}small}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{f1}\PYG{o}{.}\PYG{n}{tick\PYGZus{}labels}\PYG{o}{.}\PYG{n}{set\PYGZus{}xformat}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ddd}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{f1}\PYG{o}{.}\PYG{n}{tick\PYGZus{}labels}\PYG{o}{.}\PYG{n}{set\PYGZus{}yformat}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ddd}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{f1}\PYG{o}{.}\PYG{n}{show\PYGZus{}colorscale}\PYG{p}{(}\PYG{n}{vmin}\PYG{o}{=}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{n}{vmax}\PYG{o}{=}\PYG{l+m+mi}{10}\PYG{p}{)}
\PYG{n}{hdu2} \PYG{o}{=} \PYG{n}{fits}\PYG{o}{.}\PYG{n}{ImageHDU}\PYG{p}{(}\PYG{n}{fermi\PYGZus{}significance}\PYG{p}{,} \PYG{n}{header}\PYG{p}{)}
\PYG{n}{f2} \PYG{o}{=} \PYG{n}{FITSFigure}\PYG{p}{(}\PYG{n}{hdu2}\PYG{p}{,} \PYG{n}{figure}\PYG{o}{=}\PYG{n}{fig}\PYG{p}{,} \PYG{n}{convention}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{wells}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{subplot}\PYG{o}{=}\PYG{p}{[}\PYG{l+m+mf}{0.56}\PYG{p}{,}\PYG{l+m+mf}{0.2}\PYG{p}{,}\PYG{l+m+mf}{0.4}\PYG{p}{,}\PYG{l+m+mf}{0.52}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{f2}\PYG{o}{.}\PYG{n}{set\PYGZus{}tick\PYGZus{}labels\PYGZus{}font}\PYG{p}{(}\PYG{n}{size}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{x\PYGZhy{}small}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{f2}\PYG{o}{.}\PYG{n}{tick\PYGZus{}labels}\PYG{o}{.}\PYG{n}{set\PYGZus{}xformat}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ddd}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{f2}\PYG{o}{.}\PYG{n}{hide\PYGZus{}ytick\PYGZus{}labels}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{f2}\PYG{o}{.}\PYG{n}{hide\PYGZus{}yaxis\PYGZus{}label}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{f2}\PYG{o}{.}\PYG{n}{show\PYGZus{}colorscale}\PYG{p}{(}\PYG{n}{vmin}\PYG{o}{=}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{n}{vmax}\PYG{o}{=}\PYG{l+m+mi}{10}\PYG{p}{)}
\PYG{n}{f2}\PYG{o}{.}\PYG{n}{add\PYGZus{}colorbar}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{f2}\PYG{o}{.}\PYG{n}{colorbar}\PYG{o}{.}\PYG{n}{set\PYGZus{}width}\PYG{p}{(}\PYG{l+m+mf}{0.1}\PYG{p}{)}
\PYG{n}{f2}\PYG{o}{.}\PYG{n}{colorbar}\PYG{o}{.}\PYG{n}{set\PYGZus{}location}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{right}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{fig}\PYG{o}{.}\PYG{n}{text}\PYG{p}{(}\PYG{l+m+mf}{0.22}\PYG{p}{,}\PYG{l+m+mf}{0.72}\PYG{p}{,}\PYG{l+s}{\PYGZdq{}}\PYG{l+s}{Gammapy Significance}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,}\PYG{n}{color}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{black}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,}\PYG{n}{size}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{14}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{fig}\PYG{o}{.}\PYG{n}{text}\PYG{p}{(}\PYG{l+m+mf}{0.63}\PYG{p}{,}\PYG{l+m+mf}{0.72}\PYG{p}{,}\PYG{l+s}{\PYGZdq{}}\PYG{l+s}{Fermi Tools Significance}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,}\PYG{n}{color}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{black}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,}\PYG{n}{size}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{14}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{fig}\PYG{o}{.}\PYG{n}{canvas}\PYG{o}{.}\PYG{n}{draw}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}
\includegraphics{npred_convolved_significance.pdf}
\subsubsection{Checks}
\label{tutorials/npred/index:checks}
For small regions, the predicted counts cube and significance images may be
checked against the gtmodel output. The Vela region shown above is taken in
this example in one energy band with the parameters outlined in the
\href{https://github.com/gammapy/gammapy-extra/blob/master/datasets/vela\_region/README.rst}{README file for FermiVelaRegion}.
Images for the predicted background counts in this region in the Gammapy case
(left) and Fermi Science Tools gtmodel case (center) are shown below, based on
the differential flux contribution of the Fermi diffuse model gll\_iem\_v05\_rev1.fit.
The image on the right shows the ratio. \textbf{Note that the colorbar scale applies only to
the ratio image.}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}Runs commands to produce convolved predicted counts map in current directory.}
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}}
\PYG{k+kn}{import} \PYG{n+nn}{matplotlib.pyplot} \PYG{k+kn}{as} \PYG{n+nn}{plt}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.io} \PYG{k+kn}{import} \PYG{n}{fits}
\PYG{k+kn}{from} \PYG{n+nn}{npred\PYGZus{}general} \PYG{k+kn}{import} \PYG{n}{prepare\PYGZus{}images}
\PYG{k+kn}{from} \PYG{n+nn}{aplpy} \PYG{k+kn}{import} \PYG{n}{FITSFigure}
\PYG{n}{model}\PYG{p}{,} \PYG{n}{gtmodel}\PYG{p}{,} \PYG{n}{ratio}\PYG{p}{,} \PYG{n}{counts}\PYG{p}{,} \PYG{n}{header} \PYG{o}{=} \PYG{n}{prepare\PYGZus{}images}\PYG{p}{(}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Plotting}
\PYG{n}{fig} \PYG{o}{=} \PYG{n}{plt}\PYG{o}{.}\PYG{n}{figure}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{hdu1} \PYG{o}{=} \PYG{n}{fits}\PYG{o}{.}\PYG{n}{ImageHDU}\PYG{p}{(}\PYG{n}{model}\PYG{p}{,} \PYG{n}{header}\PYG{p}{)}
\PYG{n}{f1} \PYG{o}{=} \PYG{n}{FITSFigure}\PYG{p}{(}\PYG{n}{hdu1}\PYG{p}{,} \PYG{n}{figure}\PYG{o}{=}\PYG{n}{fig}\PYG{p}{,} \PYG{n}{convention}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{wells}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{subplot}\PYG{o}{=}\PYG{p}{[}\PYG{l+m+mf}{0.18}\PYG{p}{,} \PYG{l+m+mf}{0.264}\PYG{p}{,} \PYG{l+m+mf}{0.18}\PYG{p}{,} \PYG{l+m+mf}{0.234}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{f1}\PYG{o}{.}\PYG{n}{tick\PYGZus{}labels}\PYG{o}{.}\PYG{n}{set\PYGZus{}font}\PYG{p}{(}\PYG{n}{size}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{x\PYGZhy{}small}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{f1}\PYG{o}{.}\PYG{n}{tick\PYGZus{}labels}\PYG{o}{.}\PYG{n}{set\PYGZus{}xformat}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ddd}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{f1}\PYG{o}{.}\PYG{n}{tick\PYGZus{}labels}\PYG{o}{.}\PYG{n}{set\PYGZus{}yformat}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ddd}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{f1}\PYG{o}{.}\PYG{n}{axis\PYGZus{}labels}\PYG{o}{.}\PYG{n}{hide\PYGZus{}x}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{f1}\PYG{o}{.}\PYG{n}{show\PYGZus{}colorscale}\PYG{p}{(}\PYG{n}{vmin}\PYG{o}{=}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{n}{vmax}\PYG{o}{=}\PYG{l+m+mf}{0.3}\PYG{p}{)}
\PYG{n}{hdu2} \PYG{o}{=} \PYG{n}{fits}\PYG{o}{.}\PYG{n}{ImageHDU}\PYG{p}{(}\PYG{n}{gtmodel}\PYG{p}{,} \PYG{n}{header}\PYG{p}{)}
\PYG{n}{f2} \PYG{o}{=} \PYG{n}{FITSFigure}\PYG{p}{(}\PYG{n}{hdu2}\PYG{p}{,} \PYG{n}{figure}\PYG{o}{=}\PYG{n}{fig}\PYG{p}{,} \PYG{n}{convention}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{wells}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{subplot}\PYG{o}{=}\PYG{p}{[}\PYG{l+m+mf}{0.38}\PYG{p}{,} \PYG{l+m+mf}{0.25}\PYG{p}{,} \PYG{l+m+mf}{0.2}\PYG{p}{,} \PYG{l+m+mf}{0.26}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{f2}\PYG{o}{.}\PYG{n}{tick\PYGZus{}labels}\PYG{o}{.}\PYG{n}{set\PYGZus{}font}\PYG{p}{(}\PYG{n}{size}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{x\PYGZhy{}small}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{f2}\PYG{o}{.}\PYG{n}{tick\PYGZus{}labels}\PYG{o}{.}\PYG{n}{set\PYGZus{}xformat}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ddd}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{f2}\PYG{o}{.}\PYG{n}{tick\PYGZus{}labels}\PYG{o}{.}\PYG{n}{hide\PYGZus{}y}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{f2}\PYG{o}{.}\PYG{n}{axis\PYGZus{}labels}\PYG{o}{.}\PYG{n}{hide\PYGZus{}y}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{f2}\PYG{o}{.}\PYG{n}{show\PYGZus{}colorscale}\PYG{p}{(}\PYG{n}{vmin}\PYG{o}{=}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{n}{vmax}\PYG{o}{=}\PYG{l+m+mf}{0.3}\PYG{p}{)}
\PYG{n}{f2}\PYG{o}{.}\PYG{n}{add\PYGZus{}colorbar}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{f2}\PYG{o}{.}\PYG{n}{colorbar}\PYG{o}{.}\PYG{n}{set\PYGZus{}width}\PYG{p}{(}\PYG{l+m+mf}{0.1}\PYG{p}{)}
\PYG{n}{f2}\PYG{o}{.}\PYG{n}{colorbar}\PYG{o}{.}\PYG{n}{set\PYGZus{}location}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{right}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{hdu3} \PYG{o}{=} \PYG{n}{fits}\PYG{o}{.}\PYG{n}{ImageHDU}\PYG{p}{(}\PYG{n}{ratio}\PYG{p}{,} \PYG{n}{header}\PYG{p}{)}
\PYG{n}{f3} \PYG{o}{=} \PYG{n}{FITSFigure}\PYG{p}{(}\PYG{n}{hdu3}\PYG{p}{,} \PYG{n}{figure}\PYG{o}{=}\PYG{n}{fig}\PYG{p}{,} \PYG{n}{convention}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{wells}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{subplot}\PYG{o}{=}\PYG{p}{[}\PYG{l+m+mf}{0.67}\PYG{p}{,} \PYG{l+m+mf}{0.25}\PYG{p}{,} \PYG{l+m+mf}{0.2}\PYG{p}{,} \PYG{l+m+mf}{0.26}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{f3}\PYG{o}{.}\PYG{n}{tick\PYGZus{}labels}\PYG{o}{.}\PYG{n}{set\PYGZus{}font}\PYG{p}{(}\PYG{n}{size}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{x\PYGZhy{}small}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{f3}\PYG{o}{.}\PYG{n}{tick\PYGZus{}labels}\PYG{o}{.}\PYG{n}{set\PYGZus{}xformat}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ddd}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{f3}\PYG{o}{.}\PYG{n}{tick\PYGZus{}labels}\PYG{o}{.}\PYG{n}{hide\PYGZus{}y}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{f3}\PYG{o}{.}\PYG{n}{axis\PYGZus{}labels}\PYG{o}{.}\PYG{n}{hide}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{f3}\PYG{o}{.}\PYG{n}{show\PYGZus{}colorscale}\PYG{p}{(}\PYG{n}{vmin}\PYG{o}{=}\PYG{l+m+mf}{0.9}\PYG{p}{,} \PYG{n}{vmax}\PYG{o}{=}\PYG{l+m+mf}{1.1}\PYG{p}{)}
\PYG{n}{f3}\PYG{o}{.}\PYG{n}{add\PYGZus{}colorbar}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{f3}\PYG{o}{.}\PYG{n}{colorbar}\PYG{o}{.}\PYG{n}{set\PYGZus{}width}\PYG{p}{(}\PYG{l+m+mf}{0.1}\PYG{p}{)}
\PYG{n}{f3}\PYG{o}{.}\PYG{n}{colorbar}\PYG{o}{.}\PYG{n}{set\PYGZus{}location}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{right}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{fig}\PYG{o}{.}\PYG{n}{text}\PYG{p}{(}\PYG{l+m+mf}{0.19}\PYG{p}{,} \PYG{l+m+mf}{0.53}\PYG{p}{,} \PYG{l+s}{\PYGZdq{}}\PYG{l+s}{Gammapy Background}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{color}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{black}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{size}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{9}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{fig}\PYG{o}{.}\PYG{n}{text}\PYG{p}{(}\PYG{l+m+mf}{0.39}\PYG{p}{,} \PYG{l+m+mf}{0.53}\PYG{p}{,} \PYG{l+s}{\PYGZdq{}}\PYG{l+s}{Fermi Tools Background}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{color}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{black}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{size}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{9}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{fig}\PYG{o}{.}\PYG{n}{text}\PYG{p}{(}\PYG{l+m+mf}{0.68}\PYG{p}{,} \PYG{l+m+mf}{0.53}\PYG{p}{,} \PYG{l+s}{\PYGZdq{}}\PYG{l+s}{Ratio: }\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{ Gammapy/Fermi Tools}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{color}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{black}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{size}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{9}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{fig}\PYG{o}{.}\PYG{n}{canvas}\PYG{o}{.}\PYG{n}{draw}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}
\includegraphics{npred_convolved.pdf}
We may compare these against the true counts observed by Fermi LAT in this region
for the same parameters:
\begin{itemize}
\item {}
True total counts: 1551
\item {}
Fermi Tools gtmodel predicted background counts: 265
\item {}
Gammapy predicted background counts: 282
\end{itemize}
\subsection{Catalog \& Simulation Images}
\label{tutorials/catalog/index:astropy}\label{tutorials/catalog/index::doc}\label{tutorials/catalog/index:tutorials-catalog}\label{tutorials/catalog/index:catalog-simulation-images}
The {\hyperref[api/gammapy.image.catalog_image:gammapy.image.catalog_image]{\emph{\code{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
{\hyperref[astro/population/index:module-gammapy.astro.population]{\emph{\code{population}}}}). Examples of these two use-cases are included below.
\subsubsection{Source Catalog Images}
\label{tutorials/catalog/index: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.
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}Produces an image from 1FHL catalog point sources.}
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}}
\PYG{k+kn}{from} \PYG{n+nn}{aplpy} \PYG{k+kn}{import} \PYG{n}{FITSFigure}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.datasets} \PYG{k+kn}{import} \PYG{n}{FermiGalacticCenter}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.image} \PYG{k+kn}{import} \PYG{n}{make\PYGZus{}empty\PYGZus{}image}\PYG{p}{,} \PYG{n}{catalog\PYGZus{}image}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.irf} \PYG{k+kn}{import} \PYG{n}{EnergyDependentTablePSF}
\PYG{c}{\PYGZsh{} Create image of defined size}
\PYG{n}{reference} \PYG{o}{=} \PYG{n}{make\PYGZus{}empty\PYGZus{}image}\PYG{p}{(}\PYG{n}{nxpix}\PYG{o}{=}\PYG{l+m+mi}{300}\PYG{p}{,} \PYG{n}{nypix}\PYG{o}{=}\PYG{l+m+mi}{100}\PYG{p}{,} \PYG{n}{binsz}\PYG{o}{=}\PYG{l+m+mi}{1}\PYG{p}{)}
\PYG{n}{psf\PYGZus{}file} \PYG{o}{=} \PYG{n}{FermiGalacticCenter}\PYG{o}{.}\PYG{n}{filenames}\PYG{p}{(}\PYG{p}{)}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{psf}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}
\PYG{n}{psf} \PYG{o}{=} \PYG{n}{EnergyDependentTablePSF}\PYG{o}{.}\PYG{n}{read}\PYG{p}{(}\PYG{n}{psf\PYGZus{}file}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Create image}
\PYG{n}{image} \PYG{o}{=} \PYG{n}{catalog\PYGZus{}image}\PYG{p}{(}\PYG{n}{reference}\PYG{p}{,} \PYG{n}{psf}\PYG{p}{,} \PYG{n}{catalog}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{1FHL}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{source\PYGZus{}type}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{point}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,}
\PYG{n}{total\PYGZus{}flux}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{True}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Plot}
\PYG{n}{fig} \PYG{o}{=} \PYG{n}{FITSFigure}\PYG{p}{(}\PYG{n}{image}\PYG{o}{.}\PYG{n}{to\PYGZus{}fits}\PYG{p}{(}\PYG{p}{)}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{fig}\PYG{o}{.}\PYG{n}{show\PYGZus{}grayscale}\PYG{p}{(}\PYG{n}{stretch}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{linear}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{interpolation}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{none}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{fig}\PYG{o}{.}\PYG{n}{add\PYGZus{}colorbar}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}
\includegraphics{source_image_demo.pdf}
\subsubsection{Simulated Catalog Images}
\label{tutorials/catalog/index:simulated-catalog-images}
In this case, a galaxy is simulated with {\hyperref[astro/population/index:module-gammapy.astro.population]{\emph{\code{population}}}} to produce a
source catalog. This is then converted into an image.
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}Simulates a galaxy of point sources and produces an image.}
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.units} \PYG{k+kn}{import} \PYG{n}{Quantity}
\PYG{k+kn}{from} \PYG{n+nn}{aplpy} \PYG{k+kn}{import} \PYG{n}{FITSFigure}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.astro} \PYG{k+kn}{import} \PYG{n}{population}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.datasets} \PYG{k+kn}{import} \PYG{n}{FermiGalacticCenter}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.image} \PYG{k+kn}{import} \PYG{n}{make\PYGZus{}empty\PYGZus{}image}\PYG{p}{,} \PYG{n}{catalog\PYGZus{}image}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.irf} \PYG{k+kn}{import} \PYG{n}{EnergyDependentTablePSF}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.utils.random} \PYG{k+kn}{import} \PYG{n}{sample\PYGZus{}powerlaw}
\PYG{c}{\PYGZsh{} Create image of defined size}
\PYG{n}{reference} \PYG{o}{=} \PYG{n}{make\PYGZus{}empty\PYGZus{}image}\PYG{p}{(}\PYG{n}{nxpix}\PYG{o}{=}\PYG{l+m+mi}{300}\PYG{p}{,} \PYG{n}{nypix}\PYG{o}{=}\PYG{l+m+mi}{100}\PYG{p}{,} \PYG{n}{binsz}\PYG{o}{=}\PYG{l+m+mi}{1}\PYG{p}{)}
\PYG{n}{psf\PYGZus{}file} \PYG{o}{=} \PYG{n}{FermiGalacticCenter}\PYG{o}{.}\PYG{n}{filenames}\PYG{p}{(}\PYG{p}{)}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{psf}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}
\PYG{n}{psf} \PYG{o}{=} \PYG{n}{EnergyDependentTablePSF}\PYG{o}{.}\PYG{n}{read}\PYG{p}{(}\PYG{n}{psf\PYGZus{}file}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Simulation Parameters}
\PYG{c}{\PYGZsh{} source density at the sun (sources kpc\PYGZca{}\PYGZhy{}1)}
\PYG{n}{rho\PYGZus{}sun} \PYG{o}{=} \PYG{l+m+mi}{3}
\PYG{c}{\PYGZsh{} number of sources}
\PYG{n}{n\PYGZus{}sources} \PYG{o}{=} \PYG{n+nb}{int}\PYG{p}{(}\PYG{l+m+mf}{5e2}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Spatial distribution using Lorimer (2006) model}
\PYG{n}{rad\PYGZus{}dis} \PYG{o}{=} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{L06}\PYG{l+s}{\PYGZsq{}}
\PYG{c}{\PYGZsh{} Velocity dispersion}
\PYG{n}{vel\PYGZus{}dis} \PYG{o}{=} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{F06B}\PYG{l+s}{\PYGZsq{}}
\PYG{c}{\PYGZsh{} Includes spiral arms}
\PYG{n}{spiralarms} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{c}{\PYGZsh{} Creates table}
\PYG{n}{table} \PYG{o}{=} \PYG{n}{population}\PYG{o}{.}\PYG{n}{make\PYGZus{}base\PYGZus{}catalog\PYGZus{}galactic}\PYG{p}{(}\PYG{n}{n\PYGZus{}sources}\PYG{o}{=}\PYG{n}{n\PYGZus{}sources}\PYG{p}{,} \PYG{n}{rad\PYGZus{}dis}\PYG{o}{=}\PYG{n}{rad\PYGZus{}dis}\PYG{p}{,}
\PYG{n}{vel\PYGZus{}dis}\PYG{o}{=}\PYG{n}{vel\PYGZus{}dis}\PYG{p}{,} \PYG{n}{max\PYGZus{}age}\PYG{o}{=}\PYG{l+m+mf}{1e6}\PYG{p}{,}
\PYG{n}{spiralarms}\PYG{o}{=}\PYG{n}{spiralarms}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Minimum source luminosity (ph s\PYGZca{}\PYGZhy{}1)}
\PYG{n}{luminosity\PYGZus{}min} \PYG{o}{=} \PYG{l+m+mf}{4e34}
\PYG{c}{\PYGZsh{} Maximum source luminosity (ph s\PYGZca{}\PYGZhy{}1)}
\PYG{n}{luminosity\PYGZus{}max} \PYG{o}{=} \PYG{l+m+mf}{4e37}
\PYG{c}{\PYGZsh{} Luminosity function differential power\PYGZhy{}law index}
\PYG{n}{luminosity\PYGZus{}index} \PYG{o}{=} \PYG{l+m+mf}{1.5}
\PYG{c}{\PYGZsh{} Assigns luminosities to sources}
\PYG{n}{luminosity} \PYG{o}{=} \PYG{n}{sample\PYGZus{}powerlaw}\PYG{p}{(}\PYG{n}{luminosity\PYGZus{}min}\PYG{p}{,} \PYG{n}{luminosity\PYGZus{}max}\PYG{p}{,} \PYG{n}{luminosity\PYGZus{}index}\PYG{p}{,}
\PYG{n}{n\PYGZus{}sources}\PYG{p}{)}
\PYG{n}{table}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{luminosity}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]} \PYG{o}{=} \PYG{n}{luminosity}
\PYG{c}{\PYGZsh{} Adds parameters to table: distance, glon, glat, flux, angular\PYGZus{}extension}
\PYG{n}{table} \PYG{o}{=} \PYG{n}{population}\PYG{o}{.}\PYG{n}{add\PYGZus{}observed\PYGZus{}parameters}\PYG{p}{(}\PYG{n}{table}\PYG{p}{)}
\PYG{n}{table}\PYG{o}{.}\PYG{n}{meta}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Energy Bins}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]} \PYG{o}{=} \PYG{n}{Quantity}\PYG{p}{(}\PYG{p}{[}\PYG{l+m+mi}{10}\PYG{p}{,} \PYG{l+m+mi}{500}\PYG{p}{]}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{GeV}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Create image}
\PYG{n}{image} \PYG{o}{=} \PYG{n}{catalog\PYGZus{}image}\PYG{p}{(}\PYG{n}{reference}\PYG{p}{,} \PYG{n}{psf}\PYG{p}{,} \PYG{n}{catalog}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{simulation}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{source\PYGZus{}type}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{point}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,}
\PYG{n}{total\PYGZus{}flux}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{,} \PYG{n}{sim\PYGZus{}table}\PYG{o}{=}\PYG{n}{table}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Plot}
\PYG{n}{fig} \PYG{o}{=} \PYG{n}{FITSFigure}\PYG{p}{(}\PYG{n}{image}\PYG{o}{.}\PYG{n}{to\PYGZus{}fits}\PYG{p}{(}\PYG{p}{)}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{fig}\PYG{o}{.}\PYG{n}{show\PYGZus{}grayscale}\PYG{p}{(}\PYG{n}{stretch}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{linear}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{interpolation}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{none}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{fig}\PYG{o}{.}\PYG{n}{add\PYGZus{}colorbar}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}
\includegraphics{simulated_image_demo.pdf}
\subsubsection{Caveats \& Future Developments}
\label{tutorials/catalog/index:caveats-future-developments}\begin{description}
\item[{It should be noted that the current implementation does not support:}] \leavevmode\begin{itemize}
\item {}
The inclusion of extended sources
\item {}
Production of images in more than one energy band
\end{itemize}
\end{description}
\subsection{Where to stick your Spectral Points?}
\label{tutorials/flux_point/index:where-to-stick-your-spectral-points}\label{tutorials/flux_point/index:astropy}\label{tutorials/flux_point/index::doc}\label{tutorials/flux_point/index:tutorials-flux-point}
The {\hyperref[spectrum/index:module-gammapy.spectrum]{\emph{\code{gammapy.spectrum}}}} module offers a number of options for positioning data points within an energy band. This example offers a comparison between
the log center and Lafferty \& Wyatt (described in \phantomsection\label{tutorials/flux_point/index:id1}{\hyperref[references:lafferty1994]{\emph{{[}Lafferty1994{]}}}}) methods. See {\hyperref[api/gammapy.spectrum.compute_differential_flux_points:gammapy.spectrum.compute_differential_flux_points]{\emph{\code{gammapy.spectrum.compute\_differential\_flux\_points}}}} for documentation on usage.
\subsubsection{Lafferty \& Wyatt vs. Log Center}
\label{tutorials/flux_point/index:lafferty-wyatt-vs-log-center}
In measurements of spectra which do not vary rapidly, it is usually sufficient to represent the data within a bin using the log bin center.
However, it is sometimes the case where the region of interest lies within a low frequency regime such that
large bin widths must be chosen to ensure statistical errors remain small. In cases where the spectrum varies rapidly (for
instance, exponentially) over wide bins, simply choosing the log bin center does not offer a good representation of the true underlying spectrum.
Instead, Lafferty \& Wyatt \phantomsection\label{tutorials/flux_point/index:id2}{\hyperref[references:lafferty1994]{\emph{{[}Lafferty1994{]}}}} offer an alternative approach for such situations. In a bin of width \(\Delta E\) between bounds
\(E_1\) and \(E_2\) for energy \(E\), the expectation \(<g_{meas}>\) of the true underlying spectrum, \(g(E)\) is defined as
\begin{gather}
\begin{split}<g_{meas}> = \frac{1}{\Delta E}\int_{E_1}^{E_2}{g(E) dE}\end{split}\notag
\end{gather}
As the bin size tends to zero, the expectation of the spectrum tends to it's true value. The value of \(E\) within a bin for
which the expectation should be regarded as a measurement of the true spectrum is determined by Lafferty \& Wyatt as the energy at
which the expectation value is equal to the mean value of the underlying true spectrum within that bin, noted as \(E_{lw}\). Thus knowledge of the true spectrum
\(g(E)\) or an estimate for this (determined by fitting) is required.
So it follows that, in setting expectation equal to \(g(E)\) at \(E_{lw}\), the position of \(E_{lw}\) is given by the following equation:
\begin{gather}
\begin{split}E_{lw} = g^{-1}\left(\frac{1}{\Delta E}\int_{E_1}^{E_2}{g(E) dE}\right)\end{split}\notag
\end{gather}
For instances where a power law of spectral index 2 is taken, it can be analytically shown that the Lafferty \& Wyatt method and log center method are
coincident. In the case of steeper power laws (e.g. spectral index 3), the Lafferty \& Wyatt method
returns a lower coordinate on the energy axis than the log bin center, and the reverse effect is seen for less steep power laws (e.g. spectral index 1).
\subsubsection{Power Law Assumption}
\label{tutorials/flux_point/index:power-law-assumption}
In many ``real world'' examples, the nature of the true underlying spectrum is unknown and can only be estimated, either by using a
fitting algorithm with data points or by assuming a certain spectral form. In this example, the true spectrum (being a piecewise power law
function of spectral indices 1 through to 5 for bins of increasing energy) is shown in blue for illustration. This would be
unknown to the user who, in this example, assumes the spectrum follows a simple power law with spectral index 4 across all energies.
The plot demonstrates that in these cases where the true spectrum is not known, the Lafferty \& Wyatt method of positioning the data
points offers a closer representation than the log center method. Residuals showing the percentage difference of each data point from the true
spectrum are also shown.
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}Spectral plotting with gammapy.spectrum.flux\PYGZus{}point}
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}}
\PYG{k+kn}{import} \PYG{n+nn}{numpy} \PYG{k+kn}{as} \PYG{n+nn}{np}
\PYG{k+kn}{import} \PYG{n+nn}{matplotlib.pyplot} \PYG{k+kn}{as} \PYG{n+nn}{plt}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.table} \PYG{k+kn}{import} \PYG{n}{Table}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.spectrum.flux\PYGZus{}point} \PYG{k+kn}{import} \PYG{p}{(}\PYG{n}{compute\PYGZus{}differential\PYGZus{}flux\PYGZus{}points}\PYG{p}{,}
\PYG{n}{\PYGZus{}x\PYGZus{}lafferty}\PYG{p}{,} \PYG{n}{\PYGZus{}integrate}\PYG{p}{)}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.spectrum.powerlaw} \PYG{k+kn}{import} \PYG{n}{power\PYGZus{}law\PYGZus{}integral\PYGZus{}flux}
\PYG{n}{SPECTRAL\PYGZus{}INDEX} \PYG{o}{=} \PYG{l+m+mi}{4}
\PYG{k}{def} \PYG{n+nf}{my\PYGZus{}spectrum}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}\PYG{p}{:}
\PYG{n}{E\PYGZus{}1} \PYG{o}{=} \PYG{l+m+mi}{1}
\PYG{n}{E\PYGZus{}2} \PYG{o}{=} \PYG{l+m+mi}{10}
\PYG{n}{E\PYGZus{}3} \PYG{o}{=} \PYG{l+m+mi}{100}
\PYG{n}{E\PYGZus{}4} \PYG{o}{=} \PYG{l+m+mi}{1000}
\PYG{n}{E\PYGZus{}5} \PYG{o}{=} \PYG{l+m+mi}{10000}
\PYG{n}{g1} \PYG{o}{=} \PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{1}
\PYG{n}{g2} \PYG{o}{=} \PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{2}
\PYG{n}{g3} \PYG{o}{=} \PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{3}
\PYG{n}{g4} \PYG{o}{=} \PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{4}
\PYG{n}{g5} \PYG{o}{=} \PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{5}
\PYG{n}{im} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{select}\PYG{p}{(}\PYG{p}{[}\PYG{n}{x} \PYG{o}{\PYGZlt{}}\PYG{o}{=} \PYG{n}{E\PYGZus{}1}\PYG{p}{,} \PYG{n}{x} \PYG{o}{\PYGZlt{}}\PYG{o}{=} \PYG{n}{E\PYGZus{}2}\PYG{p}{,} \PYG{n}{x} \PYG{o}{\PYGZlt{}}\PYG{o}{=} \PYG{n}{E\PYGZus{}3}\PYG{p}{,} \PYG{n}{x} \PYG{o}{\PYGZlt{}}\PYG{o}{=} \PYG{n}{E\PYGZus{}4}\PYG{p}{,} \PYG{n}{x} \PYG{o}{\PYGZlt{}}\PYG{o}{=} \PYG{n}{E\PYGZus{}5}\PYG{p}{,} \PYG{n}{x} \PYG{o}{\PYGZgt{}} \PYG{n}{E\PYGZus{}5}\PYG{p}{]}\PYG{p}{,}
\PYG{p}{[}\PYG{p}{(}\PYG{n}{x} \PYG{o}{/} \PYG{n}{E\PYGZus{}1}\PYG{p}{)} \PYG{o}{*}\PYG{o}{*} \PYG{n}{g1}\PYG{p}{,} \PYG{l+m+mf}{1e\PYGZhy{}2} \PYG{o}{*} \PYG{p}{(}\PYG{n}{x} \PYG{o}{/} \PYG{n}{E\PYGZus{}2}\PYG{p}{)} \PYG{o}{*}\PYG{o}{*} \PYG{n}{g2}\PYG{p}{,}
\PYG{l+m+mf}{1e\PYGZhy{}5} \PYG{o}{*} \PYG{p}{(}\PYG{n}{x} \PYG{o}{/} \PYG{n}{E\PYGZus{}3}\PYG{p}{)} \PYG{o}{*}\PYG{o}{*} \PYG{n}{g3}\PYG{p}{,} \PYG{l+m+mf}{1e\PYGZhy{}9} \PYG{o}{*} \PYG{p}{(}\PYG{n}{x} \PYG{o}{/} \PYG{n}{E\PYGZus{}4}\PYG{p}{)} \PYG{o}{*}\PYG{o}{*} \PYG{n}{g4}\PYG{p}{,}
\PYG{l+m+mf}{1e\PYGZhy{}14} \PYG{o}{*} \PYG{p}{(}\PYG{n}{x} \PYG{o}{/} \PYG{n}{E\PYGZus{}5}\PYG{p}{)} \PYG{o}{*}\PYG{o}{*} \PYG{n}{g5}\PYG{p}{,} \PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{)}
\PYG{k}{return} \PYG{n}{im}
\PYG{k}{def} \PYG{n+nf}{get\PYGZus{}flux\PYGZus{}tables}\PYG{p}{(}\PYG{n}{table}\PYG{p}{,} \PYG{n}{y\PYGZus{}method}\PYG{p}{,} \PYG{n}{function}\PYG{p}{,} \PYG{n}{spectral\PYGZus{}index}\PYG{p}{)}\PYG{p}{:}
\PYG{n}{table1} \PYG{o}{=} \PYG{n}{table}\PYG{o}{.}\PYG{n}{copy}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{lafferty\PYGZus{}flux} \PYG{o}{=} \PYG{n}{compute\PYGZus{}differential\PYGZus{}flux\PYGZus{}points}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{lafferty}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{y\PYGZus{}method}\PYG{p}{,} \PYG{n}{table1}\PYG{p}{,}
\PYG{n}{function}\PYG{p}{,} \PYG{n}{spectral\PYGZus{}index}\PYG{p}{)}
\PYG{n}{table2} \PYG{o}{=} \PYG{n}{table1}\PYG{o}{.}\PYG{n}{copy}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{log\PYGZus{}flux} \PYG{o}{=} \PYG{n}{compute\PYGZus{}differential\PYGZus{}flux\PYGZus{}points}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{log\PYGZus{}center}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{y\PYGZus{}method}\PYG{p}{,} \PYG{n}{table2}\PYG{p}{,}
\PYG{n}{function}\PYG{p}{,} \PYG{n}{spectral\PYGZus{}index}\PYG{p}{)}
\PYG{k}{return} \PYG{n}{lafferty\PYGZus{}flux}\PYG{p}{,} \PYG{n}{log\PYGZus{}flux}
\PYG{k}{def} \PYG{n+nf}{plot\PYGZus{}flux\PYGZus{}points}\PYG{p}{(}\PYG{n}{table}\PYG{p}{,} \PYG{n}{x}\PYG{p}{,} \PYG{n}{y}\PYG{p}{,} \PYG{n}{function}\PYG{p}{,} \PYG{n}{energy\PYGZus{}min}\PYG{p}{,} \PYG{n}{y\PYGZus{}method}\PYG{p}{)}\PYG{p}{:}
\PYG{n}{f}\PYG{p}{,} \PYG{n}{ax} \PYG{o}{=} \PYG{n}{plt}\PYG{o}{.}\PYG{n}{subplots}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{p}{,} \PYG{n}{sharex}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{)}
\PYG{n}{lafferty\PYGZus{}flux}\PYG{p}{,} \PYG{n}{log\PYGZus{}flux} \PYG{o}{=} \PYG{n}{get\PYGZus{}flux\PYGZus{}tables}\PYG{p}{(}\PYG{n}{table}\PYG{p}{,} \PYG{n}{y\PYGZus{}method}\PYG{p}{,} \PYG{n}{function}\PYG{p}{,}
\PYG{n}{SPECTRAL\PYGZus{}INDEX}\PYG{p}{)}
\PYG{n}{ax}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{o}{.}\PYG{n}{loglog}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,} \PYG{p}{(}\PYG{n}{x} \PYG{o}{*}\PYG{o}{*} \PYG{l+m+mi}{2}\PYG{p}{)} \PYG{o}{*} \PYG{n}{y}\PYG{p}{)}
\PYG{n}{ax}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{o}{.}\PYG{n}{loglog}\PYG{p}{(}\PYG{n}{lafferty\PYGZus{}flux}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ENERGY}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{,}
\PYG{p}{(}\PYG{p}{(}\PYG{n}{lafferty\PYGZus{}flux}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ENERGY}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]} \PYG{o}{*}\PYG{o}{*} \PYG{l+m+mi}{2}\PYG{p}{)} \PYG{o}{*} \PYG{n}{lafferty\PYGZus{}flux}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{DIFF\PYGZus{}FLUX}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{)}\PYG{p}{,}
\PYG{n}{marker}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{D}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{color}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{k}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{linewidth}\PYG{o}{=}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{n}{ms}\PYG{o}{=}\PYG{l+m+mi}{5}\PYG{p}{,}
\PYG{n}{label}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Lafferty Method}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{residuals\PYGZus{}lafferty} \PYG{o}{=} \PYG{p}{(}\PYG{n}{lafferty\PYGZus{}flux}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{DIFF\PYGZus{}FLUX}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}
\PYG{o}{\PYGZhy{}} \PYG{n}{function}\PYG{p}{(}\PYG{n}{lafferty\PYGZus{}flux}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ENERGY}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{)}\PYG{p}{)} \PYG{o}{/} \PYG{n}{function}\PYG{p}{(}\PYG{n}{lafferty\PYGZus{}flux}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ENERGY}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{)} \PYG{o}{*} \PYG{l+m+mi}{100}
\PYG{n}{ax}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{o}{.}\PYG{n}{loglog}\PYG{p}{(}\PYG{n}{log\PYGZus{}flux}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ENERGY}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{,}
\PYG{p}{(}\PYG{n}{log\PYGZus{}flux}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ENERGY}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]} \PYG{o}{*}\PYG{o}{*} \PYG{l+m+mi}{2}\PYG{p}{)} \PYG{o}{*} \PYG{n}{log\PYGZus{}flux}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{DIFF\PYGZus{}FLUX}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{,}
\PYG{n}{marker}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{D}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{color}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{r}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{linewidth}\PYG{o}{=}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{n}{ms}\PYG{o}{=}\PYG{l+m+mi}{5}\PYG{p}{,}
\PYG{n}{label}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Log Center Method}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{ax}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{o}{.}\PYG{n}{legend}\PYG{p}{(}\PYG{n}{loc}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{lower left}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{fontsize}\PYG{o}{=}\PYG{l+m+mi}{10}\PYG{p}{)}
\PYG{n}{residuals\PYGZus{}log} \PYG{o}{=} \PYG{p}{(}\PYG{n}{log\PYGZus{}flux}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{DIFF\PYGZus{}FLUX}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]} \PYG{o}{\PYGZhy{}}
\PYG{n}{function}\PYG{p}{(}\PYG{n}{log\PYGZus{}flux}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ENERGY}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{)}\PYG{p}{)} \PYG{o}{/} \PYG{n}{function}\PYG{p}{(}\PYG{n}{log\PYGZus{}flux}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ENERGY}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{)} \PYG{o}{*} \PYG{l+m+mi}{100}
\PYG{n}{ax}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{o}{.}\PYG{n}{semilogx}\PYG{p}{(}\PYG{n}{lafferty\PYGZus{}flux}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ENERGY}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{,} \PYG{n}{residuals\PYGZus{}lafferty}\PYG{p}{,} \PYG{n}{marker}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{D}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,}
\PYG{n}{color}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{k}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{linewidth}\PYG{o}{=}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{n}{ms}\PYG{o}{=}\PYG{l+m+mi}{5}\PYG{p}{)}
\PYG{n}{ax}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{o}{.}\PYG{n}{semilogx}\PYG{p}{(}\PYG{n}{log\PYGZus{}flux}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ENERGY}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{,} \PYG{n}{residuals\PYGZus{}log}\PYG{p}{,} \PYG{n}{marker}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{D}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,}
\PYG{n}{color}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{r}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{linewidth}\PYG{o}{=}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{n}{ms}\PYG{o}{=}\PYG{l+m+mi}{5}\PYG{p}{)}
\PYG{n}{indices} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{arange}\PYG{p}{(}\PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{energy\PYGZus{}min}\PYG{p}{)}\PYG{p}{)}
\PYG{k}{for} \PYG{n}{index} \PYG{o+ow}{in} \PYG{n}{indices}\PYG{p}{:}
\PYG{n}{ax}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{o}{.}\PYG{n}{axvline}\PYG{p}{(}\PYG{n}{energy\PYGZus{}min}\PYG{p}{[}\PYG{n}{index}\PYG{p}{]}\PYG{p}{,} \PYG{l+m+mi}{0}\PYG{p}{,} \PYG{l+m+mf}{1e6}\PYG{p}{,} \PYG{n}{color}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{k}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,}
\PYG{n}{linestyle}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{:}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{ax}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{o}{.}\PYG{n}{axvline}\PYG{p}{(}\PYG{n}{energy\PYGZus{}min}\PYG{p}{[}\PYG{n}{index}\PYG{p}{]}\PYG{p}{,} \PYG{l+m+mi}{0}\PYG{p}{,} \PYG{l+m+mf}{1e6}\PYG{p}{,} \PYG{n}{color}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{k}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,}
\PYG{n}{linestyle}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{:}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{ax}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{o}{.}\PYG{n}{axhline}\PYG{p}{(}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{l+m+mi}{0}\PYG{p}{,} \PYG{l+m+mi}{10}\PYG{p}{,} \PYG{n}{color}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{k}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{ax}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{o}{.}\PYG{n}{set\PYGZus{}ylabel}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{E\PYGZca{}2 * Differential Flux}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{ax}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{o}{.}\PYG{n}{set\PYGZus{}ylabel}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Residuals/}\PYG{l+s}{\PYGZpc{}}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{ax}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{o}{.}\PYG{n}{set\PYGZus{}xlabel}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Energy}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{ax}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{o}{.}\PYG{n}{set\PYGZus{}xlim}\PYG{p}{(}\PYG{p}{[}\PYG{l+m+mf}{0.1}\PYG{p}{,} \PYG{l+m+mi}{10000}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{ax}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{o}{.}\PYG{n}{set\PYGZus{}ylim}\PYG{p}{(}\PYG{p}{[}\PYG{l+m+mf}{1e\PYGZhy{}6}\PYG{p}{,} \PYG{l+m+mf}{1e1}\PYG{p}{]}\PYG{p}{)}
\PYG{k}{return} \PYG{n}{f}
\PYG{k}{def} \PYG{n+nf}{plot\PYGZus{}power\PYGZus{}law}\PYG{p}{(}\PYG{p}{)}\PYG{p}{:}
\PYG{c}{\PYGZsh{} Define the function}
\PYG{n}{x} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{arange}\PYG{p}{(}\PYG{l+m+mf}{0.1}\PYG{p}{,} \PYG{l+m+mi}{100000}\PYG{p}{,} \PYG{l+m+mf}{0.1}\PYG{p}{)}
\PYG{n}{spectral\PYGZus{}model} \PYG{o}{=} \PYG{n}{my\PYGZus{}spectrum}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}
\PYG{n}{spectral\PYGZus{}model\PYGZus{}function} \PYG{o}{=} \PYG{k}{lambda} \PYG{n}{x}\PYG{p}{:} \PYG{n}{my\PYGZus{}spectrum}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}
\PYG{n}{y} \PYG{o}{=} \PYG{n}{spectral\PYGZus{}model}
\PYG{c}{\PYGZsh{} Set the x\PYGZhy{}bins}
\PYG{n}{energy\PYGZus{}min} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mf}{0.1}\PYG{p}{,} \PYG{l+m+mi}{1}\PYG{p}{,} \PYG{l+m+mi}{10}\PYG{p}{,} \PYG{l+m+mi}{100}\PYG{p}{,} \PYG{l+m+mi}{1000}\PYG{p}{]}
\PYG{n}{energy\PYGZus{}max} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{l+m+mi}{10}\PYG{p}{,} \PYG{l+m+mi}{100}\PYG{p}{,} \PYG{l+m+mi}{1000}\PYG{p}{,} \PYG{l+m+mi}{10000}\PYG{p}{]}
\PYG{n}{energies} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{array}\PYG{p}{(}\PYG{n}{\PYGZus{}x\PYGZus{}lafferty}\PYG{p}{(}\PYG{n}{energy\PYGZus{}min}\PYG{p}{,} \PYG{n}{energy\PYGZus{}max}\PYG{p}{,}
\PYG{n}{spectral\PYGZus{}model\PYGZus{}function}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{diff\PYGZus{}fluxes} \PYG{o}{=} \PYG{n}{spectral\PYGZus{}model\PYGZus{}function}\PYG{p}{(}\PYG{n}{energies}\PYG{p}{)}
\PYG{n}{indices} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{array}\PYG{p}{(}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{l+m+mi}{1}\PYG{p}{,} \PYG{l+m+mi}{2}\PYG{p}{,} \PYG{l+m+mi}{3}\PYG{p}{,} \PYG{l+m+mi}{4}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{int\PYGZus{}flux} \PYG{o}{=} \PYG{n}{power\PYGZus{}law\PYGZus{}integral\PYGZus{}flux}\PYG{p}{(}\PYG{n}{diff\PYGZus{}fluxes}\PYG{p}{,} \PYG{p}{(}\PYG{n}{indices} \PYG{o}{+} \PYG{l+m+mi}{1}\PYG{p}{)}\PYG{p}{,}
\PYG{n}{energies}\PYG{p}{,} \PYG{n}{energy\PYGZus{}min}\PYG{p}{,} \PYG{n}{energy\PYGZus{}max}\PYG{p}{)}
\PYG{n}{special} \PYG{o}{=} \PYG{k}{lambda} \PYG{n}{x}\PYG{p}{:} \PYG{n}{np}\PYG{o}{.}\PYG{n}{log}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}
\PYG{n}{int\PYGZus{}flux}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{abs}\PYG{p}{(}\PYG{n}{\PYGZus{}integrate}\PYG{p}{(}\PYG{p}{[}\PYG{n}{energy\PYGZus{}min}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,}
\PYG{p}{[}\PYG{n}{energy\PYGZus{}max}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{]}\PYG{p}{,} \PYG{n}{special}\PYG{p}{)}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Put data into table}
\PYG{n}{table} \PYG{o}{=} \PYG{n}{Table}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{table}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ENERGY\PYGZus{}MIN}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]} \PYG{o}{=} \PYG{n}{energy\PYGZus{}min}
\PYG{n}{table}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ENERGY\PYGZus{}MAX}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]} \PYG{o}{=} \PYG{n}{energy\PYGZus{}max}
\PYG{n}{table}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{INT\PYGZus{}FLUX}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]} \PYG{o}{=} \PYG{n}{int\PYGZus{}flux}
\PYG{n}{plot\PYGZus{}flux\PYGZus{}points}\PYG{p}{(}\PYG{n}{table}\PYG{p}{,} \PYG{n}{x}\PYG{p}{,} \PYG{n}{y}\PYG{p}{,} \PYG{n}{spectral\PYGZus{}model\PYGZus{}function}\PYG{p}{,}
\PYG{n}{energy\PYGZus{}min}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{power\PYGZus{}law}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{legend}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}
\includegraphics{flux_point_demo.pdf}
\subsubsection{Method Evaluation}
\label{tutorials/flux_point/index:method-evaluation}
The dependence of the positioning of the x coordinate of the flux point with assumed spectral index is demonstrated below.
As before, the underlying spectrum is a simple power law of index 4. The position is given as the fraction of the size of
the bin in Log Energy, for instance the Log Center method always positions the flux point at the center of the bin for a
Log Energy scale, and so the position is 0.5. The coincidence of the two methods for the power law case of index 2 is evident,
with the Lafferty method positioning the flux point to the right of the Log Center position for power law spectra of index
less than 2, and to the left for index greater than 2.
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}Plot of x position depending on spectral index estimation}
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}}
\PYG{k+kn}{import} \PYG{n+nn}{numpy} \PYG{k+kn}{as} \PYG{n+nn}{np}
\PYG{k+kn}{import} \PYG{n+nn}{matplotlib.pyplot} \PYG{k+kn}{as} \PYG{n+nn}{plt}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.table} \PYG{k+kn}{import} \PYG{n}{Table}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.spectrum.flux\PYGZus{}point} \PYG{k+kn}{import} \PYG{n}{\PYGZus{}energy\PYGZus{}lafferty\PYGZus{}power\PYGZus{}law}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.spectrum.powerlaw} \PYG{k+kn}{import} \PYG{n}{power\PYGZus{}law\PYGZus{}evaluate}\PYG{p}{,} \PYG{n}{power\PYGZus{}law\PYGZus{}integral\PYGZus{}flux}
\PYG{k+kn}{from} \PYG{n+nn}{flux\PYGZus{}point\PYGZus{}demo} \PYG{k+kn}{import} \PYG{n}{get\PYGZus{}flux\PYGZus{}tables}
\PYG{n}{SPECTRAL\PYGZus{}INDEX} \PYG{o}{=} \PYG{l+m+mi}{4}
\PYG{k}{def} \PYG{n+nf}{make\PYGZus{}x\PYGZus{}plot}\PYG{p}{(}\PYG{p}{)}\PYG{p}{:}
\PYG{n}{energy\PYGZus{}min} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{array}\PYG{p}{(}\PYG{p}{[}\PYG{l+m+mi}{300}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{energy\PYGZus{}max} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{array}\PYG{p}{(}\PYG{p}{[}\PYG{l+m+mi}{1000}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{energies} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{array}\PYG{p}{(}\PYG{n}{\PYGZus{}energy\PYGZus{}lafferty\PYGZus{}power\PYGZus{}law}\PYG{p}{(}\PYG{n}{energy\PYGZus{}min}\PYG{p}{,} \PYG{n}{energy\PYGZus{}max}\PYG{p}{,}
\PYG{n}{SPECTRAL\PYGZus{}INDEX}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{diff\PYGZus{}flux} \PYG{o}{=} \PYG{n}{power\PYGZus{}law\PYGZus{}evaluate}\PYG{p}{(}\PYG{n}{energies}\PYG{p}{,} \PYG{l+m+mi}{1}\PYG{p}{,} \PYG{n}{SPECTRAL\PYGZus{}INDEX}\PYG{p}{,} \PYG{l+m+mi}{1}\PYG{p}{)}
\PYG{c}{\PYGZsh{} {}`True\PYGZsq{} differential \PYGZam{} integral fluxes}
\PYG{n}{int\PYGZus{}flux} \PYG{o}{=} \PYG{n}{power\PYGZus{}law\PYGZus{}integral\PYGZus{}flux}\PYG{p}{(}\PYG{n}{diff\PYGZus{}flux}\PYG{p}{,} \PYG{n}{SPECTRAL\PYGZus{}INDEX}\PYG{p}{,}
\PYG{n}{energies}\PYG{p}{,} \PYG{n}{energy\PYGZus{}min}\PYG{p}{,} \PYG{n}{energy\PYGZus{}max}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Put data into table}
\PYG{n}{table} \PYG{o}{=} \PYG{n}{Table}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{table}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ENERGY\PYGZus{}MIN}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]} \PYG{o}{=} \PYG{n}{energy\PYGZus{}min}
\PYG{n}{table}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ENERGY\PYGZus{}MAX}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]} \PYG{o}{=} \PYG{n}{energy\PYGZus{}max}
\PYG{n}{table}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{INT\PYGZus{}FLUX}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]} \PYG{o}{=} \PYG{n}{int\PYGZus{}flux}
\PYG{n}{lafferty\PYGZus{}array} \PYG{o}{=} \PYG{p}{[}\PYG{p}{]}
\PYG{n}{log\PYGZus{}array} \PYG{o}{=} \PYG{p}{[}\PYG{p}{]}
\PYG{n}{spectral\PYGZus{}indices} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{arange}\PYG{p}{(}\PYG{l+m+mf}{1.1}\PYG{p}{,} \PYG{l+m+mi}{6}\PYG{p}{,} \PYG{l+m+mf}{0.01}\PYG{p}{)}
\PYG{k}{for} \PYG{n}{spectral\PYGZus{}index} \PYG{o+ow}{in} \PYG{n}{spectral\PYGZus{}indices}\PYG{p}{:}
\PYG{n}{lafferty\PYGZus{}flux}\PYG{p}{,} \PYG{n}{log\PYGZus{}flux} \PYG{o}{=} \PYG{n}{get\PYGZus{}flux\PYGZus{}tables}\PYG{p}{(}\PYG{n}{table}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{power\PYGZus{}law}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n+nb+bp}{None}\PYG{p}{,}
\PYG{n}{spectral\PYGZus{}index}\PYG{p}{)}
\PYG{n}{residuals\PYGZus{}lafferty} \PYG{o}{=} \PYG{p}{(}\PYG{p}{(}\PYG{n}{np}\PYG{o}{.}\PYG{n}{log}\PYG{p}{(}\PYG{n}{lafferty\PYGZus{}flux}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ENERGY}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{)}
\PYG{o}{\PYGZhy{}} \PYG{n}{np}\PYG{o}{.}\PYG{n}{log}\PYG{p}{(}\PYG{n}{energy\PYGZus{}min}\PYG{p}{)}\PYG{p}{)} \PYG{o}{/} \PYG{p}{(}\PYG{n}{np}\PYG{o}{.}\PYG{n}{log}\PYG{p}{(}\PYG{n}{energy\PYGZus{}max}\PYG{p}{)}\PYG{o}{\PYGZhy{}}\PYG{n}{np}\PYG{o}{.}\PYG{n}{log}\PYG{p}{(}\PYG{n}{energy\PYGZus{}min}\PYG{p}{)}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{residuals\PYGZus{}log} \PYG{o}{=} \PYG{p}{(}\PYG{p}{(}\PYG{n}{np}\PYG{o}{.}\PYG{n}{log}\PYG{p}{(}\PYG{n}{log\PYGZus{}flux}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ENERGY}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{)}
\PYG{o}{\PYGZhy{}} \PYG{n}{np}\PYG{o}{.}\PYG{n}{log}\PYG{p}{(}\PYG{n}{energy\PYGZus{}min}\PYG{p}{)}\PYG{p}{)} \PYG{o}{/} \PYG{p}{(}\PYG{n}{np}\PYG{o}{.}\PYG{n}{log}\PYG{p}{(}\PYG{n}{energy\PYGZus{}max}\PYG{p}{)}\PYG{o}{\PYGZhy{}}\PYG{n}{np}\PYG{o}{.}\PYG{n}{log}\PYG{p}{(}\PYG{n}{energy\PYGZus{}min}\PYG{p}{)}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{lafferty\PYGZus{}array}\PYG{o}{.}\PYG{n}{append}\PYG{p}{(}\PYG{n}{residuals\PYGZus{}lafferty}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{log\PYGZus{}array}\PYG{o}{.}\PYG{n}{append}\PYG{p}{(}\PYG{n}{residuals\PYGZus{}log}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{plot}\PYG{p}{(}\PYG{n}{spectral\PYGZus{}indices}\PYG{p}{,} \PYG{n}{lafferty\PYGZus{}array}\PYG{p}{,} \PYG{n}{color}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{k}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,}
\PYG{n}{linewidth}\PYG{o}{=}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{n}{ms}\PYG{o}{=}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{n}{label}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Lafferty Method}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{plot}\PYG{p}{(}\PYG{n}{spectral\PYGZus{}indices}\PYG{p}{,} \PYG{n}{log\PYGZus{}array}\PYG{p}{,} \PYG{n}{color}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{r}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,}
\PYG{n}{linewidth}\PYG{o}{=}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{n}{ms}\PYG{o}{=}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{n}{label}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Log Center Method}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{legend}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{ylabel}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{X position in bin}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{xlabel}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Guessed spectral Index}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\end{Verbatim}
\includegraphics{x_position_plot.pdf}
The ability of the two methods to represent an underlying spectrum is demonstrated in the residual images below. Here,
flux points are positioned using the Lafferty method (left image) and Log Center method (central image) for different
`true' and `assumed' power law spectral indices. Residuals are determined as the difference between the reconstructed flux
compared to the true flux of the underlying spectrum. The closer the residual value is to zero (white), the better the
representation offered.
The residuals log ratio image (right) shows the log ratio of residuals of the Lafferty method to those of the Log Center method,
indicating the regions of assumed/true parameter space for which the Lafferty method offers an improved representation
of the underlying frequency over the Log Center method (blue regions), and where it does not (red regions).
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}Create residuals image based on the two flux point methods}
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}}
\PYG{k+kn}{import} \PYG{n+nn}{numpy} \PYG{k+kn}{as} \PYG{n+nn}{np}
\PYG{k+kn}{import} \PYG{n+nn}{matplotlib.pyplot} \PYG{k+kn}{as} \PYG{n+nn}{plt}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.spectrum.flux\PYGZus{}point} \PYG{k+kn}{import} \PYG{n}{compute\PYGZus{}differential\PYGZus{}flux\PYGZus{}points}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.spectrum.powerlaw} \PYG{k+kn}{import} \PYG{n}{power\PYGZus{}law\PYGZus{}evaluate}\PYG{p}{,} \PYG{n}{power\PYGZus{}law\PYGZus{}integral\PYGZus{}flux}
\PYG{k}{def} \PYG{n+nf}{compute\PYGZus{}flux\PYGZus{}error}\PYG{p}{(}\PYG{n}{gamma\PYGZus{}true}\PYG{p}{,} \PYG{n}{gamma\PYGZus{}reco}\PYG{p}{,} \PYG{n}{method}\PYG{p}{)}\PYG{p}{:}
\PYG{c}{\PYGZsh{} Let\PYGZsq{}s assume a concrete true spectrum and energy bin.}
\PYG{c}{\PYGZsh{} Note that the residuals computed below do *not* depend on}
\PYG{c}{\PYGZsh{} these parameters.}
\PYG{n}{energy\PYGZus{}min}\PYG{p}{,} \PYG{n}{energy\PYGZus{}max} \PYG{o}{=} \PYG{l+m+mi}{1}\PYG{p}{,} \PYG{l+m+mi}{10}
\PYG{n}{energy\PYGZus{}ref}\PYG{p}{,} \PYG{n}{diff\PYGZus{}flux\PYGZus{}ref} \PYG{o}{=} \PYG{l+m+mi}{1}\PYG{p}{,} \PYG{l+m+mi}{1}
\PYG{c}{\PYGZsh{} Compute integral flux in the energy band assuming {}`gamma\PYGZus{}true{}`}
\PYG{n}{int\PYGZus{}flux} \PYG{o}{=} \PYG{n}{power\PYGZus{}law\PYGZus{}integral\PYGZus{}flux}\PYG{p}{(}\PYG{n}{diff\PYGZus{}flux\PYGZus{}ref}\PYG{p}{,} \PYG{n}{gamma\PYGZus{}true}\PYG{p}{,}
\PYG{n}{energy\PYGZus{}ref}\PYG{p}{,} \PYG{n}{energy\PYGZus{}min}\PYG{p}{,} \PYG{n}{energy\PYGZus{}max}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Compute flux point}
\PYG{n}{table} \PYG{o}{=} \PYG{n}{compute\PYGZus{}differential\PYGZus{}flux\PYGZus{}points}\PYG{p}{(}\PYG{n}{method}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{power\PYGZus{}law}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,}
\PYG{n}{spectral\PYGZus{}index}\PYG{o}{=}\PYG{n}{gamma\PYGZus{}reco}\PYG{p}{,}
\PYG{n}{energy\PYGZus{}min}\PYG{o}{=}\PYG{n}{energy\PYGZus{}min}\PYG{p}{,} \PYG{n}{energy\PYGZus{}max}\PYG{o}{=}\PYG{n}{energy\PYGZus{}max}\PYG{p}{,}
\PYG{n}{int\PYGZus{}flux}\PYG{o}{=}\PYG{n}{int\PYGZus{}flux}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Compute relative error of the flux point}
\PYG{n}{energy} \PYG{o}{=} \PYG{n}{table}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ENERGY}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{o}{.}\PYG{n}{data}
\PYG{n}{flux\PYGZus{}reco} \PYG{o}{=} \PYG{n}{table}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{DIFF\PYGZus{}FLUX}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{o}{.}\PYG{n}{data}
\PYG{n}{flux\PYGZus{}true} \PYG{o}{=} \PYG{n}{power\PYGZus{}law\PYGZus{}evaluate}\PYG{p}{(}\PYG{n}{energy}\PYG{p}{,} \PYG{n}{diff\PYGZus{}flux\PYGZus{}ref} \PYG{o}{*} \PYG{n}{np}\PYG{o}{.}\PYG{n}{ones\PYGZus{}like}\PYG{p}{(}\PYG{n}{energy}\PYG{p}{)}\PYG{p}{,}
\PYG{n}{np}\PYG{o}{.}\PYG{n}{array}\PYG{p}{(}\PYG{n}{gamma\PYGZus{}true}\PYG{p}{)}\PYG{o}{.}\PYG{n}{reshape}\PYG{p}{(}\PYG{n}{energy}\PYG{o}{.}\PYG{n}{shape}\PYG{p}{)}\PYG{p}{,}
\PYG{n}{energy\PYGZus{}ref} \PYG{o}{*} \PYG{n}{np}\PYG{o}{.}\PYG{n}{ones\PYGZus{}like}\PYG{p}{(}\PYG{n}{energy}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{flux\PYGZus{}true} \PYG{o}{=} \PYG{n}{flux\PYGZus{}true}\PYG{o}{.}\PYG{n}{reshape}\PYG{p}{(}\PYG{n}{gamma\PYGZus{}true}\PYG{o}{.}\PYG{n}{shape}\PYG{p}{)}
\PYG{n}{flux\PYGZus{}reco} \PYG{o}{=} \PYG{n}{flux\PYGZus{}reco}\PYG{o}{.}\PYG{n}{reshape}\PYG{p}{(}\PYG{n}{gamma\PYGZus{}true}\PYG{o}{.}\PYG{n}{shape}\PYG{p}{)}
\PYG{n}{flux\PYGZus{}error} \PYG{o}{=} \PYG{p}{(}\PYG{n}{flux\PYGZus{}reco} \PYG{o}{\PYGZhy{}} \PYG{n}{flux\PYGZus{}true}\PYG{p}{)} \PYG{o}{/} \PYG{n}{flux\PYGZus{}true}
\PYG{k}{return} \PYG{n}{flux\PYGZus{}error}
\PYG{k}{def} \PYG{n+nf}{residuals\PYGZus{}image}\PYG{p}{(}\PYG{p}{)}\PYG{p}{:}
\PYG{n}{gamma\PYGZus{}true} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{arange}\PYG{p}{(}\PYG{l+m+mf}{1.01}\PYG{p}{,} \PYG{l+m+mi}{7}\PYG{p}{,} \PYG{l+m+mi}{1}\PYG{p}{)}
\PYG{n}{gamma\PYGZus{}reco} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{arange}\PYG{p}{(}\PYG{l+m+mf}{1.01}\PYG{p}{,} \PYG{l+m+mi}{7}\PYG{p}{,} \PYG{l+m+mi}{1}\PYG{p}{)}
\PYG{n}{gamma\PYGZus{}true}\PYG{p}{,} \PYG{n}{gamma\PYGZus{}reco} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{meshgrid}\PYG{p}{(}\PYG{n}{gamma\PYGZus{}true}\PYG{p}{,} \PYG{n}{gamma\PYGZus{}reco}\PYG{p}{)}
\PYG{n}{flux\PYGZus{}error\PYGZus{}lafferty} \PYG{o}{=} \PYG{n}{compute\PYGZus{}flux\PYGZus{}error}\PYG{p}{(}\PYG{n}{gamma\PYGZus{}true}\PYG{p}{,} \PYG{n}{gamma\PYGZus{}reco}\PYG{p}{,}
\PYG{n}{method}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{lafferty}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{flux\PYGZus{}error\PYGZus{}log\PYGZus{}center} \PYG{o}{=} \PYG{n}{compute\PYGZus{}flux\PYGZus{}error}\PYG{p}{(}\PYG{n}{gamma\PYGZus{}true}\PYG{p}{,} \PYG{n}{gamma\PYGZus{}reco}\PYG{p}{,}
\PYG{n}{method}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{log\PYGZus{}center}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{flux\PYGZus{}error\PYGZus{}ratio} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{log10}\PYG{p}{(}\PYG{n}{flux\PYGZus{}error\PYGZus{}lafferty} \PYG{o}{/} \PYG{n}{flux\PYGZus{}error\PYGZus{}log\PYGZus{}center}\PYG{p}{)}
\PYG{n}{extent} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mf}{0.5}\PYG{p}{,} \PYG{l+m+mf}{6.5}\PYG{p}{,} \PYG{l+m+mf}{0.5}\PYG{p}{,} \PYG{l+m+mf}{6.5}\PYG{p}{]}
\PYG{n}{vmin}\PYG{p}{,} \PYG{n}{vmax} \PYG{o}{=} \PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{3}\PYG{p}{,} \PYG{l+m+mi}{3}
\PYG{n}{fig}\PYG{p}{,} \PYG{n}{axes} \PYG{o}{=} \PYG{n}{plt}\PYG{o}{.}\PYG{n}{subplots}\PYG{p}{(}\PYG{n}{nrows}\PYG{o}{=}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{n}{ncols}\PYG{o}{=}\PYG{l+m+mi}{3}\PYG{p}{)}
\PYG{n}{im} \PYG{o}{=} \PYG{n}{axes}\PYG{o}{.}\PYG{n}{flat}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{o}{.}\PYG{n}{imshow}\PYG{p}{(}\PYG{n}{np}\PYG{o}{.}\PYG{n}{array}\PYG{p}{(}\PYG{n}{flux\PYGZus{}error\PYGZus{}lafferty}\PYG{p}{)}\PYG{p}{,}
\PYG{n}{interpolation}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{nearest}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{extent}\PYG{o}{=}\PYG{n}{extent}\PYG{p}{,}
\PYG{n}{origin}\PYG{o}{=}\PYG{l+s}{\PYGZdq{}}\PYG{l+s}{lower}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{vmin}\PYG{o}{=}\PYG{n}{vmin}\PYG{p}{,} \PYG{n}{vmax}\PYG{o}{=}\PYG{n}{vmax}\PYG{p}{,}
\PYG{n}{cmap}\PYG{o}{=}\PYG{n}{plt}\PYG{o}{.}\PYG{n}{get\PYGZus{}cmap}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{seismic}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{axes}\PYG{o}{.}\PYG{n}{flat}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{o}{.}\PYG{n}{set\PYGZus{}ylabel}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Assumed Spectral Index}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{fontsize}\PYG{o}{=}\PYG{l+m+mi}{14}\PYG{p}{)}
\PYG{n}{axes}\PYG{o}{.}\PYG{n}{flat}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{o}{.}\PYG{n}{set\PYGZus{}title}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Lafferty Method}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{fontsize}\PYG{o}{=}\PYG{l+m+mi}{12}\PYG{p}{)}
\PYG{n}{im} \PYG{o}{=} \PYG{n}{axes}\PYG{o}{.}\PYG{n}{flat}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{o}{.}\PYG{n}{imshow}\PYG{p}{(}\PYG{n}{np}\PYG{o}{.}\PYG{n}{array}\PYG{p}{(}\PYG{n}{flux\PYGZus{}error\PYGZus{}log\PYGZus{}center}\PYG{p}{)}\PYG{p}{,}
\PYG{n}{interpolation}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{nearest}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{extent}\PYG{o}{=}\PYG{n}{extent}\PYG{p}{,}
\PYG{n}{origin}\PYG{o}{=}\PYG{l+s}{\PYGZdq{}}\PYG{l+s}{lower}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{vmin}\PYG{o}{=}\PYG{n}{vmin}\PYG{p}{,} \PYG{n}{vmax}\PYG{o}{=}\PYG{n}{vmax}\PYG{p}{,}
\PYG{n}{cmap}\PYG{o}{=}\PYG{n}{plt}\PYG{o}{.}\PYG{n}{get\PYGZus{}cmap}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{seismic}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{axes}\PYG{o}{.}\PYG{n}{flat}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{o}{.}\PYG{n}{set\PYGZus{}xlabel}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{True Spectral Index}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{fontsize}\PYG{o}{=}\PYG{l+m+mi}{14}\PYG{p}{)}
\PYG{n}{axes}\PYG{o}{.}\PYG{n}{flat}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{o}{.}\PYG{n}{set\PYGZus{}title}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Log\PYGZhy{}Center Method}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{fontsize}\PYG{o}{=}\PYG{l+m+mi}{12}\PYG{p}{)}
\PYG{n}{im} \PYG{o}{=} \PYG{n}{axes}\PYG{o}{.}\PYG{n}{flat}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{o}{.}\PYG{n}{imshow}\PYG{p}{(}\PYG{n}{np}\PYG{o}{.}\PYG{n}{array}\PYG{p}{(}\PYG{n}{flux\PYGZus{}error\PYGZus{}ratio}\PYG{p}{)}\PYG{p}{,}
\PYG{n}{interpolation}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{nearest}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{extent}\PYG{o}{=}\PYG{n}{extent}\PYG{p}{,}
\PYG{n}{origin}\PYG{o}{=}\PYG{l+s}{\PYGZdq{}}\PYG{l+s}{lower}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,} \PYG{n}{vmin}\PYG{o}{=}\PYG{n}{vmin}\PYG{p}{,} \PYG{n}{vmax}\PYG{o}{=}\PYG{n}{vmax}\PYG{p}{,}
\PYG{n}{cmap}\PYG{o}{=}\PYG{n}{plt}\PYG{o}{.}\PYG{n}{get\PYGZus{}cmap}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{seismic}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{axes}\PYG{o}{.}\PYG{n}{flat}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{o}{.}\PYG{n}{set\PYGZus{}title}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Residual Log Ratio: }\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{ Log(Lafferty/Log Center)}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,}
\PYG{n}{fontsize}\PYG{o}{=}\PYG{l+m+mi}{12}\PYG{p}{)}
\PYG{n}{fig}\PYG{o}{.}\PYG{n}{subplots\PYGZus{}adjust}\PYG{p}{(}\PYG{n}{right}\PYG{o}{=}\PYG{l+m+mf}{0.8}\PYG{p}{)}
\PYG{n}{cbar\PYGZus{}ax} \PYG{o}{=} \PYG{n}{fig}\PYG{o}{.}\PYG{n}{add\PYGZus{}axes}\PYG{p}{(}\PYG{p}{[}\PYG{l+m+mf}{0.85}\PYG{p}{,} \PYG{l+m+mf}{0.3}\PYG{p}{,} \PYG{l+m+mf}{0.025}\PYG{p}{,} \PYG{l+m+mf}{0.4}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{fig}\PYG{o}{.}\PYG{n}{colorbar}\PYG{p}{(}\PYG{n}{im}\PYG{p}{,} \PYG{n}{cax}\PYG{o}{=}\PYG{n}{cbar\PYGZus{}ax}\PYG{p}{)}
\PYG{k}{return} \PYG{n}{fig}
\end{Verbatim}
\includegraphics{residuals_images.pdf}
\subsubsection{Caveats}
\label{tutorials/flux_point/index:caveats}
It should be noted that in some cases (for instance, a power law with spectral index lower than 2), the Lafferty \& Wyatt approach
does not offer a better representation of the underlying spectrum compared to simply taking the log bin center. Indeed, the
improvements that are seen in the Lafferty \& Wyatt approach over using the bin Log Center occurs due to Lafferty \& Wyatt
simply positioning the flux point further to the left of the bin. Thus there is reason to consider further methods, namely:
\begin{itemize}
\item {}
Positioning the flux point such that the integral flux on either side of it within the energy bin are equal.
\item {}
Simply choosing a position towards the left of the bin, for instance at a position 0.2 bin lengths from the left of the bin in log energy.
\end{itemize}
\subsection{Skymaps with \texttt{gammapy-pfmap} and Sherpa}
\label{tutorials/gammapy-pfmap/index:skymaps-with-gammapy-pfmap-and-sherpa}\label{tutorials/gammapy-pfmap/index:astropy}\label{tutorials/gammapy-pfmap/index::doc}\label{tutorials/gammapy-pfmap/index:tutorials-gammapy-pfmap}
The script \code{gammapy-pfmap} is used to create binned skymaps from FITS event lists.
It calculates background maps using the ring and the template background method
(if a corresponding template background eventlist is provided)
and produces signal, background, excess, and significance maps.
These maps can be written to fits files and then viewed and analyzed with standard fits tools, e.g., fv, ds9, or sherpa.
\subsubsection{Running \texttt{gammapy-pfmap}}
\label{tutorials/gammapy-pfmap/index:running-gammapy-pfmap}
Using \code{gammapy-pfmap} is straight forward.
To create skymaps from a file \code{data.fits} using the object position from the header of the file
as center of skymap and writing the skymaps to FITS files (option: \code{-w}), use:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }gammapy\PYGZhy{}pfmap data.fits \PYGZhy{}w
\end{Verbatim}
\code{gammapy-pfmap} can also handle compressed files (gzip).
If you want to analyse several files together,
you need to create an ASCII file containing the filenames
(first string per row is used; bankfile), e.g.,:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }ls *.fits.gz \PYGZgt{} my.bnk
\PYG{n+nv}{\PYGZdl{} }python scripts/pfmap.py my.bnk \PYGZhy{}w
\end{Verbatim}
You can change the parameters of the skymap via command line options, e.g.,:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }gammapy\PYGZhy{}pfmap my.bnk \PYGZhy{}w \PYGZhy{}s 4. \PYGZhy{}b 0.1 \PYGZhy{}r 0.1 \PYGZhy{}c \PYG{l+s+s2}{\PYGZdq{}(83.633, 22.0145)\PYGZdq{}}
\end{Verbatim}
creating a skymap of size 4 deg (\code{-s}) with a bin size 0.1 deg (\code{-c})
and correlation radius for the oversampled skymap of 0.1 deg (\code{-r}).
The center of the map is set to RA=83.633 deg, Dec=22.0145 deg (J2000; -).
Check the \code{-{-}help} option for more details on the different command line options.
After running \code{gammapy-pfmap} with the option \code{-w} you will find a couple of new FITS files
in you working directory starting with \code{skymap\_ring} (or \code{skymap\_templ}).
Files containing the string overs contain correlated/oversampled maps.
The other string identifier are as follows:
\begin{itemize}
\item {}
ac = Acceptance
\item {}
al = Alpha factor
\item {}
bg = Background
\item {}
ev = Events
\item {}
ex = Excess
\item {}
si = Significance
\end{itemize}
You can view the files with with standard FITS tools, e.g., fv or ds9.
\subsubsection{Morphology fitting with Sherpa}
\label{tutorials/gammapy-pfmap/index:morphology-fitting-with-sherpa}
Find below an example python script, which shows to fit an excess skymap with a 2D double gaussian function with Sherpa.
For this to work it is assumed that you have the python packages sherpa, pyfits, and kapteyn installed on your machine.
\begin{Verbatim}[commandchars=\\\{\},numbers=left,firstnumber=1,stepnumber=1]
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}Fit gamma\PYGZhy{}ray images with Sherpa.\PYGZdq{}\PYGZdq{}\PYGZdq{}}
\PYG{k+kn}{import} \PYG{n+nn}{sherpa.astro.ui} \PYG{k+kn}{as} \PYG{n+nn}{ui}
\PYG{k+kn}{from} \PYG{n+nn}{kapteyn} \PYG{k+kn}{import} \PYG{n}{wcs}\PYG{p}{,} \PYG{n}{positions}
\PYG{k}{try}\PYG{p}{:}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.io} \PYG{k+kn}{import} \PYG{n}{fits}
\PYG{k}{except}\PYG{p}{:}
\PYG{k+kn}{import} \PYG{n+nn}{pyfits} \PYG{k+kn}{as} \PYG{n+nn}{fits}
\PYG{n}{filename} \PYG{o}{=} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{skymap\PYGZus{}ex.fits}\PYG{l+s}{\PYGZsq{}}
\PYG{n}{nomposstr} \PYG{o}{=} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{05h34m31.94s 22d00m52.2s}\PYG{l+s}{\PYGZsq{}}
\PYG{n}{header} \PYG{o}{=} \PYG{n}{fits}\PYG{o}{.}\PYG{n}{getheader}\PYG{p}{(}\PYG{n}{filename}\PYG{p}{)}
\PYG{n}{proj} \PYG{o}{=} \PYG{n}{wcs}\PYG{o}{.}\PYG{n}{Projection}\PYG{p}{(}\PYG{n}{header}\PYG{p}{)}
\PYG{n}{xc}\PYG{p}{,} \PYG{n}{yc} \PYG{o}{=} \PYG{n+nb}{float}\PYG{p}{(}\PYG{n}{header}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{NAXIS1}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{)} \PYG{o}{/} \PYG{l+m+mf}{2.}\PYG{p}{,} \PYG{n+nb}{float}\PYG{p}{(}\PYG{n}{header}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{NAXIS2}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{)} \PYG{o}{/} \PYG{l+m+mf}{2.}
\PYG{n}{ui}\PYG{o}{.}\PYG{n}{load\PYGZus{}image}\PYG{p}{(}\PYG{n}{filename}\PYG{p}{)}
\PYG{n}{ui}\PYG{o}{.}\PYG{n}{notice2d}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{circle(\PYGZob{}0\PYGZcb{}, \PYGZob{}1\PYGZcb{}, \PYGZob{}2\PYGZcb{})}\PYG{l+s}{\PYGZsq{}}\PYG{o}{.}\PYG{n}{format}\PYG{p}{(}\PYG{n}{xc}\PYG{p}{,} \PYG{n}{yc}\PYG{p}{,} \PYG{n+nb}{float}\PYG{p}{(}\PYG{n}{header}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{NAXIS2}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{)} \PYG{o}{/} \PYG{l+m+mf}{4.}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{ui}\PYG{o}{.}\PYG{n}{set\PYGZus{}source}\PYG{p}{(}\PYG{n}{ui}\PYG{o}{.}\PYG{n}{gauss2d}\PYG{o}{.}\PYG{n}{g1} \PYG{o}{+} \PYG{n}{ui}\PYG{o}{.}\PYG{n}{gauss2d}\PYG{o}{.}\PYG{n}{g2}\PYG{p}{)}
\PYG{n}{g1}\PYG{o}{.}\PYG{n}{xpos} \PYG{o}{=} \PYG{n}{xc}
\PYG{n}{g1}\PYG{o}{.}\PYG{n}{ypos} \PYG{o}{=} \PYG{n}{yc}
\PYG{n}{g2}\PYG{o}{.}\PYG{n}{fwhm} \PYG{o}{=} \PYG{n}{g1}\PYG{o}{.}\PYG{n}{fwhm} \PYG{o}{=} \PYG{l+m+mf}{3.}
\PYG{n}{ui}\PYG{o}{.}\PYG{n}{link}\PYG{p}{(}\PYG{n}{g2}\PYG{o}{.}\PYG{n}{xpos}\PYG{p}{,} \PYG{n}{g1}\PYG{o}{.}\PYG{n}{xpos}\PYG{p}{)}
\PYG{n}{ui}\PYG{o}{.}\PYG{n}{link}\PYG{p}{(}\PYG{n}{g2}\PYG{o}{.}\PYG{n}{ypos}\PYG{p}{,} \PYG{n}{g1}\PYG{o}{.}\PYG{n}{ypos}\PYG{p}{)}
\PYG{n}{g2}\PYG{o}{.}\PYG{n}{ampl} \PYG{o}{=} \PYG{l+m+mf}{50.}
\PYG{n}{g1}\PYG{o}{.}\PYG{n}{ampl} \PYG{o}{=} \PYG{l+m+mf}{50.}
\PYG{n}{ui}\PYG{o}{.}\PYG{n}{guess}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{ui}\PYG{o}{.}\PYG{n}{fit}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{ui}\PYG{o}{.}\PYG{n}{image\PYGZus{}fit}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{ui}\PYG{o}{.}\PYG{n}{covar}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{conf} \PYG{o}{=} \PYG{n}{ui}\PYG{o}{.}\PYG{n}{get\PYGZus{}covar\PYGZus{}results}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{conf\PYGZus{}dict} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{p}{[}\PYG{p}{(}\PYG{n}{n}\PYG{p}{,}\PYG{p}{(}\PYG{n}{v}\PYG{p}{,} \PYG{n}{l}\PYG{p}{,} \PYG{n}{h}\PYG{p}{)}\PYG{p}{)} \PYG{k}{for} \PYG{n}{n}\PYG{p}{,}\PYG{n}{v}\PYG{p}{,}\PYG{n}{l}\PYG{p}{,}\PYG{n}{h} \PYG{o+ow}{in}
\PYG{n+nb}{zip}\PYG{p}{(}\PYG{n}{conf}\PYG{o}{.}\PYG{n}{parnames}\PYG{p}{,} \PYG{n}{conf}\PYG{o}{.}\PYG{n}{parvals}\PYG{p}{,} \PYG{n}{conf}\PYG{o}{.}\PYG{n}{parmins}\PYG{p}{,} \PYG{n}{conf}\PYG{o}{.}\PYG{n}{parmaxes}\PYG{p}{)}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{x}\PYG{p}{,} \PYG{n}{y} \PYG{o}{=} \PYG{n}{proj}\PYG{o}{.}\PYG{n}{toworld}\PYG{p}{(}\PYG{p}{(}\PYG{n}{conf\PYGZus{}dict}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{g1.xpos}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{,} \PYG{n}{conf\PYGZus{}dict}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{g1.ypos}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{xmin}\PYG{p}{,} \PYG{n}{ymin} \PYG{o}{=} \PYG{n}{proj}\PYG{o}{.}\PYG{n}{toworld}\PYG{p}{(}\PYG{p}{(}\PYG{n}{conf\PYGZus{}dict}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{g1.xpos}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]} \PYG{o}{+} \PYG{n}{conf\PYGZus{}dict}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{g1.xpos}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{,}
\PYG{n}{conf\PYGZus{}dict}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{g1.ypos}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]} \PYG{o}{+} \PYG{n}{conf\PYGZus{}dict}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{g1.ypos}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{xmax}\PYG{p}{,} \PYG{n}{ymax} \PYG{o}{=} \PYG{n}{proj}\PYG{o}{.}\PYG{n}{toworld}\PYG{p}{(}\PYG{p}{(}\PYG{n}{conf\PYGZus{}dict}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{g1.xpos}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]} \PYG{o}{+} \PYG{n}{conf\PYGZus{}dict}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{g1.xpos}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{p}{,}
\PYG{n}{conf\PYGZus{}dict}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{g1.ypos}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]} \PYG{o}{+} \PYG{n}{conf\PYGZus{}dict}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{g1.ypos}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{nompos} \PYG{o}{=} \PYG{n}{positions}\PYG{o}{.}\PYG{n}{str2pos}\PYG{p}{(}\PYG{n}{nomposstr}\PYG{p}{,} \PYG{n}{proj}\PYG{p}{)}
\PYG{k}{print}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{\PYGZob{}0\PYGZcb{} (\PYGZob{}1\PYGZcb{}\PYGZhy{}\PYGZob{}2\PYGZcb{}) vs \PYGZob{}3\PYGZcb{}}\PYG{l+s}{\PYGZsq{}}\PYG{o}{.}\PYG{n}{format}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,} \PYG{n}{xmin}\PYG{p}{,} \PYG{n}{xmax}\PYG{p}{,} \PYG{n}{nompos}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{)}\PYG{p}{)}
\PYG{k}{print}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{\PYGZob{}0\PYGZcb{} (\PYGZob{}1\PYGZcb{}\PYGZhy{}\PYGZob{}2\PYGZcb{}) vs \PYGZob{}3\PYGZcb{}}\PYG{l+s}{\PYGZsq{}}\PYG{o}{.}\PYG{n}{format}\PYG{p}{(}\PYG{n}{y}\PYG{p}{,} \PYG{n}{ymin}\PYG{p}{,} \PYG{n}{ymax}\PYG{p}{,} \PYG{n}{nompos}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{)}\PYG{p}{)}
\end{Verbatim}
\subsection{Spectra with \texttt{gammapy-pfspec} and Sherpa}
\label{tutorials/gammapy-pfspec/index:spectra-with-gammapy-pfspec-and-sherpa}\label{tutorials/gammapy-pfspec/index:astropy}\label{tutorials/gammapy-pfspec/index::doc}\label{tutorials/gammapy-pfspec/index:tutorials-gammapy-pfspec}
\subsubsection{Running \texttt{gammapy-pfspec}}
\label{tutorials/gammapy-pfspec/index:running-gammapy-pfspec}
The script \code{gammapy-pfspec} produces PHA spectrum files from FITS event lists, which can be analyzed with tools like XSPEC.
The instrument response is taken from ARF (effective area) and RMF (energy distribution matrix) files
and is assumed to be constant over the duration of a data segment (run).
The background is estimated using a ring at the same camera/FoV distance as the source, cutting out the source position.
Per data file, \code{gammapy-pfspec} needs three inputs:
the name of the data file and the corresponding ARF and RMF file names.
These can be given via command line but usually it is more efficient to create an ASCII file (bankfile),
with each row giving the data file name, the ARF and the RMF file names, separate by spaces.
We assume, such a bankfile has been created for the data called my.bnk.
To create the pha files run:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }gammapy\PYGZhy{}pfspec my.bnk \PYGZhy{}w \PYGZhy{}r 0.125
\end{Verbatim}
The option \code{-r} denotes the radius in degree of the circular source region from which the spectrum will be extracted (theta cut).
This should match the cut used in the ARF files.
This will produce three PHA files per data file in the working directory:
\begin{itemize}
\item {}
bg = Background
\item {}
excess = Excess
\item {}
signal = Signal (i.e. excess = signal - background)
\end{itemize}
\subsubsection{Spectrum fitting with Sherpa}
\label{tutorials/gammapy-pfspec/index:spectrum-fitting-with-sherpa}
The output PHA files can be analyzed with spectra fitting tools like XSPEC or Sherpa.
Find below an example session for XSPEC.
Note that XSPEC and Sherpa do not recognize the units given in the ARF/RMF files correctly,
always assuming keV and cm\textasciicircum{}2.
Therefore, the fit results have to be converted correspondingly.
Some output has been omitted below and has been replaced with dots (...).
\begin{Verbatim}[commandchars=\\\{\}]
\PYGZdl{} xspec
XSPEC version: 12.7.0
Build Date/Time: Tue Jun 7 23:17:42 2011
XSPEC12\PYGZgt{}cpd /xw
XSPEC12\PYGZgt{}data CTA1DC\PYGZhy{}HESS\PYGZhy{}run\PYGZus{}00023523\PYGZus{}eventlist\PYGZus{}signal.pha.fits \PYGZbs{}
CTA1DC\PYGZhy{}HESS\PYGZhy{}run\PYGZus{}00023526\PYGZus{}eventlist\PYGZus{}signal.pha.fits
2 spectra in use
Spectral Data File: CTA1DC\PYGZhy{}HESS\PYGZhy{}run\PYGZus{}00023523\PYGZus{}eventlist\PYGZus{}signal.pha.fits Spectrum 1
Net count rate (cts/s) for Spectrum:1 1.174e\PYGZhy{}01 +/\PYGZhy{} 9.183e\PYGZhy{}03 (88.8 \PYGZpc{} total)
Assigned to Data Group 1 and Plot Group 1
Noticed Channels: 1\PYGZhy{}33
Telescope: unknown Instrument: unknown Channel Type: PHA
Exposure Time: 1582 sec
Using fit statistic: chi
Using Background File CTA1DC\PYGZhy{}HESS\PYGZhy{}run\PYGZus{}00023523\PYGZus{}eventlist\PYGZus{}bg.pha.fits
Background Exposure Time: 1582 sec
Using Response (RMF) File run023523\PYGZus{}dummy\PYGZus{}s0.1.rmf.fits for Source 1
Using Auxiliary Response (ARF) File CTA1DC\PYGZhy{}HESS\PYGZhy{}run023523\PYGZus{}std\PYGZus{}arf.fits.gz
...
XSPEC12\PYGZgt{}plot data
XSPEC12\PYGZgt{}model powerlaw
Input parameter value, delta, min, bot, top, and max values for ...
1 0.01( 0.01) \PYGZhy{}3 \PYGZhy{}2 9 10
1:powerlaw:PhoIndex\PYGZgt{}2.7
1 0.01( 0.01) 0 0 1e+24 1e+24
2:powerlaw:norm\PYGZgt{}1E\PYGZhy{}8
========================================================================
Model powerlaw\PYGZlt{}1\PYGZgt{} Source No.: 1 Active/On
Model Model Component Parameter Unit Value
par comp
1 1 powerlaw PhoIndex 2.70000 +/\PYGZhy{} 0.0
2 1 powerlaw norm 1.00000E\PYGZhy{}08 +/\PYGZhy{} 0.0
\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}
Chi\PYGZhy{}Squared = 336.01 using 67 PHA bins.
Reduced chi\PYGZhy{}squared = 5.1694 for 65 degrees of freedom
Null hypothesis probability = 3.604967e\PYGZhy{}38
Current data and model not fit yet.
XSPEC12\PYGZgt{}fit
...
========================================================================
Model powerlaw\PYGZlt{}1\PYGZgt{} Source No.: 1 Active/On
Model Model Component Parameter Unit Value
par comp
1 1 powerlaw PhoIndex 2.58471 +/\PYGZhy{} 9.17193E\PYGZhy{}02
2 1 powerlaw norm 3.49673E\PYGZhy{}07 +/\PYGZhy{} 2.17838E\PYGZhy{}08
\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}\PYGZus{}
Chi\PYGZhy{}Squared = 76.55 using 67 PHA bins.
Reduced chi\PYGZhy{}squared = 1.178 for 65 degrees of freedom
Null hypothesis probability = 1.548459e\PYGZhy{}01
XSPEC12\PYGZgt{}plot data delchi
\end{Verbatim}
\subsection{Background Estimation}
\label{tutorials/background/index:background-estimation}\label{tutorials/background/index:astropy}\label{tutorials/background/index::doc}
Here we introduce a background estimation method based on significance clipping.
\subsubsection{Significance Clipping}
\label{tutorials/background/index:significance-clipping}
TODO: Add a link to the proceeding, and summarise here the method \& intro from
the proceeding.
The algorithm is demonstrated in the example below, where it is applied to
5 years of Fermi-LAT counts data in the Galactic Plane, in line with the proceeding study.
4 iterations are shown here with parameters selected so as to exaggerate the action of the
algorithm.
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}Estimate a diffuse emission model from Fermi LAT data.}
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}}
\PYG{k+kn}{import} \PYG{n+nn}{numpy} \PYG{k+kn}{as} \PYG{n+nn}{np}
\PYG{k+kn}{import} \PYG{n+nn}{os}
\PYG{k+kn}{import} \PYG{n+nn}{matplotlib.pyplot} \PYG{k+kn}{as} \PYG{n+nn}{plt}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.io} \PYG{k+kn}{import} \PYG{n}{fits}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.utils.data} \PYG{k+kn}{import} \PYG{n}{download\PYGZus{}file}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy} \PYG{k+kn}{import} \PYG{n}{datasets}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.background} \PYG{k+kn}{import} \PYG{n}{IterativeKernelBackgroundEstimator}\PYG{p}{,} \PYG{n}{GammaImages}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.irf} \PYG{k+kn}{import} \PYG{n}{EnergyDependentTablePSF}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.image} \PYG{k+kn}{import} \PYG{n}{make\PYGZus{}empty\PYGZus{}image}\PYG{p}{,} \PYG{n}{catalog\PYGZus{}image}\PYG{p}{,} \PYG{n}{binary\PYGZus{}disk}\PYG{p}{,} \PYG{n}{cube\PYGZus{}to\PYGZus{}image}\PYG{p}{,} \PYG{n}{solid\PYGZus{}angle}
\PYG{c}{\PYGZsh{} *** PREPARATION ***}
\PYG{c}{\PYGZsh{} Parameters}
\PYG{n}{CORRELATION\PYGZus{}RADIUS} \PYG{o}{=} \PYG{l+m+mi}{10} \PYG{c}{\PYGZsh{} Pixels}
\PYG{n}{SIGNIFICANCE\PYGZus{}THRESHOLD} \PYG{o}{=} \PYG{l+m+mi}{5} \PYG{c}{\PYGZsh{} Sigma}
\PYG{n}{MASK\PYGZus{}DILATION\PYGZus{}RADIUS} \PYG{o}{=} \PYG{l+m+mi}{10} \PYG{c}{\PYGZsh{} Pixels}
\PYG{n}{psf\PYGZus{}file} \PYG{o}{=} \PYG{n}{datasets}\PYG{o}{.}\PYG{n}{FermiGalacticCenter}\PYG{o}{.}\PYG{n}{psf}\PYG{p}{(}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Load/create example model images.}
\PYG{n}{filename} \PYG{o}{=} \PYG{n}{datasets}\PYG{o}{.}\PYG{n}{get\PYGZus{}path}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{source\PYGZus{}diffuse\PYGZus{}separation/galactic\PYGZus{}simulations/fermi\PYGZus{}counts.fits}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,}
\PYG{n}{location}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{remote}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{c}{\PYGZsh{} *** LOADING INPUT ***}
\PYG{c}{\PYGZsh{} Counts must be provided as an ImageHDU}
\PYG{n}{counts} \PYG{o}{=} \PYG{n}{fits}\PYG{o}{.}\PYG{n}{open}\PYG{p}{(}\PYG{n}{filename}\PYG{p}{)}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{o}{.}\PYG{n}{data}
\PYG{n}{header} \PYG{o}{=} \PYG{n}{fits}\PYG{o}{.}\PYG{n}{open}\PYG{p}{(}\PYG{n}{filename}\PYG{p}{)}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{o}{.}\PYG{n}{header}
\PYG{n}{images} \PYG{o}{=} \PYG{n}{GammaImages}\PYG{p}{(}\PYG{n}{counts}\PYG{o}{=}\PYG{n}{counts}\PYG{p}{,} \PYG{n}{header}\PYG{o}{=}\PYG{n}{header}\PYG{p}{)}
\PYG{n}{source\PYGZus{}kernel} \PYG{o}{=} \PYG{n}{binary\PYGZus{}disk}\PYG{p}{(}\PYG{n}{CORRELATION\PYGZus{}RADIUS}\PYG{p}{)}
\PYG{n}{background\PYGZus{}kernel} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{ones}\PYG{p}{(}\PYG{p}{(}\PYG{l+m+mi}{10}\PYG{p}{,} \PYG{l+m+mi}{100}\PYG{p}{)}\PYG{p}{)}
\PYG{c}{\PYGZsh{} *** ITERATOR ***}
\PYG{n}{ibe} \PYG{o}{=} \PYG{n}{IterativeKernelBackgroundEstimator}\PYG{p}{(}\PYG{n}{images}\PYG{o}{=}\PYG{n}{images}\PYG{p}{,}
\PYG{n}{source\PYGZus{}kernel}\PYG{o}{=}\PYG{n}{source\PYGZus{}kernel}\PYG{p}{,}
\PYG{n}{background\PYGZus{}kernel}\PYG{o}{=}\PYG{n}{background\PYGZus{}kernel}\PYG{p}{,}
\PYG{n}{significance\PYGZus{}threshold}\PYG{o}{=}\PYG{n}{SIGNIFICANCE\PYGZus{}THRESHOLD}\PYG{p}{,}
\PYG{n}{mask\PYGZus{}dilation\PYGZus{}radius}\PYG{o}{=}\PYG{n}{MASK\PYGZus{}DILATION\PYGZus{}RADIUS}
\PYG{p}{)}
\PYG{n}{n\PYGZus{}iterations} \PYG{o}{=} \PYG{l+m+mi}{4}
\PYG{c}{\PYGZsh{} *** RUN \PYGZam{} PLOT ***}
\PYG{k}{for} \PYG{n}{iteration} \PYG{o+ow}{in} \PYG{n+nb}{range}\PYG{p}{(}\PYG{n}{n\PYGZus{}iterations}\PYG{p}{)}\PYG{p}{:}
\PYG{n}{ibe}\PYG{o}{.}\PYG{n}{run\PYGZus{}iteration}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{mask\PYGZus{}hdu} \PYG{o}{=} \PYG{n}{ibe}\PYG{o}{.}\PYG{n}{mask\PYGZus{}image\PYGZus{}hdu}
\PYG{n}{mask} \PYG{o}{=} \PYG{n}{mask\PYGZus{}hdu}\PYG{o}{.}\PYG{n}{data}\PYG{p}{[}\PYG{p}{:}\PYG{p}{,} \PYG{l+m+mi}{1400}\PYG{p}{:}\PYG{l+m+mi}{2000}\PYG{p}{]}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{subplot}\PYG{p}{(}\PYG{n}{n\PYGZus{}iterations}\PYG{p}{,} \PYG{l+m+mi}{2}\PYG{p}{,} \PYG{l+m+mi}{2} \PYG{o}{*} \PYG{n}{iteration} \PYG{o}{+} \PYG{l+m+mi}{1}\PYG{p}{)}
\PYG{n}{background\PYGZus{}hdu} \PYG{o}{=} \PYG{n}{ibe}\PYG{o}{.}\PYG{n}{background\PYGZus{}image\PYGZus{}hdu}
\PYG{n}{data} \PYG{o}{=} \PYG{n}{background\PYGZus{}hdu}\PYG{o}{.}\PYG{n}{data}\PYG{p}{[}\PYG{p}{:}\PYG{p}{,} \PYG{l+m+mi}{1400}\PYG{p}{:}\PYG{l+m+mi}{2000}\PYG{p}{]}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{imshow}\PYG{p}{(}\PYG{n}{data}\PYG{p}{,} \PYG{n}{vmin}\PYG{o}{=}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{n}{vmax}\PYG{o}{=}\PYG{l+m+mi}{1}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{contour}\PYG{p}{(}\PYG{n}{mask}\PYG{p}{,} \PYG{n}{levels}\PYG{o}{=}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{,} \PYG{n}{linewidths}\PYG{o}{=}\PYG{l+m+mi}{2}\PYG{p}{,} \PYG{n}{colors}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{white}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{axis}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{off}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{title}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Background Estimation, Iteration \PYGZob{}0\PYGZcb{}}\PYG{l+s}{\PYGZsq{}}\PYG{o}{.}\PYG{n}{format}\PYG{p}{(}\PYG{n}{iteration}\PYG{p}{)}\PYG{p}{,}
\PYG{n}{fontsize}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{small}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{subplot}\PYG{p}{(}\PYG{n}{n\PYGZus{}iterations}\PYG{p}{,} \PYG{l+m+mi}{2}\PYG{p}{,} \PYG{l+m+mi}{2} \PYG{o}{*} \PYG{n}{iteration} \PYG{o}{+} \PYG{l+m+mi}{2}\PYG{p}{)}
\PYG{n}{significance\PYGZus{}hdu} \PYG{o}{=} \PYG{n}{ibe}\PYG{o}{.}\PYG{n}{significance\PYGZus{}image\PYGZus{}hdu}
\PYG{n}{data} \PYG{o}{=} \PYG{n}{significance\PYGZus{}hdu}\PYG{o}{.}\PYG{n}{data}\PYG{p}{[}\PYG{p}{:}\PYG{p}{,} \PYG{l+m+mi}{1400}\PYG{p}{:}\PYG{l+m+mi}{2000}\PYG{p}{]}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{imshow}\PYG{p}{(}\PYG{n}{data}\PYG{p}{,} \PYG{n}{vmin}\PYG{o}{=}\PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{3}\PYG{p}{,} \PYG{n}{vmax}\PYG{o}{=}\PYG{l+m+mi}{5}\PYG{p}{,} \PYG{n}{cmap} \PYG{o}{=} \PYG{n}{plt}\PYG{o}{.}\PYG{n}{cm}\PYG{o}{.}\PYG{n}{Greys\PYGZus{}r}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{contour}\PYG{p}{(}\PYG{n}{mask}\PYG{p}{,} \PYG{n}{levels}\PYG{o}{=}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{,} \PYG{n}{linewidths}\PYG{o}{=}\PYG{l+m+mi}{2}\PYG{p}{,} \PYG{n}{colors}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{red}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{axis}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{off}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{title}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Significance Image, Iteration \PYGZob{}0\PYGZcb{}}\PYG{l+s}{\PYGZsq{}}\PYG{o}{.}\PYG{n}{format}\PYG{p}{(}\PYG{n}{iteration}\PYG{p}{)}\PYG{p}{,}
\PYG{n}{fontsize}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{small}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{tight\PYGZus{}layout}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}
\includegraphics{source_diffuse_estimation.pdf}
\begin{itemize}
\item {}
The images on the \textbf{left} show the background estimation with each iteration.
\item {}
The images on the \textbf{right} show the residual significance image with each iteration.
\item {}
The \textbf{contours} show the exclusion mask applied at each iteration.
\end{itemize}
The source mask is shown by the contours. This includes the regions
excluded above the 5 sigma significance threshold (determined by the Li \& Ma method \phantomsection\label{tutorials/background/index:id1}{\hyperref[references:lima1983]{\emph{{[}LiMa1983{]}}}})
in computing the background estimation images above.
\subsection{Fermi-LAT PSF Study}
\label{tutorials/fermi_psf/index:fermi-lat-psf-study}\label{tutorials/fermi_psf/index:astropy}\label{tutorials/fermi_psf/index::doc}
This study compares the results of the Fermi Science Tool \code{gtpsf} - which gives
information about the size of the Fermi-LAT PSF with energy - for the Galactic
center {\hyperref[api/gammapy.datasets.FermiGalacticCenter:gammapy.datasets.FermiGalacticCenter]{\emph{\code{FermiGalacticCenter}}}} and in the region of the
Vela Pulsar {\hyperref[api/gammapy.datasets.FermiVelaRegion:gammapy.datasets.FermiVelaRegion]{\emph{\code{FermiVelaRegion}}}}. The plots below compare
the PSF calculated using the Science Tools in these locations, and compare
to the published LAT PSF data for Pass 7 \code{P7SOURCEV6} and reprocessed
Pass 7 \code{P7REP\_SOURCE\_V15} IRFs at energies between 10 and 300 GeV (the range
of energies for which the calculated and published PSF results are all
available). 68\% and 95\% PSF containment radii are considered.
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}Produces table to study the size of the Fermi\PYGZhy{}LAT PSF with Energy.}
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}}
\PYG{k+kn}{import} \PYG{n+nn}{numpy} \PYG{k+kn}{as} \PYG{n+nn}{np}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.units} \PYG{k+kn}{import} \PYG{n}{Quantity}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.table} \PYG{k+kn}{import} \PYG{n}{Table}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.spectrum} \PYG{k+kn}{import} \PYG{n}{energy\PYGZus{}bounds\PYGZus{}equal\PYGZus{}log\PYGZus{}spacing}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.datasets} \PYG{k+kn}{import} \PYG{n}{FermiGalacticCenter}\PYG{p}{,} \PYG{n}{FermiVelaRegion}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.datasets} \PYG{k+kn}{import} \PYG{n}{load\PYGZus{}lat\PYGZus{}psf\PYGZus{}performance}
\PYG{k+kn}{import} \PYG{n+nn}{matplotlib.pyplot} \PYG{k+kn}{as} \PYG{n+nn}{plt}
\PYG{n}{\PYGZus{}\PYGZus{}all\PYGZus{}\PYGZus{}} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{get\PYGZus{}psf\PYGZus{}table}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{plot\PYGZus{}containment\PYGZus{}radii}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}
\PYG{k}{def} \PYG{n+nf}{get\PYGZus{}psf\PYGZus{}table}\PYG{p}{(}\PYG{n}{psf}\PYG{p}{,} \PYG{n}{emin}\PYG{p}{,} \PYG{n}{emax}\PYG{p}{,} \PYG{n}{bins}\PYG{p}{)}\PYG{p}{:}
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}Returns a table of energy and containment radius}
\PYG{l+s+sd}{ from an EnergyDependentTablePSF object.\PYGZdq{}\PYGZdq{}\PYGZdq{}}
\PYG{c}{\PYGZsh{} Container for data}
\PYG{n}{data} \PYG{o}{=} \PYG{p}{[}\PYG{p}{]}
\PYG{c}{\PYGZsh{} Loop over energies and determine PSF containment radius}
\PYG{k}{for} \PYG{n}{energy} \PYG{o+ow}{in} \PYG{n}{energy\PYGZus{}bounds\PYGZus{}equal\PYGZus{}log\PYGZus{}spacing}\PYG{p}{(}\PYG{n}{Quantity}\PYG{p}{(}\PYG{p}{(}\PYG{n}{emin}\PYG{p}{,} \PYG{n}{emax}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{MeV}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{,} \PYG{n}{bins}\PYG{p}{)}\PYG{p}{:}
\PYG{n}{energy\PYGZus{}psf} \PYG{o}{=} \PYG{n}{psf}\PYG{o}{.}\PYG{n}{table\PYGZus{}psf\PYGZus{}at\PYGZus{}energy}\PYG{p}{(}\PYG{n}{energy}\PYG{p}{)}
\PYG{n}{containment\PYGZus{}68} \PYG{o}{=} \PYG{n}{energy\PYGZus{}psf}\PYG{o}{.}\PYG{n}{containment\PYGZus{}radius}\PYG{p}{(}\PYG{l+m+mf}{0.68}\PYG{p}{)}
\PYG{n}{containment\PYGZus{}95} \PYG{o}{=} \PYG{n}{energy\PYGZus{}psf}\PYG{o}{.}\PYG{n}{containment\PYGZus{}radius}\PYG{p}{(}\PYG{l+m+mf}{0.95}\PYG{p}{)}
\PYG{n}{row} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{ENERGY}\PYG{o}{=}\PYG{n}{energy}\PYG{o}{.}\PYG{n}{value}\PYG{p}{,}
\PYG{n}{CONT\PYGZus{}68}\PYG{o}{=}\PYG{n}{containment\PYGZus{}68}\PYG{o}{.}\PYG{n}{value}\PYG{p}{,}
\PYG{n}{CONT\PYGZus{}95}\PYG{o}{=}\PYG{n}{containment\PYGZus{}95}\PYG{o}{.}\PYG{n}{value}\PYG{p}{)}
\PYG{n}{data}\PYG{o}{.}\PYG{n}{append}\PYG{p}{(}\PYG{n}{row}\PYG{p}{)}
\PYG{c}{\PYGZsh{} Construct table and add correct units to columns}
\PYG{n}{table} \PYG{o}{=} \PYG{n}{Table}\PYG{p}{(}\PYG{n}{data}\PYG{p}{)}
\PYG{n}{table}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ENERGY}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{o}{.}\PYG{n}{units} \PYG{o}{=} \PYG{n}{energy}\PYG{o}{.}\PYG{n}{unit}
\PYG{n}{table}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{CONT\PYGZus{}68}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{o}{.}\PYG{n}{units} \PYG{o}{=} \PYG{n}{containment\PYGZus{}68}\PYG{o}{.}\PYG{n}{unit}
\PYG{n}{table}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{CONT\PYGZus{}95}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{o}{.}\PYG{n}{units} \PYG{o}{=} \PYG{n}{containment\PYGZus{}95}\PYG{o}{.}\PYG{n}{unit}
\PYG{k}{return} \PYG{n}{table}
\PYG{k}{def} \PYG{n+nf}{plot\PYGZus{}containment\PYGZus{}radii}\PYG{p}{(}\PYG{n}{fraction}\PYG{p}{)}\PYG{p}{:}
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}Plotting script for 68\PYGZpc{} and 95\PYGZpc{} containment radii.\PYGZdq{}\PYGZdq{}\PYGZdq{}}
\PYG{n}{psf\PYGZus{}gc} \PYG{o}{=} \PYG{n}{FermiGalacticCenter}\PYG{o}{.}\PYG{n}{psf}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{gtpsf\PYGZus{}table\PYGZus{}gc} \PYG{o}{=} \PYG{n}{get\PYGZus{}psf\PYGZus{}table}\PYG{p}{(}\PYG{n}{psf\PYGZus{}gc}\PYG{p}{,} \PYG{l+m+mi}{10000}\PYG{p}{,} \PYG{l+m+mi}{300000}\PYG{p}{,} \PYG{l+m+mi}{15}\PYG{p}{)}
\PYG{n}{psf\PYGZus{}vela} \PYG{o}{=} \PYG{n}{FermiVelaRegion}\PYG{o}{.}\PYG{n}{psf}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{gtpsf\PYGZus{}table\PYGZus{}vela} \PYG{o}{=} \PYG{n}{get\PYGZus{}psf\PYGZus{}table}\PYG{p}{(}\PYG{n}{psf\PYGZus{}vela}\PYG{p}{,} \PYG{l+m+mi}{10000}\PYG{p}{,} \PYG{l+m+mi}{300000}\PYG{p}{,} \PYG{l+m+mi}{15}\PYG{p}{)}
\PYG{k}{if} \PYG{n}{fraction} \PYG{o}{==} \PYG{l+m+mi}{68}\PYG{p}{:}
\PYG{n}{true\PYGZus{}table\PYGZus{}rep} \PYG{o}{=} \PYG{n}{load\PYGZus{}lat\PYGZus{}psf\PYGZus{}performance}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{P7REP\PYGZus{}SOURCE\PYGZus{}V15\PYGZus{}68}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{true\PYGZus{}table} \PYG{o}{=} \PYG{n}{load\PYGZus{}lat\PYGZus{}psf\PYGZus{}performance}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{P7SOURCEV6\PYGZus{}68}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{rad} \PYG{o}{=} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{CONT\PYGZus{}68}\PYG{l+s}{\PYGZsq{}}
\PYG{k}{elif} \PYG{n}{fraction} \PYG{o}{==} \PYG{l+m+mi}{95}\PYG{p}{:}
\PYG{n}{true\PYGZus{}table\PYGZus{}rep} \PYG{o}{=} \PYG{n}{load\PYGZus{}lat\PYGZus{}psf\PYGZus{}performance}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{P7REP\PYGZus{}SOURCE\PYGZus{}V15\PYGZus{}95}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{true\PYGZus{}table} \PYG{o}{=} \PYG{n}{load\PYGZus{}lat\PYGZus{}psf\PYGZus{}performance}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{P7SOURCEV6\PYGZus{}95}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{rad} \PYG{o}{=} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{CONT\PYGZus{}95}\PYG{l+s}{\PYGZsq{}}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{plot}\PYG{p}{(}\PYG{n}{gtpsf\PYGZus{}table\PYGZus{}gc}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ENERGY}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{,} \PYG{n}{gtpsf\PYGZus{}table\PYGZus{}gc}\PYG{p}{[}\PYG{n}{rad}\PYG{p}{]}\PYG{p}{,}
\PYG{n}{color}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{red}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,}\PYG{n}{label}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Fermi Tools PSF @ Galactic Center}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{plot}\PYG{p}{(}\PYG{n}{gtpsf\PYGZus{}table\PYGZus{}vela}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ENERGY}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{,} \PYG{n}{gtpsf\PYGZus{}table\PYGZus{}vela}\PYG{p}{[}\PYG{n}{rad}\PYG{p}{]}\PYG{p}{,}
\PYG{n}{color}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{blue}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{label}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Fermi Tools PSF @ Vela Region}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{plot}\PYG{p}{(}\PYG{n}{true\PYGZus{}table\PYGZus{}rep}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{energy}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{,} \PYG{n}{true\PYGZus{}table\PYGZus{}rep}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{containment\PYGZus{}angle}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{,}
\PYG{n}{color}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{green}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{linestyle}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{\PYGZhy{}\PYGZhy{}}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{label}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{P7REP\PYGZus{}SOURCE\PYGZus{}V15}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{plot}\PYG{p}{(}\PYG{n}{true\PYGZus{}table}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{energy}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{,} \PYG{n}{true\PYGZus{}table}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{containment\PYGZus{}angle}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{p}{,}
\PYG{n}{color}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{black}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{linestyle}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{\PYGZhy{}\PYGZhy{}}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{label}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{P7SOURCEV6}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{xlim}\PYG{p}{(}\PYG{p}{[}\PYG{l+m+mi}{10000}\PYG{p}{,} \PYG{l+m+mi}{300000}\PYG{p}{]}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{legend}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{semilogx}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{xlabel}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Energy/MeV}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{ylabel}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{PSF Containment Radius/deg}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{k}{return} \PYG{n}{plt}
\end{Verbatim}
Note that for the \code{P7SOURCEV6} and \code{P7REP\_SOURCE\_V15} lines, the data was
extracted by hand and so \textbf{a 10\% error should be assumed}
\includegraphics{plot_68.pdf}
\includegraphics{plot_95.pdf}
The plot for \code{P7REP\_SOURCE\_V15} is not available online, but \code{P7REP\_CLEAN\_V15}
is very similar to \code{P7REP\_SOURCE\_V15} which is used for this study.
The plots indicate that \code{P7REP\_CLEAN\_V15} cuts (which are very similar to
\code{P7REP\_SOURCE\_V15} cuts) were used for the Vela Region data. However, for
the Galactic Center region, \code{P7SOURCEV6} cuts are consistent with the PSF
data, and \code{P7REP\_CLEAN\_V15} could not have been used here.
The published LAT PSF data may be found at:
\begin{itemize}
\item {}
\href{http://www.slac.stanford.edu/exp/glast/groups/canda/archive/p7rep\_v15/lat\_Performance\_files/cPsfEnergy\_P7REP\_SOURCE\_V15.png}{PSF\_P7REP\_SOURCE\_V15}
\item {}
\href{http://www.slac.stanford.edu/exp/glast/groups/canda/archive/pass7v6/lat\_Performance\_files/cPsfEnergy\_P7SOURCE\_V6.png}{PSF\_P7SOURCEV6}
\end{itemize}
\section{Python example scripts}
\label{tutorials/index:python-example-scripts}\label{tutorials/index:tutorials-examples}\label{tutorials/index:astropy}
The \code{examples} folder in the \code{gammapy} repo contains small Python scripts
illustrating how to use Gammapy.
\begin{notice}{note}{Note:}
For now the full list of examples is only available here:
\href{https://github.com/gammapy/gammapy/tree/master/examples}{https://github.com/gammapy/gammapy/tree/master/examples}
We plan to integrate that into the online Sphinx docs ...
please help if you know how to do this:
\href{https://github.com/gammapy/gammapy/issues/172}{https://github.com/gammapy/gammapy/issues/172}
\end{notice}
\section{IPython notebooks}
\label{tutorials/index:tutorials-notebook}\label{tutorials/index:ipython-notebooks}
The IPython notebooks are in the \href{https://github.com/gammapy/gammapy-extra}{gammapy-extra} repo,
see \href{http://nbviewer.ipython.org/github/gammapy/gammapy-extra/blob/master/notebooks/Index.ipynb}{here}.
\section{External}
\label{tutorials/index:external}
Here's some links to good external resources to learn Python, Numpy, Scipy, Astropy, ...
Python is very popular in astronomy (and data science in general).
It's possible to learn the basics within a day and to become productive within a week.
\begin{itemize}
\item {}
Tom Robitaille Python for scientists workshop –– \href{http://www2.mpia-hd.mpg.de/~robitaille/PY4SCI\_SS\_2015/}{http://www2.mpia-hd.mpg.de/\textasciitilde{}robitaille/PY4SCI\_SS\_2015/}
\item {}
Scientific Python lecture notes –– \href{https://scipy-lectures.github.io/}{https://scipy-lectures.github.io/}
\item {}
Practical Python for astronomers — \href{http://python4astronomers.github.io}{http://python4astronomers.github.io}
\item {}
MPIK Astropy workshop — \href{https://astropy4mpik.readthedocs.org/}{https://astropy4mpik.readthedocs.org/}
\item {}
CEA Python for astronomers workshop –– \href{https://github.com/kosack/CEAPythonWorkshopForAstronomers}{https://github.com/kosack/CEAPythonWorkshopForAstronomers}
\item {}
ctools — \href{http://cta.irap.omp.eu/ctools-devel/}{http://cta.irap.omp.eu/ctools-devel/}
\item {}
Astropy tutorials — \href{http://www.astropy.org/astropy-tutorials/}{http://www.astropy.org/astropy-tutorials/}
\item {}
Naima examples — \href{http://naima.readthedocs.org/en/latest/}{http://naima.readthedocs.org/en/latest/}
\item {}
Fermi ScienceTools analysis threads ––– \href{http://fermi.gsfc.nasa.gov/ssc/data/analysis/scitools/}{http://fermi.gsfc.nasa.gov/ssc/data/analysis/scitools/}
\item {}
CIAO Sherpa threads ––– \href{http://cxc.harvard.edu/sherpa/threads/index.html}{http://cxc.harvard.edu/sherpa/threads/index.html}
\item {}
\href{http://nbviewer.ipython.org/github/adonath/gamma\_astropy\_talk/blob/master/gamma\_astropy\_talk.ipynb}{Astropy tutorial by Axel Donath from December 2013}
\end{itemize}
\chapter{Data Formats}
\label{dataformats/index:data-formats}\label{dataformats/index:astropy}\label{dataformats/index::doc}\label{dataformats/index:dataformats}
Here we describe various data file formats that are useful for the exchange
of TeV data, instrument response functions and results.
\begin{notice}{note}{Note:}
In {\hyperref[datasets/index:datasets]{\emph{\DUspan{}{Access datasets (gammapy.datasets)}}}} you find example gamma-ray datasets,
some in the formats described here.
\end{notice}
Where available and useful existing standards are used, e.g.
for spectral data the X-ray community has developed the \code{PHA}, \code{ARF} and \code{RMF}
file formats and they have developed powerful tools to work with data in that format.
In other cases (flux points, point spread function, run lists) there is no standard and
we simply use general-purpose file formats define our own semantics as described
in the {\hyperref[dataformats/file_formats:dataformats-file-formats]{\emph{\DUspan{}{File formats}}}} section.
\section{Overview}
\label{dataformats/index:dataformats-overview}\label{dataformats/index:overview}
Here's an overview of the file formats supported by Gammapy and Gammalib:
\begin{tabulary}{\linewidth}{|L|L|L|L|}
\hline
\textsf{\relax
Type
} & \textsf{\relax
Format Name
} & \textsf{\relax
Gammapy
} & \textsf{\relax
Gammalib
}\\
\hline
Events
&
EVENTS
&
{\hyperref[api/gammapy.data.EventList:gammapy.data.EventList]{\emph{\code{EventList}}}}
&
\href{http://cta.irap.omp.eu/gammalib-devel/doxygen/classGEventList.html}{GEventList}
\\
\hline
Counts
&
3D
&
{\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube]{\emph{\code{SpectralCube}}}}
&
\href{http://cta.irap.omp.eu/gammalib-devel/doxygen/classGCTAEventCube.html}{GCTAEventCube}
\\
\hline
Counts
&
Image
&
no class?
&
\href{http://cta.irap.omp.eu/gammalib-devel/doxygen/classGCTASkyMap.html}{GSkyMap}
\\
\hline
Counts
&
PHA
&
{\hyperref[api/gammapy.data.CountsSpectrumDataset:gammapy.data.CountsSpectrumDataset]{\emph{\code{CountsSpectrumDataset}}}}
&
\href{http://cta.irap.omp.eu/gammalib-devel/doxygen/classGPha.html}{GPha}
\\
\hline
Exposure
&
EXPOSURE\_3D
&
{\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube]{\emph{\code{SpectralCube}}}}?
&
\href{http://cta.irap.omp.eu/gammalib-devel/doxygen/classGCTACubeExposure.html}{GCTACubeExposure}
\\
\hline
Background
&
{\hyperref[background/models:background-3d]{\emph{\DUspan{}{BACKGROUND\_3D}}}}
&
{\hyperref[api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel]{\emph{\code{CubeBackgroundModel}}}}
&
\href{http://cta.irap.omp.eu/gammalib-devel/doxygen/classGCTABackground3D.html}{GCTABackground3D}
\\
\hline
Background
&
BACKGROUND\_1D
&
N/A
&
\href{http://cta.irap.omp.eu/gammalib-devel/doxygen/classGCTAModelRadialAcceptance.html}{GCTAModelRadialAcceptance}
\\
\hline
Exposure
&
???
&
{\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube]{\emph{\code{SpectralCube}}}}?
&
\href{http://cta.irap.omp.eu/gammalib-devel/doxygen/classGCTACubeBackground.html}{GCTACubeBackground}
\\
\hline
PSF
&
PSF\_2D
&
N/A
&
\href{http://cta.irap.omp.eu/gammalib-devel/doxygen/classGCTAPsf2D.html}{GCTAPsf2D}
\\
\hline
PSF
&
PSF\_1D
&
{\hyperref[api/gammapy.irf.TablePSF:gammapy.irf.TablePSF]{\emph{\code{TablePSF}}}}
&
\href{http://cta.irap.omp.eu/gammalib-devel/doxygen/classGCTAPsfVector.html}{GCTAPsfVector}
\\
\hline
PSF
&
\href{http://fermi.gsfc.nasa.gov/ssc/data/analysis/scitools/help/gtpsf.txt}{gtpsf} output
&
{\hyperref[api/gammapy.irf.EnergyDependentTablePSF:gammapy.irf.EnergyDependentTablePSF]{\emph{\code{EnergyDependentTablePSF}}}}
&
N/A
\\
\hline
PSF
&
???
&
N/A
&
\href{http://cta.irap.omp.eu/gammalib-devel/doxygen/classGCTACubePsf.html}{GCTACubePsf}
\\
\hline
Effective area
&
AEFF\_2D
&
{\hyperref[api/gammapy.irf.EffectiveAreaTable2D:gammapy.irf.EffectiveAreaTable2D]{\emph{\code{EffectiveAreaTable2D}}}}
&
\href{http://cta.irap.omp.eu/gammalib-devel/doxygen/classGCTAAeff2D.html}{GCTAAeff2D}
\\
\hline
Effective area
&
ARF
&
{\hyperref[api/gammapy.irf.EffectiveAreaTable:gammapy.irf.EffectiveAreaTable]{\emph{\code{EffectiveAreaTable}}}}
&
\href{http://cta.irap.omp.eu/gammalib-devel/doxygen/classGCTAAeffArf.html}{GCTAAeffArf}
\\
\hline
Energy dispersion
&
EDISP\_2D
&
N/A
&
\href{http://cta.irap.omp.eu/gammalib-devel/doxygen/classGCTAEdisp2D.html}{GCTAEdisp2D}
\\
\hline
Energy dispersion
&
RMF
&
{\hyperref[api/gammapy.irf.EnergyDispersion:gammapy.irf.EnergyDispersion]{\emph{\code{EnergyDispersion}}}}
&
\href{http://cta.irap.omp.eu/gammalib-devel/doxygen/classGCTAEdispRMF.html}{GCTAEdispRMF}
\\
\hline\end{tabulary}
Notes:
\begin{itemize}
\item {}
The Gammalib docs contain a nice overview of IRFs
\href{http://cta.irap.omp.eu/gammalib-devel/user\_manual/modules/cta\_overview.html}{here}
and detailed explanations of some IRF
\href{http://cta.irap.omp.eu/gammalib-devel/user\_manual/modules/cta\_irf.html}{here}.
\item {}
We probably should unify / shorten the IRF class names in Gammapy.
\item {}
There's quite a few classes in Gammapy that don't have a well-defined format.
We should add a way to serialise every class and document the format for easier interop.
\item {}
Maybe add info which format is used by Fermi, HESS HD/PA, CTA?
\item {}
For every format there should be one or several test data files.
This could even be in a repo that's shared by Gammalib / Gammapy.
\item {}
TODO: For {\hyperref[api/gammapy.irf.TablePSF:gammapy.irf.TablePSF]{\emph{\code{TablePSF}}}} FITS I/O in the Gammalib format should be implemented.
\item {}
TODO: the format name should be chosen so that it corresponds to FITS extension names or filenames.
Is this the case? Can we agree on names with Gammalib?
\item {}
TODO: Link to native Sherpa classes once available.
\end{itemize}
\section{Sub-pages}
\label{dataformats/index:sub-pages}
\subsection{File formats}
\label{dataformats/file_formats::doc}\label{dataformats/file_formats:file-formats}\label{dataformats/file_formats:dataformats-file-formats}
\begin{notice}{note}{Note:}
This section is not very useful for astronomers trying to get some analysis done.
If this is you, maybe try to use the search field to find the specific info / method you want?
The info is for developers or advanced users that are writing analysis scripts.
\end{notice}
This section gives an introdution to the various file formats used in various
parts of Gammapy (and gamma-ray astronomy in general) as well as pointers
how to work with data in these formats and learn more about them.
It also contains comments on the strengths and weaknesses of each format,
which are certainly subjective, but might be useful to help you pick a
certain format if you ever want to store or exchange some data
where no suitable standardised format exists.
\subsubsection{Introduction}
\label{dataformats/file_formats:introduction}
In Gammapy we use existing file formats by
\href{http://fermi.gsfc.nasa.gov/}{Fermi-LAT} and
\href{https://www.cta-observatory.org/}{CTA} where available.
This increases inter-operability with the
\href{http://fermi.gsfc.nasa.gov/ssc/data/}{Fermi science tools}
and the
\href{http://cta.irap.omp.eu/ctools/}{CTA science tools}
as well as mind share with users of those tools.
We also introduce new file formats for things that should be easy to store and exchange,
but no well-defined format exists. E.g. we could define a Gaussian PSF in XML format as
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nt}{\PYGZlt{}psf} \PYG{n+na}{type=}\PYG{l+s}{\PYGZdq{}gauss\PYGZdq{}}\PYG{n+nt}{\PYGZgt{}}
\PYG{n+nt}{\PYGZlt{}parameter} \PYG{n+na}{name=}\PYG{l+s}{\PYGZdq{}amplitude\PYGZdq{}} \PYG{n+na}{value=}\PYG{l+s}{\PYGZdq{}4.2\PYGZdq{}}\PYG{n+nt}{/\PYGZgt{}}
\PYG{n+nt}{\PYGZlt{}parameter} \PYG{n+na}{name=}\PYG{l+s}{\PYGZdq{}stddev\PYGZdq{}} \PYG{n+na}{value=}\PYG{l+s}{\PYGZdq{}0.073\PYGZdq{}}\PYG{n+nt}{/\PYGZgt{}}
\PYG{n+nt}{\PYGZlt{}/psf\PYGZgt{}}
\end{Verbatim}
Or we could define a JSON file format for fit results:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{p}{\PYGZob{}}
\PYG{n+nt}{\PYGZdq{}convergence\PYGZdq{}}\PYG{p}{:} \PYG{k+kc}{true}\PYG{p}{,}
\PYG{n+nt}{\PYGZdq{}sources\PYGZdq{}}\PYG{p}{:} \PYG{p}{[}
\PYG{p}{\PYGZob{}}
\PYG{n+nt}{\PYGZdq{}type\PYGZdq{}}\PYG{p}{:} \PYG{l+s+s2}{\PYGZdq{}point\PYGZdq{}}\PYG{p}{,}
\PYG{n+nt}{\PYGZdq{}parameters\PYGZdq{}}\PYG{p}{:} \PYG{p}{\PYGZob{}} \PYG{n+nt}{\PYGZdq{}y\PYGZdq{}}\PYG{p}{:} \PYG{l+m+mf}{3.2}\PYG{p}{,} \PYG{n+nt}{\PYGZdq{}x\PYGZdq{}}\PYG{p}{:} \PYG{l+m+mf}{4.9}\PYG{p}{,} \PYG{n+nt}{\PYGZdq{}flux\PYGZdq{}}\PYG{p}{:} \PYG{l+m+mi}{99} \PYG{p}{\PYGZcb{}}
\PYG{p}{\PYGZcb{}}\PYG{p}{,}
\PYG{p}{\PYGZob{}}
\PYG{n+nt}{\PYGZdq{}type\PYGZdq{}}\PYG{p}{:} \PYG{l+s+s2}{\PYGZdq{}gauss\PYGZdq{}}\PYG{p}{,}
\PYG{n+nt}{\PYGZdq{}parameters\PYGZdq{}}\PYG{p}{:} \PYG{p}{\PYGZob{}} \PYG{n+nt}{\PYGZdq{}y\PYGZdq{}}\PYG{p}{:} \PYG{l+m+mf}{\PYGZhy{}2.3}\PYG{p}{,} \PYG{n+nt}{\PYGZdq{}x\PYGZdq{}}\PYG{p}{:} \PYG{l+m+mf}{3.3}\PYG{p}{,} \PYG{n+nt}{\PYGZdq{}stddev\PYGZdq{}}\PYG{p}{:} \PYG{l+m+mf}{0.13}\PYG{p}{,} \PYG{n+nt}{\PYGZdq{}flux\PYGZdq{}}\PYG{p}{:} \PYG{l+m+mi}{49} \PYG{p}{\PYGZcb{}}
\PYG{p}{\PYGZcb{}}
\PYG{p}{]}\PYG{p}{,}
\PYG{n+nt}{\PYGZdq{}likelihood\PYGZdq{}}\PYG{p}{:} \PYG{l+m+mf}{4.2}
\PYG{p}{\PYGZcb{}}
\end{Verbatim}
By using general-purpose, flexible file formats (XML and JSON in the examples above)
we can store and exchange any information between tools written in any programming language
(that has an XML or JSON library for parsing and generating data in that format).
All we have to do it agree on the structure
(e.g. to use XML and the fact that there's \code{psf} and \code{parameter} elements,
and that \code{parameter} elements have \code{name} and \code{value} attributes)
and semantics (e.g. that the \code{stddev} parameter of the \code{gauss} PSF is the Gaussian width in degrees).
If we don't write the structure down somewhere everyone will invent their own format,
severly limiting our ability as a community to share results and scripts and build up analysis pipelines
without having to write data converter scripts all the time.
To illustrate this issue, note that the PSF information given above could just as well have been
stored in this incompatible format:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nt}{\PYGZlt{}gauss\PYGZus{}psf}\PYG{n+nt}{\PYGZgt{}}
\PYG{n+nt}{\PYGZlt{}norm}\PYG{n+nt}{\PYGZgt{}}4.2\PYG{n+nt}{\PYGZlt{}norm}\PYG{n+nt}{/\PYGZgt{}}
\PYG{n+nt}{\PYGZlt{}sigma}\PYG{n+nt}{\PYGZgt{}}0.073\PYG{n+nt}{\PYGZlt{}sigma}\PYG{n+nt}{/\PYGZgt{}}
\PYG{n+nt}{\PYGZlt{}/psf\PYGZgt{}}
\end{Verbatim}
Note that this is the best we can do in Gammapy at this time where no
final data format specifications for CTA exist.
We hope that some of these formats will be considered useful prototypes for CTA and adopted.
We do not give any guarantees that the formats described here will be supported in the future!
In most cases the CTA collaboration will probably specify other formats
and we'll update Gammapy to use those.
The data format specifications at \href{http://dataprotocols.org/}{http://dataprotocols.org/} are a good example
how to specify formats and schemas in an easy-to-understand way.
After all most people that develop gamma-ray analysis software and have to
work with those data files and codes are astronomers with little computer science background.
\subsubsection{Overview}
\label{dataformats/file_formats:overview}
The following table gives an overview of the file formats that you'll probably
encounter at some point in your life as a gamma-ray astronomer.
\begin{tabulary}{\linewidth}{|L|L|L|L|L|L|L|}
\hline
\textsf{\relax
Format
} & \textsf{\relax
File type
} & \multicolumn{4}{l|}{\textsf{\relax
Supported data content
}} & \textsf{\relax
Schema
}\\
\hline\textsf{\relax
} & \textsf{\relax } & \textsf{\relax
Meta
} & \textsf{\relax
Table
} & \textsf{\relax
Array
} & \textsf{\relax
Tree
} & \textsf{\relax }\\
\hline
INI
&
text
&
Yes
&
No
&
No
&
No
&
Yes
\\
\hline
CSV
&
text
&
No
&
Yes
&
No
&
No
&
Yes
\\
\hline
JSON
&
text
&
Yes
&
Yes
&
Yes
&
Yes
&
Yes
\\
\hline
XML
&
text
&
Yes
&
Yes
&
Yes
&
Yes
&
Yes
\\
\hline
FITS
&
binary
&
Some
&
Yes
&
Yes
&
No
&
No
\\
\hline
ROOT
&
binary
&
No
&
Yes
&
Yes
&
Yes
&
No
\\
\hline\end{tabulary}
Almost all entries in the above table are debatable ... here's some caveats:
\begin{itemize}
\item {}
The definition of ``text'' or ``binary'' file type given here should be read as
``are files of this type in gamma-ray astronomy commonly opened up in text editors''?
In reality the distinction is not always clear, e.g. XML can contain binary data
and FITS contains text headers.
\item {}
The ``supported data content'' should be read as ``is commonly used for this kind of content''.
E.g. I put FITS as ``no'' for tree data (a.k.a. structured or hierarchical data such as
in the JSON example above) even though people have found ways to encode such information
in FITS headers or data extensions.
\item {}
The schema supports is best (very common, well-understood, good tools) for
\href{http://en.wikipedia.org/wiki/XML\_schema}{XML schema},
but there's some schema support for the other formats as well.
This will be discussed in the section {\hyperref[dataformats/file_formats:validation]{\emph{Validation}}} below.
\end{itemize}
Here's a short description of each format with references if you want to learn more:
\paragraph{INI}
\label{dataformats/file_formats:ini}
\textbf{INI} files (see \href{http://en.wikipedia.org/wiki/INI\_file}{Wikipedia})
are the most easy to write and edit for humans and can contain \code{\#} comments
and are thus a good for configuration files.
file extensions of \code{.ini}, \code{.conf} and \code{.cfg} are common.
Astropy bundles \href{http://configobj.readthedocs.org/}{configobj} to read, write and validate
INI files ... to use it in your code
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{astropy.extern.configobj} \PYG{k+kn}{import} \PYG{n}{configobj}\PYG{p}{,} \PYG{n}{validate}
\end{Verbatim}
Unfortunately INI files are not standardised, so there's only conventions and tons of variants.
\paragraph{CSV}
\label{dataformats/file_formats:csv}\label{dataformats/file_formats:csv-files}
\textbf{CSV} files (see \href{http://en.wikipedia.org/wiki/Comma-separated\_values}{Wikipedia}),
store tables as comma-separated values (or tab or whitespace separated),
sometimes with the column names in the first row, sometimes with \code{\#} comments.
The good thing is that you can import and export data in CSV format from all spreadsheet
programs (e.g. \href{http://en.wikipedia.org/wiki/Microsoft\_Excel}{Microsoft Excel},
\href{http://en.wikipedia.org/wiki/Keynote\_(presentation\_software)}{Apple Keynote} or
\href{http://en.wikipedia.org/wiki/LibreOffice\_Calc}{LibreOffice Calc})
as well as astronomy table programs such as e.g.
\href{http://www.star.bris.ac.uk/~mbt/topcat/}{TOPCAT}.
Since it's a simple text format it's easy to read or edit in any text editor or
put under version control (using e.g. \href{http://git-scm.com/}{git} or
\href{http://en.wikipedia.org/wiki/Apache\_Subversion}{SVN}).
CSV files are not standardised (there's many variants which causes problems in practice),
don't support metadata (e.g. units or descriptions of columns).
A \href{http://dataprotocols.org/tabular-data-package/}{tabular data package format} has
been defined with a clear CSV format specification and associated metadata in an extra JSON file
(see also \href{https://github.com/astropy/astropy-APEs/pull/7}{here}).
To read and write CSV data from Python you can use the extensible \href{http://docs.astropy.org/en/latest/io/ascii/index.html\#module-astropy.io.ascii}{\code{astropy.io.ascii}} methods
via the \href{http://astropy.readthedocs.org/en/latest/io/unified.html}{unified Astropy table I/O interface}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{astropy.table} \PYG{k+kn}{import} \PYG{n}{Table}
\PYG{n}{table} \PYG{o}{=} \PYG{n}{Table}\PYG{o}{.}\PYG{n}{read}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{measurements.csv}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{format}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{csv}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{table}\PYG{o}{.}\PYG{n}{write}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{measurements.tex}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{format}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{latex}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\end{Verbatim}
There's also the
\href{http://pymotw.com/2/csv/}{Python standard library csv module} as well as the
\href{http://docs.scipy.org/doc/numpy/reference/routines.io.html\#text-files}{numpy text I/O methods} and the
\href{http://pandas.pydata.org/pandas-docs/stable/io.html}{pandas text I/O methods} ...
each have certain advantages / disadvantages (e.g. availability, features, speed).
\paragraph{JSON}
\label{dataformats/file_formats:json}
\textbf{JSON} files (see \href{http://en.wikipedia.org/wiki/JSON}{Wikipedia})
TODO: describe
\paragraph{XML}
\label{dataformats/file_formats:xml}
\textbf{XML} files (see \href{http://en.wikipedia.org/wiki/Xml}{Wikipedia})
GammaLib / ctools uses an ``observation definition'' XML format described
\href{http://cta.irap.omp.eu/gammalib-devel/user\_manual/modules/obs.html\#describing-observations-using-xml}{here}.
TODO: describe
\paragraph{FITS}
\label{dataformats/file_formats:fits}
\textbf{FITS} files (see \href{http://en.wikipedia.org/wiki/FITS}{Wikipedia})
TODO: describe
\paragraph{ROOT}
\label{dataformats/file_formats:root}
\textbf{ROOT} files (see \href{http://en.wikipedia.org/wiki/ROOT}{Wikipedia})
This is a binary serialisation format (see \href{http://root.cern.ch/root/html/TFile.html}{TFile})
that is very common for low-level data in high-energy physics and astronomy and for
computing and storing instrument response functions.
If only ROOT built-in objects like simple \href{http://root.cern.ch/root/html/TTree.html}{TTree} and
\href{http://root.cern.ch/root/html/TH1.html}{Histogram} objects are stored it is
possible to exchange those files and read them from C++, Python (via
\href{http://root.cern.ch/drupal/content/pyroot}{PyROOT} or \href{http://www.rootpy.org/}{rootpy}).
Access to your own serialised C++ objects is only possible if you distribute ROOT and
a C++ library ... but storing data this way is anyways a bad idea
(see e.g. \href{https://www.youtube.com/watch?v=7KnfGDajDQw}{here}).
TODO: give examples how to read / convert ROOT data (e.g. to FITS).
\paragraph{Other}
\label{dataformats/file_formats:other}
Other file formats that are very useful but not commonly used in gamma-ray astronomy (yet):
\begin{itemize}
\item {}
\textbf{HDF5} files (see \href{http://en.wikipedia.org/wiki/Hierarchical\_Data\_Format\#HDF5}{Wikipedia}).
Advantages over FITS: much faster for some applications,
more flexible metadata, more widespread use (not astro specific),
some tools for schema validation.
\item {}
There's a bunch of efficient and flexible binary data serialization formats, e.g.
\href{https://code.google.com/p/protobuf/}{Google Protobuf} or
\href{http://msgpack.org/}{MessagePack} or \href{http://bsonspec.org/}{BSON}.
\end{itemize}
TODO: describe that most of these formats are only being considered for low-level data
for CTA, e.g. shower image I/O can be much more efficient that with FITS variable-length columns.
\begin{itemize}
\item {}
Pickle: should never be used explicitly. But it is implicitly used by multiprocessing
for communication with subprocesses, so if you use that you care if your objects can be
pickled. (Do we care at all for Gammapy or is our policy that we don't support pickling
Gammapy objects?)
\item {}
\href{http://sqlite.org/}{SQLite} gives you a \href{http://en.wikipedia.org/wiki/SQL}{SQL}
database in memory or a simple file (no server, no configuration).
TODO: describe how it can be useful for pipeline processing (async I/O and easy select)
\end{itemize}
\subsubsection{Validation}
\label{dataformats/file_formats:validation}
\paragraph{What is it?}
\label{dataformats/file_formats:what-is-it}
When data and tools are deployed to users, it is necessary for the tools to validate the
input data and give good error messages when there is a problem.
The most common problems with user-edited input files
(e.g. INI config files or XML source model specifications or CSV runlists or ...)
is that the syntax is incorrect ... this will be noticed and reported by the
parser (e.g. a message like \code{"expected '=' after element ABC on line XYZ"}).
It's usually out of your control and the error message is good enough for the
user to quickly find and fix the problem.
The second most common problem with user-edited input files is that the structure
or content doesn't match the specification.
Also format specifications change over time and there are tools that generate
output with incorrect structure or content, so this is not only an issue for user-generated files.
Checking the structure (and where possible content) is the responsibility of
the tool author and can be done either by writing a schema or code.
If you don't know what a schema is, please take a few minutes to read about it
\href{http://spacetelescope.github.io/understanding-json-schema/about.html}{here}
using JSON as an example, I won't try to explain it here.
\paragraph{Existing Tools}
\label{dataformats/file_formats:existing-tools}
TODO: Link collection and very short description of existing format and schema validation tools.
\begin{itemize}
\item {}
ftverify
\end{itemize}
The following tools are available for schema validation of the file formats listed above
(with a strong emphasis on Python tools):
\begin{itemize}
\item {}
INI
\item {}
CSV
\item {}
JSON
\item {}
XML
\item {}
FITS
\item {}
ROOT
\item {}
HDF5
\end{itemize}
\href{https://pypi.python.org/pypi/CsvSchema/}{CSV schema}
use of such schemas
\begin{itemize}
\item {}
\href{http://embray.github.io/PyFITS/schema/users\_guide/users\_schema.html}{http://embray.github.io/PyFITS/schema/users\_guide/users\_schema.html}
\item {}
\href{https://groups.google.com/d/msg/astropy-dev/CFGnVguRlgs/yObfzPTWvNkJ}{https://groups.google.com/d/msg/astropy-dev/CFGnVguRlgs/yObfzPTWvNkJ}
\item {}
\href{http://spacetelescope.github.io/understanding-json-schema/index.html}{http://spacetelescope.github.io/understanding-json-schema/index.html}
\end{itemize}
\paragraph{With Gammapy}
\label{dataformats/file_formats:with-gammapy}
TODO: Implement \code{gp\_verify} tool that can check the most common gamma-ray
data formats (e.g. event lists, ...).
\subsubsection{Useful links}
\label{dataformats/file_formats:useful-links}\begin{itemize}
\item {}
\href{http://sedfitter.readthedocs.org/en/stable/creating\_model\_packages.html\#sed-files}{http://sedfitter.readthedocs.org/en/stable/creating\_model\_packages.html\#sed-files}
\item {}
\href{http://fits.gsfc.nasa.gov/fits\_registry.html}{http://fits.gsfc.nasa.gov/fits\_registry.html}
\end{itemize}
\subsection{Event lists}
\label{dataformats/events:astropy}\label{dataformats/events::doc}\label{dataformats/events:dataformats-events}\label{dataformats/events:event-lists}
\subsubsection{\texttt{EVENTS} extension}
\label{dataformats/events:events-extension}
TODO: describe
\subsubsection{\texttt{GTI} extension}
\label{dataformats/events:gti-extension}
\href{http://heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/rates/ogip\_93\_003/ogip\_93\_003.html\#tth\_sEc6.3}{GTI description in OGIP standard}.
TODO: describe where GTIs are used.
\subsection{Maps}
\label{dataformats/maps:dataformats-maps}\label{dataformats/maps:astropy}\label{dataformats/maps::doc}\label{dataformats/maps:maps}\begin{itemize}
\item {}
\code{counts}
\item {}
\code{background} --- measured or modeled background estimate (counts per bin)
\item {}
\code{exposure} --- gamma-ray exposure
Exposure maps should contain the following header keywords:
* \code{EXP\_GAMMA} --- power law spectral index assumed in the exposure computation
* \code{UNITS} --- require cm\textasciicircum{}-2 sec\textasciicircum{}-1 or be flexible
* \code{E\_MIN}
\end{itemize}
TODO:
* exposure maps should have:
\subsection{Cubes}
\label{dataformats/cubes:cubes}\label{dataformats/cubes:astropy}\label{dataformats/cubes::doc}\label{dataformats/cubes:dataformats-cubes}
Everything that was said for maps also applies here.
TODO: give info how to specify energy axis.
(same as Fermi format)
\subsection{Spectra}
\label{dataformats/spectra:dataformats-spectra}\label{dataformats/spectra:spectra}\label{dataformats/spectra:astropy}\label{dataformats/spectra::doc}
The term \code{spectrum} is used for many different things by different people...
\subsubsection{Flux points}
\label{dataformats/spectra:flux-points}\begin{itemize}
\item {}
\code{ENERGY}, \code{ENERGY\_LO}, \code{ENERGY\_HI} with arbitrary units
\item {}
\code{FLUX}, \code{FLUX\_ERR\_LO}, \code{FLUX\_ERR\_HI} with arbitrary units
\end{itemize}
\subsubsection{Counts, effective area, energy resolution}
\label{dataformats/spectra:counts-effective-area-energy-resolution}
Use OGIP (TODO: links) \code{xspec} data formats:
\begin{itemize}
\item {}
Counts data: PHA files
\item {}
Effective area: ARF files
\item {}
Energy resolution: RMF files
\end{itemize}
\subsection{Lightcurves}
\label{dataformats/lightcurves:astropy}\label{dataformats/lightcurves::doc}\label{dataformats/lightcurves:dataformats-lightcurves}\label{dataformats/lightcurves:lightcurves}
TODO: Are there any standard formats for light curves?
TODO: Should we support this?
\begin{itemize}
\item {}
Monthly light-curves in the Fermi catalogs
\item {}
\href{http://fermi.gsfc.nasa.gov/ssc/data/access/lat/4yr\_catalog/ap\_lcs.php}{http://fermi.gsfc.nasa.gov/ssc/data/access/lat/4yr\_catalog/ap\_lcs.php}
\item {}
\href{https://github.com/gammapy/gammapy/issues/281}{https://github.com/gammapy/gammapy/issues/281}
\end{itemize}
\subsection{Point spread function}
\label{dataformats/psf:astropy}\label{dataformats/psf::doc}\label{dataformats/psf:dataformats-psf}\label{dataformats/psf:point-spread-function}\begin{itemize}
\item {}
\href{http://fermi.gsfc.nasa.gov/ssc/data/analysis/scitools/help/gtpsf.txt}{gtpsf} format can be read with {\hyperref[api/gammapy.irf.EnergyDependentTablePSF:gammapy.irf.EnergyDependentTablePSF]{\emph{\code{gammapy.irf.EnergyDependentTablePSF}}}}.
\end{itemize}
\subsection{Observation lists}
\label{dataformats/observation_lists:observation-lists}\label{dataformats/observation_lists:astropy}\label{dataformats/observation_lists::doc}\label{dataformats/observation_lists:dataformats-observation-lists}
Run lists specify a list of observation runs to be processed by a given tool.
In the end the tool will usually generate input and output data filenames from
the information in the run list. These filenames can either be given directly
or there can be naming conventions, e.g. the event list for run \code{42} could be stored
at \code{\$TEV\_DATA/RUN\_000042/Events.fits}.
A run list must have at least a column called \code{OBS\_ID}:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{OBS\PYGZus{}ID}
\PYG{l+m+mi}{42}
\PYG{l+m+mi}{43}
\end{Verbatim}
Usually it has many more columns with information about each observation. A list of
Gammapy supported columns is:
\begin{tabulary}{\linewidth}{|L|L|L|}
\hline
\textsf{\relax
column name
} & \textsf{\relax
description
} & \textsf{\relax
required?
}\\
\hline
OBS\_ID
&
observation ID as an integer
&
yes
\\
\hline
RA
&
pointing position right ascension in equatorial (ICRS) coordinates
&
yes?
\\
\hline
DEC
&
pointing position declination in equatorial (ICRS) coordinates
&
yes?
\\
\hline
AZ
&
average azimuth angle during the observation
&
no
\\
\hline
ALT
&
average altitude angle during the observation
&
no
\\
\hline
MUON\_EFFICIENCY
&
average muon efficiency of the telescopes
&
yes?
\\
\hline
TIME\_START
&
start time of the observation stored as number of seconds after \phantomsection\label{dataformats/observation_lists:id1}{\hyperref[references:met]{\emph{{[}MET{]}}}}
&
yes?
\\
\hline
TIME\_STOP
&
end time of the observation in the same format as TIME\_START
&
no
\\
\hline
TIME\_OBSERVATION
&
duration of the observation
&
no
\\
\hline
TIME\_LIVE
&
duration of the observation without dead time
&
no
\\
\hline
TRIGGER\_RATE
&
average trigger rate of the system
&
no
\\
\hline
MEAN\_TEMPERATURE
&
average temperature of the atmosphere
&
no
\\
\hline
N\_TELS
&
number of telescopes participating in the observation
&
yes?
\\
\hline
TEL\_LIST
&
string with a \phantomsection\label{dataformats/observation_lists:id2}{\hyperref[references:csv]{\emph{{[}CSV{]}}}} list of telescope IDs participating in the observation
&
yes?
\\
\hline
QUALITY
&
data quality; recommended: ``spectral'' or ``detection''
&
no
\\
\hline\end{tabulary}
Extra user-defined columns are allowed; Gammapy will ignore them.
In order for the extra columns to have full meaning the following is needed:
\begin{itemize}
\item {}
Extra row right after the column name, specifying the unit of the quantity listed on each column.
\item {}
A header with at least the following keywords:
\end{itemize}
\begin{tabulary}{\linewidth}{|L|L|L|}
\hline
\textsf{\relax
keyword
} & \textsf{\relax
description
} & \textsf{\relax
required?
}\\
\hline
OBSERVATORY\_NAME
&
name of the observatory where the observations were taken. This is
important for instance for coordinate transformations between celestial
(i.e. RA/dec) and terrestrial (i.e. az/alt) coordinate systems.
&
no
\\
\hline
MJDREFI
&
reference time: integer value in mean julian days; details in
{\hyperref[time/index:time-handling]{\emph{\DUspan{}{Time handling in Gammapy}}}}.
&
yes?
\\
\hline
MJDREFF
&
reference time: fraction of integer value defined in MJDREFI; details in
{\hyperref[time/index:time-handling]{\emph{\DUspan{}{Time handling in Gammapy}}}}.
&
yes?
\\
\hline\end{tabulary}
Extra user-defined header entries are allowed; Gammapy will ignore them.
\subsubsection{Example}
\label{dataformats/observation_lists:example}
The tool {\hyperref[api/gammapy.datasets.make_test_observation_table:gammapy.datasets.make_test_observation_table]{\emph{\code{make\_test\_observation\_table}}}} can generate a {\hyperref[api/gammapy.obs.ObservationTable:gammapy.obs.ObservationTable]{\emph{\code{ObservationTable}}}}
with dummy values.
Header (metadata):
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{p}{\PYGZob{}}\PYG{l+s}{u\PYGZsq{}}\PYG{l+s}{MJDREFI}\PYG{l+s}{\PYGZsq{}}\PYG{p}{:} \PYG{l+m+mf}{55197.0}\PYG{p}{,} \PYG{l+s}{u\PYGZsq{}}\PYG{l+s}{OBSERVATORY\PYGZus{}NAME}\PYG{l+s}{\PYGZsq{}}\PYG{p}{:} \PYG{l+s}{u\PYGZsq{}}\PYG{l+s}{HESS}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{l+s}{u\PYGZsq{}}\PYG{l+s}{MJDREFF}\PYG{l+s}{\PYGZsq{}}\PYG{p}{:} \PYG{l+m+mf}{0.0}\PYG{p}{\PYGZcb{}}
\end{Verbatim}
Table:
\begin{tabulary}{\linewidth}{|L|L|L|L|L|L|L|L|L|L|L|}
\hline
\textsf{\relax
OBS\_ID
} & \textsf{\relax
TIME\_OBSERVATION
} & \textsf{\relax
TIME\_LIVE
} & \textsf{\relax
TIME\_START
} & \textsf{\relax
TIME\_STOP
} & \textsf{\relax
AZ
} & \textsf{\relax
ALT
} & \textsf{\relax
RA
} & \textsf{\relax
DEC
} & \textsf{\relax
N\_TELS
} & \textsf{\relax
MUON\_EFFICIENCY
}\\
\hline\textsf{\relax } & \textsf{\relax
s
} & \textsf{\relax
s
} & \textsf{\relax
s
} & \textsf{\relax
s
} & \textsf{\relax
deg
} & \textsf{\relax
deg
} & \textsf{\relax
deg
} & \textsf{\relax
deg
} & \textsf{\relax } & \textsf{\relax }\\
\hline
1
&
1800.0
&
1500.0
&
118890428.352
&
118892228.352
&
130.926874751
&
49.6209457026
&
96.3849089136
&
-43.6914197077
&
3
&
0.814535992712
\\
\hline
2
&
1800.0
&
1500.0
&
112242990.559
&
112244790.559
&
272.213179564
&
70.2673929472
&
339.00128923
&
-21.1698098192
&
3
&
0.976469816749
\\
\hline
3
&
1800.0
&
1500.0
&
66444741.854
&
66446541.854
&
346.848818939
&
46.138583188
&
162.086175054
&
19.6398873974
&
4
&
0.920096961383
\\
\hline
4
&
1800.0
&
1500.0
&
22388716.9244
&
22390516.9244
&
300.850748052
&
55.1330124055
&
32.9474858892
&
-3.19910057294
&
3
&
0.678431411337
\\
\hline
5
&
1800.0
&
1500.0
&
135469063.888
&
135470863.888
&
355.160931662
&
48.734744852
&
197.123663537
&
17.9411145072
&
4
&
0.77879533822
\\
\hline
6
&
1800.0
&
1500.0
&
21857681.6916
&
21859481.6916
&
124.846967209
&
78.859585347
&
14.162859563
&
-29.3419432185
&
4
&
0.709642622408
\\
\hline
7
&
1800.0
&
1500.0
&
57554741.106
&
57556541.106
&
268.541714486
&
48.8489560299
&
64.8265458802
&
-18.2634404823
&
3
&
0.908426763354
\\
\hline
8
&
1800.0
&
1500.0
&
19181027.9045
&
19182827.9045
&
120.558129392
&
49.663761361
&
24.791511978
&
-37.1789681608
&
4
&
0.980162662473
\\
\hline
9
&
1800.0
&
1500.0
&
120447694.583
&
120449494.583
&
132.10271454
&
78.7455993174
&
89.7950895353
&
-30.5128854184
&
3
&
0.807695978946
\\
\hline
10
&
1800.0
&
1500.0
&
144207430.361
&
144209230.361
&
323.562657045
&
45.4005803262
&
324.596045439
&
13.6761217326
&
3
&
0.694201696626
\\
\hline\end{tabulary}
\subsection{Source models}
\label{dataformats/source_models:astropy}\label{dataformats/source_models::doc}\label{dataformats/source_models:source-models}\label{dataformats/source_models:dataformats-source-models}
TODO: Explain why there are different formats and give converter functions / tools.
\subsubsection{XML file format}
\label{dataformats/source_models:xml-file-format}
GammaLib / ctools uses an ``model definition'' XML format described
\href{http://gammalib.sourceforge.net/user\_manual/modules/model.html\#overview}{here}
The Fermi \code{gtlike} tool uses the same format (the implemented models are a bit different) described
\href{http://fermi.gsfc.nasa.gov/ssc/data/analysis/scitools/source\_models.html}{here}
The same format is used by \code{ctlike} and \code{gtlike} to report the model fit results,
which has the serious draw-back that useful information like the fit covariance matrix, asymmetric errors
or numbers like the fit statistic or predicted number of counts are not output
in a machine-readable format.
\subsubsection{Configuration format}
\label{dataformats/source_models:configuration-format}
TODO: document
\subsubsection{JSON format}
\label{dataformats/source_models:json-format}
TODO: document via a JSON schema.
\subsection{Target lists}
\label{dataformats/target_lists:astropy}\label{dataformats/target_lists::doc}\label{dataformats/target_lists:target-lists}\label{dataformats/target_lists:dataformats-target-lists}
There are some Gammapy tools that run analyses in batch mode,
and to simplify this we define a simple CSV ``target list'' format here.
A typical application is that there are many (potential) target positions to analyse,
but the ``target list'' could also contain the same target position several times,
varying other parameters.
\subsubsection{CSV format}
\label{dataformats/target_lists:csv-format}
We use the \href{http://en.wikipedia.org/wiki/Comma-separated\_values}{CSV} (comma-separated values) format for target lists.
A target list must have at least a column called \code{Number} with unique entries:
\begin{Verbatim}[commandchars=\\\{\}]
Number
42
43
\end{Verbatim}
Usually it has many more columns with information about each target:
\begin{Verbatim}[commandchars=\\\{\}]
Number,Name,RA,DEC
42,Crab,83.633212,22.014460
\end{Verbatim}
Special column names that the Gammapy batch processing tools understand:
\begin{itemize}
\item {}
\code{Number} --- Target number
\item {}
\code{Name} --- Target name
\item {}
\code{RA}, \code{DEC} or \code{GLON}, \code{GLAT} -- Target position in Equatorial (ICRS) or Galactic coordinates (deg)
\item {}
\code{Theta} --- Source region radius (deg)
\item {}
\code{FOV} --- Field of view radius (deg)
\end{itemize}
Usually there will be other, tool-specific parameter columns.
\chapter{References}
\label{references:references}\label{references:id1}\label{references:astropy}\label{references::doc}
\section{Publications}
\label{references:publications}\label{references:id2}
This is the bibliography containing the literature references for the implemented methods
referenced from the Gammapy docs.
The best reference to TeV data analysis is Chapter 7 of Mathieu de Naurois's habilitation thesis.
Software references:
\section{Glossary}
\label{references:id3}\label{references:glossary}
\chapter{Credit}
\label{credit:id1}\label{credit:astropy}\label{credit::doc}\label{credit:credit}
This is a short summary of who contributed what to Gammapy.
\begin{itemize}
\item {}
Christoph Deil (MPIK Heidelberg) started Gammapy in 2013 and is maintaining it.
\item {} \begin{description}
\item[{Contributions by Axel Donath (MPIK Heidelberg):}] \leavevmode\begin{itemize}
\item {}
Some code committed by Christoph Deil (e.g. functionality in {\hyperref[image/index:module-gammapy.image]{\emph{\code{gammapy.image}}}})
are actually code written by Axel for his bachelor and master's thesis.
\item {}
Various image analysis and simulation functionality.
\end{itemize}
\end{description}
\item {}
Martin Raue (DESY, Hamburg) wrote \href{http://pyfact.readthedocs.org/en/latest/}{PyFACT} in 2012 to prototype FITS gamma-ray
data analysis as part of the first CTA data challenge.
Martin has left astronomy and the last commit for PyFACT was in June 2012.
In February 2014 Christoph Deil integrated the PyFACT functionality in Gammapy
(see \href{https://github.com/gammapy/gammapy/pull/68}{GH PR 68}
for details which parts of Gammapy originate from PyFACT).
\end{itemize}
For further information see the \href{https://github.com/gammapy/gammapy/graphs/contributors}{Gammapy contributors page on Github}
and the \href{https://www.openhub.net/p/gammapy}{Gammapy project summary on Open HUB}.
Note that because Gammapy started out as a fork of the
\href{https://github.com/astropy/package-template}{Astropy affiliated package template},
the automatic contributors summary on Github and Ohloh is not accurate in the sense
that it contains the contributions to the (non-Gammapy-specific) Astropy affiliated project template.
\chapter{Development}
\label{development/index:id2}\label{development/index:development}\label{development/index:id1}\label{development/index::doc}
This page is a collection of notes for Gammapy developers and maintainers.
Note that Astropy has very extensive developer documentation
\href{http://astropy.readthedocs.org/en/latest/\#developer-documentation}{here},
this page should only mention Gammapy-specific things.
\section{How to clean up old files}
\label{development/index:make-clean}\label{development/index:how-to-clean-up-old-files}
Many projects have a \code{Makefile} to build and install the software and do all kinds of other tasks.
In Astropy and Gammapy and most Python projects, there is no \code{Makefile}, but the \code{setup.py} file
and you're supposed to type \code{python setup.py \textless{}cmd\textgreater{}} and use \code{-{-}help} and \code{-{-}help-commands} to
see all the available commands and options.
There's one common task, cleaning up old generated files, that's not done via \code{setup.py}.
The equivalent of \code{make clean} is:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }rm \PYGZhy{}r build docs/\PYGZus{}build docs/api htmlcov
\end{Verbatim}
These folders only contain generated files and are always safe to delete!
Most of the time you don't have to delete them, but if you e.g. remove or rename files or functions / classes,
then you should, because otherwise the old files will still be around and you might get confusing results,
such as Sphinx warnings or import errors or code that works locally because it uses old things, but fails
on travis-ci or for other developers.
\begin{itemize}
\item {}
The \code{build} folder is where \code{python setup.py build} or \code{python setup.py install} generate files.
\item {}
The \code{docs/api} folder is where \code{python setup.py build\_sphinx} generates \phantomsection\label{development/index:id2}{\hyperref[references:rst]{\emph{{[}RST{]}}}} files from the docstrings
(temporary files part of the HTML documentation generation).
\item {}
The \code{docs/\_build} folder is where \code{python setup.py build\_sphinx} generates the HTML and other Sphinx
documentation output files.
\item {}
The \code{htmlcov} folder is where \code{python setup.py test -{-}coverage} generates the HTML coverage report.
\end{itemize}
If you use \code{python setup.py build\_ext -{-}inplace}, then files are generated in the \code{gammapy} source folder.
Usually that's not a problem, but if you want to clean up those generated files, you can use
\href{http://git-scm.com/docs/git-clean}{git clean}:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }git status
\PYG{c}{\PYGZsh{} The following command will remove all untracked files!}
\PYG{c}{\PYGZsh{} If you have written code that is not committed yet in a new file it will be gone!}
\PYG{c}{\PYGZsh{} So use with caution!}
\PYG{n+nv}{\PYGZdl{} }git clean \PYGZhy{}fdx
\end{Verbatim}
At least for now we prefer not to add a \code{Makefile} to Gammapy, because that splits the developers into
those that use \code{setup.py} and those that use \code{make}, which can grow into an overall \textbf{more} complicated
system where some things are possible only with \code{setup.py} and others only with \code{make}.
\section{Where should I import from?}
\label{development/index:development-import-from}\label{development/index:where-should-i-import-from}
You should import from the ``end-user namespaces'', not the ``implementation module''.
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.data} \PYG{k+kn}{import} \PYG{n}{EventList} \PYG{c}{\PYGZsh{} good}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.data.event\PYGZus{}list} \PYG{k+kn}{import} \PYG{n}{EventList} \PYG{c}{\PYGZsh{} bad}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.stats} \PYG{k+kn}{import} \PYG{n}{cash} \PYG{c}{\PYGZsh{} good}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.stats.fit\PYGZus{}statistics} \PYG{k+kn}{import} \PYG{n}{cash} \PYG{c}{\PYGZsh{} bad}
\end{Verbatim}
The end-user namespace is the location that is shown in the API docs, i.e. you can
use the Sphinx full-text search to quickly find it.
To make code maintenance easier, the implementation of the functions and classes is
spread across multiple modules (\code{.py} files), but the user shouldn't care about their
names, that would be too much to remember.
The only reason to import from a module directly is if you need to access a private
function, class or variable (something that is not listed in \code{\_\_all\_\_} and thus not
imported into the end-user namespace.
Note that this means that in the definition of an ``end-user namespace'', e.g. in the
\code{gammapy/data/\_\_init\_\_.py} file, the imports have to be sorted in a way such that
modules in \code{gammapy/data} are loaded when imported from other modules in that sub-package.
\section{Why we don't sub-class other data classes}
\label{development/index:development-data-subclasses}\label{development/index:why-we-don-t-sub-class-other-data-classes}
We have considered re-using data classes developed by others,
namely \href{http://docs.astropy.org/en/latest/api/astropy.nddata.NDData.html\#astropy.nddata.NDData}{\code{NDData}} and the
\href{http://spectral-cube.readthedocs.org/en/latest/index.html}{spectral\_cube.SpectralCube}
classes.
But in both cases, the data model didn't really fit our use cases for gamma-ray astronomy
and so we decided to write our own data classes from scratch.
Here's some issues where this was discussed:
\begin{itemize}
\item {}
\href{https://github.com/radio-astro-tools/spectral-cube/issues/110}{https://github.com/radio-astro-tools/spectral-cube/issues/110}
\item {}
\href{https://github.com/astropy/astropy/pull/2855\#issuecomment-52610106}{https://github.com/astropy/astropy/pull/2855\#issuecomment-52610106}
\end{itemize}
\section{Functions returning several values}
\label{development/index:development-result-object}\label{development/index:functions-returning-several-values}
Functions that return more than a single value shouldn't return a list
or dictionary of values but rather a Python Bunch result object. A Bunch
is similar to a dict, except that it allows attribute access to the result
values. The approach is the same as e.g. the use of \href{http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.OptimizeResult.html\#scipy.optimize.OptimizeResult}{\code{OptimizeResult}}.
An example of how Bunches are used in gammapy is given by the {\hyperref[api/gammapy.detect.TSMapResult:gammapy.detect.TSMapResult]{\emph{\code{TSMapResult}}}}
class.
\section{Python 2 and 3 support}
\label{development/index:development-python2and3}\label{development/index:python-2-and-3-support}
We support Python 2.7 and 3.3 or later using a single code base.
This is the strategy adopted by most scientific Python projects and a good starting point to learn about it is
\href{http://python3porting.com/noconv.html}{here} and
\href{http://astropy.readthedocs.org/en/latest/development/codeguide.html\#writing-portable-code-for-python-2-and-3}{here}.
For developers, it would have been nice to only support Python 3 in Gammapy.
But the CIAO and Fermi Science tools software are distributed with Python 2.7
and probably never will be updated to Python 3.
Plus many potential users will likely keep running on Python 2.7 for many years
(see e.g. \href{http://ipython.org/usersurvey2013.html\#python-versions}{this survey}).
The decision to drop Python 2.6 and 3.2 support was made in August 2014 just before the Gammapy 0.1 release,
based on a few scientific Python user surveys on the web that show that only a small minority are still
using such an old version, so that it's not worth the developer and maintainer effort to test
these old versions and to find workarounds for their missing features or bugs.
\section{Wipe readthedocs}
\label{development/index:development-wipe-readthedocs}\label{development/index:wipe-readthedocs}
As described \href{http://read-the-docs.readthedocs.org/en/latest/builds.html\#deleting-a-stale-or-broken-build-environment}{here},
if the docs on readthedocs show old stuff, you need to first log in \href{https://readthedocs.org/accounts/login/}{here}
and then wipe it to create a fresh / clean version by hitting this URL:
\begin{Verbatim}[commandchars=\\\{\}]
http://readthedocs.org/wipe/gammapy/latest/
\end{Verbatim}
and then clicking the ``wipe version'' button.
You don't get a confirmation that the wipe has taken place, but you can check
\href{https://readthedocs.org/builds/gammapy/}{here} (wait a few minutes)
and if needed manually start a new build by going
\href{https://readthedocs.org/projects/gammapy/}{here} and clicking the ``Build'' button.
\section{Skip unit tests for some Astropy versions}
\label{development/index:development-skip-tests}\label{development/index:skip-unit-tests-for-some-astropy-versions}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{astropy}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.tests.helper} \PYG{k+kn}{import} \PYG{n}{pytest}
\PYG{n}{ASTROPY\PYGZus{}VERSION} \PYG{o}{=} \PYG{p}{(}\PYG{n}{astropy}\PYG{o}{.}\PYG{n}{version}\PYG{o}{.}\PYG{n}{major}\PYG{p}{,} \PYG{n}{astropy}\PYG{o}{.}\PYG{n}{version}\PYG{o}{.}\PYG{n}{minor}\PYG{p}{)}
\PYG{n+nd}{@pytest.mark.xfail}\PYG{p}{(}\PYG{n}{ASTROPY\PYGZus{}VERSION} \PYG{o}{\PYGZlt{}} \PYG{p}{(}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{l+m+mi}{4}\PYG{p}{)}\PYG{p}{,} \PYG{n}{reason}\PYG{o}{=}\PYG{l+s}{\PYGZdq{}}\PYG{l+s}{Astropy API change}\PYG{l+s}{\PYGZdq{}}\PYG{p}{)}
\PYG{k}{def} \PYG{n+nf}{test\PYGZus{}something}\PYG{p}{(}\PYG{p}{)}\PYG{p}{:}
\PYG{o}{.}\PYG{o}{.}\PYG{o}{.}
\end{Verbatim}
\section{Fix non-Unix line endings}
\label{development/index:fix-non-unix-line-endings}\label{development/index:development-check-html-links}
In the past we had non-Unix (i.e. Mac or Windows) line endings in some files.
This can be painful, e.g. git diff and autopep8 behave strangely.
Here's to commands to check for and fix this (see \href{http://stackoverflow.com/a/22521008/498873}{here}):
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }git clean \PYGZhy{}fdx
\PYG{n+nv}{\PYGZdl{} }find . \PYGZhy{}type f \PYGZhy{}print0 \PYG{p}{\textbar{}} xargs \PYGZhy{}0 \PYGZhy{}n \PYG{l+m}{1} \PYGZhy{}P \PYG{l+m}{4} dos2unix \PYGZhy{}c mac
\PYG{n+nv}{\PYGZdl{} }find . \PYGZhy{}type f \PYGZhy{}print0 \PYG{p}{\textbar{}} xargs \PYGZhy{}0 \PYGZhy{}n \PYG{l+m}{1} \PYGZhy{}P \PYG{l+m}{4} dos2unix \PYGZhy{}c ascii
\PYG{n+nv}{\PYGZdl{} }git status
\PYG{n+nv}{\PYGZdl{} }\PYG{n+nb}{cd }astropy\PYGZus{}helpers \PYG{o}{\PYGZam{}\PYGZam{}} git checkout \PYGZhy{}\PYGZhy{} . \PYG{o}{\PYGZam{}\PYGZam{}} \PYG{n+nb}{cd} ..
\end{Verbatim}
\section{Check HTML links}
\label{development/index:check-html-links}
There's two ways to check the docs for broken links.
This will check external links (not nice because you have to install first):
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }python setup.py install
\PYG{n+nv}{\PYGZdl{} }\PYG{n+nb}{cd }docs\PYG{p}{;} make linkcheck
\end{Verbatim}
To check all internal and external links use this \href{https://github.com/wummel/linkchecker}{linkchecker}:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }pip install linkchecker
\PYG{n+nv}{\PYGZdl{} }linkchecker \PYGZhy{}\PYGZhy{}check\PYGZhy{}extern docs/\PYGZus{}build/html/index.html
\end{Verbatim}
Because Sphinx doesn't warn about some broken internal links for some reason,
we run \code{linkchecker docs/\_build/html/index.html} on travis-ci,
but not with the \code{-{-}check-extern} option as that would probably fail
randomly quite often whenever one of the external websites is down.
\section{Make a Gammapy release}
\label{development/index:development-release-gammapy}\label{development/index:make-a-gammapy-release}
To make a Gammapy release, follow the instructions how to release an Astropy affiliated package
\href{http://astropy.readthedocs.org/en/latest/development/affiliated-packages.html\#releasing-an-affiliated-package}{here}.
Here's some additional notes / things to check:
\begin{itemize}
\item {}
Check external HTML links (see {\hyperref[development/index:development-check-html-links]{\emph{\DUspan{}{here}}}}).
\item {}
Update the Gammapy version number on the {\hyperref[index:gammapy-welcome]{\emph{\DUspan{}{What is Gammapy?}}}} section and the {\hyperref[install:install]{\emph{\DUspan{}{Installation}}}} section.
\item {}
Mention release in the {\hyperref[index:gammapy-news]{\emph{\DUspan{}{News}}}} section.
\item {}
After making the tag and release, update the Gammapy stable branch to point to the new tag
as described \href{http://astropy.readthedocs.org/en/latest/development/releasing.html}{here}.
\end{itemize}
After doing the release, check these things:
\begin{itemize}
\item {}
Check that the tarball and description (which is from \code{LONG\_DESCRIPTION.rst}) on PyPI is OK.
\item {}
Check that the new release shows up OK on readthedocs.
\item {}
Check \href{https://github.com/gammapy/gammapy/tags}{here} that the release tag is present on Github
\item {}
Send announcement to Gammapy mailing list, Astropy mailing list and Twitter.
\end{itemize}
\section{Other codes}
\label{development/index:other-codes}
These projects are on Github, which is great because
it has full-text search and git history view:
\begin{itemize}
\item {}
\href{https://github.com/gammapy/gammapy}{https://github.com/gammapy/gammapy}
\item {}
\href{https://github.com/gammapy/gammapy-extra}{https://github.com/gammapy/gammapy-extra}
\item {}
\href{https://github.com/astropy/astropy}{https://github.com/astropy/astropy}
\item {}
\href{https://github.com/astropy/photutils}{https://github.com/astropy/photutils}
\item {}
\href{https://github.com/gammalib/gammalib}{https://github.com/gammalib/gammalib}
\item {}
\href{https://github.com/ctools/ctools}{https://github.com/ctools/ctools}
\item {}
\href{https://github.com/sherpa/sherpa}{https://github.com/sherpa/sherpa}
\item {}
\href{https://github.com/zblz/naima}{https://github.com/zblz/naima}
\item {}
\href{https://github.com/woodmd/gammatools}{https://github.com/woodmd/gammatools}
\item {}
\href{https://github.com/fermiPy/fermipy}{https://github.com/fermiPy/fermipy}
\item {}
\href{https://github.com/kialio/VHEObserverTools}{https://github.com/kialio/VHEObserverTools}
\item {}
\href{https://github.com/taldcroft/xrayevents}{https://github.com/taldcroft/xrayevents}
\end{itemize}
These are unofficial, unmaintained copies on open codes on Github:
\begin{itemize}
\item {}
\href{https://github.com/Xarthisius/yt-drone}{https://github.com/Xarthisius/yt-drone}
\item {}
\href{https://github.com/cdeil/Fermi-ScienceTools-mirror}{https://github.com/cdeil/Fermi-ScienceTools-mirror}
\item {}
\href{https://github.com/cdeil/kapteyn-mirror}{https://github.com/cdeil/kapteyn-mirror}
\end{itemize}
\section{What checks and conversions should I do for inputs?}
\label{development/index:what-checks-and-conversions-should-i-do-for-inputs}
In Gammapy we assume that
\href{https://mail.python.org/pipermail/tutor/2003-October/025932.html}{``we're all consenting adults''},
which means that when you write a function you should write it like this:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{do\PYGZus{}something}\PYG{p}{(}\PYG{n}{data}\PYG{p}{,} \PYG{n}{option}\PYG{p}{)}\PYG{p}{:}
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}Do something.}
\PYG{l+s+sd}{ Parameters}
\PYG{l+s+sd}{ \PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}}
\PYG{l+s+sd}{ data : {}`numpy.ndarray{}`}
\PYG{l+s+sd}{ Data}
\PYG{l+s+sd}{ option : \PYGZob{}\PYGZsq{}this\PYGZsq{}, \PYGZsq{}that\PYGZsq{}\PYGZcb{}}
\PYG{l+s+sd}{ Option}
\PYG{l+s+sd}{ \PYGZdq{}\PYGZdq{}\PYGZdq{}}
\PYG{k}{if} \PYG{n}{option} \PYG{o}{==} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{this}\PYG{l+s}{\PYGZsq{}}\PYG{p}{:}
\PYG{n}{out} \PYG{o}{=} \PYG{l+m+mi}{3} \PYG{o}{*} \PYG{n}{data}
\PYG{k}{elif} \PYG{n}{option} \PYG{o}{==} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{that}\PYG{l+s}{\PYGZsq{}}\PYG{p}{:}
\PYG{n}{out} \PYG{o}{=} \PYG{n}{data} \PYG{o}{*}\PYG{o}{*} \PYG{l+m+mi}{5}
\PYG{k}{else}\PYG{p}{:}
\PYG{n+ne}{ValueError}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Invalid option: \PYGZob{}\PYGZcb{}}\PYG{l+s}{\PYGZsq{}}\PYG{o}{.}\PYG{n}{format}\PYG{p}{(}\PYG{n}{option}\PYG{p}{)}\PYG{p}{)}
\PYG{k}{return} \PYG{n}{out}
\end{Verbatim}
\begin{itemize}
\item {}
\textbf{Don't always add {}`isinstance{}` checks for everything} ... assume the caller passes valid inputs,
... in the example above this is not needed:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{assert} \PYG{n+nb}{isinstance}\PYG{p}{(}\PYG{n}{option}\PYG{p}{,} \PYG{n+nb}{str}\PYG{p}{)}
\end{Verbatim}
\item {}
\textbf{Don't always add {}`numpy.asanyarray{}` calls for all array-like inputs} ... the caller can do this if
it's really needed ... in the example above document \code{data} as type \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
instead of array-like and don't put this line:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{data} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{asanyarray}\PYG{p}{(}\PYG{n}{data}\PYG{p}{)}
\end{Verbatim}
\item {}
\textbf{Do always add an {}`else{}` clause to your {}`if{}`-{}`elif{}` clauses} ... this is boilerplate code,
but not adding it would mean users get this error if they pass an invalid option:
\begin{Verbatim}[commandchars=\\\{\}]
UnboundLocalError: local variable \PYGZsq{}out\PYGZsq{} referenced before assignment
\end{Verbatim}
\end{itemize}
Now if you really want, you can add the \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.asanyarray.html\#numpy.asanyarray}{\code{numpy.asanyarray}} and \href{http://docs.python.org/library/functions.html\#isinstance}{\code{isinstance}} checks
for functions that end-users might often use for interactive work to provide them with
better exception messages, but doing it everywhere would mean 1000s of lines of boilerplate
code and take the fun out of Python programming.
\section{Float data type: 32 bit or 64 bit?}
\label{development/index:float-data-type-32-bit-or-64-bit}
Most of the time what we want is to use 32 bit to store data on disk and 64 bit to do
computations in memory.
Using 64 bit to store data and results (e.g. large images or cubes) on disk would mean
a factor \textasciitilde{}2 increase in file sizes and slower I/O, but I'm not aware of any case
where we need that precision.
On the other hand, doing computations with millions and billions of pixels very frequently
results in inaccurate results ... e.g. the likelihood is the sum over per-pixel likelihoods
and using 32-bit will usually result in erratic and hard-to-debug optimizer behaviour
and even if the fit works incorrect results.
Now you shouldn't put this line at the top of every function ... assume the caller
passes 64-bit data:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{data} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{asanyarray}\PYG{p}{(}\PYG{n}{data}\PYG{p}{,} \PYG{n}{dtype}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{float64}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\end{Verbatim}
But you should add explicit type conversions to 64 bit when reading float data from files
and explicit type conversions to 32 bit before writing to file.
\section{Clobber or overwrite?}
\label{development/index:clobber-or-overwrite}
In Gammapy we use on \code{overwrite} bool option for {\hyperref[scripts/index:module-gammapy.scripts]{\emph{\code{gammapy.scripts}}}} and functions that
write to files.
Why not use \code{clobber} instead?
After all the
\href{http://heasarc.gsfc.nasa.gov/ftools/ftools\_menu.html}{FTOOLS}
always use \code{clobber}.
The reason is that \code{overwrite} is clear to everyone, but \code{clobber} is defined by the dictionary
(e.g. see \href{http://dictionary.reference.com/browse/clobber}{here})
as ``to batter severely; strike heavily. to defeat decisively. to denounce or criticize vigorously.''
and isn't intuitively clear to new users.
Astropy uses both \code{clobber} and \code{overwrite} in various places at the moment.
For Gammapy we can re-visit this decision before the 1.0 release, but for now,
please be consistent and use \code{overwrite}.
\section{Pixel coordinate convention}
\label{development/index:pixel-coordinate-convention}
All code in Gammapy should follow the Astropy pixel coordinate convention that the center of the first pixel
has pixel coordinates \code{(0, 0)} (and not \code{(1, 1)} as shown e.g. in ds9).
It's currently documented \href{http://photutils.readthedocs.org/en/latest/photutils/overview.html\#coordinate-conventions}{here}
but I plan to document it in the Astropy docs soon (see \href{https://github.com/astropy/astropy/issues/2607}{issue 2607}).
You should use \code{origin=0} when calling any of the pixel to world or world to pixel coordinate transformations in \href{http://docs.astropy.org/en/latest/wcs/index.html\#module-astropy.wcs}{\code{astropy.wcs}}.
\section{When to use C or Cython or Numba for speed}
\label{development/index:when-to-use-c-or-cython-or-numba-for-speed}
Most of Gammapy is written using Python and Numpy array expressions calling functions (e.g. from Scipy)
that operate on Numpy arrays.
This is often nice because it means that algorithms can be implemented with few lines of high-level code,
There is a very small fraction of code though (one or a few percent) where this results in code that is
either cumbersome or too slow. E.g. to compute TS or upper limit images, one needs to do a root finding
method with different number of iterations for each pixel ... that's impossible (or at least very
cumbersome / hard to read) to implement with array expressions and Python loops over pixels are slow.
In these cases we encourage the use of \href{http://cython.org/}{Cython} or \href{http://numba.pydata.org/}{Numba},
or writing the core code in C and exposing it to Python via Cython.
These are popular and simple ways to get C speed from Python.
To use several CPU cores consider using the Python standard library
\href{https://docs.python.org/3/library/multiprocessing.html}{multiprocessing} module.
Note that especially the use of Numba should be considered an experiment.
It is a very nice, but new technology and no-one uses it in production.
Before the Gammapy 1.0 release we will re-evaluate the status of Numba and decide whether it's
an optional dependency we use for speed, or whether we use the much more established Cython
(Scipy, scikit-image, Astropy, ... all use Cython).
At the time of writing (April 2015), the TS map computation code uses Cython and multiprocessing
and Numba is not used yet.
\section{What belongs in Gammapy and what doesn't?}
\label{development/index:what-belongs-in-gammapy-and-what-doesn-t}
The scope of Gammapy is currently not very well defined ... if in doubt whether it makes sense to
add something, please ask on the mailing list or via a Github issue.
Roughly the scope is high-level science analysis of gamma-ray data, starting with event lists
after gamma-hadron separation and corresponding IRFs, as well as source and source population modeling.
For lower-level data processing (calibration, event reconstruction, gamma-hadron separation)
there's \href{https://github.com/cta-observatory/ctapipe}{ctapipe}. There's some functionality (event list processing, PSF or background model building,
sensitivity computations ...) that could go in either ctapipe or Gammapy and we'll have to try
and avoid duplication.
SED modeling code belongs in \href{http://naima.readthedocs.org/en/latest/}{naima}.
A lot of code that's not gamma-ray specific belongs in other packages
(e.g. \href{http://scipy.org/scipylib/}{Scipy}, \href{http://astropy.org}{Astropy}, other Astropy-affiliated packages, \href{http://cxc.cfa.harvard.edu/sherpa/}{Sherpa}).
We currently have quite a bit of code that should be moved ``upstream'' or already has been,
but the Gammapy code hasn't been adapted yet.
\section{Assert convention}
\label{development/index:assert-convention}
When performing tests, the preferred numerical assert method is
\href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.testing.assert\_allclose.html\#numpy.testing.assert\_allclose}{\code{numpy.testing.assert\_allclose}}. Use
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{numpy.testing} \PYG{k+kn}{import} \PYG{n}{assert\PYGZus{}allclose}
\end{Verbatim}
at the top of the file and then just use \code{assert\_allclose} for
the tests. This makes the lines shorter, i.e. there is more space
for the arguments.
\code{assert\_allclose} covers all use cases for numerical asserts, so
it should be used consistently everywhere instead of using the
dozens of other available asserts from pytest or numpy in various
places.
In case of assertion on arrays of quantity objects, such as
\href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}} or \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}, the
following method can be used:
\href{http://docs.astropy.org/en/latest/api/astropy.tests.helper.assert\_quantity\_allclose.html\#astropy.tests.helper.assert\_quantity\_allclose}{\code{astropy.tests.helper.assert\_quantity\_allclose}}.
In this case, use
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{astropy.tests.helper} \PYG{k+kn}{import} \PYG{n}{assert\PYGZus{}quantity\PYGZus{}allclose}
\end{Verbatim}
at the top of the file and then just use \code{assert\_quantity\_allclose}
for the tests.
\section{Random numbers}
\label{development/index:development-random}\label{development/index:random-numbers}
All functions that need to call a random number generator should
take a \code{random\_state} input parameter and call the
{\hyperref[api/gammapy.utils.random.get_random_state:gammapy.utils.random.get_random_state]{\emph{\code{get\_random\_state}}}} utility function like this
(you can copy \& paste the three docstring lines and the first code line
to the function you're writing):
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.utils.random} \PYG{k+kn}{import} \PYG{n}{get\PYGZus{}random\PYGZus{}state}
\PYG{k}{def} \PYG{n+nf}{make\PYGZus{}random\PYGZus{}stuff}\PYG{p}{(}\PYG{n}{X}\PYG{p}{,} \PYG{n}{random\PYGZus{}state}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{random\PYGZhy{}seed}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{:}
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}...}
\PYG{l+s+sd}{ Parameters}
\PYG{l+s+sd}{ \PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}\PYGZhy{}}
\PYG{l+s+sd}{ random\PYGZus{}state : \PYGZob{}int, \PYGZsq{}random\PYGZhy{}seed\PYGZsq{}, \PYGZsq{}global\PYGZhy{}rng\PYGZsq{}, {}`\PYGZti{}numpy.random.RandomState{}`\PYGZcb{}}
\PYG{l+s+sd}{ Defines random number generator initialisation.}
\PYG{l+s+sd}{ Passed to {}`\PYGZti{}gammapy.utils.random.get\PYGZus{}random\PYGZus{}state{}`.}
\PYG{l+s+sd}{ \PYGZdq{}\PYGZdq{}\PYGZdq{}}
\PYG{n}{random\PYGZus{}state} \PYG{o}{=} \PYG{n}{get\PYGZus{}random\PYGZus{}state}\PYG{p}{(}\PYG{n}{random\PYGZus{}state}\PYG{p}{)}
\PYG{n}{data} \PYG{o}{=} \PYG{n}{random\PYGZus{}state}\PYG{o}{.}\PYG{n}{uniform}\PYG{p}{(}\PYG{n}{low}\PYG{o}{=}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{n}{high}\PYG{o}{=}\PYG{l+m+mi}{3}\PYG{p}{,} \PYG{n}{size}\PYG{o}{=}\PYG{l+m+mi}{10}\PYG{p}{)}
\PYG{k}{return} \PYG{n}{data}
\end{Verbatim}
This allows callers flexible control over which random number generator
(i.e. which \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.RandomState.html\#numpy.random.RandomState}{\code{numpy.random.RandomState}} instance) is used and how it's initialised.
The default \code{random\_state='random-seed'} means ``create a new RNG, seed it in a random way'',
i.e. different random numbers will be generated on every call.
There's a few ways to get deterministic results from a script that call
functions that generate random numbers.
One option is to create a single \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.RandomState.html\#numpy.random.RandomState}{\code{RandomState}} object seeded with an integer
and then pass that \code{random\_state} object to every function that generates random numbers:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{numpy.random} \PYG{k+kn}{import} \PYG{n}{RandomState}
\PYG{n}{random\PYGZus{}state} \PYG{o}{=} \PYG{n}{RandomState}\PYG{p}{(}\PYG{n}{seed}\PYG{o}{=}\PYG{l+m+mi}{0}\PYG{p}{)}
\PYG{n}{stuff1} \PYG{o}{=} \PYG{n}{make\PYGZus{}some\PYGZus{}random\PYGZus{}stuff}\PYG{p}{(}\PYG{n}{random\PYGZus{}state}\PYG{o}{=}\PYG{n}{random\PYGZus{}state}\PYG{p}{)}
\PYG{n}{stuff2} \PYG{o}{=} \PYG{n}{make\PYGZus{}more\PYGZus{}random\PYGZus{}stuff}\PYG{p}{(}\PYG{n}{random\PYGZus{}state}\PYG{o}{=}\PYG{n}{random\PYGZus{}state}\PYG{p}{)}
\end{Verbatim}
Another option is to pass an integer seed to every function that generates random numbers:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{seed} \PYG{o}{=} \PYG{l+m+mi}{0}
\PYG{n}{stuff1} \PYG{o}{=} \PYG{n}{make\PYGZus{}some\PYGZus{}random\PYGZus{}stuff}\PYG{p}{(}\PYG{n}{random\PYGZus{}state}\PYG{o}{=}\PYG{n}{seed}\PYG{p}{)}
\PYG{n}{stuff2} \PYG{o}{=} \PYG{n}{make\PYGZus{}more\PYGZus{}random\PYGZus{}stuff}\PYG{p}{(}\PYG{n}{random\PYGZus{}state}\PYG{o}{=}\PYG{n}{seed}\PYG{p}{)}
\end{Verbatim}
This pattern was inspired by the way
\href{http://scikit-learn.org/stable/developers/\#random-numbers}{scikit-learn handles random numbers}.
We have changed the \code{None} option of \code{sklearn.utils.check\_random\_state} to \code{'global-rng'},
because we felt that this meaning for \code{None} was confusing given that \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.RandomState.html\#numpy.random.RandomState}{\code{numpy.random.RandomState}}
uses a different meaning (for which we use the option \code{'global-rng'}).
\chapter{Changelog}
\label{changelog:id3}\label{changelog:id1}\label{changelog:changelog}\label{changelog::doc}
This is the changelog for Gammapy.
For now we use a one-line description of every pull request, roughly in chronological order.
We don't list every pull request.
Maintenance and cleanup changes (e.g. to update astropy-helpers or fix the docs build)
are not of interest to users and are not listed here.
After the 1.0 release we will keep a more detailed changelog for users.
\section{1.0 (Fall, 2015)}
\label{changelog:fall-2015}
Gammapy 1.0 will be released in fall 2015.
We aim for October 2015, but are willing to delay a bit if important features are missing
or the documentation and tests need further work.
Gammapy 1.0 will depend on the Astropy 1.1 and Sherpa 4.8.
For plans and progress see \href{https://github.com/gammapy/gammapy/milestones/1.0}{https://github.com/gammapy/gammapy/milestones/1.0}
\subsection{Pull requests}
\label{changelog:pull-requests}\begin{itemize}
\item {}
No changes yet
\end{itemize}
\section{0.4 (August 24, 2015)}
\label{changelog:august-24-2015}
Gammapy 0.4 will be released on August 24, 2015.
For plans and progress see \href{https://github.com/gammapy/gammapy/milestones/0.4}{https://github.com/gammapy/gammapy/milestones/0.4}
\subsection{Pull requests}
\label{changelog:id2}\begin{itemize}
\item {}
No changes yet
\end{itemize}
\section{0.3 (July 9 , 2015)}
\label{changelog:july-9-2015}\label{changelog:gammapy-0p3-release}
Gammapy 0.3 will be released on July 9, 2015.
For plans and progress see \href{https://github.com/gammapy/gammapy/milestones/0.3}{https://github.com/gammapy/gammapy/milestones/0.3}
\subsection{Pull requests}
\label{changelog:id3}\begin{itemize}
\item {}
EventList class fixes and new features {[}\#256{]} (Christoph Deil)
\item {}
Add offset-dependent effective area IRF class {[}\#260{]} (Johannes King)
\item {}
Fix spiral arm model bar radius {[}\#261{]} (Stefan Klepser)
\item {}
Add SNRCat dataset access function {[}\#262{]} (Christoph Deil)
\item {}
Add hspec - spectral analysis using Sherpa {[}\#264{]} (Regis Terrier, Ignasi Reichardt, Christoph Deil)
\item {}
Improve SNRcat dataset {[}\#279{]} (Christoph Deil)
\item {}
Add new subpackage: gammapy.time {[}\#280{]} (Christoph Deil)
\item {}
Document observation tables and improve \code{gammapy.obs} {[}\#278{]} (Manuel Paz Arribas)
\item {}
Add infos how to handle times in Gammapy {[}\#285{]} (Christoph Deil)
\item {}
Function to plot Fermi 3FGL light curves {[}\#286{]} (Jonathan Harris)
\item {}
Add EffectiveAreaTable exporter to EffectiveAreaTable2D {[}\#276{]} (Johannes King)
\item {}
Add interface to HESS FitSpectrum JSON output {[}\#296{]} (Christoph Deil)
\item {}
Remove gammapy.shower package {[}\#291{]} (Christoph Deil)
\item {}
Add cube background model class {[}\#299{]} (Manuel Paz Arribas)
\item {}
Use assert\_quantity\_allclose from Astropy {[}\#306{]} (Manuel Paz Arribas)
\item {}
Consistent random number handling and improve sample\_sphere {[}\#283{]} (Manuel Paz Arribas)
\end{itemize}
\section{0.2 (April 13, 2015)}
\label{changelog:gammapy-0p2-release}\label{changelog:april-13-2015}
\subsection{Release notes}
\label{changelog:release-notes}\begin{itemize}
\item {}
Released on April 13, 2015 (\href{https://pypi.python.org/pypi/gammapy/0.2}{Gammapy 0.2 on PyPI})
\item {}
Contributors: Manuel Paz Arribas (new), Axel Donath, Ellis Owen, Christoph Deil
\item {}
8 months of work (from August 25, 2014 to April 13, 2015)
\item {}
40 pull requests, 4 authors
\item {}
Requires Astropy version 1.0 or later.
\item {}
Gammapy now uses \href{http://cython.org/}{Cython},
i.e. requires a C compiler for end-users and in addition Cython for developers.
\end{itemize}
\subsection{Pull requests}
\label{changelog:id4}\begin{itemize}
\item {}
Add iterative kernel background estimator {[}\#186{]} (Ellis Owen)
\item {}
Fix bugs in spectral cube class {[}\#187{]} (Ellis Owen)
\item {}
Add tests for spectral\_cube.integral\_flux\_image {[}\#188{]} (Ellis Owen)
\item {}
Add Fermi PSF dataset and example {[}\#191{]} (Ellis Owen)
\item {}
Bundle TeVCat in gammapy.datasets {[}\#194{]} (Christoph Deil)
\item {}
Fix quantity errors from astro source models {[}\#200{]} (Christoph Deil)
\item {}
Remove healpix\_to\_image function (moved to reproject repo) {[}\#205{]} (Christoph Deil)
\item {}
Restructure image measurement functions {[}\#210{]} (Axel Donath)
\item {}
Bundle xmltodict.py in gammapy/extern {[}\#212{]} (Christoph Deil)
\item {}
Restructure TS map computation {[}\#215{]} (Axel Donath)
\item {}
TS map calculation update and docs {[}\#221{]} (Axel Donath)
\item {}
Misc cleanup {[}\#225{]} (Christoph Deil)
\item {}
Use setuptools entry\_points for scripts {[}\#230{]} (Christoph Deil)
\item {}
Add observatory and data classes {[}\#231{]} (Christoph Deil)
\item {}
Add multi-scale TS image computation {[}\#234{]} (Axel Donath)
\item {}
Add some catalog utilities {[}\#235{]} (Christoph Deil)
\item {}
Add likelihood converter function {[}\#236{]} (Christoph Deil)
\item {}
Add 3FGL to dataset fetch functions {[}\#244{]} (Manuel Paz Arribas)
\item {}
Add colormap and PSF inset plotting functions {[}\#245{]} (Axel Donath)
\item {}
Add catalog and plotting utils {[}\#246{]} (Axel Donath)
\item {}
Various fixes to image utils docstrings {[}\#247{]} (Manuel Paz Arribas)
\item {}
Add function to fill acceptance image from curve {[}\#248{]} (Manuel Paz Arribas)
\item {}
Add data store and observation table classes, improve event list classes {[}\#249{]} (Christoph Deil)
\item {}
Implement TS map computation in Cython {[}\#252{]} (Axel Donath)
\item {}
Add changelog for Gammapy {[}\#254{]} (Christoph Deil)
\end{itemize}
\section{0.1 (August 25, 2014)}
\label{changelog:august-25-2014}\label{changelog:gammapy-0p1-release}
\subsection{Release notes}
\label{changelog:id5}\begin{itemize}
\item {}
Released on August 25, 2014 (\href{https://pypi.python.org/pypi/gammapy/0.1}{Gammapy 0.1 on PyPI})
\item {}
Contributors: Axel Donath, Ellis Owen, Regis Terrier, Rolf Bühler, Christoph Deil
\item {}
15 months of work (from May 15, 2013 to August 25, 2014)
\item {}
82 pull requests, 5 authors
\item {}
Requires Astropy version 0.4 or later.
\end{itemize}
\subsection{Pull requests}
\label{changelog:id6}
Note that Gammapy development started out directly in the master branch,
i.e. for some things there is no pull request we can list here.
\begin{itemize}
\item {}
Start tevpy repo with \href{https://github.com/gammapy/gammapy/commit/11af4c7436bb79f8e2cae8d0441693232eebe1ba}{commit 11af4c} (Christoph Deil)
\item {}
Rename tevpy to Gammapy in \href{https://github.com/cdeil/gammapy/commit/7e955ffae71353f7b10c9de4a69b977e7c036c6d}{commit 7e955f} on Aug 19, 2013 (Christoph Deil)
\item {}
Add blob detection {[}\#11{]} (Axel Donath)
\item {}
Add coverage reports to continuous integration on coveralls {[}\#12{]} (Christoph Deil)
\item {}
Add continuous wavelet transform class {[}\#25{]} (Regis Terrier)
\item {}
Rename tevpy to gammapy {[}\#34{]} (Christoph Deil)
\item {}
Add sphere and power-law sampling functions {[}\#48{]} (Christoph Deil)
\item {}
Add per-pixel solid angle function in image utils {[}\#58{]} (Ellis Owen)
\item {}
Add coordinate string IAU designation format {[}\#64{]} (Christoph Deil)
\item {}
Add model image and image measurement functionality {[}\#65{]} (Axel Donath)
\item {}
Add plotting module and HESS colormap {[}\#66{]} (Axel Donath)
\item {}
Add image measure methods {[}\#67{]} (Christoph Deil)
\item {}
Integrate PyFACT functionality in Gammapy {[}\#68{]} (Christoph Deil)
\item {}
Add TablePSF and Fermi PSF {[}\#84{]} (Christoph Deil)
\item {}
Add block reduce function for HDUs {[}\#88{]} (Ellis Owen)
\item {}
Add wstat likelihood function for spectra and images {[}\#96{]} (Christoph Deil)
\item {}
Add image plotting routines {[}\#100{]} (Christoph Deil)
\item {}
Add datasets functions to fetch Fermi catalogs {[}\#103{]} (Ellis Owen)
\item {}
Python 2 / 3 compatibility with a single codebase {[}\#109{]} (Christoph Deil)
\item {}
Add Galactic source catalog simulation methods {[}\#116{]} (Christoph Deil)
\item {}
Improve synthetic Milky Way modeling {[}\#117{]} (Christoph Deil)
\item {}
Add morphology models as Astropy models {[}\#122{]} (Axel Donath)
\item {}
Add flux point computation using Lafferty \& Wyatt (1995) {[}\#128{]} (Ellis Owen)
\item {}
Add Crab flux point dataset {[}\#138{]} (Rolf Bühler)
\item {}
Add EffectiveAreaTable and EnergyDependentMultiGaussPSF classes {[}\#142{]} (Axel Donath)
\item {}
Add npred cube computation {[}\#150{]} (Christoph Deil and Ellis Owen)
\item {}
Improve npred cube functionality {[}\#151{]} (Ellis Owen)
\item {}
Add Fermi PSF convolution method {[}\#154{]} (Ellis Owen)
\item {}
Add PSF convolve function {[}\#155{]} (Ellis Owen)
\item {}
Add Fermi Vela dataset {[}\#156{]} (Ellis Owen)
\item {}
Re-write Galaxy modelling code {[}\#157{]} (Axel Donath)
\item {}
Add code to make model images from a source catalog {[}\#160{]} (Ellis Owen)
\item {}
Add SED from Cube function {[}\#166{]} (Ellis Owen)
\item {}
Add image profile function {[}\#167{]} (Ellis Owen)
\item {}
Add new gammapy.data sub-package {[}\#176{]} (Christoph Deil)
\item {}
Misc code and docs cleanup {[}\#177{]} (Christoph Deil)
\item {}
Clean up datasets code and docs {[}\#180{]} (Christoph Deil)
\end{itemize}
\part{The Gammapy toolbox}
\label{index:astropy}\label{index:the-gammapy-toolbox}
\chapter{Astrophysical source and population models (\texttt{gammapy.astro})}
\label{astro/index:astrophysical-source-and-population-models-gammapy-astro}\label{astro/index::doc}\label{astro/index:astro}
\section{Introduction}
\label{astro/index:introduction}
Common astrophysical source and population models are implemented in
{\hyperref[astro/source/index:module-gammapy.astro.source]{\emph{\code{gammapy.astro.source}}}} and {\hyperref[astro/population/index:module-gammapy.astro.population]{\emph{\code{gammapy.astro.population}}}}.
The \code{gammapy.astro} namespace is empty ... use these import statements:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.astro} \PYG{k+kn}{import} \PYG{n}{source}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.astro} \PYG{k+kn}{import} \PYG{n}{population}
\end{Verbatim}
\subsection{Astrophysical source models (\texttt{gammapy.astro.source})}
\label{astro/source/index:astrophysical-source-models-gammapy-astro-source}\label{astro/source/index::doc}\label{astro/source/index:astro-source}
\subsubsection{Introduction}
\label{astro/source/index:introduction}
The {\hyperref[astro/source/index:module-gammapy.astro.source]{\emph{\code{gammapy.astro.source}}}} module contains classes of source models, which can be used for population synthesis of galactic gamma-ray sources.
\subsubsection{Source Models}
\label{astro/source/index:source-models}
The following source models are available:
\paragraph{Supernova Remnant Models}
\label{astro/source/snr::doc}\label{astro/source/snr:supernova-remnant-models}\label{astro/source/snr:astro-source-snr}
Plot the evolution of radius of the SNR:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}Plot SNR radius evolution versus time.\PYGZdq{}\PYGZdq{}\PYGZdq{}}
\PYG{k+kn}{import} \PYG{n+nn}{numpy} \PYG{k+kn}{as} \PYG{n+nn}{np}
\PYG{k+kn}{import} \PYG{n+nn}{matplotlib.pyplot} \PYG{k+kn}{as} \PYG{n+nn}{plt}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.units} \PYG{k+kn}{import} \PYG{n}{Quantity}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.astro.source} \PYG{k+kn}{import} \PYG{n}{SNR}\PYG{p}{,} \PYG{n}{SNRTrueloveMcKee}
\PYG{n}{snr\PYGZus{}models} \PYG{o}{=} \PYG{p}{[}\PYG{n}{SNR}\PYG{p}{,} \PYG{n}{SNRTrueloveMcKee}\PYG{p}{]}
\PYG{n}{densities} \PYG{o}{=} \PYG{n}{Quantity}\PYG{p}{(}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{l+m+mf}{0.1}\PYG{p}{]}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{cm\PYGZca{}\PYGZhy{}3}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{linestyles} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{\PYGZhy{}}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{\PYGZhy{}\PYGZhy{}}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}
\PYG{n}{colors} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{b}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{g}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}
\PYG{n}{t} \PYG{o}{=} \PYG{n}{Quantity}\PYG{p}{(}\PYG{n}{np}\PYG{o}{.}\PYG{n}{logspace}\PYG{p}{(}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{l+m+mi}{5}\PYG{p}{,} \PYG{l+m+mi}{100}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{yr}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{k}{for} \PYG{n}{color}\PYG{p}{,} \PYG{n}{density} \PYG{o+ow}{in} \PYG{n+nb}{zip}\PYG{p}{(}\PYG{n}{colors}\PYG{p}{,} \PYG{n}{densities}\PYG{p}{)}\PYG{p}{:}
\PYG{k}{for} \PYG{n}{linestyle}\PYG{p}{,} \PYG{n}{snr\PYGZus{}model} \PYG{o+ow}{in} \PYG{n+nb}{zip}\PYG{p}{(}\PYG{n}{linestyles}\PYG{p}{,} \PYG{n}{snr\PYGZus{}models}\PYG{p}{)}\PYG{p}{:}
\PYG{n}{snr} \PYG{o}{=} \PYG{n}{snr\PYGZus{}model}\PYG{p}{(}\PYG{n}{n\PYGZus{}ISM}\PYG{o}{=}\PYG{n}{density}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{plot}\PYG{p}{(}\PYG{n}{t}\PYG{o}{.}\PYG{n}{value}\PYG{p}{,} \PYG{n}{snr}\PYG{o}{.}\PYG{n}{radius}\PYG{p}{(}\PYG{n}{t}\PYG{p}{)}\PYG{o}{.}\PYG{n}{to}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{pc}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{o}{.}\PYG{n}{value}\PYG{p}{,}
\PYG{n}{label}\PYG{o}{=}\PYG{n}{snr}\PYG{o}{.}\PYG{n}{\PYGZus{}\PYGZus{}class\PYGZus{}\PYGZus{}}\PYG{o}{.}\PYG{n}{\PYGZus{}\PYGZus{}name\PYGZus{}\PYGZus{}} \PYG{o}{+} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ (n\PYGZus{}ISM = \PYGZob{}0\PYGZcb{})}\PYG{l+s}{\PYGZsq{}}\PYG{o}{.}\PYG{n}{format}\PYG{p}{(}\PYG{n}{density}\PYG{o}{.}\PYG{n}{value}\PYG{p}{)}\PYG{p}{,}
\PYG{n}{linestyle}\PYG{o}{=}\PYG{n}{linestyle}\PYG{p}{,} \PYG{n}{color}\PYG{o}{=}\PYG{n}{color}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{xlabel}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{time [years]}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{ylabel}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{radius [pc]}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{legend}\PYG{p}{(}\PYG{n}{loc}\PYG{o}{=}\PYG{l+m+mi}{4}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{loglog}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{show}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}
\includegraphics{plot_snr_radius_evolution.pdf}
Plot the evolution of the flux of the SNR above 1 TeV and at 1 kpc distance:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}Plot SNR brightness evolution.\PYGZdq{}\PYGZdq{}\PYGZdq{}}
\PYG{k+kn}{import} \PYG{n+nn}{numpy} \PYG{k+kn}{as} \PYG{n+nn}{np}
\PYG{k+kn}{import} \PYG{n+nn}{matplotlib.pyplot} \PYG{k+kn}{as} \PYG{n+nn}{plt}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.units} \PYG{k+kn}{import} \PYG{n}{Quantity}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.astro.source} \PYG{k+kn}{import} \PYG{n}{SNR}
\PYG{n}{densities} \PYG{o}{=} \PYG{n}{Quantity}\PYG{p}{(}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{l+m+mf}{0.1}\PYG{p}{]}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{cm\PYGZca{}\PYGZhy{}3}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{colors} \PYG{o}{=} \PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{b}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{g}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}
\PYG{n}{t} \PYG{o}{=} \PYG{n}{Quantity}\PYG{p}{(}\PYG{n}{np}\PYG{o}{.}\PYG{n}{logspace}\PYG{p}{(}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{l+m+mi}{5}\PYG{p}{,} \PYG{l+m+mi}{100}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{yr}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{k}{for} \PYG{n}{color}\PYG{p}{,} \PYG{n}{density} \PYG{o+ow}{in} \PYG{n+nb}{zip}\PYG{p}{(}\PYG{n}{colors}\PYG{p}{,} \PYG{n}{densities}\PYG{p}{)}\PYG{p}{:}
\PYG{n}{snr} \PYG{o}{=} \PYG{n}{SNR}\PYG{p}{(}\PYG{n}{n\PYGZus{}ISM}\PYG{o}{=}\PYG{n}{density}\PYG{p}{)}
\PYG{n}{F} \PYG{o}{=} \PYG{n}{snr}\PYG{o}{.}\PYG{n}{luminosity\PYGZus{}tev}\PYG{p}{(}\PYG{n}{t}\PYG{p}{)} \PYG{o}{/} \PYG{p}{(}\PYG{l+m+mi}{4} \PYG{o}{*} \PYG{n}{np}\PYG{o}{.}\PYG{n}{pi} \PYG{o}{*} \PYG{n}{Quantity}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{kpc}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)} \PYG{o}{*}\PYG{o}{*} \PYG{l+m+mi}{2}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{plot}\PYG{p}{(}\PYG{n}{t}\PYG{o}{.}\PYG{n}{value}\PYG{p}{,} \PYG{n}{F}\PYG{o}{.}\PYG{n}{to}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ph s\PYGZca{}\PYGZhy{}1 cm\PYGZca{}\PYGZhy{}2}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{o}{.}\PYG{n}{value}\PYG{p}{,} \PYG{n}{color}\PYG{o}{=}\PYG{n}{color}\PYG{p}{,} \PYG{n}{label}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{n\PYGZus{}ISM = \PYGZob{}0\PYGZcb{}}\PYG{l+s}{\PYGZsq{}}\PYG{o}{.}\PYG{n}{format}\PYG{p}{(}\PYG{n}{density}\PYG{o}{.}\PYG{n}{value}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{vlines}\PYG{p}{(}\PYG{n}{snr}\PYG{o}{.}\PYG{n}{sedov\PYGZus{}taylor\PYGZus{}begin}\PYG{o}{.}\PYG{n}{to}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{yr}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{o}{.}\PYG{n}{value}\PYG{p}{,} \PYG{l+m+mf}{1E\PYGZhy{}13}\PYG{p}{,} \PYG{l+m+mf}{1E\PYGZhy{}10}\PYG{p}{,} \PYG{n}{linestyle}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{\PYGZhy{}\PYGZhy{}}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{color}\PYG{o}{=}\PYG{n}{color}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{vlines}\PYG{p}{(}\PYG{n}{snr}\PYG{o}{.}\PYG{n}{sedov\PYGZus{}taylor\PYGZus{}end}\PYG{o}{.}\PYG{n}{to}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{yr}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{o}{.}\PYG{n}{value}\PYG{p}{,} \PYG{l+m+mf}{1E\PYGZhy{}13}\PYG{p}{,} \PYG{l+m+mf}{1E\PYGZhy{}10}\PYG{p}{,} \PYG{n}{linestyle}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{\PYGZhy{}\PYGZhy{}}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{color}\PYG{o}{=}\PYG{n}{color}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{xlim}\PYG{p}{(}\PYG{l+m+mf}{1E2}\PYG{p}{,} \PYG{l+m+mf}{1E5}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{ylim}\PYG{p}{(}\PYG{l+m+mf}{1E\PYGZhy{}13}\PYG{p}{,} \PYG{l+m+mf}{1E\PYGZhy{}10}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{xlabel}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{time [years]}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{ylabel}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{flux @ 1kpc [ph s\PYGZca{}\PYGZhy{}1 cm \PYGZca{}\PYGZhy{}2]}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{legend}\PYG{p}{(}\PYG{n}{loc}\PYG{o}{=}\PYG{l+m+mi}{4}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{loglog}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{show}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}
\includegraphics{plot_snr_brightness_evolution.pdf}
\paragraph{Pulsar Wind Nebula Source Models}
\label{astro/source/pwn:astro-source-pwn}\label{astro/source/pwn:pulsar-wind-nebula-source-models}\label{astro/source/pwn:astropy}\label{astro/source/pwn::doc}
Plot the evolution of the radius of the PWN:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}Plot PWN evolution with time.\PYGZdq{}\PYGZdq{}\PYGZdq{}}
\PYG{k+kn}{import} \PYG{n+nn}{numpy} \PYG{k+kn}{as} \PYG{n+nn}{np}
\PYG{k+kn}{import} \PYG{n+nn}{matplotlib.pyplot} \PYG{k+kn}{as} \PYG{n+nn}{plt}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.units} \PYG{k+kn}{import} \PYG{n}{Quantity}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.constants} \PYG{k+kn}{import} \PYG{n}{M\PYGZus{}sun}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.astro.source} \PYG{k+kn}{import} \PYG{n}{PWN}\PYG{p}{,} \PYG{n}{SNRTrueloveMcKee}
\PYG{n}{t} \PYG{o}{=} \PYG{n}{Quantity}\PYG{p}{(}\PYG{n}{np}\PYG{o}{.}\PYG{n}{logspace}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{l+m+mi}{5}\PYG{p}{,} \PYG{l+m+mi}{100}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{yr}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{n\PYGZus{}ISM} \PYG{o}{=} \PYG{n}{Quantity}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{cm\PYGZca{}\PYGZhy{}3}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{snr} \PYG{o}{=} \PYG{n}{SNRTrueloveMcKee}\PYG{p}{(}\PYG{n}{m\PYGZus{}ejecta}\PYG{o}{=}\PYG{l+m+mi}{8} \PYG{o}{*} \PYG{n}{M\PYGZus{}sun}\PYG{p}{,} \PYG{n}{n\PYGZus{}ISM}\PYG{o}{=}\PYG{n}{n\PYGZus{}ISM}\PYG{p}{)}
\PYG{n}{pwn} \PYG{o}{=} \PYG{n}{PWN}\PYG{p}{(}\PYG{n}{snr}\PYG{o}{=}\PYG{n}{snr}\PYG{p}{)}
\PYG{n}{pwn}\PYG{o}{.}\PYG{n}{pulsar}\PYG{o}{.}\PYG{n}{L\PYGZus{}0} \PYG{o}{=} \PYG{n}{Quantity}\PYG{p}{(}\PYG{l+m+mf}{1E40}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{erg/s}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{plot}\PYG{p}{(}\PYG{n}{t}\PYG{o}{.}\PYG{n}{value}\PYG{p}{,} \PYG{n}{pwn}\PYG{o}{.}\PYG{n}{radius}\PYG{p}{(}\PYG{n}{t}\PYG{p}{)}\PYG{o}{.}\PYG{n}{to}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{pc}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{o}{.}\PYG{n}{value}\PYG{p}{,} \PYG{n}{label}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Radius SNR}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{plot}\PYG{p}{(}\PYG{n}{t}\PYG{o}{.}\PYG{n}{value}\PYG{p}{,} \PYG{n}{pwn}\PYG{o}{.}\PYG{n}{snr}\PYG{o}{.}\PYG{n}{radius\PYGZus{}reverse\PYGZus{}shock}\PYG{p}{(}\PYG{n}{t}\PYG{p}{)}\PYG{o}{.}\PYG{n}{to}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{pc}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{o}{.}\PYG{n}{value}\PYG{p}{,} \PYG{n}{label}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Reverse Shock SNR}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{plot}\PYG{p}{(}\PYG{n}{t}\PYG{o}{.}\PYG{n}{value}\PYG{p}{,} \PYG{n}{pwn}\PYG{o}{.}\PYG{n}{snr}\PYG{o}{.}\PYG{n}{radius}\PYG{p}{(}\PYG{n}{t}\PYG{p}{)}\PYG{o}{.}\PYG{n}{to}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{pc}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{o}{.}\PYG{n}{value}\PYG{p}{,} \PYG{n}{label}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Radius PWN}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{xlabel}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{time [years]}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{ylabel}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{radius [pc]}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{legend}\PYG{p}{(}\PYG{n}{loc}\PYG{o}{=}\PYG{l+m+mi}{4}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{loglog}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{show}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}
\includegraphics{plot_pwn_evolution.pdf}
\paragraph{Pulsar Source Models}
\label{astro/source/pulsar:pulsar-source-models}\label{astro/source/pulsar:astropy}\label{astro/source/pulsar::doc}\label{astro/source/pulsar:astro-source-pulsar}
Plot spin frequency of the pulsar with time:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}Plot spin frequency of the pulsar with time.\PYGZdq{}\PYGZdq{}\PYGZdq{}}
\PYG{k+kn}{import} \PYG{n+nn}{numpy} \PYG{k+kn}{as} \PYG{n+nn}{np}
\PYG{k+kn}{import} \PYG{n+nn}{matplotlib.pyplot} \PYG{k+kn}{as} \PYG{n+nn}{plt}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.units} \PYG{k+kn}{import} \PYG{n}{Quantity}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.astro.source} \PYG{k+kn}{import} \PYG{n}{Pulsar}
\PYG{n}{t} \PYG{o}{=} \PYG{n}{Quantity}\PYG{p}{(}\PYG{n}{np}\PYG{o}{.}\PYG{n}{logspace}\PYG{p}{(}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{l+m+mi}{6}\PYG{p}{,} \PYG{l+m+mi}{100}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{yr}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{pulsar} \PYG{o}{=} \PYG{n}{Pulsar}\PYG{p}{(}\PYG{n}{P\PYGZus{}0}\PYG{o}{=}\PYG{n}{Quantity}\PYG{p}{(}\PYG{l+m+mf}{0.01}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{s}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{,} \PYG{n}{logB}\PYG{o}{=}\PYG{l+m+mi}{12}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{plot}\PYG{p}{(}\PYG{n}{t}\PYG{o}{.}\PYG{n}{value}\PYG{p}{,} \PYG{l+m+mi}{1} \PYG{o}{/} \PYG{n}{pulsar}\PYG{o}{.}\PYG{n}{period}\PYG{p}{(}\PYG{n}{t}\PYG{p}{)}\PYG{o}{.}\PYG{n}{cgs}\PYG{o}{.}\PYG{n}{value}\PYG{p}{,} \PYG{n}{color}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{b}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{xlabel}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{time [years]}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{ylabel}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{frequency [1/s]}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{ylim}\PYG{p}{(}\PYG{l+m+mf}{1E0}\PYG{p}{,} \PYG{l+m+mf}{1E2}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{loglog}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{show}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}
\includegraphics{plot_pulsar_spindown.pdf}
\subsubsection{Reference/API}
\label{astro/source/index:reference-api}\label{astro/source/index:astropy}
\paragraph{gammapy.astro.source Package}
\label{astro/source/index:module-gammapy.astro.source}\label{astro/source/index:gammapy-astro-source-package}\index{gammapy.astro.source (module)}
Astrophysical source models
\subparagraph{Classes}
\label{astro/source/index:classes}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.astro.source.PWN:gammapy.astro.source.PWN]{\emph{\code{PWN}}}}({[}pulsar, snr, eta\_e, eta\_B, morphology, age{]})
&
Simple pulsar wind nebula (PWN) evolution model.
\\
\hline
{\hyperref[api/gammapy.astro.source.Pulsar:gammapy.astro.source.Pulsar]{\emph{\code{Pulsar}}}}({[}P\_0, logB, n, I, R, age, L\_0, ...{]})
&
Magnetic dipole spin-down pulsar model.
\\
\hline
{\hyperref[api/gammapy.astro.source.SNR:gammapy.astro.source.SNR]{\emph{\code{SNR}}}}({[}e\_sn, theta, n\_ISM, m\_ejecta, ...{]})
&
Simple supernova remnant (SNR) evolution model.
\\
\hline
{\hyperref[api/gammapy.astro.source.SNRTrueloveMcKee:gammapy.astro.source.SNRTrueloveMcKee]{\emph{\code{SNRTrueloveMcKee}}}}(*args, **kwargs)
&
SNR model according to Truelove \& McKee (1999).
\\
\hline
{\hyperref[api/gammapy.astro.source.SimplePulsar:gammapy.astro.source.SimplePulsar]{\emph{\code{SimplePulsar}}}}(P, P\_dot{[}, I, R{]})
&
Magnetic dipole spin-down model for a pulsar.
\\
\hline\end{longtable}
\subparagraph{PWN}
\label{api/gammapy.astro.source.PWN:pwn}\label{api/gammapy.astro.source.PWN::doc}\index{PWN (class in gammapy.astro.source)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.PWN:gammapy.astro.source.PWN}\pysiglinewithargsret{\strong{class }\code{gammapy.astro.source.}\bfcode{PWN}}{\emph{pulsar=\textless{}gammapy.astro.source.pulsar.Pulsar object\textgreater{}}, \emph{snr=\textless{}gammapy.astro.source.snr.SNRTrueloveMcKee object\textgreater{}}, \emph{eta\_e=0.999}, \emph{eta\_B=0.001}, \emph{morphology='Gaussian2D'}, \emph{age=None}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Simple pulsar wind nebula (PWN) evolution model.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{pulsar} : {\hyperref[api/gammapy.astro.source.Pulsar:gammapy.astro.source.Pulsar]{\emph{\code{Pulsar}}}}
\begin{quote}
Pulsar model instance.
\end{quote}
\textbf{snr} : {\hyperref[api/gammapy.astro.source.SNRTrueloveMcKee:gammapy.astro.source.SNRTrueloveMcKee]{\emph{\code{SNRTrueloveMcKee}}}}
\begin{quote}
SNR model instance
\end{quote}
\textbf{eta\_e} : float
\begin{quote}
Fraction of energy going into electrons.
\end{quote}
\textbf{eta\_B} : float
\begin{quote}
Fraction of energy going into magnetic fields.
\end{quote}
\textbf{age} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Age of the PWN.
\end{quote}
\textbf{morphology} : str
\begin{quote}
Morphology model of the PWN
\end{quote}
\end{description}\end{quote}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{luminosity\_tev() (gammapy.astro.source.PWN method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.PWN:gammapy.astro.source.PWN.luminosity_tev}\pysiglinewithargsret{\bfcode{luminosity\_tev}}{\emph{t=None}, \emph{fraction=0.1}}{}
Simple luminosity evolution model.
Assumes that the luminosity is just a fraction of the total energy content
of the pulsar. No cooling is considered and therefore the estimate is very bad.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{t} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Time after birth of the SNR.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{magnetic\_field() (gammapy.astro.source.PWN method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.PWN:gammapy.astro.source.PWN.magnetic_field}\pysiglinewithargsret{\bfcode{magnetic\_field}}{\emph{t=None}}{}
Estimation of the magnetic field inside the PWN.
By assuming that a certain fraction of the spin down energy is
converted to magnetic field energy an estimation of the magnetic
field can be derived.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{t} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Time after birth of the SNR.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{radius() (gammapy.astro.source.PWN method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.PWN:gammapy.astro.source.PWN.radius}\pysiglinewithargsret{\bfcode{radius}}{\emph{t=None}}{}
Radius of the PWN at age t.
Reference: \href{http://adsabs.harvard.edu/abs/2006ARA\%26A..44...17G}{http://adsabs.harvard.edu/abs/2006ARA\%26A..44...17G} (Formula 8).
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{t} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Time after birth of the SNR.
\end{quote}
\end{description}\end{quote}
\paragraph{Notes}
During the free expansion phase the radius of the PWN evolves like:
\begin{gather}
\begin{split}R_{PWN}(t) = 1.44\text{pc}\left(\frac{E_{SN}^3\dot{E}_0^2}
{M_{ej}^5}\right)^{1/10}t^{6/5}\end{split}\notag
\end{gather}
After the collision with the reverse shock of the SNR, the radius is
assumed to be constant (See {\hyperref[api/gammapy.astro.source.SNRTrueloveMcKee:gammapy.astro.source.SNRTrueloveMcKee.radius_reverse_shock]{\emph{\code{radius\_reverse\_shock}}}})
\end{fulllineitems}
\end{fulllineitems}
\subparagraph{Pulsar}
\label{api/gammapy.astro.source.Pulsar:pulsar}\label{api/gammapy.astro.source.Pulsar:astropy}\label{api/gammapy.astro.source.Pulsar::doc}\index{Pulsar (class in gammapy.astro.source)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.Pulsar:gammapy.astro.source.Pulsar}\pysiglinewithargsret{\strong{class }\code{gammapy.astro.source.}\bfcode{Pulsar}}{\emph{P\_0=\textless{}Quantity 0.1 s\textgreater{}}, \emph{logB=10}, \emph{n=3}, \emph{I=\textless{}Quantity 1e+45 cm2 g\textgreater{}}, \emph{R=\textless{}Quantity 1000000.0 cm\textgreater{}}, \emph{age=None}, \emph{L\_0=None}, \emph{morphology='Delta2D'}}{}
Bases: {\hyperref[api/gammapy.astro.source.SimplePulsar:gammapy.astro.source.SimplePulsar]{\emph{\code{gammapy.astro.source.SimplePulsar}}}}
Magnetic dipole spin-down pulsar model.
Reference: \href{http://www.cv.nrao.edu/course/astr534/Pulsars.html}{http://www.cv.nrao.edu/course/astr534/Pulsars.html}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{P\_0} : float
\begin{quote}
Period at birth
\end{quote}
\textbf{logB} : float
\begin{quote}
Logarithm of the magnetic field, which is constant
\end{quote}
\textbf{n} : float
\begin{quote}
Spin-down braking index
\end{quote}
\textbf{I} : float
\begin{quote}
Moment of inertia
\end{quote}
\textbf{R} : float
\begin{quote}
Radius
\end{quote}
\end{description}\end{quote}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{energy\_integrated() (gammapy.astro.source.Pulsar method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.Pulsar:gammapy.astro.source.Pulsar.energy_integrated}\pysiglinewithargsret{\bfcode{energy\_integrated}}{\emph{t=None}}{}
Total released energy at age t.
Time-integrated spin-down luminosity since birth.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{t} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Time after birth of the pulsar.
\end{quote}
\end{description}\end{quote}
\paragraph{Notes}
The time integrated energy is given by:
\begin{gather}
\begin{split}E(t) = \dot{L}_0 \tau_0 \frac{t}{t + \tau_0}\end{split}\notag
\end{gather}
\end{fulllineitems}
\index{luminosity\_spindown() (gammapy.astro.source.Pulsar method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.Pulsar:gammapy.astro.source.Pulsar.luminosity_spindown}\pysiglinewithargsret{\bfcode{luminosity\_spindown}}{\emph{t=None}}{}
Spin down luminosity at age t.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{t} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Time after birth of the pulsar.
\end{quote}
\end{description}\end{quote}
\paragraph{Notes}
The spin-down luminosity is given by:
\begin{gather}
\begin{split}\dot{L}(t) = \dot{L}_0 \left(1 + \frac{t}{\tau_0}\right)^{\frac{n + 1}{n - 1}}\end{split}\notag
\end{gather}
\end{fulllineitems}
\index{luminosity\_tev() (gammapy.astro.source.Pulsar method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.Pulsar:gammapy.astro.source.Pulsar.luminosity_tev}\pysiglinewithargsret{\bfcode{luminosity\_tev}}{\emph{t=None}, \emph{fraction=0.1}}{}
Gamma luminosity assumed to be a certain fraction of the spin-down
luminosity.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{t} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Time after birth of the pulsar.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{magnetic\_field() (gammapy.astro.source.Pulsar method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.Pulsar:gammapy.astro.source.Pulsar.magnetic_field}\pysiglinewithargsret{\bfcode{magnetic\_field}}{\emph{t=None}}{}
Magnetic field strength at the polar cap. Assumed to be constant.
\paragraph{Notes}
The magnetic field is given by:
\begin{gather}
\begin{split}B = 3.2\cdot 10^{19} (P\dot{P})^{1/2} [\textnormal(Gauss)]\end{split}\notag
\end{gather}
\end{fulllineitems}
\index{period() (gammapy.astro.source.Pulsar method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.Pulsar:gammapy.astro.source.Pulsar.period}\pysiglinewithargsret{\bfcode{period}}{\emph{t=None}}{}
Period at age t.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{t} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Time after birth of the pulsar.
\end{quote}
\end{description}\end{quote}
\paragraph{Notes}
The period is given by:
\begin{gather}
\begin{split}P(t) = P_0\left(1 + \frac{t}{\tau_0}\right)^{\frac{1}{n - 1}}\end{split}\notag
\end{gather}
\end{fulllineitems}
\index{period\_dot() (gammapy.astro.source.Pulsar method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.Pulsar:gammapy.astro.source.Pulsar.period_dot}\pysiglinewithargsret{\bfcode{period\_dot}}{\emph{t=None}}{}
Period derivative at age t.
P\_dot for a given period and magnetic field B, assuming a dipole
spin-down.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{t} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Time after birth of the pulsar.
\end{quote}
\end{description}\end{quote}
\paragraph{Notes}
The period derivative is given by:
\begin{gather}
\begin{split}\dot{P}(t) = \frac{B^2}{3.2 \cdot 10^{19} P(t)}\end{split}\notag
\end{gather}
\end{fulllineitems}
\index{tau() (gammapy.astro.source.Pulsar method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.Pulsar:gammapy.astro.source.Pulsar.tau}\pysiglinewithargsret{\bfcode{tau}}{\emph{t=None}}{}
Characteristic age at real age t.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{t} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Time after birth of the pulsar.
\end{quote}
\end{description}\end{quote}
\paragraph{Notes}
The characteritic age is given by:
\begin{gather}
\begin{split}\tau = \frac{P}{2\dot{P}}\end{split}\notag
\end{gather}
\end{fulllineitems}
\end{fulllineitems}
\subparagraph{SNR}
\label{api/gammapy.astro.source.SNR:astropy}\label{api/gammapy.astro.source.SNR::doc}\label{api/gammapy.astro.source.SNR:snr}\index{SNR (class in gammapy.astro.source)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.SNR:gammapy.astro.source.SNR}\pysiglinewithargsret{\strong{class }\code{gammapy.astro.source.}\bfcode{SNR}}{\emph{e\_sn=\textless{}Quantity 1e+51 erg\textgreater{}}, \emph{theta=\textless{}Quantity 0.1\textgreater{}}, \emph{n\_ISM=\textless{}Quantity 1.0 1 / cm3\textgreater{}}, \emph{m\_ejecta=\textless{}Constant name='Solar mass' value=1.9891e+30 error=5e+25 units='kg' reference=''Allen's Astrophysical Quantities 4th Ed.''\textgreater{}}, \emph{t\_stop=\textless{}Quantity 1000000.0 K\textgreater{}}, \emph{age=None}, \emph{morphology='Shell2D'}, \emph{spectral\_index=2.1}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Simple supernova remnant (SNR) evolution model.
The model is based on the Sedov-Taylor solution for strong explosions.
Reference: \href{http://adsabs.harvard.edu/abs/1950RSPSA.201..159T}{http://adsabs.harvard.edu/abs/1950RSPSA.201..159T}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{e\_sn} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
SNR energy (erg), equal to the SN energy after neutrino losses
\end{quote}
\textbf{theta} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Fraction of E\_SN that goes into cosmic rays
\end{quote}
\textbf{n\_ISM} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
ISM density (g cm\textasciicircum{}-3)
\end{quote}
\textbf{m\_ejecta} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Ejecta mass (g)
\end{quote}
\textbf{t\_stop} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Post-shock temperature where gamma-ray emission stops.
\end{quote}
\end{description}\end{quote}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{sedov\_taylor\_begin (gammapy.astro.source.SNR attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.SNR:gammapy.astro.source.SNR.sedov_taylor_begin}\pysigline{\bfcode{sedov\_taylor\_begin}}
Characteristic time scale when the Sedov-Taylor phase of the SNR's
evolution begins.
\paragraph{Notes}
The beginning of the Sedov-Taylor phase of the SNR is defined by the condition,
that the swept up mass of the surrounding medium equals the mass of the
ejected mass. The time scale is given by:
\begin{gather}
\begin{split}t_{begin} \approx 200 \ \textnormal{}
\left(\frac{E_{SN}}{10^{51}erg}\right)^{-1/2}
\left(\frac{M_{ej}}{M_{\odot}}\right)^{5/6}
\left(\frac{\rho_{ISM}}{10^{-24}g/cm^3}\right)^{-1/3}\end{split}\notag
\end{gather}
\end{fulllineitems}
\index{sedov\_taylor\_end (gammapy.astro.source.SNR attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.SNR:gammapy.astro.source.SNR.sedov_taylor_end}\pysigline{\bfcode{sedov\_taylor\_end}}
Characteristic time scale when the Sedov-Taylor phase of the SNR's evolution ends.
\paragraph{Notes}
The end of the Sedov-Taylor phase of the SNR is defined by the condition, that the
temperature at the shock drops below T = 10\textasciicircum{}6 K. The time scale is given by:
\begin{gather}
\begin{split}t_{end} \approx 43000 \textnormal{ }
\left(\frac{m}{1.66\cdot 10^{-24}g}\right)^{5/6}
\left(\frac{E_{SN}}{10^{51}erg}\right)^{1/3}
\left(\frac{\rho_{ISM}}{1.66\cdot 10^{-24}g/cm^3}\right)^{-1/3}\end{split}\notag
\end{gather}
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{luminosity\_tev() (gammapy.astro.source.SNR method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.SNR:gammapy.astro.source.SNR.luminosity_tev}\pysiglinewithargsret{\bfcode{luminosity\_tev}}{\emph{t=None}, \emph{energy\_min=\textless{}Quantity 1.0 TeV\textgreater{}}}{}
Gamma-ray luminosity above \code{energy\_min} at age t .
The luminosity is assumed constant in a given age interval and zero
before and after. The assumed spectral index is 2.1.
Reference: \href{http://adsabs.harvard.edu/abs/1994A\%26A...287..959D}{http://adsabs.harvard.edu/abs/1994A\%26A...287..959D} (Formula (7)).
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{t} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Time after birth of the SNR.
\end{quote}
\textbf{energy\_min} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Lower energy limit for the luminosity.
\end{quote}
\end{description}\end{quote}
\paragraph{Notes}
The gamma-ray luminosity above 1 TeV is given by:
\begin{gather}
\begin{split}L_{\gamma}(\geq 1TeV) \approx 10^{34} \theta
\left(\frac{E_{SN}}{10^{51} erg}\right)
\left(\frac{\rho_{ISM}}{1.66\cdot 10^{-24} g/cm^{3}} \right)
\textnormal{ph} s^{-1}\end{split}\notag
\end{gather}
\end{fulllineitems}
\index{radius() (gammapy.astro.source.SNR method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.SNR:gammapy.astro.source.SNR.radius}\pysiglinewithargsret{\bfcode{radius}}{\emph{t=None}}{}
Outer shell radius at age t.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{t} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Time after birth of the SNR.
\end{quote}
\end{description}\end{quote}
\paragraph{Notes}
The radius during the free expansion phase is given by:
\begin{gather}
\begin{split}r_{SNR}(t) \approx 0.01 \textnormal{}
\left(\frac{E_{SN}}{10^{51}erg}\right)^{1/2}
\left(\frac{M_{ej}}{M_{\odot}}\right)^{-1/2} t\end{split}\notag
\end{gather}
The radius during the Sedov-Taylor phase evolves like:
\begin{gather}
\begin{split}r_{SNR}(t) \approx \left(\frac{E_{SN}}{\rho_{ISM}}\right)^{1/5}t^{2/5}\end{split}\notag
\end{gather}
\end{fulllineitems}
\index{radius\_inner() (gammapy.astro.source.SNR method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.SNR:gammapy.astro.source.SNR.radius_inner}\pysiglinewithargsret{\bfcode{radius\_inner}}{\emph{t}, \emph{fraction=0.0914}}{}
Inner radius at age t of the SNR shell.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{t} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Time after birth of the SNR.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\end{fulllineitems}
\subparagraph{SNRTrueloveMcKee}
\label{api/gammapy.astro.source.SNRTrueloveMcKee:astropy}\label{api/gammapy.astro.source.SNRTrueloveMcKee::doc}\label{api/gammapy.astro.source.SNRTrueloveMcKee:snrtruelovemckee}\index{SNRTrueloveMcKee (class in gammapy.astro.source)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.SNRTrueloveMcKee:gammapy.astro.source.SNRTrueloveMcKee}\pysiglinewithargsret{\strong{class }\code{gammapy.astro.source.}\bfcode{SNRTrueloveMcKee}}{\emph{*args}, \emph{**kwargs}}{}
Bases: {\hyperref[api/gammapy.astro.source.SNR:gammapy.astro.source.SNR]{\emph{\code{gammapy.astro.source.SNR}}}}
SNR model according to Truelove \& McKee (1999).
Reference: \href{http://adsabs.harvard.edu/abs/1999ApJS..120..299T}{http://adsabs.harvard.edu/abs/1999ApJS..120..299T}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{sedov\_taylor\_begin (gammapy.astro.source.SNRTrueloveMcKee attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.SNRTrueloveMcKee:gammapy.astro.source.SNRTrueloveMcKee.sedov_taylor_begin}\pysigline{\bfcode{sedov\_taylor\_begin}}
Characteristic time scale when the Sedov-Taylor phase of the SNR's
evolution begins given by \(t_{ST} \approx 0.52 t_{ch}\)
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{radius() (gammapy.astro.source.SNRTrueloveMcKee method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.SNRTrueloveMcKee:gammapy.astro.source.SNRTrueloveMcKee.radius}\pysiglinewithargsret{\bfcode{radius}}{\emph{t=None}}{}
Outer shell radius at age t.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{t} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Time after birth of the SNR.
\end{quote}
\end{description}\end{quote}
\paragraph{Notes}
The radius during the free expansion phase is given by:
\begin{gather}
\begin{split}R_{SNR}(t) = 1.12R_{ch}\left(\frac{t}{t_{ch}}\right)^{2/3}\end{split}\notag
\end{gather}
The radius during the Sedov-Taylor phase evolves like:
\begin{gather}
\begin{split}R_{SNR}(t) = \left[R_{SNR, ST}^{5/2} + \left(2.026\frac{E_{SN}}
{\rho_{ISM}}\right)^{1/2}(t - t_{ST})\right]^{2/5}\end{split}\notag
\end{gather}
Using the characteristic dimensions:
\begin{gather}
\begin{split}R_{ch} = M_{ej}^{1/3}\rho_{ISM}^{-1/3} \ \
\textnormal{and} \ \ t_{ch} = E_{SN}^{-1/2}M_{ej}^{5/6}\rho_{ISM}^{-1/3}\end{split}\notag
\end{gather}
\end{fulllineitems}
\index{radius\_reverse\_shock() (gammapy.astro.source.SNRTrueloveMcKee method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.SNRTrueloveMcKee:gammapy.astro.source.SNRTrueloveMcKee.radius_reverse_shock}\pysiglinewithargsret{\bfcode{radius\_reverse\_shock}}{\emph{t}}{}
Reverse shock radius at age t .
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{t} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Time after birth of the SNR.
\end{quote}
\end{description}\end{quote}
\paragraph{Notes}
Initially the reverse shock co-evolves with the radius of the SNR:
\begin{gather}
\begin{split}R_{RS}(t) = \frac{1}{1.19}r_{SNR}(t)\end{split}\notag
\end{gather}
After a time \(t_{core} \simeq 0.25t_{ch}\) the reverse shock reaches
the core and then propagates as:
\begin{gather}
\begin{split}R_{RS}(t) = \left[1.49 - 0.16 \frac{t - t_{core}}{t_{ch}} - 0.46
\ln \left(\frac{t}{t_{core}}\right)\right]\frac{R_{ch}}{t_{ch}}t\end{split}\notag
\end{gather}
\end{fulllineitems}
\end{fulllineitems}
\subparagraph{SimplePulsar}
\label{api/gammapy.astro.source.SimplePulsar:astropy}\label{api/gammapy.astro.source.SimplePulsar::doc}\label{api/gammapy.astro.source.SimplePulsar:simplepulsar}\index{SimplePulsar (class in gammapy.astro.source)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.SimplePulsar:gammapy.astro.source.SimplePulsar}\pysiglinewithargsret{\strong{class }\code{gammapy.astro.source.}\bfcode{SimplePulsar}}{\emph{P}, \emph{P\_dot}, \emph{I=\textless{}Quantity 1e+45 cm2 g\textgreater{}}, \emph{R=\textless{}Quantity 1000000.0 cm\textgreater{}}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Magnetic dipole spin-down model for a pulsar.
Reference: \href{http://www.cv.nrao.edu/course/astr534/Pulsars.html}{http://www.cv.nrao.edu/course/astr534/Pulsars.html}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{P} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Rotation period (sec)
\end{quote}
\textbf{P\_dot} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Rotation period derivative (sec sec\textasciicircum{}-1)
\end{quote}
\textbf{I} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Moment of inertia (g cm\textasciicircum{}2)
\end{quote}
\textbf{R} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Radius of the pulsar (cm)
\end{quote}
\end{description}\end{quote}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.astro.source.SimplePulsar:gammapy.astro.source.SimplePulsar.luminosity_spindown]{\emph{\code{luminosity\_spindown}}}}
&
Spin-down luminosity.
\\
\hline
{\hyperref[api/gammapy.astro.source.SimplePulsar:gammapy.astro.source.SimplePulsar.magnetic_field]{\emph{\code{magnetic\_field}}}}
&
Magnetic field strength at the polar cap.
\\
\hline
{\hyperref[api/gammapy.astro.source.SimplePulsar:gammapy.astro.source.SimplePulsar.tau]{\emph{\code{tau}}}}
&
Characteristic age.
\\
\hline\end{longtable}
\paragraph{Attributes Documentation}
\index{luminosity\_spindown (gammapy.astro.source.SimplePulsar attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.SimplePulsar:gammapy.astro.source.SimplePulsar.luminosity_spindown}\pysigline{\bfcode{luminosity\_spindown}}
Spin-down luminosity.
\paragraph{Notes}
The spin-down luminosity is given by:
\begin{gather}
\begin{split}\dot{L} = 4\pi^2 I \frac{\dot{P}}{P^{3}}\end{split}\notag
\end{gather}
\end{fulllineitems}
\index{magnetic\_field (gammapy.astro.source.SimplePulsar attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.SimplePulsar:gammapy.astro.source.SimplePulsar.magnetic_field}\pysigline{\bfcode{magnetic\_field}}
Magnetic field strength at the polar cap.
\paragraph{Notes}
The magnetic field is given by:
\begin{gather}
\begin{split}B = 3.2\cdot 10^{19} (P\dot{P})^{1/2} [\textnormal(Gauss)]\end{split}\notag
\end{gather}
\end{fulllineitems}
\index{tau (gammapy.astro.source.SimplePulsar attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.source.SimplePulsar:gammapy.astro.source.SimplePulsar.tau}\pysigline{\bfcode{tau}}
Characteristic age.
\paragraph{Notes}
The characteristic age is given by:
\begin{gather}
\begin{split}\tau = \frac{P}{2\dot{P}}\end{split}\notag
\end{gather}
\end{fulllineitems}
\end{fulllineitems}
\subsection{Astrophysical source population models (\texttt{gammapy.astro.population})}
\label{astro/population/index:astrophysical-source-population-models-gammapy-astro-population}\label{astro/population/index:astropy}\label{astro/population/index::doc}\label{astro/population/index:astro-population}
\subsubsection{Introduction}
\label{astro/population/index:introduction}
The {\hyperref[astro/population/index:module-gammapy.astro.population]{\emph{\code{gammapy.astro.population}}}} module provides a simple framework for population synthesis of
gamma-ray sources.
\subsubsection{Getting Started}
\label{astro/population/index:getting-started}
TODO
\subsubsection{Radial surface density distributions}
\label{astro/population/index:radial-surface-density-distributions}
Here is a comparison plot of all available radial distribution functions of the surface density of pulsars
and related objects used in literature:
\includegraphics{plot_radial_distributions.pdf}
\subsubsection{Velocity distributions}
\label{astro/population/index:velocity-distributions}
Here is a comparison plot of all available velocity distribution functions:
\includegraphics{plot_velocity_distributions.pdf}
\subsubsection{Reference/API}
\label{astro/population/index:reference-api}
\paragraph{gammapy.astro.population Package}
\label{astro/population/index:gammapy-astro-population-package}\label{astro/population/index:module-gammapy.astro.population}\index{gammapy.astro.population (module)}
Astrophysical population models
\subparagraph{Functions}
\label{astro/population/index:functions}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.astro.population.add_observed_parameters:gammapy.astro.population.add_observed_parameters]{\emph{\code{add\_observed\_parameters}}}}(table{[}, obs\_pos{]})
&
For a given observer position (default: earth) add observed parameters to the table for given physical parameters.
\\
\hline
{\hyperref[api/gammapy.astro.population.add_observed_source_parameters:gammapy.astro.population.add_observed_source_parameters]{\emph{\code{add\_observed\_source\_parameters}}}}(table)
&
Adds observed source parameters to the table.
\\
\hline
{\hyperref[api/gammapy.astro.population.add_pulsar_parameters:gammapy.astro.population.add_pulsar_parameters]{\emph{\code{add\_pulsar\_parameters}}}}(table{[}, B\_mean, ...{]})
&
Adds pulsar parameters to the table.
\\
\hline
{\hyperref[api/gammapy.astro.population.add_pwn_parameters:gammapy.astro.population.add_pwn_parameters]{\emph{\code{add\_pwn\_parameters}}}}(table)
&
Adds PWN parameters to the table.
\\
\hline
{\hyperref[api/gammapy.astro.population.add_snr_parameters:gammapy.astro.population.add_snr_parameters]{\emph{\code{add\_snr\_parameters}}}}(table)
&
Adds SNR parameters to the table.
\\
\hline
{\hyperref[api/gammapy.astro.population.make_base_catalog_galactic:gammapy.astro.population.make_base_catalog_galactic]{\emph{\code{make\_base\_catalog\_galactic}}}}(n\_sources{[}, ...{]})
&
Make a catalog of Galactic sources, with basic parameters like position, age and proper velocity.
\\
\hline
{\hyperref[api/gammapy.astro.population.make_catalog_random_positions_cube:gammapy.astro.population.make_catalog_random_positions_cube]{\emph{\code{make\_catalog\_random\_positions\_cube}}}}({[}size, ...{]})
&
Make a catalog of sources randomly distributed on a line, square or cube.
\\
\hline
{\hyperref[api/gammapy.astro.population.make_catalog_random_positions_sphere:gammapy.astro.population.make_catalog_random_positions_sphere]{\emph{\code{make\_catalog\_random\_positions\_sphere}}}}(size{[}, ...{]})
&
Sample random source locations in a sphere.
\\
\hline\end{longtable}
\subparagraph{add\_observed\_parameters}
\label{api/gammapy.astro.population.add_observed_parameters::doc}\label{api/gammapy.astro.population.add_observed_parameters:add-observed-parameters}\index{add\_observed\_parameters() (in module gammapy.astro.population)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.add_observed_parameters:gammapy.astro.population.add_observed_parameters}\pysiglinewithargsret{\code{gammapy.astro.population.}\bfcode{add\_observed\_parameters}}{\emph{table, obs\_pos={[}\textless{}Quantity 8.5 kpc\textgreater{}, 0, 0{]}}}{}
For a given observer position (default: earth)
add observed parameters to the
table for given physical parameters.
Input parameters:
x, y, z, extension, luminosity
Output parameters:
distance, glon, glat, flux, angular\_extension
Position of observer in cartesian coordinates.
Center of galaxy as origin, x-axis goes trough sun.
\end{fulllineitems}
\subparagraph{add\_observed\_source\_parameters}
\label{api/gammapy.astro.population.add_observed_source_parameters:astropy}\label{api/gammapy.astro.population.add_observed_source_parameters::doc}\label{api/gammapy.astro.population.add_observed_source_parameters:add-observed-source-parameters}\index{add\_observed\_source\_parameters() (in module gammapy.astro.population)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.add_observed_source_parameters:gammapy.astro.population.add_observed_source_parameters}\pysiglinewithargsret{\code{gammapy.astro.population.}\bfcode{add\_observed\_source\_parameters}}{\emph{table}}{}
Adds observed source parameters to the table.
\end{fulllineitems}
\subparagraph{add\_pulsar\_parameters}
\label{api/gammapy.astro.population.add_pulsar_parameters:astropy}\label{api/gammapy.astro.population.add_pulsar_parameters::doc}\label{api/gammapy.astro.population.add_pulsar_parameters:add-pulsar-parameters}\index{add\_pulsar\_parameters() (in module gammapy.astro.population)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.add_pulsar_parameters:gammapy.astro.population.add_pulsar_parameters}\pysiglinewithargsret{\code{gammapy.astro.population.}\bfcode{add\_pulsar\_parameters}}{\emph{table}, \emph{B\_mean=12.05}, \emph{B\_stdv=0.55}, \emph{P\_mean=0.3}, \emph{P\_stdv=0.15}, \emph{random\_state='random-seed'}}{}
Adds pulsar parameters to the table.
For the initial normal distribution of period and logB can exist the following
Parameters: B\_mean=12.05{[}log Gauss{]}, B\_stdv=0.55, P\_mean=0.3{[}s{]}, P\_stdv=0.15
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{random\_state} : \{int, `random-seed', `global-rng', \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.RandomState.html\#numpy.random.RandomState}{\code{RandomState}}\}
\begin{quote}
Defines random number generator initialisation.
Passed to {\hyperref[api/gammapy.utils.random.get_random_state:gammapy.utils.random.get_random_state]{\emph{\code{get\_random\_state}}}}.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\subparagraph{add\_pwn\_parameters}
\label{api/gammapy.astro.population.add_pwn_parameters:astropy}\label{api/gammapy.astro.population.add_pwn_parameters::doc}\label{api/gammapy.astro.population.add_pwn_parameters:add-pwn-parameters}\index{add\_pwn\_parameters() (in module gammapy.astro.population)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.add_pwn_parameters:gammapy.astro.population.add_pwn_parameters}\pysiglinewithargsret{\code{gammapy.astro.population.}\bfcode{add\_pwn\_parameters}}{\emph{table}}{}
Adds PWN parameters to the table.
\end{fulllineitems}
\subparagraph{add\_snr\_parameters}
\label{api/gammapy.astro.population.add_snr_parameters:add-snr-parameters}\label{api/gammapy.astro.population.add_snr_parameters:astropy}\label{api/gammapy.astro.population.add_snr_parameters::doc}\index{add\_snr\_parameters() (in module gammapy.astro.population)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.add_snr_parameters:gammapy.astro.population.add_snr_parameters}\pysiglinewithargsret{\code{gammapy.astro.population.}\bfcode{add\_snr\_parameters}}{\emph{table}}{}
Adds SNR parameters to the table.
\end{fulllineitems}
\subparagraph{make\_base\_catalog\_galactic}
\label{api/gammapy.astro.population.make_base_catalog_galactic:astropy}\label{api/gammapy.astro.population.make_base_catalog_galactic::doc}\label{api/gammapy.astro.population.make_base_catalog_galactic:make-base-catalog-galactic}\index{make\_base\_catalog\_galactic() (in module gammapy.astro.population)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.make_base_catalog_galactic:gammapy.astro.population.make_base_catalog_galactic}\pysiglinewithargsret{\code{gammapy.astro.population.}\bfcode{make\_base\_catalog\_galactic}}{\emph{n\_sources}, \emph{rad\_dis='YK04'}, \emph{vel\_dis='H05'}, \emph{max\_age=\textless{}Quantity 1000000.0 yr\textgreater{}}, \emph{spiralarms=True}, \emph{n\_ISM=\textless{}Quantity 1.0 1 / cm3\textgreater{}}, \emph{random\_state='random-seed'}}{}
Make a catalog of Galactic sources, with basic parameters like position, age and
proper velocity.
Choose a radial distribution, a velocity distribution, the number
of pulsars n\_pulsars, the maximal age max\_age{[}years{]} and the fraction
of the individual morphtypes. There's an option spiralarms. If set on
True a spiralarm modelling after Faucher\&Kaspi is included.
max\_age and n\_sources effectively correspond to s SN rate:
SN\_rate = n\_sources / max\_age
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{n\_sources} : int
\begin{quote}
Number of sources to simulate.
\end{quote}
\textbf{rad\_dis} : callable
\begin{quote}
Radial surface density distribution of sources.
\end{quote}
\textbf{vel\_dis} : callable
\begin{quote}
Proper motion velocity distribution of sources.
\end{quote}
\textbf{max\_age} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Maximal age of the source
\end{quote}
\textbf{spiralarms} : bool
\begin{quote}
Include a spiralarm model in the catalog.
\end{quote}
\textbf{n\_ISM} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Density of the interstellar medium.
\end{quote}
\textbf{random\_state} : \{int, `random-seed', `global-rng', \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.RandomState.html\#numpy.random.RandomState}{\code{RandomState}}\}
\begin{quote}
Defines random number generator initialisation.
Passed to {\hyperref[api/gammapy.utils.random.get_random_state:gammapy.utils.random.get_random_state]{\emph{\code{get\_random\_state}}}}.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{table} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Catalog of simulated source positions and proper velocities.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\subparagraph{make\_catalog\_random\_positions\_cube}
\label{api/gammapy.astro.population.make_catalog_random_positions_cube:astropy}\label{api/gammapy.astro.population.make_catalog_random_positions_cube::doc}\label{api/gammapy.astro.population.make_catalog_random_positions_cube:make-catalog-random-positions-cube}\index{make\_catalog\_random\_positions\_cube() (in module gammapy.astro.population)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.make_catalog_random_positions_cube:gammapy.astro.population.make_catalog_random_positions_cube}\pysiglinewithargsret{\code{gammapy.astro.population.}\bfcode{make\_catalog\_random\_positions\_cube}}{\emph{size=100}, \emph{dimension=3}, \emph{dmax=10}, \emph{random\_state='random-seed'}}{}
Make a catalog of sources randomly distributed
on a line, square or cube.
\begin{description}
\item[{TODO: is this useful enough for general use or should we hide it as an}] \leavevmode
internal method to generate test datasets?
\end{description}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{size} : int, optional
\begin{quote}
Number of sources
\end{quote}
\textbf{dimension} : int, optional
\begin{quote}
Number of dimensions
\end{quote}
\textbf{dmax} : int, optional
\begin{quote}
Maximum distance in pc.
\end{quote}
\textbf{random\_state} : \{int, `random-seed', `global-rng', \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.RandomState.html\#numpy.random.RandomState}{\code{RandomState}}\}
\begin{quote}
Defines random number generator initialisation.
Passed to {\hyperref[api/gammapy.utils.random.get_random_state:gammapy.utils.random.get_random_state]{\emph{\code{get\_random\_state}}}}.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{catalog} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Source catalog with columns:
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\subparagraph{make\_catalog\_random\_positions\_sphere}
\label{api/gammapy.astro.population.make_catalog_random_positions_sphere:astropy}\label{api/gammapy.astro.population.make_catalog_random_positions_sphere::doc}\label{api/gammapy.astro.population.make_catalog_random_positions_sphere:make-catalog-random-positions-sphere}\index{make\_catalog\_random\_positions\_sphere() (in module gammapy.astro.population)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.make_catalog_random_positions_sphere:gammapy.astro.population.make_catalog_random_positions_sphere}\pysiglinewithargsret{\code{gammapy.astro.population.}\bfcode{make\_catalog\_random\_positions\_sphere}}{\emph{size}, \emph{center='Earth'}, \emph{distance=\textless{}Quantity {[} 0.}, \emph{1.{]} Mpc\textgreater{}}, \emph{random\_state='random-seed'}}{}
Sample random source locations in a sphere.
This can be used to generate an isotropic source population
to represent extra-galactic sources.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{size} : int
\begin{quote}
Number of sources
\end{quote}
\textbf{center} : \{`Earth', `Milky Way'\}
\begin{quote}
Sphere center
\end{quote}
\textbf{distance} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}} tuple
\begin{quote}
Distance min / max range.
\end{quote}
\textbf{random\_state} : \{int, `random-seed', `global-rng', \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.RandomState.html\#numpy.random.RandomState}{\code{RandomState}}\}
\begin{quote}
Defines random number generator initialisation.
Passed to {\hyperref[api/gammapy.utils.random.get_random_state:gammapy.utils.random.get_random_state]{\emph{\code{get\_random\_state}}}}.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{catalog} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Source catalog with columns:
\begin{itemize}
\item {}
RAJ2000, DEJ2000 (deg)
\item {}
GLON, GLAT (deg)
\item {}
Distance (Mpc)
\end{itemize}
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\subparagraph{Classes}
\label{astro/population/index:astropy}\label{astro/population/index:classes}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.astro.population.CaseBattacharya1998:gammapy.astro.population.CaseBattacharya1998]{\emph{\code{CaseBattacharya1998}}}}({[}amplitude, alpha, beta{]})
&
Radial distribution of the surface density of supernova remnants in the galaxy - Case \& Battacharya 1998.
\\
\hline
{\hyperref[api/gammapy.astro.population.Exponential:gammapy.astro.population.Exponential]{\emph{\code{Exponential}}}}({[}amplitude, z\_0{]})
&
Exponential distribution.
\\
\hline
{\hyperref[api/gammapy.astro.population.FaucherKaspi2006:gammapy.astro.population.FaucherKaspi2006]{\emph{\code{FaucherKaspi2006}}}}({[}amplitude, r\_0, sigma{]})
&
Radial distribution of the birth surface density of pulsars in the galaxy - Faucher-Giguere \& Kaspi 2006.
\\
\hline
{\hyperref[api/gammapy.astro.population.FaucherKaspi2006VelocityBimodal:gammapy.astro.population.FaucherKaspi2006VelocityBimodal]{\emph{\code{FaucherKaspi2006VelocityBimodal}}}}({[}amplitude, ...{]})
&
Bimodal pulsar velocity distribution - Faucher \& Kaspi (2006).
\\
\hline
{\hyperref[api/gammapy.astro.population.FaucherKaspi2006VelocityMaxwellian:gammapy.astro.population.FaucherKaspi2006VelocityMaxwellian]{\emph{\code{FaucherKaspi2006VelocityMaxwellian}}}}({[}...{]})
&
Maxwellian pulsar velocity distribution.
\\
\hline
{\hyperref[api/gammapy.astro.population.FaucherSpiral:gammapy.astro.population.FaucherSpiral]{\emph{\code{FaucherSpiral}}}}
&
Milky way spiral arm used in Faucher et al.
\\
\hline
{\hyperref[api/gammapy.astro.population.LogSpiral:gammapy.astro.population.LogSpiral]{\emph{\code{LogSpiral}}}}
&
Logarithmic spiral.
\\
\hline
{\hyperref[api/gammapy.astro.population.Lorimer2006:gammapy.astro.population.Lorimer2006]{\emph{\code{Lorimer2006}}}}({[}amplitude, B, C{]})
&
Radial distribution of the suface density of pulsars in the galaxy - Lorimer 2006.
\\
\hline
{\hyperref[api/gammapy.astro.population.Paczynski1990:gammapy.astro.population.Paczynski1990]{\emph{\code{Paczynski1990}}}}({[}amplitude, r\_exp{]})
&
Radial distribution of the birth surface density of neutron stars - Paczynski 1990.
\\
\hline
{\hyperref[api/gammapy.astro.population.Paczynski1990Velocity:gammapy.astro.population.Paczynski1990Velocity]{\emph{\code{Paczynski1990Velocity}}}}({[}amplitude, v\_0{]})
&
Distribution by Lyne 1982 and adopted by Paczynski and Faucher.
\\
\hline
{\hyperref[api/gammapy.astro.population.ValleeSpiral:gammapy.astro.population.ValleeSpiral]{\emph{\code{ValleeSpiral}}}}()
&
Milky way spiral arm model from Vallee (2008).
\\
\hline
{\hyperref[api/gammapy.astro.population.YusifovKucuk2004:gammapy.astro.population.YusifovKucuk2004]{\emph{\code{YusifovKucuk2004}}}}({[}amplitude, a, b, r\_1{]})
&
Radial distribution of the surface density of pulsars in the galaxy - Yusifov \& Kucuk 2004.
\\
\hline
{\hyperref[api/gammapy.astro.population.YusifovKucuk2004B:gammapy.astro.population.YusifovKucuk2004B]{\emph{\code{YusifovKucuk2004B}}}}({[}amplitude, a, b{]})
&
Radial distribution of the surface density of OB stars in the galaxy - Yusifov \& Kucuk 2004.
\\
\hline\end{longtable}
\subparagraph{CaseBattacharya1998}
\label{api/gammapy.astro.population.CaseBattacharya1998::doc}\label{api/gammapy.astro.population.CaseBattacharya1998:casebattacharya1998}\index{CaseBattacharya1998 (class in gammapy.astro.population)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.CaseBattacharya1998:gammapy.astro.population.CaseBattacharya1998}\pysiglinewithargsret{\strong{class }\code{gammapy.astro.population.}\bfcode{CaseBattacharya1998}}{\emph{amplitude=1.0}, \emph{alpha=2}, \emph{beta=3.53}, \emph{**kwargs}}{}
Bases: \href{http://docs.astropy.org/en/latest/api/astropy.modeling.Fittable1DModel.html\#astropy.modeling.Fittable1DModel}{\code{astropy.modeling.Fittable1DModel}}
Radial distribution of the surface density of supernova remnants in the
galaxy - Case \& Battacharya 1998.
\begin{gather}
\begin{split}f(r) = A \left( \frac{r}{r_{\odot}} \right) ^ \alpha \exp
\left[ -\beta \left( \frac{ r - r_{\odot}}{r_{\odot}} \right) \right]\end{split}\notag
\end{gather}
Reference: \href{http://adsabs.harvard.edu//abs/1998ApJ...504..761C}{http://adsabs.harvard.edu//abs/1998ApJ...504..761C} (Formula (14))
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{amplitude} : float
\begin{quote}
See model formula
\end{quote}
\textbf{alpha} : float
\begin{quote}
See model formula
\end{quote}
\textbf{beta} : float
\begin{quote}
See model formula
\end{quote}
\end{description}\end{quote}
\strong{See also:}
{\hyperref[api/gammapy.astro.population.Paczynski1990:gammapy.astro.population.Paczynski1990]{\emph{\code{Paczynski1990}}}}, {\hyperref[api/gammapy.astro.population.YusifovKucuk2004:gammapy.astro.population.YusifovKucuk2004]{\emph{\code{YusifovKucuk2004}}}}, {\hyperref[api/gammapy.astro.population.Lorimer2006:gammapy.astro.population.Lorimer2006]{\emph{\code{Lorimer2006}}}}, {\hyperref[api/gammapy.astro.population.YusifovKucuk2004B:gammapy.astro.population.YusifovKucuk2004B]{\emph{\code{YusifovKucuk2004B}}}}, {\hyperref[api/gammapy.astro.population.FaucherKaspi2006:gammapy.astro.population.FaucherKaspi2006]{\emph{\code{FaucherKaspi2006}}}}, {\hyperref[api/gammapy.astro.population.Exponential:gammapy.astro.population.Exponential]{\emph{\code{Exponential}}}}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.astro.population.CaseBattacharya1998:gammapy.astro.population.CaseBattacharya1998.evolved]{\emph{\code{evolved}}}}
&
\\
\hline
{\hyperref[api/gammapy.astro.population.CaseBattacharya1998:gammapy.astro.population.CaseBattacharya1998.param_names]{\emph{\code{param\_names}}}}
&
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{alpha (gammapy.astro.population.CaseBattacharya1998 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.CaseBattacharya1998:gammapy.astro.population.CaseBattacharya1998.alpha}\pysigline{\bfcode{alpha}}
\end{fulllineitems}
\index{amplitude (gammapy.astro.population.CaseBattacharya1998 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.CaseBattacharya1998:gammapy.astro.population.CaseBattacharya1998.amplitude}\pysigline{\bfcode{amplitude}}
\end{fulllineitems}
\index{beta (gammapy.astro.population.CaseBattacharya1998 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.CaseBattacharya1998:gammapy.astro.population.CaseBattacharya1998.beta}\pysigline{\bfcode{beta}}
\end{fulllineitems}
\index{evolved (gammapy.astro.population.CaseBattacharya1998 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.CaseBattacharya1998:gammapy.astro.population.CaseBattacharya1998.evolved}\pysigline{\bfcode{evolved}\strong{ = True}}
\end{fulllineitems}
\index{param\_names (gammapy.astro.population.CaseBattacharya1998 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.CaseBattacharya1998:gammapy.astro.population.CaseBattacharya1998.param_names}\pysigline{\bfcode{param\_names}\strong{ = (`amplitude', `alpha', `beta')}}
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{evaluate() (gammapy.astro.population.CaseBattacharya1998 static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.CaseBattacharya1998:gammapy.astro.population.CaseBattacharya1998.evaluate}\pysiglinewithargsret{\strong{static }\bfcode{evaluate}}{\emph{r}, \emph{amplitude}, \emph{alpha}, \emph{beta}}{}
One dimensional Case \& Battacharya 2006 model function
\end{fulllineitems}
\end{fulllineitems}
\subparagraph{Exponential}
\label{api/gammapy.astro.population.Exponential:exponential}\label{api/gammapy.astro.population.Exponential:astropy}\label{api/gammapy.astro.population.Exponential::doc}\index{Exponential (class in gammapy.astro.population)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Exponential:gammapy.astro.population.Exponential}\pysiglinewithargsret{\strong{class }\code{gammapy.astro.population.}\bfcode{Exponential}}{\emph{amplitude=1}, \emph{z\_0=0.05}, \emph{**kwargs}}{}
Bases: \href{http://docs.astropy.org/en/latest/api/astropy.modeling.Fittable1DModel.html\#astropy.modeling.Fittable1DModel}{\code{astropy.modeling.Fittable1DModel}}
Exponential distribution.
\begin{gather}
\begin{split}f(z) = A \exp \left(- \frac{|z|}{z_0} \right)\end{split}\notag
\end{gather}
Usually used for height distribution above the Galactic plane,
with 0.05 kpc as a commonly used birth height distribution.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{amplitude} : float
\begin{quote}
See model formula
\end{quote}
\textbf{z\_0} : float
\begin{quote}
Scale height of the distribution
\end{quote}
\end{description}\end{quote}
\strong{See also:}
{\hyperref[api/gammapy.astro.population.CaseBattacharya1998:gammapy.astro.population.CaseBattacharya1998]{\emph{\code{CaseBattacharya1998}}}}, {\hyperref[api/gammapy.astro.population.Paczynski1990:gammapy.astro.population.Paczynski1990]{\emph{\code{Paczynski1990}}}}, {\hyperref[api/gammapy.astro.population.YusifovKucuk2004:gammapy.astro.population.YusifovKucuk2004]{\emph{\code{YusifovKucuk2004}}}}, {\hyperref[api/gammapy.astro.population.Lorimer2006:gammapy.astro.population.Lorimer2006]{\emph{\code{Lorimer2006}}}}, {\hyperref[api/gammapy.astro.population.YusifovKucuk2004B:gammapy.astro.population.YusifovKucuk2004B]{\emph{\code{YusifovKucuk2004B}}}}, {\hyperref[api/gammapy.astro.population.FaucherKaspi2006:gammapy.astro.population.FaucherKaspi2006]{\emph{\code{FaucherKaspi2006}}}}, {\hyperref[api/gammapy.astro.population.Exponential:gammapy.astro.population.Exponential]{\emph{\code{Exponential}}}}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.astro.population.Exponential:gammapy.astro.population.Exponential.evolved]{\emph{\code{evolved}}}}
&
\\
\hline
{\hyperref[api/gammapy.astro.population.Exponential:gammapy.astro.population.Exponential.param_names]{\emph{\code{param\_names}}}}
&
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{amplitude (gammapy.astro.population.Exponential attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Exponential:gammapy.astro.population.Exponential.amplitude}\pysigline{\bfcode{amplitude}}
\end{fulllineitems}
\index{evolved (gammapy.astro.population.Exponential attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Exponential:gammapy.astro.population.Exponential.evolved}\pysigline{\bfcode{evolved}\strong{ = False}}
\end{fulllineitems}
\index{param\_names (gammapy.astro.population.Exponential attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Exponential:gammapy.astro.population.Exponential.param_names}\pysigline{\bfcode{param\_names}\strong{ = (`amplitude', `z\_0')}}
\end{fulllineitems}
\index{z\_0 (gammapy.astro.population.Exponential attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Exponential:gammapy.astro.population.Exponential.z_0}\pysigline{\bfcode{z\_0}}
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{evaluate() (gammapy.astro.population.Exponential static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Exponential:gammapy.astro.population.Exponential.evaluate}\pysiglinewithargsret{\strong{static }\bfcode{evaluate}}{\emph{z}, \emph{amplitude}, \emph{z\_0}}{}
One dimensional exponential model function
\end{fulllineitems}
\end{fulllineitems}
\subparagraph{FaucherKaspi2006}
\label{api/gammapy.astro.population.FaucherKaspi2006:faucherkaspi2006}\label{api/gammapy.astro.population.FaucherKaspi2006:astropy}\label{api/gammapy.astro.population.FaucherKaspi2006::doc}\index{FaucherKaspi2006 (class in gammapy.astro.population)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherKaspi2006:gammapy.astro.population.FaucherKaspi2006}\pysiglinewithargsret{\strong{class }\code{gammapy.astro.population.}\bfcode{FaucherKaspi2006}}{\emph{amplitude=1}, \emph{r\_0=7.04}, \emph{sigma=1.83}, \emph{**kwargs}}{}
Bases: \href{http://docs.astropy.org/en/latest/api/astropy.modeling.Fittable1DModel.html\#astropy.modeling.Fittable1DModel}{\code{astropy.modeling.Fittable1DModel}}
Radial distribution of the birth surface density of pulsars in the galaxy - Faucher-Giguere \& Kaspi 2006.
\begin{gather}
\begin{split}f(r) = A \frac{1}{\sqrt{2 \pi} \sigma} \exp
\left(- \frac{(r - r_0)^2}{2 \sigma ^ 2}\right)\end{split}\notag
\end{gather}
Reference: \href{http://adsabs.harvard.edu/abs/2006ApJ...643..332F}{http://adsabs.harvard.edu/abs/2006ApJ...643..332F} (Appendix B)
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{amplitude} : float
\begin{quote}
See model formula
\end{quote}
\textbf{r\_0} : float
\begin{quote}
See model formula
\end{quote}
\textbf{sigma} : float
\begin{quote}
See model formula
\end{quote}
\end{description}\end{quote}
\strong{See also:}
{\hyperref[api/gammapy.astro.population.CaseBattacharya1998:gammapy.astro.population.CaseBattacharya1998]{\emph{\code{CaseBattacharya1998}}}}, {\hyperref[api/gammapy.astro.population.Paczynski1990:gammapy.astro.population.Paczynski1990]{\emph{\code{Paczynski1990}}}}, {\hyperref[api/gammapy.astro.population.YusifovKucuk2004:gammapy.astro.population.YusifovKucuk2004]{\emph{\code{YusifovKucuk2004}}}}, {\hyperref[api/gammapy.astro.population.Lorimer2006:gammapy.astro.population.Lorimer2006]{\emph{\code{Lorimer2006}}}}, {\hyperref[api/gammapy.astro.population.YusifovKucuk2004B:gammapy.astro.population.YusifovKucuk2004B]{\emph{\code{YusifovKucuk2004B}}}}, {\hyperref[api/gammapy.astro.population.Exponential:gammapy.astro.population.Exponential]{\emph{\code{Exponential}}}}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.astro.population.FaucherKaspi2006:gammapy.astro.population.FaucherKaspi2006.evolved]{\emph{\code{evolved}}}}
&
\\
\hline
{\hyperref[api/gammapy.astro.population.FaucherKaspi2006:gammapy.astro.population.FaucherKaspi2006.param_names]{\emph{\code{param\_names}}}}
&
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{amplitude (gammapy.astro.population.FaucherKaspi2006 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherKaspi2006:gammapy.astro.population.FaucherKaspi2006.amplitude}\pysigline{\bfcode{amplitude}}
\end{fulllineitems}
\index{evolved (gammapy.astro.population.FaucherKaspi2006 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherKaspi2006:gammapy.astro.population.FaucherKaspi2006.evolved}\pysigline{\bfcode{evolved}\strong{ = False}}
\end{fulllineitems}
\index{param\_names (gammapy.astro.population.FaucherKaspi2006 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherKaspi2006:gammapy.astro.population.FaucherKaspi2006.param_names}\pysigline{\bfcode{param\_names}\strong{ = (`amplitude', `r\_0', `sigma')}}
\end{fulllineitems}
\index{r\_0 (gammapy.astro.population.FaucherKaspi2006 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherKaspi2006:gammapy.astro.population.FaucherKaspi2006.r_0}\pysigline{\bfcode{r\_0}}
\end{fulllineitems}
\index{sigma (gammapy.astro.population.FaucherKaspi2006 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherKaspi2006:gammapy.astro.population.FaucherKaspi2006.sigma}\pysigline{\bfcode{sigma}}
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{evaluate() (gammapy.astro.population.FaucherKaspi2006 static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherKaspi2006:gammapy.astro.population.FaucherKaspi2006.evaluate}\pysiglinewithargsret{\strong{static }\bfcode{evaluate}}{\emph{r}, \emph{amplitude}, \emph{r\_0}, \emph{sigma}}{}
One dimensional Faucher-Giguere \& Kaspi 2006 model function
\end{fulllineitems}
\end{fulllineitems}
\subparagraph{FaucherKaspi2006VelocityBimodal}
\label{api/gammapy.astro.population.FaucherKaspi2006VelocityBimodal:astropy}\label{api/gammapy.astro.population.FaucherKaspi2006VelocityBimodal::doc}\label{api/gammapy.astro.population.FaucherKaspi2006VelocityBimodal:faucherkaspi2006velocitybimodal}\index{FaucherKaspi2006VelocityBimodal (class in gammapy.astro.population)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherKaspi2006VelocityBimodal:gammapy.astro.population.FaucherKaspi2006VelocityBimodal}\pysiglinewithargsret{\strong{class }\code{gammapy.astro.population.}\bfcode{FaucherKaspi2006VelocityBimodal}}{\emph{amplitude=1}, \emph{sigma\_1=160}, \emph{sigma\_2=780}, \emph{w=0.9}, \emph{**kwargs}}{}
Bases: \href{http://docs.astropy.org/en/latest/api/astropy.modeling.Fittable1DModel.html\#astropy.modeling.Fittable1DModel}{\code{astropy.modeling.Fittable1DModel}}
Bimodal pulsar velocity distribution - Faucher \& Kaspi (2006).
\begin{gather}
\begin{split}f(v) = A\sqrt{\frac{2}{\pi}} v^2 \left[\frac{w}{\sigma_1^3}
\exp \left(-\frac{v^2}{2\sigma_1^2} \right) + \frac{1-w}{\sigma_2^3}
\exp \left(-\frac{v^2}{2\sigma_2^2} \right) \right]\end{split}\notag
\end{gather}
Reference: \href{http://adsabs.harvard.edu/abs/2006ApJ...643..332F}{http://adsabs.harvard.edu/abs/2006ApJ...643..332F} (Formula (7))
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{amplitude} : float
\begin{quote}
Value of the integral
\end{quote}
\textbf{sigma1} : float
\begin{quote}
See model formula
\end{quote}
\textbf{sigma2} : float
\begin{quote}
See model formula
\end{quote}
\textbf{w} : float
\begin{quote}
See model formula
\end{quote}
\end{description}\end{quote}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.astro.population.FaucherKaspi2006VelocityBimodal:gammapy.astro.population.FaucherKaspi2006VelocityBimodal.param_names]{\emph{\code{param\_names}}}}
&
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{amplitude (gammapy.astro.population.FaucherKaspi2006VelocityBimodal attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherKaspi2006VelocityBimodal:gammapy.astro.population.FaucherKaspi2006VelocityBimodal.amplitude}\pysigline{\bfcode{amplitude}}
\end{fulllineitems}
\index{param\_names (gammapy.astro.population.FaucherKaspi2006VelocityBimodal attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherKaspi2006VelocityBimodal:gammapy.astro.population.FaucherKaspi2006VelocityBimodal.param_names}\pysigline{\bfcode{param\_names}\strong{ = (`amplitude', `sigma\_1', `sigma\_2', `w')}}
\end{fulllineitems}
\index{sigma\_1 (gammapy.astro.population.FaucherKaspi2006VelocityBimodal attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherKaspi2006VelocityBimodal:gammapy.astro.population.FaucherKaspi2006VelocityBimodal.sigma_1}\pysigline{\bfcode{sigma\_1}}
\end{fulllineitems}
\index{sigma\_2 (gammapy.astro.population.FaucherKaspi2006VelocityBimodal attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherKaspi2006VelocityBimodal:gammapy.astro.population.FaucherKaspi2006VelocityBimodal.sigma_2}\pysigline{\bfcode{sigma\_2}}
\end{fulllineitems}
\index{w (gammapy.astro.population.FaucherKaspi2006VelocityBimodal attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherKaspi2006VelocityBimodal:gammapy.astro.population.FaucherKaspi2006VelocityBimodal.w}\pysigline{\bfcode{w}}
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{evaluate() (gammapy.astro.population.FaucherKaspi2006VelocityBimodal static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherKaspi2006VelocityBimodal:gammapy.astro.population.FaucherKaspi2006VelocityBimodal.evaluate}\pysiglinewithargsret{\strong{static }\bfcode{evaluate}}{\emph{v}, \emph{amplitude}, \emph{sigma\_1}, \emph{sigma\_2}, \emph{w}}{}
One dimensional Faucher-Guigere \& Kaspi 2006 velocity model function
\end{fulllineitems}
\end{fulllineitems}
\subparagraph{FaucherKaspi2006VelocityMaxwellian}
\label{api/gammapy.astro.population.FaucherKaspi2006VelocityMaxwellian:astropy}\label{api/gammapy.astro.population.FaucherKaspi2006VelocityMaxwellian::doc}\label{api/gammapy.astro.population.FaucherKaspi2006VelocityMaxwellian:faucherkaspi2006velocitymaxwellian}\index{FaucherKaspi2006VelocityMaxwellian (class in gammapy.astro.population)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherKaspi2006VelocityMaxwellian:gammapy.astro.population.FaucherKaspi2006VelocityMaxwellian}\pysiglinewithargsret{\strong{class }\code{gammapy.astro.population.}\bfcode{FaucherKaspi2006VelocityMaxwellian}}{\emph{amplitude=1}, \emph{sigma=265}, \emph{**kwargs}}{}
Bases: \href{http://docs.astropy.org/en/latest/api/astropy.modeling.Fittable1DModel.html\#astropy.modeling.Fittable1DModel}{\code{astropy.modeling.Fittable1DModel}}
Maxwellian pulsar velocity distribution.
\begin{gather}
\begin{split}f(v) = A \sqrt{ \frac{2}{\pi}} \frac{v ^ 2}{\sigma ^ 3 }
\exp \left(-\frac{v ^ 2}{2 \sigma ^ 2} \right)\end{split}\notag
\end{gather}
Reference: \href{http://adsabs.harvard.edu/abs/2006ApJ...643..332F}{http://adsabs.harvard.edu/abs/2006ApJ...643..332F}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{amplitude} : float
\begin{quote}
Value of the integral
\end{quote}
\textbf{sigma} : float
\begin{quote}
Velocity parameter (km s\textasciicircum{}-1)
\end{quote}
\end{description}\end{quote}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.astro.population.FaucherKaspi2006VelocityMaxwellian:gammapy.astro.population.FaucherKaspi2006VelocityMaxwellian.param_names]{\emph{\code{param\_names}}}}
&
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{amplitude (gammapy.astro.population.FaucherKaspi2006VelocityMaxwellian attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherKaspi2006VelocityMaxwellian:gammapy.astro.population.FaucherKaspi2006VelocityMaxwellian.amplitude}\pysigline{\bfcode{amplitude}}
\end{fulllineitems}
\index{param\_names (gammapy.astro.population.FaucherKaspi2006VelocityMaxwellian attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherKaspi2006VelocityMaxwellian:gammapy.astro.population.FaucherKaspi2006VelocityMaxwellian.param_names}\pysigline{\bfcode{param\_names}\strong{ = (`amplitude', `sigma')}}
\end{fulllineitems}
\index{sigma (gammapy.astro.population.FaucherKaspi2006VelocityMaxwellian attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherKaspi2006VelocityMaxwellian:gammapy.astro.population.FaucherKaspi2006VelocityMaxwellian.sigma}\pysigline{\bfcode{sigma}}
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{evaluate() (gammapy.astro.population.FaucherKaspi2006VelocityMaxwellian static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherKaspi2006VelocityMaxwellian:gammapy.astro.population.FaucherKaspi2006VelocityMaxwellian.evaluate}\pysiglinewithargsret{\strong{static }\bfcode{evaluate}}{\emph{v}, \emph{amplitude}, \emph{sigma}}{}
One dimensional Faucher-Guigere \& Kaspi 2006 velocity model function
\end{fulllineitems}
\end{fulllineitems}
\subparagraph{FaucherSpiral}
\label{api/gammapy.astro.population.FaucherSpiral:astropy}\label{api/gammapy.astro.population.FaucherSpiral::doc}\label{api/gammapy.astro.population.FaucherSpiral:faucherspiral}\index{FaucherSpiral (class in gammapy.astro.population)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherSpiral:gammapy.astro.population.FaucherSpiral}\pysigline{\strong{class }\code{gammapy.astro.population.}\bfcode{FaucherSpiral}}
Bases: {\hyperref[api/gammapy.astro.population.LogSpiral:gammapy.astro.population.LogSpiral]{\emph{\code{gammapy.astro.population.LogSpiral}}}}
Milky way spiral arm used in Faucher et al. (2006).
Reference: \href{http://adsabs.harvard.edu/abs/2006ApJ...643..332F}{http://adsabs.harvard.edu/abs/2006ApJ...643..332F}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.astro.population.FaucherSpiral:gammapy.astro.population.FaucherSpiral.spiralarms]{\emph{\code{spiralarms}}}}
&
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{k (gammapy.astro.population.FaucherSpiral attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherSpiral:gammapy.astro.population.FaucherSpiral.k}\pysigline{\bfcode{k}\strong{ = \textless{}Quantity {[} 4.25, 4.25, 4.89, 4.89{]} rad\textgreater{}}}
\end{fulllineitems}
\index{r\_0 (gammapy.astro.population.FaucherSpiral attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherSpiral:gammapy.astro.population.FaucherSpiral.r_0}\pysigline{\bfcode{r\_0}\strong{ = \textless{}Quantity {[} 3.48, 3.48, 4.9 , 4.9 {]} kpc\textgreater{}}}
\end{fulllineitems}
\index{spiralarms (gammapy.astro.population.FaucherSpiral attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherSpiral:gammapy.astro.population.FaucherSpiral.spiralarms}\pysigline{\bfcode{spiralarms}\strong{ = array({[}'Norma', `Carina Sagittarius', `Perseus', `Crux Scutum'{]}, dtype='\textless{}U18')}}
\end{fulllineitems}
\index{theta\_0 (gammapy.astro.population.FaucherSpiral attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherSpiral:gammapy.astro.population.FaucherSpiral.theta_0}\pysigline{\bfcode{theta\_0}\strong{ = \textless{}Quantity {[} 1.57, 4.71, 4.09, 0.95{]} rad\textgreater{}}}
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{\_\_call\_\_() (gammapy.astro.population.FaucherSpiral method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.FaucherSpiral:gammapy.astro.population.FaucherSpiral.__call__}\pysiglinewithargsret{\bfcode{\_\_call\_\_}}{\emph{radius}, \emph{blur=True}, \emph{random\_state='random-seed'}}{}
Draw random position from spiral arm distribution.
Returns the corresponding angle theta{[}rad{]} to a given radius{[}kpc{]} and number of spiralarm.
Possible numbers are:
\begin{itemize}
\item {}
Norma = 0,
\item {}
Carina Sagittarius = 1,
\item {}
Perseus = 2
\item {}
Crux Scutum = 3.
\end{itemize}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{random\_state} : \{int, `random-seed', `global-rng', \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.RandomState.html\#numpy.random.RandomState}{\code{RandomState}}\}
\begin{quote}
Defines random number generator initialisation.
Passed to {\hyperref[api/gammapy.utils.random.get_random_state:gammapy.utils.random.get_random_state]{\emph{\code{get\_random\_state}}}}.
\end{quote}
\item[{Returns}] \leavevmode
Returns dx and dy, if blurring= true.
\end{description}\end{quote}
\end{fulllineitems}
\end{fulllineitems}
\subparagraph{LogSpiral}
\label{api/gammapy.astro.population.LogSpiral:astropy}\label{api/gammapy.astro.population.LogSpiral::doc}\label{api/gammapy.astro.population.LogSpiral:logspiral}\index{LogSpiral (class in gammapy.astro.population)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.LogSpiral:gammapy.astro.population.LogSpiral}\pysigline{\strong{class }\code{gammapy.astro.population.}\bfcode{LogSpiral}}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Logarithmic spiral.
Reference: \href{http://en.wikipedia.org/wiki/Logarithmic\_spiral}{http://en.wikipedia.org/wiki/Logarithmic\_spiral}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{radius() (gammapy.astro.population.LogSpiral method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.LogSpiral:gammapy.astro.population.LogSpiral.radius}\pysiglinewithargsret{\bfcode{radius}}{\emph{theta}, \emph{spiralarm\_index}}{}
Radius for a given angle.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{theta} : array\_like
\begin{quote}
Angle (deg)
\end{quote}
\textbf{spiralarm\_index} : int
\begin{quote}
Spiral arm index
\end{quote}
\item[{Returns}] \leavevmode
\textbf{radius} : array\_like
\begin{quote}
Radius (kpc)
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{theta() (gammapy.astro.population.LogSpiral method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.LogSpiral:gammapy.astro.population.LogSpiral.theta}\pysiglinewithargsret{\bfcode{theta}}{\emph{radius}, \emph{spiralarm\_index}}{}
Angle for a given radius.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{radius} : array\_like
\begin{quote}
Radius (kpc)
\end{quote}
\textbf{spiralarm\_index} : int
\begin{quote}
Spiral arm index
\end{quote}
\item[{Returns}] \leavevmode
\textbf{theta} : array\_like
\begin{quote}
Angle (deg)
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{xy\_position() (gammapy.astro.population.LogSpiral method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.LogSpiral:gammapy.astro.population.LogSpiral.xy_position}\pysiglinewithargsret{\bfcode{xy\_position}}{\emph{theta=None}, \emph{radius=None}, \emph{spiralarm\_index=0}}{}
Compute (x, y) position for a given angle or radius.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{theta} : array\_like
\begin{quote}
Angle (deg)
\end{quote}
\textbf{radius} : array\_like
\begin{quote}
Radius (kpc)
\end{quote}
\textbf{spiralarm\_index} : int
\begin{quote}
Spiral arm index
\end{quote}
\item[{Returns}] \leavevmode
\textbf{x, y} : array\_like
\begin{quote}
Position (x, y)
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\end{fulllineitems}
\subparagraph{Lorimer2006}
\label{api/gammapy.astro.population.Lorimer2006:astropy}\label{api/gammapy.astro.population.Lorimer2006::doc}\label{api/gammapy.astro.population.Lorimer2006:lorimer2006}\index{Lorimer2006 (class in gammapy.astro.population)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Lorimer2006:gammapy.astro.population.Lorimer2006}\pysiglinewithargsret{\strong{class }\code{gammapy.astro.population.}\bfcode{Lorimer2006}}{\emph{amplitude=1}, \emph{B=1.9}, \emph{C=5.0}, \emph{**kwargs}}{}
Bases: \href{http://docs.astropy.org/en/latest/api/astropy.modeling.Fittable1DModel.html\#astropy.modeling.Fittable1DModel}{\code{astropy.modeling.Fittable1DModel}}
Radial distribution of the suface density of pulsars in the galaxy - Lorimer 2006.
\begin{gather}
\begin{split}f(r) = A \left( \frac{r}{r_{\odot}} \right) ^ B \exp
\left[ -C \left( \frac{r - r_{\odot}}{r_{\odot}} \right) \right]\end{split}\notag
\end{gather}
Reference: \href{http://adsabs.harvard.edu/abs/2006MNRAS.372..777L}{http://adsabs.harvard.edu/abs/2006MNRAS.372..777L} (Formula (10))
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{amplitude} : float
\begin{quote}
See model formula
\end{quote}
\textbf{B} : float
\begin{quote}
See model formula
\end{quote}
\textbf{C} : float
\begin{quote}
See model formula
\end{quote}
\end{description}\end{quote}
\strong{See also:}
{\hyperref[api/gammapy.astro.population.CaseBattacharya1998:gammapy.astro.population.CaseBattacharya1998]{\emph{\code{CaseBattacharya1998}}}}, {\hyperref[api/gammapy.astro.population.Paczynski1990:gammapy.astro.population.Paczynski1990]{\emph{\code{Paczynski1990}}}}, {\hyperref[api/gammapy.astro.population.YusifovKucuk2004:gammapy.astro.population.YusifovKucuk2004]{\emph{\code{YusifovKucuk2004}}}}, {\hyperref[api/gammapy.astro.population.Lorimer2006:gammapy.astro.population.Lorimer2006]{\emph{\code{Lorimer2006}}}}, {\hyperref[api/gammapy.astro.population.YusifovKucuk2004B:gammapy.astro.population.YusifovKucuk2004B]{\emph{\code{YusifovKucuk2004B}}}}, {\hyperref[api/gammapy.astro.population.FaucherKaspi2006:gammapy.astro.population.FaucherKaspi2006]{\emph{\code{FaucherKaspi2006}}}}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.astro.population.Lorimer2006:gammapy.astro.population.Lorimer2006.evolved]{\emph{\code{evolved}}}}
&
\\
\hline
{\hyperref[api/gammapy.astro.population.Lorimer2006:gammapy.astro.population.Lorimer2006.param_names]{\emph{\code{param\_names}}}}
&
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{B (gammapy.astro.population.Lorimer2006 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Lorimer2006:gammapy.astro.population.Lorimer2006.B}\pysigline{\bfcode{B}}
\end{fulllineitems}
\index{C (gammapy.astro.population.Lorimer2006 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Lorimer2006:gammapy.astro.population.Lorimer2006.C}\pysigline{\bfcode{C}}
\end{fulllineitems}
\index{amplitude (gammapy.astro.population.Lorimer2006 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Lorimer2006:gammapy.astro.population.Lorimer2006.amplitude}\pysigline{\bfcode{amplitude}}
\end{fulllineitems}
\index{evolved (gammapy.astro.population.Lorimer2006 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Lorimer2006:gammapy.astro.population.Lorimer2006.evolved}\pysigline{\bfcode{evolved}\strong{ = True}}
\end{fulllineitems}
\index{param\_names (gammapy.astro.population.Lorimer2006 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Lorimer2006:gammapy.astro.population.Lorimer2006.param_names}\pysigline{\bfcode{param\_names}\strong{ = (`amplitude', `B', `C')}}
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{evaluate() (gammapy.astro.population.Lorimer2006 static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Lorimer2006:gammapy.astro.population.Lorimer2006.evaluate}\pysiglinewithargsret{\strong{static }\bfcode{evaluate}}{\emph{r}, \emph{amplitude}, \emph{B}, \emph{C}}{}
One dimensional Lorimer 2006 model function
\end{fulllineitems}
\end{fulllineitems}
\subparagraph{Paczynski1990}
\label{api/gammapy.astro.population.Paczynski1990:astropy}\label{api/gammapy.astro.population.Paczynski1990::doc}\label{api/gammapy.astro.population.Paczynski1990:paczynski1990}\index{Paczynski1990 (class in gammapy.astro.population)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Paczynski1990:gammapy.astro.population.Paczynski1990}\pysiglinewithargsret{\strong{class }\code{gammapy.astro.population.}\bfcode{Paczynski1990}}{\emph{amplitude=1}, \emph{r\_exp=4.5}, \emph{**kwargs}}{}
Bases: \href{http://docs.astropy.org/en/latest/api/astropy.modeling.Fittable1DModel.html\#astropy.modeling.Fittable1DModel}{\code{astropy.modeling.Fittable1DModel}}
Radial distribution of the birth surface density of neutron stars - Paczynski 1990.
\begin{gather}
\begin{split}f(r) = A r_{exp}^{-2} \exp \left(-\frac{r}{r_{exp}} \right)\end{split}\notag
\end{gather}
Reference: \href{http://adsabs.harvard.edu/abs/1990ApJ...348..485P}{http://adsabs.harvard.edu/abs/1990ApJ...348..485P} (Formula (2))
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{amplitude} : float
\begin{quote}
See formula
\end{quote}
\textbf{r\_exp} : float
\begin{quote}
See formula
\end{quote}
\end{description}\end{quote}
\strong{See also:}
{\hyperref[api/gammapy.astro.population.CaseBattacharya1998:gammapy.astro.population.CaseBattacharya1998]{\emph{\code{CaseBattacharya1998}}}}, {\hyperref[api/gammapy.astro.population.YusifovKucuk2004:gammapy.astro.population.YusifovKucuk2004]{\emph{\code{YusifovKucuk2004}}}}, {\hyperref[api/gammapy.astro.population.Lorimer2006:gammapy.astro.population.Lorimer2006]{\emph{\code{Lorimer2006}}}}, {\hyperref[api/gammapy.astro.population.YusifovKucuk2004B:gammapy.astro.population.YusifovKucuk2004B]{\emph{\code{YusifovKucuk2004B}}}}, {\hyperref[api/gammapy.astro.population.FaucherKaspi2006:gammapy.astro.population.FaucherKaspi2006]{\emph{\code{FaucherKaspi2006}}}}, {\hyperref[api/gammapy.astro.population.Exponential:gammapy.astro.population.Exponential]{\emph{\code{Exponential}}}}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.astro.population.Paczynski1990:gammapy.astro.population.Paczynski1990.evolved]{\emph{\code{evolved}}}}
&
\\
\hline
{\hyperref[api/gammapy.astro.population.Paczynski1990:gammapy.astro.population.Paczynski1990.param_names]{\emph{\code{param\_names}}}}
&
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{amplitude (gammapy.astro.population.Paczynski1990 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Paczynski1990:gammapy.astro.population.Paczynski1990.amplitude}\pysigline{\bfcode{amplitude}}
\end{fulllineitems}
\index{evolved (gammapy.astro.population.Paczynski1990 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Paczynski1990:gammapy.astro.population.Paczynski1990.evolved}\pysigline{\bfcode{evolved}\strong{ = False}}
\end{fulllineitems}
\index{param\_names (gammapy.astro.population.Paczynski1990 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Paczynski1990:gammapy.astro.population.Paczynski1990.param_names}\pysigline{\bfcode{param\_names}\strong{ = (`amplitude', `r\_exp')}}
\end{fulllineitems}
\index{r\_exp (gammapy.astro.population.Paczynski1990 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Paczynski1990:gammapy.astro.population.Paczynski1990.r_exp}\pysigline{\bfcode{r\_exp}}
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{evaluate() (gammapy.astro.population.Paczynski1990 static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Paczynski1990:gammapy.astro.population.Paczynski1990.evaluate}\pysiglinewithargsret{\strong{static }\bfcode{evaluate}}{\emph{r}, \emph{amplitude}, \emph{r\_exp}}{}
One dimensional Paczynski 1990 model function
\end{fulllineitems}
\end{fulllineitems}
\subparagraph{Paczynski1990Velocity}
\label{api/gammapy.astro.population.Paczynski1990Velocity:astropy}\label{api/gammapy.astro.population.Paczynski1990Velocity::doc}\label{api/gammapy.astro.population.Paczynski1990Velocity:paczynski1990velocity}\index{Paczynski1990Velocity (class in gammapy.astro.population)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Paczynski1990Velocity:gammapy.astro.population.Paczynski1990Velocity}\pysiglinewithargsret{\strong{class }\code{gammapy.astro.population.}\bfcode{Paczynski1990Velocity}}{\emph{amplitude=1}, \emph{v\_0=560}, \emph{**kwargs}}{}
Bases: \href{http://docs.astropy.org/en/latest/api/astropy.modeling.Fittable1DModel.html\#astropy.modeling.Fittable1DModel}{\code{astropy.modeling.Fittable1DModel}}
Distribution by Lyne 1982 and adopted by Paczynski and Faucher.
\begin{gather}
\begin{split}f(v) = A\frac{4}{\pi} \frac{1}{v_{0} \left[1 + (v / v_{0}) ^ 2 \right] ^ 2}\end{split}\notag
\end{gather}
Reference: \href{http://adsabs.harvard.edu/abs/1990ApJ...348..485P}{http://adsabs.harvard.edu/abs/1990ApJ...348..485P} (Formula (3))
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{amplitude} : float
\begin{quote}
Value of the integral
\end{quote}
\textbf{v\_0} : float
\begin{quote}
Velocity parameter (km s\textasciicircum{}-1)
\end{quote}
\end{description}\end{quote}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.astro.population.Paczynski1990Velocity:gammapy.astro.population.Paczynski1990Velocity.param_names]{\emph{\code{param\_names}}}}
&
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{amplitude (gammapy.astro.population.Paczynski1990Velocity attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Paczynski1990Velocity:gammapy.astro.population.Paczynski1990Velocity.amplitude}\pysigline{\bfcode{amplitude}}
\end{fulllineitems}
\index{param\_names (gammapy.astro.population.Paczynski1990Velocity attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Paczynski1990Velocity:gammapy.astro.population.Paczynski1990Velocity.param_names}\pysigline{\bfcode{param\_names}\strong{ = (`amplitude', `v\_0')}}
\end{fulllineitems}
\index{v\_0 (gammapy.astro.population.Paczynski1990Velocity attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Paczynski1990Velocity:gammapy.astro.population.Paczynski1990Velocity.v_0}\pysigline{\bfcode{v\_0}}
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{evaluate() (gammapy.astro.population.Paczynski1990Velocity static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.Paczynski1990Velocity:gammapy.astro.population.Paczynski1990Velocity.evaluate}\pysiglinewithargsret{\strong{static }\bfcode{evaluate}}{\emph{v}, \emph{amplitude}, \emph{v\_0}}{}
One dimensional Paczynski 1990 velocity model function
\end{fulllineitems}
\end{fulllineitems}
\subparagraph{ValleeSpiral}
\label{api/gammapy.astro.population.ValleeSpiral:astropy}\label{api/gammapy.astro.population.ValleeSpiral::doc}\label{api/gammapy.astro.population.ValleeSpiral:valleespiral}\index{ValleeSpiral (class in gammapy.astro.population)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.ValleeSpiral:gammapy.astro.population.ValleeSpiral}\pysigline{\strong{class }\code{gammapy.astro.population.}\bfcode{ValleeSpiral}}
Bases: {\hyperref[api/gammapy.astro.population.LogSpiral:gammapy.astro.population.LogSpiral]{\emph{\code{gammapy.astro.population.LogSpiral}}}}
Milky way spiral arm model from Vallee (2008).
Reference: \href{http://adsabs.harvard.edu/abs/2008AJ....135.1301V}{http://adsabs.harvard.edu/abs/2008AJ....135.1301V}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.astro.population.ValleeSpiral:gammapy.astro.population.ValleeSpiral.bar_radius]{\emph{\code{bar\_radius}}}}
&
\\
\hline
{\hyperref[api/gammapy.astro.population.ValleeSpiral:gammapy.astro.population.ValleeSpiral.m]{\emph{\code{m}}}}
&
\\
\hline
{\hyperref[api/gammapy.astro.population.ValleeSpiral:gammapy.astro.population.ValleeSpiral.p]{\emph{\code{p}}}}
&
\\
\hline
{\hyperref[api/gammapy.astro.population.ValleeSpiral:gammapy.astro.population.ValleeSpiral.r_0]{\emph{\code{r\_0}}}}
&
\\
\hline
{\hyperref[api/gammapy.astro.population.ValleeSpiral:gammapy.astro.population.ValleeSpiral.r_sun]{\emph{\code{r\_sun}}}}
&
\\
\hline
{\hyperref[api/gammapy.astro.population.ValleeSpiral:gammapy.astro.population.ValleeSpiral.spiralarms]{\emph{\code{spiralarms}}}}
&
\\
\hline
{\hyperref[api/gammapy.astro.population.ValleeSpiral:gammapy.astro.population.ValleeSpiral.theta_0]{\emph{\code{theta\_0}}}}
&
\\
\hline\end{longtable}
\paragraph{Attributes Documentation}
\index{bar\_radius (gammapy.astro.population.ValleeSpiral attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.ValleeSpiral:gammapy.astro.population.ValleeSpiral.bar_radius}\pysigline{\bfcode{bar\_radius}\strong{ = 3.0}}
\end{fulllineitems}
\index{m (gammapy.astro.population.ValleeSpiral attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.ValleeSpiral:gammapy.astro.population.ValleeSpiral.m}\pysigline{\bfcode{m}\strong{ = 4}}
\end{fulllineitems}
\index{p (gammapy.astro.population.ValleeSpiral attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.ValleeSpiral:gammapy.astro.population.ValleeSpiral.p}\pysigline{\bfcode{p}\strong{ = 12.8}}
\end{fulllineitems}
\index{r\_0 (gammapy.astro.population.ValleeSpiral attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.ValleeSpiral:gammapy.astro.population.ValleeSpiral.r_0}\pysigline{\bfcode{r\_0}\strong{ = 2.1}}
\end{fulllineitems}
\index{r\_sun (gammapy.astro.population.ValleeSpiral attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.ValleeSpiral:gammapy.astro.population.ValleeSpiral.r_sun}\pysigline{\bfcode{r\_sun}\strong{ = 7.6}}
\end{fulllineitems}
\index{spiralarms (gammapy.astro.population.ValleeSpiral attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.ValleeSpiral:gammapy.astro.population.ValleeSpiral.spiralarms}\pysigline{\bfcode{spiralarms}\strong{ = array({[}'Norma', `Perseus', `Carina Sagittarius', `Crux Scutum'{]}, dtype='\textless{}U18')}}
\end{fulllineitems}
\index{theta\_0 (gammapy.astro.population.ValleeSpiral attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.ValleeSpiral:gammapy.astro.population.ValleeSpiral.theta_0}\pysigline{\bfcode{theta\_0}\strong{ = -20}}
\end{fulllineitems}
\end{fulllineitems}
\subparagraph{YusifovKucuk2004}
\label{api/gammapy.astro.population.YusifovKucuk2004:yusifovkucuk2004}\label{api/gammapy.astro.population.YusifovKucuk2004:astropy}\label{api/gammapy.astro.population.YusifovKucuk2004::doc}\index{YusifovKucuk2004 (class in gammapy.astro.population)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.YusifovKucuk2004:gammapy.astro.population.YusifovKucuk2004}\pysiglinewithargsret{\strong{class }\code{gammapy.astro.population.}\bfcode{YusifovKucuk2004}}{\emph{amplitude=1}, \emph{a=1.64}, \emph{b=4.01}, \emph{r\_1=0.55}, \emph{**kwargs}}{}
Bases: \href{http://docs.astropy.org/en/latest/api/astropy.modeling.Fittable1DModel.html\#astropy.modeling.Fittable1DModel}{\code{astropy.modeling.Fittable1DModel}}
Radial distribution of the surface density of pulsars in the galaxy - Yusifov \& Kucuk 2004.
\begin{gather}
\begin{split}f(r) = A \left ( \frac{r + r_1}{r_{\odot} + r_1} \right )^a \exp
\left [-b \left( \frac{r - r_{\odot}}{r_{\odot} + r_1} \right ) \right ]\end{split}\notag
\end{gather}
Used by Faucher-Guigere and Kaspi. Density at \code{r = 0} is nonzero.
Reference: \href{http://adsabs.harvard.edu/abs/2004A\%26A...422..545Y}{http://adsabs.harvard.edu/abs/2004A\%26A...422..545Y} (Formula (15))
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{amplitude} : float
\begin{quote}
See model formula
\end{quote}
\textbf{a} : float
\begin{quote}
See model formula
\end{quote}
\textbf{b} : float
\begin{quote}
See model formula
\end{quote}
\textbf{r\_1} : float
\begin{quote}
See model formula
\end{quote}
\end{description}\end{quote}
\strong{See also:}
{\hyperref[api/gammapy.astro.population.CaseBattacharya1998:gammapy.astro.population.CaseBattacharya1998]{\emph{\code{CaseBattacharya1998}}}}, {\hyperref[api/gammapy.astro.population.Paczynski1990:gammapy.astro.population.Paczynski1990]{\emph{\code{Paczynski1990}}}}, {\hyperref[api/gammapy.astro.population.Lorimer2006:gammapy.astro.population.Lorimer2006]{\emph{\code{Lorimer2006}}}}, {\hyperref[api/gammapy.astro.population.YusifovKucuk2004B:gammapy.astro.population.YusifovKucuk2004B]{\emph{\code{YusifovKucuk2004B}}}}, {\hyperref[api/gammapy.astro.population.FaucherKaspi2006:gammapy.astro.population.FaucherKaspi2006]{\emph{\code{FaucherKaspi2006}}}}, {\hyperref[api/gammapy.astro.population.Exponential:gammapy.astro.population.Exponential]{\emph{\code{Exponential}}}}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.astro.population.YusifovKucuk2004:gammapy.astro.population.YusifovKucuk2004.evolved]{\emph{\code{evolved}}}}
&
\\
\hline
{\hyperref[api/gammapy.astro.population.YusifovKucuk2004:gammapy.astro.population.YusifovKucuk2004.param_names]{\emph{\code{param\_names}}}}
&
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{a (gammapy.astro.population.YusifovKucuk2004 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.YusifovKucuk2004:gammapy.astro.population.YusifovKucuk2004.a}\pysigline{\bfcode{a}}
\end{fulllineitems}
\index{amplitude (gammapy.astro.population.YusifovKucuk2004 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.YusifovKucuk2004:gammapy.astro.population.YusifovKucuk2004.amplitude}\pysigline{\bfcode{amplitude}}
\end{fulllineitems}
\index{b (gammapy.astro.population.YusifovKucuk2004 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.YusifovKucuk2004:gammapy.astro.population.YusifovKucuk2004.b}\pysigline{\bfcode{b}}
\end{fulllineitems}
\index{evolved (gammapy.astro.population.YusifovKucuk2004 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.YusifovKucuk2004:gammapy.astro.population.YusifovKucuk2004.evolved}\pysigline{\bfcode{evolved}\strong{ = True}}
\end{fulllineitems}
\index{param\_names (gammapy.astro.population.YusifovKucuk2004 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.YusifovKucuk2004:gammapy.astro.population.YusifovKucuk2004.param_names}\pysigline{\bfcode{param\_names}\strong{ = (`amplitude', `a', `b', `r\_1')}}
\end{fulllineitems}
\index{r\_1 (gammapy.astro.population.YusifovKucuk2004 attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.YusifovKucuk2004:gammapy.astro.population.YusifovKucuk2004.r_1}\pysigline{\bfcode{r\_1}}
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{evaluate() (gammapy.astro.population.YusifovKucuk2004 static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.YusifovKucuk2004:gammapy.astro.population.YusifovKucuk2004.evaluate}\pysiglinewithargsret{\strong{static }\bfcode{evaluate}}{\emph{r}, \emph{amplitude}, \emph{a}, \emph{b}, \emph{r\_1}}{}
One dimensional Yusifov \& Kucuk 2004 model function
\end{fulllineitems}
\end{fulllineitems}
\subparagraph{YusifovKucuk2004B}
\label{api/gammapy.astro.population.YusifovKucuk2004B:astropy}\label{api/gammapy.astro.population.YusifovKucuk2004B::doc}\label{api/gammapy.astro.population.YusifovKucuk2004B:yusifovkucuk2004b}\index{YusifovKucuk2004B (class in gammapy.astro.population)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.YusifovKucuk2004B:gammapy.astro.population.YusifovKucuk2004B}\pysiglinewithargsret{\strong{class }\code{gammapy.astro.population.}\bfcode{YusifovKucuk2004B}}{\emph{amplitude=1}, \emph{a=4}, \emph{b=6.8}, \emph{**kwargs}}{}
Bases: \href{http://docs.astropy.org/en/latest/api/astropy.modeling.Fittable1DModel.html\#astropy.modeling.Fittable1DModel}{\code{astropy.modeling.Fittable1DModel}}
Radial distribution of the surface density of OB stars in the galaxy - Yusifov \& Kucuk 2004.
\begin{gather}
\begin{split}f(r) = A \left( \frac{r}{r_{\odot}} \right) ^ a
\exp \left[ -b \left( \frac{r}{r_{\odot}} \right) \right]\end{split}\notag
\end{gather}
Derived empirically from OB-stars distribution.
Reference: \href{http://adsabs.harvard.edu/abs/2004A\%26A...422..545Y}{http://adsabs.harvard.edu/abs/2004A\%26A...422..545Y} (Formula (17))
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{amplitude} : float
\begin{quote}
See model formula
\end{quote}
\textbf{a} : float
\begin{quote}
See model formula
\end{quote}
\textbf{b} : float
\begin{quote}
See model formula
\end{quote}
\end{description}\end{quote}
\strong{See also:}
{\hyperref[api/gammapy.astro.population.CaseBattacharya1998:gammapy.astro.population.CaseBattacharya1998]{\emph{\code{CaseBattacharya1998}}}}, {\hyperref[api/gammapy.astro.population.Paczynski1990:gammapy.astro.population.Paczynski1990]{\emph{\code{Paczynski1990}}}}, {\hyperref[api/gammapy.astro.population.YusifovKucuk2004:gammapy.astro.population.YusifovKucuk2004]{\emph{\code{YusifovKucuk2004}}}}, {\hyperref[api/gammapy.astro.population.Lorimer2006:gammapy.astro.population.Lorimer2006]{\emph{\code{Lorimer2006}}}}, {\hyperref[api/gammapy.astro.population.FaucherKaspi2006:gammapy.astro.population.FaucherKaspi2006]{\emph{\code{FaucherKaspi2006}}}}, {\hyperref[api/gammapy.astro.population.Exponential:gammapy.astro.population.Exponential]{\emph{\code{Exponential}}}}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.astro.population.YusifovKucuk2004B:gammapy.astro.population.YusifovKucuk2004B.evolved]{\emph{\code{evolved}}}}
&
\\
\hline
{\hyperref[api/gammapy.astro.population.YusifovKucuk2004B:gammapy.astro.population.YusifovKucuk2004B.param_names]{\emph{\code{param\_names}}}}
&
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{a (gammapy.astro.population.YusifovKucuk2004B attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.YusifovKucuk2004B:gammapy.astro.population.YusifovKucuk2004B.a}\pysigline{\bfcode{a}}
\end{fulllineitems}
\index{amplitude (gammapy.astro.population.YusifovKucuk2004B attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.YusifovKucuk2004B:gammapy.astro.population.YusifovKucuk2004B.amplitude}\pysigline{\bfcode{amplitude}}
\end{fulllineitems}
\index{b (gammapy.astro.population.YusifovKucuk2004B attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.YusifovKucuk2004B:gammapy.astro.population.YusifovKucuk2004B.b}\pysigline{\bfcode{b}}
\end{fulllineitems}
\index{evolved (gammapy.astro.population.YusifovKucuk2004B attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.YusifovKucuk2004B:gammapy.astro.population.YusifovKucuk2004B.evolved}\pysigline{\bfcode{evolved}\strong{ = False}}
\end{fulllineitems}
\index{param\_names (gammapy.astro.population.YusifovKucuk2004B attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.YusifovKucuk2004B:gammapy.astro.population.YusifovKucuk2004B.param_names}\pysigline{\bfcode{param\_names}\strong{ = (`amplitude', `a', `b')}}
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{evaluate() (gammapy.astro.population.YusifovKucuk2004B static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.astro.population.YusifovKucuk2004B:gammapy.astro.population.YusifovKucuk2004B.evaluate}\pysiglinewithargsret{\strong{static }\bfcode{evaluate}}{\emph{r}, \emph{amplitude}, \emph{a}, \emph{b}}{}
One dimensional Yusifov \& Kucuk 2004 model function
\end{fulllineitems}
\end{fulllineitems}
\section{Getting Started}
\label{astro/index:astropy}\label{astro/index:getting-started}
\section{Example}
\label{astro/index:example}
TODO: Galactic gamma-ray source population model (catalog distributions, flux image, significance images)
\chapter{Background estimation and modeling (\texttt{gammapy.background})}
\label{background/index:background-estimation-and-modeling-gammapy-background}\label{background/index:astropy}\label{background/index::doc}\label{background/index:background}
\section{Introduction}
\label{background/index:introduction}
{\hyperref[background/index:module-gammapy.background]{\emph{\code{gammapy.background}}}} contains methods to estimate and model background.
The central data structure is the {\hyperref[api/gammapy.background.Maps:gammapy.background.Maps]{\emph{\code{Maps}}}} container.
TODO: describe
Most of the methods implemented are described in \phantomsection\label{background/index:id1}{\hyperref[references:berge2007]{\emph{{[}Berge2007{]}}}}.
Section 7.3 ``Background subtraction''
and Section 7.4 ``Acceptance determination and predicted background''
in \phantomsection\label{background/index:id2}{\hyperref[references:naurois2012]{\emph{{[}Naurois2012{]}}}} describe mostly the same methods as \phantomsection\label{background/index:id3}{\hyperref[references:berge2007]{\emph{{[}Berge2007{]}}}},
except for the ``2D acceptance model'' described in Section 7.4.3.
The background models implemented in Gammapy are documented in {\hyperref[background/models:bg-models]{\emph{\DUspan{}{Background Models}}}}.
\section{Getting Started}
\label{background/index:getting-started}
TODO
Hello World.
\section{Reference/API}
\label{background/index:reference-api}
\subsection{gammapy.background Package}
\label{background/index:gammapy-background-package}\label{background/index:module-gammapy.background}\index{gammapy.background (module)}
Background estimation and modeling methods.
\subsubsection{Functions}
\label{background/index:functions}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.background.fill_acceptance_image:gammapy.background.fill_acceptance_image]{\emph{\code{fill\_acceptance\_image}}}}(image, center, offset, ...)
&
Generate a 2D image of a radial acceptance curve.
\\
\hline
{\hyperref[api/gammapy.background.ring_alpha:gammapy.background.ring_alpha]{\emph{\code{ring\_alpha}}}}(theta, r\_in, r\_out)
&
Compute ring alpha, the inverse area factor.
\\
\hline
{\hyperref[api/gammapy.background.ring_area_factor:gammapy.background.ring_area_factor]{\emph{\code{ring\_area\_factor}}}}(theta, r\_in, r\_out)
&
Compute ring area factor.
\\
\hline
{\hyperref[api/gammapy.background.ring_correlate_off_maps:gammapy.background.ring_correlate_off_maps]{\emph{\code{ring\_correlate\_off\_maps}}}}(maps, r\_in, r\_out)
&
Ring-correlate the basic off maps.
\\
\hline
{\hyperref[api/gammapy.background.ring_r_out:gammapy.background.ring_r_out]{\emph{\code{ring\_r\_out}}}}(theta, r\_in, area\_factor)
&
Compute ring outer radius.
\\
\hline\end{longtable}
\paragraph{fill\_acceptance\_image}
\label{api/gammapy.background.fill_acceptance_image:fill-acceptance-image}\label{api/gammapy.background.fill_acceptance_image::doc}\index{fill\_acceptance\_image() (in module gammapy.background)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.fill_acceptance_image:gammapy.background.fill_acceptance_image}\pysiglinewithargsret{\code{gammapy.background.}\bfcode{fill\_acceptance\_image}}{\emph{image}, \emph{center}, \emph{offset}, \emph{acceptance}}{}
Generate a 2D image of a radial acceptance curve.
The radial acceptance curve is given as an array of values
defined at the specified offsets.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{image} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
Empty image to fill.
\end{quote}
\textbf{center} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.SkyCoord.html\#astropy.coordinates.SkyCoord}{\code{SkyCoord}}
\begin{quote}
Coordinate of the center of the image.
\end{quote}
\textbf{offset} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
1D array of offset values where acceptance is defined.
\end{quote}
\textbf{acceptance} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Array of acceptance values.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{image} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
Image filled with radial acceptance.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{ring\_alpha}
\label{api/gammapy.background.ring_alpha:astropy}\label{api/gammapy.background.ring_alpha::doc}\label{api/gammapy.background.ring_alpha:ring-alpha}\index{ring\_alpha() (in module gammapy.background)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.ring_alpha:gammapy.background.ring_alpha}\pysiglinewithargsret{\code{gammapy.background.}\bfcode{ring\_alpha}}{\emph{theta}, \emph{r\_in}, \emph{r\_out}}{}
Compute ring alpha, the inverse area factor.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{theta} : float
\begin{quote}
On region radius
\end{quote}
\textbf{r\_in} : float
\begin{quote}
Inner ring radius
\end{quote}
\textbf{r\_out} : float
\begin{quote}
Outer ring radius
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{ring\_area\_factor}
\label{api/gammapy.background.ring_area_factor:astropy}\label{api/gammapy.background.ring_area_factor::doc}\label{api/gammapy.background.ring_area_factor:ring-area-factor}\index{ring\_area\_factor() (in module gammapy.background)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.ring_area_factor:gammapy.background.ring_area_factor}\pysiglinewithargsret{\code{gammapy.background.}\bfcode{ring\_area\_factor}}{\emph{theta}, \emph{r\_in}, \emph{r\_out}}{}
Compute ring area factor.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{theta} : float
\begin{quote}
On region radius
\end{quote}
\textbf{r\_in} : float
\begin{quote}
Inner ring radius
\end{quote}
\textbf{r\_out} : float
\begin{quote}
Outer ring radius
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{ring\_correlate\_off\_maps}
\label{api/gammapy.background.ring_correlate_off_maps:ring-correlate-off-maps}\label{api/gammapy.background.ring_correlate_off_maps:astropy}\label{api/gammapy.background.ring_correlate_off_maps::doc}\index{ring\_correlate\_off\_maps() (in module gammapy.background)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.ring_correlate_off_maps:gammapy.background.ring_correlate_off_maps}\pysiglinewithargsret{\code{gammapy.background.}\bfcode{ring\_correlate\_off\_maps}}{\emph{maps}, \emph{r\_in}, \emph{r\_out}}{}
Ring-correlate the basic off maps.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{maps} : gammapy.background.maps.Maps
\begin{quote}
Maps container
\end{quote}
\textbf{r\_in} : float
\begin{quote}
Inner ring radius (deg)
\end{quote}
\textbf{r\_out} : float
\begin{quote}
Outer ring radius (deg)
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{ring\_r\_out}
\label{api/gammapy.background.ring_r_out:ring-r-out}\label{api/gammapy.background.ring_r_out:astropy}\label{api/gammapy.background.ring_r_out::doc}\index{ring\_r\_out() (in module gammapy.background)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.ring_r_out:gammapy.background.ring_r_out}\pysiglinewithargsret{\code{gammapy.background.}\bfcode{ring\_r\_out}}{\emph{theta}, \emph{r\_in}, \emph{area\_factor}}{}
Compute ring outer radius.
\begin{description}
\item[{The determining equation is:}] \leavevmode
area\_factor =
off\_area / on\_area =
(pi (r\_out**2 - r\_in**2)) / (pi * theta**2 )
\end{description}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{theta} : float
\begin{quote}
On region radius
\end{quote}
\textbf{r\_in} : float
\begin{quote}
Inner ring radius
\end{quote}
\textbf{area\_factor} : float
\begin{quote}
Desired off / on area ratio
\end{quote}
\item[{Returns}] \leavevmode
\textbf{r\_out} : float
\begin{quote}
Outer ring radius
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\subsubsection{Classes}
\label{background/index:astropy}\label{background/index:classes}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel]{\emph{\code{CubeBackgroundModel}}}}(detx\_bins, dety\_bins, ...)
&
Cube background model.
\\
\hline
{\hyperref[api/gammapy.background.GammaImages:gammapy.background.GammaImages]{\emph{\code{GammaImages}}}}(counts{[}, background, mask, header{]})
&
TODO: implement a more general images container class that can be re-used in other places as well.
\\
\hline
{\hyperref[api/gammapy.background.GaussianBand2D:gammapy.background.GaussianBand2D]{\emph{\code{GaussianBand2D}}}}(table{[}, spline\_kwargs{]})
&
Gaussian band model.
\\
\hline
{\hyperref[api/gammapy.background.IterativeKernelBackgroundEstimator:gammapy.background.IterativeKernelBackgroundEstimator]{\emph{\code{IterativeKernelBackgroundEstimator}}}}(images, ...)
&
Iteratively estimate a background model.
\\
\hline
{\hyperref[api/gammapy.background.Maps:gammapy.background.Maps]{\emph{\code{Maps}}}}({[}hdus, file, rename\_hdus, ...{]})
&
Maps container for basic maps and methods to compute derived maps.
\\
\hline
{\hyperref[api/gammapy.background.ReflectedBgMaker:gammapy.background.ReflectedBgMaker]{\emph{\code{ReflectedBgMaker}}}}
&
Compute background using the reflected background method
\\
\hline
{\hyperref[api/gammapy.background.ReflectedRegionMaker:gammapy.background.ReflectedRegionMaker]{\emph{\code{ReflectedRegionMaker}}}}(exclusion, fov{[}, ...{]})
&
Finds reflected regions.
\\
\hline
{\hyperref[api/gammapy.background.RingBgMaker:gammapy.background.RingBgMaker]{\emph{\code{RingBgMaker}}}}(r\_in, r\_out{[}, pixscale{]})
&
Ring background method for cartesian coordinates.
\\
\hline\end{longtable}
\paragraph{CubeBackgroundModel}
\label{api/gammapy.background.CubeBackgroundModel:cubebackgroundmodel}\label{api/gammapy.background.CubeBackgroundModel::doc}\index{CubeBackgroundModel (class in gammapy.background)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel}\pysiglinewithargsret{\strong{class }\code{gammapy.background.}\bfcode{CubeBackgroundModel}}{\emph{detx\_bins}, \emph{dety\_bins}, \emph{energy\_bins}, \emph{background}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Cube background model.
Container class for cube background model (X, Y, energy).
(X, Y) are detector coordinates (a.k.a. nominal system).
The class hass methods for reading a model from a fits file,
write a model to a fits file and plot the models.
The order of the axes in the background cube is \code{(E, y, x)},
so in order to access the data correctly, the call is
\code{bg\_cube\_model.background{[}energy\_bin, dety\_bin, detx\_bin{]}}.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{detx\_bins} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
Spatial bin edges vector (low and high). X coordinate.
\end{quote}
\textbf{dety\_bins} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
Spatial bin edges vector (low and high). Y coordinate.
\end{quote}
\textbf{energy\_bins} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Energy bin edges vector (low and high).
\end{quote}
\textbf{background} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Background cube in (energy, X, Y) format.
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
Access cube bg model data:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{energy\PYGZus{}bin} \PYG{o}{=} \PYG{n}{bg\PYGZus{}cube\PYGZus{}model}\PYG{o}{.}\PYG{n}{find\PYGZus{}energy\PYGZus{}bin}\PYG{p}{(}\PYG{n}{energy}\PYG{o}{=}\PYG{n}{Quantity}\PYG{p}{(}\PYG{l+m+mf}{2.}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{TeV}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{det\PYGZus{}bin} \PYG{o}{=} \PYG{n}{bg\PYGZus{}cube\PYGZus{}model}\PYG{o}{.}\PYG{n}{find\PYGZus{}det\PYGZus{}bin}\PYG{p}{(}\PYG{n}{det}\PYG{o}{=}\PYG{n}{Angle}\PYG{p}{(}\PYG{p}{[}\PYG{l+m+mf}{0.}\PYG{p}{,} \PYG{l+m+mf}{0.}\PYG{p}{]}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{degree}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{bg\PYGZus{}cube\PYGZus{}model}\PYG{o}{.}\PYG{n}{background}\PYG{p}{[}\PYG{n}{energy\PYGZus{}bin}\PYG{p}{,} \PYG{n}{det\PYGZus{}bin}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{,} \PYG{n}{det\PYGZus{}bin}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{]}
\end{Verbatim}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel.det_wcs]{\emph{\code{det\_wcs}}}}
&
WCS object describing the coordinates of the det (X, Y) bins.
\\
\hline
{\hyperref[api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel.energy_bin_centers]{\emph{\code{energy\_bin\_centers}}}}
&
Energy bin centers (logarithmic center).
\\
\hline
{\hyperref[api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel.image_bin_centers]{\emph{\code{image\_bin\_centers}}}}
&
Image bin centers \code{(x, y)}.
\\
\hline
{\hyperref[api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel.image_extent]{\emph{\code{image\_extent}}}}
&
Image extent \code{(x\_lo, x\_hi, y\_lo, y\_hi)}.
\\
\hline
{\hyperref[api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel.spectrum_extent]{\emph{\code{spectrum\_extent}}}}
&
Spectrum extent \code{(e\_lo, e\_hi)}.
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{det\_wcs (gammapy.background.CubeBackgroundModel attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel.det_wcs}\pysigline{\bfcode{det\_wcs}}
WCS object describing the coordinates of the det (X, Y) bins.
This method gives the correct answer only for linear X, Y binning.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{wcs} : \href{http://docs.astropy.org/en/latest/api/astropy.wcs.WCS.html\#astropy.wcs.WCS}{\code{WCS}}
\begin{quote}
WCS object describing the bin coordinates
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{energy\_bin\_centers (gammapy.background.CubeBackgroundModel attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel.energy_bin_centers}\pysigline{\bfcode{energy\_bin\_centers}}
Energy bin centers (logarithmic center).
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{energy\_bin\_centers} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
array of spectrum bin centers
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{image\_bin\_centers (gammapy.background.CubeBackgroundModel attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel.image_bin_centers}\pysigline{\bfcode{image\_bin\_centers}}
Image bin centers \code{(x, y)}.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{detx\_edges\_centers} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
array of image bin centers (X coord)
\end{quote}
\textbf{dety\_edges\_centers} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
array of image bin centers (Y coord)
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{image\_extent (gammapy.background.CubeBackgroundModel attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel.image_extent}\pysigline{\bfcode{image\_extent}}
Image extent \code{(x\_lo, x\_hi, y\_lo, y\_hi)}.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{im\_extent} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
array of bins with the image extent
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{spectrum\_extent (gammapy.background.CubeBackgroundModel attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel.spectrum_extent}\pysigline{\bfcode{spectrum\_extent}}
Spectrum extent \code{(e\_lo, e\_hi)}.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{spec\_extent} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
array of bins with the spectrum extent
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{find\_det\_bin() (gammapy.background.CubeBackgroundModel method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel.find_det_bin}\pysiglinewithargsret{\bfcode{find\_det\_bin}}{\emph{det}}{}
Find the bins that contain the specified det (X, Y) pairs.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{det} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html\#numpy.array}{\code{array}}
\begin{quote}
array of \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}} det (X, Y) pairs to search for
\end{quote}
\item[{Returns}] \leavevmode
\textbf{bin\_index} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html\#numpy.array}{\code{array}}
\begin{quote}
array of integers with the indices (x, y) of the det
bin containing the specified det (X, Y) pair
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{find\_det\_bin\_edges() (gammapy.background.CubeBackgroundModel method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel.find_det_bin_edges}\pysiglinewithargsret{\bfcode{find\_det\_bin\_edges}}{\emph{det}}{}
Find the bin edges of the specified det (X, Y) pairs.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{det} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html\#numpy.array}{\code{array}}
\begin{quote}
array of \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}} det (X, Y) pairs to search for
\end{quote}
\item[{Returns}] \leavevmode
\textbf{bin\_edges} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
det bin edges (x\_lo, x\_hi, y\_lo, y\_hi)
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{find\_energy\_bin() (gammapy.background.CubeBackgroundModel method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel.find_energy_bin}\pysiglinewithargsret{\bfcode{find\_energy\_bin}}{\emph{energy}}{}
Find the bins that contain the specified energy values.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energy} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html\#numpy.array}{\code{array}}
\begin{quote}
array of \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}} energies to search for
\end{quote}
\item[{Returns}] \leavevmode
\textbf{bin\_index} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html\#numpy.array}{\code{array}}
\begin{quote}
indices of the energy bins containing the specified energies
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{find\_energy\_bin\_edges() (gammapy.background.CubeBackgroundModel method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel.find_energy_bin_edges}\pysiglinewithargsret{\bfcode{find\_energy\_bin\_edges}}{\emph{energy}}{}
Find the bin edges of the specified energy values.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energy} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html\#numpy.array}{\code{array}}
\begin{quote}
array of \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}} energies to search for
\end{quote}
\item[{Returns}] \leavevmode
\textbf{bin\_edges} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
energy bin edges {[}E\_min, E\_max)
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{from\_fits\_image() (gammapy.background.CubeBackgroundModel static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel.from_fits_image}\pysiglinewithargsret{\strong{static }\bfcode{from\_fits\_image}}{\emph{imhdu}, \emph{enhdu}}{}
Read cube background model from a fits image.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{imhdu} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdus.html\#astropy.io.fits.PrimaryHDU}{\code{PrimaryHDU}}
\begin{quote}
image for the bg cube
\end{quote}
\textbf{enhdu} : \href{http://docs.astropy.org/en/latest/io/fits/api/tables.html\#astropy.io.fits.BinTableHDU}{\code{BinTableHDU}}
\begin{quote}
table for the energy binning
\end{quote}
\item[{Returns}] \leavevmode
\textbf{bg\_cube} : {\hyperref[api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel]{\emph{\code{CubeBackgroundModel}}}}
\begin{quote}
bg model cube object
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{from\_fits\_table() (gammapy.background.CubeBackgroundModel static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel.from_fits_table}\pysiglinewithargsret{\strong{static }\bfcode{from\_fits\_table}}{\emph{tbhdu}}{}
Read cube background model from a fits binary table.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{tbhdu} : \href{http://docs.astropy.org/en/latest/io/fits/api/tables.html\#astropy.io.fits.BinTableHDU}{\code{BinTableHDU}}
\begin{quote}
HDU binary table for the bg cube
\end{quote}
\item[{Returns}] \leavevmode
\textbf{bg\_cube} : {\hyperref[api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel]{\emph{\code{CubeBackgroundModel}}}}
\begin{quote}
bg model cube object
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{plot\_image() (gammapy.background.CubeBackgroundModel method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel.plot_image}\pysiglinewithargsret{\bfcode{plot\_image}}{\emph{energy}, \emph{ax=None}, \emph{style\_kwargs=None}}{}
Plot image for the energy bin containing the specified energy.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energy} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
energy of bin to plot the bg model
\end{quote}
\textbf{ax} : \code{Axes}, optional
\begin{quote}
axes of the figure for the plot
\end{quote}
\textbf{style\_kwargs} : dict, optional
\begin{quote}
style options for the plot
\end{quote}
\item[{Returns}] \leavevmode
\textbf{ax} : \code{Axes}
\begin{quote}
axes of the figure containing the plot
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{plot\_spectrum() (gammapy.background.CubeBackgroundModel method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel.plot_spectrum}\pysiglinewithargsret{\bfcode{plot\_spectrum}}{\emph{det}, \emph{ax=None}, \emph{style\_kwargs=None}}{}
Plot spectra for the det bin containing the specified det (X, Y) pair.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{det} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
det (X,Y) pair of bin to plot the bg model
\end{quote}
\textbf{ax} : \code{Axes}, optional
\begin{quote}
axes of the figure for the plot
\end{quote}
\textbf{style\_kwargs} : dict, optional
\begin{quote}
style options for the plot
\end{quote}
\item[{Returns}] \leavevmode
\textbf{ax} : \code{Axes}
\begin{quote}
axes of the figure containing the plot
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{read() (gammapy.background.CubeBackgroundModel static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel.read}\pysiglinewithargsret{\strong{static }\bfcode{read}}{\emph{filename}, \emph{format='table'}}{}
Read cube background model from fits file.
Several input formats are accepted, depending on the value
of the \href{http://docs.python.org/library/functions.html\#format}{\code{format}} parameter:
\begin{itemize}
\item {}
table (default and preferred format): \href{http://docs.astropy.org/en/latest/io/fits/api/tables.html\#astropy.io.fits.BinTableHDU}{\code{BinTableHDU}}
\item {}
image (alternative format): \href{http://docs.astropy.org/en/latest/io/fits/api/hdus.html\#astropy.io.fits.PrimaryHDU}{\code{PrimaryHDU}},
with the energy binning stored as \href{http://docs.astropy.org/en/latest/io/fits/api/tables.html\#astropy.io.fits.BinTableHDU}{\code{BinTableHDU}}
\end{itemize}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{filename} : str
\begin{quote}
name of file with the bg cube
\end{quote}
\textbf{format} : str, optional
\begin{quote}
format of the bg cube to read
\end{quote}
\item[{Returns}] \leavevmode
\textbf{bg\_cube} : {\hyperref[api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel]{\emph{\code{CubeBackgroundModel}}}}
\begin{quote}
bg model cube object
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{to\_fits\_image() (gammapy.background.CubeBackgroundModel method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel.to_fits_image}\pysiglinewithargsret{\bfcode{to\_fits\_image}}{}{}
Convert cube background model to image fits format.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{hdu\_list} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}
\begin{quote}
HDU list with:
\begin{itemize}
\item {}
one \href{http://docs.astropy.org/en/latest/io/fits/api/hdus.html\#astropy.io.fits.PrimaryHDU}{\code{PrimaryHDU}} image for the bg cube
\item {}
one \href{http://docs.astropy.org/en/latest/io/fits/api/tables.html\#astropy.io.fits.BinTableHDU}{\code{BinTableHDU}} table for the energy binning
\end{itemize}
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{to\_fits\_table() (gammapy.background.CubeBackgroundModel method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel.to_fits_table}\pysiglinewithargsret{\bfcode{to\_fits\_table}}{}{}
Convert cube background model to binary table fits format.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{tbhdu} : \href{http://docs.astropy.org/en/latest/io/fits/api/tables.html\#astropy.io.fits.BinTableHDU}{\code{BinTableHDU}}
\begin{quote}
table containing the bg cube
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{to\_table() (gammapy.background.CubeBackgroundModel method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel.to_table}\pysiglinewithargsret{\bfcode{to\_table}}{}{}
Convert cube background model to astropy table format.
The name of the table is stored in the table meta information
under the keyword `name'.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{table} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
table containing the bg cube
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{write() (gammapy.background.CubeBackgroundModel method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel.write}\pysiglinewithargsret{\bfcode{write}}{\emph{outfile}, \emph{format='table'}, \emph{**kwargs}}{}
Write cube background model to fits file.
Several output formats are accepted, depending on the value
of the \href{http://docs.python.org/library/functions.html\#format}{\code{format}} parameter:
\begin{itemize}
\item {}
table (default and preferred format): \href{http://docs.astropy.org/en/latest/io/fits/api/tables.html\#astropy.io.fits.BinTableHDU}{\code{BinTableHDU}}
\item {}
image (alternative format): \href{http://docs.astropy.org/en/latest/io/fits/api/hdus.html\#astropy.io.fits.PrimaryHDU}{\code{PrimaryHDU}},
with the energy binning stored as \href{http://docs.astropy.org/en/latest/io/fits/api/tables.html\#astropy.io.fits.BinTableHDU}{\code{BinTableHDU}}
\end{itemize}
Depending on the value of the \href{http://docs.python.org/library/functions.html\#format}{\code{format}} parameter, this
method calls either \href{http://docs.astropy.org/en/latest/io/fits/api/tables.html\#astropy.io.fits.BinTableHDU.writeto}{\code{writeto}} or
\href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList.writeto}{\code{writeto}}, forwarding the
\code{kwargs} arguments.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{outfile} : str
\begin{quote}
name of file to write
\end{quote}
\textbf{format} : str, optional
\begin{quote}
format of the bg cube to write
\end{quote}
\textbf{kwargs}
\begin{quote}
extra arguments for the corresponding \code{io.fits} \code{writeto} method
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\end{fulllineitems}
\paragraph{GammaImages}
\label{api/gammapy.background.GammaImages:astropy}\label{api/gammapy.background.GammaImages::doc}\label{api/gammapy.background.GammaImages:gammaimages}\index{GammaImages (class in gammapy.background)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.GammaImages:gammapy.background.GammaImages}\pysiglinewithargsret{\strong{class }\code{gammapy.background.}\bfcode{GammaImages}}{\emph{counts}, \emph{background=None}, \emph{mask=None}, \emph{header=None}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
TODO: implement a more general images container class
that can be re-used in other places as well.
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{compute\_correlated\_maps() (gammapy.background.GammaImages method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.GammaImages:gammapy.background.GammaImages.compute_correlated_maps}\pysiglinewithargsret{\bfcode{compute\_correlated\_maps}}{\emph{kernel}}{}
Compute significance image for a given kernel.
\end{fulllineitems}
\index{initial\_background() (gammapy.background.GammaImages method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.GammaImages:gammapy.background.GammaImages.initial_background}\pysiglinewithargsret{\bfcode{initial\_background}}{\emph{kernel}}{}
Computes initial background estimation
\end{fulllineitems}
\end{fulllineitems}
\paragraph{GaussianBand2D}
\label{api/gammapy.background.GaussianBand2D:astropy}\label{api/gammapy.background.GaussianBand2D::doc}\label{api/gammapy.background.GaussianBand2D:gaussianband2d}\index{GaussianBand2D (class in gammapy.background)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.GaussianBand2D:gammapy.background.GaussianBand2D}\pysiglinewithargsret{\strong{class }\code{gammapy.background.}\bfcode{GaussianBand2D}}{\emph{table}, \emph{spline\_kwargs=\{`k': 1}, \emph{`s': 0\}}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Gaussian band model.
This 2-dimensional model is Gaussian in \code{y} for a given \code{x},
and the Gaussian parameters can vary in \code{x}.
One application of this model is the diffuse emission along the
Galactic plane, i.e. \code{x = GLON} and \code{y = GLAT}.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{table} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Table of Gaussian parameters.
\code{x}, \code{amplitude}, \code{mean}, \code{stddev}.
\end{quote}
\textbf{spline\_kwargs} : dict
\begin{quote}
Keyword arguments passed to \href{http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.UnivariateSpline.html\#scipy.interpolate.UnivariateSpline}{\code{UnivariateSpline}}
\end{quote}
\end{description}\end{quote}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{evaluate() (gammapy.background.GaussianBand2D method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.GaussianBand2D:gammapy.background.GaussianBand2D.evaluate}\pysiglinewithargsret{\bfcode{evaluate}}{\emph{x}, \emph{y}}{}
Evaluate model at a given position \code{(x, y)} position.
\end{fulllineitems}
\index{parvals() (gammapy.background.GaussianBand2D method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.GaussianBand2D:gammapy.background.GaussianBand2D.parvals}\pysiglinewithargsret{\bfcode{parvals}}{\emph{x}}{}
Interpolated parameter values at a given \code{x}.
\end{fulllineitems}
\index{y\_model() (gammapy.background.GaussianBand2D method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.GaussianBand2D:gammapy.background.GaussianBand2D.y_model}\pysiglinewithargsret{\bfcode{y\_model}}{\emph{x}}{}
Create model at a given \code{x} position.
\end{fulllineitems}
\end{fulllineitems}
\paragraph{IterativeKernelBackgroundEstimator}
\label{api/gammapy.background.IterativeKernelBackgroundEstimator:astropy}\label{api/gammapy.background.IterativeKernelBackgroundEstimator::doc}\label{api/gammapy.background.IterativeKernelBackgroundEstimator:iterativekernelbackgroundestimator}\index{IterativeKernelBackgroundEstimator (class in gammapy.background)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.IterativeKernelBackgroundEstimator:gammapy.background.IterativeKernelBackgroundEstimator}\pysiglinewithargsret{\strong{class }\code{gammapy.background.}\bfcode{IterativeKernelBackgroundEstimator}}{\emph{images}, \emph{source\_kernel}, \emph{background\_kernel}, \emph{significance\_threshold}, \emph{mask\_dilation\_radius}, \emph{delete\_intermediate\_results=True}, \emph{save\_intermediate\_results=False}, \emph{filebase='temp'}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Iteratively estimate a background model.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{images} : {\hyperref[api/gammapy.background.GammaImages:gammapy.background.GammaImages]{\emph{\code{GammaImages}}}}
\begin{quote}
GammaImages object containing counts image and (optional) initial
background estimation.
\end{quote}
\textbf{source\_kernel} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{numpy.ndarray}}
\begin{quote}
Source kernel as a numpy array.
\end{quote}
\textbf{background\_kernel} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{numpy.ndarray}}
\begin{quote}
Background convolution kernel as a numpy array.
\end{quote}
\textbf{significance\_threshold} : float
\begin{quote}
Significance threshold above which regions are excluded.
\end{quote}
\textbf{mask\_dilation\_radius} : float
\begin{quote}
Amount by which mask is dilated with each iteration.
\end{quote}
\textbf{delete\_intermediate\_results} : bool
\begin{quote}
Specify whether results of intermediate iterations should be deleted.
(Otherwise, these are held in memory). Default True.
\end{quote}
\textbf{save\_intermediate\_results} : bool
\begin{quote}
Specify whether to save intermediate results as FITS files to disk.
Default False.
\end{quote}
\textbf{filebase} : str (optional)
\begin{quote}
Base of filenames if save\_intermediate\_results = True. Default `temp'.
\end{quote}
\end{description}\end{quote}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.background.IterativeKernelBackgroundEstimator:gammapy.background.IterativeKernelBackgroundEstimator.background_image_hdu]{\emph{\code{background\_image\_hdu}}}}
&
Returns resulting background estimate as \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}.
\\
\hline
{\hyperref[api/gammapy.background.IterativeKernelBackgroundEstimator:gammapy.background.IterativeKernelBackgroundEstimator.mask_image_hdu]{\emph{\code{mask\_image\_hdu}}}}
&
Returns mask as \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}.
\\
\hline
{\hyperref[api/gammapy.background.IterativeKernelBackgroundEstimator:gammapy.background.IterativeKernelBackgroundEstimator.significance_image_hdu]{\emph{\code{significance\_image\_hdu}}}}
&
Returns resulting background estimate as \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}.
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{background\_image\_hdu (gammapy.background.IterativeKernelBackgroundEstimator attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.IterativeKernelBackgroundEstimator:gammapy.background.IterativeKernelBackgroundEstimator.background_image_hdu}\pysigline{\bfcode{background\_image\_hdu}}
Returns resulting background estimate as \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}.
\end{fulllineitems}
\index{mask\_image\_hdu (gammapy.background.IterativeKernelBackgroundEstimator attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.IterativeKernelBackgroundEstimator:gammapy.background.IterativeKernelBackgroundEstimator.mask_image_hdu}\pysigline{\bfcode{mask\_image\_hdu}}
Returns mask as \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}.
\end{fulllineitems}
\index{significance\_image\_hdu (gammapy.background.IterativeKernelBackgroundEstimator attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.IterativeKernelBackgroundEstimator:gammapy.background.IterativeKernelBackgroundEstimator.significance_image_hdu}\pysigline{\bfcode{significance\_image\_hdu}}
Returns resulting background estimate as \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}.
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{run() (gammapy.background.IterativeKernelBackgroundEstimator method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.IterativeKernelBackgroundEstimator:gammapy.background.IterativeKernelBackgroundEstimator.run}\pysiglinewithargsret{\bfcode{run}}{\emph{filebase=None}, \emph{max\_iterations=10}}{}
Run iterations until mask does not change (stopping condition).
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{filebase} : str
\begin{quote}
Base string for filenames if iterations are saved to disk.
Default None.
\end{quote}
\textbf{max\_iterations} : int
\begin{quote}
Maximum number of iterations after which the algorithm is
terminated, if the termination condition (no change of mask between
iterations) is not already satisfied.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{mask} : array-like
\begin{quote}
Boolean array for the final mask after iterations are ended.
\end{quote}
\textbf{background} : array-like
\begin{quote}
Array of floats for the final background estimation after
iterations are complete.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{run\_iteration() (gammapy.background.IterativeKernelBackgroundEstimator method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.IterativeKernelBackgroundEstimator:gammapy.background.IterativeKernelBackgroundEstimator.run_iteration}\pysiglinewithargsret{\bfcode{run\_iteration}}{\emph{update\_mask=True}}{}
Run one iteration.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{update\_mask} : bool
\begin{quote}
Specify whether to update the exclusion mask stored in the input
{\hyperref[api/gammapy.background.GammaImages:gammapy.background.GammaImages]{\emph{\code{GammaImages}}}} object with the exclusion mask
newly calculated in this method.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{save\_files() (gammapy.background.IterativeKernelBackgroundEstimator method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.IterativeKernelBackgroundEstimator:gammapy.background.IterativeKernelBackgroundEstimator.save_files}\pysiglinewithargsret{\bfcode{save\_files}}{\emph{filebase}, \emph{index}}{}
Saves files to fits.
\end{fulllineitems}
\end{fulllineitems}
\paragraph{Maps}
\label{api/gammapy.background.Maps:astropy}\label{api/gammapy.background.Maps::doc}\label{api/gammapy.background.Maps:maps}\index{Maps (class in gammapy.background)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.Maps:gammapy.background.Maps}\pysiglinewithargsret{\strong{class }\code{gammapy.background.}\bfcode{Maps}}{\emph{hdus={[}{]}}, \emph{file=None}, \emph{rename\_hdus=None}, \emph{is\_off\_correlated=True}, \emph{theta=None}, \emph{theta\_pix=0}}{}
Bases: \code{astropy.io.fits.hdu.hdulist.HDUList}
Maps container for basic maps and methods to compute derived maps.
It is simply a list of HDUs containing the maps, plus methods to
compute the derived maps.
These maps allow implementing all background estimation methods.
Not all maps are used for each method, unused maps are typically
filled with zeros or ones as appropriate.
\begin{description}
\item[{TODO: Correlation of basic maps is done repeatedly when}] \leavevmode
computing all derived maps.
Is it worth speeding things up by writing the steps explicitly?
\end{description}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{hdus} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}} containing \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}} objects
\begin{quote}
Must contain at least one of the basic maps
\end{quote}
\textbf{file} : str
\begin{quote}
Passed right on to HDUList constructor
\end{quote}
\textbf{rename\_hdus} : dict
\begin{quote}
Dictionary of HDUs to rename, e.g. rename\_hdus=dict(n\_on=3, exclusion=2).
\end{quote}
\textbf{is\_off\_correlated} : bool
\begin{quote}
Flag whether the off map is already correlated
\end{quote}
\textbf{theta} : float
\begin{quote}
Correlation radius (deg)
\end{quote}
\textbf{theta\_pix} : float
\begin{quote}
Correlation radius (pix)
\end{quote}
\end{description}\end{quote}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.background.Maps:gammapy.background.Maps.alpha]{\emph{\code{alpha}}}}
&
Alpha map HDU.
\\
\hline
{\hyperref[api/gammapy.background.Maps:gammapy.background.Maps.area_factor]{\emph{\code{area\_factor}}}}
&
Area factor map HDU.
\\
\hline
{\hyperref[api/gammapy.background.Maps:gammapy.background.Maps.background]{\emph{\code{background}}}}
&
Background map HDU.
\\
\hline
{\hyperref[api/gammapy.background.Maps:gammapy.background.Maps.flux]{\emph{\code{flux}}}}
&
Flux map HDU.
\\
\hline
{\hyperref[api/gammapy.background.Maps:gammapy.background.Maps.make_excess]{\emph{\code{make\_excess}}}}
&
Excess map HDU.
\\
\hline
{\hyperref[api/gammapy.background.Maps:gammapy.background.Maps.significance]{\emph{\code{significance}}}}
&
Significance map HDU.
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{alpha (gammapy.background.Maps attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.Maps:gammapy.background.Maps.alpha}\pysigline{\bfcode{alpha}}
Alpha map HDU.
\end{fulllineitems}
\index{area\_factor (gammapy.background.Maps attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.Maps:gammapy.background.Maps.area_factor}\pysigline{\bfcode{area\_factor}}
Area factor map HDU.
\end{fulllineitems}
\index{background (gammapy.background.Maps attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.Maps:gammapy.background.Maps.background}\pysigline{\bfcode{background}}
Background map HDU.
\end{fulllineitems}
\index{flux (gammapy.background.Maps attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.Maps:gammapy.background.Maps.flux}\pysigline{\bfcode{flux}}
Flux map HDU.
\end{fulllineitems}
\index{make\_excess (gammapy.background.Maps attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.Maps:gammapy.background.Maps.make_excess}\pysigline{\bfcode{make\_excess}}
Excess map HDU.
\end{fulllineitems}
\index{significance (gammapy.background.Maps attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.Maps:gammapy.background.Maps.significance}\pysigline{\bfcode{significance}}
Significance map HDU.
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{get\_basic() (gammapy.background.Maps method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.Maps:gammapy.background.Maps.get_basic}\pysiglinewithargsret{\bfcode{get\_basic}}{\emph{name}}{}
Gets the data of a basic map and disk-correlates if required.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{name} : str
\begin{quote}
Map name
\end{quote}
\item[{Returns}] \leavevmode
\textbf{image} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html\#numpy.array}{\code{numpy.array}}
\begin{quote}
Map data
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{get\_derived() (gammapy.background.Maps method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.Maps:gammapy.background.Maps.get_derived}\pysiglinewithargsret{\bfcode{get\_derived}}{\emph{name}}{}
Gets the data if it exists or makes it if not.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{name} : str
\begin{quote}
Map name
\end{quote}
\item[{Returns}] \leavevmode
\textbf{image} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html\#numpy.array}{\code{numpy.array}}
\begin{quote}
Map data
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{make\_correlated\_basic\_maps() (gammapy.background.Maps method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.Maps:gammapy.background.Maps.make_correlated_basic_maps}\pysiglinewithargsret{\bfcode{make\_correlated\_basic\_maps}}{}{}
Make correlated versions of all the basic maps.
@note This is mainly useful for debugging.
@note All maps are disk-correlated, even e.g. the off map
if it had been ring-correlated before already.
\end{fulllineitems}
\index{make\_derived\_maps() (gammapy.background.Maps method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.Maps:gammapy.background.Maps.make_derived_maps}\pysiglinewithargsret{\bfcode{make\_derived\_maps}}{}{}
Make all the derived maps.
\end{fulllineitems}
\end{fulllineitems}
\paragraph{ReflectedBgMaker}
\label{api/gammapy.background.ReflectedBgMaker:astropy}\label{api/gammapy.background.ReflectedBgMaker::doc}\label{api/gammapy.background.ReflectedBgMaker:reflectedbgmaker}\index{ReflectedBgMaker (class in gammapy.background)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.ReflectedBgMaker:gammapy.background.ReflectedBgMaker}\pysigline{\strong{class }\code{gammapy.background.}\bfcode{ReflectedBgMaker}}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Compute background using the reflected background method
\end{fulllineitems}
\paragraph{ReflectedRegionMaker}
\label{api/gammapy.background.ReflectedRegionMaker:astropy}\label{api/gammapy.background.ReflectedRegionMaker::doc}\label{api/gammapy.background.ReflectedRegionMaker:reflectedregionmaker}\index{ReflectedRegionMaker (class in gammapy.background)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.ReflectedRegionMaker:gammapy.background.ReflectedRegionMaker}\pysiglinewithargsret{\strong{class }\code{gammapy.background.}\bfcode{ReflectedRegionMaker}}{\emph{exclusion}, \emph{fov}, \emph{min\_on\_distance=0.1}, \emph{angle\_increment=0.1}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Finds reflected regions.
TODO: At the moment only works for circular regions!
TODO: should work with world or pixel coordinates internally!???
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{compute() (gammapy.background.ReflectedRegionMaker method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.ReflectedRegionMaker:gammapy.background.ReflectedRegionMaker.compute}\pysiglinewithargsret{\bfcode{compute}}{\emph{x\_on}, \emph{y\_on}, \emph{r\_on}}{}
\end{fulllineitems}
\index{write\_off\_regions() (gammapy.background.ReflectedRegionMaker method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.ReflectedRegionMaker:gammapy.background.ReflectedRegionMaker.write_off_regions}\pysiglinewithargsret{\bfcode{write\_off\_regions}}{\emph{filename}}{}
\end{fulllineitems}
\end{fulllineitems}
\paragraph{RingBgMaker}
\label{api/gammapy.background.RingBgMaker:astropy}\label{api/gammapy.background.RingBgMaker::doc}\label{api/gammapy.background.RingBgMaker:ringbgmaker}\index{RingBgMaker (class in gammapy.background)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.RingBgMaker:gammapy.background.RingBgMaker}\pysiglinewithargsret{\strong{class }\code{gammapy.background.}\bfcode{RingBgMaker}}{\emph{r\_in}, \emph{r\_out}, \emph{pixscale=0.01}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Ring background method for cartesian coordinates.
Step 1: apply exclusion mask
Step 2: ring-correlate
Step 3: apply psi cut
TODO: add method to apply the psi cut
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{r\_in} : float
\begin{quote}
Inner ring radius (deg)
\end{quote}
\textbf{r\_out} : float
\begin{quote}
Outer ring radius (deg)
\end{quote}
\textbf{pixscale} : float
\begin{quote}
degrees per pixel
\end{quote}
\end{description}\end{quote}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{correlate() (gammapy.background.RingBgMaker method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.RingBgMaker:gammapy.background.RingBgMaker.correlate}\pysiglinewithargsret{\bfcode{correlate}}{\emph{image}}{}
Ring-correlate a given image.
\end{fulllineitems}
\index{correlate\_maps() (gammapy.background.RingBgMaker method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.RingBgMaker:gammapy.background.RingBgMaker.correlate_maps}\pysiglinewithargsret{\bfcode{correlate\_maps}}{\emph{maps}}{}
Compute off maps as ring-correlated versions of the on maps.
The exclusion map is taken into account.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{maps} : gammapy.background.maps.Maps
\begin{quote}
Input maps (is modified in-place)
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{info() (gammapy.background.RingBgMaker method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.background.RingBgMaker:gammapy.background.RingBgMaker.info}\pysiglinewithargsret{\bfcode{info}}{}{}
Print some basic parameter info.
\end{fulllineitems}
\end{fulllineitems}
\subsection{Sub-pages}
\label{background/index:astropy}\label{background/index:sub-pages}
\subsubsection{Background Models}
\label{background/models:bg-models}\label{background/models:background-models}\label{background/models::doc}
The naming of the models in this section follows the convention from
{\hyperref[dataformats/index:dataformats-overview]{\emph{\DUspan{}{Overview}}}}.
\paragraph{BACKGROUND\_3D}
\label{background/models:background-3d}\label{background/models:id1}
\code{BACKGROUND\_3D} is a background rate 3D cube (X, Y, energy) in
units of per energy, per time, per solid angle. \code{X} and \code{Y} are
given in detector coordinates \code{(DETX, DETY)}, a.k.a.
\code{nominal system}. This is a tangential system to the instrument
during observations.
The {\hyperref[api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel]{\emph{\code{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 \code{gammapy-extra} repository
(\href{https://github.com/gammapy/gammapy-extra/blob/master/test\_datasets/background/bg\_cube\_model\_test.fits}{bg\_cube\_model\_test.fits}).
The file comes originally from the \code{GammaLib} repository but has
been slightly modified.
An example script of how to read/write the files and perform some
simple plots is given in the \code{examples} directory:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}Plot background model and store as cube so that it can viewed with ds9.}
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}}
\PYG{k+kn}{import} \PYG{n+nn}{matplotlib.pyplot} \PYG{k+kn}{as} \PYG{n+nn}{plt}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.units} \PYG{k+kn}{import} \PYG{n}{Quantity}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.coordinates} \PYG{k+kn}{import} \PYG{n}{Angle}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.background} \PYG{k+kn}{import} \PYG{n}{CubeBackgroundModel}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy} \PYG{k+kn}{import} \PYG{n}{datasets}
\PYG{n}{filename} \PYG{o}{=} \PYG{n}{datasets}\PYG{o}{.}\PYG{n}{get\PYGZus{}path}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{../test\PYGZus{}datasets/background/bg\PYGZus{}cube\PYGZus{}model\PYGZus{}test.fits}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,}
\PYG{n}{location}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{remote}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{bg\PYGZus{}model} \PYG{o}{=} \PYG{n}{CubeBackgroundModel}\PYG{o}{.}\PYG{n}{read}\PYG{p}{(}\PYG{n}{filename}\PYG{p}{,} \PYG{n}{format}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{table}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{bg\PYGZus{}model}\PYG{o}{.}\PYG{n}{plot\PYGZus{}image}\PYG{p}{(}\PYG{n}{energy}\PYG{o}{=}\PYG{n}{Quantity}\PYG{p}{(}\PYG{l+m+mf}{2.}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{TeV}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{bg\PYGZus{}model}\PYG{o}{.}\PYG{n}{plot\PYGZus{}spectrum}\PYG{p}{(}\PYG{n}{det}\PYG{o}{=}\PYG{n}{Angle}\PYG{p}{(}\PYG{p}{[}\PYG{l+m+mf}{0.}\PYG{p}{,} \PYG{l+m+mf}{0.}\PYG{p}{]}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{degree}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{outname} \PYG{o}{=} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{cube\PYGZus{}background\PYGZus{}model}\PYG{l+s}{\PYGZsq{}}
\PYG{n}{bg\PYGZus{}model}\PYG{o}{.}\PYG{n}{write}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{\PYGZob{}\PYGZcb{}\PYGZus{}bin\PYGZus{}table.fits}\PYG{l+s}{\PYGZsq{}}\PYG{o}{.}\PYG{n}{format}\PYG{p}{(}\PYG{n}{outname}\PYG{p}{)}\PYG{p}{,} \PYG{n}{format}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{table}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{clobber}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{)}
\PYG{n}{bg\PYGZus{}model}\PYG{o}{.}\PYG{n}{write}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{\PYGZob{}\PYGZcb{}\PYGZus{}image.fits}\PYG{l+s}{\PYGZsq{}}\PYG{o}{.}\PYG{n}{format}\PYG{p}{(}\PYG{n}{outname}\PYG{p}{)}\PYG{p}{,} \PYG{n}{format}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{image}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{clobber}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{show}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}
The data of the cube can be accessed via:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{energy\PYGZus{}bin} \PYG{o}{=} \PYG{n}{bg\PYGZus{}cube\PYGZus{}model}\PYG{o}{.}\PYG{n}{find\PYGZus{}energy\PYGZus{}bin}\PYG{p}{(}\PYG{n}{energy}\PYG{o}{=}\PYG{n}{Quantity}\PYG{p}{(}\PYG{l+m+mf}{2.}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{TeV}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{det\PYGZus{}bin} \PYG{o}{=} \PYG{n}{bg\PYGZus{}cube\PYGZus{}model}\PYG{o}{.}\PYG{n}{find\PYGZus{}det\PYGZus{}bin}\PYG{p}{(}\PYG{n}{det}\PYG{o}{=}\PYG{n}{Angle}\PYG{p}{(}\PYG{p}{[}\PYG{l+m+mf}{0.}\PYG{p}{,} \PYG{l+m+mf}{0.}\PYG{p}{]}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{degree}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{bg\PYGZus{}cube\PYGZus{}model}\PYG{o}{.}\PYG{n}{background}\PYG{p}{[}\PYG{n}{energy\PYGZus{}bin}\PYG{p}{,} \PYG{n}{det\PYGZus{}bin}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{,} \PYG{n}{det\PYGZus{}bin}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{]}
\end{Verbatim}
More complex plots can be easily produced with a few lines of code:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{matplotlib.pyplot} \PYG{k+kn}{as} \PYG{n+nn}{plt}
\PYG{k+kn}{from} \PYG{n+nn}{matplotlib.colors} \PYG{k+kn}{import} \PYG{n}{LogNorm}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.units} \PYG{k+kn}{import} \PYG{n}{Quantity}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.coordinates} \PYG{k+kn}{import} \PYG{n}{Angle}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.background} \PYG{k+kn}{import} \PYG{n}{CubeBackgroundModel}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy} \PYG{k+kn}{import} \PYG{n}{datasets}
\PYG{n}{filename} \PYG{o}{=} \PYG{n}{datasets}\PYG{o}{.}\PYG{n}{get\PYGZus{}path}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{../test\PYGZus{}datasets/background/bg\PYGZus{}cube\PYGZus{}model\PYGZus{}test.fits}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,}
\PYG{n}{location}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{remote}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{bg\PYGZus{}model} \PYG{o}{=} \PYG{n}{CubeBackgroundModel}\PYG{o}{.}\PYG{n}{read}\PYG{p}{(}\PYG{n}{filename}\PYG{p}{,} \PYG{n}{format}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{table}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{fig}\PYG{p}{,} \PYG{n}{axes} \PYG{o}{=} \PYG{n}{plt}\PYG{o}{.}\PYG{n}{subplots}\PYG{p}{(}\PYG{n}{nrows}\PYG{o}{=}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{n}{ncols}\PYG{o}{=}\PYG{l+m+mi}{3}\PYG{p}{)}
\PYG{n}{fig}\PYG{o}{.}\PYG{n}{set\PYGZus{}size\PYGZus{}inches}\PYG{p}{(}\PYG{l+m+mf}{30.}\PYG{p}{,} \PYG{l+m+mf}{8.}\PYG{p}{,} \PYG{n}{forward}\PYG{o}{=}\PYG{n+nb+bp}{True}\PYG{p}{)}
\PYG{c}{\PYGZsh{} plot images}
\PYG{n}{bg\PYGZus{}model}\PYG{o}{.}\PYG{n}{plot\PYGZus{}image}\PYG{p}{(}\PYG{n}{energy}\PYG{o}{=}\PYG{n}{Quantity}\PYG{p}{(}\PYG{l+m+mf}{0.5}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{TeV}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{,} \PYG{n}{ax}\PYG{o}{=}\PYG{n}{axes}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{p}{,} \PYG{n}{style\PYGZus{}kwargs}\PYG{o}{=}\PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{norm}\PYG{o}{=}\PYG{n}{LogNorm}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{bg\PYGZus{}model}\PYG{o}{.}\PYG{n}{plot\PYGZus{}image}\PYG{p}{(}\PYG{n}{energy}\PYG{o}{=}\PYG{n}{Quantity}\PYG{p}{(}\PYG{l+m+mf}{50.}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{TeV}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{,} \PYG{n}{ax}\PYG{o}{=}\PYG{n}{axes}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{p}{,} \PYG{n}{style\PYGZus{}kwargs}\PYG{o}{=}\PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{norm}\PYG{o}{=}\PYG{n}{LogNorm}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}\PYG{p}{)}
\PYG{c}{\PYGZsh{} plot spectra}
\PYG{n}{bg\PYGZus{}model}\PYG{o}{.}\PYG{n}{plot\PYGZus{}spectrum}\PYG{p}{(}\PYG{n}{det}\PYG{o}{=}\PYG{n}{Angle}\PYG{p}{(}\PYG{p}{[}\PYG{l+m+mf}{0.}\PYG{p}{,} \PYG{l+m+mf}{0.}\PYG{p}{]}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{degree}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{,} \PYG{n}{ax}\PYG{o}{=}\PYG{n}{axes}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{p}{,}
\PYG{n}{style\PYGZus{}kwargs}\PYG{o}{=}\PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{color}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{blue}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{label}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{(0, 0) deg}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{bg\PYGZus{}model}\PYG{o}{.}\PYG{n}{plot\PYGZus{}spectrum}\PYG{p}{(}\PYG{n}{det}\PYG{o}{=}\PYG{n}{Angle}\PYG{p}{(}\PYG{p}{[}\PYG{l+m+mf}{2.}\PYG{p}{,} \PYG{l+m+mf}{2.}\PYG{p}{]}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{degree}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{,} \PYG{n}{ax}\PYG{o}{=}\PYG{n}{axes}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{p}{,}
\PYG{n}{style\PYGZus{}kwargs}\PYG{o}{=}\PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{color}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{red}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{label}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{(2, 2) deg}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{axes}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{o}{.}\PYG{n}{set\PYGZus{}title}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{axes}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{o}{.}\PYG{n}{legend}\PYG{p}{(}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{show}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}
\includegraphics{plot_bgcube.pdf}
There is also a method in the {\hyperref[datasets/index:module-gammapy.datasets]{\emph{\code{datasets}}}} module called
{\hyperref[api/gammapy.datasets.make_test_bg_cube_model:gammapy.datasets.make_test_bg_cube_model]{\emph{\code{make\_test\_bg\_cube\_model}}}} for creating test
{\hyperref[api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel]{\emph{\code{CubeBackgroundModel}}}} objects.
\chapter{Catalog (\texttt{gammapy.catalog})}
\label{catalog/index:astropy}\label{catalog/index::doc}\label{catalog/index:catalog}\label{catalog/index:catalog-gammapy-catalog}
\section{Introduction}
\label{catalog/index:introduction}
{\hyperref[catalog/index:module-gammapy.catalog]{\emph{\code{gammapy.catalog}}}} contains tools to create and analyse source catalogs,
as well as high-level interfaces to the most relevant catalog for gamma-ray astronomy.
TODO: give one example, e.g. how to reproduce a log(N)-log(S) plot from a Fermi catalog paper.
\section{Getting Started}
\label{catalog/index:getting-started}
TODO: give some more example.
\section{Reference/API}
\label{catalog/index:reference-api}
\subsection{gammapy.catalog Package}
\label{catalog/index:module-gammapy.catalog}\label{catalog/index:gammapy-catalog-package}\index{gammapy.catalog (module)}
Tools to create and analyse source catalogs.
\subsubsection{Functions}
\label{catalog/index:functions}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.catalog.catalog_xmatch_circle:gammapy.catalog.catalog_xmatch_circle]{\emph{\code{catalog\_xmatch\_circle}}}}(catalog, other\_catalog)
&
Find associations within a circle around each source.
\\
\hline
{\hyperref[api/gammapy.catalog.catalog_xmatch_combine:gammapy.catalog.catalog_xmatch_combine]{\emph{\code{catalog\_xmatch\_combine}}}}(associations)
&
Combine (vertical stack) association tables.
\\
\hline
{\hyperref[api/gammapy.catalog.coordinate_iau_format:gammapy.catalog.coordinate_iau_format]{\emph{\code{coordinate\_iau\_format}}}}(coordinate, ra\_digits)
&
Coordinate format as an IAU source designation.
\\
\hline
{\hyperref[api/gammapy.catalog.dec_iau_format:gammapy.catalog.dec_iau_format]{\emph{\code{dec\_iau\_format}}}}(dec, digits)
&
Declination part of an IAU source designation.
\\
\hline
{\hyperref[api/gammapy.catalog.get_source_by_name:gammapy.catalog.get_source_by_name]{\emph{\code{get\_source\_by\_name}}}}(source, catalog{[}, id\_column{]})
&
Get source catalog entry by source name.
\\
\hline
{\hyperref[api/gammapy.catalog.ra_iau_format:gammapy.catalog.ra_iau_format]{\emph{\code{ra\_iau\_format}}}}(ra, digits)
&
Right Ascension part of an IAU source designation.
\\
\hline
{\hyperref[api/gammapy.catalog.select_sky_box:gammapy.catalog.select_sky_box]{\emph{\code{select\_sky\_box}}}}(table, lon\_lim, lat\_lim{[}, frame{]})
&
Select sky positions in a box.
\\
\hline
{\hyperref[api/gammapy.catalog.skycoord_from_table:gammapy.catalog.skycoord_from_table]{\emph{\code{skycoord\_from\_table}}}}(table)
&
Make \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.SkyCoord.html\#astropy.coordinates.SkyCoord}{\code{SkyCoord}} from lon, lat columns in \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}.
\\
\hline
{\hyperref[api/gammapy.catalog.table_xmatch:gammapy.catalog.table_xmatch]{\emph{\code{table\_xmatch}}}}(table1, table2, xmatch\_criterion)
&
Cross-match rows from two tables with a cross-match criterion callback.
\\
\hline
{\hyperref[api/gammapy.catalog.table_xmatch_circle_criterion:gammapy.catalog.table_xmatch_circle_criterion]{\emph{\code{table\_xmatch\_circle\_criterion}}}}(max\_separation)
&
An example cross-match criterion for {\hyperref[api/gammapy.catalog.table_xmatch:gammapy.catalog.table_xmatch]{\emph{\code{table\_xmatch}}}} that reproduces {\hyperref[api/gammapy.catalog.catalog_xmatch_circle:gammapy.catalog.catalog_xmatch_circle]{\emph{\code{catalog\_xmatch\_circle}}}}.
\\
\hline
{\hyperref[api/gammapy.catalog.to_ds9_region:gammapy.catalog.to_ds9_region]{\emph{\code{to\_ds9\_region}}}}(catalog{[}, radius, color, ...{]})
&
Write ds9 region file from catalog.
\\
\hline\end{longtable}
\paragraph{catalog\_xmatch\_circle}
\label{api/gammapy.catalog.catalog_xmatch_circle:catalog-xmatch-circle}\label{api/gammapy.catalog.catalog_xmatch_circle::doc}\index{catalog\_xmatch\_circle() (in module gammapy.catalog)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.catalog.catalog_xmatch_circle:gammapy.catalog.catalog_xmatch_circle}\pysiglinewithargsret{\code{gammapy.catalog.}\bfcode{catalog\_xmatch\_circle}}{\emph{catalog}, \emph{other\_catalog}, \emph{radius='Association\_Radius'}, \emph{other\_radius=\textless{}Angle 0.0 deg\textgreater{}}}{}
Find associations within a circle around each source.
This is convenience function built on \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.SkyCoord.html\#astropy.coordinates.SkyCoord.search\_around\_sky}{\code{search\_around\_sky}},
extending it in two ways:
\begin{enumerate}
\item {}
Each source can have a different association radius.
\item {}
Handle source catalogs (\href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}) instead of \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.SkyCoord.html\#astropy.coordinates.SkyCoord}{\code{SkyCoord}}.
\end{enumerate}
Sources are associated if the sum of their radii is smaller than their separation on the sky.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{catalog} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Main source catalog
\end{quote}
\textbf{other\_catalog} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Other source catalog of potential associations
\end{quote}
\textbf{radius, other\_radius} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}} or \href{http://docs.python.org/library/functions.html\#str}{\code{str}}
\begin{quote}
Main source catalog association radius.
For \href{http://docs.python.org/library/functions.html\#str}{\code{str}} this must be a column name (in \code{deg} if without units)
\end{quote}
\item[{Returns}] \leavevmode
\textbf{associations} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
The list of associations.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{catalog\_xmatch\_combine}
\label{api/gammapy.catalog.catalog_xmatch_combine:catalog-xmatch-combine}\label{api/gammapy.catalog.catalog_xmatch_combine:astropy}\label{api/gammapy.catalog.catalog_xmatch_combine::doc}\index{catalog\_xmatch\_combine() (in module gammapy.catalog)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.catalog.catalog_xmatch_combine:gammapy.catalog.catalog_xmatch_combine}\pysiglinewithargsret{\code{gammapy.catalog.}\bfcode{catalog\_xmatch\_combine}}{\emph{associations}}{}
Combine (vertical stack) association tables.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{associations} : dict or (str, \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}})
\begin{quote}
Associations
\end{quote}
\item[{Returns}] \leavevmode
\textbf{combined\_associations} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Combined associations table.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{coordinate\_iau\_format}
\label{api/gammapy.catalog.coordinate_iau_format:astropy}\label{api/gammapy.catalog.coordinate_iau_format::doc}\label{api/gammapy.catalog.coordinate_iau_format:coordinate-iau-format}\index{coordinate\_iau\_format() (in module gammapy.catalog)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.catalog.coordinate_iau_format:gammapy.catalog.coordinate_iau_format}\pysiglinewithargsret{\code{gammapy.catalog.}\bfcode{coordinate\_iau\_format}}{\emph{coordinate}, \emph{ra\_digits}, \emph{dec\_digits=None}, \emph{prefix='`}}{}
Coordinate format as an IAU source designation.
Reference: \href{http://cdsweb.u-strasbg.fr/Dic/iau-spec.html}{http://cdsweb.u-strasbg.fr/Dic/iau-spec.html}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{coordinate} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.SkyCoord.html\#astropy.coordinates.SkyCoord}{\code{SkyCoord}}
\begin{quote}
Source coordinate
\end{quote}
\textbf{ra\_digits} : int (\textgreater{}=2)
\begin{quote}
Number of digits for the Right Ascension part
\end{quote}
\textbf{dec\_digits} : int (\textgreater{}=2) or None
\begin{quote}
Number of digits for the declination part
Default is \code{dec\_digits} = None, meaning \code{dec\_digits} = \code{ra\_digits} - 1
\end{quote}
\textbf{prefix} : str
\begin{quote}
Prefix to put before the coordinate string, e.g. ``SDSS J''.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{strrepr} : str or list of strings
\begin{quote}
IAU format string representation of the coordinate.
If this input coordinate is an array, the output is a list of strings.
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{astropy.coordinates} \PYG{k+kn}{import} \PYG{n}{SkyCoord}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.catalog} \PYG{k+kn}{import} \PYG{n}{coordinate\PYGZus{}iau\PYGZus{}format}
\end{Verbatim}
Example position from IAU specification
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{coordinate} \PYG{o}{=} \PYG{n}{SkyCoord}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{00h51m09.38s \PYGZhy{}42d26m33.8s}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{frame}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{icrs}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{designation} \PYG{o}{=} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{QSO J}\PYG{l+s}{\PYGZsq{}} \PYG{o}{+} \PYG{n}{coordinate\PYGZus{}iau\PYGZus{}format}\PYG{p}{(}\PYG{n}{coordinate}\PYG{p}{,} \PYG{n}{ra\PYGZus{}digits}\PYG{o}{=}\PYG{l+m+mi}{6}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k}{print}\PYG{p}{(}\PYG{n}{designation}\PYG{p}{)}
\PYG{g+go}{QSO J005109\PYGZhy{}4226.5}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{coordinate} \PYG{o}{=} \PYG{n}{coordinate}\PYG{o}{.}\PYG{n}{transform\PYGZus{}to}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{fk4}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{designation} \PYG{o}{=} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{QSO B}\PYG{l+s}{\PYGZsq{}} \PYG{o}{+} \PYG{n}{coordinate\PYGZus{}iau\PYGZus{}format}\PYG{p}{(}\PYG{n}{coordinate}\PYG{p}{,} \PYG{n}{ra\PYGZus{}digits}\PYG{o}{=}\PYG{l+m+mi}{6}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k}{print}\PYG{p}{(}\PYG{n}{designation}\PYG{p}{)}
\PYG{g+go}{QSO B004848\PYGZhy{}4242.8}
\end{Verbatim}
Crab pulsar position (positive declination)
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{coordinate} \PYG{o}{=} \PYG{n}{SkyCoord}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{05h34m31.93830s +22d00m52.1758s}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{frame}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{icrs}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{designation} \PYG{o}{=} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{HESS J}\PYG{l+s}{\PYGZsq{}} \PYG{o}{+} \PYG{n}{coordinate\PYGZus{}iau\PYGZus{}format}\PYG{p}{(}\PYG{n}{coordinate}\PYG{p}{,} \PYG{n}{ra\PYGZus{}digits}\PYG{o}{=}\PYG{l+m+mi}{4}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k}{print}\PYG{p}{(}\PYG{n}{designation}\PYG{p}{)}
\PYG{g+go}{HESS J0534+220}
\end{Verbatim}
PKS 2155-304 AGN position (negative declination)
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{coordinate} \PYG{o}{=} \PYG{n}{SkyCoord}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{21h58m52.06511s \PYGZhy{}30d13m32.1182s}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{frame}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{icrs}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{designation} \PYG{o}{=} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{2FGL J}\PYG{l+s}{\PYGZsq{}} \PYG{o}{+} \PYG{n}{coordinate\PYGZus{}iau\PYGZus{}format}\PYG{p}{(}\PYG{n}{coordinate}\PYG{p}{,} \PYG{n}{ra\PYGZus{}digits}\PYG{o}{=}\PYG{l+m+mi}{5}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k}{print}\PYG{p}{(}\PYG{n}{designation}\PYG{p}{)}
\PYG{g+go}{2FGL J2158.8\PYGZhy{}3013}
\end{Verbatim}
Coordinate array inputs result in list of string output.
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{coordinates} \PYG{o}{=} \PYG{n}{SkyCoord}\PYG{p}{(}\PYG{n}{ra}\PYG{o}{=}\PYG{p}{[}\PYG{l+m+mf}{10.68458}\PYG{p}{,} \PYG{l+m+mf}{83.82208}\PYG{p}{]}\PYG{p}{,}
\PYG{g+gp}{... } \PYG{n}{dec}\PYG{o}{=}\PYG{p}{[}\PYG{l+m+mf}{41.26917}\PYG{p}{,} \PYG{o}{\PYGZhy{}}\PYG{l+m+mf}{5.39111}\PYG{p}{]}\PYG{p}{,}
\PYG{g+gp}{... } \PYG{n}{unit}\PYG{o}{=}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{deg}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{deg}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{,} \PYG{n}{frame}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{icrs}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{designations} \PYG{o}{=} \PYG{n}{coordinate\PYGZus{}iau\PYGZus{}format}\PYG{p}{(}\PYG{n}{coordinates}\PYG{p}{,} \PYG{n}{ra\PYGZus{}digits}\PYG{o}{=}\PYG{l+m+mi}{5}\PYG{p}{,} \PYG{n}{prefix}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{HESS J}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k}{print}\PYG{p}{(}\PYG{n}{designations}\PYG{p}{)}
\PYG{g+go}{[\PYGZsq{}HESS J0042.7+4116\PYGZsq{}, \PYGZsq{}HESS J0535.2\PYGZhy{}0523\PYGZsq{}]}
\end{Verbatim}
\end{fulllineitems}
\paragraph{dec\_iau\_format}
\label{api/gammapy.catalog.dec_iau_format:astropy}\label{api/gammapy.catalog.dec_iau_format::doc}\label{api/gammapy.catalog.dec_iau_format:dec-iau-format}\index{dec\_iau\_format() (in module gammapy.catalog)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.catalog.dec_iau_format:gammapy.catalog.dec_iau_format}\pysiglinewithargsret{\code{gammapy.catalog.}\bfcode{dec\_iau\_format}}{\emph{dec}, \emph{digits}}{}
Declination part of an IAU source designation.
Reference: \href{http://cdsweb.u-strasbg.fr/Dic/iau-spec.html}{http://cdsweb.u-strasbg.fr/Dic/iau-spec.html}
\begin{tabulary}{\linewidth}{|L|L|}
\hline
\textsf{\relax
digits
} & \textsf{\relax
format
}\\
\hline
2
&
+DD
\\
\hline
3
&
+DDd
\\
\hline
4
&
+DDMM
\\
\hline
5
&
+DDMM.m
\\
\hline
6
&
+DDMMSS
\\
\hline
7
&
+DDMMSS.s
\\
\hline\end{tabulary}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{dec} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Latitude.html\#astropy.coordinates.Latitude}{\code{Latitude}}
\begin{quote}
Declination
\end{quote}
\textbf{digits} : int (\textgreater{}=2)
\begin{quote}
Number of digits
\end{quote}
\item[{Returns}] \leavevmode
\textbf{strrepr} : str
\begin{quote}
IAU format string representation of the angle
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{get\_source\_by\_name}
\label{api/gammapy.catalog.get_source_by_name:get-source-by-name}\label{api/gammapy.catalog.get_source_by_name:astropy}\label{api/gammapy.catalog.get_source_by_name::doc}\index{get\_source\_by\_name() (in module gammapy.catalog)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.catalog.get_source_by_name:gammapy.catalog.get_source_by_name}\pysiglinewithargsret{\code{gammapy.catalog.}\bfcode{get\_source\_by\_name}}{\emph{source}, \emph{catalog}, \emph{id\_column='Source\_Name'}}{}
Get source catalog entry by source name.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{source} : string
\begin{quote}
Source name.
\end{quote}
\textbf{catalog} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Catalog table.
\end{quote}
\textbf{id\_column} : str (default = `Source\_Name')
\begin{quote}
Column name of the source names.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{source} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Row.html\#astropy.table.Row}{\code{Row}}
\begin{quote}
Entry for the given source.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{ra\_iau\_format}
\label{api/gammapy.catalog.ra_iau_format:ra-iau-format}\label{api/gammapy.catalog.ra_iau_format:astropy}\label{api/gammapy.catalog.ra_iau_format::doc}\index{ra\_iau\_format() (in module gammapy.catalog)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.catalog.ra_iau_format:gammapy.catalog.ra_iau_format}\pysiglinewithargsret{\code{gammapy.catalog.}\bfcode{ra\_iau\_format}}{\emph{ra}, \emph{digits}}{}
Right Ascension part of an IAU source designation.
Reference: \href{http://cdsweb.u-strasbg.fr/Dic/iau-spec.html}{http://cdsweb.u-strasbg.fr/Dic/iau-spec.html}
\begin{tabulary}{\linewidth}{|L|L|}
\hline
\textsf{\relax
digits
} & \textsf{\relax
format
}\\
\hline
2
&
HH
\\
\hline
3
&
HHh
\\
\hline
4
&
HHMM
\\
\hline
5
&
HHMM.m
\\
\hline
6
&
HHMMSS
\\
\hline
7
&
HHMMSS.s
\\
\hline\end{tabulary}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{ra} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Longitude.html\#astropy.coordinates.Longitude}{\code{Longitude}}
\begin{quote}
Right ascension
\end{quote}
\textbf{digits} : int (\textgreater{}=2)
\begin{quote}
Number of digits
\end{quote}
\item[{Returns}] \leavevmode
\textbf{strrepr} : str
\begin{quote}
IAU format string representation of the angle
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{select\_sky\_box}
\label{api/gammapy.catalog.select_sky_box:select-sky-box}\label{api/gammapy.catalog.select_sky_box:astropy}\label{api/gammapy.catalog.select_sky_box::doc}\index{select\_sky\_box() (in module gammapy.catalog)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.catalog.select_sky_box:gammapy.catalog.select_sky_box}\pysiglinewithargsret{\code{gammapy.catalog.}\bfcode{select\_sky\_box}}{\emph{table}, \emph{lon\_lim}, \emph{lat\_lim}, \emph{frame='icrs'}}{}
Select sky positions in a box.
This function can be applied e.g. to event lists of source catalogs.
Note: if useful we can add a function that returns the mask
or indices instead of applying the selection directly
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{table} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Table with sky coordinate columns
\end{quote}
\textbf{lon\_lim, lat\_lim} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
Box limits (each should be a min, max tuple)
\end{quote}
\textbf{frame} : str
\begin{quote}
Frame in which to apply the box cut.
Built-in Astropy coordinate frames are supported, e.g.
`icrs', `fk5' or `galactic'.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{table} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Copy of input table with box cut applied
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
TODO
\end{fulllineitems}
\paragraph{skycoord\_from\_table}
\label{api/gammapy.catalog.skycoord_from_table:skycoord-from-table}\label{api/gammapy.catalog.skycoord_from_table:astropy}\label{api/gammapy.catalog.skycoord_from_table::doc}\index{skycoord\_from\_table() (in module gammapy.catalog)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.catalog.skycoord_from_table:gammapy.catalog.skycoord_from_table}\pysiglinewithargsret{\code{gammapy.catalog.}\bfcode{skycoord\_from\_table}}{\emph{table}}{}
Make \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.SkyCoord.html\#astropy.coordinates.SkyCoord}{\code{SkyCoord}} from lon, lat columns in \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}.
This is a convenience function similar to \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.SkyCoord.html\#astropy.coordinates.SkyCoord.guess\_from\_table}{\code{guess\_from\_table}},
but with the column names we usually use.
TODO: I'm not sure if it's a good idea to use this because it's not always clear
which positions are taken.
\end{fulllineitems}
\paragraph{table\_xmatch}
\label{api/gammapy.catalog.table_xmatch:table-xmatch}\label{api/gammapy.catalog.table_xmatch:astropy}\label{api/gammapy.catalog.table_xmatch::doc}\index{table\_xmatch() (in module gammapy.catalog)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.catalog.table_xmatch:gammapy.catalog.table_xmatch}\pysiglinewithargsret{\code{gammapy.catalog.}\bfcode{table\_xmatch}}{\emph{table1}, \emph{table2}, \emph{xmatch\_criterion}, \emph{return\_indices=True}}{}
Cross-match rows from two tables with a cross-match criterion callback.
Note: This is a very flexible and simple way to find matching
rows from two tables, but it can be very slow, e.g. if you
create \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.SkyCoord.html\#astropy.coordinates.SkyCoord}{\code{SkyCoord}} objects or index into them
in the callback cross-match criterion function:
\href{https://github.com/astropy/astropy/issues/3323\#issuecomment-71657245}{https://github.com/astropy/astropy/issues/3323\#issuecomment-71657245}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{table1, table2} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Input tables
\end{quote}
\textbf{xmatch\_criterion} : callable
\begin{quote}
Callable that takes two \href{http://docs.astropy.org/en/latest/api/astropy.table.Row.html\#astropy.table.Row}{\code{Row}} objects as input
and returns \href{http://docs.python.org/library/constants.html\#True}{\code{True}} / \href{http://docs.python.org/library/constants.html\#False}{\code{False}} when they match / don't match.
\end{quote}
\textbf{return\_indices} : bool
\begin{quote}
If \href{http://docs.python.org/library/constants.html\#True}{\code{True}} this function returns a Table with match indices
\code{idx1} and \code{idx2}, if \href{http://docs.python.org/library/constants.html\#False}{\code{False}} it stacks the matches in a table using
\href{http://docs.astropy.org/en/latest/api/astropy.table.hstack.html\#astropy.table.hstack}{\code{hstack}}.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{matches} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Match table (one match per row)
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{table\_xmatch\_circle\_criterion}
\label{api/gammapy.catalog.table_xmatch_circle_criterion:table-xmatch-circle-criterion}\label{api/gammapy.catalog.table_xmatch_circle_criterion:astropy}\label{api/gammapy.catalog.table_xmatch_circle_criterion::doc}\index{table\_xmatch\_circle\_criterion() (in module gammapy.catalog)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.catalog.table_xmatch_circle_criterion:gammapy.catalog.table_xmatch_circle_criterion}\pysiglinewithargsret{\code{gammapy.catalog.}\bfcode{table\_xmatch\_circle\_criterion}}{\emph{max\_separation}}{}
An example cross-match criterion for {\hyperref[api/gammapy.catalog.table_xmatch:gammapy.catalog.table_xmatch]{\emph{\code{table\_xmatch}}}} that reproduces {\hyperref[api/gammapy.catalog.catalog_xmatch_circle:gammapy.catalog.catalog_xmatch_circle]{\emph{\code{catalog\_xmatch\_circle}}}}.
TODO: finish implementing this and test it.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{max\_separation} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
Maximum separation
\end{quote}
\item[{Returns}] \leavevmode
\textbf{xmatch} : function
\begin{quote}
Cross-match function to be passed to {\hyperref[api/gammapy.catalog.table_xmatch:gammapy.catalog.table_xmatch]{\emph{\code{table\_xmatch}}}}.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{to\_ds9\_region}
\label{api/gammapy.catalog.to_ds9_region:astropy}\label{api/gammapy.catalog.to_ds9_region::doc}\label{api/gammapy.catalog.to_ds9_region:to-ds9-region}\index{to\_ds9\_region() (in module gammapy.catalog)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.catalog.to_ds9_region:gammapy.catalog.to_ds9_region}\pysiglinewithargsret{\code{gammapy.catalog.}\bfcode{to\_ds9\_region}}{\emph{catalog}, \emph{radius=None}, \emph{color='green'}, \emph{glon='GLON'}, \emph{unc\_glon=None}, \emph{glat='GLAT'}, \emph{unc\_glat=None}, \emph{label=None}, \emph{label\_position='top'}, \emph{label\_additional\_info=None}, \emph{label\_distance=1.2}, \emph{marker='diamond'}, \emph{dashed=False}, \emph{width=3}}{}
Write ds9 region file from catalog.
Currently works only for galactic coordinates.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{catalog} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Catalog with position and size information.
\end{quote}
\textbf{glon} : str (`GLON')
\begin{quote}
Catalog column containing galactic longitude position.
\end{quote}
\textbf{glat} : str (`GLAT')
\begin{quote}
Catalog column containing galactic latitude position.
\end{quote}
\textbf{unc\_glon} : str (None)
\begin{quote}
Catalog column containing galactic longitude position uncertainty.
\end{quote}
\textbf{unc\_glat} : str (None)
\begin{quote}
Catalog column containing galactic latitude position uncertainty.
\end{quote}
\textbf{radius} : str (None)
\begin{quote}
Catalog column containing extension information.
\end{quote}
\textbf{color} : str (`green')
\begin{quote}
Valid ds9 color.
\end{quote}
\textbf{label} : str (None)
\begin{quote}
Catalog column to use for the label.
\end{quote}
\textbf{label\_position: str (`top')}
\begin{quote}
Position of the region label. Either `top' or `bottom'.
\end{quote}
\textbf{label\_distance: float (1.2)}
\begin{quote}
Distance of the label from the regions center. Given
in multiple of the region's radius.
\end{quote}
\textbf{label\_additional\_info: dict}
\begin{quote}
Additional info to be shown in the region label.
\end{quote}
\textbf{dashed} : bool (False)
\begin{quote}
Dashed region line.
\end{quote}
\textbf{width} : int
\begin{quote}
Width of the region line.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{region} : str
\begin{quote}
DS9 region string.
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
This example reads Greens catalog from {\hyperref[datasets/index:module-gammapy.datasets]{\emph{\code{gammapy.datasets}}}} and writes it to a
ds9 region file.
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.datasets} \PYG{k+kn}{import} \PYG{n}{load\PYGZus{}catalog\PYGZus{}green}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{green} \PYG{o}{=} \PYG{n}{load\PYGZus{}catalog\PYGZus{}green}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{green}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{MeanDiam}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]} \PYG{o}{/}\PYG{o}{=} \PYG{l+m+mf}{120.}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{green\PYGZus{}str} \PYG{o}{=} \PYG{n}{to\PYGZus{}ds9\PYGZus{}region}\PYG{p}{(}\PYG{n}{green}\PYG{p}{,} \PYG{n}{radius}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{MeanDiam}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} } \PYG{n}{label}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Source\PYGZus{}Name}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{color}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{red}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k}{with} \PYG{n+nb}{open}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}}\PYG{l+s}{region\PYGZus{}green.reg}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,} \PYG{l+s}{\PYGZdq{}}\PYG{l+s}{w}\PYG{l+s}{\PYGZdq{}}\PYG{p}{)} \PYG{k}{as} \PYG{n}{region\PYGZus{}file}\PYG{p}{:}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} } \PYG{n}{region\PYGZus{}file}\PYG{o}{.}\PYG{n}{write}\PYG{p}{(}\PYG{n}{green\PYGZus{}str}\PYG{p}{)}
\end{Verbatim}
\end{fulllineitems}
\subsubsection{Classes}
\label{catalog/index:astropy}\label{catalog/index:classes}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.catalog.FluxDistribution:gammapy.catalog.FluxDistribution]{\emph{\code{FluxDistribution}}}}(table, label)
&
Catalog flux distribution analysis and plotting.
\\
\hline\end{longtable}
\paragraph{FluxDistribution}
\label{api/gammapy.catalog.FluxDistribution:fluxdistribution}\label{api/gammapy.catalog.FluxDistribution::doc}\index{FluxDistribution (class in gammapy.catalog)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.catalog.FluxDistribution:gammapy.catalog.FluxDistribution}\pysiglinewithargsret{\strong{class }\code{gammapy.catalog.}\bfcode{FluxDistribution}}{\emph{table}, \emph{label}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Catalog flux distribution analysis and plotting.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{table} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Input catalog. Must contain the following columns:
\begin{itemize}
\item {}
Source flux column called `S'
\item {}
Source extension column called `r'
\end{itemize}
\end{quote}
\end{description}\end{quote}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{fit\_power\_law() (gammapy.catalog.FluxDistribution method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.catalog.FluxDistribution:gammapy.catalog.FluxDistribution.fit_power_law}\pysiglinewithargsret{\bfcode{fit\_power\_law}}{\emph{S\_min}, \emph{S\_max}}{}
\end{fulllineitems}
\index{plot\_differential\_count() (gammapy.catalog.FluxDistribution method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.catalog.FluxDistribution:gammapy.catalog.FluxDistribution.plot_differential_count}\pysiglinewithargsret{\bfcode{plot\_differential\_count}}{}{}
\end{fulllineitems}
\index{plot\_differential\_flux() (gammapy.catalog.FluxDistribution method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.catalog.FluxDistribution:gammapy.catalog.FluxDistribution.plot_differential_flux}\pysiglinewithargsret{\bfcode{plot\_differential\_flux}}{}{}
\end{fulllineitems}
\index{plot\_integral\_count() (gammapy.catalog.FluxDistribution method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.catalog.FluxDistribution:gammapy.catalog.FluxDistribution.plot_integral_count}\pysiglinewithargsret{\bfcode{plot\_integral\_count}}{}{}
\end{fulllineitems}
\index{plot\_integral\_flux() (gammapy.catalog.FluxDistribution method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.catalog.FluxDistribution:gammapy.catalog.FluxDistribution.plot_integral_flux}\pysiglinewithargsret{\bfcode{plot\_integral\_flux}}{}{}
\end{fulllineitems}
\index{print\_info() (gammapy.catalog.FluxDistribution method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.catalog.FluxDistribution:gammapy.catalog.FluxDistribution.print_info}\pysiglinewithargsret{\bfcode{print\_info}}{}{}
\end{fulllineitems}
\end{fulllineitems}
\chapter{Data classes (\texttt{gammapy.data})}
\label{data/index:data-classes-gammapy-data}\label{data/index:data}\label{data/index:astropy}\label{data/index::doc}
\section{Introduction}
\label{data/index:introduction}
{\hyperref[data/index:module-gammapy.data]{\emph{\code{gammapy.data}}}} contains classes to represent gamma-ray data.
We follow the Fermi data model and FITS formats as much as possible.
The data format used is FITS and we define one container class to represent
each FITS extension. In addition we define two high-level dataset classes
that group all info data and metadata that's usually given for a single
observation together:
\begin{itemize}
\item {}
Unbinned data is represented by a {\hyperref[api/gammapy.data.EventListDataset:gammapy.data.EventListDataset]{\emph{\code{EventListDataset}}}}, which contains:
\begin{itemize}
\item {}
{\hyperref[api/gammapy.data.EventList:gammapy.data.EventList]{\emph{\code{EventList}}}} - table with time, position and energy for each event
\item {}
{\hyperref[api/gammapy.data.GoodTimeIntervals:gammapy.data.GoodTimeIntervals]{\emph{\code{GoodTimeIntervals}}}} - table of good time intervals.
Used for livetime and exposure computation.
\item {}
{\hyperref[api/gammapy.data.TelescopeArray:gammapy.data.TelescopeArray]{\emph{\code{TelescopeArray}}}} - some info about the array that took the data.
Optional, not used at the moment.
\end{itemize}
\item {}
For most analysis the first step is to bin the data, which turns the
{\hyperref[api/gammapy.data.EventListDataset:gammapy.data.EventListDataset]{\emph{\code{EventListDataset}}}} into one of:
\begin{itemize}
\item {}
{\hyperref[api/gammapy.data.CountsCubeDataset:gammapy.data.CountsCubeDataset]{\emph{\code{CountsCubeDataset}}}} (lon, lat, energy)
\item {}
{\hyperref[api/gammapy.data.CountsSpectrumDataset:gammapy.data.CountsSpectrumDataset]{\emph{\code{CountsSpectrumDataset}}}} (energy)
\item {}
{\hyperref[api/gammapy.data.CountsImageDataset:gammapy.data.CountsImageDataset]{\emph{\code{CountsImageDataset}}}} (lon, lat)
\item {}
{\hyperref[api/gammapy.data.CountsLightCurveDataset:gammapy.data.CountsLightCurveDataset]{\emph{\code{CountsLightCurveDataset}}}} (time)
\end{itemize}
\item {}
TODO: add IRFs to the dataset classes?
\item {}
TODO: do we need the \code{*Dataset} wrappers or can we only have
\code{EventList}, \code{CountsCube}, \code{CountsSpectrum}, \code{CountsImage}, ...?
\item {}
We'll have to see if we want to copy the IRF and / or GTI and / or TelescopeArray info
over to the binned dataset classes ... at the moment it's not clear if we need that info.
\end{itemize}
\subsection{Energy binning}
\label{data/index:energy-binning}\begin{itemize}
\item {}
{\hyperref[api/gammapy.spectrum.EnergyBinCenters:gammapy.spectrum.EnergyBinCenters]{\emph{\code{EnergyBinCenters}}}} and FITS ``ENERGIES'' extensions.
\item {}
{\hyperref[api/gammapy.spectrum.EnergyBinEdges:gammapy.spectrum.EnergyBinEdges]{\emph{\code{EnergyBinEdges}}}} and FITS ``EBOUNDS'' extensions.
\end{itemize}
\subsection{Spatial binning}
\label{data/index:spatial-binning}
TODO: Should we define a ``SpatialGrid'' or ``SpatialBinning'' class that wraps
the 2d image FITS WCS and add convenience methods like generating them from scratch
e.g. centered on the target or aligned to a survey map grid?
\section{Getting Started}
\label{data/index:getting-started}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.data} \PYG{k+kn}{import} \PYG{n}{EventListDataset}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{events\PYGZus{}ds} \PYG{o}{=} \PYG{n}{EventListDataset}\PYG{o}{.}\PYG{n}{read}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{events.fits}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{events\PYGZus{}ds}\PYG{o}{.}\PYG{n}{info}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.data} \PYG{k+kn}{import} \PYG{n}{CountsCubeDataset}
\PYG{g+go}{\PYGZsh{} This is just an idea ... not implemented!}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{counts\PYGZus{}ds} \PYG{o}{=} \PYG{n}{CountsCubeDataset}\PYG{o}{.}\PYG{n}{from\PYGZus{}events}\PYG{p}{(}\PYG{n}{events\PYGZus{}ds}\PYG{p}{,} \PYG{o}{.}\PYG{o}{.}\PYG{o}{.}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{counts\PYGZus{}ds} \PYG{o}{=} \PYG{n}{events\PYGZus{}ds}\PYG{o}{.}\PYG{n}{make\PYGZus{}counts\PYGZus{}cube}\PYG{p}{(}\PYG{o}{.}\PYG{o}{.}\PYG{o}{.}\PYG{p}{)}
\end{Verbatim}
\section{Reference/API}
\label{data/index:reference-api}
\subsection{gammapy.data Package}
\label{data/index:gammapy-data-package}\label{data/index:module-gammapy.data}\index{gammapy.data (module)}
Data classes.
\subsubsection{Functions}
\label{data/index:functions}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.data.compute_npred_cube:gammapy.data.compute_npred_cube]{\emph{\code{compute\_npred\_cube}}}}(flux\_cube, exposure\_cube, ...)
&
Computes predicted counts cube in energy bins.
\\
\hline
{\hyperref[api/gammapy.data.convolve_cube:gammapy.data.convolve_cube]{\emph{\code{convolve\_cube}}}}(cube, psf, offset\_max)
&
Convolves a predicted counts cube in energy bins with the an energy-dependent PSF.
\\
\hline
{\hyperref[api/gammapy.data.event_lists_to_counts_image:gammapy.data.event_lists_to_counts_image]{\emph{\code{event\_lists\_to\_counts\_image}}}}(header, ...{[}, ...{]})
&
Make count image from event lists (like gtbin).
\\
\hline\end{longtable}
\paragraph{compute\_npred\_cube}
\label{api/gammapy.data.compute_npred_cube:compute-npred-cube}\label{api/gammapy.data.compute_npred_cube::doc}\index{compute\_npred\_cube() (in module gammapy.data)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.compute_npred_cube:gammapy.data.compute_npred_cube}\pysiglinewithargsret{\code{gammapy.data.}\bfcode{compute\_npred\_cube}}{\emph{flux\_cube}, \emph{exposure\_cube}, \emph{energy\_bins}, \emph{integral\_resolution=10}}{}
Computes predicted counts cube in energy bins.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{flux\_cube} : {\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube]{\emph{\code{SpectralCube}}}}
\begin{quote}
Differential flux cube.
\end{quote}
\textbf{exposure\_cube} : {\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube]{\emph{\code{SpectralCube}}}}
\begin{quote}
Instrument exposure cube.
\end{quote}
\textbf{energy\_bins} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
An array of Quantities specifying the edges of the energy band
required for the predicted counts cube.
\end{quote}
\textbf{integral\_resolution} : int (optional)
\begin{quote}
Number of integration steps in energy bin when computing integral flux.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{npred\_cube} : {\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube]{\emph{\code{SpectralCube}}}}
\begin{quote}
Predicted counts cube in energy bins.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{convolve\_cube}
\label{api/gammapy.data.convolve_cube:astropy}\label{api/gammapy.data.convolve_cube::doc}\label{api/gammapy.data.convolve_cube:convolve-cube}\index{convolve\_cube() (in module gammapy.data)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.convolve_cube:gammapy.data.convolve_cube}\pysiglinewithargsret{\code{gammapy.data.}\bfcode{convolve\_cube}}{\emph{cube}, \emph{psf}, \emph{offset\_max}}{}
Convolves a predicted counts cube in energy bins with the an
energy-dependent PSF.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{cube} : {\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube]{\emph{\code{SpectralCube}}}}
\begin{quote}
Counts cube in energy bins.
\end{quote}
\textbf{psf} : {\hyperref[api/gammapy.irf.EnergyDependentTablePSF:gammapy.irf.EnergyDependentTablePSF]{\emph{\code{EnergyDependentTablePSF}}}}
\begin{quote}
Energy dependent PSF.
\end{quote}
\textbf{offset\_max} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Maximum offset in degrees of the PSF convolution kernel from its center.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{convolved\_cube} : {\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube]{\emph{\code{SpectralCube}}}}
\begin{quote}
PSF convolved predicted counts cube in energy bins.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{event\_lists\_to\_counts\_image}
\label{api/gammapy.data.event_lists_to_counts_image:event-lists-to-counts-image}\label{api/gammapy.data.event_lists_to_counts_image:astropy}\label{api/gammapy.data.event_lists_to_counts_image::doc}\index{event\_lists\_to\_counts\_image() (in module gammapy.data)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.event_lists_to_counts_image:gammapy.data.event_lists_to_counts_image}\pysiglinewithargsret{\code{gammapy.data.}\bfcode{event\_lists\_to\_counts\_image}}{\emph{header}, \emph{table\_of\_files}, \emph{logger=None}}{}
Make count image from event lists (like gtbin).
TODO: what's a good API and location for this?
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{header} : \href{http://docs.astropy.org/en/latest/io/fits/api/headers.html\#astropy.io.fits.Header}{\code{Header}}
\begin{quote}
FITS header
\end{quote}
\textbf{table\_of\_files} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Table of event list filenames
\end{quote}
\textbf{logger} : \href{http://docs.python.org/library/logging.html\#logging.Logger}{\code{logging.Logger}} or None
\begin{quote}
Logger to use
\end{quote}
\item[{Returns}] \leavevmode
\textbf{image} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
Count image
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\subsubsection{Classes}
\label{data/index:astropy}\label{data/index:classes}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.data.CountsCubeDataset:gammapy.data.CountsCubeDataset]{\emph{\code{CountsCubeDataset}}}}
&
Counts cube dataset.
\\
\hline
{\hyperref[api/gammapy.data.CountsImageDataset:gammapy.data.CountsImageDataset]{\emph{\code{CountsImageDataset}}}}
&
Counts image dataset.
\\
\hline
{\hyperref[api/gammapy.data.CountsLightCurveDataset:gammapy.data.CountsLightCurveDataset]{\emph{\code{CountsLightCurveDataset}}}}
&
Counts light-curve dataset.
\\
\hline
{\hyperref[api/gammapy.data.CountsSpectrumDataset:gammapy.data.CountsSpectrumDataset]{\emph{\code{CountsSpectrumDataset}}}}
&
Counts spectrum dataset.
\\
\hline
{\hyperref[api/gammapy.data.EventList:gammapy.data.EventList]{\emph{\code{EventList}}}}({[}data, masked, names, dtype, ...{]})
&
Event list \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}.
\\
\hline
{\hyperref[api/gammapy.data.EventListDataset:gammapy.data.EventListDataset]{\emph{\code{EventListDataset}}}}(event\_list{[}, ...{]})
&
Event list dataset (event list plus some extra info).
\\
\hline
{\hyperref[api/gammapy.data.EventListDatasetChecker:gammapy.data.EventListDatasetChecker]{\emph{\code{EventListDatasetChecker}}}}(event\_list\_dataset)
&
Event list dataset checker.
\\
\hline
{\hyperref[api/gammapy.data.GoodTimeIntervals:gammapy.data.GoodTimeIntervals]{\emph{\code{GoodTimeIntervals}}}}(*args, **kwargs)
&
Good time intervals (GTI) \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}.
\\
\hline
{\hyperref[api/gammapy.data.InvalidDataError:gammapy.data.InvalidDataError]{\emph{\code{InvalidDataError}}}}
&
Invalid data found.
\\
\hline
{\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube]{\emph{\code{SpectralCube}}}}(data, wcs, energy)
&
Spectral cube for gamma-ray astronomy.
\\
\hline
{\hyperref[api/gammapy.data.TelescopeArray:gammapy.data.TelescopeArray]{\emph{\code{TelescopeArray}}}}({[}data, masked, names, dtype, ...{]})
&
Telescope array info.
\\
\hline\end{longtable}
\paragraph{CountsCubeDataset}
\label{api/gammapy.data.CountsCubeDataset::doc}\label{api/gammapy.data.CountsCubeDataset:countscubedataset}\index{CountsCubeDataset (class in gammapy.data)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.CountsCubeDataset:gammapy.data.CountsCubeDataset}\pysigline{\strong{class }\code{gammapy.data.}\bfcode{CountsCubeDataset}}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Counts cube dataset.
\end{fulllineitems}
\paragraph{CountsImageDataset}
\label{api/gammapy.data.CountsImageDataset:astropy}\label{api/gammapy.data.CountsImageDataset::doc}\label{api/gammapy.data.CountsImageDataset:countsimagedataset}\index{CountsImageDataset (class in gammapy.data)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.CountsImageDataset:gammapy.data.CountsImageDataset}\pysigline{\strong{class }\code{gammapy.data.}\bfcode{CountsImageDataset}}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Counts image dataset.
\end{fulllineitems}
\paragraph{CountsLightCurveDataset}
\label{api/gammapy.data.CountsLightCurveDataset:countslightcurvedataset}\label{api/gammapy.data.CountsLightCurveDataset:astropy}\label{api/gammapy.data.CountsLightCurveDataset::doc}\index{CountsLightCurveDataset (class in gammapy.data)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.CountsLightCurveDataset:gammapy.data.CountsLightCurveDataset}\pysigline{\strong{class }\code{gammapy.data.}\bfcode{CountsLightCurveDataset}}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Counts light-curve dataset.
\end{fulllineitems}
\paragraph{CountsSpectrumDataset}
\label{api/gammapy.data.CountsSpectrumDataset:astropy}\label{api/gammapy.data.CountsSpectrumDataset::doc}\label{api/gammapy.data.CountsSpectrumDataset:countsspectrumdataset}\index{CountsSpectrumDataset (class in gammapy.data)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.CountsSpectrumDataset:gammapy.data.CountsSpectrumDataset}\pysigline{\strong{class }\code{gammapy.data.}\bfcode{CountsSpectrumDataset}}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Counts spectrum dataset.
\end{fulllineitems}
\paragraph{EventList}
\label{api/gammapy.data.EventList:eventlist}\label{api/gammapy.data.EventList:astropy}\label{api/gammapy.data.EventList::doc}\index{EventList (class in gammapy.data)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventList:gammapy.data.EventList}\pysiglinewithargsret{\strong{class }\code{gammapy.data.}\bfcode{EventList}}{\emph{data=None}, \emph{masked=None}, \emph{names=None}, \emph{dtype=None}, \emph{meta=None}, \emph{copy=True}, \emph{rows=None}}{}
Bases: \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{astropy.table.Table}}
Event list \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}.
The most important reconstructed event parameters
are available as the following columns:
\begin{itemize}
\item {}
\code{TIME} - Mission elapsed time (sec)
\item {}
\code{RA}, \code{DEC} - FK5 J2000 (or ICRS?) position (deg)
\item {}
\code{ENERGY} - Energy (usually MeV for Fermi and TeV for IACTs)
\end{itemize}
Other optional (columns) that are sometimes useful for high-level analysis:
\begin{itemize}
\item {}
\code{GLON}, \code{GLAT} - Galactic coordinates (deg)
\item {}
\code{DETX}, \code{DETY} - Field of view coordinates (radian?)
\end{itemize}
Note that when reading data for analysis you shouldn't use those
values directly, but access them via properties which create objects
of the appropriate class:
\begin{itemize}
\item {}
{\hyperref[api/gammapy.data.EventList:gammapy.data.EventList.time]{\emph{\code{time}}}} for \code{TIME}
\item {}
{\hyperref[api/gammapy.data.EventList:gammapy.data.EventList.radec]{\emph{\code{radec}}}} for \code{RA}, \code{DEC}
\item {}
{\hyperref[api/gammapy.data.EventList:gammapy.data.EventList.energy]{\emph{\code{energy}}}} for \code{ENERGY}
\item {}
{\hyperref[api/gammapy.data.EventList:gammapy.data.EventList.galactic]{\emph{\code{galactic}}}} for \code{GLON}, \code{GLAT}
\end{itemize}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.data.EventList:gammapy.data.EventList.altaz]{\emph{\code{altaz}}}}
&
Event horizontal sky coordinates (\href{http://docs.astropy.org/en/latest/api/astropy.coordinates.SkyCoord.html\#astropy.coordinates.SkyCoord}{\code{SkyCoord}})
\\
\hline
{\hyperref[api/gammapy.data.EventList:gammapy.data.EventList.energy]{\emph{\code{energy}}}}
&
Event energies (\href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}).
\\
\hline
{\hyperref[api/gammapy.data.EventList:gammapy.data.EventList.galactic]{\emph{\code{galactic}}}}
&
Event Galactic sky coordinates (\href{http://docs.astropy.org/en/latest/api/astropy.coordinates.SkyCoord.html\#astropy.coordinates.SkyCoord}{\code{SkyCoord}}).
\\
\hline
{\hyperref[api/gammapy.data.EventList:gammapy.data.EventList.info]{\emph{\code{info}}}}
&
Summary info string.
\\
\hline
{\hyperref[api/gammapy.data.EventList:gammapy.data.EventList.observation_dead_time_fraction]{\emph{\code{observation\_dead\_time\_fraction}}}}
&
Dead-time fraction.
\\
\hline
{\hyperref[api/gammapy.data.EventList:gammapy.data.EventList.observation_live_time_duration]{\emph{\code{observation\_live\_time\_duration}}}}
&
Live-time duration in seconds (\href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}).
\\
\hline
{\hyperref[api/gammapy.data.EventList:gammapy.data.EventList.observation_time_duration]{\emph{\code{observation\_time\_duration}}}}
&
Observation time duration in seconds (\href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}).
\\
\hline
{\hyperref[api/gammapy.data.EventList:gammapy.data.EventList.observatory_earth_location]{\emph{\code{observatory\_earth\_location}}}}
&
Observatory location (\href{http://docs.astropy.org/en/latest/api/astropy.coordinates.EarthLocation.html\#astropy.coordinates.EarthLocation}{\code{EarthLocation}})
\\
\hline
{\hyperref[api/gammapy.data.EventList:gammapy.data.EventList.radec]{\emph{\code{radec}}}}
&
Event RA / DEC sky coordinates (\href{http://docs.astropy.org/en/latest/api/astropy.coordinates.SkyCoord.html\#astropy.coordinates.SkyCoord}{\code{SkyCoord}})
\\
\hline
{\hyperref[api/gammapy.data.EventList:gammapy.data.EventList.time]{\emph{\code{time}}}}
&
Event times (\href{http://docs.astropy.org/en/latest/api/astropy.time.Time.html\#astropy.time.Time}{\code{Time}}).
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{altaz (gammapy.data.EventList attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventList:gammapy.data.EventList.altaz}\pysigline{\bfcode{altaz}}
Event horizontal sky coordinates (\href{http://docs.astropy.org/en/latest/api/astropy.coordinates.SkyCoord.html\#astropy.coordinates.SkyCoord}{\code{SkyCoord}})
\end{fulllineitems}
\index{energy (gammapy.data.EventList attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventList:gammapy.data.EventList.energy}\pysigline{\bfcode{energy}}
Event energies (\href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}).
\end{fulllineitems}
\index{galactic (gammapy.data.EventList attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventList:gammapy.data.EventList.galactic}\pysigline{\bfcode{galactic}}
Event Galactic sky coordinates (\href{http://docs.astropy.org/en/latest/api/astropy.coordinates.SkyCoord.html\#astropy.coordinates.SkyCoord}{\code{SkyCoord}}).
Note: uses the \code{GLON} and \code{GLAT} columns.
If only \code{RA} and \code{DEC} are present use the explicit
\code{event\_list.radec.to('galactic')} instead.
\end{fulllineitems}
\index{info (gammapy.data.EventList attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventList:gammapy.data.EventList.info}\pysigline{\bfcode{info}}
Summary info string.
\end{fulllineitems}
\index{observation\_dead\_time\_fraction (gammapy.data.EventList attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventList:gammapy.data.EventList.observation_dead_time_fraction}\pysigline{\bfcode{observation\_dead\_time\_fraction}}
Dead-time fraction.
Defined as dead-time over observation time.
Dead-time is defined as the time during the observation
where the detector didn't record events:
\href{http://en.wikipedia.org/wiki/Dead\_time}{http://en.wikipedia.org/wiki/Dead\_time}
\href{http://adsabs.harvard.edu/abs/2004APh....22..285F}{http://adsabs.harvard.edu/abs/2004APh....22..285F}
The dead-time fraction is used in the live-time computation,
which in turn is used in the exposure and flux computation.
\end{fulllineitems}
\index{observation\_live\_time\_duration (gammapy.data.EventList attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventList:gammapy.data.EventList.observation_live_time_duration}\pysigline{\bfcode{observation\_live\_time\_duration}}
Live-time duration in seconds (\href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}).
The dead-time-corrected observation time.
Computed as \code{t\_live = t\_observation * (1 - f\_dead)}
where \code{f\_dead} is the dead-time fraction.
\end{fulllineitems}
\index{observation\_time\_duration (gammapy.data.EventList attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventList:gammapy.data.EventList.observation_time_duration}\pysigline{\bfcode{observation\_time\_duration}}
Observation time duration in seconds (\href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}).
The wall time, including dead-time.
\end{fulllineitems}
\index{observatory\_earth\_location (gammapy.data.EventList attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventList:gammapy.data.EventList.observatory_earth_location}\pysigline{\bfcode{observatory\_earth\_location}}
Observatory location (\href{http://docs.astropy.org/en/latest/api/astropy.coordinates.EarthLocation.html\#astropy.coordinates.EarthLocation}{\code{EarthLocation}})
\end{fulllineitems}
\index{radec (gammapy.data.EventList attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventList:gammapy.data.EventList.radec}\pysigline{\bfcode{radec}}
Event RA / DEC sky coordinates (\href{http://docs.astropy.org/en/latest/api/astropy.coordinates.SkyCoord.html\#astropy.coordinates.SkyCoord}{\code{SkyCoord}})
TODO: the {\hyperref[api/gammapy.data.EventList:gammapy.data.EventList.radec]{\emph{\code{radec}}}} and {\hyperref[api/gammapy.data.EventList:gammapy.data.EventList.galactic]{\emph{\code{galactic}}}} properties should be cached as table columns
\end{fulllineitems}
\index{time (gammapy.data.EventList attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventList:gammapy.data.EventList.time}\pysigline{\bfcode{time}}
Event times (\href{http://docs.astropy.org/en/latest/api/astropy.time.Time.html\#astropy.time.Time}{\code{Time}}).
\paragraph{Notes}
Times are automatically converted to 64-bit floats.
With 32-bit floats times will be incorrect by a few seconds
when e.g. adding them to the reference time.
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{add\_galactic\_columns() (gammapy.data.EventList method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventList:gammapy.data.EventList.add_galactic_columns}\pysiglinewithargsret{\bfcode{add\_galactic\_columns}}{}{}
Add Galactic coordinate columns to the table.
Adds the following columns to the table if not already present:
- ``GLON'' - Galactic longitude (deg)
- ``GLAT'' - Galactic latitude (deg)
\end{fulllineitems}
\index{fill\_counts\_header() (gammapy.data.EventList method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventList:gammapy.data.EventList.fill_counts_header}\pysiglinewithargsret{\bfcode{fill\_counts\_header}}{\emph{header}}{}
Fill events in counts image specified by a FITS header.
TODO: document. Is this a good API?
\strong{See also:}
{\hyperref[api/gammapy.data.EventList:gammapy.data.EventList.fill_counts_image]{\emph{\code{EventList.fill\_counts\_image}}}}
\end{fulllineitems}
\index{fill\_counts\_image() (gammapy.data.EventList method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventList:gammapy.data.EventList.fill_counts_image}\pysiglinewithargsret{\bfcode{fill\_counts\_image}}{\emph{image}}{}
Fill events in counts image.
TODO: what's a good API here to support ImageHDU and Header as input?
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{image} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
Image HDU
\end{quote}
\item[{Returns}] \leavevmode
\textbf{image} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
Input image with changed data (event count added)
\end{quote}
\end{description}\end{quote}
\strong{See also:}
{\hyperref[api/gammapy.data.EventList:gammapy.data.EventList.fill_counts_header]{\emph{\code{EventList.fill\_counts\_header}}}}
\end{fulllineitems}
\index{select\_energy() (gammapy.data.EventList method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventList:gammapy.data.EventList.select_energy}\pysiglinewithargsret{\bfcode{select\_energy}}{\emph{energy\_band}}{}
Select events in energy band.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energy\_band} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Energy band \code{{[}energy\_min, energy\_max)}
\end{quote}
\item[{Returns}] \leavevmode
\textbf{event\_list} : {\hyperref[api/gammapy.data.EventList:gammapy.data.EventList]{\emph{\code{EventList}}}}
\begin{quote}
Copy of event list with selection applied.
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{astropy.units} \PYG{k+kn}{import} \PYG{n}{Quantity}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.data} \PYG{k+kn}{import} \PYG{n}{EventList}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{event\PYGZus{}list} \PYG{o}{=} \PYG{n}{EventList}\PYG{o}{.}\PYG{n}{read}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{events.fits}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{energy\PYGZus{}band} \PYG{o}{=} \PYG{n}{Quantity}\PYG{p}{(}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{l+m+mi}{20}\PYG{p}{]}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{TeV}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{event\PYGZus{}list} \PYG{o}{=} \PYG{n}{event\PYGZus{}list}\PYG{o}{.}\PYG{n}{select\PYGZus{}energy}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}
\end{fulllineitems}
\index{select\_sky\_box() (gammapy.data.EventList method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventList:gammapy.data.EventList.select_sky_box}\pysiglinewithargsret{\bfcode{select\_sky\_box}}{\emph{lon\_lim}, \emph{lat\_lim}, \emph{frame='icrs'}}{}
Select events in sky box.
TODO: move {\hyperref[api/gammapy.catalog.select_sky_box:gammapy.catalog.select_sky_box]{\emph{\code{gammapy.catalog.select\_sky\_box}}}} to \code{gammapy.utils}.
\end{fulllineitems}
\index{select\_sky\_cone() (gammapy.data.EventList method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventList:gammapy.data.EventList.select_sky_cone}\pysiglinewithargsret{\bfcode{select\_sky\_cone}}{\emph{center}, \emph{radius}}{}
Select events in sky circle.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{center} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.SkyCoord.html\#astropy.coordinates.SkyCoord}{\code{SkyCoord}}
\begin{quote}
Sky circle center
\end{quote}
\textbf{radius} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
Sky circle radius
\end{quote}
\item[{Returns}] \leavevmode
\textbf{event\_list} : {\hyperref[api/gammapy.data.EventList:gammapy.data.EventList]{\emph{\code{EventList}}}}
\begin{quote}
Copy of event list with selection applied.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{select\_time() (gammapy.data.EventList method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventList:gammapy.data.EventList.select_time}\pysiglinewithargsret{\bfcode{select\_time}}{\emph{time\_interval}}{}
Select events in interval.
\end{fulllineitems}
\end{fulllineitems}
\paragraph{EventListDataset}
\label{api/gammapy.data.EventListDataset:eventlistdataset}\label{api/gammapy.data.EventListDataset:astropy}\label{api/gammapy.data.EventListDataset::doc}\index{EventListDataset (class in gammapy.data)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventListDataset:gammapy.data.EventListDataset}\pysiglinewithargsret{\strong{class }\code{gammapy.data.}\bfcode{EventListDataset}}{\emph{event\_list}, \emph{telescope\_array=None}, \emph{good\_time\_intervals=None}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Event list dataset (event list plus some extra info).
TODO: I'm not sure if IRFs should be included in this
class or if an extra container class should be added.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{event\_list} : {\hyperref[api/gammapy.data.EventList:gammapy.data.EventList]{\emph{\code{EventList}}}}
\begin{quote}
Event list table
\end{quote}
\textbf{telescope\_array} : {\hyperref[api/gammapy.data.TelescopeArray:gammapy.data.TelescopeArray]{\emph{\code{TelescopeArray}}}}
\begin{quote}
Telescope array info
\end{quote}
\textbf{good\_time\_intervals} : {\hyperref[api/gammapy.data.GoodTimeIntervals:gammapy.data.GoodTimeIntervals]{\emph{\code{GoodTimeIntervals}}}}
\begin{quote}
Observation time interval info
\end{quote}
\end{description}\end{quote}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.data.EventListDataset:gammapy.data.EventListDataset.info]{\emph{\code{info}}}}
&
Summary info string.
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{info (gammapy.data.EventListDataset attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventListDataset:gammapy.data.EventListDataset.info}\pysigline{\bfcode{info}}
Summary info string.
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{check() (gammapy.data.EventListDataset method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventListDataset:gammapy.data.EventListDataset.check}\pysiglinewithargsret{\bfcode{check}}{\emph{checks='all'}}{}
Check if format and content is ok.
This is a convenience method that instantiates
and runs a {\hyperref[api/gammapy.data.EventListDatasetChecker:gammapy.data.EventListDatasetChecker]{\emph{\code{EventListDatasetChecker}}}} ...
if you want more options use this way to use it:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.data} \PYG{k+kn}{import} \PYG{n}{EventListDatasetChecker}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{checker} \PYG{o}{=} \PYG{n}{EventListDatasetChecker}\PYG{p}{(}\PYG{n}{event\PYGZus{}list}\PYG{p}{,} \PYG{o}{.}\PYG{o}{.}\PYG{o}{.}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{checker}\PYG{o}{.}\PYG{n}{run}\PYG{p}{(}\PYG{n}{which}\PYG{p}{,} \PYG{o}{.}\PYG{o}{.}\PYG{o}{.}\PYG{p}{)} \PYG{c}{\PYGZsh{}}
\end{Verbatim}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{checks} : list of str or `all'
\begin{quote}
Which checks to run (see list in
{\hyperref[api/gammapy.data.EventListDatasetChecker:gammapy.data.EventListDatasetChecker.run]{\emph{\code{run}}}} docstring).
\end{quote}
\item[{Returns}] \leavevmode
\textbf{ok} : bool
\begin{quote}
Everything ok?
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{from\_hdu\_list() (gammapy.data.EventListDataset static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventListDataset:gammapy.data.EventListDataset.from_hdu_list}\pysiglinewithargsret{\strong{static }\bfcode{from\_hdu\_list}}{\emph{hdu\_list}}{}
Create {\hyperref[api/gammapy.data.EventList:gammapy.data.EventList]{\emph{\code{EventList}}}} from a \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}.
\end{fulllineitems}
\index{read() (gammapy.data.EventListDataset static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventListDataset:gammapy.data.EventListDataset.read}\pysiglinewithargsret{\strong{static }\bfcode{read}}{\emph{filename}}{}
Read event list from FITS file.
\end{fulllineitems}
\index{to\_fits() (gammapy.data.EventListDataset method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventListDataset:gammapy.data.EventListDataset.to_fits}\pysiglinewithargsret{\bfcode{to\_fits}}{}{}
Convert to FITS HDU list format.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{hdu\_list} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}
\begin{quote}
HDU list with EVENTS and GTI extension.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{vstack\_from\_files() (gammapy.data.EventListDataset static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventListDataset:gammapy.data.EventListDataset.vstack_from_files}\pysiglinewithargsret{\strong{static }\bfcode{vstack\_from\_files}}{\emph{filenames}, \emph{logger=None}}{}
Stack event lists vertically (combine events and GTIs).
This function stacks (a.k.a. concatenates) event lists.
E.g. if you have one event list with 100 events (i.e. 100 rows)
and another with 42 events, the output event list will have 142 events.
It also stacks the GTIs so that exposure computations are still
possible using the stacked event list.
At the moment this can require a lot of memory.
All event lists are loaded into memory at the same time.
TODO: implement and benchmark different a more efficient method:
Get number of rows from headers, pre-allocate a large table,
open files one by one and fill correct rows.
TODO: handle header keywords ``correctly''.
At the moment the output event list header keywords are copies of
the values from the first observation, i.e. meaningless.
Here's a (probably incomplete) list of values we should handle
(usually by computing the min, max or mean or removing it):
- OBS\_ID
- DATE\_OBS, DATE\_END
- TIME\_OBS, TIME\_END
- TSTART, TSTOP
- LIVETIME, DEADC
- RA\_PNT, DEC\_PNT
- ALT\_PNT, AZ\_PNT
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{filenames} : list of str
\begin{quote}
List of event list filenames
\end{quote}
\item[{Returns}] \leavevmode
\textbf{event\_list\_dataset} : {\hyperref[api/gammapy.data.EventListDataset:gammapy.data.EventListDataset]{\emph{\code{EventListDataset}}}}
\end{description}\end{quote}
\end{fulllineitems}
\index{write() (gammapy.data.EventListDataset method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventListDataset:gammapy.data.EventListDataset.write}\pysiglinewithargsret{\bfcode{write}}{\emph{*args}, \emph{**kwargs}}{}
Write to FITS file.
Calls \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList.writeto}{\code{writeto}}, forwarding all arguments.
\end{fulllineitems}
\end{fulllineitems}
\paragraph{EventListDatasetChecker}
\label{api/gammapy.data.EventListDatasetChecker:astropy}\label{api/gammapy.data.EventListDatasetChecker::doc}\label{api/gammapy.data.EventListDatasetChecker:eventlistdatasetchecker}\index{EventListDatasetChecker (class in gammapy.data)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventListDatasetChecker:gammapy.data.EventListDatasetChecker}\pysiglinewithargsret{\strong{class }\code{gammapy.data.}\bfcode{EventListDatasetChecker}}{\emph{event\_list\_dataset}, \emph{logger=None}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Event list dataset checker.
\begin{description}
\item[{TODO: link to defining standard documents,}] \leavevmode
especially the CTA event list spec.
\end{description}
Having such a checker is useful at the moment because
the CTA data formats are quickly evolving and there's
various sources of event list data, e.g. exporters are
being written for the existing IACTs and simulators
are being written for CTA.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{event\_list\_dataset} : {\hyperref[api/gammapy.data.EventListDataset:gammapy.data.EventListDataset]{\emph{\code{EventListDataset}}}}
\begin{quote}
Event list dataset
\end{quote}
\textbf{logger} : \href{http://docs.python.org/library/logging.html\#logging.Logger}{\code{logging.Logger}} or None
\begin{quote}
Logger to use
\end{quote}
\end{description}\end{quote}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{accuracy (gammapy.data.EventListDatasetChecker attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventListDatasetChecker:gammapy.data.EventListDatasetChecker.accuracy}\pysigline{\bfcode{accuracy}\strong{ = OrderedDict({[}(`time', \textless{}Quantity 1.0 us\textgreater{}), (`angle', \textless{}Angle 1.0 arcsec\textgreater{}){]})}}
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{check\_coordinates() (gammapy.data.EventListDatasetChecker method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventListDatasetChecker:gammapy.data.EventListDatasetChecker.check_coordinates}\pysiglinewithargsret{\bfcode{check\_coordinates}}{}{}
Check if various event list coordinates are consistent.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{event\_list\_dataset} : {\hyperref[api/gammapy.data.EventListDataset:gammapy.data.EventListDataset]{\emph{\code{EventListDataset}}}}
\begin{quote}
Event list dataset
\end{quote}
\textbf{accuracy} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
Required accuracy.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{status} : bool
\begin{quote}
All coordinates consistent?
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{check\_misc() (gammapy.data.EventListDatasetChecker method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventListDatasetChecker:gammapy.data.EventListDatasetChecker.check_misc}\pysiglinewithargsret{\bfcode{check\_misc}}{}{}
Check misc basic stuff.
\end{fulllineitems}
\index{check\_times() (gammapy.data.EventListDatasetChecker method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventListDatasetChecker:gammapy.data.EventListDatasetChecker.check_times}\pysiglinewithargsret{\bfcode{check\_times}}{}{}
Check if various times are consistent.
The headers and tables of the FITS EVENTS and GTI extension
contain various observation and event time information.
\end{fulllineitems}
\index{run() (gammapy.data.EventListDatasetChecker method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.EventListDatasetChecker:gammapy.data.EventListDatasetChecker.run}\pysiglinewithargsret{\bfcode{run}}{\emph{checks='all'}}{}
Run checks.
Available checks: \{...\}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{checks} : list of str or ``all''
\begin{quote}
Which checks to run
\end{quote}
\item[{Returns}] \leavevmode
\textbf{ok} : bool
\begin{quote}
Everything ok?
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\end{fulllineitems}
\paragraph{GoodTimeIntervals}
\label{api/gammapy.data.GoodTimeIntervals:astropy}\label{api/gammapy.data.GoodTimeIntervals::doc}\label{api/gammapy.data.GoodTimeIntervals:goodtimeintervals}\index{GoodTimeIntervals (class in gammapy.data)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.GoodTimeIntervals:gammapy.data.GoodTimeIntervals}\pysiglinewithargsret{\strong{class }\code{gammapy.data.}\bfcode{GoodTimeIntervals}}{\emph{*args}, \emph{**kwargs}}{}
Bases: \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{astropy.table.Table}}
Good time intervals (GTI) \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}.
Note: at the moment dead-time and live-time is in the
EVENTS header ... the GTI header just deals with
observation times.
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.data.GoodTimeIntervals:gammapy.data.GoodTimeIntervals.info]{\emph{\code{info}}}}
&
Summary info string.
\\
\hline
{\hyperref[api/gammapy.data.GoodTimeIntervals:gammapy.data.GoodTimeIntervals.time_delta]{\emph{\code{time\_delta}}}}
&
GTI durations in seconds (\href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}).
\\
\hline
{\hyperref[api/gammapy.data.GoodTimeIntervals:gammapy.data.GoodTimeIntervals.time_start]{\emph{\code{time\_start}}}}
&
GTI start times (\href{http://docs.astropy.org/en/latest/api/astropy.time.Time.html\#astropy.time.Time}{\code{Time}}).
\\
\hline
{\hyperref[api/gammapy.data.GoodTimeIntervals:gammapy.data.GoodTimeIntervals.time_stop]{\emph{\code{time\_stop}}}}
&
GTI end times (\href{http://docs.astropy.org/en/latest/api/astropy.time.Time.html\#astropy.time.Time}{\code{Time}}).
\\
\hline
{\hyperref[api/gammapy.data.GoodTimeIntervals:gammapy.data.GoodTimeIntervals.time_sum]{\emph{\code{time\_sum}}}}
&
Sum of GTIs in seconds (\href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}).
\\
\hline\end{longtable}
\paragraph{Attributes Documentation}
\index{info (gammapy.data.GoodTimeIntervals attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.GoodTimeIntervals:gammapy.data.GoodTimeIntervals.info}\pysigline{\bfcode{info}}
Summary info string.
\end{fulllineitems}
\index{time\_delta (gammapy.data.GoodTimeIntervals attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.GoodTimeIntervals:gammapy.data.GoodTimeIntervals.time_delta}\pysigline{\bfcode{time\_delta}}
GTI durations in seconds (\href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}).
\end{fulllineitems}
\index{time\_start (gammapy.data.GoodTimeIntervals attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.GoodTimeIntervals:gammapy.data.GoodTimeIntervals.time_start}\pysigline{\bfcode{time\_start}}
GTI start times (\href{http://docs.astropy.org/en/latest/api/astropy.time.Time.html\#astropy.time.Time}{\code{Time}}).
\end{fulllineitems}
\index{time\_stop (gammapy.data.GoodTimeIntervals attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.GoodTimeIntervals:gammapy.data.GoodTimeIntervals.time_stop}\pysigline{\bfcode{time\_stop}}
GTI end times (\href{http://docs.astropy.org/en/latest/api/astropy.time.Time.html\#astropy.time.Time}{\code{Time}}).
\end{fulllineitems}
\index{time\_sum (gammapy.data.GoodTimeIntervals attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.GoodTimeIntervals:gammapy.data.GoodTimeIntervals.time_sum}\pysigline{\bfcode{time\_sum}}
Sum of GTIs in seconds (\href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}).
\end{fulllineitems}
\end{fulllineitems}
\paragraph{InvalidDataError}
\label{api/gammapy.data.InvalidDataError:astropy}\label{api/gammapy.data.InvalidDataError::doc}\label{api/gammapy.data.InvalidDataError:invaliddataerror}\index{InvalidDataError}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.InvalidDataError:gammapy.data.InvalidDataError}\pysigline{\strong{exception }\code{gammapy.data.}\bfcode{InvalidDataError}}
Invalid data found.
\end{fulllineitems}
\paragraph{SpectralCube}
\label{api/gammapy.data.SpectralCube:astropy}\label{api/gammapy.data.SpectralCube::doc}\label{api/gammapy.data.SpectralCube:spectralcube}\index{SpectralCube (class in gammapy.data)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.SpectralCube:gammapy.data.SpectralCube}\pysiglinewithargsret{\strong{class }\code{gammapy.data.}\bfcode{SpectralCube}}{\emph{data}, \emph{wcs}, \emph{energy}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Spectral cube for gamma-ray astronomy.
Can be used e.g. for Fermi or GALPROP diffuse model cubes.
Note that there is a very nice \code{SpectralCube} implementation here:
\href{http://spectral-cube.readthedocs.org/en/latest/index.html}{http://spectral-cube.readthedocs.org/en/latest/index.html}
Here is some discussion if / how it could be used:
\href{https://github.com/radio-astro-tools/spectral-cube/issues/110}{https://github.com/radio-astro-tools/spectral-cube/issues/110}
For now we re-implement what we need here.
The order of the spectral cube axes can be very confusing ... this should help:
\begin{itemize}
\item {}
The \code{data} array axis order is \code{(energy, lat, lon)}.
\item {}
The \code{wcs} object axis order is \code{(lon, lat, energy)}.
\item {}
Methods use the \code{wcs} order of \code{(lon, lat, energy)},
but internally when accessing the data often the reverse order is used.
We use \code{(xx, yy, zz)} as pixel coordinates for \code{(lon, lat, energy)},
as that matches the common definition of \code{x} and \code{y} in image viewers.
\end{itemize}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{data} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Data array (3-dim)
\end{quote}
\textbf{wcs} : \href{http://docs.astropy.org/en/latest/api/astropy.wcs.WCS.html\#astropy.wcs.WCS}{\code{WCS}}
\begin{quote}
Word coordinate system transformation
\end{quote}
\textbf{energy} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Energy array
\end{quote}
\end{description}\end{quote}
\paragraph{Notes}
Diffuse model files in this format are distributed with the Fermi Science tools
software and can also be downloaded at
\href{http://fermi.gsfc.nasa.gov/ssc/data/access/lat/BackgroundModels.html}{http://fermi.gsfc.nasa.gov/ssc/data/access/lat/BackgroundModels.html}
E.g. the 2-year diffuse model that was used in the 2FGL catalog production is at
\href{http://fermi.gsfc.nasa.gov/ssc/data/analysis/software/aux/gal\_2yearp7v6\_v0.fits}{http://fermi.gsfc.nasa.gov/ssc/data/analysis/software/aux/gal\_2yearp7v6\_v0.fits}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube.solid_angle_image]{\emph{\code{solid\_angle\_image}}}}
&
Solid angle image.
\\
\hline
{\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube.spatial_coordinate_images]{\emph{\code{spatial\_coordinate\_images}}}}
&
Spatial coordinate images.
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{solid\_angle\_image (gammapy.data.SpectralCube attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.SpectralCube:gammapy.data.SpectralCube.solid_angle_image}\pysigline{\bfcode{solid\_angle\_image}}
Solid angle image.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{solid\_angle\_image} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Solid angle image (steradian)
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{spatial\_coordinate\_images (gammapy.data.SpectralCube attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.SpectralCube:gammapy.data.SpectralCube.spatial_coordinate_images}\pysigline{\bfcode{spatial\_coordinate\_images}}
Spatial coordinate images.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{lon, lat} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Arrays of longitude and latitude pixel coordinates.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{flux() (gammapy.data.SpectralCube method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.SpectralCube:gammapy.data.SpectralCube.flux}\pysiglinewithargsret{\bfcode{flux}}{\emph{lon}, \emph{lat}, \emph{energy}}{}
Differential flux (linear interpolation).
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{lon} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
Longitude
\end{quote}
\textbf{lat} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
Latitude
\end{quote}
\textbf{energy} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Energy
\end{quote}
\item[{Returns}] \leavevmode
\textbf{flux} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Differential flux (1 / (cm2 MeV s sr))
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{integral\_flux\_image() (gammapy.data.SpectralCube method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.SpectralCube:gammapy.data.SpectralCube.integral_flux_image}\pysiglinewithargsret{\bfcode{integral\_flux\_image}}{\emph{energy\_band}, \emph{energy\_bins=10}}{}
Integral flux image for a given energy band.
A local power-law approximation in small energy bins is
used to compute the integral.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energy\_band} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Tuple \code{(energy\_min, energy\_max)}
\end{quote}
\textbf{energy\_bins} : int or \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Energy bin definition.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{image} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
Integral flux image (1 / (cm\textasciicircum{}2 s sr))
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{pix2world() (gammapy.data.SpectralCube method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.SpectralCube:gammapy.data.SpectralCube.pix2world}\pysiglinewithargsret{\bfcode{pix2world}}{\emph{x}, \emph{y}, \emph{z}}{}
Convert world to pixel coordinates.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{x, y, z}
\item[{Returns}] \leavevmode
lon, lat, energy
\end{description}\end{quote}
\end{fulllineitems}
\index{read() (gammapy.data.SpectralCube static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.SpectralCube:gammapy.data.SpectralCube.read}\pysiglinewithargsret{\strong{static }\bfcode{read}}{\emph{filename}}{}
Read spectral cube from FITS file.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{filename} : str
\begin{quote}
File name
\end{quote}
\item[{Returns}] \leavevmode
\textbf{spectral\_cube} : {\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube]{\emph{\code{SpectralCube}}}}
\begin{quote}
Spectral cube
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{read\_hdu() (gammapy.data.SpectralCube static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.SpectralCube:gammapy.data.SpectralCube.read_hdu}\pysiglinewithargsret{\strong{static }\bfcode{read\_hdu}}{\emph{hdu\_list}}{}
Read spectral cube from HDU.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{object\_hdu} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
Image HDU object to be read
\end{quote}
\textbf{energy\_table\_hdu} : \href{http://docs.astropy.org/en/latest/io/fits/api/tables.html\#astropy.io.fits.TableHDU}{\code{TableHDU}}
\begin{quote}
Table HDU object giving energies of each slice
of the Image HDU object\_hdu
\end{quote}
\item[{Returns}] \leavevmode
\textbf{spectral\_cube} : {\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube]{\emph{\code{SpectralCube}}}}
\begin{quote}
Spectral cube
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{reproject\_to() (gammapy.data.SpectralCube method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.SpectralCube:gammapy.data.SpectralCube.reproject_to}\pysiglinewithargsret{\bfcode{reproject\_to}}{\emph{reference\_cube}, \emph{projection\_type='bicubic'}}{}
Spatially reprojects a {\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube]{\emph{\code{SpectralCube}}}} onto a reference cube.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{reference\_cube} : {\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube]{\emph{\code{SpectralCube}}}}
\begin{quote}
Reference cube with the desired spatial projection.
\end{quote}
\textbf{projection\_type} : \{`nearest-neighbor', `bilinear',
\begin{quote}
`biquadratic', `bicubic', `flux-conserving'\}
Specify method of reprojection. Default: `bilinear'.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{reprojected\_cube} : {\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube]{\emph{\code{SpectralCube}}}}
\begin{quote}
Cube spatially reprojected to the reference cube.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{spectral\_index() (gammapy.data.SpectralCube method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.SpectralCube:gammapy.data.SpectralCube.spectral_index}\pysiglinewithargsret{\bfcode{spectral\_index}}{\emph{lon}, \emph{lat}, \emph{energy}, \emph{dz=0.001}}{}
Power law spectral index.
A forward finite difference method with step \code{dz} is used along
the \code{z = log10(energy)} axis.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{lon} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
Longitude
\end{quote}
\textbf{lat} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
Latitude
\end{quote}
\textbf{energy} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Energy
\end{quote}
\item[{Returns}] \leavevmode
\textbf{spectral\_index} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Spectral index
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{to\_fits() (gammapy.data.SpectralCube method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.SpectralCube:gammapy.data.SpectralCube.to_fits}\pysiglinewithargsret{\bfcode{to\_fits}}{}{}
Writes SpectralCube to fits hdu\_list.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{hdu\_list} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}
\begin{itemize}
\item {} \begin{description}
\item[{hdu\_list{[}0{]}}] \leavevmode{[}\href{http://docs.astropy.org/en/latest/io/fits/api/hdus.html\#astropy.io.fits.PrimaryHDU}{\code{PrimaryHDU}}{]}
Image array of data
\end{description}
\item {} \begin{description}
\item[{hdu\_list{[}1{]}}] \leavevmode{[}\href{http://docs.astropy.org/en/latest/io/fits/api/tables.html\#astropy.io.fits.BinTableHDU}{\code{BinTableHDU}}{]}
Table of energies
\end{description}
\end{itemize}
\end{description}\end{quote}
\end{fulllineitems}
\index{world2pix() (gammapy.data.SpectralCube method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.SpectralCube:gammapy.data.SpectralCube.world2pix}\pysiglinewithargsret{\bfcode{world2pix}}{\emph{lon}, \emph{lat}, \emph{energy}, \emph{combine=False}}{}
Convert world to pixel coordinates.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{lon, lat, energy}
\item[{Returns}] \leavevmode
x, y, z or array with (x, y, z) as columns
\end{description}\end{quote}
\end{fulllineitems}
\index{writeto() (gammapy.data.SpectralCube method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.SpectralCube:gammapy.data.SpectralCube.writeto}\pysiglinewithargsret{\bfcode{writeto}}{\emph{filename}, \emph{**kwargs}}{}
Writes SpectralCube to fits file.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{filename} : string
\begin{quote}
Name of output file (.fits)
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\end{fulllineitems}
\paragraph{TelescopeArray}
\label{api/gammapy.data.TelescopeArray:astropy}\label{api/gammapy.data.TelescopeArray::doc}\label{api/gammapy.data.TelescopeArray:telescopearray}\index{TelescopeArray (class in gammapy.data)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.TelescopeArray:gammapy.data.TelescopeArray}\pysiglinewithargsret{\strong{class }\code{gammapy.data.}\bfcode{TelescopeArray}}{\emph{data=None}, \emph{masked=None}, \emph{names=None}, \emph{dtype=None}, \emph{meta=None}, \emph{copy=True}, \emph{rows=None}}{}
Bases: \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{astropy.table.Table}}
Telescope array info.
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.data.TelescopeArray:gammapy.data.TelescopeArray.info]{\emph{\code{info}}}}
&
Summary info string.
\\
\hline
{\hyperref[api/gammapy.data.TelescopeArray:gammapy.data.TelescopeArray.observatory_earth_location]{\emph{\code{observatory\_earth\_location}}}}
&
Observatory location (\href{http://docs.astropy.org/en/latest/api/astropy.coordinates.EarthLocation.html\#astropy.coordinates.EarthLocation}{\code{EarthLocation}})
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{info (gammapy.data.TelescopeArray attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.TelescopeArray:gammapy.data.TelescopeArray.info}\pysigline{\bfcode{info}}
Summary info string.
\end{fulllineitems}
\index{observatory\_earth\_location (gammapy.data.TelescopeArray attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.TelescopeArray:gammapy.data.TelescopeArray.observatory_earth_location}\pysigline{\bfcode{observatory\_earth\_location}}
Observatory location (\href{http://docs.astropy.org/en/latest/api/astropy.coordinates.EarthLocation.html\#astropy.coordinates.EarthLocation}{\code{EarthLocation}})
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{plot() (gammapy.data.TelescopeArray method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.data.TelescopeArray:gammapy.data.TelescopeArray.plot}\pysiglinewithargsret{\bfcode{plot}}{\emph{ax}}{}
Plot telescope locations.
\end{fulllineitems}
\end{fulllineitems}
\chapter{Access datasets (\texttt{gammapy.datasets})}
\label{datasets/index:id1}\label{datasets/index:astropy}\label{datasets/index::doc}\label{datasets/index:datasets}\label{datasets/index:access-datasets-gammapy-datasets}
\section{Introduction}
\label{datasets/index:introduction}
{\hyperref[datasets/index:module-gammapy.datasets]{\emph{\code{gammapy.datasets}}}} contains function to easily access datasets that are
relevant for gamma-ray astronomy.
The functions have a naming pattern (following the \code{sklearn.datasets} lead):
\begin{itemize}
\item {}
\code{load\_*} functions load datasets that are distributed with Gammapy (bundled in the repo)
\item {}
\code{fetch\_*} functions fetch datasets from the web (either from \code{gammapy-extra} or other sites)
\item {}
\code{make\_*} functions create datasets programatically (sometimes involving a random number generator)
\end{itemize}
\begin{notice}{note}{Note:}
The {\hyperref[datasets/index:module-gammapy.datasets]{\emph{\code{gammapy.datasets}}}} sub-package shouldn't be confused with the {\hyperref[data/index:module-gammapy.data]{\emph{\code{gammapy.data}}}}
sub-package, which contains classes representing gamma-ray data.
And there is a separate section describing the {\hyperref[dataformats/index:dataformats]{\emph{\DUspan{}{Data Formats}}}}
that are commonly used in gamma-ray astronomy.
\end{notice}
\section{Getting Started}
\label{datasets/index:getting-started}
Example how to load a dataset that is distributed with the code
in the \code{gammapy} repo (i.e. will be available even if you're offline)
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.datasets} \PYG{k+kn}{import} \PYG{n}{load\PYGZus{}crab\PYGZus{}flux\PYGZus{}points}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{flux\PYGZus{}points} \PYG{o}{=} \PYG{n}{load\PYGZus{}crab\PYGZus{}flux\PYGZus{}points}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}
Example how to fetch a dataset from the web (i.e. will download to
the Astropy cache and need internet access on first call):
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.datasets} \PYG{k+kn}{import} \PYG{n}{fetch\PYGZus{}fermi\PYGZus{}catalog}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{catalog} \PYG{o}{=} \PYG{n}{fetch\PYGZus{}fermi\PYGZus{}catalog}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{2FGL}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{LAT\PYGZus{}Point\PYGZus{}Source\PYGZus{}Catalog}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\end{Verbatim}
TODO: explain how the Astropy cache works and make it configurable for Gammapy.
Example how to make a dataset (from scratch, no file is loaded):
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.datasets} \PYG{k+kn}{import} \PYG{n}{make\PYGZus{}test\PYGZus{}psf}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{psf} \PYG{o}{=} \PYG{n}{make\PYGZus{}test\PYGZus{}psf}\PYG{p}{(}\PYG{n}{energy\PYGZus{}bins}\PYG{o}{=}\PYG{l+m+mi}{20}\PYG{p}{)}
\end{Verbatim}
\section{Reference/API}
\label{datasets/index:reference-api}
\subsection{gammapy.datasets Package}
\label{datasets/index:module-gammapy.datasets}\label{datasets/index:gammapy-datasets-package}\index{gammapy.datasets (module)}
Access datasets.
\subsubsection{Functions}
\label{datasets/index:functions}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.datasets.fetch_catalog_snrcat:gammapy.datasets.fetch_catalog_snrcat]{\emph{\code{fetch\_catalog\_snrcat}}}}({[}cache{]})
&
Fetch SNRcat supernova remnant catalog.
\\
\hline
{\hyperref[api/gammapy.datasets.fetch_fermi_catalog:gammapy.datasets.fetch_fermi_catalog]{\emph{\code{fetch\_fermi\_catalog}}}}(catalog{[}, extension{]})
&
Fetch Fermi catalog data.
\\
\hline
{\hyperref[api/gammapy.datasets.fetch_fermi_diffuse_background_model:gammapy.datasets.fetch_fermi_diffuse_background_model]{\emph{\code{fetch\_fermi\_diffuse\_background\_model}}}}({[}filename{]})
&
Fetch Fermi diffuse background model.
\\
\hline
{\hyperref[api/gammapy.datasets.fetch_fermi_extended_sources:gammapy.datasets.fetch_fermi_extended_sources]{\emph{\code{fetch\_fermi\_extended\_sources}}}}(catalog)
&
Fetch Fermi catalog extended source images.
\\
\hline
{\hyperref[api/gammapy.datasets.get_path:gammapy.datasets.get_path]{\emph{\code{get\_path}}}}(filename{[}, location, cache{]})
&
Get path (location on your disk) for a given file.
\\
\hline
{\hyperref[api/gammapy.datasets.load_aeff2D_fits_table:gammapy.datasets.load_aeff2D_fits_table]{\emph{\code{load\_aeff2D\_fits\_table}}}}()
&
Load an example aeff2D FITS file..
\\
\hline
{\hyperref[api/gammapy.datasets.load_arf_fits_table:gammapy.datasets.load_arf_fits_table]{\emph{\code{load\_arf\_fits\_table}}}}()
&
Load an example ARF FITS table.
\\
\hline
{\hyperref[api/gammapy.datasets.load_catalog_atnf:gammapy.datasets.load_catalog_atnf]{\emph{\code{load\_catalog\_atnf}}}}()
&
Load ATNF pulsar catalog.
\\
\hline
{\hyperref[api/gammapy.datasets.load_catalog_green:gammapy.datasets.load_catalog_green]{\emph{\code{load\_catalog\_green}}}}()
&
Load Green's supernova remnant catalog.
\\
\hline
{\hyperref[api/gammapy.datasets.load_catalog_hess_galactic:gammapy.datasets.load_catalog_hess_galactic]{\emph{\code{load\_catalog\_hess\_galactic}}}}()
&
Load catalog with info on HESS Galactic sources from individual publications.
\\
\hline
{\hyperref[api/gammapy.datasets.load_catalog_tevcat:gammapy.datasets.load_catalog_tevcat]{\emph{\code{load\_catalog\_tevcat}}}}()
&
Load TeVCat source catalog.
\\
\hline
{\hyperref[api/gammapy.datasets.load_crab_flux_points:gammapy.datasets.load_crab_flux_points]{\emph{\code{load\_crab\_flux\_points}}}}({[}component, ...{]})
&
Load published Crab pulsar and nebula flux points.
\\
\hline
{\hyperref[api/gammapy.datasets.load_diffuse_gamma_spectrum:gammapy.datasets.load_diffuse_gamma_spectrum]{\emph{\code{load\_diffuse\_gamma\_spectrum}}}}(reference)
&
Load published diffuse gamma-ray spectrum.
\\
\hline
{\hyperref[api/gammapy.datasets.load_electron_spectrum:gammapy.datasets.load_electron_spectrum]{\emph{\code{load\_electron\_spectrum}}}}(reference)
&
Load published electron spectrum.
\\
\hline
{\hyperref[api/gammapy.datasets.load_lat_psf_performance:gammapy.datasets.load_lat_psf_performance]{\emph{\code{load\_lat\_psf\_performance}}}}(performance\_file)
&
Loads Fermi-LAT TOTAL PSF performance data.
\\
\hline
{\hyperref[api/gammapy.datasets.load_poisson_stats_image:gammapy.datasets.load_poisson_stats_image]{\emph{\code{load\_poisson\_stats\_image}}}}({[}extra\_info, ...{]})
&
Load Poisson statistics counts image of a Gaussian source on flat background.
\\
\hline
{\hyperref[api/gammapy.datasets.load_psf_fits_table:gammapy.datasets.load_psf_fits_table]{\emph{\code{load\_psf\_fits\_table}}}}()
&
Load an example PSF FITS file..
\\
\hline
{\hyperref[api/gammapy.datasets.load_tev_spectrum:gammapy.datasets.load_tev_spectrum]{\emph{\code{load\_tev\_spectrum}}}}(source\_name)
&
Load published TeV flux point measurements.
\\
\hline
{\hyperref[api/gammapy.datasets.make_test_bg_cube_model:gammapy.datasets.make_test_bg_cube_model]{\emph{\code{make\_test\_bg\_cube\_model}}}}({[}detx\_range, ...{]})
&
Make a test bg cube model.
\\
\hline
{\hyperref[api/gammapy.datasets.make_test_observation_table:gammapy.datasets.make_test_observation_table]{\emph{\code{make\_test\_observation\_table}}}}(...{[}, debug, ...{]})
&
Make a test observation table.
\\
\hline
{\hyperref[api/gammapy.datasets.make_test_psf:gammapy.datasets.make_test_psf]{\emph{\code{make\_test\_psf}}}}({[}energy\_bins, theta\_bins{]})
&
Create a test FITS PSF file.
\\
\hline\end{longtable}
\paragraph{fetch\_catalog\_snrcat}
\label{api/gammapy.datasets.fetch_catalog_snrcat:fetch-catalog-snrcat}\label{api/gammapy.datasets.fetch_catalog_snrcat::doc}\index{fetch\_catalog\_snrcat() (in module gammapy.datasets)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.fetch_catalog_snrcat:gammapy.datasets.fetch_catalog_snrcat}\pysiglinewithargsret{\code{gammapy.datasets.}\bfcode{fetch\_catalog\_snrcat}}{\emph{cache=False}}{}
Fetch SNRcat supernova remnant catalog.
\href{http://www.physics.umanitoba.ca/snr/SNRcat/}{SNRcat}
is a census of high-energy observations of Galactic supernova remnants.
This function downloads the following CSV-format tables
and adds some useful columns and unit information:
\begin{itemize}
\item {}
\href{http://www.physics.umanitoba.ca/snr/SNRcat/SNRdownload.php?table=SNR}{http://www.physics.umanitoba.ca/snr/SNRcat/SNRdownload.php?table=SNR}
\item {}
\href{http://www.physics.umanitoba.ca/snr/SNRcat/SNRdownload.php?table=OBS}{http://www.physics.umanitoba.ca/snr/SNRcat/SNRdownload.php?table=OBS}
\end{itemize}
This only represents a subset of the information available in SNRcat,
to get at the rest we would have to scrape their web pages.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{cache} : bool, optional
\begin{quote}
Use cached version?
\end{quote}
\item[{Returns}] \leavevmode
\textbf{data} : \code{Bunch}
\begin{quote}
\begin{description}
\item[{Dictionary-like object with attributes:}] \leavevmode\begin{itemize}
\item {}
\code{snr\_table} (\href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}) -- SNR info table
\item {}
\code{obs\_table} (\href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}) -- High-energy observation info table
\end{itemize}
\end{description}
Each table has a \code{version} string containing the download date in the \code{table.meta} dictionary.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{fetch\_fermi\_catalog}
\label{api/gammapy.datasets.fetch_fermi_catalog:fetch-fermi-catalog}\label{api/gammapy.datasets.fetch_fermi_catalog:astropy}\label{api/gammapy.datasets.fetch_fermi_catalog::doc}\index{fetch\_fermi\_catalog() (in module gammapy.datasets)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.fetch_fermi_catalog:gammapy.datasets.fetch_fermi_catalog}\pysiglinewithargsret{\code{gammapy.datasets.}\bfcode{fetch\_fermi\_catalog}}{\emph{catalog}, \emph{extension=None}}{}
Fetch Fermi catalog data.
Reference: \href{http://fermi.gsfc.nasa.gov/ssc/data/access/lat/}{http://fermi.gsfc.nasa.gov/ssc/data/access/lat/}.
The Fermi catalogs contain the following relevant catalog HDUs:
\begin{itemize}
\item {} \begin{description}
\item[{3FGL Catalog}] \leavevmode{[}LAT 4-year Point Source Catalog{]}\begin{itemize}
\item {}
\code{LAT\_Point\_Source\_Catalog} Point Source Catalog Table.
\item {}
\code{ExtendedSources} Extended Source Catalog Table.
\end{itemize}
\end{description}
\item {} \begin{description}
\item[{2FGL Catalog}] \leavevmode{[}LAT 2-year Point Source Catalog{]}\begin{itemize}
\item {}
\code{LAT\_Point\_Source\_Catalog} Point Source Catalog Table.
\item {}
\code{ExtendedSources} Extended Source Catalog Table.
\end{itemize}
\end{description}
\item {} \begin{description}
\item[{1FGL Catalog}] \leavevmode{[}LAT 1-year Point Source Catalog{]}\begin{itemize}
\item {}
\code{LAT\_Point\_Source\_Catalog} Point Source Catalog Table.
\end{itemize}
\end{description}
\item {} \begin{description}
\item[{1FHL Catalog}] \leavevmode{[}First Fermi-LAT Catalog of Sources above 10 GeV{]}\begin{itemize}
\item {}
\code{LAT\_Point\_Source\_Catalog} Point Source Catalog Table.
\item {}
\code{ExtendedSources} Extended Source Catalog Table.
\end{itemize}
\end{description}
\item {} \begin{description}
\item[{2PC Catalog}] \leavevmode{[}LAT Second Catalog of Gamma-ray Pulsars{]}\begin{itemize}
\item {}
\code{PULSAR\_CATALOG} Pulsar Catalog Table.
\item {}
\code{SPECTRAL} Table of Pulsar Spectra Parameters.
\item {}
\code{OFF\_PEAK} Table for further Spectral and Flux data for the Catalog.
\end{itemize}
\end{description}
\end{itemize}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{catalog} : \{`3FGL', `2FGL', `1FGL', `1FHL', `2PC'\}
\begin{quote}
Specifies which catalog to display.
\end{quote}
\textbf{extension} : str
\begin{quote}
Specifies which catalog HDU to provide as a table (optional).
See list of catalog HDUs above.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{hdu\_list (Default)} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}
\begin{quote}
Catalog FITS HDU list (for access to full catalog dataset).
\end{quote}
\textbf{catalog\_table} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Catalog table for a selected hdu extension.
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.datasets} \PYG{k+kn}{import} \PYG{n}{fetch\PYGZus{}fermi\PYGZus{}catalog}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{fetch\PYGZus{}fermi\PYGZus{}catalog}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{2FGL}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{g+go}{ [\PYGZlt{}astropy.io.fits.hdu.image.PrimaryHDU at 0x3330790\PYGZgt{},}
\PYG{g+go}{ \PYGZlt{}astropy.io.fits.hdu.table.BinTableHDU at 0x338b990\PYGZgt{},}
\PYG{g+go}{ \PYGZlt{}astropy.io.fits.hdu.table.BinTableHDU at 0x3396450\PYGZgt{},}
\PYG{g+go}{ \PYGZlt{}astropy.io.fits.hdu.table.BinTableHDU at 0x339af10\PYGZgt{},}
\PYG{g+go}{ \PYGZlt{}astropy.io.fits.hdu.table.BinTableHDU at 0x339ff10\PYGZgt{}]}
\end{Verbatim}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.datasets} \PYG{k+kn}{import} \PYG{n}{fetch\PYGZus{}fermi\PYGZus{}catalog}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{fetch\PYGZus{}fermi\PYGZus{}catalog}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{2FGL}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{LAT\PYGZus{}Point\PYGZus{}Source\PYGZus{}Catalog}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{g+go}{ \PYGZlt{}Table rows=1873 names= ... \PYGZgt{}}
\end{Verbatim}
\end{fulllineitems}
\paragraph{fetch\_fermi\_diffuse\_background\_model}
\label{api/gammapy.datasets.fetch_fermi_diffuse_background_model:astropy}\label{api/gammapy.datasets.fetch_fermi_diffuse_background_model::doc}\label{api/gammapy.datasets.fetch_fermi_diffuse_background_model:fetch-fermi-diffuse-background-model}\index{fetch\_fermi\_diffuse\_background\_model() (in module gammapy.datasets)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.fetch_fermi_diffuse_background_model:gammapy.datasets.fetch_fermi_diffuse_background_model}\pysiglinewithargsret{\code{gammapy.datasets.}\bfcode{fetch\_fermi\_diffuse\_background\_model}}{\emph{filename='gll\_iem\_v02.fit'}}{}
Fetch Fermi diffuse background model.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{filename} : str
\begin{quote}
Diffuse model file name
\end{quote}
\item[{Returns}] \leavevmode
\textbf{filename} : str
\begin{quote}
Full local path name
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{fetch\_fermi\_extended\_sources}
\label{api/gammapy.datasets.fetch_fermi_extended_sources:fetch-fermi-extended-sources}\label{api/gammapy.datasets.fetch_fermi_extended_sources:astropy}\label{api/gammapy.datasets.fetch_fermi_extended_sources::doc}\index{fetch\_fermi\_extended\_sources() (in module gammapy.datasets)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.fetch_fermi_extended_sources:gammapy.datasets.fetch_fermi_extended_sources}\pysiglinewithargsret{\code{gammapy.datasets.}\bfcode{fetch\_fermi\_extended\_sources}}{\emph{catalog}}{}
Fetch Fermi catalog extended source images.
Reference: \href{http://fermi.gsfc.nasa.gov/ssc/data/access/lat/}{http://fermi.gsfc.nasa.gov/ssc/data/access/lat/}.
Extended source are available for the following Fermi catalogs:
\begin{itemize}
\item {}
3FGL Catalog : LAT 4-year Point Source Catalog
\item {}
2FGL Catalog : LAT 2-year Point Source Catalog
\item {}
1FHL Catalog : First Fermi-LAT Catalog of Sources above 10 GeV
\end{itemize}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{catalog} : \{`3FGL', `2FGL', `1FHL'\}
\begin{quote}
Specifies which catalog extended sources to return.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{hdu\_list} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}
\begin{quote}
FITS HDU list of FITS ImageHDUs for the extended sources.
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.datasets} \PYG{k+kn}{import} \PYG{n}{fetch\PYGZus{}fermi\PYGZus{}extended\PYGZus{}sources}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{sources} \PYG{o}{=} \PYG{n}{fetch\PYGZus{}fermi\PYGZus{}extended\PYGZus{}sources}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{2FGL}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{sources}\PYG{p}{)} \PYG{o}{=} \PYG{l+m+mi}{12}
\end{Verbatim}
\end{fulllineitems}
\paragraph{get\_path}
\label{api/gammapy.datasets.get_path:get-path}\label{api/gammapy.datasets.get_path:astropy}\label{api/gammapy.datasets.get_path::doc}\index{get\_path() (in module gammapy.datasets)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.get_path:gammapy.datasets.get_path}\pysiglinewithargsret{\code{gammapy.datasets.}\bfcode{get\_path}}{\emph{filename}, \emph{location='local'}, \emph{cache=True}}{}
Get path (location on your disk) for a given file.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{filename} : str
\begin{quote}
File name in the local or remote data folder
\end{quote}
\textbf{location} : \{`local', `remote'\}
\begin{quote}
File location.
\code{'local'} means bundled with \code{gammapy}.
\code{'remote'} means in the \code{gammapy-extra} repo in the \code{datasets} folder.
\end{quote}
\textbf{cache} : bool
\begin{quote}
if \href{http://docs.python.org/library/constants.html\#True}{\code{True}} and using \code{location=remote}, the file is searched
first within the local astropy cache and only downloaded if
it does not exist
\end{quote}
\item[{Returns}] \leavevmode
\textbf{path} : str
\begin{quote}
Path (location on your disk) of the file.
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy} \PYG{k+kn}{import} \PYG{n}{datasets}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{datasets}\PYG{o}{.}\PYG{n}{get\PYGZus{}path}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{fermi/fermi\PYGZus{}counts.fits.gz}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{g+go}{\PYGZsq{}/Users/deil/code/gammapy/gammapy/datasets/data/fermi/fermi\PYGZus{}counts.fits.gz\PYGZsq{}}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{datasets}\PYG{o}{.}\PYG{n}{get\PYGZus{}path}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{vela\PYGZus{}region/counts\PYGZus{}vela.fits}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{location}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{remote}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{g+go}{\PYGZsq{}/Users/deil/.astropy/cache/download/ce2456b0c9d1476bfd342eb4148144dd\PYGZsq{}}
\end{Verbatim}
\end{fulllineitems}
\paragraph{load\_aeff2D\_fits\_table}
\label{api/gammapy.datasets.load_aeff2D_fits_table:astropy}\label{api/gammapy.datasets.load_aeff2D_fits_table::doc}\label{api/gammapy.datasets.load_aeff2D_fits_table:load-aeff2d-fits-table}\index{load\_aeff2D\_fits\_table() (in module gammapy.datasets)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.load_aeff2D_fits_table:gammapy.datasets.load_aeff2D_fits_table}\pysiglinewithargsret{\code{gammapy.datasets.}\bfcode{load\_aeff2D\_fits\_table}}{}{}
Load an example aeff2D FITS file..
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{hdu\_list} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}
\begin{quote}
aeff2D file contents.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{load\_arf\_fits\_table}
\label{api/gammapy.datasets.load_arf_fits_table:astropy}\label{api/gammapy.datasets.load_arf_fits_table::doc}\label{api/gammapy.datasets.load_arf_fits_table:load-arf-fits-table}\index{load\_arf\_fits\_table() (in module gammapy.datasets)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.load_arf_fits_table:gammapy.datasets.load_arf_fits_table}\pysiglinewithargsret{\code{gammapy.datasets.}\bfcode{load\_arf\_fits\_table}}{}{}
Load an example ARF FITS table.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{hdu\_list} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}
\begin{quote}
ARF file contents.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{load\_catalog\_atnf}
\label{api/gammapy.datasets.load_catalog_atnf:astropy}\label{api/gammapy.datasets.load_catalog_atnf::doc}\label{api/gammapy.datasets.load_catalog_atnf:load-catalog-atnf}\index{load\_catalog\_atnf() (in module gammapy.datasets)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.load_catalog_atnf:gammapy.datasets.load_catalog_atnf}\pysiglinewithargsret{\code{gammapy.datasets.}\bfcode{load\_catalog\_atnf}}{}{}
Load ATNF pulsar catalog.
The \href{http://www.atnf.csiro.au/people/pulsar/psrcat/}{ATNF pulsar catalog}
is \textbf{the} collection of information on all pulsars.
Unfortunately it's only available in a database format that can only
be read with their software.
This function loads a FITS copy of version 1.51 of the ATNF catalog:
\href{http://www.atnf.csiro.au/research/pulsar/psrcat/catalogueHistory.html}{http://www.atnf.csiro.au/research/pulsar/psrcat/catalogueHistory.html}
The \code{ATNF\_v1.51.fits.gz} file and \code{make\_atnf.py} script are available
\href{https://github.com/gammapy/gammapy-extra/blob/master/datasets/catalogs/}{here}.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{catalog} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Source catalog
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{load\_catalog\_green}
\label{api/gammapy.datasets.load_catalog_green:astropy}\label{api/gammapy.datasets.load_catalog_green::doc}\label{api/gammapy.datasets.load_catalog_green:load-catalog-green}\index{load\_catalog\_green() (in module gammapy.datasets)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.load_catalog_green:gammapy.datasets.load_catalog_green}\pysiglinewithargsret{\code{gammapy.datasets.}\bfcode{load\_catalog\_green}}{}{}
Load Green's supernova remnant catalog.
This is the May 2014 version of the catalog, which contains 294 sources.
References:
\begin{itemize}
\item {}
\href{http://www.mrao.cam.ac.uk/surveys/snrs/}{http://www.mrao.cam.ac.uk/surveys/snrs/}
\item {}
\href{http://vizier.u-strasbg.fr/viz-bin/VizieR?-source=VII/272}{http://vizier.u-strasbg.fr/viz-bin/VizieR?-source=VII/272}
\item {}
\href{http://adsabs.harvard.edu/abs/2014BASI...42...47G}{http://adsabs.harvard.edu/abs/2014BASI...42...47G}
\end{itemize}
The \code{Green\_2014-05.fits.gz} file and \code{make\_green.py} script are available
\href{https://github.com/gammapy/gammapy-extra/blob/master/datasets/catalogs/}{here}.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{catalog} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Source catalog
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{load\_catalog\_hess\_galactic}
\label{api/gammapy.datasets.load_catalog_hess_galactic:load-catalog-hess-galactic}\label{api/gammapy.datasets.load_catalog_hess_galactic:astropy}\label{api/gammapy.datasets.load_catalog_hess_galactic::doc}\index{load\_catalog\_hess\_galactic() (in module gammapy.datasets)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.load_catalog_hess_galactic:gammapy.datasets.load_catalog_hess_galactic}\pysiglinewithargsret{\code{gammapy.datasets.}\bfcode{load\_catalog\_hess\_galactic}}{}{}
Load catalog with info on HESS Galactic sources from individual publications.
Note that this is different from the
\href{http://www.mpi-hd.mpg.de/hfm/HESS/pages/home/sources/}{official ``H.E.S.S. source catalog''}.
The main difference is that we only include Galactic sources (and the ones
from the large Magellanic cloud) and that we collect more information
(morphological and spectral parameters, associations, paper links to ADS),
using the latest publication for each source.
Please drop us an email if you have any questions or find something incorrect or outdated.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{catalog} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Source catalog
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{load\_catalog\_tevcat}
\label{api/gammapy.datasets.load_catalog_tevcat:astropy}\label{api/gammapy.datasets.load_catalog_tevcat::doc}\label{api/gammapy.datasets.load_catalog_tevcat:load-catalog-tevcat}\index{load\_catalog\_tevcat() (in module gammapy.datasets)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.load_catalog_tevcat:gammapy.datasets.load_catalog_tevcat}\pysiglinewithargsret{\code{gammapy.datasets.}\bfcode{load\_catalog\_tevcat}}{}{}
Load TeVCat source catalog.
\href{http://tevcat.uchicago.edu/}{TeVCat} is an online catalog
for TeV astronomy.
Unfortunately the TeVCat is not available in electronic format.
This is a dump of TeVCat as of 2014-09-24 created by scraping their
web page using the script available
\href{https://github.com/astropy/astroquery/pull/41}{here}.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{catalog} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Source catalog
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{load\_crab\_flux\_points}
\label{api/gammapy.datasets.load_crab_flux_points:load-crab-flux-points}\label{api/gammapy.datasets.load_crab_flux_points:astropy}\label{api/gammapy.datasets.load_crab_flux_points::doc}\index{load\_crab\_flux\_points() (in module gammapy.datasets)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.load_crab_flux_points:gammapy.datasets.load_crab_flux_points}\pysiglinewithargsret{\code{gammapy.datasets.}\bfcode{load\_crab\_flux\_points}}{\emph{component='both'}, \emph{with\_fermi\_flare=False}}{}
Load published Crab pulsar and nebula flux points.
Besides the usual flux point columns, this table contains
the following two columns:
\begin{itemize}
\item {}
component : \{`pulsar', `nebula'\}
\item {}
paper : Short string describing which point originates from which paper.
\end{itemize}
TODO:
\begin{itemize}
\item {}
Add link to Crab flux point tutorial in Gammapy where these points are plotted.
\item {}
Add html links to ADS directly in the docstring and as a table column.
\end{itemize}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{component} : \{`pulsar', `nebula', `both'\}
\begin{quote}
Which emission component to include
\end{quote}
\item[{Returns}] \leavevmode
\textbf{flux\_points} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Flux point table
\end{quote}
\end{description}\end{quote}
\paragraph{Notes}
This data compilation is from Buehler and Blandford, Rep. Prog. Phys. 77, 2014.
It was contributed to Gammapy directly by Rolf Buehler via a pull request.
The data for the nebula were taken from Meyer et al. Astron. Astrophys. 523 2010
with the addition of the Fermi-LAT measurement reported in Buehler et al. ApJ 749 2012.
The pulsar spectrum is reproduced from Kuiper et al Astron. Astrophys. 378 2001 .
Additionally shown are infrared measurements reported in Sollerman et al. ApJ 537 2000
and Tziamtzis et al. Astron. Astrophys. 508 2009, radio measurements referenced in
Thompson et al. ApJ 516 1999 and gamma-ray measurements referenced in
Aleksic et al. ApJ 742 2011, Aliu et al. Science 334 2011,
Aleksic et al. Astron. Astrophys. 540 2012
and Abdo et al. Astrophys. J. Suppl. Ser. 208 2013.
\end{fulllineitems}
\paragraph{load\_diffuse\_gamma\_spectrum}
\label{api/gammapy.datasets.load_diffuse_gamma_spectrum:astropy}\label{api/gammapy.datasets.load_diffuse_gamma_spectrum::doc}\label{api/gammapy.datasets.load_diffuse_gamma_spectrum:load-diffuse-gamma-spectrum}\index{load\_diffuse\_gamma\_spectrum() (in module gammapy.datasets)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.load_diffuse_gamma_spectrum:gammapy.datasets.load_diffuse_gamma_spectrum}\pysiglinewithargsret{\code{gammapy.datasets.}\bfcode{load\_diffuse\_gamma\_spectrum}}{\emph{reference}}{}
Load published diffuse gamma-ray spectrum.
TODO: give references to publications and describe the returned table.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{reference} : \{`Fermi', `Fermi2'\}
\begin{quote}
Which publication.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{spectrum} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Energy spectrum as a table (one flux point per row).
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{load\_electron\_spectrum}
\label{api/gammapy.datasets.load_electron_spectrum:astropy}\label{api/gammapy.datasets.load_electron_spectrum::doc}\label{api/gammapy.datasets.load_electron_spectrum:load-electron-spectrum}\index{load\_electron\_spectrum() (in module gammapy.datasets)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.load_electron_spectrum:gammapy.datasets.load_electron_spectrum}\pysiglinewithargsret{\code{gammapy.datasets.}\bfcode{load\_electron\_spectrum}}{\emph{reference}}{}
Load published electron spectrum.
TODO: give references to publications and describe the returned table.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{reference} : \{`HESS', `HESS low energy', `Fermi'\}
\begin{quote}
Which publication.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{spectrum} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Energy spectrum as a table (one flux point per row).
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{load\_lat\_psf\_performance}
\label{api/gammapy.datasets.load_lat_psf_performance:astropy}\label{api/gammapy.datasets.load_lat_psf_performance::doc}\label{api/gammapy.datasets.load_lat_psf_performance:load-lat-psf-performance}\index{load\_lat\_psf\_performance() (in module gammapy.datasets)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.load_lat_psf_performance:gammapy.datasets.load_lat_psf_performance}\pysiglinewithargsret{\code{gammapy.datasets.}\bfcode{load\_lat\_psf\_performance}}{\emph{performance\_file}}{}
Loads Fermi-LAT TOTAL PSF performance data.
These points are extracted by hand from:
\begin{itemize}
\item {}
\href{http://www.slac.stanford.edu/exp/glast/groups/canda/archive/p7rep\_v15/lat\_Performance\_files/cPsfEnergy\_P7REP\_SOURCE\_V15.png}{PSF\_P7REP\_SOURCE\_V15}
\item {}
\href{http://www.slac.stanford.edu/exp/glast/groups/canda/archive/pass7v6/lat\_Performance\_files/cPsfEnergy\_P7SOURCE\_V6.png}{PSF\_P7SOURCEV6}
\end{itemize}
As such, a 10\% error in the values should be assumed.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{performance\_file} : str
\begin{quote}
Specify which PSF performance file to return.
\begin{itemize}
\item {}
\code{P7REP\_SOURCE\_V15\_68} P7REP\_SOURCE\_V15, 68\% containment
\item {}
\code{P7REP\_SOURCE\_V15\_95} P7REP\_SOURCE\_V15, 95\% containment
\item {}
\code{P7SOURCEV6\_68} P7SOURCEV6, 68\% containment
\item {}
\code{P7SOURCEV6\_95} P7SOURCEV6, 95\% containment
\end{itemize}
\end{quote}
\item[{Returns}] \leavevmode
\textbf{table} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Table of psf size (deg) for selected containment radius and IRF at
energies (MeV).
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{load\_poisson\_stats\_image}
\label{api/gammapy.datasets.load_poisson_stats_image:astropy}\label{api/gammapy.datasets.load_poisson_stats_image::doc}\label{api/gammapy.datasets.load_poisson_stats_image:load-poisson-stats-image}\index{load\_poisson\_stats\_image() (in module gammapy.datasets)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.load_poisson_stats_image:gammapy.datasets.load_poisson_stats_image}\pysiglinewithargsret{\code{gammapy.datasets.}\bfcode{load\_poisson\_stats\_image}}{\emph{extra\_info=False}, \emph{return\_filenames=False}}{}
Load Poisson statistics counts image of a Gaussian source on flat background.
See poissson\_stats\_image/README.md for further info.
TODO: add better description (extract from README?)
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{extra\_info} : bool
\begin{quote}
If true, a dict of images is returned.
\end{quote}
\textbf{return\_filenames} : bool
\begin{quote}
If true, return filenames instead of images
\end{quote}
\item[{Returns}] \leavevmode
\textbf{data} : numpy array or dict of arrays or filenames
\begin{quote}
Depending on the \code{extra\_info} and \code{return\_filenames} options.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{load\_psf\_fits\_table}
\label{api/gammapy.datasets.load_psf_fits_table:load-psf-fits-table}\label{api/gammapy.datasets.load_psf_fits_table:astropy}\label{api/gammapy.datasets.load_psf_fits_table::doc}\index{load\_psf\_fits\_table() (in module gammapy.datasets)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.load_psf_fits_table:gammapy.datasets.load_psf_fits_table}\pysiglinewithargsret{\code{gammapy.datasets.}\bfcode{load\_psf\_fits\_table}}{}{}
Load an example PSF FITS file..
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{hdu\_list} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}
\begin{quote}
ARF file contents.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{load\_tev\_spectrum}
\label{api/gammapy.datasets.load_tev_spectrum:astropy}\label{api/gammapy.datasets.load_tev_spectrum::doc}\label{api/gammapy.datasets.load_tev_spectrum:load-tev-spectrum}\index{load\_tev\_spectrum() (in module gammapy.datasets)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.load_tev_spectrum:gammapy.datasets.load_tev_spectrum}\pysiglinewithargsret{\code{gammapy.datasets.}\bfcode{load\_tev\_spectrum}}{\emph{source\_name}}{}
Load published TeV flux point measurements.
TODO: give references to publications and describe the returned table.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{source\_name} : str
\begin{quote}
Source name
\end{quote}
\item[{Returns}] \leavevmode
\textbf{spectrum} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Energy spectrum as a table (one flux point per row).
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{make\_test\_bg\_cube\_model}
\label{api/gammapy.datasets.make_test_bg_cube_model:astropy}\label{api/gammapy.datasets.make_test_bg_cube_model::doc}\label{api/gammapy.datasets.make_test_bg_cube_model:make-test-bg-cube-model}\index{make\_test\_bg\_cube\_model() (in module gammapy.datasets)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.make_test_bg_cube_model:gammapy.datasets.make_test_bg_cube_model}\pysiglinewithargsret{\code{gammapy.datasets.}\bfcode{make\_test\_bg\_cube\_model}}{\emph{detx\_range=\textless{}Angle {[}-10.}, \emph{10.{]} deg\textgreater{}}, \emph{ndetx\_bins=24}, \emph{dety\_range=\textless{}Angle {[}-10.}, \emph{10.{]} deg\textgreater{}}, \emph{ndety\_bins=24}, \emph{energy\_band=\textless{}Quantity {[} 1.00000000e-02}, \emph{1.00000000e+02{]} TeV\textgreater{}}, \emph{nenergy\_bins=14}, \emph{sigma=\textless{}Angle 5.0 deg\textgreater{}}, \emph{spectral\_index=2.7}, \emph{apply\_mask=False}}{}
Make a test bg cube model.
The background is created following a 2D symmetric gaussian
model for the spatial coordinates (X, Y) and a power-law in
energy.
The Gaussian width varies in energy from sigma/2 to sigma.
The power-law slope in log-log representation is given by
the spectral\_index parameter.
It is possible to mask 1/4th of the image (for \code{x \textgreater{} x\_center} and
\code{y \textgreater{} y\_center}). Useful for testing coordinate rotations.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{detx\_range} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}, optional
\begin{quote}
X coordinate range (min, max)
\end{quote}
\textbf{ndetx\_bins} : int, optional
\begin{quote}
number of (linear) bins in X coordinate
\end{quote}
\textbf{dety\_range} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}, optional
\begin{quote}
Y coordinate range (min, max)
\end{quote}
\textbf{ndety\_bins} : int, optional
\begin{quote}
number of (linear) bins in Y coordinate
\end{quote}
\textbf{energy\_band} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}, optional
\begin{quote}
energy range (min, max)
\end{quote}
\textbf{nenergy\_bins} : int, optional
\begin{quote}
number of (logarithmic) bins in energy
\end{quote}
\textbf{sigma} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}, optional
\begin{quote}
width of the gaussian model used for the spatial coordinates
\end{quote}
\textbf{spectral\_index} : double, optional
\begin{quote}
index for the power-law model used for the energy coordinate
\end{quote}
\textbf{apply\_mask} : bool, optional
\begin{quote}
if set, 1/4th of the image is masked (for \code{x \textgreater{} x\_center} and
\code{y \textgreater{} y\_center})
\end{quote}
\item[{Returns}] \leavevmode
\textbf{bg\_cube\_model} : {\hyperref[api/gammapy.background.CubeBackgroundModel:gammapy.background.CubeBackgroundModel]{\emph{\code{CubeBackgroundModel}}}}
\begin{quote}
bg cube model
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{make\_test\_observation\_table}
\label{api/gammapy.datasets.make_test_observation_table:astropy}\label{api/gammapy.datasets.make_test_observation_table::doc}\label{api/gammapy.datasets.make_test_observation_table:make-test-observation-table}\index{make\_test\_observation\_table() (in module gammapy.datasets)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.make_test_observation_table:gammapy.datasets.make_test_observation_table}\pysiglinewithargsret{\code{gammapy.datasets.}\bfcode{make\_test\_observation\_table}}{\emph{observatory\_name}, \emph{n\_obs}, \emph{debug=False}, \emph{random\_state='random-seed'}}{}
Make a test observation table.
For the moment, only random observation tables are created.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{observatory\_name} : str
\begin{quote}
name of the observatory; a list of choices is given in \code{observatory\_locations}
\end{quote}
\textbf{n\_obs} : int
\begin{quote}
number of observations for the obs table
\end{quote}
\textbf{debug} : bool, optional
\begin{quote}
show UTC times instead of seconds after the reference
\end{quote}
\textbf{random\_state} : \{int, `random-seed', `global-rng', \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.RandomState.html\#numpy.random.RandomState}{\code{RandomState}}\}
\begin{quote}
Defines random number generator initialisation.
Passed to {\hyperref[api/gammapy.utils.random.get_random_state:gammapy.utils.random.get_random_state]{\emph{\code{get\_random\_state}}}}.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{obs\_table} : {\hyperref[api/gammapy.obs.ObservationTable:gammapy.obs.ObservationTable]{\emph{\code{ObservationTable}}}}
\begin{quote}
observation table
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{make\_test\_psf}
\label{api/gammapy.datasets.make_test_psf:astropy}\label{api/gammapy.datasets.make_test_psf::doc}\label{api/gammapy.datasets.make_test_psf:make-test-psf}\index{make\_test\_psf() (in module gammapy.datasets)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.make_test_psf:gammapy.datasets.make_test_psf}\pysiglinewithargsret{\code{gammapy.datasets.}\bfcode{make\_test\_psf}}{\emph{energy\_bins=15}, \emph{theta\_bins=12}}{}
Create a test FITS PSF file.
A log-linear dependency in energy is assumed, where the size of
the PSF decreases by a factor of tow over tow decades. The
theta dependency is a parabola where at theta = 2 deg the size
of the PSF has increased by 30\%.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energy\_bins} : int
\begin{quote}
Number of energy bins
\end{quote}
\textbf{theta\_bins} : int
\begin{quote}
Number of theta bins
\end{quote}
\item[{Returns}] \leavevmode
\textbf{psf} : {\hyperref[api/gammapy.irf.EnergyDependentMultiGaussPSF:gammapy.irf.EnergyDependentMultiGaussPSF]{\emph{\code{EnergyDependentMultiGaussPSF}}}}
\begin{quote}
PSF
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\subsubsection{Classes}
\label{datasets/index:astropy}\label{datasets/index:classes}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.datasets.FermiGalacticCenter:gammapy.datasets.FermiGalacticCenter]{\emph{\code{FermiGalacticCenter}}}}
&
Fermi high-energy data for the Galactic center region.
\\
\hline
{\hyperref[api/gammapy.datasets.FermiVelaRegion:gammapy.datasets.FermiVelaRegion]{\emph{\code{FermiVelaRegion}}}}
&
Fermi high-energy data for the Vela region.
\\
\hline\end{longtable}
\paragraph{FermiGalacticCenter}
\label{api/gammapy.datasets.FermiGalacticCenter::doc}\label{api/gammapy.datasets.FermiGalacticCenter:fermigalacticcenter}\index{FermiGalacticCenter (class in gammapy.datasets)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.FermiGalacticCenter:gammapy.datasets.FermiGalacticCenter}\pysigline{\strong{class }\code{gammapy.datasets.}\bfcode{FermiGalacticCenter}}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Fermi high-energy data for the Galactic center region.
For details, see this
\href{https://github.com/gammapy/gammapy/blob/master/gammapy/datasets/data/fermi/README.rst}{README file}.
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{counts() (gammapy.datasets.FermiGalacticCenter static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.FermiGalacticCenter:gammapy.datasets.FermiGalacticCenter.counts}\pysiglinewithargsret{\strong{static }\bfcode{counts}}{}{}
Counts image as \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{astropy.io.fits.ImageHDU}}.
\end{fulllineitems}
\index{diffuse\_model() (gammapy.datasets.FermiGalacticCenter static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.FermiGalacticCenter:gammapy.datasets.FermiGalacticCenter.diffuse_model}\pysiglinewithargsret{\strong{static }\bfcode{diffuse\_model}}{}{}
Diffuse model spectral cube.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{spectral\_cube} : {\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube]{\emph{\code{SpectralCube}}}}
\begin{quote}
Diffuse model spectral cube
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{exposure\_cube() (gammapy.datasets.FermiGalacticCenter static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.FermiGalacticCenter:gammapy.datasets.FermiGalacticCenter.exposure_cube}\pysiglinewithargsret{\strong{static }\bfcode{exposure\_cube}}{}{}
Exposure cube.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{spectral\_cube} : {\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube]{\emph{\code{SpectralCube}}}}
\begin{quote}
Exposure cube
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{filenames() (gammapy.datasets.FermiGalacticCenter static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.FermiGalacticCenter:gammapy.datasets.FermiGalacticCenter.filenames}\pysiglinewithargsret{\strong{static }\bfcode{filenames}}{}{}
Dictionary of available file names.
\end{fulllineitems}
\index{psf() (gammapy.datasets.FermiGalacticCenter static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.FermiGalacticCenter:gammapy.datasets.FermiGalacticCenter.psf}\pysiglinewithargsret{\strong{static }\bfcode{psf}}{}{}
PSF as {\hyperref[api/gammapy.irf.EnergyDependentTablePSF:gammapy.irf.EnergyDependentTablePSF]{\emph{\code{EnergyDependentTablePSF}}}}.
\end{fulllineitems}
\end{fulllineitems}
\paragraph{FermiVelaRegion}
\label{api/gammapy.datasets.FermiVelaRegion:fermivelaregion}\label{api/gammapy.datasets.FermiVelaRegion:astropy}\label{api/gammapy.datasets.FermiVelaRegion::doc}\index{FermiVelaRegion (class in gammapy.datasets)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.FermiVelaRegion:gammapy.datasets.FermiVelaRegion}\pysigline{\strong{class }\code{gammapy.datasets.}\bfcode{FermiVelaRegion}}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Fermi high-energy data for the Vela region.
For details, see
\href{https://github.com/gammapy/gammapy-extra/blob/master/datasets/vela\_region/README.rst}{README file for FermiVelaRegion}.
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{background\_image() (gammapy.datasets.FermiVelaRegion static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.FermiVelaRegion:gammapy.datasets.FermiVelaRegion.background_image}\pysiglinewithargsret{\strong{static }\bfcode{background\_image}}{}{}
Predicted background counts image.
Based on the Fermi Diffuse model (see class docstring).
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{background\_cube} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdus.html\#astropy.io.fits.PrimaryHDU}{\code{PrimaryHDU}}
\begin{quote}
Diffuse model image.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{counts\_cube() (gammapy.datasets.FermiVelaRegion static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.FermiVelaRegion:gammapy.datasets.FermiVelaRegion.counts_cube}\pysiglinewithargsret{\strong{static }\bfcode{counts\_cube}}{}{}
Counts cube.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{hdu\_list} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}
\begin{itemize}
\item {}
Counts cube \href{http://docs.astropy.org/en/latest/io/fits/api/hdus.html\#astropy.io.fits.PrimaryHDU}{\code{PrimaryHDU}}.
\item {}
Energy bins \href{http://docs.astropy.org/en/latest/io/fits/api/tables.html\#astropy.io.fits.BinTableHDU}{\code{BinTableHDU}}.
\item {}
MET bins \href{http://docs.astropy.org/en/latest/io/fits/api/tables.html\#astropy.io.fits.BinTableHDU}{\code{BinTableHDU}}.
\end{itemize}
\end{description}\end{quote}
\end{fulllineitems}
\index{diffuse\_model() (gammapy.datasets.FermiVelaRegion static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.FermiVelaRegion:gammapy.datasets.FermiVelaRegion.diffuse_model}\pysiglinewithargsret{\strong{static }\bfcode{diffuse\_model}}{}{}
Diffuse model spectral cube cutout for Vela region.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{spectral\_cube} : {\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube]{\emph{\code{SpectralCube}}}}
\begin{quote}
Diffuse model spectral cube
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{events() (gammapy.datasets.FermiVelaRegion static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.FermiVelaRegion:gammapy.datasets.FermiVelaRegion.events}\pysiglinewithargsret{\strong{static }\bfcode{events}}{}{}
Fermi Events list for Vela Region.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{hdu\_list} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}.
\begin{quote}
Events list.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{exposure\_cube() (gammapy.datasets.FermiVelaRegion static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.FermiVelaRegion:gammapy.datasets.FermiVelaRegion.exposure_cube}\pysiglinewithargsret{\strong{static }\bfcode{exposure\_cube}}{}{}
Exposure cube.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{exposure\_cube} : {\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube]{\emph{\code{SpectralCube}}}}
\begin{quote}
Exposure cube
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{filenames() (gammapy.datasets.FermiVelaRegion static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.FermiVelaRegion:gammapy.datasets.FermiVelaRegion.filenames}\pysiglinewithargsret{\strong{static }\bfcode{filenames}}{}{}
Dictionary of available file names.
\end{fulllineitems}
\index{livetime\_cube() (gammapy.datasets.FermiVelaRegion static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.FermiVelaRegion:gammapy.datasets.FermiVelaRegion.livetime_cube}\pysiglinewithargsret{\strong{static }\bfcode{livetime\_cube}}{}{}
Livetime cube.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{livetime\_cube} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}
\begin{quote}
Livetime cube hdu\_list
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{predicted\_image() (gammapy.datasets.FermiVelaRegion static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.FermiVelaRegion:gammapy.datasets.FermiVelaRegion.predicted_image}\pysiglinewithargsret{\strong{static }\bfcode{predicted\_image}}{}{}
Predicted counts spectral image including Vela Pulsar.
Based on the Fermi Diffuse model (see class docstring) and
Vela Point source model.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{background\_cube} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdus.html\#astropy.io.fits.PrimaryHDU}{\code{PrimaryHDU}}
\begin{quote}
Predicted model image.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{psf() (gammapy.datasets.FermiVelaRegion static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.datasets.FermiVelaRegion:gammapy.datasets.FermiVelaRegion.psf}\pysiglinewithargsret{\strong{static }\bfcode{psf}}{}{}
Fermi PSF for the Vela region.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{psf} : {\hyperref[api/gammapy.irf.EnergyDependentTablePSF:gammapy.irf.EnergyDependentTablePSF]{\emph{\code{EnergyDependentTablePSF}}}}.
\begin{quote}
PSF
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\end{fulllineitems}
\chapter{Source detection tools (\texttt{gammapy.detect})}
\label{detect/index:detect}\label{detect/index:astropy}\label{detect/index::doc}\label{detect/index:source-detection-tools-gammapy-detect}
\section{Introduction}
\label{detect/index:introduction}
{\hyperref[detect/index:module-gammapy.detect]{\emph{\code{gammapy.detect}}}} holds source detection methods that turn event lists or images or cubes
into source catalogs.
\begin{itemize}
\item {}
TODO: Describe references: \phantomsection\label{detect/index:id1}{\hyperref[references:stewart2009]{\emph{{[}Stewart2009{]}}}}
\item {}
TODO: general intro
\item {}
TODO: describe the \code{gammapy-iterative-source-detect} tool.
\item {}
TODO: describe the \code{gammapy-image-decompose-a-trous} tool.
\end{itemize}
\section{Getting Started}
\label{detect/index:getting-started}
\subsection{Computation of TS maps}
\label{detect/index:computation-of-ts-maps}
The {\hyperref[detect/index:module-gammapy.detect]{\emph{\code{gammapy.detect}}}} module includes a high performance {\hyperref[api/gammapy.detect.compute_ts_map:gammapy.detect.compute_ts_map]{\emph{\code{compute\_ts\_map}}}} function to
compute test statistics (TS) maps for Gamma-Ray survey data. The implementation is based on the method
described in \phantomsection\label{detect/index:id2}{\hyperref[references:stewart2009]{\emph{{[}Stewart2009{]}}}}.
Assuming a certain source morphology, which can be defined by any \href{http://docs.astropy.org/en/latest/api/astropy.convolution.Kernel2D.html\#astropy.convolution.Kernel2D}{\code{astropy.convolution.Kernel2D}}
instance, the amplitude of the morphology model is fitted at every pixel of the input data using a
Poisson maximum likelihood procedure. As input data a counts, background and exposure map have to be provided.
Based on the best fit flux amplitude, the change in TS, compared to the null hypothesis is computed
using {\hyperref[api/gammapy.stats.cash:gammapy.stats.cash]{\emph{\code{cash}}}} statistics.
To optimize the performance of the code, the fitting procedure is simplified by finding roots
of the derivative of the fit statistics with respect to the flux amplitude. This approach is
described in detail in Appendix A of \phantomsection\label{detect/index:id3}{\hyperref[references:stewart2009]{\emph{{[}Stewart2009{]}}}}. To further improve the performance,
Pythons's \href{http://docs.python.org/library/multiprocessing.html\#module-multiprocessing}{\code{multiprocessing}} facility is used.
In the following the computation of a TS map for prepared Fermi survey data, which is provided in
\href{https://github.com/gammapy/gammapy-extra/tree/master/datasets/fermi\_survey}{gammapy-extra}, shall be demonstrated:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{astropy.io} \PYG{k+kn}{import} \PYG{n}{fits}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.convolution} \PYG{k+kn}{import} \PYG{n}{Gaussian2DKernel}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.detect} \PYG{k+kn}{import} \PYG{n}{compute\PYGZus{}ts\PYGZus{}map}
\PYG{n}{hdu\PYGZus{}list} \PYG{o}{=} \PYG{n}{fits}\PYG{o}{.}\PYG{n}{open}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{all.fits.gz}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{kernel} \PYG{o}{=} \PYG{n}{Gaussian2DKernel}\PYG{p}{(}\PYG{l+m+mi}{5}\PYG{p}{)}
\PYG{n}{result} \PYG{o}{=} \PYG{n}{compute\PYGZus{}ts\PYGZus{}map}\PYG{p}{(}\PYG{n}{hdu\PYGZus{}list}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{On}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{o}{.}\PYG{n}{data}\PYG{p}{,} \PYG{n}{hdu\PYGZus{}list}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{Background}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{o}{.}\PYG{n}{data}\PYG{p}{,}
\PYG{n}{hdu\PYGZus{}list}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{ExpGammaMap}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}\PYG{o}{.}\PYG{n}{data}\PYG{p}{,} \PYG{n}{kernel}\PYG{p}{)}
\end{Verbatim}
The function returns a {\hyperref[api/gammapy.detect.TSMapResult:gammapy.detect.TSMapResult]{\emph{\code{TSMapResult}}}} object, that bundles all relevant
data. E.g. the time needed for the TS map computation can be checked by:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{print}\PYG{p}{(}\PYG{n}{result}\PYG{o}{.}\PYG{n}{runtime}\PYG{p}{)}
\end{Verbatim}
The TS map itself can bes accessed using the \code{ts} attribute of the {\hyperref[api/gammapy.detect.TSMapResult:gammapy.detect.TSMapResult]{\emph{\code{TSMapResult}}}} object:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{print}\PYG{p}{(}\PYG{n}{result}\PYG{o}{.}\PYG{n}{ts}\PYG{o}{.}\PYG{n}{max}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}
\end{Verbatim}
\subsection{Command line tool}
\label{detect/index:command-line-tool}
Gammapy also provides a command line tool \code{gammapy-ts-image} for TS map computation, which can be run
on the Fermi example dataset by:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }\PYG{n+nb}{cd }gammapy\PYGZhy{}extra/datasets/fermi\PYGZus{}survey
\PYG{n+nv}{\PYGZdl{} }gammapy\PYGZhy{}ts\PYGZhy{}image all.fits.gz ts\PYGZus{}map\PYGZus{}0.00.fits \PYGZhy{}\PYGZhy{}scale 0
\end{Verbatim}
The command line tool additionally requires a psf json file, where the psf shape is defined by the parameters
of a triple Gaussian model. See also {\hyperref[api/gammapy.irf.multi_gauss_psf_kernel:gammapy.irf.multi_gauss_psf_kernel]{\emph{\code{gammapy.irf.multi\_gauss\_psf\_kernel}}}}. By default the command line tool uses
a Gaussian source kernel, where the width in degree can be defined by the \code{-{-}scale} parameter. When setting
\code{-{-}scale 0} only the psf is used as source model, which is the preferred setting to detect point sources.
When using scales that are larger than five times the binning of the data, the data is sampled down and later
sampled up again to speed up the performance. See {\hyperref[api/gammapy.image.downsample_2N:gammapy.image.downsample_2N]{\emph{\code{downsample\_2N}}}} and {\hyperref[api/gammapy.image.upsample_2N:gammapy.image.upsample_2N]{\emph{\code{upsample\_2N}}}} for details.
Furthermore it is possible to compute residual TS maps. Using the following options:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }gammapy\PYGZhy{}ts\PYGZhy{}image all.fits.gz residual\PYGZus{}ts\PYGZus{}map\PYGZus{}0.00.fits \PYGZhy{}\PYGZhy{}scale \PYG{l+m}{0} \PYGZhy{}\PYGZhy{}residual \PYGZhy{}\PYGZhy{}model model.fits.gz
\end{Verbatim}
When \code{-{-}residual} is set an excess model must be provided using the \code{-{-}model} option.
\section{Reference/API}
\label{detect/index:reference-api}
\subsection{gammapy.detect Package}
\label{detect/index:gammapy-detect-package}\label{detect/index:module-gammapy.detect}\index{gammapy.detect (module)}
Source detection and measurement methods.
\subsubsection{Functions}
\label{detect/index:functions}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.detect.compute_maximum_ts_map:gammapy.detect.compute_maximum_ts_map]{\emph{\code{compute\_maximum\_ts\_map}}}}(ts\_map\_results)
&
Compute maximum TS map across a list of given {\hyperref[api/gammapy.detect.TSMapResult:gammapy.detect.TSMapResult]{\emph{\code{TSMapResult}}}} objects.
\\
\hline
{\hyperref[api/gammapy.detect.compute_ts_map:gammapy.detect.compute_ts_map]{\emph{\code{compute\_ts\_map}}}}(counts, background, exposure, ...)
&
Compute TS map using different optimization methods.
\\
\hline
{\hyperref[api/gammapy.detect.compute_ts_map_multiscale:gammapy.detect.compute_ts_map_multiscale]{\emph{\code{compute\_ts\_map\_multiscale}}}}(maps, psf\_parameters)
&
Compute multiscale TS maps using compute\_ts\_map.
\\
\hline
{\hyperref[api/gammapy.detect.probability_center:gammapy.detect.probability_center]{\emph{\code{probability\_center}}}}(images, kernel)
&
Compute matched-filter p-value at the kernel center.
\\
\hline
{\hyperref[api/gammapy.detect.probability_image:gammapy.detect.probability_image]{\emph{\code{probability\_image}}}}(images, kernel)
&
Compute matched-filter p-value image.
\\
\hline
{\hyperref[api/gammapy.detect.sex:gammapy.detect.sex]{\emph{\code{sex}}}}(image{[}, image2, catalog\_name, ...{]})
&
Run SExtractor to detect sources in an image.
\\
\hline
{\hyperref[api/gammapy.detect.significance_center:gammapy.detect.significance_center]{\emph{\code{significance\_center}}}}(images, kernel)
&
Compute matched-filter significance at the kernel center.
\\
\hline
{\hyperref[api/gammapy.detect.significance_image:gammapy.detect.significance_image]{\emph{\code{significance\_image}}}}(images, kernel)
&
Compute matched-filter significance image.
\\
\hline\end{longtable}
\paragraph{compute\_maximum\_ts\_map}
\label{api/gammapy.detect.compute_maximum_ts_map:compute-maximum-ts-map}\label{api/gammapy.detect.compute_maximum_ts_map::doc}\index{compute\_maximum\_ts\_map() (in module gammapy.detect)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.compute_maximum_ts_map:gammapy.detect.compute_maximum_ts_map}\pysiglinewithargsret{\code{gammapy.detect.}\bfcode{compute\_maximum\_ts\_map}}{\emph{ts\_map\_results}}{}
Compute maximum TS map across a list of given {\hyperref[api/gammapy.detect.TSMapResult:gammapy.detect.TSMapResult]{\emph{\code{TSMapResult}}}} objects.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{ts\_map\_results} : list
\begin{quote}
List of {\hyperref[api/gammapy.detect.TSMapResult:gammapy.detect.TSMapResult]{\emph{\code{TSMapResult}}}} objects.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{TS} : {\hyperref[api/gammapy.detect.TSMapResult:gammapy.detect.TSMapResult]{\emph{\code{TSMapResult}}}}
\begin{quote}
{\hyperref[api/gammapy.detect.TSMapResult:gammapy.detect.TSMapResult]{\emph{\code{TSMapResult}}}} object.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{compute\_ts\_map}
\label{api/gammapy.detect.compute_ts_map:astropy}\label{api/gammapy.detect.compute_ts_map::doc}\label{api/gammapy.detect.compute_ts_map:compute-ts-map}\index{compute\_ts\_map() (in module gammapy.detect)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.compute_ts_map:gammapy.detect.compute_ts_map}\pysiglinewithargsret{\code{gammapy.detect.}\bfcode{compute\_ts\_map}}{\emph{counts}, \emph{background}, \emph{exposure}, \emph{kernel}, \emph{mask=None}, \emph{flux=None}, \emph{method='root brentq'}, \emph{optimizer='Brent'}, \emph{parallel=True}, \emph{threshold=None}}{}
Compute TS map using different optimization methods.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{counts} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Count map
\end{quote}
\textbf{background} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Background map
\end{quote}
\textbf{exposure} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Exposure map
\end{quote}
\textbf{kernel} : \href{http://docs.astropy.org/en/latest/api/astropy.convolution.Kernel2D.html\#astropy.convolution.Kernel2D}{\code{astropy.convolution.Kernel2D}}
\begin{quote}
Source model kernel.
\end{quote}
\textbf{flux} : float (None)
\begin{quote}
Flux map used as a starting value for the amplitude fit.
\end{quote}
\textbf{method} : str (`root')
\begin{quote}
\begin{description}
\item[{The following options are available:}] \leavevmode\begin{itemize}
\item {} \begin{description}
\item[{\code{'root'} (default)}] \leavevmode
Fit amplitude finding roots of the the derivative of
the fit statistics. Described in Appendix A in Stewart (2009).
\end{description}
\item {} \begin{description}
\item[{\code{'fit scipy'}}] \leavevmode
Use \href{http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize\_scalar.html\#scipy.optimize.minimize\_scalar}{\code{scipy.optimize.minimize\_scalar}} for fitting.
\end{description}
\item {} \begin{description}
\item[{\code{'fit minuit'}}] \leavevmode
Use minuit for fitting.
\end{description}
\end{itemize}
\end{description}
\end{quote}
\textbf{optimizer} : str (`Brent')
\begin{quote}
Which optimizing algorithm to use from scipy. See
\href{http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize\_scalar.html\#scipy.optimize.minimize\_scalar}{\code{scipy.optimize.minimize\_scalar}} for options.
\end{quote}
\textbf{parallel} : bool (True)
\begin{quote}
Whether to use multiple cores for parallel processing.
\end{quote}
\textbf{threshold} : float (None)
\begin{quote}
If the TS value corresponding to the initial flux estimate is not above
this threshold, the optimizing step is omitted to save computing time.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{TS} : {\hyperref[api/gammapy.detect.TSMapResult:gammapy.detect.TSMapResult]{\emph{\code{TSMapResult}}}}
\begin{quote}
{\hyperref[api/gammapy.detect.TSMapResult:gammapy.detect.TSMapResult]{\emph{\code{TSMapResult}}}} object.
\end{quote}
\end{description}\end{quote}
\paragraph{Notes}
Negative \(TS\) values are defined as following:
\begin{gather}
\begin{split}TS = \left \{
\begin{array}{ll}
-TS & : \textnormal{if} \ F < 0 \\
\ \ TS & : \textnormal{else}
\end{array}
\right.\end{split}\notag
\end{gather}
Where \(F\) is the fitted flux amplitude.
\paragraph{References}
\phantomsection\label{api/gammapy.detect.compute_ts_map:id1}{\hyperref[references:stewart2009]{\emph{{[}Stewart2009{]}}}}
\end{fulllineitems}
\paragraph{compute\_ts\_map\_multiscale}
\label{api/gammapy.detect.compute_ts_map_multiscale:compute-ts-map-multiscale}\label{api/gammapy.detect.compute_ts_map_multiscale:astropy}\label{api/gammapy.detect.compute_ts_map_multiscale::doc}\index{compute\_ts\_map\_multiscale() (in module gammapy.detect)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.compute_ts_map_multiscale:gammapy.detect.compute_ts_map_multiscale}\pysiglinewithargsret{\code{gammapy.detect.}\bfcode{compute\_ts\_map\_multiscale}}{\emph{maps, psf\_parameters, scales={[}0{]}, downsample='auto', residual=False, morphology='Gaussian2D', width=None, *args, **kwargs}}{}
Compute multiscale TS maps using compute\_ts\_map.
High level TS map computation using a multi gauss PSF kernel and assuming
a given source morphology. To optimize the performance the input data
can be sampled down when computing TS maps on larger scales.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{maps} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{astropy.io.fits.HDUList}}
\begin{quote}
\begin{description}
\item[{HDU list containing the data. The list must contain the following HDU extensions:}] \leavevmode\begin{itemize}
\item {}
`On', Counts image
\item {}
`Background', Background image
\item {}
`Diffuse', Diffuse model image
\item {}
`ExpGammaMap', Exposure image
\end{itemize}
\end{description}
\end{quote}
\textbf{psf\_parameters} : dict
\begin{quote}
Dict defining the multi gauss PSF parameters.
See \code{multi\_gauss\_psf} for details.
\end{quote}
\textbf{scales} : list ({[}0{]})
\begin{quote}
List of scales to use for TS map computation.
\end{quote}
\textbf{downsample} : int (`auto')
\begin{quote}
Down sampling factor. Can be set to `auto' if the down sampling
factor should be chosen automatically.
\end{quote}
\textbf{residual} : bool (False)
\begin{quote}
Compute a TS residual map.
\end{quote}
\textbf{morphology} : str (`Gaussian2D')
\begin{quote}
Source morphology assumption. Either `Gaussian2D' or `Shell2D'.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{multiscale\_result} : list
\begin{quote}
List of {\hyperref[api/gammapy.detect.TSMapResult:gammapy.detect.TSMapResult]{\emph{\code{TSMapResult}}}} objects.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{probability\_center}
\label{api/gammapy.detect.probability_center:astropy}\label{api/gammapy.detect.probability_center::doc}\label{api/gammapy.detect.probability_center:probability-center}\index{probability\_center() (in module gammapy.detect)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.probability_center:gammapy.detect.probability_center}\pysiglinewithargsret{\code{gammapy.detect.}\bfcode{probability\_center}}{\emph{images}, \emph{kernel}}{}
Compute matched-filter p-value at the kernel center.
The shapes of the images and the kernel must match.
\begin{description}
\item[{Reference: Appendix B.1.2 from Stewart (2009)}] \leavevmode
\href{http://adsabs.harvard.edu/abs/2009A\%26A...495..989S}{http://adsabs.harvard.edu/abs/2009A\%26A...495..989S}
\end{description}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{images} : dict of arrays
\begin{quote}
Keys: `counts', `background'
\end{quote}
\textbf{kernel} : array\_like
\begin{quote}
Kernel array
\end{quote}
\item[{Returns}] \leavevmode
\textbf{probability} : float
\begin{quote}
Probability that counts is not a background fluctuation
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{probability\_image}
\label{api/gammapy.detect.probability_image:astropy}\label{api/gammapy.detect.probability_image::doc}\label{api/gammapy.detect.probability_image:probability-image}\index{probability\_image() (in module gammapy.detect)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.probability_image:gammapy.detect.probability_image}\pysiglinewithargsret{\code{gammapy.detect.}\bfcode{probability\_image}}{\emph{images}, \emph{kernel}}{}
Compute matched-filter p-value image.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{images} : dict of arrays
\begin{quote}
Keys: `counts', `background'
\end{quote}
\textbf{kernel} : array\_like
\item[{Returns}] \leavevmode
\textbf{probability} : array
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{sex}
\label{api/gammapy.detect.sex:sex}\label{api/gammapy.detect.sex:astropy}\label{api/gammapy.detect.sex::doc}\index{sex() (in module gammapy.detect)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.sex:gammapy.detect.sex}\pysiglinewithargsret{\code{gammapy.detect.}\bfcode{sex}}{\emph{image}, \emph{image2='`}, \emph{catalog\_name=None}, \emph{config\_name=None}, \emph{parameters\_name=None}, \emph{checkimage\_name=None}, \emph{detect\_thresh=5}, \emph{detect\_minarea=1}, \emph{deblend\_mincont=1}}{}
Run SExtractor to detect sources in an image.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{image} : str
\begin{quote}
Detection image filename
\end{quote}
\textbf{image2} : str
\begin{quote}
Measurement image filename (same as image if `')
\end{quote}
\textbf{catalog\_name} : str
\begin{quote}
Output catalog filename
\end{quote}
\textbf{config\_name} : str
\begin{quote}
Config filename
\end{quote}
\textbf{parameters\_name} : str
\begin{quote}
Name of the file describing the catalog output parameters
\end{quote}
\textbf{checkimage\_name} : str
\begin{quote}
Filename for the check-image (TODO: none for `')
\end{quote}
\textbf{detect\_thresh} : float
\begin{quote}
Detection threshold
\end{quote}
\textbf{detect\_minarea} : int
\begin{quote}
Minimum number of pixels above threshold
\end{quote}
\textbf{deblend\_mincont} : float in range 0 to 1
\begin{quote}
Minimum contrast parameter for deblending.
\begin{itemize}
\item {}
0 = each peak is a single source
\item {}
1 = no deblending, one source per segment
\end{itemize}
\end{quote}
\item[{Returns}] \leavevmode
\textbf{catalog} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Catalog of detected objects
\end{quote}
\textbf{checkimage} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdus.html\#astropy.io.fits.PrimaryHDU}{\code{PrimaryHDU}}
\begin{quote}
Segmented image
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
TODO: look what other Python sextractor wrappers do:
TODO: where to run the command and put the output files?
TODO: return filenames or dict with results?
\end{fulllineitems}
\paragraph{significance\_center}
\label{api/gammapy.detect.significance_center:astropy}\label{api/gammapy.detect.significance_center::doc}\label{api/gammapy.detect.significance_center:significance-center}\index{significance\_center() (in module gammapy.detect)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.significance_center:gammapy.detect.significance_center}\pysiglinewithargsret{\code{gammapy.detect.}\bfcode{significance\_center}}{\emph{images}, \emph{kernel}}{}
Compute matched-filter significance at the kernel center.
See {\hyperref[api/gammapy.detect.probability_center:gammapy.detect.probability_center]{\emph{\code{probability\_center}}}} docstring.
\end{fulllineitems}
\paragraph{significance\_image}
\label{api/gammapy.detect.significance_image:significance-image}\label{api/gammapy.detect.significance_image:astropy}\label{api/gammapy.detect.significance_image::doc}\index{significance\_image() (in module gammapy.detect)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.significance_image:gammapy.detect.significance_image}\pysiglinewithargsret{\code{gammapy.detect.}\bfcode{significance\_image}}{\emph{images}, \emph{kernel}}{}
Compute matched-filter significance image.
See {\hyperref[api/gammapy.detect.probability_image:gammapy.detect.probability_image]{\emph{\code{probability\_image}}}} docstring.
\end{fulllineitems}
\subsubsection{Classes}
\label{detect/index:astropy}\label{detect/index:classes}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.detect.CWT:gammapy.detect.CWT]{\emph{\code{CWT}}}}(min\_scale, nscales, scale\_step)
&
Continuous wavelet transform.
\\
\hline
{\hyperref[api/gammapy.detect.IterativeSourceDetector:gammapy.detect.IterativeSourceDetector]{\emph{\code{IterativeSourceDetector}}}}(maps, scales{[}, ...{]})
&
An iterative source detection algorithm.
\\
\hline
{\hyperref[api/gammapy.detect.TSMapResult:gammapy.detect.TSMapResult]{\emph{\code{TSMapResult}}}}
&
Represents the TS map computation result.
\\
\hline\end{longtable}
\paragraph{CWT}
\label{api/gammapy.detect.CWT::doc}\label{api/gammapy.detect.CWT:cwt}\index{CWT (class in gammapy.detect)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.CWT:gammapy.detect.CWT}\pysiglinewithargsret{\strong{class }\code{gammapy.detect.}\bfcode{CWT}}{\emph{min\_scale}, \emph{nscales}, \emph{scale\_step}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Continuous wavelet transform.
TODO: describe algorithm
TODO: give references
Initialization of wavelet family.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{min\_scale} : float
\begin{quote}
first scale used
\end{quote}
\textbf{nscales} : int
\begin{quote}
number of scales considered
\end{quote}
\textbf{scale\_step} : float
\begin{quote}
base scaling factor
\end{quote}
\end{description}\end{quote}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{compute\_support\_peak() (gammapy.detect.CWT method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.CWT:gammapy.detect.CWT.compute_support_peak}\pysiglinewithargsret{\bfcode{compute\_support\_peak}}{\emph{nsigma=2.0}, \emph{nsigmap=4.0}, \emph{remove\_isolated=True}}{}
Compute the multiresolution support with hard sigma clipping.
Imposing a minimum significance on a connex region of significant pixels
(i.e. source detection)
\end{fulllineitems}
\index{do\_transform() (gammapy.detect.CWT method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.CWT:gammapy.detect.CWT.do_transform}\pysiglinewithargsret{\bfcode{do\_transform}}{}{}
Do the transform itself.
\end{fulllineitems}
\index{inverse\_transform() (gammapy.detect.CWT method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.CWT:gammapy.detect.CWT.inverse_transform}\pysiglinewithargsret{\bfcode{inverse\_transform}}{}{}
Do the inverse transform (reconstruct the image).
\end{fulllineitems}
\index{iterative\_filter\_peak() (gammapy.detect.CWT method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.CWT:gammapy.detect.CWT.iterative_filter_peak}\pysiglinewithargsret{\bfcode{iterative\_filter\_peak}}{\emph{nsigma=3.0}, \emph{nsigmap=4.0}, \emph{niter=2}, \emph{convergence=1e-05}}{}
Run iterative filter peak algorithm.
\end{fulllineitems}
\index{max\_scale\_image() (gammapy.detect.CWT method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.CWT:gammapy.detect.CWT.max_scale_image}\pysiglinewithargsret{\bfcode{max\_scale\_image}}{}{}
Compute the maximum scale image.
\end{fulllineitems}
\index{save\_filter() (gammapy.detect.CWT method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.CWT:gammapy.detect.CWT.save_filter}\pysiglinewithargsret{\bfcode{save\_filter}}{\emph{filename}, \emph{overwrite=False}}{}
Save filter to file.
\end{fulllineitems}
\index{set\_data() (gammapy.detect.CWT method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.CWT:gammapy.detect.CWT.set_data}\pysiglinewithargsret{\bfcode{set\_data}}{\emph{image}, \emph{background}}{}
Set input images.
\end{fulllineitems}
\index{set\_file() (gammapy.detect.CWT method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.CWT:gammapy.detect.CWT.set_file}\pysiglinewithargsret{\bfcode{set\_file}}{\emph{filename}}{}
Set input images from FITS file
\end{fulllineitems}
\end{fulllineitems}
\paragraph{IterativeSourceDetector}
\label{api/gammapy.detect.IterativeSourceDetector:astropy}\label{api/gammapy.detect.IterativeSourceDetector::doc}\label{api/gammapy.detect.IterativeSourceDetector:iterativesourcedetector}\index{IterativeSourceDetector (class in gammapy.detect)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.IterativeSourceDetector:gammapy.detect.IterativeSourceDetector}\pysiglinewithargsret{\strong{class }\code{gammapy.detect.}\bfcode{IterativeSourceDetector}}{\emph{maps}, \emph{scales}, \emph{max\_sources=10}, \emph{significance\_threshold=5}, \emph{max\_ncall=300}, \emph{debug\_output\_folder='`}, \emph{overwrite=False}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
An iterative source detection algorithm.
TODO: document
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{debug\_output\_folder} : str
\begin{quote}
Use empty string for no debug output.
\end{quote}
\end{description}\end{quote}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{compute\_iter\_maps() (gammapy.detect.IterativeSourceDetector method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.IterativeSourceDetector:gammapy.detect.IterativeSourceDetector.compute_iter_maps}\pysiglinewithargsret{\bfcode{compute\_iter\_maps}}{}{}
Compute maps for this iteration.
\end{fulllineitems}
\index{estimate\_flux() (gammapy.detect.IterativeSourceDetector method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.IterativeSourceDetector:gammapy.detect.IterativeSourceDetector.estimate_flux}\pysiglinewithargsret{\bfcode{estimate\_flux}}{\emph{source}, \emph{method='sum\_and\_divide'}}{}
Estimate flux in a circular region around the source.
Note: It's not clear which is the better flux estimate.
\begin{itemize}
\item {}
\code{method == 'sum\_and\_divide'}:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{flux} \PYG{o}{=} \PYG{p}{(}\PYG{n}{counts}\PYG{o}{.}\PYG{n}{sum}\PYG{p}{(}\PYG{p}{)} \PYG{o}{\PYGZhy{}} \PYG{n}{background}\PYG{o}{.}\PYG{n}{sum}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)} \PYG{o}{/} \PYG{n}{exposure}\PYG{o}{.}\PYG{n}{mean}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}
\item {}
\code{method = 'divide\_and\_sum'}:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{flux} \PYG{o}{=} \PYG{p}{(}\PYG{p}{(}\PYG{n}{counts} \PYG{o}{\PYGZhy{}} \PYG{n}{background}\PYG{p}{)} \PYG{o}{/} \PYG{n}{exposure}\PYG{p}{)}\PYG{o}{.}\PYG{n}{sum}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}
\end{itemize}
\end{fulllineitems}
\index{find\_peaks() (gammapy.detect.IterativeSourceDetector method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.IterativeSourceDetector:gammapy.detect.IterativeSourceDetector.find_peaks}\pysiglinewithargsret{\bfcode{find\_peaks}}{}{}
Find peaks in residual significance image.
\end{fulllineitems}
\index{fit\_source\_parameters() (gammapy.detect.IterativeSourceDetector method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.IterativeSourceDetector:gammapy.detect.IterativeSourceDetector.fit_source_parameters}\pysiglinewithargsret{\bfcode{fit\_source\_parameters}}{}{}
Fit source parameters using the guess as start values.
For this prototype we simply roll our own using iminuit,
this should probably be changed to astropy or Sherpa.
\end{fulllineitems}
\index{guess\_source\_parameters() (gammapy.detect.IterativeSourceDetector method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.IterativeSourceDetector:gammapy.detect.IterativeSourceDetector.guess_source_parameters}\pysiglinewithargsret{\bfcode{guess\_source\_parameters}}{}{}
Guess source start parameters for the fit.
At the moment take the position and scale of the maximum residual peak
and compute the excess within a circle around that position.
\end{fulllineitems}
\index{model\_excess() (gammapy.detect.IterativeSourceDetector method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.IterativeSourceDetector:gammapy.detect.IterativeSourceDetector.model_excess}\pysiglinewithargsret{\bfcode{model\_excess}}{\emph{sources}}{}
Compute model excess image.
\end{fulllineitems}
\index{run() (gammapy.detect.IterativeSourceDetector method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.IterativeSourceDetector:gammapy.detect.IterativeSourceDetector.run}\pysiglinewithargsret{\bfcode{run}}{}{}
Run source detection.
\end{fulllineitems}
\index{save\_fits() (gammapy.detect.IterativeSourceDetector method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.IterativeSourceDetector:gammapy.detect.IterativeSourceDetector.save_fits}\pysiglinewithargsret{\bfcode{save\_fits}}{\emph{filename}}{}
Save source catalog to FITS file.
\end{fulllineitems}
\index{save\_json() (gammapy.detect.IterativeSourceDetector method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.IterativeSourceDetector:gammapy.detect.IterativeSourceDetector.save_json}\pysiglinewithargsret{\bfcode{save\_json}}{\emph{filename}}{}
Save source catalog to JSON file.
\end{fulllineitems}
\index{save\_regions() (gammapy.detect.IterativeSourceDetector method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.IterativeSourceDetector:gammapy.detect.IterativeSourceDetector.save_regions}\pysiglinewithargsret{\bfcode{save\_regions}}{\emph{filename}, \emph{selection='fit'}}{}
Save ds9 region file.
\end{fulllineitems}
\index{stop\_iteration() (gammapy.detect.IterativeSourceDetector method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.IterativeSourceDetector:gammapy.detect.IterativeSourceDetector.stop_iteration}\pysiglinewithargsret{\bfcode{stop\_iteration}}{}{}
Criteria to stop the iteration process.
\end{fulllineitems}
\end{fulllineitems}
\paragraph{TSMapResult}
\label{api/gammapy.detect.TSMapResult:astropy}\label{api/gammapy.detect.TSMapResult::doc}\label{api/gammapy.detect.TSMapResult:tsmapresult}\index{TSMapResult (class in gammapy.detect)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.TSMapResult:gammapy.detect.TSMapResult}\pysigline{\strong{class }\code{gammapy.detect.}\bfcode{TSMapResult}}
Bases: \code{gammapy.extern.bunch.Bunch}
Represents the TS map computation result.
\paragraph{Attributes}
\begin{tabulary}{\linewidth}{|L|L|}
\hline
ts
&
(\href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}) Estimated TS map
\\
\hline
sqrt\_ts
&
(\href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}) Estimated sqrt(TS) map
\\
\hline
amplitude
&
(\href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}) Estimated best fit flux amplitude map
\\
\hline
niter
&
(\href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}) Number of iterations map
\\
\hline
runtime
&
(float) Time needed to compute TS map.
\\
\hline
scale
&
(float) Scale parameter.
\\
\hline
morphology
&
(str) Source morphology assumption.
\\
\hline\end{tabulary}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{read() (gammapy.detect.TSMapResult static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.TSMapResult:gammapy.detect.TSMapResult.read}\pysiglinewithargsret{\strong{static }\bfcode{read}}{\emph{filename}}{}
Read TS map result from file.
\end{fulllineitems}
\index{write() (gammapy.detect.TSMapResult method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.detect.TSMapResult:gammapy.detect.TSMapResult.write}\pysiglinewithargsret{\bfcode{write}}{\emph{filename}, \emph{header}, \emph{overwrite=False}}{}
Write TS map results to file.
\end{fulllineitems}
\end{fulllineitems}
\chapter{Image processing and analysis tools (\texttt{gammapy.image})}
\label{image/index:astropy}\label{image/index::doc}\label{image/index:image-processing-and-analysis-tools-gammapy-image}\label{image/index:image}
\section{Introduction}
\label{image/index:introduction}
{\hyperref[image/index:module-gammapy.image]{\emph{\code{gammapy.image}}}} contains some image processing and analysis methods that are not readily available elsewhere.
The goal is to contribute most of these methods to \href{http://docs.scipy.org/doc/scipy/reference/ndimage.html\#module-scipy.ndimage}{\code{scipy.ndimage}}, \href{http://scikit-image.org}{scikit-image}, \href{http://astropy.org}{astropy} or \href{http://photutils.readthedocs.org}{photutils},
and to only keep gamma-ray analysis specific functionality here.
\section{Getting Started}
\label{image/index:getting-started}
Most of the functions in this module have objects of type \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html\#numpy.array}{\code{numpy.array}}
or an \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{astropy.io.fits.ImageHDU}} or \href{http://docs.astropy.org/en/latest/io/fits/api/hdus.html\#astropy.io.fits.PrimaryHDU}{\code{astropy.io.fits.PrimaryHDU}}
as input and output:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.datasets} \PYG{k+kn}{import} \PYG{n}{poisson\PYGZus{}stats\PYGZus{}image}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.image} \PYG{k+kn}{import} \PYG{n}{lookup}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{image} \PYG{o}{=} \PYG{n}{poisson\PYGZus{}stats\PYGZus{}image}\PYG{p}{(}\PYG{p}{)} \PYG{c}{\PYGZsh{} image is a 2D numpy array}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{lookup}\PYG{p}{(}\PYG{n}{image}\PYG{p}{,} \PYG{l+m+mi}{42}\PYG{p}{,} \PYG{l+m+mi}{44}\PYG{p}{,} \PYG{n}{world}\PYG{o}{=}\PYG{n+nb+bp}{False}\PYG{p}{)}
\PYG{g+go}{3.0}
\end{Verbatim}
\section{Using \texttt{gammapy.image}}
\label{image/index:using-gammapy-image}
\subsection{Image plotting}
\label{image/plotting:image-plotting}\label{image/plotting:id1}\label{image/plotting::doc}
{\hyperref[image/index:module-gammapy.image]{\emph{\code{gammapy.image}}}} provides a few helper functions and classes to create
publication-quality images.
\subsubsection{Colormaps}
\label{image/plotting:colormaps}
The following example shows how to plot images using colormaps that are commonly
used in gamma-ray astronomy ({\hyperref[api/gammapy.image.colormap_hess:gammapy.image.colormap_hess]{\emph{\code{colormap\_hess}}}} and {\hyperref[api/gammapy.image.colormap_milagro:gammapy.image.colormap_milagro]{\emph{\code{colormap\_milagro}}}}).
\includegraphics{colormap_example.pdf}
\subsubsection{Multi-panel Galactic plane survey image plots}
\label{image/plotting:multi-panel-galactic-plane-survey-image-plots}
The following example shows how to plot a very wide Galactic plane survey image
by splitting it into multiple panels using the {\hyperref[api/gammapy.image.GalacticPlaneSurveyPanelPlot:gammapy.image.GalacticPlaneSurveyPanelPlot]{\emph{\code{GalacticPlaneSurveyPanelPlot}}}} class.
\includegraphics{survey_example.pdf}
\subsection{Bounding boxes}
\label{image/bounding_box:astropy}\label{image/bounding_box::doc}\label{image/bounding_box:image-bounding-box}\label{image/bounding_box:bounding-boxes}
\begin{notice}{warning}{Warning:}
At the moment this section is pretty much just a set of notes for myself.
This needs to be cleaned up and translated into code used consistently throughout gammapy
(and probably astropy and photutils and maybe scikit-image ...)
\end{notice}
This document gives a detailed description of bounding boxes.
This is mostly useful for developers writing new functions that use bounding boxes.
Users can consider bounding boxes an implementation detail (even though they are part of the public API in some places).
\subsubsection{What's a bounding box and why do we need it?}
\label{image/bounding_box:what-s-a-bounding-box-and-why-do-we-need-it}
In gammapy we use \href{http://en.wikipedia.org/wiki/Minimum\_bounding\_box}{bounding boxes} to speed up image processing.
Let's say you have a large image, but are only interested in a small box (a rectangular sub-image)
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{numpy} \PYG{k+kn}{as} \PYG{n+nn}{np}
\PYG{n}{full\PYGZus{}array} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{random}\PYG{o}{.}\PYG{n}{random}\PYG{p}{(}\PYG{p}{(}\PYG{l+m+mi}{2000}\PYG{p}{,} \PYG{l+m+mi}{3000}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{sub\PYGZus{}array} \PYG{o}{=} \PYG{n}{full\PYGZus{}array}\PYG{p}{[}\PYG{l+m+mi}{1000}\PYG{p}{:}\PYG{l+m+mi}{1010}\PYG{p}{,} \PYG{l+m+mi}{2000}\PYG{p}{:}\PYG{l+m+mi}{2020}\PYG{p}{]}
\PYG{n}{np}\PYG{o}{.}\PYG{n}{sum}\PYG{p}{(}\PYG{n}{full\PYGZus{}array}\PYG{p}{)}
\PYG{n}{np}\PYG{o}{.}\PYG{n}{sum}\PYG{p}{(}\PYG{n}{sub\PYGZus{}array}\PYG{p}{)}
\end{Verbatim}
Numpy supports working with such boxes efficiently through the concept of
\href{http://scipy-lectures.github.io/intro/numpy/array\_object.html\#indexing-and-slicing}{slicing}
and
\href{http://scipy-lectures.github.io/intro/numpy/array\_object.html\#copies-and-views}{views}.
By slicing \code{{[}1000:1010, 2000:2020{]}} we created a view (not a copy) \code{sub\_array} into the \code{full\_array}.
On my machine making a measurement on \code{sub\_array} is about 1000 times as fast as for \code{full\_array}:
\begin{Verbatim}[commandchars=\\\{\}]
In [34]: \PYGZpc{}timeit np.sum(full\PYGZus{}array)
100 loops, best of 3: 5.32 ms per loop
In [35]: \PYGZpc{}timeit np.sum(sub\PYGZus{}array)
100000 loops, best of 3: 7.41 µs per loop
\end{Verbatim}
\subsubsection{How to represent bounding boxes and pass them around in code?}
\label{image/bounding_box:how-to-represent-bounding-boxes-and-pass-them-around-in-code}
In gammapy we frequently need to bass bounding boxes around, e.g. from a function that detects
many small objects in a large survey image to another function that measures some properties of these objects.
Python does have a built-in \href{https://docs.python.org/3/library/functions.html\#slice}{slice} class,
and we can use it to represent 1-dimensional slices:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{find\PYGZus{}objects}\PYG{p}{(}\PYG{n}{array}\PYG{p}{,} \PYG{n}{threshold}\PYG{p}{)}\PYG{p}{:}
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}Find segments above threshold in 1\PYGZhy{}dimensional array.\PYGZdq{}\PYGZdq{}\PYGZdq{}}
\PYG{n}{object\PYGZus{}slices} \PYG{o}{=} \PYG{p}{[}\PYG{p}{]}
\PYG{n}{in\PYGZus{}object} \PYG{o}{=} \PYG{n+nb+bp}{False}
\PYG{k}{for} \PYG{n}{ii} \PYG{o+ow}{in} \PYG{n+nb}{range}\PYG{p}{(}\PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{array}\PYG{p}{)}\PYG{p}{)}\PYG{p}{:}
\PYG{n}{value} \PYG{o}{=} \PYG{n}{array}\PYG{p}{[}\PYG{n}{ii}\PYG{p}{]}
\PYG{k}{if} \PYG{p}{(}\PYG{n}{value} \PYG{o}{\PYGZgt{}} \PYG{n}{threshold}\PYG{p}{)} \PYG{o+ow}{and} \PYG{p}{(}\PYG{o+ow}{not} \PYG{n}{in\PYGZus{}object}\PYG{p}{)}\PYG{p}{:}
\PYG{n}{in\PYGZus{}object} \PYG{o}{=} \PYG{n+nb+bp}{True}
\PYG{n}{start} \PYG{o}{=} \PYG{n}{ii}
\PYG{k}{elif} \PYG{p}{(}\PYG{n}{value} \PYG{o}{\PYGZlt{}}\PYG{o}{=} \PYG{n}{threshold}\PYG{p}{)} \PYG{o+ow}{and} \PYG{p}{(}\PYG{n}{in\PYGZus{}object}\PYG{p}{)}\PYG{p}{:}
\PYG{n}{in\PYGZus{}object} \PYG{o}{=} \PYG{n+nb+bp}{False}
\PYG{n}{stop} \PYG{o}{=} \PYG{n}{ii}
\PYG{n}{object\PYGZus{}slices}\PYG{o}{.}\PYG{n}{append}\PYG{p}{(}\PYG{n+nb}{slice}\PYG{p}{(}\PYG{n}{start}\PYG{p}{,} \PYG{n}{stop}\PYG{p}{)}\PYG{p}{)}
\PYG{k}{return} \PYG{n}{object\PYGZus{}slices}
\PYG{k}{def} \PYG{n+nf}{measure\PYGZus{}objects}\PYG{p}{(}\PYG{n}{array}\PYG{p}{,} \PYG{n}{object\PYGZus{}slices}\PYG{p}{)}\PYG{p}{:}
\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}Measure something for all objects and print the result.\PYGZdq{}\PYGZdq{}\PYGZdq{}}
\PYG{k}{for} \PYG{n}{object\PYGZus{}slice} \PYG{o+ow}{in} \PYG{n}{object\PYGZus{}slices}\PYG{p}{:}
\PYG{n}{data} \PYG{o}{=} \PYG{n}{array}\PYG{p}{[}\PYG{n}{object\PYGZus{}slice}\PYG{p}{]}
\PYG{n}{measurement} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{sum}\PYG{p}{(}\PYG{n}{data}\PYG{p}{)}
\PYG{k}{print}\PYG{p}{(}\PYG{n}{object\PYGZus{}slice}\PYG{o}{.}\PYG{n}{start}\PYG{p}{,} \PYG{n}{object\PYGZus{}slice}\PYG{o}{.}\PYG{n}{stop}\PYG{p}{,} \PYG{n}{measurement}\PYG{p}{)}
\PYG{k+kn}{import} \PYG{n+nn}{numpy} \PYG{k+kn}{as} \PYG{n+nn}{np}
\PYG{n}{np}\PYG{o}{.}\PYG{n}{random}\PYG{o}{.}\PYG{n}{seed}\PYG{p}{(}\PYG{l+m+mi}{42}\PYG{p}{)}
\PYG{n}{array} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{random}\PYG{o}{.}\PYG{n}{random}\PYG{p}{(}\PYG{l+m+mi}{1000}\PYG{p}{)}
\PYG{n}{threshold} \PYG{o}{=} \PYG{l+m+mf}{0.99}
\PYG{n}{objects} \PYG{o}{=} \PYG{n}{find\PYGZus{}objects}\PYG{p}{(}\PYG{n}{array}\PYG{p}{,} \PYG{n}{threshold}\PYG{p}{)}
\PYG{n}{measure\PYGZus{}objects}\PYG{p}{(}\PYG{n}{array}\PYG{p}{,} \PYG{n}{objects}\PYG{p}{)}
\end{Verbatim}
Unfortunately, there is no n-dimensional slice or bounding box class in Python or Numpy.
\subsubsection{Bounding boxes in other packages}
\label{image/bounding_box:bounding-boxes-in-other-packages}
Before inventing our own, let's look at what kinds of representations others have come up with:
\begin{itemize}
\item {}
The \href{http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.measurements.find\_objects.html\#scipy.ndimage.measurements.find\_objects}{\code{scipy.ndimage.measurements.find\_objects}} function returns a Python list of
Python tuples of Python \href{http://docs.python.org/library/functions.html\#slice}{\code{slice}} objects to represent a list of bounding boxes.
I.e. a single n-dimensional bounding box is represented as a Python tuple of n slice objects,
e.g. for a 2-dimensional bounding box:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{bbox} \PYG{o}{=} \PYG{p}{(}\PYG{n+nb}{slice}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{l+m+mi}{3}\PYG{p}{,} \PYG{n+nb+bp}{None}\PYG{p}{)}\PYG{p}{,} \PYG{n+nb}{slice}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{p}{,} \PYG{l+m+mi}{5}\PYG{p}{,} \PYG{n+nb+bp}{None}\PYG{p}{)}\PYG{p}{)}
\end{Verbatim}
This has the advantage that for a numpy array it is very easy to create views
for the rectangles represented by the bounding box:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{array} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{random}\PYG{o}{.}\PYG{n}{random}\PYG{p}{(}\PYG{p}{(}\PYG{l+m+mi}{1000}\PYG{p}{,} \PYG{l+m+mi}{2000}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{bboxes} \PYG{o}{=} \PYG{n}{scipy}\PYG{o}{.}\PYG{n}{ndimage}\PYG{o}{.}\PYG{n}{find\PYGZus{}objects}\PYG{p}{(}\PYG{n}{array}\PYG{p}{,} \PYG{o}{.}\PYG{o}{.}\PYG{o}{.}\PYG{p}{)}
\PYG{k}{for} \PYG{n}{bbox} \PYG{o+ow}{in} \PYG{n}{bboxes}\PYG{p}{:}
\PYG{n}{view} \PYG{o}{=} \PYG{n}{array}\PYG{p}{[}\PYG{n}{bbox}\PYG{p}{]}
\PYG{n}{measurement} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{sum}\PYG{p}{(}\PYG{n}{view}\PYG{p}{)}
\end{Verbatim}
As far as I can see no other function except \href{http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.measurements.find\_objects.html\#scipy.ndimage.measurements.find\_objects}{\code{scipy.ndimage.measurements.find\_objects}} uses
this bbox format, though. E.g. all other functions in \href{http://docs.scipy.org/doc/scipy/reference/ndimage.html\#module-scipy.ndimage.measurements}{\code{scipy.ndimage.measurements}} take a
\code{label} array as input, none has a \code{bboxes} argument.
\item {}
The \href{http://scikit-image.org/docs/stable/api/skimage.measure.html\#skimage.measure.regionprops}{\code{skimage.measure.regionprops}} function returns \code{properties}, a list of dict-like objects
with (among many other things) a \code{bbox} entry, which is a Python tuple of integers:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{bbox} \PYG{o}{=} \PYG{p}{(}\PYG{n}{min\PYGZus{}row}\PYG{p}{,} \PYG{n}{min\PYGZus{}col}\PYG{p}{,} \PYG{n}{max\PYGZus{}row}\PYG{p}{,} \PYG{n}{max\PYGZus{}col}\PYG{p}{)}
\end{Verbatim}
Looking under the hood (this is not part of their API) at the implementation in
\href{https://github.com/scikit-image/scikit-image/blob/master/skimage/measure/\_regionprops.py}{skimage/measure/\_regionprops.py} ,
we see that \href{http://scikit-image.org/docs/stable/api/skimage.measure.html\#skimage.measure.regionprops}{\code{skimage.measure.regionprops}} is just a wrapper storing the \href{http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.measurements.find\_objects.html\#scipy.ndimage.measurements.find\_objects}{\code{scipy.ndimage.measurements.find\_objects}} bboxes
in an object as \code{RegionProperties.\_slice} and then generating the integer index tuple on demand:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{bbox}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{)}\PYG{p}{:}
\PYG{k}{return} \PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{\PYGZus{}slice}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{o}{.}\PYG{n}{start}\PYG{p}{,} \PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{\PYGZus{}slice}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{o}{.}\PYG{n}{start}\PYG{p}{,}
\PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{\PYGZus{}slice}\PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{]}\PYG{o}{.}\PYG{n}{stop}\PYG{p}{,} \PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{\PYGZus{}slice}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]}\PYG{o}{.}\PYG{n}{stop}\PYG{p}{)}
\end{Verbatim}
As for \href{http://docs.scipy.org/doc/scipy/reference/ndimage.html\#module-scipy.ndimage}{\code{scipy.ndimage}}, as far as I can see, \code{bbox} is not used elsewhere in \href{http://scikit-image.org/docs/stable/api/skimage.html\#module-skimage}{\code{skimage}}.
\item {}
\href{http://photutils.readthedocs.org/en/latest/photutils/high-level\_API.html\#module-photutils}{\code{photutils}} has this \href{http://photutils.readthedocs.org/en/latest/photutils/overview.html\#coordinate-conventions}{coordinate convention}.
Looking at the \href{http://photutils.readthedocs.org/en/latest/api/photutils.aperture\_photometry.html\#photutils.aperture\_photometry}{\code{photutils.aperture\_photometry}} implementation, it looks like they don't have an official \code{bbox} representation,
but simply compute \code{(x\_min, x\_max, y\_min, y\_max)} where needed and then use \code{data{[}y\_min:y\_max, x\_min:x\_max{]}} views.
TODO: update once this is in: \href{https://github.com/astropy/astropy/issues/2607}{https://github.com/astropy/astropy/issues/2607}
\item {}
\href{http://imutils.readthedocs.org/en/latest/}{imutils} has a
\href{http://imutils.readthedocs.org/en/latest/api/imutils.Cutout.html}{Cutout} class.
\end{itemize}
I also found
\href{http://stackoverflow.com/questions/9525313/rectangular-bounding-box-around-blobs-in-a-monochrome-image-using-python}{this}
and
\href{http://stackoverflow.com/questions/4087919/how-can-i-improve-my-paw-detection}{this}
stackoverflow entry a bit useful.
\subsubsection{Bounding boxes in gammapy}
\label{image/bounding_box:bounding-boxes-in-gammapy}
In gammapy, a single bounding box is represented as a {\hyperref[api/gammapy.image.BoundingBox:gammapy.image.BoundingBox]{\emph{\code{gammapy.image.BoundingBox}}}} objects.
I decided to make a class, because I think it will help:
\begin{itemize}
\item {}
Getting the index order right shouldn't be left up to the user (\code{(x, y)} and \code{(y, x)} in different places)
\item {}
Getting the position right shouldn't be left up to the user (\code{(0, 0)} or \code{(1, 1)} and sub-pixel positions)
\end{itemize}
TODO: describe. Give examples of functions that take bounding boxes as input or output.
TODO: there should probably also be a \code{PixelCoordinate} class instead of passing \code{(x, y)} tuples around.
\section{Reference/API}
\label{image/index:reference-api}\label{image/index:astropy}
\subsection{gammapy.image Package}
\label{image/index:gammapy-image-package}\label{image/index:module-gammapy.image}\index{gammapy.image (module)}
Image processing and analysis tools.
\subsubsection{Functions}
\label{image/index:functions}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.image.atrous_hdu:gammapy.image.atrous_hdu]{\emph{\code{atrous\_hdu}}}}(hdu, n\_levels)
&
Compute a trous transform for a given FITS HDU.
\\
\hline
{\hyperref[api/gammapy.image.atrous_image:gammapy.image.atrous_image]{\emph{\code{atrous\_image}}}}(image, n\_levels)
&
Compute a trous transform for a given image.
\\
\hline
{\hyperref[api/gammapy.image.bbox:gammapy.image.bbox]{\emph{\code{bbox}}}}(mask, margin, binsz)
&
Determine the bounding box of a mask.
\\
\hline
{\hyperref[api/gammapy.image.bin_events_in_cube:gammapy.image.bin_events_in_cube]{\emph{\code{bin\_events\_in\_cube}}}}(events, reference\_cube, ...)
&
Bin events in LON-LAT-Energy cube.
\\
\hline
{\hyperref[api/gammapy.image.bin_events_in_image:gammapy.image.bin_events_in_image]{\emph{\code{bin\_events\_in\_image}}}}(events, reference\_image)
&
Bin events into an image.
\\
\hline
{\hyperref[api/gammapy.image.binary_dilation_circle:gammapy.image.binary_dilation_circle]{\emph{\code{binary\_dilation\_circle}}}}(input, radius)
&
Dilate with disk of given radius.
\\
\hline
{\hyperref[api/gammapy.image.binary_disk:gammapy.image.binary_disk]{\emph{\code{binary\_disk}}}}(radius)
&
Generate a binary disk mask.
\\
\hline
{\hyperref[api/gammapy.image.binary_opening_circle:gammapy.image.binary_opening_circle]{\emph{\code{binary\_opening\_circle}}}}(input, radius)
&
Binary opening with circle as structuring element.
\\
\hline
{\hyperref[api/gammapy.image.binary_ring:gammapy.image.binary_ring]{\emph{\code{binary\_ring}}}}(r\_in, r\_out)
&
Generate a binary ring mask.
\\
\hline
{\hyperref[api/gammapy.image.block_reduce_hdu:gammapy.image.block_reduce_hdu]{\emph{\code{block\_reduce\_hdu}}}}(input\_hdu, block\_size, func)
&
Provides block reduce functionality for image HDUs.
\\
\hline
{\hyperref[api/gammapy.image.catalog_image:gammapy.image.catalog_image]{\emph{\code{catalog\_image}}}}(reference, psf{[}, catalog, ...{]})
&
Creates an image from a simulated catalog, or from 1FHL or 2FGL sources.
\\
\hline
{\hyperref[api/gammapy.image.catalog_table:gammapy.image.catalog_table]{\emph{\code{catalog\_table}}}}(catalog{[}, energy\_bands{]})
&
Creates catalog table from published source catalog.
\\
\hline
{\hyperref[api/gammapy.image.colormap_hess:gammapy.image.colormap_hess]{\emph{\code{colormap\_hess}}}}({[}transition, width{]})
&
Colormap often used in H.E.S.S.
\\
\hline
{\hyperref[api/gammapy.image.colormap_milagro:gammapy.image.colormap_milagro]{\emph{\code{colormap\_milagro}}}}({[}transition, width, huestart{]})
&
Colormap often used in Milagro collaboration publications.
\\
\hline
{\hyperref[api/gammapy.image.compute_binning:gammapy.image.compute_binning]{\emph{\code{compute\_binning}}}}(data, n\_bins{[}, method, eps{]})
&
Computes 1D array of bin edges.
\\
\hline
{\hyperref[api/gammapy.image.contains:gammapy.image.contains]{\emph{\code{contains}}}}(image, x, y{[}, world{]})
&
Check if given pixel or world positions are in an image.
\\
\hline
{\hyperref[api/gammapy.image.coordinates:gammapy.image.coordinates]{\emph{\code{coordinates}}}}(image{[}, world, lon\_sym, radians{]})
&
Get coordinate images for a given image.
\\
\hline
{\hyperref[api/gammapy.image.crop_image:gammapy.image.crop_image]{\emph{\code{crop\_image}}}}(image, bounding\_box)
&
Crop an image (cut out a rectangular part).
\\
\hline
{\hyperref[api/gammapy.image.cube_to_image:gammapy.image.cube_to_image]{\emph{\code{cube\_to\_image}}}}(cube{[}, slicepos{]})
&
Slice or project 3-dim cube into a 2-dim image.
\\
\hline
{\hyperref[api/gammapy.image.cube_to_spec:gammapy.image.cube_to_spec]{\emph{\code{cube\_to\_spec}}}}(cube, mask{[}, weighting{]})
&
Integrate spatial dimensions of a FITS cube to give a spectrum.
\\
\hline
{\hyperref[api/gammapy.image.dict_to_hdulist:gammapy.image.dict_to_hdulist]{\emph{\code{dict\_to\_hdulist}}}}(image\_dict, header)
&
Take a dictionary of image data and a header to create a HDUList.
\\
\hline
{\hyperref[api/gammapy.image.disk_correlate:gammapy.image.disk_correlate]{\emph{\code{disk\_correlate}}}}(image, radius{[}, mode{]})
&
Correlate image with binary disk kernel.
\\
\hline
{\hyperref[api/gammapy.image.downsample_2N:gammapy.image.downsample_2N]{\emph{\code{downsample\_2N}}}}(image, factor{[}, method, shape{]})
&
Down sample image by a power of two.
\\
\hline
{\hyperref[api/gammapy.image.exclusion_distance:gammapy.image.exclusion_distance]{\emph{\code{exclusion\_distance}}}}(exclusion)
&
Distance to nearest exclusion region.
\\
\hline
{\hyperref[api/gammapy.image.find_max:gammapy.image.find_max]{\emph{\code{find\_max}}}}(image)
&
Find position of maximum in an image.
\\
\hline
{\hyperref[api/gammapy.image.fits_to_png:gammapy.image.fits_to_png]{\emph{\code{fits\_to\_png}}}}(infile, outfile, draw{[}, dpi{]})
&
Plot FITS image in PNG format.
\\
\hline
{\hyperref[api/gammapy.image.fitsfigure_add_psf_inset:gammapy.image.fitsfigure_add_psf_inset]{\emph{\code{fitsfigure\_add\_psf\_inset}}}}(ff, psf, box{[}, ...{]})
&
Add PSF inset to \href{http://aplpy.readthedocs.org/en/latest/api/aplpy.FITSFigure.html\#aplpy.FITSFigure}{\code{FITSFigure}} instance.
\\
\hline
{\hyperref[api/gammapy.image.grayify_colormap:gammapy.image.grayify_colormap]{\emph{\code{grayify\_colormap}}}}(cmap{[}, mode{]})
&
Return a grayscale version a the colormap.
\\
\hline
{\hyperref[api/gammapy.image.illustrate_colormap:gammapy.image.illustrate_colormap]{\emph{\code{illustrate\_colormap}}}}(cmap, **kwargs)
&
Illustrate color distribution and perceived luminance of a colormap.
\\
\hline
{\hyperref[api/gammapy.image.image_groupby:gammapy.image.image_groupby]{\emph{\code{image\_groupby}}}}(images, labels)
&
Group pixel by labels.
\\
\hline
{\hyperref[api/gammapy.image.image_profile:gammapy.image.image_profile]{\emph{\code{image\_profile}}}}(profile\_axis, image, lats, ...)
&
Creates a latitude or longitude profile from input flux image HDU.
\\
\hline
{\hyperref[api/gammapy.image.images_to_cube:gammapy.image.images_to_cube]{\emph{\code{images\_to\_cube}}}}(hdu\_list)
&
Convert a list of image HDUs into one cube.
\\
\hline
{\hyperref[api/gammapy.image.lon_lat_rectangle_mask:gammapy.image.lon_lat_rectangle_mask]{\emph{\code{lon\_lat\_rectangle\_mask}}}}(lons, lats{[}, ...{]})
&
Produces a rectangular boolean mask array based on lat and lon limits.
\\
\hline
{\hyperref[api/gammapy.image.lookup:gammapy.image.lookup]{\emph{\code{lookup}}}}(image, x, y{[}, world{]})
&
Look up values in an image.
\\
\hline
{\hyperref[api/gammapy.image.lookup_max:gammapy.image.lookup_max]{\emph{\code{lookup\_max}}}}(image, GLON, GLAT, theta)
&
Look up the max image values within a circle of radius theta
\\
\hline
{\hyperref[api/gammapy.image.make_empty_image:gammapy.image.make_empty_image]{\emph{\code{make\_empty\_image}}}}({[}nxpix, nypix, binsz, ...{]})
&
Make an empty (i.e.
\\
\hline
{\hyperref[api/gammapy.image.make_header:gammapy.image.make_header]{\emph{\code{make\_header}}}}({[}nxpix, nypix, binsz, xref, ...{]})
&
Generate a FITS header from scratch.
\\
\hline
{\hyperref[api/gammapy.image.measure_containment:gammapy.image.measure_containment]{\emph{\code{measure\_containment}}}}(image, glon, glat, radius)
&
Measure containment in a given circle around the source position.
\\
\hline
{\hyperref[api/gammapy.image.measure_containment_fraction:gammapy.image.measure_containment_fraction]{\emph{\code{measure\_containment\_fraction}}}}(r, rr, image)
&
Measure containment fraction.
\\
\hline
{\hyperref[api/gammapy.image.measure_containment_radius:gammapy.image.measure_containment_radius]{\emph{\code{measure\_containment\_radius}}}}(image, glon, glat)
&
Measure containment radius.
\\
\hline
{\hyperref[api/gammapy.image.measure_curve_of_growth:gammapy.image.measure_curve_of_growth]{\emph{\code{measure\_curve\_of\_growth}}}}(image, glon, glat{[}, ...{]})
&
Measure the curve of growth for a given source position.
\\
\hline
{\hyperref[api/gammapy.image.measure_image_moments:gammapy.image.measure_image_moments]{\emph{\code{measure\_image\_moments}}}}(image)
&
Compute 0th, 1st and 2nd moments of an image.
\\
\hline
{\hyperref[api/gammapy.image.measure_labeled_regions:gammapy.image.measure_labeled_regions]{\emph{\code{measure\_labeled\_regions}}}}(data, labels{[}, tag, ...{]})
&
Measure source properties in image.
\\
\hline
{\hyperref[api/gammapy.image.paste_cutout_into_image:gammapy.image.paste_cutout_into_image]{\emph{\code{paste\_cutout\_into\_image}}}}(total, cutout{[}, method{]})
&
Paste cutout into a total image.
\\
\hline
{\hyperref[api/gammapy.image.process_image_pixels:gammapy.image.process_image_pixels]{\emph{\code{process\_image\_pixels}}}}(images, kernel, out, ...)
&
Process images for a given kernel and per-pixel function.
\\
\hline
{\hyperref[api/gammapy.image.ring_correlate:gammapy.image.ring_correlate]{\emph{\code{ring\_correlate}}}}(image, r\_in, r\_out{[}, mode{]})
&
Correlate image with binary ring kernel.
\\
\hline
{\hyperref[api/gammapy.image.separation:gammapy.image.separation]{\emph{\code{separation}}}}(image, center{[}, world, radians{]})
&
Compute distance image from a given center point.
\\
\hline
{\hyperref[api/gammapy.image.shape_2N:gammapy.image.shape_2N]{\emph{\code{shape\_2N}}}}(shape{[}, N{]})
&
Round a given shape to values that are divisible by 2\textasciicircum{}N.
\\
\hline
{\hyperref[api/gammapy.image.solid_angle:gammapy.image.solid_angle]{\emph{\code{solid\_angle}}}}(image)
&
Compute the solid angle of each pixel.
\\
\hline
{\hyperref[api/gammapy.image.threshold:gammapy.image.threshold]{\emph{\code{threshold}}}}(array{[}, threshold{]})
&
Set all pixels below threshold to zero.
\\
\hline
{\hyperref[api/gammapy.image.upsample_2N:gammapy.image.upsample_2N]{\emph{\code{upsample\_2N}}}}(image, factor{[}, order, shape{]})
&
Up sample image by a power of two.
\\
\hline
{\hyperref[api/gammapy.image.wcs_histogram2d:gammapy.image.wcs_histogram2d]{\emph{\code{wcs\_histogram2d}}}}(header, lon, lat{[}, weights{]})
&
Histogram in world coordinates.
\\
\hline\end{longtable}
\paragraph{atrous\_hdu}
\label{api/gammapy.image.atrous_hdu:atrous-hdu}\label{api/gammapy.image.atrous_hdu::doc}\index{atrous\_hdu() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.atrous_hdu:gammapy.image.atrous_hdu}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{atrous\_hdu}}{\emph{hdu}, \emph{n\_levels}}{}
Compute a trous transform for a given FITS HDU.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{hdu} : 2D image HDU
\begin{quote}
Input image
\end{quote}
\textbf{n\_levels} : integer
\begin{quote}
Number of wavelet scales.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{images} : HDUList
\begin{quote}
Wavelet transformed images.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{atrous\_image}
\label{api/gammapy.image.atrous_image:astropy}\label{api/gammapy.image.atrous_image::doc}\label{api/gammapy.image.atrous_image:atrous-image}\index{atrous\_image() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.atrous_image:gammapy.image.atrous_image}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{atrous\_image}}{\emph{image}, \emph{n\_levels}}{}
Compute a trous transform for a given image.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{image} : 2D array
\begin{quote}
Input image
\end{quote}
\textbf{n\_levels} : integer
\begin{quote}
Number of wavelet scales.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{images} : list of 2D arrays
\begin{quote}
Wavelet transformed images.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{bbox}
\label{api/gammapy.image.bbox:astropy}\label{api/gammapy.image.bbox::doc}\label{api/gammapy.image.bbox:bbox}\index{bbox() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.bbox:gammapy.image.bbox}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{bbox}}{\emph{mask}, \emph{margin}, \emph{binsz}}{}
Determine the bounding box of a mask.
TODO: this is an old utility function ... put it into the BoundingBox class.
\end{fulllineitems}
\paragraph{bin\_events\_in\_cube}
\label{api/gammapy.image.bin_events_in_cube:astropy}\label{api/gammapy.image.bin_events_in_cube::doc}\label{api/gammapy.image.bin_events_in_cube:bin-events-in-cube}\index{bin\_events\_in\_cube() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.bin_events_in_cube:gammapy.image.bin_events_in_cube}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{bin\_events\_in\_cube}}{\emph{events}, \emph{reference\_cube}, \emph{energies}}{}
Bin events in LON-LAT-Energy cube.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{events} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Event list table
\end{quote}
\textbf{reference\_cube} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
A cube defining the spatial bins.
\end{quote}
\textbf{energies} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Table defining the energy bins.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{count\_cube} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
Count cube
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{bin\_events\_in\_image}
\label{api/gammapy.image.bin_events_in_image:bin-events-in-image}\label{api/gammapy.image.bin_events_in_image:astropy}\label{api/gammapy.image.bin_events_in_image::doc}\index{bin\_events\_in\_image() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.bin_events_in_image:gammapy.image.bin_events_in_image}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{bin\_events\_in\_image}}{\emph{events}, \emph{reference\_image}}{}
Bin events into an image.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{events} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Event list table
\end{quote}
\textbf{reference\_image} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
An image defining the spatial bins.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{count\_image} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
Count image
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{binary\_dilation\_circle}
\label{api/gammapy.image.binary_dilation_circle:binary-dilation-circle}\label{api/gammapy.image.binary_dilation_circle:astropy}\label{api/gammapy.image.binary_dilation_circle::doc}\index{binary\_dilation\_circle() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.binary_dilation_circle:gammapy.image.binary_dilation_circle}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{binary\_dilation\_circle}}{\emph{input}, \emph{radius}}{}
Dilate with disk of given radius.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{input} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Input array
\end{quote}
\textbf{radius} : float
\begin{quote}
Dilation radius (pix)
\end{quote}
\item[{Returns}] \leavevmode
\textbf{binary\_dilation} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}} of bools
\begin{quote}
Dilation of the input array by a disk of the given radius.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{binary\_disk}
\label{api/gammapy.image.binary_disk:binary-disk}\label{api/gammapy.image.binary_disk:astropy}\label{api/gammapy.image.binary_disk::doc}\index{binary\_disk() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.binary_disk:gammapy.image.binary_disk}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{binary\_disk}}{\emph{radius}}{}
Generate a binary disk mask.
Value 1 inside and 0 outside.
Useful as a structure element for morphological transformations.
Note that the returned structure always has an odd number
of pixels so that shifts during correlation are avoided.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{radius} : float
\begin{quote}
Disk radius in pixels
\end{quote}
\item[{Returns}] \leavevmode
\textbf{structure} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html\#numpy.array}{\code{numpy.array}}
\begin{quote}
Structure element (bool array)
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{binary\_opening\_circle}
\label{api/gammapy.image.binary_opening_circle:astropy}\label{api/gammapy.image.binary_opening_circle::doc}\label{api/gammapy.image.binary_opening_circle:binary-opening-circle}\index{binary\_opening\_circle() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.binary_opening_circle:gammapy.image.binary_opening_circle}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{binary\_opening\_circle}}{\emph{input}, \emph{radius}}{}
Binary opening with circle as structuring element.
This calls \href{http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.morphology.binary\_opening.html\#scipy.ndimage.morphology.binary\_opening}{\code{scipy.ndimage.morphology.binary\_opening}} with a {\hyperref[api/gammapy.image.binary_disk:gammapy.image.binary_disk]{\emph{\code{binary\_disk}}}}
as structuring element.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{input} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Input array
\end{quote}
\textbf{radius} : float
\begin{quote}
Dilation radius (pix)
\end{quote}
\item[{Returns}] \leavevmode
\textbf{binary\_opening} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}} of bools
\begin{quote}
Opening of the input array by a disk of the given radius.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{binary\_ring}
\label{api/gammapy.image.binary_ring:astropy}\label{api/gammapy.image.binary_ring::doc}\label{api/gammapy.image.binary_ring:binary-ring}\index{binary\_ring() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.binary_ring:gammapy.image.binary_ring}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{binary\_ring}}{\emph{r\_in}, \emph{r\_out}}{}
Generate a binary ring mask.
Value 1 inside and 0 outside.
Useful as a structure element for morphological transformations.
Note that the returned structure always has an odd number
of pixels so that shifts during correlation are avoided.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{r\_in} : float
\begin{quote}
Ring inner radius in pixels
\end{quote}
\textbf{r\_out} : float
\begin{quote}
Ring outer radius in pixels
\end{quote}
\item[{Returns}] \leavevmode
\textbf{structure} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html\#numpy.array}{\code{numpy.array}}
\begin{quote}
Structure element (bool array)
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{block\_reduce\_hdu}
\label{api/gammapy.image.block_reduce_hdu:block-reduce-hdu}\label{api/gammapy.image.block_reduce_hdu:astropy}\label{api/gammapy.image.block_reduce_hdu::doc}\index{block\_reduce\_hdu() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.block_reduce_hdu:gammapy.image.block_reduce_hdu}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{block\_reduce\_hdu}}{\emph{input\_hdu}, \emph{block\_size}, \emph{func}, \emph{cval=0}}{}
Provides block reduce functionality for image HDUs.
See \href{http://scikit-image.org/docs/dev/api/skimage.measure.html\#skimage.measure.block\_reduce}{http://scikit-image.org/docs/dev/api/skimage.measure.html\#skimage.measure.block\_reduce}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{image\_hdu} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
Original image HDU, unscaled
\end{quote}
\textbf{block\_size} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Array containing down-sampling integer factor along each axis.
\end{quote}
\textbf{func} : callable
\begin{quote}
Function object which is used to calculate the return value for each local block.
This function must implement an axis parameter such as \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.sum.html\#numpy.sum}{\code{numpy.sum}} or \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.mean.html\#numpy.mean}{\code{numpy.mean}}.
\end{quote}
\textbf{cval} : float, optional
\begin{quote}
Constant padding value if image is not perfectly divisible by the block size. Default 0.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{image\_hdu} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
Rebinned Image HDU
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{catalog\_image}
\label{api/gammapy.image.catalog_image:astropy}\label{api/gammapy.image.catalog_image::doc}\label{api/gammapy.image.catalog_image:catalog-image}\index{catalog\_image() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.catalog_image:gammapy.image.catalog_image}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{catalog\_image}}{\emph{reference}, \emph{psf}, \emph{catalog=`1FHL'}, \emph{source\_type='point'}, \emph{total\_flux=False}, \emph{sim\_table=None}}{}
Creates an image from a simulated catalog, or from 1FHL or 2FGL sources.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{reference} : \code{ImageHDU}
\begin{quote}
Reference Image HDU. The output takes the shape and resolution of this.
\end{quote}
\textbf{psf} : {\hyperref[api/gammapy.irf.EnergyDependentTablePSF:gammapy.irf.EnergyDependentTablePSF]{\emph{\code{EnergyDependentTablePSF}}}}
\begin{quote}
Energy dependent Table PSF object for image convolution.
\end{quote}
\textbf{catalog} : \{`1FHL', `2FGL', `simulation'\}
\begin{quote}
Flag which source catalog is to be used to create the image.
If `simulation' is used, sim\_table must also be provided.
\end{quote}
\textbf{source\_type} : \{`point', `extended', `all'\}
\begin{quote}
Specify whether point or extended sources should be included, or both.
TODO: Currently only `point' is implemented.
\end{quote}
\textbf{total\_flux} : bool
\begin{quote}
Specify whether to conserve total flux.
\end{quote}
\textbf{sim\_table} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Table of simulated point sources. Only required if catalog = `simulation'
\end{quote}
\item[{Returns}] \leavevmode
\textbf{out\_cube} : {\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube]{\emph{\code{SpectralCube}}}}
\begin{quote}
2D Spectral cube containing the image.
\end{quote}
\end{description}\end{quote}
\paragraph{Notes}
This is currently only implemented for a single energy band.
\end{fulllineitems}
\paragraph{catalog\_table}
\label{api/gammapy.image.catalog_table:catalog-table}\label{api/gammapy.image.catalog_table:astropy}\label{api/gammapy.image.catalog_table::doc}\index{catalog\_table() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.catalog_table:gammapy.image.catalog_table}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{catalog\_table}}{\emph{catalog}, \emph{energy\_bands=False}}{}
Creates catalog table from published source catalog.
This creates a table of catalog sources, positions and fluxes for an
indicated published source catalog - either 1FHL or 2FGL. This should
be used to in instances where a table is required, for instance as an
input for the {\hyperref[api/gammapy.image.catalog_image:gammapy.image.catalog_image]{\emph{\code{catalog\_image}}}} function.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{catalog} : \{`1FHL', `2FGL'\}
\begin{quote}
Catalog to load.
\end{quote}
\textbf{energy\_bands} : bool
\begin{quote}
Whether to return catalog in energy bands.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{table} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Point source catalog table.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{colormap\_hess}
\label{api/gammapy.image.colormap_hess:astropy}\label{api/gammapy.image.colormap_hess::doc}\label{api/gammapy.image.colormap_hess:colormap-hess}\index{colormap\_hess() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.colormap_hess:gammapy.image.colormap_hess}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{colormap\_hess}}{\emph{transition=0.5}, \emph{width=0.1}}{}
Colormap often used in H.E.S.S. collaboration publications.
This colormap goes black -\textgreater{} blue -\textgreater{} red -\textgreater{} yellow -\textgreater{} white.
A sharp blue -\textgreater{} red -\textgreater{} yellow transition is often used for significance images
with a value of red at \code{transition \textasciitilde{} 5} or \code{transition \textasciitilde{} 7}
so that the following effect is achieved:
\begin{itemize}
\item {}
black, blue: non-significant features, not well visible
\item {}
red: features at the detection threshold \code{transition}
\item {}
yellow, white: significant features, very well visible
\end{itemize}
The transition parameter is defined between 0 and 1. To calculate the value
from data units an \href{http://docs.astropy.org/en/latest/api/astropy.visualization.mpl\_normalize.ImageNormalize.html\#astropy.visualization.mpl\_normalize.ImageNormalize}{\code{ImageNormalize}}
instance should be used (see example below).
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{transition} : float (default = 0.5)
\begin{quote}
Value of the transition to red (between 0 and 1).
\end{quote}
\textbf{width} : float (default = 0.5)
\begin{quote}
Width of the blue-red color transition (between 0 and 1).
\end{quote}
\item[{Returns}] \leavevmode
\textbf{colormap} : \code{matplotlib.colors.LinearSegmentedColormap}
\begin{quote}
Colormap
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.image} \PYG{k+kn}{import} \PYG{n}{colormap\PYGZus{}hess}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{astropy.visualization.mpl\PYGZus{}normalize} \PYG{k+kn}{import} \PYG{n}{ImageNormalize}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{astropy.visualization} \PYG{k+kn}{import} \PYG{n}{LinearStretch}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{normalize} \PYG{o}{=} \PYG{n}{ImageNormalize}\PYG{p}{(}\PYG{n}{vmin}\PYG{o}{=}\PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{5}\PYG{p}{,} \PYG{n}{vmax}\PYG{o}{=}\PYG{l+m+mi}{15}\PYG{p}{,} \PYG{n}{stretch}\PYG{o}{=}\PYG{n}{LinearStretch}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{transition} \PYG{o}{=} \PYG{n}{normalize}\PYG{p}{(}\PYG{l+m+mi}{5}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{cmap} \PYG{o}{=} \PYG{n}{colormap\PYGZus{}hess}\PYG{p}{(}\PYG{n}{transition}\PYG{o}{=}\PYG{n}{transition}\PYG{p}{)}
\end{Verbatim}
\includegraphics{gammapy-image-colormap_hess-1.pdf}
\end{fulllineitems}
\paragraph{colormap\_milagro}
\label{api/gammapy.image.colormap_milagro:astropy}\label{api/gammapy.image.colormap_milagro::doc}\label{api/gammapy.image.colormap_milagro:colormap-milagro}\index{colormap\_milagro() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.colormap_milagro:gammapy.image.colormap_milagro}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{colormap\_milagro}}{\emph{transition=0.5}, \emph{width=0.0001}, \emph{huestart=0.6}}{}
Colormap often used in Milagro collaboration publications.
This colormap is gray below \code{transition} and similar to the jet colormap above.
A sharp gray -\textgreater{} color transition is often used for significance images
with a transition value of \code{transition \textasciitilde{} 5} or \code{transition \textasciitilde{} 7},
so that the following effect is achieved:
\begin{itemize}
\item {}
gray: non-significant features are not well visible
\item {}
color: significant features at the detection threshold \code{transition}
\end{itemize}
Note that this colormap is often critizised for over-exaggerating small differences
in significance below and above the gray - color transition threshold.
The transition parameter is defined between 0 and 1. To calculate the value
from data units an \code{ImageNormalize} instance should be
used (see example below).
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{transition} : float (default = 0.5)
\begin{quote}
Transition value (below: gray, above: color).
\end{quote}
\textbf{width} : float (default = 0.0001)
\begin{quote}
Width of the transition
\end{quote}
\textbf{huestart} : float (default = 0.6)
\begin{quote}
Hue of the color at \code{transition}
\end{quote}
\item[{Returns}] \leavevmode
\textbf{colormap} : \code{matplotlib.colors.LinearSegmentedColormap}
\begin{quote}
Colormap
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.image} \PYG{k+kn}{import} \PYG{n}{colormap\PYGZus{}milagro}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{astropy.visualization.mpl\PYGZus{}normalize} \PYG{k+kn}{import} \PYG{n}{ImageNormalize}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{astropy.visualization} \PYG{k+kn}{import} \PYG{n}{LinearStretch}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{normalize} \PYG{o}{=} \PYG{n}{ImageNormalize}\PYG{p}{(}\PYG{n}{vmin}\PYG{o}{=}\PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{5}\PYG{p}{,} \PYG{n}{vmax}\PYG{o}{=}\PYG{l+m+mi}{15}\PYG{p}{,} \PYG{n}{stretch}\PYG{o}{=}\PYG{n}{LinearStretch}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{transition} \PYG{o}{=} \PYG{n}{normalize}\PYG{p}{(}\PYG{l+m+mi}{5}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{cmap} \PYG{o}{=} \PYG{n}{colormap\PYGZus{}milagro}\PYG{p}{(}\PYG{n}{transition}\PYG{o}{=}\PYG{n}{transition}\PYG{p}{)}
\end{Verbatim}
\includegraphics{gammapy-image-colormap_milagro-1.pdf}
\end{fulllineitems}
\paragraph{compute\_binning}
\label{api/gammapy.image.compute_binning:astropy}\label{api/gammapy.image.compute_binning::doc}\label{api/gammapy.image.compute_binning:compute-binning}\index{compute\_binning() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.compute_binning:gammapy.image.compute_binning}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{compute\_binning}}{\emph{data}, \emph{n\_bins}, \emph{method='equal width'}, \emph{eps=1e-10}}{}
Computes 1D array of bin edges.
The range of the bin\_edges is always {[}min(data), max(data){]}
Note that bin\_edges has n\_bins bins, i.e. length n\_bins + 1.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{data} : array\_like
\begin{quote}
Data to be binned (any dimension)
\end{quote}
\textbf{n\_bins} : int
\begin{quote}
Number of bins
\end{quote}
\textbf{method} : str
\begin{quote}
One of: `equal width', `equal entries'
\end{quote}
\textbf{eps} : float
\begin{quote}
added to range so that the max data point is inside the
last bin. If eps=0 it falls on the right edge of the last
data point and thus would be not cointained.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{bin\_edges} : 1D ndarray
\begin{quote}
Array of bin edges.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{contains}
\label{api/gammapy.image.contains:astropy}\label{api/gammapy.image.contains::doc}\label{api/gammapy.image.contains:contains}\index{contains() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.contains:gammapy.image.contains}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{contains}}{\emph{image}, \emph{x}, \emph{y}, \emph{world=True}}{}
Check if given pixel or world positions are in an image.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{image} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
2-dim FITS image
\end{quote}
\textbf{x} : float
\begin{quote}
x coordinate in the image
\end{quote}
\textbf{y} : float
\begin{quote}
y coordinate in the image
\end{quote}
\textbf{world} : bool, optional
\begin{quote}
Are x and y in world coordinates (or pixel coordinates)?
\end{quote}
\item[{Returns}] \leavevmode
\textbf{containment} : array
\begin{quote}
Bool array
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{coordinates}
\label{api/gammapy.image.coordinates:astropy}\label{api/gammapy.image.coordinates::doc}\label{api/gammapy.image.coordinates:coordinates}\index{coordinates() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.coordinates:gammapy.image.coordinates}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{coordinates}}{\emph{image}, \emph{world=True}, \emph{lon\_sym=True}, \emph{radians=False}}{}
Get coordinate images for a given image.
This function is useful if you want to compute
an image with values that are a function of position.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{image} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}} or \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Input image
\end{quote}
\textbf{world} : bool, optional
\begin{quote}
Use world coordinates (or pixel coordinates)?
\end{quote}
\textbf{lon\_sym} : bool, optional
\begin{quote}
Use symmetric longitude range \code{(-180, 180)} (or \code{(0, 360)})?
\end{quote}
\textbf{radians} : bool, optional
\begin{quote}
Return coordinates in radians or degrees?
\end{quote}
\item[{Returns}] \leavevmode
\textbf{(lon, lat)} : tuple of arrays
\begin{quote}
Images as numpy arrays with values
containing the position of the given pixel.
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{import} \PYG{n+nn}{numpy} \PYG{k+kn}{as} \PYG{n+nn}{np}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.datasets} \PYG{k+kn}{import} \PYG{n}{FermiGalacticCenter}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{lon}\PYG{p}{,} \PYG{n}{lat} \PYG{o}{=} \PYG{n}{coordinates}\PYG{p}{(}\PYG{n}{FermiGalacticCenter}\PYG{o}{.}\PYG{n}{counts}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{dist} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{sqrt}\PYG{p}{(}\PYG{n}{lon} \PYG{o}{*}\PYG{o}{*} \PYG{l+m+mi}{2} \PYG{o}{+} \PYG{n}{lat} \PYG{o}{*}\PYG{o}{*} \PYG{l+m+mi}{2}\PYG{p}{)}
\end{Verbatim}
\end{fulllineitems}
\paragraph{crop\_image}
\label{api/gammapy.image.crop_image:astropy}\label{api/gammapy.image.crop_image::doc}\label{api/gammapy.image.crop_image:crop-image}\index{crop\_image() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.crop_image:gammapy.image.crop_image}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{crop\_image}}{\emph{image}, \emph{bounding\_box}}{}
Crop an image (cut out a rectangular part).
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{image} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
Image
\end{quote}
\textbf{bounding\_box} : {\hyperref[api/gammapy.image.BoundingBox:gammapy.image.BoundingBox]{\emph{\code{BoundingBox}}}}
\begin{quote}
Bounding box
\end{quote}
\item[{Returns}] \leavevmode
\textbf{new\_image} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
Cropped image
\end{quote}
\end{description}\end{quote}
\strong{See also:}
{\hyperref[api/gammapy.image.paste_cutout_into_image:gammapy.image.paste_cutout_into_image]{\emph{\code{paste\_cutout\_into\_image}}}}
\end{fulllineitems}
\paragraph{cube\_to\_image}
\label{api/gammapy.image.cube_to_image:astropy}\label{api/gammapy.image.cube_to_image::doc}\label{api/gammapy.image.cube_to_image:cube-to-image}\index{cube\_to\_image() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.cube_to_image:gammapy.image.cube_to_image}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{cube\_to\_image}}{\emph{cube}, \emph{slicepos=None}}{}
Slice or project 3-dim cube into a 2-dim image.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{cube} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
3-dim FITS cube
\end{quote}
\textbf{slicepos} : int or None, optional
\begin{quote}
Slice position (None means to sum along the spectral axis)
\end{quote}
\item[{Returns}] \leavevmode
\textbf{image} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
2-dim FITS image
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{cube\_to\_spec}
\label{api/gammapy.image.cube_to_spec:astropy}\label{api/gammapy.image.cube_to_spec::doc}\label{api/gammapy.image.cube_to_spec:cube-to-spec}\index{cube\_to\_spec() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.cube_to_spec:gammapy.image.cube_to_spec}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{cube\_to\_spec}}{\emph{cube}, \emph{mask}, \emph{weighting='none'}}{}
Integrate spatial dimensions of a FITS cube to give a spectrum.
TODO: give formulas.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{cube} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
3-dim FITS cube
\end{quote}
\textbf{mask} : numpy.array
\begin{quote}
2-dim mask array.
\end{quote}
\textbf{weighting} : \{`none', `solid\_angle'\}, optional
\begin{quote}
Weighting factor to use.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{spectrum} : numpy.array
\begin{quote}
Summed spectrum of pixels in the mask.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{dict\_to\_hdulist}
\label{api/gammapy.image.dict_to_hdulist:astropy}\label{api/gammapy.image.dict_to_hdulist::doc}\label{api/gammapy.image.dict_to_hdulist:dict-to-hdulist}\index{dict\_to\_hdulist() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.dict_to_hdulist:gammapy.image.dict_to_hdulist}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{dict\_to\_hdulist}}{\emph{image\_dict}, \emph{header}}{}
Take a dictionary of image data and a header to create a HDUList.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{image\_dict} : dict
\begin{quote}
Dictionary of input data. The keys are used as FITS extension names.
Image data are the corresponding values.
\end{quote}
\textbf{header} : \href{http://docs.astropy.org/en/latest/io/fits/api/headers.html\#astropy.io.fits.Header}{\code{astropy.io.fits.Header}}
\begin{quote}
Header to be used for all images.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{hdu\_list} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{astropy.io.fits.HDUList}}
\begin{quote}
HDU list of input dictionary.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{disk\_correlate}
\label{api/gammapy.image.disk_correlate:disk-correlate}\label{api/gammapy.image.disk_correlate:astropy}\label{api/gammapy.image.disk_correlate::doc}\index{disk\_correlate() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.disk_correlate:gammapy.image.disk_correlate}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{disk\_correlate}}{\emph{image}, \emph{radius}, \emph{mode='constant'}}{}
Correlate image with binary disk kernel.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{image} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Image to be correlated.
\end{quote}
\textbf{radius} : float
\begin{quote}
Disk radius in pixels.
\end{quote}
\textbf{mode} : \{`reflect','constant','nearest','mirror', `wrap'\}, optional
\begin{quote}
the mode parameter determines how the array borders are handled.
For `constant' mode, values beyond borders are set to be cval.
Default is `constant'.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{convolve} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
The result of convolution of image with disk of given radius.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{downsample\_2N}
\label{api/gammapy.image.downsample_2N:astropy}\label{api/gammapy.image.downsample_2N::doc}\label{api/gammapy.image.downsample_2N:downsample-2n}\index{downsample\_2N() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.downsample_2N:gammapy.image.downsample_2N}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{downsample\_2N}}{\emph{image}, \emph{factor}, \emph{method=\textless{}function nansum\textgreater{}}, \emph{shape=None}}{}
Down sample image by a power of two.
The image is down sampled using \href{http://scikit-image.org/docs/stable/api/skimage.measure.html\#skimage.measure.block\_reduce}{\code{skimage.measure.block\_reduce}}. Only
down sampling factor, that are a power of two are allowed. The image is
padded to a given size using the `reflect' method, before the down sampling
is done.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{image} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Image to be down sampled.
\end{quote}
\textbf{factor} : int
\begin{quote}
Down sampling factor, must be power of two.
\end{quote}
\textbf{method} : np.ufunc (np.nansum), optional
\begin{quote}
Method how to combine the image blocks.
\end{quote}
\textbf{shape} : tuple (None), optional
\begin{quote}
If shape is specified, the image is padded prior to the down sampling
symmetrically in x and y direction to the given shape.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{image} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Down sampled image.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{exclusion\_distance}
\label{api/gammapy.image.exclusion_distance:astropy}\label{api/gammapy.image.exclusion_distance::doc}\label{api/gammapy.image.exclusion_distance:exclusion-distance}\index{exclusion\_distance() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.exclusion_distance:gammapy.image.exclusion_distance}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{exclusion\_distance}}{\emph{exclusion}}{}
Distance to nearest exclusion region.
Compute distance map, i.e. the Euclidean (=Cartesian 2D)
distance (in pixels) to the nearest exclusion region.
We need to call distance\_transform\_edt twice because it only computes
dist for pixels outside exclusion regions, so to get the
distances for pixels inside we call it on the inverted mask
and then combine both distance images into one, using negative
distances (note the minus sign) for pixels inside exclusion regions.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{exclusion} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Exclusion regions as mask.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{distance} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Map of distance to nearest exclusion region.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{find\_max}
\label{api/gammapy.image.find_max:astropy}\label{api/gammapy.image.find_max::doc}\label{api/gammapy.image.find_max:find-max}\index{find\_max() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.find_max:gammapy.image.find_max}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{find\_max}}{\emph{image}}{}
Find position of maximum in an image.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{image} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
Input image
\end{quote}
\item[{Returns}] \leavevmode
\textbf{lon, lat, value} : float
\begin{quote}
Maximum value and its position
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{fits\_to\_png}
\label{api/gammapy.image.fits_to_png:astropy}\label{api/gammapy.image.fits_to_png::doc}\label{api/gammapy.image.fits_to_png:fits-to-png}\index{fits\_to\_png() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.fits_to_png:gammapy.image.fits_to_png}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{fits\_to\_png}}{\emph{infile}, \emph{outfile}, \emph{draw}, \emph{dpi=100}}{}
Plot FITS image in PNG format.
For the default \code{dpi=100} a 1:1 copy of the pixels in the FITS image
and the PNG image is achieved, i.e. they have exactly the same size.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{infile} : str
\begin{quote}
Input FITS file name
\end{quote}
\textbf{outfile} : str
\begin{quote}
Output PNG file name
\end{quote}
\textbf{draw} : callable
\begin{quote}
Callback function \code{draw(figure)}
where \code{figure} is an \href{http://aplpy.readthedocs.org/en/latest/api/aplpy.FITSFigure.html\#aplpy.FITSFigure}{\code{FITSFigure}}.
\end{quote}
\textbf{dpi} : int
\begin{quote}
Resolution
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k}{def} \PYG{n+nf}{draw}\PYG{p}{(}\PYG{n}{figure}\PYG{p}{)}\PYG{p}{:}
\PYG{g+gp}{... } \PYG{n}{x}\PYG{p}{,} \PYG{n}{y}\PYG{p}{,} \PYG{n}{width}\PYG{p}{,} \PYG{n}{height} \PYG{o}{=} \PYG{l+m+mi}{42}\PYG{p}{,} \PYG{l+m+mi}{0}\PYG{p}{,} \PYG{l+m+mi}{3}\PYG{p}{,} \PYG{l+m+mi}{2}
\PYG{g+gp}{... } \PYG{n}{figure}\PYG{o}{.}\PYG{n}{recenter}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,} \PYG{n}{y}\PYG{p}{,} \PYG{n}{width}\PYG{p}{,} \PYG{n}{height}\PYG{p}{)}
\PYG{g+gp}{... } \PYG{n}{figure}\PYG{o}{.}\PYG{n}{show\PYGZus{}grayscale}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.image} \PYG{k+kn}{import} \PYG{n}{fits\PYGZus{}to\PYGZus{}png}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{fits\PYGZus{}to\PYGZus{}png}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{image.fits}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{image.png}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{draw}\PYG{p}{)}
\end{Verbatim}
\end{fulllineitems}
\paragraph{fitsfigure\_add\_psf\_inset}
\label{api/gammapy.image.fitsfigure_add_psf_inset:astropy}\label{api/gammapy.image.fitsfigure_add_psf_inset::doc}\label{api/gammapy.image.fitsfigure_add_psf_inset:fitsfigure-add-psf-inset}\index{fitsfigure\_add\_psf\_inset() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.fitsfigure_add_psf_inset:gammapy.image.fitsfigure_add_psf_inset}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{fitsfigure\_add\_psf\_inset}}{\emph{ff}, \emph{psf}, \emph{box}, \emph{linewidth=1}, \emph{color='w'}, \emph{psf\_position=(0}, \emph{0)}, \emph{**kwargs}}{}
Add PSF inset to \href{http://aplpy.readthedocs.org/en/latest/api/aplpy.FITSFigure.html\#aplpy.FITSFigure}{\code{FITSFigure}} instance.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{ff} : \href{http://aplpy.readthedocs.org/en/latest/api/aplpy.FITSFigure.html\#aplpy.FITSFigure}{\code{FITSFigure}}
\begin{quote}
\href{http://aplpy.readthedocs.org/en/latest/api/aplpy.FITSFigure.html\#aplpy.FITSFigure}{\code{FITSFigure}} instance.
\end{quote}
\textbf{psf} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{astropy.io.fits.ImageHDU}}
\begin{quote}
PSF image.
\end{quote}
\textbf{box} : tuple
\begin{quote}
(x, y, width, height) of the PSF inset in world coordinates.
\end{quote}
\textbf{linewidth} : float
\begin{quote}
Linewidth of the PSF inset frame.
\end{quote}
\textbf{color} : str
\begin{quote}
Color of the PSF inset frame.
\end{quote}
\textbf{psf\_position} : tuple
\begin{quote}
(x, y) position of the psf in in the psf image in pixel coordinates.
\end{quote}
\textbf{kwargs} : dict
\begin{quote}
Further arguments passed to \code{imshow}.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{psf} : \code{Axes}
\begin{quote}
PSF \code{Axes} instance, can be used for further plotting.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{grayify\_colormap}
\label{api/gammapy.image.grayify_colormap:astropy}\label{api/gammapy.image.grayify_colormap::doc}\label{api/gammapy.image.grayify_colormap:grayify-colormap}\index{grayify\_colormap() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.grayify_colormap:gammapy.image.grayify_colormap}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{grayify\_colormap}}{\emph{cmap}, \emph{mode='hsp'}}{}
Return a grayscale version a the colormap.
The grayscale conversion of the colormap is bases on perceived luminance of
the colors. For the conversion either the \href{http://scikit-image.org/docs/stable/api/skimage.color.html\#skimage.color.rgb2gray}{\code{rgb2gray}} or a
generic method called \code{hsp} \phantomsection\label{api/gammapy.image.grayify_colormap:id1}{\hyperref[api/gammapy.image.grayify_colormap:r1]{\emph{{[}R1{]}}}} can be used. The code is loosely based
on \phantomsection\label{api/gammapy.image.grayify_colormap:id2}{\hyperref[api/gammapy.image.grayify_colormap:r2]{\emph{{[}R2{]}}}}.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{cmap} : str or \code{Colormap}
\begin{quote}
Colormap name or instance.
\end{quote}
\textbf{mode} : \{`skimage, `hsp'\}
\begin{quote}
Grayscale conversion method. Either \code{skimage} or \code{hsp}.
\end{quote}
\end{description}\end{quote}
\paragraph{References}
\phantomsection\label{api/gammapy.image.grayify_colormap:id3}{\hyperref[api/gammapy.image.grayify_colormap:r1]{\emph{{[}R1{]}}}}, \phantomsection\label{api/gammapy.image.grayify_colormap:id4}{\hyperref[api/gammapy.image.grayify_colormap:r2]{\emph{{[}R2{]}}}}
\end{fulllineitems}
\paragraph{illustrate\_colormap}
\label{api/gammapy.image.illustrate_colormap:illustrate-colormap}\label{api/gammapy.image.illustrate_colormap:astropy}\label{api/gammapy.image.illustrate_colormap::doc}\index{illustrate\_colormap() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.illustrate_colormap:gammapy.image.illustrate_colormap}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{illustrate\_colormap}}{\emph{cmap}, \emph{**kwargs}}{}
Illustrate color distribution and perceived luminance of a colormap.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{cmap} : str or \code{Colormap}
\begin{quote}
Colormap name or instance.
\end{quote}
\textbf{kwargs} : dicts
\begin{quote}
Keyword arguments passed to {\hyperref[api/gammapy.image.grayify_colormap:gammapy.image.grayify_colormap]{\emph{\code{grayify\_colormap}}}}.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{image\_groupby}
\label{api/gammapy.image.image_groupby:image-groupby}\label{api/gammapy.image.image_groupby:astropy}\label{api/gammapy.image.image_groupby::doc}\index{image\_groupby() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.image_groupby:gammapy.image.image_groupby}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{image\_groupby}}{\emph{images}, \emph{labels}}{}
Group pixel by labels.
This function is similar to \href{http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.measurements.labeled\_comprehension.html\#scipy.ndimage.measurements.labeled\_comprehension}{\code{scipy.ndimage.measurements.labeled\_comprehension}},
but more general because it supports multiple input and output images.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{images} : list of \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
List of image objects.
\end{quote}
\textbf{labels} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Labels for pixel grouping.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{groups} : list of \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Grouped pixels acording to the labels.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{image\_profile}
\label{api/gammapy.image.image_profile:astropy}\label{api/gammapy.image.image_profile::doc}\label{api/gammapy.image.image_profile:image-profile}\index{image\_profile() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.image_profile:gammapy.image.image_profile}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{image\_profile}}{\emph{profile\_axis}, \emph{image}, \emph{lats}, \emph{lons}, \emph{binsz}, \emph{counts=None}, \emph{mask=None}, \emph{errors=False}, \emph{standard\_error=0.1}}{}
Creates a latitude or longitude profile from input flux image HDU.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{profile\_axis} : String, \{`lat', `lon'\}
\begin{quote}
Specified whether galactic latitude (`lat') or longitude (`lon')
profile is to be returned.
\end{quote}
\textbf{image} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
Image HDU object to produce GLAT or GLON profile.
\end{quote}
\textbf{lats} : array\_like
\begin{quote}
Specified as {[}GLAT\_min, GLAT\_max{]}, with GLAT\_min and GLAT\_max
as floats. A 1x2 array specifying the maximum and minimum latitudes to
include in the region of the image for which the profile is formed,
which should be within the spatial bounds of the image.
\end{quote}
\textbf{lons} : array\_like
\begin{quote}
Specified as {[}GLON\_min, GLON\_max{]}, with GLON\_min and GLON\_max
as floats. A 1x2 array specifying the maximum and minimum longitudes to
include in the region of the image for which the profile is formed,
which should be within the spatial bounds of the image.
\end{quote}
\textbf{binsz} : float
\begin{quote}
Latitude bin size of the resulting latitude profile. This should be
no less than 5 times the pixel resolution.
\end{quote}
\textbf{counts} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
Counts image to allow Poisson errors to be calculated. If not provided,
a standard\_error should be provided, or zero errors will be returned.
(Optional).
\end{quote}
\textbf{mask} : array\_like
\begin{quote}
2D mask array, matching spatial dimensions of input image. (Optional).
A mask value of True indicates a value that should be ignored, while a
mask value of False indicates a valid value.
\end{quote}
\textbf{errors} : bool
\begin{quote}
If True, computes errors, if possible, according to provided inputs.
If False (default), returns all errors as zero.
\end{quote}
\textbf{standard\_error} : float
\begin{quote}
If counts image is not provided, but error values required, this
specifies a standard fractional error to be applied to values.
Default = 0.1.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{table} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Galactic latitude or longitude profile as table, with latitude bin
boundaries, profile values and errors.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{images\_to\_cube}
\label{api/gammapy.image.images_to_cube:images-to-cube}\label{api/gammapy.image.images_to_cube:astropy}\label{api/gammapy.image.images_to_cube::doc}\index{images\_to\_cube() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.images_to_cube:gammapy.image.images_to_cube}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{images\_to\_cube}}{\emph{hdu\_list}}{}
Convert a list of image HDUs into one cube.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{hdu\_list} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}
\begin{quote}
List of 2-dimensional image HDUs
\end{quote}
\item[{Returns}] \leavevmode
\textbf{cube} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
3-dimensional cube HDU
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{lon\_lat\_rectangle\_mask}
\label{api/gammapy.image.lon_lat_rectangle_mask:lon-lat-rectangle-mask}\label{api/gammapy.image.lon_lat_rectangle_mask:astropy}\label{api/gammapy.image.lon_lat_rectangle_mask::doc}\index{lon\_lat\_rectangle\_mask() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.lon_lat_rectangle_mask:gammapy.image.lon_lat_rectangle_mask}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{lon\_lat\_rectangle\_mask}}{\emph{lons}, \emph{lats}, \emph{lon\_min=None}, \emph{lon\_max=None}, \emph{lat\_min=None}, \emph{lat\_max=None}}{}
Produces a rectangular boolean mask array based on lat and lon limits.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{lons} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Array of longitude values.
\end{quote}
\textbf{lats} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Array of latitude values.
\end{quote}
\textbf{lon\_min} : float, optional
\begin{quote}
Minimum longitude of rectangular mask.
\end{quote}
\textbf{lon\_max} : float, optional
\begin{quote}
Maximum longitude of rectangular mask.
\end{quote}
\textbf{lat\_min} : float, optional
\begin{quote}
Minimum latitude of rectangular mask.
\end{quote}
\textbf{lat\_max} : float, optional
\begin{quote}
Maximum latitude of rectangular mask.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{mask} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Boolean mask array for a rectangular sub-region defined by specified
maxima and minima lon and lat.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{lookup}
\label{api/gammapy.image.lookup:astropy}\label{api/gammapy.image.lookup::doc}\label{api/gammapy.image.lookup:lookup}\index{lookup() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.lookup:gammapy.image.lookup}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{lookup}}{\emph{image}, \emph{x}, \emph{y}, \emph{world=True}}{}
Look up values in an image.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{image} : array\_like if world=False, astropy.io.fits.ImageHDU if world=True
\begin{quote}
Array or image to look up the value
\end{quote}
\textbf{x} : array\_like
\begin{quote}
Array of X lookup positions
\end{quote}
\textbf{y} : array\_like
\begin{quote}
Array of Y lookup positions
\end{quote}
\textbf{world} : bool
\begin{quote}
Are (x, y) WCS coordinates?
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{lookup\_max}
\label{api/gammapy.image.lookup_max:lookup-max}\label{api/gammapy.image.lookup_max:astropy}\label{api/gammapy.image.lookup_max::doc}\index{lookup\_max() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.lookup_max:gammapy.image.lookup_max}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{lookup\_max}}{\emph{image}, \emph{GLON}, \emph{GLAT}, \emph{theta}}{}
Look up the max image values within a circle of radius theta
around lists of given positions (nan if outside)
\end{fulllineitems}
\paragraph{make\_empty\_image}
\label{api/gammapy.image.make_empty_image:make-empty-image}\label{api/gammapy.image.make_empty_image:astropy}\label{api/gammapy.image.make_empty_image::doc}\index{make\_empty\_image() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.make_empty_image:gammapy.image.make_empty_image}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{make\_empty\_image}}{\emph{nxpix=100}, \emph{nypix=100}, \emph{binsz=0.1}, \emph{xref=0}, \emph{yref=0}, \emph{fill=0}, \emph{proj='CAR'}, \emph{coordsys='GAL'}, \emph{xrefpix=None}, \emph{yrefpix=None}, \emph{dtype='float32'}}{}
Make an empty (i.e. values 0) image.
Uses the same parameter names as the Fermi tool gtbin
(see \href{http://fermi.gsfc.nasa.gov/ssc/data/analysis/scitools/help/gtbin.txt}{http://fermi.gsfc.nasa.gov/ssc/data/analysis/scitools/help/gtbin.txt}).
If no reference pixel position is given it is assumed to be
at the center of the image.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{nxpix} : int, optional
\begin{quote}
Number of pixels in x axis. Default is 100.
\end{quote}
\textbf{nypix} : int, optional
\begin{quote}
Number of pixels in y axis. Default is 100.
\end{quote}
\textbf{binsz} : float, optional
\begin{quote}
Bin size for x and y axes in units of degrees. Default is 0.1.
\end{quote}
\textbf{xref} : float, optional
\begin{quote}
Coordinate system value at reference pixel for x axis. Default is 0.
\end{quote}
\textbf{yref} : float, optional
\begin{quote}
Coordinate system value at reference pixel for y axis. Default is 0.
\end{quote}
\textbf{fill} : float or `checkerboard', optional
\begin{quote}
Creates checkerboard image or uniform image of any float
\end{quote}
\textbf{proj} : string, optional
\begin{quote}
Projection type. Default is `CAR' (cartesian).
\end{quote}
\textbf{coordsys} : \{`CEL', `GAL'\}, optional
\begin{quote}
Coordinate system. Default is `GAL' (Galactic).
\end{quote}
\textbf{xrefpix} : float, optional
\begin{quote}
Coordinate system reference pixel for x axis. Default is None.
\end{quote}
\textbf{yrefpix: float, optional}
\begin{quote}
Coordinate system reference pixel for y axis. Default is None.
\end{quote}
\textbf{dtype} : str, optional
\begin{quote}
Data type, default is float32
\end{quote}
\item[{Returns}] \leavevmode
\textbf{image} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
Empty image
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{make\_header}
\label{api/gammapy.image.make_header:astropy}\label{api/gammapy.image.make_header::doc}\label{api/gammapy.image.make_header:make-header}\index{make\_header() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.make_header:gammapy.image.make_header}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{make\_header}}{\emph{nxpix=100}, \emph{nypix=100}, \emph{binsz=0.1}, \emph{xref=0}, \emph{yref=0}, \emph{proj='CAR'}, \emph{coordsys='GAL'}, \emph{xrefpix=None}, \emph{yrefpix=None}}{}
Generate a FITS header from scratch.
Uses the same parameter names as the Fermi tool gtbin.
If no reference pixel position is given it is assumed ot be
at the center of the image.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{nxpix} : int, optional
\begin{quote}
Number of pixels in x axis. Default is 100.
\end{quote}
\textbf{nypix} : int, optional
\begin{quote}
Number of pixels in y axis. Default is 100.
\end{quote}
\textbf{binsz} : float, optional
\begin{quote}
Bin size for x and y axes in units of degrees. Default is 0.1.
\end{quote}
\textbf{xref} : float, optional
\begin{quote}
Coordinate system value at reference pixel for x axis. Default is 0.
\end{quote}
\textbf{yref} : float, optional
\begin{quote}
Coordinate system value at reference pixel for y axis. Default is 0.
\end{quote}
\textbf{proj} : string, optional
\begin{quote}
Projection type. Default is `CAR' (cartesian).
\end{quote}
\textbf{coordsys} : \{`CEL', `GAL'\}, optional
\begin{quote}
Coordinate system. Default is `GAL' (Galactic).
\end{quote}
\textbf{xrefpix} : float, optional
\begin{quote}
Coordinate system reference pixel for x axis. Default is None.
\end{quote}
\textbf{yrefpix: float, optional}
\begin{quote}
Coordinate system reference pixel for y axis. Default is None.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{header} : \href{http://docs.astropy.org/en/latest/io/fits/api/headers.html\#astropy.io.fits.Header}{\code{Header}}
\begin{quote}
Header
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{measure\_containment}
\label{api/gammapy.image.measure_containment:astropy}\label{api/gammapy.image.measure_containment::doc}\label{api/gammapy.image.measure_containment:measure-containment}\index{measure\_containment() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.measure_containment:gammapy.image.measure_containment}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{measure\_containment}}{\emph{image}, \emph{glon}, \emph{glat}, \emph{radius}}{}
Measure containment in a given circle around the source position.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{image} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{astropy.io.fits.ImageHDU}}
\begin{quote}
Image to measure on.
\end{quote}
\textbf{glon} : float
\begin{quote}
Source longitude in degree.
\end{quote}
\textbf{glat} : float
\begin{quote}
Source latitude in degree.
\end{quote}
\textbf{radius} : float
\begin{quote}
Radius of the region to measure the containment in.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{measure\_containment\_fraction}
\label{api/gammapy.image.measure_containment_fraction:astropy}\label{api/gammapy.image.measure_containment_fraction::doc}\label{api/gammapy.image.measure_containment_fraction:measure-containment-fraction}\index{measure\_containment\_fraction() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.measure_containment_fraction:gammapy.image.measure_containment_fraction}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{measure\_containment\_fraction}}{\emph{r}, \emph{rr}, \emph{image}}{}
Measure containment fraction.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{r} : float
\begin{quote}
Containment radius.
\end{quote}
\textbf{rr} : array
\begin{quote}
Squared radius array.
\end{quote}
\textbf{image} : array
\begin{quote}
The image has to be normalized! I.e. image.sum() = 1.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{containment\_fraction} : float
\begin{quote}
Containment fraction
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{measure\_containment\_radius}
\label{api/gammapy.image.measure_containment_radius:astropy}\label{api/gammapy.image.measure_containment_radius::doc}\label{api/gammapy.image.measure_containment_radius:measure-containment-radius}\index{measure\_containment\_radius() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.measure_containment_radius:gammapy.image.measure_containment_radius}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{measure\_containment\_radius}}{\emph{image}, \emph{glon}, \emph{glat}, \emph{containment\_fraction=0.8}}{}
Measure containment radius.
Uses \href{http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.brentq.html\#scipy.optimize.brentq}{\code{scipy.optimize.brentq}}.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{image} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{astropy.io.fits.ImageHDU}}
\begin{quote}
Image to measure on.
\end{quote}
\textbf{glon} : float
\begin{quote}
Source longitude in degree.
\end{quote}
\textbf{glat} : float
\begin{quote}
Source latitude in degree.
\end{quote}
\textbf{containment\_fraction} : float (default 0.8)
\begin{quote}
Containment fraction
\end{quote}
\item[{Returns}] \leavevmode
\textbf{containment\_radius} : float
\begin{quote}
Containment radius (pix)
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{measure\_curve\_of\_growth}
\label{api/gammapy.image.measure_curve_of_growth:measure-curve-of-growth}\label{api/gammapy.image.measure_curve_of_growth:astropy}\label{api/gammapy.image.measure_curve_of_growth::doc}\index{measure\_curve\_of\_growth() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.measure_curve_of_growth:gammapy.image.measure_curve_of_growth}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{measure\_curve\_of\_growth}}{\emph{image}, \emph{glon}, \emph{glat}, \emph{r\_max=0.2}, \emph{delta\_r=0.01}}{}
Measure the curve of growth for a given source position.
The curve of growth is determined by measuring the flux in a circle around
the source and radius of this circle is increased
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{image} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{astropy.io.fits.ImageHDU}}
\begin{quote}
Image to measure on.
\end{quote}
\textbf{glon} : float
\begin{quote}
Source longitude in degree.
\end{quote}
\textbf{glat} : float
\begin{quote}
Source latitude in degree.
\end{quote}
\textbf{r\_max} : float (default 0.2)
\begin{quote}
Maximal radius, up to which the containment is measured in degree.
\end{quote}
\textbf{delta\_r} : int (default 10)
\begin{quote}
Stepsize for the radius grid in degree.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{radii} : array
\begin{quote}
Radii where the containment was measured.
\end{quote}
\textbf{containment} : array
\begin{quote}
Corresponding contained flux.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{measure\_image\_moments}
\label{api/gammapy.image.measure_image_moments:astropy}\label{api/gammapy.image.measure_image_moments::doc}\label{api/gammapy.image.measure_image_moments:measure-image-moments}\index{measure\_image\_moments() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.measure_image_moments:gammapy.image.measure_image_moments}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{measure\_image\_moments}}{\emph{image}}{}
Compute 0th, 1st and 2nd moments of an image.
NaN values are ignored in the computation.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{image :{}`astropy.io.fits.ImageHDU{}`}
\begin{quote}
Image to measure on.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{image moments} : list
\begin{quote}
List of image moments:
{[}A, x\_cms, y\_cms, x\_sigma, y\_sigma, sqrt(x\_sigma * y\_sigma){]}
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{measure\_labeled\_regions}
\label{api/gammapy.image.measure_labeled_regions:astropy}\label{api/gammapy.image.measure_labeled_regions::doc}\label{api/gammapy.image.measure_labeled_regions:measure-labeled-regions}\index{measure\_labeled\_regions() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.measure_labeled_regions:gammapy.image.measure_labeled_regions}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{measure\_labeled\_regions}}{\emph{data}, \emph{labels}, \emph{tag='IMAGE'}, \emph{measure\_positions=True}, \emph{measure\_values=True}, \emph{fits\_offset=True}, \emph{bbox\_offset=True}}{}
Measure source properties in image.
Sources are defined by a label image.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{TODO}
\item[{Returns}] \leavevmode
TODO
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{paste\_cutout\_into\_image}
\label{api/gammapy.image.paste_cutout_into_image:paste-cutout-into-image}\label{api/gammapy.image.paste_cutout_into_image:astropy}\label{api/gammapy.image.paste_cutout_into_image::doc}\index{paste\_cutout\_into\_image() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.paste_cutout_into_image:gammapy.image.paste_cutout_into_image}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{paste\_cutout\_into\_image}}{\emph{total}, \emph{cutout}, \emph{method='sum'}}{}
Paste cutout into a total image.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{total, cutout} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
Total and cutout image.
\end{quote}
\textbf{method} : \{`sum', `replace'\}, optional
\begin{quote}
Sum or replace total values with cutout values.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{total} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
A reference to the total input HDU that was modified in-place.
\end{quote}
\end{description}\end{quote}
\strong{See also:}
{\hyperref[api/gammapy.image.crop_image:gammapy.image.crop_image]{\emph{\code{crop\_image}}}}
\end{fulllineitems}
\paragraph{process\_image\_pixels}
\label{api/gammapy.image.process_image_pixels:astropy}\label{api/gammapy.image.process_image_pixels::doc}\label{api/gammapy.image.process_image_pixels:process-image-pixels}\index{process\_image\_pixels() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.process_image_pixels:gammapy.image.process_image_pixels}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{process\_image\_pixels}}{\emph{images}, \emph{kernel}, \emph{out}, \emph{pixel\_function}}{}
Process images for a given kernel and per-pixel function.
This is a helper function for the following common task:
For a given set of same-shaped images and a smaller-shaped kernel,
process each image pixel by moving the kernel at that position,
cut out kernel-shaped parts from the images and call a function
to compute output values for that position.
This function loops over image pixels and takes care of bounding
box computations, including image boundary handling.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{images} : dict of arrays
\begin{quote}
Images needed to compute out
\end{quote}
\textbf{kernel} : array (shape must be odd-valued)
\begin{quote}
kernel shape must be odd-valued
\end{quote}
\textbf{out} : single array or dict of arrays
\begin{quote}
These arrays must have been pre-created by the caller
\end{quote}
\textbf{pixel\_function} : function to process a part of the images
\end{description}\end{quote}
\paragraph{Examples}
As an example, here is how to implement convolution as a special
case of process\_image\_pixels with one input and output image:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{convolve}\PYG{p}{(}\PYG{n}{image}\PYG{p}{,} \PYG{n}{kernel}\PYG{p}{)}\PYG{p}{:}
\PYG{l+s+sd}{\PYGZsq{}\PYGZsq{}\PYGZsq{}Convolve image with kernel\PYGZsq{}\PYGZsq{}\PYGZsq{}}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.image.utils} \PYG{k+kn}{import} \PYG{n}{process\PYGZus{}image\PYGZus{}pixels}
\PYG{n}{images} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{image}\PYG{o}{=}\PYG{n}{np}\PYG{o}{.}\PYG{n}{asanyarray}\PYG{p}{(}\PYG{n}{image}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{kernel} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{asanyarray}\PYG{p}{(}\PYG{n}{kernel}\PYG{p}{)}
\PYG{n}{out} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{image}\PYG{o}{=}\PYG{n}{np}\PYG{o}{.}\PYG{n}{empty\PYGZus{}like}\PYG{p}{(}\PYG{n}{image}\PYG{p}{)}\PYG{p}{)}
\PYG{k}{def} \PYG{n+nf}{convolve\PYGZus{}function}\PYG{p}{(}\PYG{n}{images}\PYG{p}{,} \PYG{n}{kernel}\PYG{p}{)}\PYG{p}{:}
\PYG{n}{value} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{sum}\PYG{p}{(}\PYG{n}{images}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{image}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]} \PYG{o}{*} \PYG{n}{kernel}\PYG{p}{)}
\PYG{k}{return} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{image}\PYG{o}{=}\PYG{n}{value}\PYG{p}{)}
\PYG{n}{process\PYGZus{}image\PYGZus{}pixels}\PYG{p}{(}\PYG{n}{images}\PYG{p}{,} \PYG{n}{kernel}\PYG{p}{,} \PYG{n}{out}\PYG{p}{,} \PYG{n}{convolve\PYGZus{}function}\PYG{p}{)}
\PYG{k}{return} \PYG{n}{out}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{image}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]}
\end{Verbatim}
\begin{itemize}
\item {}
TODO: add different options to treat the edges
\item {}
TODO: implement multiprocessing version
\item {} \begin{description}
\item[{TODO: this function is similar to view\_as\_windows in scikit-image:}] \leavevmode
\href{http://scikit-image.org/docs/dev/api/skimage.util.html\#view-as-windows}{http://scikit-image.org/docs/dev/api/skimage.util.html\#view-as-windows}
Is this function needed or can everything be done with view\_as\_windows?
\end{description}
\end{itemize}
\end{fulllineitems}
\paragraph{ring\_correlate}
\label{api/gammapy.image.ring_correlate:ring-correlate}\label{api/gammapy.image.ring_correlate:astropy}\label{api/gammapy.image.ring_correlate::doc}\index{ring\_correlate() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.ring_correlate:gammapy.image.ring_correlate}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{ring\_correlate}}{\emph{image}, \emph{r\_in}, \emph{r\_out}, \emph{mode='constant'}}{}
Correlate image with binary ring kernel.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{image} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Image to be correlated.
\end{quote}
\textbf{r\_in} : float
\begin{quote}
Ring inner radius in pixels.
\end{quote}
\textbf{r\_out} : float
\begin{quote}
Ring outer radius in pixels.
\end{quote}
\textbf{mode} : \{`reflect','constant','nearest','mirror', `wrap'\}, optional
\begin{quote}
the mode parameter determines how the array borders are handled.
For `constant' mode, values beyond borders are set to be cval.
Default is `constant'.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{convolve} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
The result of convolution of image with ring of given inner and outer radii.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{separation}
\label{api/gammapy.image.separation:astropy}\label{api/gammapy.image.separation::doc}\label{api/gammapy.image.separation:separation}\index{separation() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.separation:gammapy.image.separation}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{separation}}{\emph{image}, \emph{center}, \emph{world=True}, \emph{radians=False}}{}
Compute distance image from a given center point.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{image} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
Input image
\end{quote}
\textbf{center} : (x, y) tuple
\begin{quote}
Center position
\end{quote}
\textbf{world} : bool, optional
\begin{quote}
Use world coordinates (or pixel coordinates)?
\end{quote}
\textbf{radians} : bool, optional
\begin{quote}
Return distance in radians or degrees?
(only applicable for world coordinates).
\end{quote}
\item[{Returns}] \leavevmode
\textbf{separation} : array
\begin{quote}
Image of pixel separation to \code{center}.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{shape\_2N}
\label{api/gammapy.image.shape_2N:shape-2n}\label{api/gammapy.image.shape_2N:astropy}\label{api/gammapy.image.shape_2N::doc}\index{shape\_2N() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.shape_2N:gammapy.image.shape_2N}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{shape\_2N}}{\emph{shape}, \emph{N=3}}{}
Round a given shape to values that are divisible by 2\textasciicircum{}N.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{shape} : tuple
\begin{quote}
Input shape.
\end{quote}
\textbf{N} : int (default = 3), optional
\begin{quote}
Exponent of two.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{new\_shape} : Tuple
\begin{quote}
New shape extended to integers divisible by 2\textasciicircum{}N
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{solid\_angle}
\label{api/gammapy.image.solid_angle:astropy}\label{api/gammapy.image.solid_angle::doc}\label{api/gammapy.image.solid_angle:solid-angle}\index{solid\_angle() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.solid_angle:gammapy.image.solid_angle}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{solid\_angle}}{\emph{image}}{}
Compute the solid angle of each pixel.
This will only give correct results for CAR maps!
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{image} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
Input image
\end{quote}
\item[{Returns}] \leavevmode
\textbf{area\_image} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Solid angle image (matching the input image) in steradians.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{threshold}
\label{api/gammapy.image.threshold:astropy}\label{api/gammapy.image.threshold::doc}\label{api/gammapy.image.threshold:threshold}\index{threshold() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.threshold:gammapy.image.threshold}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{threshold}}{\emph{array}, \emph{threshold=5}}{}
Set all pixels below threshold to zero.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{array} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Input array
\end{quote}
\textbf{threshold} : float, optional
\begin{quote}
Minimum threshold
\end{quote}
\item[{Returns}] \leavevmode
\textbf{data} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Copy of input array with pixels below threshold set to zero.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{upsample\_2N}
\label{api/gammapy.image.upsample_2N:upsample-2n}\label{api/gammapy.image.upsample_2N:astropy}\label{api/gammapy.image.upsample_2N::doc}\index{upsample\_2N() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.upsample_2N:gammapy.image.upsample_2N}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{upsample\_2N}}{\emph{image}, \emph{factor}, \emph{order=3}, \emph{shape=None}}{}
Up sample image by a power of two.
The image is up sampled using \code{scipy.ndimage.zoom}. Only
up sampling factors, that are a power of two are allowed. The image is
cropped to a given size.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{image} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Image to be up sampled.
\end{quote}
\textbf{factor} : int
\begin{quote}
up sampling factor, must be power of two.
\end{quote}
\textbf{order} : np.ufunc (np.nansum), optional
\begin{quote}
Method how to combine the image blocks.
\end{quote}
\textbf{shape} : tuple (None), optional
\begin{quote}
If shape is specified, the image is cropped after the up sampling
symmetrically in x and y direction to the given shape.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{image} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Down sampled image.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{wcs\_histogram2d}
\label{api/gammapy.image.wcs_histogram2d:wcs-histogram2d}\label{api/gammapy.image.wcs_histogram2d:astropy}\label{api/gammapy.image.wcs_histogram2d::doc}\index{wcs\_histogram2d() (in module gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.wcs_histogram2d:gammapy.image.wcs_histogram2d}\pysiglinewithargsret{\code{gammapy.image.}\bfcode{wcs\_histogram2d}}{\emph{header}, \emph{lon}, \emph{lat}, \emph{weights=None}}{}
Histogram in world coordinates.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{header} : \href{http://docs.astropy.org/en/latest/io/fits/api/headers.html\#astropy.io.fits.Header}{\code{Header}}
\begin{quote}
FITS Header
\end{quote}
\textbf{lon, lat} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
World coordinates
\end{quote}
\textbf{weights} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}, optional
\begin{quote}
Weights
\end{quote}
\item[{Returns}] \leavevmode
\textbf{histogram} : \href{http://docs.astropy.org/en/latest/io/fits/api/images.html\#astropy.io.fits.ImageHDU}{\code{ImageHDU}}
\begin{quote}
Histogram
\end{quote}
\end{description}\end{quote}
\strong{See also:}
\href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.histogramdd.html\#numpy.histogramdd}{\code{numpy.histogramdd}}
\end{fulllineitems}
\subsubsection{Classes}
\label{image/index:astropy}\label{image/index:classes}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.image.BoundingBox:gammapy.image.BoundingBox]{\emph{\code{BoundingBox}}}}(x\_start, y\_start, x\_stop, y\_stop)
&
Rectangular bounding box.
\\
\hline
{\hyperref[api/gammapy.image.FluxProfile:gammapy.image.FluxProfile]{\emph{\code{FluxProfile}}}}(x\_image, x\_edges, counts, ...{[}, ...{]})
&
Flux profile.
\\
\hline
{\hyperref[api/gammapy.image.GalacticPlaneSurveyPanelPlot:gammapy.image.GalacticPlaneSurveyPanelPlot]{\emph{\code{GalacticPlaneSurveyPanelPlot}}}}({[}npanels, ...{]})
&
Plot Galactic plane survey images in multiple panels.
\\
\hline\end{longtable}
\paragraph{BoundingBox}
\label{api/gammapy.image.BoundingBox:boundingbox}\label{api/gammapy.image.BoundingBox::doc}\index{BoundingBox (class in gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.BoundingBox:gammapy.image.BoundingBox}\pysiglinewithargsret{\strong{class }\code{gammapy.image.}\bfcode{BoundingBox}}{\emph{x\_start}, \emph{y\_start}, \emph{x\_stop}, \emph{y\_stop}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Rectangular bounding box.
TODO: Link to bounding box docs.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{x\_start, y\_start} : float
\begin{quote}
Start pixel coordinates (0-based indexing, inclusive)
\end{quote}
\textbf{x\_stop, y\_stop} : float
\begin{quote}
Stop pixel coordinates (0-based indexing, exclusive)
\end{quote}
\end{description}\end{quote}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.image.BoundingBox:gammapy.image.BoundingBox.ftcopy_string]{\emph{\code{ftcopy\_string}}}}
&
Bounding box in ftcopy string format.
\\
\hline
{\hyperref[api/gammapy.image.BoundingBox:gammapy.image.BoundingBox.is_empty]{\emph{\code{is\_empty}}}}
&
\\
\hline
{\hyperref[api/gammapy.image.BoundingBox:gammapy.image.BoundingBox.slice]{\emph{\code{slice}}}}
&
Bounding box in slice format.
\\
\hline
{\hyperref[api/gammapy.image.BoundingBox:gammapy.image.BoundingBox.x_slice]{\emph{\code{x\_slice}}}}
&
\\
\hline
{\hyperref[api/gammapy.image.BoundingBox:gammapy.image.BoundingBox.y_slice]{\emph{\code{y\_slice}}}}
&
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{ftcopy\_string (gammapy.image.BoundingBox attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.BoundingBox:gammapy.image.BoundingBox.ftcopy_string}\pysigline{\bfcode{ftcopy\_string}}
Bounding box in ftcopy string format.
\paragraph{Examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.image} \PYG{k+kn}{import} \PYG{n}{BoundingBox}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{bounding\PYGZus{}box} \PYG{o}{=} \PYG{n}{BoundingBox}\PYG{p}{(}\PYG{l+m+mi}{7}\PYG{p}{,} \PYG{l+m+mi}{9}\PYG{p}{,} \PYG{l+m+mi}{43}\PYG{p}{,} \PYG{l+m+mi}{44}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{bounding\PYGZus{}box}\PYG{o}{.}\PYG{n}{ftcopy\PYGZus{}string}
\PYG{g+go}{TODO}
\end{Verbatim}
\end{fulllineitems}
\index{is\_empty (gammapy.image.BoundingBox attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.BoundingBox:gammapy.image.BoundingBox.is_empty}\pysigline{\bfcode{is\_empty}}
\end{fulllineitems}
\index{slice (gammapy.image.BoundingBox attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.BoundingBox:gammapy.image.BoundingBox.slice}\pysigline{\bfcode{slice}}
Bounding box in slice format.
\paragraph{Examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.image} \PYG{k+kn}{import} \PYG{n}{BoundingBox}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{bounding\PYGZus{}box} \PYG{o}{=} \PYG{n}{BoundingBox}\PYG{p}{(}\PYG{l+m+mi}{7}\PYG{p}{,} \PYG{l+m+mi}{9}\PYG{p}{,} \PYG{l+m+mi}{43}\PYG{p}{,} \PYG{l+m+mi}{44}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{bounding\PYGZus{}box}\PYG{o}{.}\PYG{n}{slice}
\PYG{g+go}{TODO}
\end{Verbatim}
\end{fulllineitems}
\index{x\_slice (gammapy.image.BoundingBox attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.BoundingBox:gammapy.image.BoundingBox.x_slice}\pysigline{\bfcode{x\_slice}}
\end{fulllineitems}
\index{y\_slice (gammapy.image.BoundingBox attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.BoundingBox:gammapy.image.BoundingBox.y_slice}\pysigline{\bfcode{y\_slice}}
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{for\_circle() (gammapy.image.BoundingBox static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.BoundingBox:gammapy.image.BoundingBox.for_circle}\pysiglinewithargsret{\strong{static }\bfcode{for\_circle}}{\emph{x}, \emph{y}, \emph{radius}}{}
Compute bounding box for a circle.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{x, y} : float
\begin{quote}
Circle center position
\end{quote}
\textbf{radius} : float
\begin{quote}
Circle radius (pix)
\end{quote}
\item[{Returns}] \leavevmode
\textbf{bounding\_box} : BoundingBox
\begin{quote}
Bounding box
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{intersection() (gammapy.image.BoundingBox method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.BoundingBox:gammapy.image.BoundingBox.intersection}\pysiglinewithargsret{\bfcode{intersection}}{\emph{other}}{}
Compute intersection of two bounding boxes.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{other} : {\hyperref[api/gammapy.image.BoundingBox:gammapy.image.BoundingBox]{\emph{\code{BoundingBox}}}}
\begin{quote}
Other bounding box.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{intersection} : {\hyperref[api/gammapy.image.BoundingBox:gammapy.image.BoundingBox]{\emph{\code{BoundingBox}}}}
\begin{quote}
New intersection bounding box
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{b1} \PYG{o}{=} \PYG{n}{BoundingBox}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{l+m+mi}{5}\PYG{p}{,} \PYG{l+m+mi}{10}\PYG{p}{,} \PYG{l+m+mi}{11}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{b2} \PYG{o}{=} \PYG{n}{BoundingBox}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{p}{,} \PYG{l+m+mi}{4}\PYG{p}{,} \PYG{l+m+mi}{13}\PYG{p}{,} \PYG{l+m+mi}{9}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{b1}\PYG{o}{.}\PYG{n}{intersection}\PYG{p}{(}\PYG{n}{b2}\PYG{p}{)}
\PYG{g+go}{TODO}
\end{Verbatim}
\end{fulllineitems}
\index{overlaps() (gammapy.image.BoundingBox method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.BoundingBox:gammapy.image.BoundingBox.overlaps}\pysiglinewithargsret{\bfcode{overlaps}}{\emph{other}}{}
Does this bounding box overlap the other bounding box?
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{other} : {\hyperref[api/gammapy.image.BoundingBox:gammapy.image.BoundingBox]{\emph{\code{BoundingBox}}}}
\begin{quote}
Other bounding box
\end{quote}
\item[{Returns}] \leavevmode
\textbf{overlaps} : bool
\begin{quote}
True of there is overlap
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
TODO
\end{fulllineitems}
\end{fulllineitems}
\paragraph{FluxProfile}
\label{api/gammapy.image.FluxProfile:astropy}\label{api/gammapy.image.FluxProfile::doc}\label{api/gammapy.image.FluxProfile:fluxprofile}\index{FluxProfile (class in gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.FluxProfile:gammapy.image.FluxProfile}\pysiglinewithargsret{\strong{class }\code{gammapy.image.}\bfcode{FluxProfile}}{\emph{x\_image}, \emph{x\_edges}, \emph{counts}, \emph{background}, \emph{exposure}, \emph{mask=None}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Flux profile.
Note: over- and underflow is ignored and not stored in the profile
Note: this is implemented by creating bin labels and storing the
input 2D data in 1D \href{http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html\#pandas.DataFrame}{\code{pandas.DataFrame}} tables.
The 1D profile is also stored as a \href{http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html\#pandas.DataFrame}{\code{pandas.DataFrame}} and computed
using the fast and flexible pandas groupby and apply functions.
\begin{itemize}
\item {}
TODO: take mask into account everywhere
\item {}
TODO: separate FluxProfile.profile into a separate ProfileStack or HistogramStack class?
\item {}
TODO: add \code{solid\_angle} to input arrays.
\end{itemize}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{x\_image} : array\_like
\begin{quote}
Label image (2-dimensional)
\end{quote}
\textbf{x\_edges} : array\_like
\begin{quote}
Defines binning in \code{x} (could be GLON, GLAT, DIST, ...)
\end{quote}
\textbf{counts, background, exposure} : array\_like
\begin{quote}
Input images (2-dimensional)
\end{quote}
\textbf{mask} : array\_like
\begin{quote}
possibility to mask pixels (i.e. ignore in computations)
\end{quote}
\end{description}\end{quote}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{compute() (gammapy.image.FluxProfile method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.FluxProfile:gammapy.image.FluxProfile.compute}\pysiglinewithargsret{\bfcode{compute}}{}{}
Compute the flux profile.
TODO: call {\hyperref[api/gammapy.stats.compute_total_stats:gammapy.stats.compute_total_stats]{\emph{\code{compute\_total\_stats}}}} instead.
Note: the current implementation is very inefficienct in speed and memory.
There are various fast implementations, but none is flexible enough to
allow combining many input quantities (counts, background, exposure) in a
flexlible way:
- \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html\#numpy.histogram}{\code{numpy.histogram}}
- \href{http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.measurements.labeled\_comprehension.html\#scipy.ndimage.measurements.labeled\_comprehension}{\code{scipy.ndimage.measurements.labeled\_comprehension}} and special cases
pandas DataFrame groupby followed by apply is flexible enough, I think:
\href{http://pandas.pydata.org/pandas-docs/dev/groupby.html}{http://pandas.pydata.org/pandas-docs/dev/groupby.html}
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{results} : dict
\begin{quote}
Dictionary of profile measurements, also stored in \code{self.profile}.
\end{quote}
\end{description}\end{quote}
\strong{See also:}
{\hyperref[api/gammapy.stats.compute_total_stats:gammapy.stats.compute_total_stats]{\emph{\code{gammapy.stats.compute\_total\_stats}}}}
\end{fulllineitems}
\index{plot() (gammapy.image.FluxProfile method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.FluxProfile:gammapy.image.FluxProfile.plot}\pysiglinewithargsret{\bfcode{plot}}{\emph{which='n\_entries'}, \emph{xlabel='Distance (deg)'}, \emph{ylabel=None}}{}
Plot flux profile.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{TODO}
\end{description}\end{quote}
\end{fulllineitems}
\index{save() (gammapy.image.FluxProfile method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.FluxProfile:gammapy.image.FluxProfile.save}\pysiglinewithargsret{\bfcode{save}}{\emph{filename}}{}
Save all profiles to a FITS file.
\end{fulllineitems}
\end{fulllineitems}
\paragraph{GalacticPlaneSurveyPanelPlot}
\label{api/gammapy.image.GalacticPlaneSurveyPanelPlot:galacticplanesurveypanelplot}\label{api/gammapy.image.GalacticPlaneSurveyPanelPlot:astropy}\label{api/gammapy.image.GalacticPlaneSurveyPanelPlot::doc}\index{GalacticPlaneSurveyPanelPlot (class in gammapy.image)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.GalacticPlaneSurveyPanelPlot:gammapy.image.GalacticPlaneSurveyPanelPlot}\pysiglinewithargsret{\strong{class }\code{gammapy.image.}\bfcode{GalacticPlaneSurveyPanelPlot}}{\emph{npanels=4}, \emph{center=(0}, \emph{0)}, \emph{fov=(10}, \emph{1)}, \emph{xsize=10}, \emph{ysize=None}, \emph{xborder=0.5}, \emph{yborder=0.5}, \emph{yspacing=0.5}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Plot Galactic plane survey images in multiple panels.
This is useful for very wide, but not so high survey images
(\textasciitilde{}100 deg in Galactic longitude and \textasciitilde{}10 deg in Galactic latitude).
TODO: describe how the callbacks work
References:
\href{http://aplpy.readthedocs.org/en/latest/howto\_subplot.html}{http://aplpy.readthedocs.org/en/latest/howto\_subplot.html}
Attributes:
\begin{itemize}
\item {}
\code{panel\_parameters} -- dict of panel parameters
\item {}
\code{figure} --- Main matplotlib figure (cantains all panels)
\item {}
\code{fits\_figure} --- Current \href{http://aplpy.readthedocs.org/en/latest/api/aplpy.FITSFigure.html\#aplpy.FITSFigure}{\code{aplpy.FITSFigure}}
\end{itemize}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{fits\_figure} : \href{http://aplpy.readthedocs.org/en/latest/api/aplpy.FITSFigure.html\#aplpy.FITSFigure}{\code{aplpy.FITSFigure}}
\begin{quote}
FITSFigure to plot on all panels
\end{quote}
\textbf{npanels} : int
\begin{quote}
Number of panels
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
TODO
TODO: Link to tutorial example
Compute panel parameters and make a matplotlib Figure.
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{bottom() (gammapy.image.GalacticPlaneSurveyPanelPlot method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.GalacticPlaneSurveyPanelPlot:gammapy.image.GalacticPlaneSurveyPanelPlot.bottom}\pysiglinewithargsret{\bfcode{bottom}}{\emph{colorbar\_pars=\{\}}, \emph{colorbar\_label='`}}{}
TODO: needed?
\end{fulllineitems}
\index{draw\_panel() (gammapy.image.GalacticPlaneSurveyPanelPlot method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.GalacticPlaneSurveyPanelPlot:gammapy.image.GalacticPlaneSurveyPanelPlot.draw_panel}\pysiglinewithargsret{\bfcode{draw\_panel}}{\emph{panel=0}, \emph{format=True}}{}
Draw panel.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{panel} : int
\begin{quote}
Panel index
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{draw\_panels() (gammapy.image.GalacticPlaneSurveyPanelPlot method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.GalacticPlaneSurveyPanelPlot:gammapy.image.GalacticPlaneSurveyPanelPlot.draw_panels}\pysiglinewithargsret{\bfcode{draw\_panels}}{\emph{panels='all'}, \emph{format=True}}{}
Draw panels.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{panels} : list of ints or `all'
\begin{quote}
List of panels to draw.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{format\_fits\_figure() (gammapy.image.GalacticPlaneSurveyPanelPlot static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.GalacticPlaneSurveyPanelPlot:gammapy.image.GalacticPlaneSurveyPanelPlot.format_fits_figure}\pysiglinewithargsret{\strong{static }\bfcode{format\_fits\_figure}}{\emph{fits\_figure}, \emph{theme=None}}{}
TODO: describe
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{TODO}
\end{description}\end{quote}
\end{fulllineitems}
\index{top() (gammapy.image.GalacticPlaneSurveyPanelPlot method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.image.GalacticPlaneSurveyPanelPlot:gammapy.image.GalacticPlaneSurveyPanelPlot.top}\pysiglinewithargsret{\bfcode{top}}{}{}
TODO: needed?
\end{fulllineitems}
\end{fulllineitems}
\chapter{Instrument response function (IRF) functionality (\texttt{gammapy.irf})}
\label{irf/index:id1}\label{irf/index:astropy}\label{irf/index::doc}\label{irf/index:irf}\label{irf/index:instrument-response-function-irf-functionality-gammapy-irf}
\section{Introduction}
\label{irf/index:introduction}
{\hyperref[irf/index:module-gammapy.irf]{\emph{\code{gammapy.irf}}}} contains functions and classes to access and model
instrument response functions (IRFs).
\subsection{Theory}
\label{irf/index:theory}
For high-level gamma-ray data analysis (measuring morphology and spectra of sources)
a canonical detector model is used, where the gamma-ray detection process is simplified
as being fully characterized by the following three ``instrument response functions'':
\begin{itemize}
\item {}
Effective area \(A(p, E)\) (unit: \(m^2\))
\item {}
Point spread function \(PSF(p'|p, E)\) (unit: \(sr^{-1}\))
\item {}
Energy dispersion \(D(E'|p, E)\) (unit: \(TeV^{-1}\))
\end{itemize}
The effective area represents the gamma-ray detection efficiency,
the PSF the angular resolution and the energy dispersion the energy resolution
of the instrument.
The full instrument response is given by
\begin{gather}
\begin{split}R(p', E'|p, E) = A(p, E) \times PSF(p'|p, E) \times D(E'|p, E),\end{split}\notag
\end{gather}
where \(p\) and \(E\) are the true gamma-ray position and energy
and \(p'\) and \(E'\) are the reconstructed gamma-ray position and energy.
The instrument function relates sky flux models to expected observed counts distributions via
\begin{gather}
\begin{split}N(p', E') = t_{obs} \int_E \int_\Omega R(p', E'|p, E) \times F(p, E) dp dE,\end{split}\notag
\end{gather}
where \(F\), \(R\), \(t_{obs}\) and \(N\) are the following quantities:
\begin{itemize}
\item {}
Sky flux model \(F(p, E)\) (unit: \(m^{-2} s^{-1} TeV^{-1} sr^{-1}\))
\item {}
Instrument response \(R(p', E'|p, E)\) (unit: \(m^2 TeV^{-1} sr^{-1}\))
\item {}
Observation time: \(t_{obs}\) (unit: \(s\))
\item {}
Expected observed counts model \(N(p', E')\) (unit: \(sr^{-1} TeV^{-1}\))
\end{itemize}
If you'd like to learn more about instrument response functions, have a look at the descriptions for
\href{http://fermi.gsfc.nasa.gov/ssc/data/analysis/documentation/Cicerone/Cicerone\_LAT\_IRFs/index.html}{Fermi},
for \href{http://inspirehep.net/record/1122589}{TeV data analysis}
and for \href{http://gammalib.sourceforge.net/user\_manual/modules/obs.html\#handling-the-instrument-response}{GammaLib}.
TODO: add an overview of what is / isn't available in Gammapy.
\section{Getting Started}
\label{irf/index:getting-started}
TODO: document
\section{Using \texttt{gammapy.image}}
\label{irf/index:using-gammapy-image}
\subsection{Effective area}
\label{irf/effective_area:irf-effective-area}\label{irf/effective_area::doc}\label{irf/effective_area:effective-area}
Here we use {\hyperref[api/gammapy.irf.abramowski_effective_area:gammapy.irf.abramowski_effective_area]{\emph{\code{abramowski\_effective\_area}}}} to show the very approximate effective area of a few TeV telescopes.
\includegraphics{plot_effective_area.pdf}
\subsection{Point spread function}
\label{irf/psf:point-spread-function}\label{irf/psf:astropy}\label{irf/psf::doc}\label{irf/psf:irf-psf}
The {\hyperref[api/gammapy.irf.TablePSF:gammapy.irf.TablePSF]{\emph{\code{TablePSF}}}} and {\hyperref[api/gammapy.irf.EnergyDependentTablePSF:gammapy.irf.EnergyDependentTablePSF]{\emph{\code{EnergyDependentTablePSF}}}} classes
represent radially-symmetric PSFs where the PSF is given at a number of offsets:
\includegraphics{plot_fermi_psf.pdf}
TODO: discuss noise when PSF is estimated from real or simulated data.
\subsection{Energy dispersion}
\label{irf/energy_dispersion:energy-dispersion}\label{irf/energy_dispersion:astropy}\label{irf/energy_dispersion::doc}\label{irf/energy_dispersion:irf-energy-dispersion}
{\hyperref[api/gammapy.irf.EnergyDispersion:gammapy.irf.EnergyDispersion]{\emph{\code{EnergyDispersion}}}}
{\hyperref[api/gammapy.irf.gauss_energy_dispersion_matrix:gammapy.irf.gauss_energy_dispersion_matrix]{\emph{\code{gauss\_energy\_dispersion\_matrix}}}}
{\hyperref[api/gammapy.irf.np_to_rmf:gammapy.irf.np_to_rmf]{\emph{\code{np\_to\_rmf}}}}
\includegraphics{plot_energy_dispersion.pdf}
\section{Reference/API}
\label{irf/index:reference-api}\label{irf/index:astropy}
\subsection{gammapy.irf Package}
\label{irf/index:gammapy-irf-package}\label{irf/index:module-gammapy.irf}\index{gammapy.irf (module)}
Instrument response functions (IRFs)
\subsubsection{Functions}
\label{irf/index:functions}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.irf.abramowski_effective_area:gammapy.irf.abramowski_effective_area]{\emph{\code{abramowski\_effective\_area}}}}(energy{[}, instrument{]})
&
Simple IACT effective area parametrizations from Abramowski et al.
\\
\hline
{\hyperref[api/gammapy.irf.gauss_energy_dispersion_matrix:gammapy.irf.gauss_energy_dispersion_matrix]{\emph{\code{gauss\_energy\_dispersion\_matrix}}}}(ebounds{[}, sigma{]})
&
Create Gaussian energy dispersion matrix.
\\
\hline
{\hyperref[api/gammapy.irf.multi_gauss_psf_kernel:gammapy.irf.multi_gauss_psf_kernel]{\emph{\code{multi\_gauss\_psf\_kernel}}}}(psf\_parameters{[}, ...{]})
&
Create multi-Gauss PSF kernel.
\\
\hline
{\hyperref[api/gammapy.irf.np_to_rmf:gammapy.irf.np_to_rmf]{\emph{\code{np\_to\_rmf}}}}(rm, erange, ebounds, minprob{[}, ...{]})
&
Converts a 2D numpy array to an RMF FITS file.
\\
\hline\end{longtable}
\paragraph{abramowski\_effective\_area}
\label{api/gammapy.irf.abramowski_effective_area::doc}\label{api/gammapy.irf.abramowski_effective_area:abramowski-effective-area}\index{abramowski\_effective\_area() (in module gammapy.irf)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.abramowski_effective_area:gammapy.irf.abramowski_effective_area}\pysiglinewithargsret{\code{gammapy.irf.}\bfcode{abramowski\_effective\_area}}{\emph{energy}, \emph{instrument='HESS'}}{}
Simple IACT effective area parametrizations from Abramowski et al. (2010).
TODO: give formula
Parametrizations of the effective areas of Cherenkov telescopes
taken from Appendix B of \href{http://adsabs.harvard.edu/abs/2010MNRAS.402.1342A}{http://adsabs.harvard.edu/abs/2010MNRAS.402.1342A} .
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energy} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Energy
\end{quote}
\textbf{instrument} : \{`HESS', `HESS2', `CTA'\}
\begin{quote}
Instrument name
\end{quote}
\item[{Returns}] \leavevmode
\textbf{effective\_area} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Effective area in cm\textasciicircum{}2
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{gauss\_energy\_dispersion\_matrix}
\label{api/gammapy.irf.gauss_energy_dispersion_matrix:astropy}\label{api/gammapy.irf.gauss_energy_dispersion_matrix::doc}\label{api/gammapy.irf.gauss_energy_dispersion_matrix:gauss-energy-dispersion-matrix}\index{gauss\_energy\_dispersion\_matrix() (in module gammapy.irf)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.gauss_energy_dispersion_matrix:gammapy.irf.gauss_energy_dispersion_matrix}\pysiglinewithargsret{\code{gammapy.irf.}\bfcode{gauss\_energy\_dispersion\_matrix}}{\emph{ebounds}, \emph{sigma=0.2}}{}
Create Gaussian energy dispersion matrix.
TODO: this is Gaussian in e\_reco ... should be log(e\_reco) I think.
TODO: give formula: Gaussian in log(e\_reco)
TODO: add option to add poisson noise
TODO: extend to have a vector of bias and resolution for various true energies.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{ebounds} : array\_like
\begin{quote}
1-dim energy binning array (TeV)
\end{quote}
\textbf{sigma} : float
\begin{quote}
RMS width of Gaussian energy dispersion.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{pdf\_matrix} : array
\begin{quote}
PDF matrix
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{multi\_gauss\_psf\_kernel}
\label{api/gammapy.irf.multi_gauss_psf_kernel:astropy}\label{api/gammapy.irf.multi_gauss_psf_kernel::doc}\label{api/gammapy.irf.multi_gauss_psf_kernel:multi-gauss-psf-kernel}\index{multi\_gauss\_psf\_kernel() (in module gammapy.irf)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.multi_gauss_psf_kernel:gammapy.irf.multi_gauss_psf_kernel}\pysiglinewithargsret{\code{gammapy.irf.}\bfcode{multi\_gauss\_psf\_kernel}}{\emph{psf\_parameters}, \emph{BINSZ=0.02}, \emph{NEW\_BINSZ=0.02}, \emph{**kwargs}}{}
Create multi-Gauss PSF kernel.
The Gaussian PSF components are specified via the
amplitude at the center and the FWHM.
See the example for the exact format.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{psf\_parameters} : dict
\begin{quote}
PSF parameters
\end{quote}
\textbf{BINSZ} : float (0.02)
\begin{quote}
Pixel size used for the given parameters in deg.
\end{quote}
\textbf{NEW\_BINSZ} : float (0.02)
\begin{quote}
New pixel size in deg. USed to change the resolution of the PSF.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{psf\_kernel} : \href{http://docs.astropy.org/en/latest/api/astropy.convolution.Kernel2D.html\#astropy.convolution.Kernel2D}{\code{astropy.convolution.Kernel2D}}
\begin{quote}
PSF kernel
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{psf\PYGZus{}pars} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{psf\PYGZus{}pars}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{psf1}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{ampl}\PYG{o}{=}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{n}{fwhm}\PYG{o}{=}\PYG{l+m+mf}{2.5}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{psf\PYGZus{}pars}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{psf2}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{ampl}\PYG{o}{=}\PYG{l+m+mf}{0.06}\PYG{p}{,} \PYG{n}{fwhm}\PYG{o}{=}\PYG{l+m+mf}{11.14}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{psf\PYGZus{}pars}\PYG{p}{[}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{psf3}\PYG{l+s}{\PYGZsq{}}\PYG{p}{]} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{ampl}\PYG{o}{=}\PYG{l+m+mf}{0.47}\PYG{p}{,} \PYG{n}{fwhm}\PYG{o}{=}\PYG{l+m+mf}{5.16}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{psf\PYGZus{}kernel} \PYG{o}{=} \PYG{n}{multi\PYGZus{}gauss\PYGZus{}psf\PYGZus{}kernel}\PYG{p}{(}\PYG{n}{psf\PYGZus{}pars}\PYG{p}{,} \PYG{n}{x\PYGZus{}size}\PYG{o}{=}\PYG{l+m+mi}{51}\PYG{p}{)}
\end{Verbatim}
\end{fulllineitems}
\paragraph{np\_to\_rmf}
\label{api/gammapy.irf.np_to_rmf:np-to-rmf}\label{api/gammapy.irf.np_to_rmf:astropy}\label{api/gammapy.irf.np_to_rmf::doc}\index{np\_to\_rmf() (in module gammapy.irf)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.np_to_rmf:gammapy.irf.np_to_rmf}\pysiglinewithargsret{\code{gammapy.irf.}\bfcode{np\_to\_rmf}}{\emph{rm}, \emph{erange}, \emph{ebounds}, \emph{minprob}, \emph{telescope='DUMMY'}, \emph{instrument='DUMMY'}, \emph{filter='NONE'}}{}
Converts a 2D numpy array to an RMF FITS file.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{rm} : 2D float numpy array
\begin{quote}
Energy distribution matrix (probability density) E\_true vs E\_reco.
\end{quote}
\textbf{erange} : 1D float numpy array
\begin{quote}
Bin limits E\_true {[}TeV{]}.
\end{quote}
\textbf{ebounds} : 1D float numpy array
\begin{quote}
Bin limits E\_reco {[}TeV{]}.
\end{quote}
\textbf{minprob} : float
\begin{quote}
Minimal probability density to be stored in the RMF.
\end{quote}
\textbf{telescope, instrument, filter} : string
\begin{quote}
Keyword information for the FITS header.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{hdulist} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}
\begin{quote}
RMF in HDUList format.
\end{quote}
\end{description}\end{quote}
\paragraph{Notes}
For more info on the RMF FITS file format see:
\href{http://heasarc.gsfc.nasa.gov/docs/heasarc/caldb/docs/summary/cal\_gen\_92\_002\_summary.html}{http://heasarc.gsfc.nasa.gov/docs/heasarc/caldb/docs/summary/cal\_gen\_92\_002\_summary.html}
\end{fulllineitems}
\subsubsection{Classes}
\label{irf/index:astropy}\label{irf/index:classes}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.irf.EffectiveAreaTable:gammapy.irf.EffectiveAreaTable]{\emph{\code{EffectiveAreaTable}}}}(energy\_lo, energy\_hi, ...)
&
Effective area table class.
\\
\hline
{\hyperref[api/gammapy.irf.EffectiveAreaTable2D:gammapy.irf.EffectiveAreaTable2D]{\emph{\code{EffectiveAreaTable2D}}}}(energ\_lo, energ\_hi, ...)
&
Offset-dependent radially-symmetric table effective area.
\\
\hline
{\hyperref[api/gammapy.irf.EnergyDependentMultiGaussPSF:gammapy.irf.EnergyDependentMultiGaussPSF]{\emph{\code{EnergyDependentMultiGaussPSF}}}}(energy\_lo, ...)
&
Triple Gauss analytical PSF depending on energy and theta.
\\
\hline
{\hyperref[api/gammapy.irf.EnergyDependentTablePSF:gammapy.irf.EnergyDependentTablePSF]{\emph{\code{EnergyDependentTablePSF}}}}(energy, offset, ...)
&
Energy-dependent radially-symmetric table PSF (\code{gtpsf} format).
\\
\hline
{\hyperref[api/gammapy.irf.EnergyDispersion:gammapy.irf.EnergyDispersion]{\emph{\code{EnergyDispersion}}}}(pdf\_matrix, energy\_true\_bounds)
&
Energy dispersion matrix.
\\
\hline
{\hyperref[api/gammapy.irf.GaussPSF:gammapy.irf.GaussPSF]{\emph{\code{GaussPSF}}}}({[}sigma{]})
&
Extension of Gauss2D PDF by PSF-specific functionality.
\\
\hline
{\hyperref[api/gammapy.irf.HESSMultiGaussPSF:gammapy.irf.HESSMultiGaussPSF]{\emph{\code{HESSMultiGaussPSF}}}}(source)
&
Multi-Gauss PSF as represented in the HESS software.
\\
\hline
{\hyperref[api/gammapy.irf.PositionDependentMultiGaussPSF:gammapy.irf.PositionDependentMultiGaussPSF]{\emph{\code{PositionDependentMultiGaussPSF}}}}(hdu\_list)
&
Position-dependent multi-Gauss PSF.
\\
\hline
{\hyperref[api/gammapy.irf.SherpaMultiGaussPSF:gammapy.irf.SherpaMultiGaussPSF]{\emph{\code{SherpaMultiGaussPSF}}}}(source)
&
Multi-Gauss PSF as represented in the Sherpa software.
\\
\hline
{\hyperref[api/gammapy.irf.TablePSF:gammapy.irf.TablePSF]{\emph{\code{TablePSF}}}}(offset, dp\_domega{[}, spline\_kwargs{]})
&
Radially-symmetric table PSF.
\\
\hline\end{longtable}
\paragraph{EffectiveAreaTable}
\label{api/gammapy.irf.EffectiveAreaTable::doc}\label{api/gammapy.irf.EffectiveAreaTable:effectiveareatable}\index{EffectiveAreaTable (class in gammapy.irf)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EffectiveAreaTable:gammapy.irf.EffectiveAreaTable}\pysiglinewithargsret{\strong{class }\code{gammapy.irf.}\bfcode{EffectiveAreaTable}}{\emph{energy\_lo}, \emph{energy\_hi}, \emph{effective\_area}, \emph{energy\_thresh\_lo=\textless{}Quantity 0.1 TeV\textgreater{}}, \emph{energy\_thresh\_hi=\textless{}Quantity 100.0 TeV\textgreater{}}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Effective area table class.
Not interpolation is used.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energy\_lo} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Lower energy boundary of the energy bin.
\end{quote}
\textbf{energy\_hi} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Upper energy boundary of the energy bin.
\end{quote}
\textbf{effective\_area} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Effective area at the given energy bins.
\end{quote}
\textbf{energy\_thresh\_lo} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Lower save energy threshold of the psf.
\end{quote}
\textbf{energy\_thresh\_hi} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Upper save energy threshold of the psf.
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
Plot effective area vs. energy:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{matplotlib.pyplot} \PYG{k+kn}{as} \PYG{n+nn}{plt}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.irf} \PYG{k+kn}{import} \PYG{n}{EffectiveAreaTable}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.datasets} \PYG{k+kn}{import} \PYG{n}{load\PYGZus{}arf\PYGZus{}fits\PYGZus{}table}
\PYG{n}{arf} \PYG{o}{=} \PYG{n}{EffectiveAreaTable}\PYG{o}{.}\PYG{n}{from\PYGZus{}fits}\PYG{p}{(}\PYG{n}{load\PYGZus{}arf\PYGZus{}fits\PYGZus{}table}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{arf}\PYG{o}{.}\PYG{n}{plot\PYGZus{}area\PYGZus{}vs\PYGZus{}energy}\PYG{p}{(}\PYG{n}{show\PYGZus{}save\PYGZus{}energy}\PYG{o}{=}\PYG{n+nb+bp}{False}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{show}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}
\includegraphics{gammapy-irf-EffectiveAreaTable-1.pdf}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{effective\_area\_at\_energy() (gammapy.irf.EffectiveAreaTable method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EffectiveAreaTable:gammapy.irf.EffectiveAreaTable.effective_area_at_energy}\pysiglinewithargsret{\bfcode{effective\_area\_at\_energy}}{\emph{energy}}{}
Get effective area for given energy.
Not interpolation is used.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energy} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Energy where to return effective area.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{effective\_area} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Effective area at given energy.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{from\_fits() (gammapy.irf.EffectiveAreaTable static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EffectiveAreaTable:gammapy.irf.EffectiveAreaTable.from_fits}\pysiglinewithargsret{\strong{static }\bfcode{from\_fits}}{\emph{hdu\_list}}{}
Create EnergyDependentARF from HDU list.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{hdu\_list} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}
\begin{quote}
HDU list with \code{SPECRESP} extensions.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{arf} : \code{EnergyDependentARF}
\begin{quote}
ARF object.
\end{quote}
\end{description}\end{quote}
\paragraph{Notes}
For more info on the ARF FITS file format see:
\href{http://heasarc.gsfc.nasa.gov/docs/heasarc/caldb/docs/summary/cal\_gen\_92\_002\_summary.html}{http://heasarc.gsfc.nasa.gov/docs/heasarc/caldb/docs/summary/cal\_gen\_92\_002\_summary.html}
Recommended units for ARF tables are keV and cm\textasciicircum{}2,
but TeV and m\textasciicircum{}2 are chosen here as the more natural units for IACTs.
\end{fulllineitems}
\index{info() (gammapy.irf.EffectiveAreaTable method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EffectiveAreaTable:gammapy.irf.EffectiveAreaTable.info}\pysiglinewithargsret{\bfcode{info}}{\emph{energies=\textless{}Quantity {[} 1.}, \emph{10.{]} TeV\textgreater{}}}{}
Print some ARF info.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energies} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Energies for which to print effective areas.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{plot\_area\_vs\_energy() (gammapy.irf.EffectiveAreaTable method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EffectiveAreaTable:gammapy.irf.EffectiveAreaTable.plot_area_vs_energy}\pysiglinewithargsret{\bfcode{plot\_area\_vs\_energy}}{\emph{filename=None}, \emph{show\_save\_energy=True}}{}
Plot effective area vs. energy.
\end{fulllineitems}
\index{read() (gammapy.irf.EffectiveAreaTable static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EffectiveAreaTable:gammapy.irf.EffectiveAreaTable.read}\pysiglinewithargsret{\strong{static }\bfcode{read}}{\emph{filename}}{}
Read FITS format ARF file.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{filename} : str
\begin{quote}
File name
\end{quote}
\item[{Returns}] \leavevmode
\textbf{parf} : \code{EnergyDependentARF}
\begin{quote}
ARF object.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{to\_fits() (gammapy.irf.EffectiveAreaTable method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EffectiveAreaTable:gammapy.irf.EffectiveAreaTable.to_fits}\pysiglinewithargsret{\bfcode{to\_fits}}{\emph{header=None}, \emph{energy\_unit='TeV'}, \emph{effarea\_unit='m2'}, \emph{**kwargs}}{}
Convert ARF to FITS HDU list format.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{header} : \code{Header}
\begin{quote}
Header to be written in the fits file.
\end{quote}
\textbf{energy\_unit} : str
\begin{quote}
Unit in which the energy is written in the fits file
\end{quote}
\textbf{effarea\_\_u} : str
\begin{quote}
Unit in which the effective area is written in the fits file
\end{quote}
\item[{Returns}] \leavevmode
\textbf{hdu\_list} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}
\begin{quote}
ARF in HDU list format.
\end{quote}
\end{description}\end{quote}
\paragraph{Notes}
For more info on the ARF FITS file format see:
\href{http://heasarc.gsfc.nasa.gov/docs/heasarc/caldb/docs/summary/cal\_gen\_92\_002\_summary.html}{http://heasarc.gsfc.nasa.gov/docs/heasarc/caldb/docs/summary/cal\_gen\_92\_002\_summary.html}
Recommended units for ARF tables in X-ray astronomy are keV and cm\textasciicircum{}2,
but TeV and m\textasciicircum{}2 are chosen here by default, as they are the more
natural units for IACTs
\end{fulllineitems}
\index{write() (gammapy.irf.EffectiveAreaTable method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EffectiveAreaTable:gammapy.irf.EffectiveAreaTable.write}\pysiglinewithargsret{\bfcode{write}}{\emph{filename}, \emph{*args}, \emph{**kwargs}}{}
Write ARF to FITS file.
Calls \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList.writeto}{\code{writeto}}, forwarding all arguments.
\end{fulllineitems}
\end{fulllineitems}
\paragraph{EffectiveAreaTable2D}
\label{api/gammapy.irf.EffectiveAreaTable2D:effectiveareatable2d}\label{api/gammapy.irf.EffectiveAreaTable2D:astropy}\label{api/gammapy.irf.EffectiveAreaTable2D::doc}\index{EffectiveAreaTable2D (class in gammapy.irf)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EffectiveAreaTable2D:gammapy.irf.EffectiveAreaTable2D}\pysiglinewithargsret{\strong{class }\code{gammapy.irf.}\bfcode{EffectiveAreaTable2D}}{\emph{energ\_lo}, \emph{energ\_hi}, \emph{offset\_lo}, \emph{offset\_hi}, \emph{eff\_area}, \emph{eff\_area\_reco}, \emph{method='linear'}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Offset-dependent radially-symmetric table effective area.
Two Interpolation methods area available:
\begin{itemize}
\item {}
\href{http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.LinearNDInterpolator.html\#scipy.interpolate.LinearNDInterpolator}{\code{LinearNDInterpolator}} (default)
\item {}
\href{http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.RectBivariateSpline.html\#scipy.interpolate.RectBivariateSpline}{\code{RectBivariateSpline}}
\end{itemize}
Equivalent to GammaLib/ctools{}`{}`GCTAAeff2D FITS{}`{}` format
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energ\_lo} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Lower energy bin edges vector
\end{quote}
\textbf{energ\_hi} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Upper energy bin edges vector
\end{quote}
\textbf{offset\_lo} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
Lower offset bin edges vector
\end{quote}
\textbf{offset\_hi} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
Upper offset bin edges vector
\end{quote}
\textbf{eff\_area} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Effective area vector (true energy)
\end{quote}
\textbf{eff\_area\_reco} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Effective area vector (reconstructed energy)
\end{quote}
\textbf{method} : str
\begin{quote}
Interpolation method
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
Get effective area vs. energy for a given offset and energy binning:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{numpy} \PYG{k+kn}{as} \PYG{n+nn}{np}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.coordinates} \PYG{k+kn}{import} \PYG{n}{Angle}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.units} \PYG{k+kn}{import} \PYG{n}{Quantity}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.irf} \PYG{k+kn}{import} \PYG{n}{EffectiveAreaTable2D}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.datasets} \PYG{k+kn}{import} \PYG{n}{load\PYGZus{}aeff2D\PYGZus{}fits\PYGZus{}table}
\PYG{n}{aeff2D} \PYG{o}{=} \PYG{n}{EffectiveAreaTable2D}\PYG{o}{.}\PYG{n}{from\PYGZus{}fits}\PYG{p}{(}\PYG{n}{load\PYGZus{}aeff2D\PYGZus{}fits\PYGZus{}table}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{offset} \PYG{o}{=} \PYG{n}{Angle}\PYG{p}{(}\PYG{l+m+mf}{0.6}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{degree}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{energy} \PYG{o}{=} \PYG{n}{Quantity}\PYG{p}{(}\PYG{n}{np}\PYG{o}{.}\PYG{n}{logspace}\PYG{p}{(}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{l+m+mi}{1}\PYG{p}{,} \PYG{l+m+mi}{60}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{TeV}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{eff\PYGZus{}area} \PYG{o}{=} \PYG{n}{aeff2D}\PYG{o}{.}\PYG{n}{evaluate}\PYG{p}{(}\PYG{n}{offset}\PYG{p}{,} \PYG{n}{energy}\PYG{p}{)}
\end{Verbatim}
Create ARF fits file for a given offest and energy binning:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{numpy} \PYG{k+kn}{as} \PYG{n+nn}{np}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.coordinates} \PYG{k+kn}{import} \PYG{n}{Angle}
\PYG{k+kn}{from} \PYG{n+nn}{astropy.units} \PYG{k+kn}{import} \PYG{n}{Quantity}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.irf} \PYG{k+kn}{import} \PYG{n}{EffectiveAreaTable2D}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.spectrum} \PYG{k+kn}{import} \PYG{n}{energy\PYGZus{}bounds\PYGZus{}equal\PYGZus{}log\PYGZus{}spacing}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.datasets} \PYG{k+kn}{import} \PYG{n}{load\PYGZus{}aeff2D\PYGZus{}fits\PYGZus{}table}
\PYG{n}{aeff2D} \PYG{o}{=} \PYG{n}{EffectiveAreaTable2D}\PYG{o}{.}\PYG{n}{from\PYGZus{}fits}\PYG{p}{(}\PYG{n}{load\PYGZus{}aeff2D\PYGZus{}fits\PYGZus{}table}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{offset} \PYG{o}{=} \PYG{n}{Angle}\PYG{p}{(}\PYG{l+m+mf}{0.43}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{degree}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{n}{nbins} \PYG{o}{=} \PYG{l+m+mi}{50}
\PYG{n}{energy} \PYG{o}{=} \PYG{n}{energy\PYGZus{}bounds\PYGZus{}equal\PYGZus{}log\PYGZus{}spacing}\PYG{p}{(}\PYG{n}{Quantity}\PYG{p}{(}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{10}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{TeV}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{,} \PYG{n}{nbins}\PYG{p}{)}
\PYG{n}{energ\PYGZus{}lo} \PYG{o}{=} \PYG{n}{energy}\PYG{p}{[}\PYG{p}{:}\PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{1}\PYG{p}{]}
\PYG{n}{energ\PYGZus{}hi} \PYG{o}{=} \PYG{n}{energy}\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{:}\PYG{p}{]}
\PYG{n}{arf\PYGZus{}table} \PYG{o}{=} \PYG{n}{aeff2D}\PYG{o}{.}\PYG{n}{to\PYGZus{}effective\PYGZus{}area\PYGZus{}table}\PYG{p}{(}\PYG{n}{offset}\PYG{p}{,} \PYG{n}{energ\PYGZus{}lo}\PYG{p}{,} \PYG{n}{energ\PYGZus{}hi}\PYG{p}{)}
\PYG{n}{arf\PYGZus{}table}\PYG{o}{.}\PYG{n}{write}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{arf.fits}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\end{Verbatim}
Plot energy dependence
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{matplotlib.pyplot} \PYG{k+kn}{as} \PYG{n+nn}{plt}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.irf} \PYG{k+kn}{import} \PYG{n}{EffectiveAreaTable2D}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.datasets} \PYG{k+kn}{import} \PYG{n}{load\PYGZus{}aeff2D\PYGZus{}fits\PYGZus{}table}
\PYG{n}{aeff2D} \PYG{o}{=} \PYG{n}{EffectiveAreaTable2D}\PYG{o}{.}\PYG{n}{from\PYGZus{}fits}\PYG{p}{(}\PYG{n}{load\PYGZus{}aeff2D\PYGZus{}fits\PYGZus{}table}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{aeff2D}\PYG{o}{.}\PYG{n}{plot\PYGZus{}energy\PYGZus{}dependence}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}
\includegraphics{gammapy-irf-EffectiveAreaTable2D-1.pdf}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{evaluate() (gammapy.irf.EffectiveAreaTable2D method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EffectiveAreaTable2D:gammapy.irf.EffectiveAreaTable2D.evaluate}\pysiglinewithargsret{\bfcode{evaluate}}{\emph{offset=None}, \emph{energy=None}}{}
Evalute effective area for a given energy and offset
If a parameter is not given, the nodes from the FITS table are used.
2D input arrays are not supported yet.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{offset} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
offset
\end{quote}
\textbf{energy} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
energy
\end{quote}
\item[{Returns}] \leavevmode
\textbf{eff\_area} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Effective Area
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{from\_fits() (gammapy.irf.EffectiveAreaTable2D static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EffectiveAreaTable2D:gammapy.irf.EffectiveAreaTable2D.from_fits}\pysiglinewithargsret{\strong{static }\bfcode{from\_fits}}{\emph{hdu\_list}}{}
Create EffectiveAreaTable2D from \code{GCTAAeff2D} format HDU list.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{hdu\_list} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}
\begin{quote}
HDU list with \code{EFFECTIVE AREA} extension.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{eff\_area} : {\hyperref[api/gammapy.irf.EffectiveAreaTable2D:gammapy.irf.EffectiveAreaTable2D]{\emph{\code{EffectiveAreaTable2D}}}}
\begin{quote}
Offset dependent Effective Area object.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{plot\_energy\_dependence() (gammapy.irf.EffectiveAreaTable2D method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EffectiveAreaTable2D:gammapy.irf.EffectiveAreaTable2D.plot_energy_dependence}\pysiglinewithargsret{\bfcode{plot\_energy\_dependence}}{\emph{ax=None}, \emph{offset=None}, \emph{energy=None}, \emph{**kwargs}}{}
Plot effective area versus energy for a given offset.
\end{fulllineitems}
\index{plot\_offset\_dependence() (gammapy.irf.EffectiveAreaTable2D method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EffectiveAreaTable2D:gammapy.irf.EffectiveAreaTable2D.plot_offset_dependence}\pysiglinewithargsret{\bfcode{plot\_offset\_dependence}}{\emph{ax=None}, \emph{offset=None}, \emph{energy=None}, \emph{**kwargs}}{}
Plot effective area versus offset for a given energy
\end{fulllineitems}
\index{read() (gammapy.irf.EffectiveAreaTable2D static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EffectiveAreaTable2D:gammapy.irf.EffectiveAreaTable2D.read}\pysiglinewithargsret{\strong{static }\bfcode{read}}{\emph{filename}}{}
Read FITS format effective area file (\code{GCTAAeff2D} output).
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{filename} : str
\begin{quote}
File name
\end{quote}
\item[{Returns}] \leavevmode
\textbf{eff\_area} : {\hyperref[api/gammapy.irf.EffectiveAreaTable2D:gammapy.irf.EffectiveAreaTable2D]{\emph{\code{EffectiveAreaTable2D}}}}
\begin{quote}
Offset dependent Effective Area object.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{to\_effective\_area\_table() (gammapy.irf.EffectiveAreaTable2D method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EffectiveAreaTable2D:gammapy.irf.EffectiveAreaTable2D.to_effective_area_table}\pysiglinewithargsret{\bfcode{to\_effective\_area\_table}}{\emph{offset}, \emph{energy\_lo=None}, \emph{energy\_hi=None}}{}
Evaluate at a given offset and return effective area table.
The energy thresholds in the effective area table object are not set.
If the effective area table is intended to be used for spectral analysis,
the final energy binning should be given here, since the
effective area table class does no interpolation.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{offset} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
offset
\end{quote}
\textbf{energy\_lo} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
energy lower bounds array
\end{quote}
\textbf{energy\_hi} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
energy upper bounds array
\end{quote}
\item[{Returns}] \leavevmode
\textbf{eff\_area\_table} : {\hyperref[api/gammapy.irf.EffectiveAreaTable:gammapy.irf.EffectiveAreaTable]{\emph{\code{EffectiveAreaTable}}}}
\begin{quote}
Effective area table
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\end{fulllineitems}
\paragraph{EnergyDependentMultiGaussPSF}
\label{api/gammapy.irf.EnergyDependentMultiGaussPSF:astropy}\label{api/gammapy.irf.EnergyDependentMultiGaussPSF::doc}\label{api/gammapy.irf.EnergyDependentMultiGaussPSF:energydependentmultigausspsf}\index{EnergyDependentMultiGaussPSF (class in gammapy.irf)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDependentMultiGaussPSF:gammapy.irf.EnergyDependentMultiGaussPSF}\pysiglinewithargsret{\strong{class }\code{gammapy.irf.}\bfcode{EnergyDependentMultiGaussPSF}}{\emph{energy\_lo}, \emph{energy\_hi}, \emph{theta}, \emph{sigmas}, \emph{norms}, \emph{energy\_thresh\_lo=\textless{}Quantity 0.1 TeV\textgreater{}}, \emph{energy\_thresh\_hi=\textless{}Quantity 100.0 TeV\textgreater{}}, \emph{azimuth=\textless{}Quantity {[} 0.{]} deg\textgreater{}}, \emph{zenith=\textless{}Quantity {[} 0.{]} deg\textgreater{}}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Triple Gauss analytical PSF depending on energy and theta.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energy\_lo} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Lower energy boundary of the energy bin.
\end{quote}
\textbf{energy\_hi} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Upper energy boundary of the energy bin.
\end{quote}
\textbf{theta} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Center values of the theta bins.
\end{quote}
\textbf{sigmas} : list of `numpy.ndarray'
\begin{quote}
Triple Gauss sigma parameters, where every entry is
a two dimensional `numpy.ndarray' containing the sigma
value for every given energy and theta.
\end{quote}
\textbf{norms} : list of `numpy.ndarray'
\begin{quote}
Triple Gauss norm parameters, where every entry is
a two dimensional `numpy.ndarray' containing the norm
value for every given energy and theta. Norm corresponds
to the value of the Gaussian at theta = 0.
\end{quote}
\textbf{energy\_thresh\_lo} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Lower save energy threshold of the psf.
\end{quote}
\textbf{energy\_thresh\_hi} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Upper save energy threshold of the psf.
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
Plot R68 of the PSF vs. theta and energy:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{matplotlib.pyplot} \PYG{k+kn}{as} \PYG{n+nn}{plt}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.irf} \PYG{k+kn}{import} \PYG{n}{EnergyDependentMultiGaussPSF}
\PYG{k+kn}{from} \PYG{n+nn}{gammapy.datasets} \PYG{k+kn}{import} \PYG{n}{load\PYGZus{}psf\PYGZus{}fits\PYGZus{}table}
\PYG{n}{psf} \PYG{o}{=} \PYG{n}{EnergyDependentMultiGaussPSF}\PYG{o}{.}\PYG{n}{from\PYGZus{}fits}\PYG{p}{(}\PYG{n}{load\PYGZus{}psf\PYGZus{}fits\PYGZus{}table}\PYG{p}{(}\PYG{p}{)}\PYG{p}{)}
\PYG{n}{psf}\PYG{o}{.}\PYG{n}{plot\PYGZus{}containment}\PYG{p}{(}\PYG{l+m+mf}{0.68}\PYG{p}{,} \PYG{n}{show\PYGZus{}save\PYGZus{}energy}\PYG{o}{=}\PYG{n+nb+bp}{False}\PYG{p}{)}
\PYG{n}{plt}\PYG{o}{.}\PYG{n}{show}\PYG{p}{(}\PYG{p}{)}
\end{Verbatim}
\includegraphics{gammapy-irf-EnergyDependentMultiGaussPSF-1.pdf}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{from\_fits() (gammapy.irf.EnergyDependentMultiGaussPSF static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDependentMultiGaussPSF:gammapy.irf.EnergyDependentMultiGaussPSF.from_fits}\pysiglinewithargsret{\strong{static }\bfcode{from\_fits}}{\emph{hdu\_list}}{}
Create EnergyDependentMultiGaussPSF from HDU list.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{hdu\_list} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}
\begin{quote}
HDU list with correct extensions.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{psf} : {\hyperref[api/gammapy.irf.EnergyDependentMultiGaussPSF:gammapy.irf.EnergyDependentMultiGaussPSF]{\emph{\code{EnergyDependentMultiGaussPSF}}}}
\begin{quote}
PSF
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{info() (gammapy.irf.EnergyDependentMultiGaussPSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDependentMultiGaussPSF:gammapy.irf.EnergyDependentMultiGaussPSF.info}\pysiglinewithargsret{\bfcode{info}}{\emph{fractions={[}0.68, 0.95{]}, energies=\textless{}Quantity {[} 1., 10.{]} TeV\textgreater{}, thetas=\textless{}Quantity {[} 0.{]} deg\textgreater{}}}{}
Print PSF summary info.
The containment radius for given fraction, energies and thetas is
computed and printed on the command line.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{fractions} : list
\begin{quote}
Containment fraction to compute containment radius for.
\end{quote}
\textbf{energies} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Energies to compute containment radius for.
\end{quote}
\textbf{thetas} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Thetas to compute containment radius for.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{ss} : string
\begin{quote}
Formatted string containing the summary info.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{plot\_containment() (gammapy.irf.EnergyDependentMultiGaussPSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDependentMultiGaussPSF:gammapy.irf.EnergyDependentMultiGaussPSF.plot_containment}\pysiglinewithargsret{\bfcode{plot\_containment}}{\emph{fraction}, \emph{filename=None}, \emph{show\_save\_energy=True}}{}
Plot containment image with energy and theta axes.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{fraction} : float
\begin{quote}
Containment fraction between 0 and 1.
\end{quote}
\textbf{filename} : string
\begin{quote}
Filename under which the plot is saved.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{psf\_at\_energy\_and\_theta() (gammapy.irf.EnergyDependentMultiGaussPSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDependentMultiGaussPSF:gammapy.irf.EnergyDependentMultiGaussPSF.psf_at_energy_and_theta}\pysiglinewithargsret{\bfcode{psf\_at\_energy\_and\_theta}}{\emph{energy}, \emph{theta}}{}
Get {\hyperref[api/gammapy.morphology.MultiGauss2D:gammapy.morphology.MultiGauss2D]{\emph{\code{MultiGauss2D}}}} model for given energy and theta.
No interpolation is used.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energy} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Energy at which a PSF is requested.
\end{quote}
\textbf{theta} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
Offset angle at which a PSF is requested.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{psf} : {\hyperref[api/gammapy.morphology.MultiGauss2D:gammapy.morphology.MultiGauss2D]{\emph{\code{MultiGauss2D}}}}
\begin{quote}
Multigauss PSF object.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{read() (gammapy.irf.EnergyDependentMultiGaussPSF static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDependentMultiGaussPSF:gammapy.irf.EnergyDependentMultiGaussPSF.read}\pysiglinewithargsret{\strong{static }\bfcode{read}}{\emph{filename}}{}
Read FITS format PSF file.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{filename} : str
\begin{quote}
File name
\end{quote}
\item[{Returns}] \leavevmode
\textbf{psf} : {\hyperref[api/gammapy.irf.EnergyDependentMultiGaussPSF:gammapy.irf.EnergyDependentMultiGaussPSF]{\emph{\code{EnergyDependentMultiGaussPSF}}}}
\begin{quote}
PSF
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{to\_fits() (gammapy.irf.EnergyDependentMultiGaussPSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDependentMultiGaussPSF:gammapy.irf.EnergyDependentMultiGaussPSF.to_fits}\pysiglinewithargsret{\bfcode{to\_fits}}{\emph{header=None}, \emph{**kwargs}}{}
Convert psf table data to FITS hdu list.
Any FITS header keyword can be passed to the function and will be
changed in the header.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{header} : \code{Header}
\begin{quote}
Header to be written in the fits file.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{hdu\_list} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}
\begin{quote}
PSF in HDU list format.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{write() (gammapy.irf.EnergyDependentMultiGaussPSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDependentMultiGaussPSF:gammapy.irf.EnergyDependentMultiGaussPSF.write}\pysiglinewithargsret{\bfcode{write}}{\emph{filename}, \emph{*args}, \emph{**kwargs}}{}
Write PSF to FITS file.
Calls \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList.writeto}{\code{writeto}}, forwarding all arguments.
\end{fulllineitems}
\end{fulllineitems}
\paragraph{EnergyDependentTablePSF}
\label{api/gammapy.irf.EnergyDependentTablePSF:energydependenttablepsf}\label{api/gammapy.irf.EnergyDependentTablePSF:astropy}\label{api/gammapy.irf.EnergyDependentTablePSF::doc}\index{EnergyDependentTablePSF (class in gammapy.irf)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDependentTablePSF:gammapy.irf.EnergyDependentTablePSF}\pysiglinewithargsret{\strong{class }\code{gammapy.irf.}\bfcode{EnergyDependentTablePSF}}{\emph{energy}, \emph{offset}, \emph{exposure}, \emph{psf\_value}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Energy-dependent radially-symmetric table PSF (\code{gtpsf} format).
TODO: add references and explanations.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energy} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Energy (1-dim)
\end{quote}
\textbf{offset} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
Offset angle (1-dim)
\end{quote}
\textbf{exposure} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Exposure (1-dim)
\end{quote}
\textbf{psf\_value} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
PSF (2-dim with axes: psf{[}energy\_index, offset\_index{]}
\end{quote}
\end{description}\end{quote}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{containment\_radius() (gammapy.irf.EnergyDependentTablePSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDependentTablePSF:gammapy.irf.EnergyDependentTablePSF.containment_radius}\pysiglinewithargsret{\bfcode{containment\_radius}}{\emph{energy}, \emph{fraction}}{}
Containment radius.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energy} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Energy
\end{quote}
\textbf{fraction} : float
\begin{quote}
Containment fraction in \%
\end{quote}
\item[{Returns}] \leavevmode
\textbf{radius} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Containment radius in deg
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{from\_fits() (gammapy.irf.EnergyDependentTablePSF static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDependentTablePSF:gammapy.irf.EnergyDependentTablePSF.from_fits}\pysiglinewithargsret{\strong{static }\bfcode{from\_fits}}{\emph{hdu\_list}}{}
Create EnergyDependentTablePSF from \code{gtpsf} format HDU list.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{hdu\_list} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}
\begin{quote}
HDU list with \code{THETA} and \code{PSF} extensions.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{psf} : {\hyperref[api/gammapy.irf.EnergyDependentTablePSF:gammapy.irf.EnergyDependentTablePSF]{\emph{\code{EnergyDependentTablePSF}}}}
\begin{quote}
PSF object.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{info() (gammapy.irf.EnergyDependentTablePSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDependentTablePSF:gammapy.irf.EnergyDependentTablePSF.info}\pysiglinewithargsret{\bfcode{info}}{}{}
Print basic info.
\end{fulllineitems}
\index{integral() (gammapy.irf.EnergyDependentTablePSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDependentTablePSF:gammapy.irf.EnergyDependentTablePSF.integral}\pysiglinewithargsret{\bfcode{integral}}{\emph{energy}, \emph{offset\_min}, \emph{offset\_max}}{}
Containment fraction.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energy} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Energy
\end{quote}
\textbf{offset\_min, offset\_max} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
Offset
\end{quote}
\item[{Returns}] \leavevmode
\textbf{fraction} : array\_like
\begin{quote}
Containment fraction (in range 0 .. 1)
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{plot\_containment\_vs\_energy() (gammapy.irf.EnergyDependentTablePSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDependentTablePSF:gammapy.irf.EnergyDependentTablePSF.plot_containment_vs_energy}\pysiglinewithargsret{\bfcode{plot\_containment\_vs\_energy}}{\emph{filename=None}}{}
Plot containment versus energy.
\end{fulllineitems}
\index{plot\_exposure\_vs\_energy() (gammapy.irf.EnergyDependentTablePSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDependentTablePSF:gammapy.irf.EnergyDependentTablePSF.plot_exposure_vs_energy}\pysiglinewithargsret{\bfcode{plot\_exposure\_vs\_energy}}{\emph{filename=None}}{}
Plot exposure versus energy.
\end{fulllineitems}
\index{plot\_psf\_vs\_theta() (gammapy.irf.EnergyDependentTablePSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDependentTablePSF:gammapy.irf.EnergyDependentTablePSF.plot_psf_vs_theta}\pysiglinewithargsret{\bfcode{plot\_psf\_vs\_theta}}{\emph{filename=None, energies={[}10000.0, 100000.0, 1000000.0{]}}}{}
Plot PSF vs theta.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{TODO}
\end{description}\end{quote}
\end{fulllineitems}
\index{read() (gammapy.irf.EnergyDependentTablePSF static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDependentTablePSF:gammapy.irf.EnergyDependentTablePSF.read}\pysiglinewithargsret{\strong{static }\bfcode{read}}{\emph{filename}}{}
Read FITS format PSF file (\code{gtpsf} output).
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{filename} : str
\begin{quote}
File name
\end{quote}
\item[{Returns}] \leavevmode
\textbf{psf} : {\hyperref[api/gammapy.irf.EnergyDependentTablePSF:gammapy.irf.EnergyDependentTablePSF]{\emph{\code{EnergyDependentTablePSF}}}}
\begin{quote}
PSF object.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{table\_psf\_at\_energy() (gammapy.irf.EnergyDependentTablePSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDependentTablePSF:gammapy.irf.EnergyDependentTablePSF.table_psf_at_energy}\pysiglinewithargsret{\bfcode{table\_psf\_at\_energy}}{\emph{energy}, \emph{**kwargs}}{}
TablePSF at a given energy.
Extra \code{kwargs} are passed to the {\hyperref[api/gammapy.irf.TablePSF:gammapy.irf.TablePSF]{\emph{\code{TablePSF}}}} constructor.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energy} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Energy
\end{quote}
\item[{Returns}] \leavevmode
\textbf{psf} : {\hyperref[api/gammapy.irf.TablePSF:gammapy.irf.TablePSF]{\emph{\code{TablePSF}}}}
\begin{quote}
PSF
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{table\_psf\_in\_energy\_band() (gammapy.irf.EnergyDependentTablePSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDependentTablePSF:gammapy.irf.EnergyDependentTablePSF.table_psf_in_energy_band}\pysiglinewithargsret{\bfcode{table\_psf\_in\_energy\_band}}{\emph{energy\_band}, \emph{spectral\_index=2}, \emph{spectrum=None}, \emph{**kwargs}}{}
Average PSF in a given energy band.
Expected counts in sub energy bands given the given exposure
and spectrum are used as weights.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energy\_band} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Energy band
\end{quote}
\textbf{spectral\_index} : float
\begin{quote}
Power law spectral index (used if spectrum=None).
\end{quote}
\textbf{spectrum} : callable
\begin{quote}
Spectrum (callable with energy as parameter).
\end{quote}
\item[{Returns}] \leavevmode
\textbf{psf} : {\hyperref[api/gammapy.irf.TablePSF:gammapy.irf.TablePSF]{\emph{\code{TablePSF}}}}
\begin{quote}
Table PSF
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{to\_fits() (gammapy.irf.EnergyDependentTablePSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDependentTablePSF:gammapy.irf.EnergyDependentTablePSF.to_fits}\pysiglinewithargsret{\bfcode{to\_fits}}{}{}
Convert to FITS HDU list format.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{hdu\_list} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}
\begin{quote}
PSF in HDU list format.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{write() (gammapy.irf.EnergyDependentTablePSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDependentTablePSF:gammapy.irf.EnergyDependentTablePSF.write}\pysiglinewithargsret{\bfcode{write}}{\emph{*args}, \emph{**kwargs}}{}
Write to FITS file.
Calls \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList.writeto}{\code{writeto}}, forwarding all arguments.
\end{fulllineitems}
\end{fulllineitems}
\paragraph{EnergyDispersion}
\label{api/gammapy.irf.EnergyDispersion:astropy}\label{api/gammapy.irf.EnergyDispersion::doc}\label{api/gammapy.irf.EnergyDispersion:energydispersion}\index{EnergyDispersion (class in gammapy.irf)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDispersion:gammapy.irf.EnergyDispersion}\pysiglinewithargsret{\strong{class }\code{gammapy.irf.}\bfcode{EnergyDispersion}}{\emph{pdf\_matrix}, \emph{energy\_true\_bounds}, \emph{energy\_reco\_bounds=None}, \emph{pdf\_threshold=1e-06}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Energy dispersion matrix.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{pdf\_matrix} : array\_like
\begin{quote}
2-dim energy dispersion matrix (probability density).
First index for true energy, second index for reco energy.
\end{quote}
\textbf{energy\_true\_bounds} : array\_like
\begin{quote}
1-dim true energy binning array (TeV)
\end{quote}
\textbf{energy\_reco\_bounds} : array\_like
\begin{quote}
1-dim reco energy binning array (TeV)
\end{quote}
\end{description}\end{quote}
\paragraph{Notes}
We use a dense matrix (\href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{numpy.ndarray}}) for the energy dispersion matrix.
An alternative would be to store a sparse matrix (\href{http://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csc\_matrix.html\#scipy.sparse.csc\_matrix}{\code{scipy.sparse.csc\_matrix}}).
It's not clear which would be more efficient for typical gamma-ray
energy dispersion matrices.
The most common file format for energy dispersion matrices is the
RMF (Redistribution Matrix File) format from X-ray astronomy:
\href{http://heasarc.gsfc.nasa.gov/docs/heasarc/caldb/docs/summary/cal\_gen\_92\_002\_summary.html}{http://heasarc.gsfc.nasa.gov/docs/heasarc/caldb/docs/summary/cal\_gen\_92\_002\_summary.html}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.irf.EnergyDispersion:gammapy.irf.EnergyDispersion.DEFAULT_PDF_THRESHOLD]{\emph{\code{DEFAULT\_PDF\_THRESHOLD}}}}
&
\\
\hline
{\hyperref[api/gammapy.irf.EnergyDispersion:gammapy.irf.EnergyDispersion.pdf_threshold]{\emph{\code{pdf\_threshold}}}}
&
PDF matrix zero-suppression threshold.
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{DEFAULT\_PDF\_THRESHOLD (gammapy.irf.EnergyDispersion attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDispersion:gammapy.irf.EnergyDispersion.DEFAULT_PDF_THRESHOLD}\pysigline{\bfcode{DEFAULT\_PDF\_THRESHOLD}\strong{ = 1e-06}}
\end{fulllineitems}
\index{pdf\_threshold (gammapy.irf.EnergyDispersion attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDispersion:gammapy.irf.EnergyDispersion.pdf_threshold}\pysigline{\bfcode{pdf\_threshold}}
PDF matrix zero-suppression threshold.
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{\_\_call\_\_() (gammapy.irf.EnergyDispersion method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDispersion:gammapy.irf.EnergyDispersion.__call__}\pysiglinewithargsret{\bfcode{\_\_call\_\_}}{\emph{energy\_true}, \emph{energy\_reco}, \emph{method='step'}}{}
Compute energy dispersion.
Available evalutation methods:
\begin{itemize}
\item {}
\code{"step"} -- TODO
\item {}
\code{"interpolate2d"} -- TODO
\end{itemize}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energy\_true} : array\_like
\begin{quote}
True energy
\end{quote}
\textbf{energy\_reco} : array\_like
\begin{quote}
Reconstructed energy
\end{quote}
\textbf{method} : \{`interpolate2d'\}
\begin{quote}
Evaluation method
\end{quote}
\item[{Returns}] \leavevmode
\textbf{pdf} : array
\begin{quote}
Probability density dP / dlog10E\_reco
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{apply() (gammapy.irf.EnergyDispersion method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDispersion:gammapy.irf.EnergyDispersion.apply}\pysiglinewithargsret{\bfcode{apply}}{\emph{data}}{}
Apply energy dispersion.
Computes the matrix product of \code{data}
(which typically is model flux or counts in true energy bins)
with the energy dispersion matrix.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{data} : array\_like
\begin{quote}
1-dim data array.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{convolved\_data} : array
\begin{quote}
1-dim data array after multiplication with the energy dispersion matrix
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{energy\_bounds() (gammapy.irf.EnergyDispersion method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDispersion:gammapy.irf.EnergyDispersion.energy_bounds}\pysiglinewithargsret{\bfcode{energy\_bounds}}{\emph{axis='true'}}{}
Energy bounds array.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{axis} : \{`true', `reco'\}
\begin{quote}
Which axis?
\end{quote}
\item[{Returns}] \leavevmode
\textbf{energy\_bounds} : array
\begin{quote}
Energy bounds array.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{energy\_range() (gammapy.irf.EnergyDispersion method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDispersion:gammapy.irf.EnergyDispersion.energy_range}\pysiglinewithargsret{\bfcode{energy\_range}}{\emph{axis='true'}}{}
Energy axis range.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{axis} : \{`true', `reco'\}
\begin{quote}
Which axis?
\end{quote}
\item[{Returns}] \leavevmode
\textbf{(emin, emax)} : tuple of float
\begin{quote}
Energy axis range.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{from\_hdu\_list() (gammapy.irf.EnergyDispersion static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDispersion:gammapy.irf.EnergyDispersion.from_hdu_list}\pysiglinewithargsret{\strong{static }\bfcode{from\_hdu\_list}}{\emph{hdu\_list}}{}
Create EnergyDistribution object from \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{hdu\_list} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}
\begin{quote}
HDU list with \code{MATRIX} and \code{EBOUNDS} extensions.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{plot() (gammapy.irf.EnergyDispersion method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDispersion:gammapy.irf.EnergyDispersion.plot}\pysiglinewithargsret{\bfcode{plot}}{\emph{type='matrix'}, \emph{energy=None}}{}
Create energy dispersion plot.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{type} : \{`matrix', `bias', `pdf\_energy\_true', `pdf\_energy\_reco'\}
\begin{quote}
Type of plot to generate
\end{quote}
\textbf{energy} : array\_like
\begin{quote}
Energies at which to plot the PDF.
Only applies to type `pdf\_energy\_true' and `pdf\_energy\_reco'.
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
TODO
\end{fulllineitems}
\index{read() (gammapy.irf.EnergyDispersion static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDispersion:gammapy.irf.EnergyDispersion.read}\pysiglinewithargsret{\strong{static }\bfcode{read}}{\emph{filename}, \emph{format='RMF'}}{}
Read from file.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{filename} : str
\begin{quote}
File name
\end{quote}
\textbf{format} : \{`RMF'\}
\begin{quote}
File format
\end{quote}
\item[{Returns}] \leavevmode
\textbf{energy\_dispersion} : {\hyperref[api/gammapy.irf.EnergyDispersion:gammapy.irf.EnergyDispersion]{\emph{\code{EnergyDispersion}}}}
\begin{quote}
Energy dispersion
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{write() (gammapy.irf.EnergyDispersion method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.EnergyDispersion:gammapy.irf.EnergyDispersion.write}\pysiglinewithargsret{\bfcode{write}}{\emph{filename}, \emph{format='RMF'}}{}
Write to file.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{filename} : str
\begin{quote}
File name
\end{quote}
\textbf{format} : \{`RMF'\}
\begin{quote}
File format
\end{quote}
\textbf{pdf\_threshold} : float
\begin{quote}
Zero suppression threshold for energy distribution matrix
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\end{fulllineitems}
\paragraph{GaussPSF}
\label{api/gammapy.irf.GaussPSF:astropy}\label{api/gammapy.irf.GaussPSF::doc}\label{api/gammapy.irf.GaussPSF:gausspsf}\index{GaussPSF (class in gammapy.irf)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.GaussPSF:gammapy.irf.GaussPSF}\pysiglinewithargsret{\strong{class }\code{gammapy.irf.}\bfcode{GaussPSF}}{\emph{sigma=1}}{}
Bases: {\hyperref[api/gammapy.morphology.Gauss2DPDF:gammapy.morphology.Gauss2DPDF]{\emph{\code{gammapy.morphology.Gauss2DPDF}}}}
Extension of Gauss2D PDF by PSF-specific functionality.
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{to\_hess() (gammapy.irf.GaussPSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.GaussPSF:gammapy.irf.GaussPSF.to_hess}\pysiglinewithargsret{\bfcode{to\_hess}}{}{}
\end{fulllineitems}
\index{to\_sherpa() (gammapy.irf.GaussPSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.GaussPSF:gammapy.irf.GaussPSF.to_sherpa}\pysiglinewithargsret{\bfcode{to\_sherpa}}{\emph{binsz}}{}
Generate gauss2d parameters for Sherpa such
that the integral is 1
\end{fulllineitems}
\end{fulllineitems}
\paragraph{HESSMultiGaussPSF}
\label{api/gammapy.irf.HESSMultiGaussPSF:astropy}\label{api/gammapy.irf.HESSMultiGaussPSF::doc}\label{api/gammapy.irf.HESSMultiGaussPSF:hessmultigausspsf}\index{HESSMultiGaussPSF (class in gammapy.irf)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.HESSMultiGaussPSF:gammapy.irf.HESSMultiGaussPSF}\pysiglinewithargsret{\strong{class }\code{gammapy.irf.}\bfcode{HESSMultiGaussPSF}}{\emph{source}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Multi-Gauss PSF as represented in the HESS software.
The 2D Gaussian is represented as a 1D exponential
probability density function per offset angle squared:
dp / dtheta**2 = {[}0{]}*(exp(-x/(2*{[}1{]}*{[}1{]}))+{[}2{]}*exp(-x/(2*{[}3{]}*{[}3{]}))
@param source: either a dict of a filename
The following two parameters control numerical
precision / speed. Usually the defaults are fine.
@param theta\_max: Maximum offset in numerical computations
@param npoints: Number of points in numerical computations
@param eps: Allowed tolerance on normalization of total P to 1
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{containment\_radius() (gammapy.irf.HESSMultiGaussPSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.HESSMultiGaussPSF:gammapy.irf.HESSMultiGaussPSF.containment_radius}\pysiglinewithargsret{\bfcode{containment\_radius}}{\emph{containment\_fraction}}{}
Convolve this PSF with a Gaussian source of width sigma,
then compute the containment angle of that distribution.
\end{fulllineitems}
\index{dpdtheta2() (gammapy.irf.HESSMultiGaussPSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.HESSMultiGaussPSF:gammapy.irf.HESSMultiGaussPSF.dpdtheta2}\pysiglinewithargsret{\bfcode{dpdtheta2}}{\emph{theta2}}{}
dp / dtheta2 at position theta2 = theta \textasciicircum{} 2.
\end{fulllineitems}
\index{n\_gauss() (gammapy.irf.HESSMultiGaussPSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.HESSMultiGaussPSF:gammapy.irf.HESSMultiGaussPSF.n_gauss}\pysiglinewithargsret{\bfcode{n\_gauss}}{}{}
Count number of Gaussians.
\end{fulllineitems}
\index{to\_MultiGauss2D() (gammapy.irf.HESSMultiGaussPSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.HESSMultiGaussPSF:gammapy.irf.HESSMultiGaussPSF.to_MultiGauss2D}\pysiglinewithargsret{\bfcode{to\_MultiGauss2D}}{\emph{normalize=True}}{}
Use this to compute containment angles and fractions.
@note: We have to set norm = 2 * A * sigma \textasciicircum{} 2, because in
MultiGauss2D norm represents the integral, and in HESS A
represents the amplitude at 0.
\end{fulllineitems}
\index{to\_file() (gammapy.irf.HESSMultiGaussPSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.HESSMultiGaussPSF:gammapy.irf.HESSMultiGaussPSF.to_file}\pysiglinewithargsret{\bfcode{to\_file}}{\emph{filename}, \emph{binsz}, \emph{fmt='json'}}{}
Convert parameters to Sherpa format and write them to a JSON file.
\end{fulllineitems}
\index{to\_sherpa() (gammapy.irf.HESSMultiGaussPSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.HESSMultiGaussPSF:gammapy.irf.HESSMultiGaussPSF.to_sherpa}\pysiglinewithargsret{\bfcode{to\_sherpa}}{\emph{binsz}}{}
Convert parameters to Sherpa format.
@param binsz: Bin size (deg)
@return: dict of Sherpa parameters
@note Sherpa uses the following function
f(x,y) = f(r) = A exp{[}-f(r/F)\textasciicircum{}2{]}
f = 2.7725887 = 4log2 relates the full-width
at half-maximum F to the Gaussian sigma.
@note: The sigma parameters in this class are in
deg, but in Sherpa we use pix, so we convert here.
For further explanations on how to convert 1D to 2D Gaussian,
see the docstring of GCTAResponse::psf\_dummy in GammaLib
Input is unnormalized anyways, so we don't care about absolute
PSF normalization here, Sherpa automatically renormalizes. -\textgreater{} Check!
\end{fulllineitems}
\end{fulllineitems}
\paragraph{PositionDependentMultiGaussPSF}
\label{api/gammapy.irf.PositionDependentMultiGaussPSF:astropy}\label{api/gammapy.irf.PositionDependentMultiGaussPSF::doc}\label{api/gammapy.irf.PositionDependentMultiGaussPSF:positiondependentmultigausspsf}\index{PositionDependentMultiGaussPSF (class in gammapy.irf)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.PositionDependentMultiGaussPSF:gammapy.irf.PositionDependentMultiGaussPSF}\pysiglinewithargsret{\strong{class }\code{gammapy.irf.}\bfcode{PositionDependentMultiGaussPSF}}{\emph{hdu\_list}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Position-dependent multi-Gauss PSF.
Represented by a set of images of multi-Gauss PSF parameters.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{hdu\_list} : \href{http://docs.astropy.org/en/latest/io/fits/api/hdulists.html\#astropy.io.fits.HDUList}{\code{HDUList}}
\begin{quote}
HDU list.
\end{quote}
\end{description}\end{quote}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{containment\_radius\_image() (gammapy.irf.PositionDependentMultiGaussPSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.PositionDependentMultiGaussPSF:gammapy.irf.PositionDependentMultiGaussPSF.containment_radius_image}\pysiglinewithargsret{\bfcode{containment\_radius\_image}}{\emph{fraction}}{}
Compute containment radius image.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{fraction} : float
\begin{quote}
Containment fraction
\end{quote}
\item[{Returns}] \leavevmode
\textbf{image} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{numpy.ndarray}}
\begin{quote}
Containment radius image
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{read() (gammapy.irf.PositionDependentMultiGaussPSF static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.PositionDependentMultiGaussPSF:gammapy.irf.PositionDependentMultiGaussPSF.read}\pysiglinewithargsret{\strong{static }\bfcode{read}}{\emph{filename}}{}
Read from FITS file.
\end{fulllineitems}
\end{fulllineitems}
\paragraph{SherpaMultiGaussPSF}
\label{api/gammapy.irf.SherpaMultiGaussPSF:astropy}\label{api/gammapy.irf.SherpaMultiGaussPSF::doc}\label{api/gammapy.irf.SherpaMultiGaussPSF:sherpamultigausspsf}\index{SherpaMultiGaussPSF (class in gammapy.irf)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.SherpaMultiGaussPSF:gammapy.irf.SherpaMultiGaussPSF}\pysiglinewithargsret{\strong{class }\code{gammapy.irf.}\bfcode{SherpaMultiGaussPSF}}{\emph{source}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Multi-Gauss PSF as represented in the Sherpa software.
Note that Sherpa uses the following function
f(x,y) = f(r) = A exp{[}-f(r/F)\textasciicircum{}2{]}
f = 2.7725887 = 4log2 relates the full-width
at half-maximum F to the Gaussian sigma
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{center\_psf() (gammapy.irf.SherpaMultiGaussPSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.SherpaMultiGaussPSF:gammapy.irf.SherpaMultiGaussPSF.center_psf}\pysiglinewithargsret{\bfcode{center\_psf}}{}{}
Set \code{xpos} and \code{ypos} of the PSF to the dataspace center.
\end{fulllineitems}
\index{containment\_fraction() (gammapy.irf.SherpaMultiGaussPSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.SherpaMultiGaussPSF:gammapy.irf.SherpaMultiGaussPSF.containment_fraction}\pysiglinewithargsret{\bfcode{containment\_fraction}}{\emph{theta}, \emph{npix=1000}}{}
Compute fraction of PSF contained inside theta.
\end{fulllineitems}
\index{evaluate() (gammapy.irf.SherpaMultiGaussPSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.SherpaMultiGaussPSF:gammapy.irf.SherpaMultiGaussPSF.evaluate}\pysiglinewithargsret{\bfcode{evaluate}}{\emph{t}, \emph{ampl1}, \emph{fwhm1}, \emph{ampl2}, \emph{fwhm2}, \emph{ampl3}, \emph{fwhm3}}{}
Hand-coded evaluate for debugging.
\end{fulllineitems}
\index{set() (gammapy.irf.SherpaMultiGaussPSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.SherpaMultiGaussPSF:gammapy.irf.SherpaMultiGaussPSF.set}\pysiglinewithargsret{\bfcode{set}}{}{}
Set the PSF for Sherpa.
\end{fulllineitems}
\end{fulllineitems}
\paragraph{TablePSF}
\label{api/gammapy.irf.TablePSF:astropy}\label{api/gammapy.irf.TablePSF::doc}\label{api/gammapy.irf.TablePSF:tablepsf}\index{TablePSF (class in gammapy.irf)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.TablePSF:gammapy.irf.TablePSF}\pysiglinewithargsret{\strong{class }\code{gammapy.irf.}\bfcode{TablePSF}}{\emph{offset}, \emph{dp\_domega}, \emph{spline\_kwargs=\{`k': 1}, \emph{`s': 0\}}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Radially-symmetric table PSF.
This PSF represents a \(PSF(\theta)=dP / d\Omega(\theta)\)
spline interpolation curve for a given set of offset \(\theta\)
and \(PSF\) points.
Uses \href{http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.UnivariateSpline.html\#scipy.interpolate.UnivariateSpline}{\code{scipy.interpolate.UnivariateSpline}}.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{offset} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
Offset angle array
\end{quote}
\textbf{dp\_domega} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
PSF value array
\end{quote}
\textbf{spline\_kwargs} : dict
\begin{quote}
Keyword arguments passed to \href{http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.UnivariateSpline.html\#scipy.interpolate.UnivariateSpline}{\code{UnivariateSpline}}
\end{quote}
\end{description}\end{quote}
\paragraph{Notes}
\begin{itemize}
\item {}
This PSF class works well for model PSFs of arbitrary shape (represented by a table),
but might give unstable results if the PSF has noise.
E.g. if \code{dp\_domega} was estimated from histograms of real or simulated event data
with finite statistics, it will have noise and it is your responsibility
to check that the interpolating spline is reasonable.
\item {}
To customize the spline, pass keyword arguments to \href{http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.UnivariateSpline.html\#scipy.interpolate.UnivariateSpline}{\code{UnivariateSpline}}
in \code{spline\_kwargs}. E.g. passing \code{dict(k=1)} changes from the default cubic to
linear interpolation.
\item {}
TODO: evaluate spline for \code{(log(offset), log(PSF))} for numerical stability?
\item {}
TODO: merge morphology.theta class functionality with this class.
\item {}
TODO: add FITS I/O methods
\item {}
TODO: add \code{normalize} argument to \code{\_\_init\_\_} with default \code{True}?
\item {}
TODO: \code{\_\_call\_\_} doesn't show up in the html API docs, but it should:
\href{https://github.com/astropy/astropy/pull/2135}{https://github.com/astropy/astropy/pull/2135}
\end{itemize}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{\_\_call\_\_() (gammapy.irf.TablePSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.TablePSF:gammapy.irf.TablePSF.__call__}\pysiglinewithargsret{\bfcode{\_\_call\_\_}}{\emph{lon}, \emph{lat}}{}
Evaluate PSF at a 2D position.
The PSF is centered on \code{(0, 0)}.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{lon, lat} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
Longitude / latitude position
\end{quote}
\item[{Returns}] \leavevmode
\textbf{psf\_value} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
PSF value
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{broaden() (gammapy.irf.TablePSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.TablePSF:gammapy.irf.TablePSF.broaden}\pysiglinewithargsret{\bfcode{broaden}}{\emph{factor}, \emph{normalize=True}}{}
Broaden PSF by scaling the offset array.
For a broadening factor \(f\) and the offset
array \(\theta\), the offset array scaled
in the following way:
\begin{gather}
\begin{split}\theta_{new} = f \times \theta_{old}
\frac{dP}{d\theta}(\theta_{new}) = \frac{dP}{d\theta}(\theta_{old})\end{split}\notag
\end{gather}\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{factor} : float
\begin{quote}
Broadening factor
\end{quote}
\textbf{normalize} : bool
\begin{quote}
Normalize PSF after broadening
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{containment\_radius() (gammapy.irf.TablePSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.TablePSF:gammapy.irf.TablePSF.containment_radius}\pysiglinewithargsret{\bfcode{containment\_radius}}{\emph{fraction}}{}
Containment radius.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{fraction} : array\_like
\begin{quote}
Containment fraction (range 0 .. 1)
\end{quote}
\item[{Returns}] \leavevmode
\textbf{radius} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
Containment radius angle
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{evaluate() (gammapy.irf.TablePSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.TablePSF:gammapy.irf.TablePSF.evaluate}\pysiglinewithargsret{\bfcode{evaluate}}{\emph{offset}, \emph{quantity='dp\_domega'}}{}
Evaluate PSF.
The following PSF quantities are available:
\begin{itemize}
\item {}
`dp\_domega': PDF per 2-dim solid angle \(\Omega\) in sr\textasciicircum{}-1
\begin{quote}
\begin{gather}
\begin{split}\frac{dP}{d\Omega}\end{split}\notag
\end{gather}\end{quote}
\item {}
`dp\_dtheta': PDF per 1-dim offset \(\theta\) in radian\textasciicircum{}-1
\begin{quote}
\begin{gather}
\begin{split}\frac{dP}{d\theta} = 2 \pi \theta \frac{dP}{d\Omega}\end{split}\notag
\end{gather}\end{quote}
\end{itemize}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{offset} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
Offset angle
\end{quote}
\textbf{quantity} : \{`dp\_domega', `dp\_dtheta'\}
\begin{quote}
Which PSF quantity?
\end{quote}
\item[{Returns}] \leavevmode
\textbf{psf\_value} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
PSF value
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{from\_shape() (gammapy.irf.TablePSF static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.TablePSF:gammapy.irf.TablePSF.from_shape}\pysiglinewithargsret{\strong{static }\bfcode{from\_shape}}{\emph{shape}, \emph{width}, \emph{offset}}{}
Make TablePSF objects with commonly used shapes.
This function is mostly useful for examples and testing.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{shape} : \{`disk', `gauss'\}
\begin{quote}
PSF shape.
\end{quote}
\textbf{width} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
PSF width angle (radius for disk, sigma for Gauss).
\end{quote}
\textbf{offset} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
Offset angle
\end{quote}
\item[{Returns}] \leavevmode
\textbf{psf} : {\hyperref[api/gammapy.irf.TablePSF:gammapy.irf.TablePSF]{\emph{\code{TablePSF}}}}
\begin{quote}
Table PSF
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{import} \PYG{n+nn}{numpy} \PYG{k+kn}{as} \PYG{n+nn}{np}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{astropy.coordinates} \PYG{k+kn}{import} \PYG{n}{Angle}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.irf} \PYG{k+kn}{import} \PYG{n}{make\PYGZus{}table\PYGZus{}psf}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{make\PYGZus{}table\PYGZus{}psf}\PYG{p}{(}\PYG{n}{shape}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{gauss}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{width}\PYG{o}{=}\PYG{n}{Angle}\PYG{p}{(}\PYG{l+m+mf}{0.2}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{degree}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{,}
\PYG{g+gp}{... } \PYG{n}{offset}\PYG{o}{=}\PYG{n}{Angle}\PYG{p}{(}\PYG{n}{np}\PYG{o}{.}\PYG{n}{linspace}\PYG{p}{(}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{l+m+mf}{0.7}\PYG{p}{,} \PYG{l+m+mi}{100}\PYG{p}{)}\PYG{p}{,} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{degree}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}\PYG{p}{)}
\end{Verbatim}
\end{fulllineitems}
\index{info() (gammapy.irf.TablePSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.TablePSF:gammapy.irf.TablePSF.info}\pysiglinewithargsret{\bfcode{info}}{}{}
Print basic info.
\end{fulllineitems}
\index{integral() (gammapy.irf.TablePSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.TablePSF:gammapy.irf.TablePSF.integral}\pysiglinewithargsret{\bfcode{integral}}{\emph{offset\_min=None}, \emph{offset\_max=None}}{}
Compute PSF integral, aka containment fraction.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{offset\_min, offset\_max} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
Offset angle range
\end{quote}
\item[{Returns}] \leavevmode
\textbf{integral} : float
\begin{quote}
PSF integral
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{kernel() (gammapy.irf.TablePSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.TablePSF:gammapy.irf.TablePSF.kernel}\pysiglinewithargsret{\bfcode{kernel}}{\emph{pixel\_size}, \emph{offset\_max=None}, \emph{normalize=True}, \emph{discretize\_model\_kwargs=\{`factor': 10\}}}{}
Make a 2-dimensional kernel image.
The kernel image is evaluated on a cartesian
grid with \code{pixel\_size} spacing, not on the sphere.
Calls \href{http://docs.astropy.org/en/latest/api/astropy.convolution.discretize\_model.html\#astropy.convolution.discretize\_model}{\code{astropy.convolution.discretize\_model}},
allowing for accurate discretization.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{pixel\_size} : \href{http://docs.astropy.org/en/latest/api/astropy.coordinates.Angle.html\#astropy.coordinates.Angle}{\code{Angle}}
\begin{quote}
Kernel pixel size
\end{quote}
\textbf{discretize\_model\_kwargs} : dict
\begin{quote}
Keyword arguments passed to
\href{http://docs.astropy.org/en/latest/api/astropy.convolution.discretize\_model.html\#astropy.convolution.discretize\_model}{\code{astropy.convolution.discretize\_model}}
\end{quote}
\item[{Returns}] \leavevmode
\textbf{kernel} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Kernel 2D image of Quantities
\end{quote}
\end{description}\end{quote}
\paragraph{Notes}
\begin{itemize}
\item {}
In the future, \href{http://docs.astropy.org/en/latest/api/astropy.modeling.Fittable2DModel.html\#astropy.modeling.Fittable2DModel}{\code{astropy.modeling.Fittable2DModel}} and
\href{http://docs.astropy.org/en/latest/api/astropy.convolution.Model2DKernel.html\#astropy.convolution.Model2DKernel}{\code{astropy.convolution.Model2DKernel}} could be used to construct
the kernel.
\end{itemize}
\end{fulllineitems}
\index{normalize() (gammapy.irf.TablePSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.TablePSF:gammapy.irf.TablePSF.normalize}\pysiglinewithargsret{\bfcode{normalize}}{}{}
Normalize PSF to unit integral.
Computes the total PSF integral via the \(dP / d heta\) spline
and then divides the \(dP / d heta\) array.
\end{fulllineitems}
\index{plot\_psf\_vs\_theta() (gammapy.irf.TablePSF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.irf.TablePSF:gammapy.irf.TablePSF.plot_psf_vs_theta}\pysiglinewithargsret{\bfcode{plot\_psf\_vs\_theta}}{\emph{quantity='dp\_domega'}}{}
Plot PSF vs offset.
TODO: describe PSF \code{quantity} argument in a central place and link to it from here.
\end{fulllineitems}
\end{fulllineitems}
\chapter{Morphology and PSF methods (\texttt{gammapy.morphology})}
\label{morphology/index:morphology-and-psf-methods-gammapy-morphology}\label{morphology/index:astropy}\label{morphology/index::doc}\label{morphology/index:morphology}
\section{Introduction}
\label{morphology/index:introduction}
{\hyperref[morphology/index:module-gammapy.morphology]{\emph{\code{gammapy.morphology}}}} contains functions and classes for morphology and PSF computations.
TODO: write me
\section{Getting Started}
\label{morphology/index:getting-started}
TODO: write me
\section{Reference/API}
\label{morphology/index:reference-api}
\subsection{gammapy.morphology Package}
\label{morphology/index:module-gammapy.morphology}\label{morphology/index:gammapy-morphology-package}\index{gammapy.morphology (module)}
Morphology and PSF methods.
Some parts of this package use Sherpa.
\subsubsection{Functions}
\label{morphology/index:functions}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.morphology.gaussian_sum_moments:gammapy.morphology.gaussian_sum_moments]{\emph{\code{gaussian\_sum\_moments}}}}(F, sigma, x, y, cov\_matrix)
&
Compute image moments with uncertainties for sum of Gaussians.
\\
\hline
{\hyperref[api/gammapy.morphology.make_test_model:gammapy.morphology.make_test_model]{\emph{\code{make\_test\_model}}}}({[}nsources, npix, ampl, ...{]})
&
Create a model of several Gaussian sources.
\\
\hline
{\hyperref[api/gammapy.morphology.read_ascii:gammapy.morphology.read_ascii]{\emph{\code{read\_ascii}}}}(filename, setter)
&
Read from ASCII file.
\\
\hline
{\hyperref[api/gammapy.morphology.read_json:gammapy.morphology.read_json]{\emph{\code{read\_json}}}}(source, setter)
&
Read from JSON file.
\\
\hline
{\hyperref[api/gammapy.morphology.write_all:gammapy.morphology.write_all]{\emph{\code{write\_all}}}}({[}filename{]})
&
Dump source, fit results and conf results to a JSON file.
\\
\hline
{\hyperref[api/gammapy.morphology.write_ascii:gammapy.morphology.write_ascii]{\emph{\code{write\_ascii}}}}(pars, filename)
&
Write to ASCII
\\
\hline
{\hyperref[api/gammapy.morphology.write_json:gammapy.morphology.write_json]{\emph{\code{write\_json}}}}(pars, filename)
&
Write to JSON file.
\\
\hline\end{longtable}
\paragraph{gaussian\_sum\_moments}
\label{api/gammapy.morphology.gaussian_sum_moments::doc}\label{api/gammapy.morphology.gaussian_sum_moments:gaussian-sum-moments}\index{gaussian\_sum\_moments() (in module gammapy.morphology)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.gaussian_sum_moments:gammapy.morphology.gaussian_sum_moments}\pysiglinewithargsret{\code{gammapy.morphology.}\bfcode{gaussian\_sum\_moments}}{\emph{F}, \emph{sigma}, \emph{x}, \emph{y}, \emph{cov\_matrix}, \emph{shift=0.5}}{}
Compute image moments with uncertainties for sum of Gaussians.
The moments are computed analytically, the formulae are documented below.
Calls \code{uncertainties.correlated\_values} to propagate the errors.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{F} : array
\begin{quote}
Integral norms of the Gaussian components.
\end{quote}
\textbf{sigmas} : array
\begin{quote}
Widths of the Gaussian components.
\end{quote}
\textbf{x} : array
\begin{quote}
x positions of the Gaussian components.
\end{quote}
\textbf{y} : array
\begin{quote}
y positions of the Gaussian components.
\end{quote}
\textbf{cov\_matrix} : array
\begin{quote}
Covariance matrix of the parameters. The columns have to follow the order:
{[}sigma\_1, x\_1, y\_1, F\_1, sigma\_2, x\_2, y\_2, F\_2, ..., sigma\_N, x\_N, y\_N, F\_N{]}
\end{quote}
\textbf{shift} : float (default = 0.5)
\begin{quote}
Depending on where the image values are given, the grid has to be
shifted. If the values are given at the center of the pixel
shift = 0.5.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{nominal\_values} : list
\begin{quote}
List of image moment nominal values:
{[}F\_sum, x\_sum, y\_sum, x\_sigma, y\_sigma, sqrt(x\_sigma * y\_sigma){]}
All values are given in pixel coordinates.
\end{quote}
\textbf{std\_devs} : list
\begin{quote}
List of image moment standard deviations.
\end{quote}
\end{description}\end{quote}
\paragraph{Notes}
The 0th moment (total flux) is given by:
\begin{gather}
\begin{split}F_{\Sigma} = \int_{-\infty}^{\infty}f_{\Sigma}(x, y)dx dy =
\sum_i^N F_i\end{split}\notag
\end{gather}
The 1st moments (position) are given by:
\begin{gather}
\begin{split}x_{\Sigma} = \frac{1}{F_{\Sigma}} \int_{-\infty}^{\infty}x
f_{\Sigma}(x, y)dx dy = \frac{1}{F_{\Sigma}}\sum_i^N x_iF_i\end{split}\notag\\\begin{split}y_{\Sigma} = \frac{1}{F_{\Sigma}} \int_{-\infty}^{\infty}y
f_{\Sigma}(x, y)dx dy = \frac{1}{F_{\Sigma}}\sum_i^N y_iF_i\end{split}\notag
\end{gather}
The 2nd moments (extension) are given by:
\begin{gather}
\begin{split}\sigma_{\Sigma_x}^2 = \frac{1}{F_{\Sigma}} \sum_i^N F_i
\cdot (\sigma_i^2 + x_i^2) - x_{\Sigma}^2\end{split}\notag\\\begin{split}\sigma_{\Sigma_y}^2 = \frac{1}{F_{\Sigma}} \sum_i^N F_i
\cdot (\sigma_i^2 + y_i^2) - y_{\Sigma}^2\end{split}\notag
\end{gather}\paragraph{Examples}
A simple example for an image consisting of three Gaussians
with zero covariance matrix:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{import} \PYG{n+nn}{numpy} \PYG{k+kn}{as} \PYG{n+nn}{np}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.morphology.gauss} \PYG{k+kn}{import} \PYG{n}{gaussian\PYGZus{}sum\PYGZus{}moments}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{cov\PYGZus{}matrix} \PYG{o}{=} \PYG{n}{np}\PYG{o}{.}\PYG{n}{zeros}\PYG{p}{(}\PYG{p}{(}\PYG{l+m+mi}{12}\PYG{p}{,} \PYG{l+m+mi}{12}\PYG{p}{)}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{F} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mi}{100}\PYG{p}{,} \PYG{l+m+mi}{200}\PYG{p}{,} \PYG{l+m+mi}{300}\PYG{p}{]}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{sigma} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mi}{15}\PYG{p}{,} \PYG{l+m+mi}{10}\PYG{p}{,} \PYG{l+m+mi}{5}\PYG{p}{]}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{x} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mi}{100}\PYG{p}{,} \PYG{l+m+mi}{120}\PYG{p}{,} \PYG{l+m+mi}{70}\PYG{p}{]}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{y} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mi}{100}\PYG{p}{,} \PYG{l+m+mi}{90}\PYG{p}{,} \PYG{l+m+mi}{120}\PYG{p}{]}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{nominal\PYGZus{}values}\PYG{p}{,} \PYG{n}{std\PYGZus{}devs} \PYG{o}{=} \PYG{n}{gaussian\PYGZus{}sum\PYGZus{}moments}\PYG{p}{(}\PYG{n}{F}\PYG{p}{,} \PYG{n}{sigma}\PYG{p}{,} \PYG{n}{x}\PYG{p}{,} \PYG{n}{y}\PYG{p}{,} \PYG{n}{cov\PYGZus{}matrix}\PYG{p}{)}
\end{Verbatim}
\end{fulllineitems}
\paragraph{make\_test\_model}
\label{api/gammapy.morphology.make_test_model:make-test-model}\label{api/gammapy.morphology.make_test_model:astropy}\label{api/gammapy.morphology.make_test_model::doc}\index{make\_test\_model() (in module gammapy.morphology)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.make_test_model:gammapy.morphology.make_test_model}\pysiglinewithargsret{\code{gammapy.morphology.}\bfcode{make\_test\_model}}{\emph{nsources=100}, \emph{npix=500}, \emph{ampl=100}, \emph{fwhm=30}, \emph{random\_state='random-seed'}}{}
Create a model of several Gaussian sources.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{random\_state} : \{int, `random-seed', `global-rng', \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.RandomState.html\#numpy.random.RandomState}{\code{RandomState}}\}
\begin{quote}
Defines random number generator initialisation.
Passed to {\hyperref[api/gammapy.utils.random.get_random_state:gammapy.utils.random.get_random_state]{\emph{\code{get\_random\_state}}}}.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{read\_ascii}
\label{api/gammapy.morphology.read_ascii:astropy}\label{api/gammapy.morphology.read_ascii::doc}\label{api/gammapy.morphology.read_ascii:read-ascii}\index{read\_ascii() (in module gammapy.morphology)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.read_ascii:gammapy.morphology.read_ascii}\pysiglinewithargsret{\code{gammapy.morphology.}\bfcode{read\_ascii}}{\emph{filename}, \emph{setter}}{}
Read from ASCII file.
\end{fulllineitems}
\paragraph{read\_json}
\label{api/gammapy.morphology.read_json:astropy}\label{api/gammapy.morphology.read_json::doc}\label{api/gammapy.morphology.read_json:read-json}\index{read\_json() (in module gammapy.morphology)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.read_json:gammapy.morphology.read_json}\pysiglinewithargsret{\code{gammapy.morphology.}\bfcode{read\_json}}{\emph{source}, \emph{setter}}{}
Read from JSON file.
\end{fulllineitems}
\paragraph{write\_all}
\label{api/gammapy.morphology.write_all:write-all}\label{api/gammapy.morphology.write_all:astropy}\label{api/gammapy.morphology.write_all::doc}\index{write\_all() (in module gammapy.morphology)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.write_all:gammapy.morphology.write_all}\pysiglinewithargsret{\code{gammapy.morphology.}\bfcode{write\_all}}{\emph{filename='results.json'}}{}
Dump source, fit results and conf results to a JSON file.
\href{http://www.astropython.org/snippet/2010/7/Save-sherpa-fit-and-conf-results-to-a-JSON-file}{http://www.astropython.org/snippet/2010/7/Save-sherpa-fit-and-conf-results-to-a-JSON-file}
\end{fulllineitems}
\paragraph{write\_ascii}
\label{api/gammapy.morphology.write_ascii:write-ascii}\label{api/gammapy.morphology.write_ascii:astropy}\label{api/gammapy.morphology.write_ascii::doc}\index{write\_ascii() (in module gammapy.morphology)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.write_ascii:gammapy.morphology.write_ascii}\pysiglinewithargsret{\code{gammapy.morphology.}\bfcode{write\_ascii}}{\emph{pars}, \emph{filename}}{}
Write to ASCII
\end{fulllineitems}
\paragraph{write\_json}
\label{api/gammapy.morphology.write_json:astropy}\label{api/gammapy.morphology.write_json::doc}\label{api/gammapy.morphology.write_json:write-json}\index{write\_json() (in module gammapy.morphology)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.write_json:gammapy.morphology.write_json}\pysiglinewithargsret{\code{gammapy.morphology.}\bfcode{write\_json}}{\emph{pars}, \emph{filename}}{}
Write to JSON file.
\end{fulllineitems}
\subsubsection{Classes}
\label{morphology/index:astropy}\label{morphology/index:classes}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.morphology.Delta2D:gammapy.morphology.Delta2D]{\emph{\code{Delta2D}}}}(amplitude, x\_0, y\_0, **constraints)
&
Two dimensional delta function .
\\
\hline
{\hyperref[api/gammapy.morphology.Gauss2DPDF:gammapy.morphology.Gauss2DPDF]{\emph{\code{Gauss2DPDF}}}}({[}sigma{]})
&
2D symmetric Gaussian PDF.
\\
\hline
{\hyperref[api/gammapy.morphology.GaussCatalog:gammapy.morphology.GaussCatalog]{\emph{\code{GaussCatalog}}}}(source)
&
Multi-Gauss catalog utils.
\\
\hline
{\hyperref[api/gammapy.morphology.ModelThetaCalculator:gammapy.morphology.ModelThetaCalculator]{\emph{\code{ModelThetaCalculator}}}}(source, psf, fov, binsz)
&
Compute containment radius for given radially symmetric source and psf as well as desired containment fraction.
\\
\hline
{\hyperref[api/gammapy.morphology.MorphModelImageCreator:gammapy.morphology.MorphModelImageCreator]{\emph{\code{MorphModelImageCreator}}}}(cfg\_file, exposure{[}, ...{]})
&
Create model images from a HGPS pipeline source config file.
\\
\hline
{\hyperref[api/gammapy.morphology.MultiGauss2D:gammapy.morphology.MultiGauss2D]{\emph{\code{MultiGauss2D}}}}(sigmas{[}, norms{]})
&
Sum of multiple 2D Gaussians.
\\
\hline
{\hyperref[api/gammapy.morphology.Shell2D:gammapy.morphology.Shell2D]{\emph{\code{Shell2D}}}}(amplitude, x\_0, y\_0, r\_in{[}, width, ...{]})
&
Projected homogeneous radiating shell model.
\\
\hline
{\hyperref[api/gammapy.morphology.Sphere2D:gammapy.morphology.Sphere2D]{\emph{\code{Sphere2D}}}}(amplitude, x\_0, y\_0, r\_0{[}, normed{]})
&
Projected homogeneous radiating sphere model.
\\
\hline
{\hyperref[api/gammapy.morphology.ThetaCalculator:gammapy.morphology.ThetaCalculator]{\emph{\code{ThetaCalculator}}}}(dist, theta\_max, n\_bins{[}, ...{]})
&
Provides methods \code{containment\_fraction(theta)} and \code{containment\_radius(containment\_fraction)} given some 1D distribution (not necessarily normalized).
\\
\hline
{\hyperref[api/gammapy.morphology.ThetaCalculator2D:gammapy.morphology.ThetaCalculator2D]{\emph{\code{ThetaCalculator2D}}}}(dist, x, y)
&
Methods to compute theta and containment for a given 2D probability distribution image.
\\
\hline
{\hyperref[api/gammapy.morphology.ThetaCalculatorScipy:gammapy.morphology.ThetaCalculatorScipy]{\emph{\code{ThetaCalculatorScipy}}}}(dist, theta\_max{[}, ...{]})
&
Same functionality as NumericalThetaCalculator, but uses \code{scipy.integrate.quad} and \code{scipy.optimize.fsolve} instead.
\\
\hline\end{longtable}
\paragraph{Delta2D}
\label{api/gammapy.morphology.Delta2D:delta2d}\label{api/gammapy.morphology.Delta2D::doc}\index{Delta2D (class in gammapy.morphology)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Delta2D:gammapy.morphology.Delta2D}\pysiglinewithargsret{\strong{class }\code{gammapy.morphology.}\bfcode{Delta2D}}{\emph{amplitude}, \emph{x\_0}, \emph{y\_0}, \emph{**constraints}}{}
Bases: \href{http://docs.astropy.org/en/latest/api/astropy.modeling.Fittable2DModel.html\#astropy.modeling.Fittable2DModel}{\code{astropy.modeling.Fittable2DModel}}
Two dimensional delta function .
This model can be used for a point source morphology.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{amplitude} : float
\begin{quote}
Peak value of the point source
\end{quote}
\textbf{x\_0} : float
\begin{quote}
x position center of the point source
\end{quote}
\textbf{y\_0} : float
\begin{quote}
y position center of the point source
\end{quote}
\end{description}\end{quote}
\strong{See also:}
{\hyperref[api/gammapy.morphology.Shell2D:gammapy.morphology.Shell2D]{\emph{\code{Shell2D}}}}, {\hyperref[api/gammapy.morphology.Sphere2D:gammapy.morphology.Sphere2D]{\emph{\code{Sphere2D}}}}, \code{astropy.modeling.models.Gaussian2D}
\paragraph{Notes}
Model formula:
\begin{gather}
\begin{split}f(x, y) = \cdot \left \{
\begin{array}{ll}
A & : x = x_0 \ \mathrm{and} \ y = y_0 \\
0 & : else
\end{array}
\right.\end{split}\notag
\end{gather}
The pixel positions x\_0 and y\_0 are rounded to integers. Subpixel
information is lost.
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.morphology.Delta2D:gammapy.morphology.Delta2D.param_names]{\emph{\code{param\_names}}}}
&
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{amplitude (gammapy.morphology.Delta2D attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Delta2D:gammapy.morphology.Delta2D.amplitude}\pysigline{\bfcode{amplitude}}
\end{fulllineitems}
\index{param\_names (gammapy.morphology.Delta2D attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Delta2D:gammapy.morphology.Delta2D.param_names}\pysigline{\bfcode{param\_names}\strong{ = (`amplitude', `x\_0', `y\_0')}}
\end{fulllineitems}
\index{x\_0 (gammapy.morphology.Delta2D attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Delta2D:gammapy.morphology.Delta2D.x_0}\pysigline{\bfcode{x\_0}}
\end{fulllineitems}
\index{y\_0 (gammapy.morphology.Delta2D attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Delta2D:gammapy.morphology.Delta2D.y_0}\pysigline{\bfcode{y\_0}}
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{evaluate() (gammapy.morphology.Delta2D static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Delta2D:gammapy.morphology.Delta2D.evaluate}\pysiglinewithargsret{\strong{static }\bfcode{evaluate}}{\emph{x}, \emph{y}, \emph{amplitude}, \emph{x\_0}, \emph{y\_0}}{}
Two dimensional delta model function
\end{fulllineitems}
\end{fulllineitems}
\paragraph{Gauss2DPDF}
\label{api/gammapy.morphology.Gauss2DPDF:gauss2dpdf}\label{api/gammapy.morphology.Gauss2DPDF:astropy}\label{api/gammapy.morphology.Gauss2DPDF::doc}\index{Gauss2DPDF (class in gammapy.morphology)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Gauss2DPDF:gammapy.morphology.Gauss2DPDF}\pysiglinewithargsret{\strong{class }\code{gammapy.morphology.}\bfcode{Gauss2DPDF}}{\emph{sigma=1}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
2D symmetric Gaussian PDF.
Reference: \href{http://en.wikipedia.org/wiki/Multivariate\_normal\_distribution\#Bivariate\_case}{http://en.wikipedia.org/wiki/Multivariate\_normal\_distribution\#Bivariate\_case}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{sigma} : float
\begin{quote}
Gaussian width.
\end{quote}
\end{description}\end{quote}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.morphology.Gauss2DPDF:gammapy.morphology.Gauss2DPDF.amplitude]{\emph{\code{amplitude}}}}
&
PDF amplitude at the center.
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{amplitude (gammapy.morphology.Gauss2DPDF attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Gauss2DPDF:gammapy.morphology.Gauss2DPDF.amplitude}\pysigline{\bfcode{amplitude}}
PDF amplitude at the center.
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{\_\_call\_\_() (gammapy.morphology.Gauss2DPDF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Gauss2DPDF:gammapy.morphology.Gauss2DPDF.__call__}\pysiglinewithargsret{\bfcode{\_\_call\_\_}}{\emph{x}, \emph{y=0}}{}
dp / (dx dy) at position (x, y).
\end{fulllineitems}
\index{containment\_fraction() (gammapy.morphology.Gauss2DPDF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Gauss2DPDF:gammapy.morphology.Gauss2DPDF.containment_fraction}\pysiglinewithargsret{\bfcode{containment\_fraction}}{\emph{theta}}{}
Containment fraction.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{theta} : array\_like
\begin{quote}
Offset
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{containment\_radius() (gammapy.morphology.Gauss2DPDF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Gauss2DPDF:gammapy.morphology.Gauss2DPDF.containment_radius}\pysiglinewithargsret{\bfcode{containment\_radius}}{\emph{containment\_fraction}}{}
Containment angle for a given containment fraction.
\end{fulllineitems}
\index{dpdtheta2() (gammapy.morphology.Gauss2DPDF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Gauss2DPDF:gammapy.morphology.Gauss2DPDF.dpdtheta2}\pysiglinewithargsret{\bfcode{dpdtheta2}}{\emph{theta2}}{}
dp / dtheta2 at position theta2 = theta \textasciicircum{} 2.
\end{fulllineitems}
\index{gauss\_convolve() (gammapy.morphology.Gauss2DPDF method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Gauss2DPDF:gammapy.morphology.Gauss2DPDF.gauss_convolve}\pysiglinewithargsret{\bfcode{gauss\_convolve}}{\emph{sigma}}{}
Convolve with another Gaussian 2D PDF.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{TODO}
\item[{Returns}] \leavevmode
TODO
\end{description}\end{quote}
\end{fulllineitems}
\end{fulllineitems}
\paragraph{GaussCatalog}
\label{api/gammapy.morphology.GaussCatalog:gausscatalog}\label{api/gammapy.morphology.GaussCatalog:astropy}\label{api/gammapy.morphology.GaussCatalog::doc}\index{GaussCatalog (class in gammapy.morphology)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.GaussCatalog:gammapy.morphology.GaussCatalog}\pysiglinewithargsret{\strong{class }\code{gammapy.morphology.}\bfcode{GaussCatalog}}{\emph{source}}{}
Bases: \href{http://docs.python.org/library/stdtypes.html\#dict}{\code{dict}}
Multi-Gauss catalog utils.
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{set() (gammapy.morphology.GaussCatalog method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.GaussCatalog:gammapy.morphology.GaussCatalog.set}\pysiglinewithargsret{\bfcode{set}}{}{}
\end{fulllineitems}
\end{fulllineitems}
\paragraph{ModelThetaCalculator}
\label{api/gammapy.morphology.ModelThetaCalculator:astropy}\label{api/gammapy.morphology.ModelThetaCalculator::doc}\label{api/gammapy.morphology.ModelThetaCalculator:modelthetacalculator}\index{ModelThetaCalculator (class in gammapy.morphology)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.ModelThetaCalculator:gammapy.morphology.ModelThetaCalculator}\pysiglinewithargsret{\strong{class }\code{gammapy.morphology.}\bfcode{ModelThetaCalculator}}{\emph{source}, \emph{psf}, \emph{fov}, \emph{binsz}, \emph{call2d=False}}{}
Bases: {\hyperref[api/gammapy.morphology.ThetaCalculator:gammapy.morphology.ThetaCalculator]{\emph{\code{gammapy.morphology.ThetaCalculator}}}}
Compute containment radius for given radially symmetric
source and psf as well as desired containment fraction.
Uses 2D images for the computation.
Slow but simple, so useful to check more complicated methods.
Source and PSF must be callable and return
dP/dtheta (@todo: or dP/dtheta\textasciicircum{}2?)
fov = field of view (deg)
binsz = bin size (deg)
The source is supposed to be contained in the FOV
even after PSF convolution.
\end{fulllineitems}
\paragraph{MorphModelImageCreator}
\label{api/gammapy.morphology.MorphModelImageCreator:astropy}\label{api/gammapy.morphology.MorphModelImageCreator::doc}\label{api/gammapy.morphology.MorphModelImageCreator:morphmodelimagecreator}\index{MorphModelImageCreator (class in gammapy.morphology)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.MorphModelImageCreator:gammapy.morphology.MorphModelImageCreator}\pysiglinewithargsret{\strong{class }\code{gammapy.morphology.}\bfcode{MorphModelImageCreator}}{\emph{cfg\_file}, \emph{exposure}, \emph{psf\_file=None}, \emph{apply\_psf=True}, \emph{background=None}, \emph{flux\_factor=1e-12}, \emph{compute\_excess=True}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Create model images from a HGPS pipeline source config file.
Uses astropy to evaluate the source model, with oversampling or integrating
over pixels.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{cfg\_file} : str
\begin{quote}
Config file with all the sources listed.
\end{quote}
\textbf{exposure} : str
\begin{quote}
Fits image file with the exposure.
\end{quote}
\textbf{psf\_file} : str (optional)
\begin{quote}
Json file with PSF information.
\end{quote}
\textbf{background} : str (optional)
\begin{quote}
Fits image file with the background.
\end{quote}
\textbf{apply\_psf} : bool (default True)
\begin{quote}
Whether the psf should be applied.
\end{quote}
\textbf{compute\_excess} : bool (default True)
\begin{quote}
Whether to compute an excess image.
\end{quote}
\textbf{flux\_factor} : float (default 1E-12)
\begin{quote}
Flux conversion factor.
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
Here is an example how to use {\hyperref[api/gammapy.morphology.MorphModelImageCreator:gammapy.morphology.MorphModelImageCreator]{\emph{\code{MorphModelImageCreator}}}}:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.morphology} \PYG{k+kn}{import} \PYG{n}{MorphModelImageCreator}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{model\PYGZus{}image\PYGZus{}creator} \PYG{o}{=} \PYG{n}{MorphModelImageCreator}\PYG{p}{(}\PYG{n}{cfg\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{input\PYGZus{}sherpa.cfg}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,}
\PYG{g+gp}{... } \PYG{n}{exposure}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{exposure.fits}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,}
\PYG{g+gp}{... } \PYG{n}{psf\PYGZus{}file}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{psf.json}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{model\PYGZus{}image\PYGZus{}creator}\PYG{o}{.}\PYG{n}{evaluate\PYGZus{}model}\PYG{p}{(}\PYG{n}{mode}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{center}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{model\PYGZus{}image\PYGZus{}creator}\PYG{o}{.}\PYG{n}{save}\PYG{p}{(}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{model\PYGZus{}image.fits}\PYG{l+s}{\PYGZsq{}}\PYG{p}{)}
\end{Verbatim}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{evaluate\_model() (gammapy.morphology.MorphModelImageCreator method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.MorphModelImageCreator:gammapy.morphology.MorphModelImageCreator.evaluate_model}\pysiglinewithargsret{\bfcode{evaluate\_model}}{\emph{**kwargs}}{}
Evaluate model by oversampling or taking the value at the center of the pixel.
\end{fulllineitems}
\index{fake\_counts() (gammapy.morphology.MorphModelImageCreator method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.MorphModelImageCreator:gammapy.morphology.MorphModelImageCreator.fake_counts}\pysiglinewithargsret{\bfcode{fake\_counts}}{\emph{N}, \emph{random\_state='random-seed'}, \emph{**kwargs}}{}
Fake measurement data by adding Poisson noise to the model image.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{N} : int
\begin{quote}
Number of measurements to fake.
\end{quote}
\textbf{random\_state} : \{int, `random-seed', `global-rng', \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.RandomState.html\#numpy.random.RandomState}{\code{RandomState}}\}
\begin{quote}
Defines random number generator initialisation.
Passed to {\hyperref[api/gammapy.utils.random.get_random_state:gammapy.utils.random.get_random_state]{\emph{\code{get\_random\_state}}}}.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{save() (gammapy.morphology.MorphModelImageCreator method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.MorphModelImageCreator:gammapy.morphology.MorphModelImageCreator.save}\pysiglinewithargsret{\bfcode{save}}{\emph{filename}, \emph{**kwargs}}{}
Save model image to file.
\end{fulllineitems}
\end{fulllineitems}
\paragraph{MultiGauss2D}
\label{api/gammapy.morphology.MultiGauss2D:astropy}\label{api/gammapy.morphology.MultiGauss2D::doc}\label{api/gammapy.morphology.MultiGauss2D:multigauss2d}\index{MultiGauss2D (class in gammapy.morphology)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.MultiGauss2D:gammapy.morphology.MultiGauss2D}\pysiglinewithargsret{\strong{class }\code{gammapy.morphology.}\bfcode{MultiGauss2D}}{\emph{sigmas}, \emph{norms=None}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Sum of multiple 2D Gaussians.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{TODO}
\end{description}\end{quote}
\paragraph{Notes}
\begin{itemize}
\item {}
This sum is no longer a PDF, it is not normalized to 1.
\item {}
The ``norm'' of each component represents the 2D integral,
not the amplitude at the origin.
\end{itemize}
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.morphology.MultiGauss2D:gammapy.morphology.MultiGauss2D.amplitude]{\emph{\code{amplitude}}}}
&
\\
\hline
{\hyperref[api/gammapy.morphology.MultiGauss2D:gammapy.morphology.MultiGauss2D.eff_sigma]{\emph{\code{eff\_sigma}}}}
&
Effective sigma for single-Gauss approximation.
\\
\hline
{\hyperref[api/gammapy.morphology.MultiGauss2D:gammapy.morphology.MultiGauss2D.integral]{\emph{\code{integral}}}}
&
\\
\hline
{\hyperref[api/gammapy.morphology.MultiGauss2D:gammapy.morphology.MultiGauss2D.max_sigma]{\emph{\code{max\_sigma}}}}
&
\\
\hline
{\hyperref[api/gammapy.morphology.MultiGauss2D:gammapy.morphology.MultiGauss2D.n_components]{\emph{\code{n\_components}}}}
&
\\
\hline
{\hyperref[api/gammapy.morphology.MultiGauss2D:gammapy.morphology.MultiGauss2D.sigmas]{\emph{\code{sigmas}}}}
&
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{amplitude (gammapy.morphology.MultiGauss2D attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.MultiGauss2D:gammapy.morphology.MultiGauss2D.amplitude}\pysigline{\bfcode{amplitude}}
\end{fulllineitems}
\index{eff\_sigma (gammapy.morphology.MultiGauss2D attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.MultiGauss2D:gammapy.morphology.MultiGauss2D.eff_sigma}\pysigline{\bfcode{eff\_sigma}}
Effective sigma for single-Gauss approximation.
TODO: give formula.
\end{fulllineitems}
\index{integral (gammapy.morphology.MultiGauss2D attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.MultiGauss2D:gammapy.morphology.MultiGauss2D.integral}\pysigline{\bfcode{integral}}
\end{fulllineitems}
\index{max\_sigma (gammapy.morphology.MultiGauss2D attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.MultiGauss2D:gammapy.morphology.MultiGauss2D.max_sigma}\pysigline{\bfcode{max\_sigma}}
\end{fulllineitems}
\index{n\_components (gammapy.morphology.MultiGauss2D attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.MultiGauss2D:gammapy.morphology.MultiGauss2D.n_components}\pysigline{\bfcode{n\_components}}
\end{fulllineitems}
\index{sigmas (gammapy.morphology.MultiGauss2D attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.MultiGauss2D:gammapy.morphology.MultiGauss2D.sigmas}\pysigline{\bfcode{sigmas}}
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{\_\_call\_\_() (gammapy.morphology.MultiGauss2D method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.MultiGauss2D:gammapy.morphology.MultiGauss2D.__call__}\pysiglinewithargsret{\bfcode{\_\_call\_\_}}{\emph{x}, \emph{y=0}}{}
TODO
\end{fulllineitems}
\index{containment\_fraction() (gammapy.morphology.MultiGauss2D method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.MultiGauss2D:gammapy.morphology.MultiGauss2D.containment_fraction}\pysiglinewithargsret{\bfcode{containment\_fraction}}{\emph{theta}}{}
Containment fraction.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{theta} : array\_like
\begin{quote}
Containment angle
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{containment\_radius() (gammapy.morphology.MultiGauss2D method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.MultiGauss2D:gammapy.morphology.MultiGauss2D.containment_radius}\pysiglinewithargsret{\bfcode{containment\_radius}}{\emph{containment\_fraction}}{}
Containment angle.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{fraction} : float
\begin{quote}
Containment fraction
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{dpdtheta2() (gammapy.morphology.MultiGauss2D method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.MultiGauss2D:gammapy.morphology.MultiGauss2D.dpdtheta2}\pysiglinewithargsret{\bfcode{dpdtheta2}}{\emph{theta2}}{}
TODO: document
\end{fulllineitems}
\index{gauss\_convolve() (gammapy.morphology.MultiGauss2D method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.MultiGauss2D:gammapy.morphology.MultiGauss2D.gauss_convolve}\pysiglinewithargsret{\bfcode{gauss\_convolve}}{\emph{sigma}, \emph{norm=1}}{}
Convolve with another Gauss.
Compute new norms and sigmas of all the components such that
the new distribution represents the convolved old distribution
by a Gaussian of width sigma and then multiplied by norm.
This MultiGauss2D is unchanged, a new one is created and returned.
This is useful if you need to e.g. compute theta for one PSF
and many sigmas.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{sigma} : array\_like
\begin{quote}
TODO
\end{quote}
\textbf{norm} : TODO
\begin{quote}
TODO
\end{quote}
\item[{Returns}] \leavevmode
\textbf{new\_multi\_gauss\_2d} : MultiGauss2D
\begin{quote}
New MultiGauss2D
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{match\_sigma() (gammapy.morphology.MultiGauss2D method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.MultiGauss2D:gammapy.morphology.MultiGauss2D.match_sigma}\pysiglinewithargsret{\bfcode{match\_sigma}}{\emph{containment\_fraction}}{}
Compute equivalent Gauss width.
Find the sigma of a single-Gaussian distribution that
approximates this one, such that theta matches for a given
containment.
\end{fulllineitems}
\index{normalize() (gammapy.morphology.MultiGauss2D method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.MultiGauss2D:gammapy.morphology.MultiGauss2D.normalize}\pysiglinewithargsret{\bfcode{normalize}}{}{}
TODO: document
\end{fulllineitems}
\end{fulllineitems}
\paragraph{Shell2D}
\label{api/gammapy.morphology.Shell2D:astropy}\label{api/gammapy.morphology.Shell2D::doc}\label{api/gammapy.morphology.Shell2D:shell2d}\index{Shell2D (class in gammapy.morphology)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Shell2D:gammapy.morphology.Shell2D}\pysiglinewithargsret{\strong{class }\code{gammapy.morphology.}\bfcode{Shell2D}}{\emph{amplitude}, \emph{x\_0}, \emph{y\_0}, \emph{r\_in}, \emph{width=None}, \emph{r\_out=None}, \emph{normed=True}, \emph{**constraints}}{}
Bases: \href{http://docs.astropy.org/en/latest/api/astropy.modeling.Fittable2DModel.html\#astropy.modeling.Fittable2DModel}{\code{astropy.modeling.Fittable2DModel}}
Projected homogeneous radiating shell model.
This model can be used for a shell type SNR source morphology.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{amplitude} : float
\begin{quote}
Value of the integral of the shell function.
\end{quote}
\textbf{x\_0} : float
\begin{quote}
x position center of the shell
\end{quote}
\textbf{y\_0} : float
\begin{quote}
y position center of the shell
\end{quote}
\textbf{r\_in} : float
\begin{quote}
Inner radius of the shell
\end{quote}
\textbf{width} : float
\begin{quote}
Width of the shell
\end{quote}
\textbf{r\_out} : float (optional)
\begin{quote}
Outer radius of the shell
\end{quote}
\textbf{normed} : bool (True)
\begin{quote}
If set the amplitude parameter corresponds to the integral of the
function. If not set the `amplitude' parameter corresponds to the
peak value of the function (value at \(r = r_{in}\)).
\end{quote}
\end{description}\end{quote}
\strong{See also:}
{\hyperref[api/gammapy.morphology.Sphere2D:gammapy.morphology.Sphere2D]{\emph{\code{Sphere2D}}}}, {\hyperref[api/gammapy.morphology.Delta2D:gammapy.morphology.Delta2D]{\emph{\code{Delta2D}}}}, \code{astropy.modeling.models.Gaussian2D}
\paragraph{Notes}
Model formula with integral normalization:
\begin{gather}
\begin{split}f(r) = A \frac{3}{2 \pi (r_{out}^3 - r_{in}^3)} \cdot \left \{
\begin{array}{ll}
\sqrt{r_{out}^2 - r^2} - \sqrt{r_{in}^2 - r^2} & : r < r_{in} \\
\sqrt{r_{out}^2 - r^2} & : r_{in} \leq r \leq r_{out} \\
0 & : r > r_{out}
\end{array}
\right.\end{split}\notag
\end{gather}
Model formula with peak normalization:
\begin{gather}
\begin{split}f(r) = A \frac{1}{\sqrt{r_{out}^2 - r_{in}^2}} \cdot \left \{
\begin{array}{ll}
\sqrt{r_{out}^2 - r^2} - \sqrt{r_{in}^2 - r^2} & : r < r_{in} \\
\sqrt{r_{out}^2 - r^2} & : r_{in} \leq r \leq r_{out} \\
0 & : r > r_{out}
\end{array}
\right.\end{split}\notag
\end{gather}
With \(r_{out} = r_{in} + \mathrm{width}\).
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.morphology.Shell2D:gammapy.morphology.Shell2D.param_names]{\emph{\code{param\_names}}}}
&
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{amplitude (gammapy.morphology.Shell2D attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Shell2D:gammapy.morphology.Shell2D.amplitude}\pysigline{\bfcode{amplitude}}
\end{fulllineitems}
\index{param\_names (gammapy.morphology.Shell2D attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Shell2D:gammapy.morphology.Shell2D.param_names}\pysigline{\bfcode{param\_names}\strong{ = (`amplitude', `x\_0', `y\_0', `r\_in', `width')}}
\end{fulllineitems}
\index{r\_in (gammapy.morphology.Shell2D attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Shell2D:gammapy.morphology.Shell2D.r_in}\pysigline{\bfcode{r\_in}}
\end{fulllineitems}
\index{width (gammapy.morphology.Shell2D attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Shell2D:gammapy.morphology.Shell2D.width}\pysigline{\bfcode{width}}
\end{fulllineitems}
\index{x\_0 (gammapy.morphology.Shell2D attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Shell2D:gammapy.morphology.Shell2D.x_0}\pysigline{\bfcode{x\_0}}
\end{fulllineitems}
\index{y\_0 (gammapy.morphology.Shell2D attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Shell2D:gammapy.morphology.Shell2D.y_0}\pysigline{\bfcode{y\_0}}
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{evaluate() (gammapy.morphology.Shell2D static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Shell2D:gammapy.morphology.Shell2D.evaluate}\pysiglinewithargsret{\strong{static }\bfcode{evaluate}}{\emph{x}, \emph{y}, \emph{amplitude}, \emph{x\_0}, \emph{y\_0}, \emph{r\_in}, \emph{width}}{}
Two dimensional Shell model function normed to integral
\end{fulllineitems}
\index{evaluate\_peak\_norm() (gammapy.morphology.Shell2D static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Shell2D:gammapy.morphology.Shell2D.evaluate_peak_norm}\pysiglinewithargsret{\strong{static }\bfcode{evaluate\_peak\_norm}}{\emph{x}, \emph{y}, \emph{amplitude}, \emph{x\_0}, \emph{y\_0}, \emph{r\_in}, \emph{width}}{}
Two dimensional Shell model function normed to peak value
\end{fulllineitems}
\end{fulllineitems}
\paragraph{Sphere2D}
\label{api/gammapy.morphology.Sphere2D:sphere2d}\label{api/gammapy.morphology.Sphere2D:astropy}\label{api/gammapy.morphology.Sphere2D::doc}\index{Sphere2D (class in gammapy.morphology)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Sphere2D:gammapy.morphology.Sphere2D}\pysiglinewithargsret{\strong{class }\code{gammapy.morphology.}\bfcode{Sphere2D}}{\emph{amplitude}, \emph{x\_0}, \emph{y\_0}, \emph{r\_0}, \emph{normed=True}, \emph{**constraints}}{}
Bases: \href{http://docs.astropy.org/en/latest/api/astropy.modeling.Fittable2DModel.html\#astropy.modeling.Fittable2DModel}{\code{astropy.modeling.Fittable2DModel}}
Projected homogeneous radiating sphere model.
This model can be used for a simple PWN source morphology.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{amplitude} : float
\begin{quote}
Value of the integral of the sphere function
\end{quote}
\textbf{x\_0} : float
\begin{quote}
x position center of the sphere
\end{quote}
\textbf{y\_0} : float
\begin{quote}
y position center of the sphere
\end{quote}
\textbf{r\_0} : float
\begin{quote}
Radius of the sphere
\end{quote}
\textbf{normed} : bool (True)
\begin{quote}
If set the amplitude parameter corresponds to the integral of the
function. If not set the `amplitude' parameter corresponds to the
peak value of the function (value at \(r = 0\)).
\end{quote}
\end{description}\end{quote}
\strong{See also:}
{\hyperref[api/gammapy.morphology.Shell2D:gammapy.morphology.Shell2D]{\emph{\code{Shell2D}}}}, {\hyperref[api/gammapy.morphology.Delta2D:gammapy.morphology.Delta2D]{\emph{\code{Delta2D}}}}, \code{astropy.modeling.models.Gaussian2D}
\paragraph{Notes}
Model formula with integral normalization:
\begin{gather}
\begin{split}f(r) = A \frac{3}{4 \pi r_0^3} \cdot \left \{
\begin{array}{ll}
\sqrt{r_0^2 - r^2} & : r \leq r_0 \\
0 & : r > r_0
\end{array}
\right.\end{split}\notag
\end{gather}
Model formula with peak normalization:
\begin{gather}
\begin{split}f(r) = A \frac{1}{r_0} \cdot \left \{
\begin{array}{ll}
\sqrt{r_0^2 - r^2} & : r \leq r_0 \\
0 & : r > r_0
\end{array}
\right.\end{split}\notag
\end{gather}\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.morphology.Sphere2D:gammapy.morphology.Sphere2D.param_names]{\emph{\code{param\_names}}}}
&
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{amplitude (gammapy.morphology.Sphere2D attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Sphere2D:gammapy.morphology.Sphere2D.amplitude}\pysigline{\bfcode{amplitude}}
\end{fulllineitems}
\index{param\_names (gammapy.morphology.Sphere2D attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Sphere2D:gammapy.morphology.Sphere2D.param_names}\pysigline{\bfcode{param\_names}\strong{ = (`amplitude', `x\_0', `y\_0', `r\_0')}}
\end{fulllineitems}
\index{r\_0 (gammapy.morphology.Sphere2D attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Sphere2D:gammapy.morphology.Sphere2D.r_0}\pysigline{\bfcode{r\_0}}
\end{fulllineitems}
\index{x\_0 (gammapy.morphology.Sphere2D attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Sphere2D:gammapy.morphology.Sphere2D.x_0}\pysigline{\bfcode{x\_0}}
\end{fulllineitems}
\index{y\_0 (gammapy.morphology.Sphere2D attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Sphere2D:gammapy.morphology.Sphere2D.y_0}\pysigline{\bfcode{y\_0}}
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{evaluate() (gammapy.morphology.Sphere2D static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Sphere2D:gammapy.morphology.Sphere2D.evaluate}\pysiglinewithargsret{\strong{static }\bfcode{evaluate}}{\emph{x}, \emph{y}, \emph{amplitude}, \emph{x\_0}, \emph{y\_0}, \emph{r\_0}}{}
Two dimensional Sphere model function normed to integral
\end{fulllineitems}
\index{evaluate\_peak\_norm() (gammapy.morphology.Sphere2D static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.Sphere2D:gammapy.morphology.Sphere2D.evaluate_peak_norm}\pysiglinewithargsret{\strong{static }\bfcode{evaluate\_peak\_norm}}{\emph{x}, \emph{y}, \emph{amplitude}, \emph{x\_0}, \emph{y\_0}, \emph{r\_0}}{}
Two dimensional Sphere model function normed to peak value
\end{fulllineitems}
\end{fulllineitems}
\paragraph{ThetaCalculator}
\label{api/gammapy.morphology.ThetaCalculator:astropy}\label{api/gammapy.morphology.ThetaCalculator::doc}\label{api/gammapy.morphology.ThetaCalculator:thetacalculator}\index{ThetaCalculator (class in gammapy.morphology)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.ThetaCalculator:gammapy.morphology.ThetaCalculator}\pysiglinewithargsret{\strong{class }\code{gammapy.morphology.}\bfcode{ThetaCalculator}}{\emph{dist}, \emph{theta\_max}, \emph{n\_bins}, \emph{normalize=False}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Provides methods \code{containment\_fraction(theta)} and \code{containment\_radius(containment\_fraction)}
given some 1D distribution (not necessarily normalized).
Notes
If you have to compute theta or containment many times for
the same dist, this is much faster than ThetaCalculatorScipy.
If you want only one value it could actually be slower,
especially the containment calculation.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{dist} : callable
\begin{quote}
Distribution function dp / dtheta2 (theta2)
\end{quote}
\textbf{theta\_max} : float
\begin{quote}
Integration range will be 0 .. theta\_max \textasciicircum{} 2
\end{quote}
\textbf{nbins} : int
\begin{quote}
Integration step size
\end{quote}
\textbf{normalize} : bool
\begin{quote}
Normalize discretized distribution to 1?
\end{quote}
\end{description}\end{quote}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{containment\_fraction() (gammapy.morphology.ThetaCalculator method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.ThetaCalculator:gammapy.morphology.ThetaCalculator.containment_fraction}\pysiglinewithargsret{\bfcode{containment\_fraction}}{\emph{theta}}{}
Compute containment fraction for a given theta.
\end{fulllineitems}
\index{containment\_radius() (gammapy.morphology.ThetaCalculator method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.ThetaCalculator:gammapy.morphology.ThetaCalculator.containment_radius}\pysiglinewithargsret{\bfcode{containment\_radius}}{\emph{containment\_fraction}}{}
Compute theta for a given containment fraction.
\end{fulllineitems}
\end{fulllineitems}
\paragraph{ThetaCalculator2D}
\label{api/gammapy.morphology.ThetaCalculator2D:thetacalculator2d}\label{api/gammapy.morphology.ThetaCalculator2D:astropy}\label{api/gammapy.morphology.ThetaCalculator2D::doc}\index{ThetaCalculator2D (class in gammapy.morphology)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.ThetaCalculator2D:gammapy.morphology.ThetaCalculator2D}\pysiglinewithargsret{\strong{class }\code{gammapy.morphology.}\bfcode{ThetaCalculator2D}}{\emph{dist}, \emph{x}, \emph{y}}{}
Bases: {\hyperref[api/gammapy.morphology.ThetaCalculatorScipy:gammapy.morphology.ThetaCalculatorScipy]{\emph{\code{gammapy.morphology.ThetaCalculatorScipy}}}}
Methods to compute theta and containment
for a given 2D probability distribution image.
Typically this method is used for PSF-convolved
model images, where analytical distributions or
1D distributions are not available.
@note: The theta and containment is calculated relative
to the origin (x, y) = (0, 0).
@note: We do simple bin summing. In principle we could
do integration over bins by using scipy.integrate.dblquad
in combination with e.g. scipy.interpolate.interp2d,
but for the speed / precision we need this is overkill.
@todo: I just realized that probably the best thing to
do is to bin (x,y) -\textgreater{} theta2, make a spline interpolation
and then call ThetaCalculatorScipy!
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{dist} : 2-dimensional array
\begin{quote}
Probability distribution (per dx * dy)
\end{quote}
\textbf{x} : 2-dimensional array
\begin{quote}
Pixel \code{x} coordinate array. Must match shape of \code{dist}.
\end{quote}
\textbf{x} : 2-dimensional array
\begin{quote}
Pixel \code{x} coordinate array. Must match share of \code{dist}.
\end{quote}
\end{description}\end{quote}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{containment\_fraction() (gammapy.morphology.ThetaCalculator2D method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.ThetaCalculator2D:gammapy.morphology.ThetaCalculator2D.containment_fraction}\pysiglinewithargsret{\bfcode{containment\_fraction}}{\emph{theta}}{}
\end{fulllineitems}
\end{fulllineitems}
\paragraph{ThetaCalculatorScipy}
\label{api/gammapy.morphology.ThetaCalculatorScipy:astropy}\label{api/gammapy.morphology.ThetaCalculatorScipy::doc}\label{api/gammapy.morphology.ThetaCalculatorScipy:thetacalculatorscipy}\index{ThetaCalculatorScipy (class in gammapy.morphology)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.ThetaCalculatorScipy:gammapy.morphology.ThetaCalculatorScipy}\pysiglinewithargsret{\strong{class }\code{gammapy.morphology.}\bfcode{ThetaCalculatorScipy}}{\emph{dist}, \emph{theta\_max}, \emph{normalize=False}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Same functionality as NumericalThetaCalculator, but uses
\code{scipy.integrate.quad} and \code{scipy.optimize.fsolve} instead.
Notes:
It is more precise than ThetaCalculator and doesn't
require you to think about which theta binning and range
gives your desired precision.
If you have to compute many thetas this can be quite slow
because it is a root finding with nested integration.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{dist} : callable
\begin{quote}
Probability distribution (probability per theta \textasciicircum{} 2)
\end{quote}
\textbf{theta\_max} : float
\begin{quote}
Integration range will be 0 .. theta\_max \textasciicircum{} 2
\end{quote}
\textbf{normalize} : bool
\begin{quote}
Normalize discretized distribution to 1?
\end{quote}
\end{description}\end{quote}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{containment\_fraction() (gammapy.morphology.ThetaCalculatorScipy method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.ThetaCalculatorScipy:gammapy.morphology.ThetaCalculatorScipy.containment_fraction}\pysiglinewithargsret{\bfcode{containment\_fraction}}{\emph{theta}}{}
\end{fulllineitems}
\index{containment\_radius() (gammapy.morphology.ThetaCalculatorScipy method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.morphology.ThetaCalculatorScipy:gammapy.morphology.ThetaCalculatorScipy.containment_radius}\pysiglinewithargsret{\bfcode{containment\_radius}}{\emph{containment\_fraction}}{}
Compute containment angle using the containment\_fraction
method plus numerical root finding.
\end{fulllineitems}
\end{fulllineitems}
\chapter{Observation handling (\texttt{gammapy.obs})}
\label{obs/index:obs}\label{obs/index:astropy}\label{obs/index::doc}\label{obs/index:observation-handling-gammapy-obs}
\section{Introduction}
\label{obs/index:introduction}
{\hyperref[obs/index:module-gammapy.obs]{\emph{\code{gammapy.obs}}}} contains methods to handle observations.
In TeV astronomy an observation (a.k.a. a run) means pointing the telescopes at some
position on the sky (fixed in celestial coordinates, not in horizon coordinates)
for a given amount of time (e.g. half an hour) and switching the central trigger on.
The total dataset for a given target will usually consist of a few to a few 100 runs
and some book-keeping is required when running the analysis.
\section{Getting Started}
\label{obs/index:getting-started}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k+kn}{from} \PYG{n+nn}{gammapy.obs} \PYG{k+kn}{import} \PYG{n}{observatory\PYGZus{}locations}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{observatory\PYGZus{}locations}\PYG{o}{.}\PYG{n}{HESS}
\PYG{g+go}{\PYGZlt{}EarthLocation (7237.152530011689, 2143.7727767623487, \PYGZhy{}3229.3927009565496) km\PYGZgt{}}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k}{print}\PYG{p}{(}\PYG{n}{observatory\PYGZus{}locations}\PYG{o}{.}\PYG{n}{HESS}\PYG{o}{.}\PYG{n}{geodetic}\PYG{p}{)}
\PYG{g+go}{(\PYGZlt{}Longitude 16.500222222222224 deg\PYGZgt{}, \PYGZlt{}Latitude \PYGZhy{}23.271777777772456 deg\PYGZgt{}, \PYGZlt{}Quantity 1835.0 km\PYGZgt{})}
\end{Verbatim}
\section{Using \texttt{gammapy.obs}}
\label{obs/index:using-gammapy-obs}
\subsection{findruns}
\label{obs/findruns:obs-findruns}\label{obs/findruns::doc}\label{obs/findruns:findruns}
TODO: reference run list format
The \code{gammapy-findruns} command line tool can be used to select a subset of runs from a given run list.
Examples:
\begin{itemize}
\item {}
Find all runs within 5 deg of the Galactic center:
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }gammapy\PYGZhy{}findruns cone \PYGZhy{}\PYGZhy{}x \PYG{l+m}{0} \PYGZhy{}\PYGZhy{}y \PYG{l+m}{0} \PYGZhy{}\PYGZhy{}r \PYG{l+m}{5} \PYGZhy{}\PYGZhy{}system galactic \PYG{l+s+se}{\PYGZbs{}}
\PYGZhy{}\PYGZhy{}in all\PYGZus{}runs.lis \PYGZhy{}\PYGZhy{}out galactic\PYGZus{}center\PYGZus{}runs.lis
\end{Verbatim}
\item {}
Select all runs in a box along the Galactic plane (GLON = -20 .. +20 deg, GLAT = -3 .. +3 deg):
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }gammapy\PYGZhy{}findruns box \PYGZhy{}\PYGZhy{}x \PYG{l+m}{0} \PYGZhy{}\PYGZhy{}y \PYG{l+m}{0} \PYGZhy{}\PYGZhy{}dx \PYG{l+m}{20} \PYGZhy{}\PYGZhy{}dy \PYG{l+m}{3} \PYGZhy{}\PYGZhy{}system galactic \PYG{l+s+se}{\PYGZbs{}}
\PYGZhy{}\PYGZhy{}in all\PYGZus{}runs.lis \PYGZhy{}\PYGZhy{}out galactic\PYGZus{}plane\PYGZus{}runs.lis
\end{Verbatim}
\item {}
Select all runs in a given date range (can of course be combined with other selections shown above):
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }gammapy\PYGZhy{}findruns \PYGZhy{}\PYGZhy{}date\PYGZus{}min 2010\PYGZhy{}04\PYGZhy{}26 \PYGZhy{}\PYGZhy{}date\PYGZus{}max \PYG{l+s+s2}{\PYGZdq{}2010\PYGZhy{}04\PYGZhy{}29 12:42\PYGZdq{}} \PYG{l+s+se}{\PYGZbs{}}
\PYGZhy{}\PYGZhy{}in all\PYGZus{}runs.lis \PYGZhy{}\PYGZhy{}out run\PYGZus{}042\PYGZus{}to\PYGZus{}100.lis
\end{Verbatim}
\item {}
Select all runs in a given run range (can of course be combined with other selections shown above):
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }gammapy\PYGZhy{}findruns \PYGZhy{}\PYGZhy{}run\PYGZus{}min \PYG{l+m}{42} \PYGZhy{}\PYGZhy{}run\PYGZus{}max \PYG{l+m}{100} \PYG{l+s+se}{\PYGZbs{}}
\PYGZhy{}\PYGZhy{}in all\PYGZus{}runs.lis \PYGZhy{}\PYGZhy{}out run\PYGZus{}042\PYGZus{}to\PYGZus{}100.lis
\end{Verbatim}
\end{itemize}
Using \code{gammapy-findruns} is easy, you don't have to remember all the options, just type:
\begin{quote}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n+nv}{\PYGZdl{} }findruns \PYGZhy{}\PYGZhy{}help
\end{Verbatim}
\end{quote}
at the command line or read the usage help (TODO: add link here).
\begin{notice}{note}{Note:}
Noel Dawe's \code{goodruns} tool for \href{http://atlas.ch}{ATLAS} run selection
(\href{http://ndawe.github.io/goodruns/}{docs}, \href{https://github.com/ndawe/goodruns}{code})
is a nice example for a run selection tool.
\end{notice}
\section{Reference/API}
\label{obs/index:reference-api}\label{obs/index:astropy}
\subsection{gammapy.obs Package}
\label{obs/index:module-gammapy.obs}\label{obs/index:gammapy-obs-package}\index{gammapy.obs (module)}
Observation utility functions and classes
\subsubsection{Classes}
\label{obs/index:classes}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.obs.DataStore:gammapy.obs.DataStore]{\emph{\code{DataStore}}}}(dir{[}, scheme{]})
&
Data store - convenient way to access and select data.
\\
\hline
{\hyperref[api/gammapy.obs.DataStoreIndexTable:gammapy.obs.DataStoreIndexTable]{\emph{\code{DataStoreIndexTable}}}}({[}data, masked, names, ...{]})
&
Data store index table.
\\
\hline
{\hyperref[api/gammapy.obs.ObservationTable:gammapy.obs.ObservationTable]{\emph{\code{ObservationTable}}}}({[}data, masked, names, ...{]})
&
Observation table (a.k.a.
\\
\hline\end{longtable}
\paragraph{DataStore}
\label{api/gammapy.obs.DataStore::doc}\label{api/gammapy.obs.DataStore:datastore}\index{DataStore (class in gammapy.obs)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.obs.DataStore:gammapy.obs.DataStore}\pysiglinewithargsret{\strong{class }\code{gammapy.obs.}\bfcode{DataStore}}{\emph{dir}, \emph{scheme='hess'}}{}
Bases: \href{http://docs.python.org/3/library/functions.html\#object}{\code{object}}
Data store - convenient way to access and select data.
This is an ad-hoc prototype implementation for HESS of what will be the ``archive''
and ``archive interface'' for CTA.
TODO: add methods to sync with remote datastore...
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{dir} : \href{http://docs.python.org/library/functions.html\#str}{\code{str}}
\begin{quote}
Data store directory on user machine
\end{quote}
\textbf{scheme} : \{`hess'\}
\begin{quote}
Scheme of organising and naming the files.
\end{quote}
\end{description}\end{quote}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{check\_available\_event\_lists() (gammapy.obs.DataStore method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.obs.DataStore:gammapy.obs.DataStore.check_available_event_lists}\pysiglinewithargsret{\bfcode{check\_available\_event\_lists}}{\emph{logger=None}}{}
Check if all event lists are available.
TODO: extend this function, or combine e.g. with \code{make\_table\_of\_files}.
\begin{quote}\begin{description}
\item[{Returns}] \leavevmode
\textbf{file\_available} : \href{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html\#numpy.ndarray}{\code{ndarray}}
\begin{quote}
Boolean mask which files are available.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{check\_integrity() (gammapy.obs.DataStore method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.obs.DataStore:gammapy.obs.DataStore.check_integrity}\pysiglinewithargsret{\bfcode{check\_integrity}}{\emph{logger}}{}
Check integrity, i.e. whether index table and files match.
\end{fulllineitems}
\index{filename() (gammapy.obs.DataStore method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.obs.DataStore:gammapy.obs.DataStore.filename}\pysiglinewithargsret{\bfcode{filename}}{\emph{obs\_id}, \emph{filetype='events'}, \emph{abspath=True}}{}
File name (relative to datastore \href{http://docs.python.org/library/functions.html\#dir}{\code{dir}}).
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{obs\_id} : int
\begin{quote}
Observation ID
\end{quote}
\textbf{filetype} : \{`events', `effective area', `psf', `background'\}
\begin{quote}
Type of file
\end{quote}
\textbf{abspath} : bool
\begin{quote}
Absolute path (including data store dir)?
\end{quote}
\item[{Returns}] \leavevmode
\textbf{filename} : str
\begin{quote}
Filename (including the directory path).
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\index{info() (gammapy.obs.DataStore method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.obs.DataStore:gammapy.obs.DataStore.info}\pysiglinewithargsret{\bfcode{info}}{}{}
Summary info string.
\end{fulllineitems}
\index{make\_observation\_table() (gammapy.obs.DataStore method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.obs.DataStore:gammapy.obs.DataStore.make_observation_table}\pysiglinewithargsret{\bfcode{make\_observation\_table}}{\emph{selection=None}}{}
Make an observation table, applying some selection.
TODO: implement a more flexible scheme to make box cuts
on any fields (including e.g. OBSID or TIME
Not sure what a simple yet powerful method to implement this is!?
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{selection} : TODO
\begin{quote}
TODO: describe me
\end{quote}
\item[{Returns}] \leavevmode
\textbf{table} : {\hyperref[api/gammapy.obs.ObservationTable:gammapy.obs.ObservationTable]{\emph{\code{ObservationTable}}}}
\begin{quote}
Observation table
\end{quote}
\end{description}\end{quote}
\paragraph{Examples}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{selection} \PYG{o}{=} \PYG{n+nb}{dict}\PYG{p}{(}\PYG{n}{shape}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{box}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,} \PYG{n}{frame}\PYG{o}{=}\PYG{l+s}{\PYGZsq{}}\PYG{l+s}{galactic}\PYG{l+s}{\PYGZsq{}}\PYG{p}{,}
\PYG{g+gp}{... } \PYG{n}{lon}\PYG{o}{=}\PYG{p}{(}\PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{100}\PYG{p}{,} \PYG{l+m+mi}{50}\PYG{p}{)}\PYG{p}{,} \PYG{n}{lat}\PYG{o}{=}\PYG{p}{(}\PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{5}\PYG{p}{,} \PYG{l+m+mi}{5}\PYG{p}{)}\PYG{p}{,} \PYG{n}{border}\PYG{o}{=}\PYG{l+m+mi}{2}\PYG{p}{)}
\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{n}{run\PYGZus{}list} \PYG{o}{=} \PYG{n}{data\PYGZus{}store}\PYG{o}{.}\PYG{n}{make\PYGZus{}observation\PYGZus{}table}\PYG{p}{(}\PYG{n}{selection}\PYG{p}{)}
\end{Verbatim}
\end{fulllineitems}
\index{make\_summary\_plots() (gammapy.obs.DataStore method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.obs.DataStore:gammapy.obs.DataStore.make_summary_plots}\pysiglinewithargsret{\bfcode{make\_summary\_plots}}{}{}
Make some plots summarising the available observations.
E.g. histograms of time, run duration, muon efficiency, zenith angle, ...
Aitoff plot showing run locations.
\end{fulllineitems}
\index{make\_table\_of\_files() (gammapy.obs.DataStore method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.obs.DataStore:gammapy.obs.DataStore.make_table_of_files}\pysiglinewithargsret{\bfcode{make\_table\_of\_files}}{\emph{observation\_table=None, filetypes={[}'events'{]}}}{}
Make list of files in the datastore directory.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{observation\_table} : {\hyperref[api/gammapy.obs.ObservationTable:gammapy.obs.ObservationTable]{\emph{\code{ObservationTable}}}} or None
\begin{quote}
Observation table (\code{None} means select all observations)
\end{quote}
\textbf{filetypes} : list of str
\begin{quote}
File types (TODO: document in a central location and reference from here)
\end{quote}
\item[{Returns}] \leavevmode
\textbf{table} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Table summarising info about files.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\end{fulllineitems}
\paragraph{DataStoreIndexTable}
\label{api/gammapy.obs.DataStoreIndexTable:astropy}\label{api/gammapy.obs.DataStoreIndexTable::doc}\label{api/gammapy.obs.DataStoreIndexTable:datastoreindextable}\index{DataStoreIndexTable (class in gammapy.obs)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.obs.DataStoreIndexTable:gammapy.obs.DataStoreIndexTable}\pysiglinewithargsret{\strong{class }\code{gammapy.obs.}\bfcode{DataStoreIndexTable}}{\emph{data=None}, \emph{masked=None}, \emph{names=None}, \emph{dtype=None}, \emph{meta=None}, \emph{copy=True}, \emph{rows=None}}{}
Bases: \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{astropy.table.Table}}
Data store index table.
The index table is a FITS file that stores which observations
are available and what their most important parameters are.
This makes it possible to select observation of interest and find out
what data is available without opening up thousands of FITS files
that contain the event list and IRFs and have similar information in the
FITS header.
TODO: how is this different from an {\hyperref[api/gammapy.obs.ObservationTable:gammapy.obs.ObservationTable]{\emph{\code{gammapy.obs.ObservationTable}}}}?
Can they be combined or code be shared?
(I think we want both, but the {\hyperref[api/gammapy.obs.DataStoreIndexTable:gammapy.obs.DataStoreIndexTable]{\emph{\code{DataStoreIndexTable}}}} contains more info
like event list and IRF file names and basic info
... maybe it should be a sub-class of {\hyperref[api/gammapy.obs.ObservationTable:gammapy.obs.ObservationTable]{\emph{\code{gammapy.obs.ObservationTable}}}}?)
\paragraph{Attributes Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.obs.DataStoreIndexTable:gammapy.obs.DataStoreIndexTable.galactic]{\emph{\code{galactic}}}}
&
Galactic sky coordinates (\href{http://docs.astropy.org/en/latest/api/astropy.coordinates.SkyCoord.html\#astropy.coordinates.SkyCoord}{\code{SkyCoord}})
\\
\hline
{\hyperref[api/gammapy.obs.DataStoreIndexTable:gammapy.obs.DataStoreIndexTable.radec]{\emph{\code{radec}}}}
&
ICRS sky coordinates (\href{http://docs.astropy.org/en/latest/api/astropy.coordinates.SkyCoord.html\#astropy.coordinates.SkyCoord}{\code{SkyCoord}})
\\
\hline\end{longtable}
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Attributes Documentation}
\index{galactic (gammapy.obs.DataStoreIndexTable attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.obs.DataStoreIndexTable:gammapy.obs.DataStoreIndexTable.galactic}\pysigline{\bfcode{galactic}}
Galactic sky coordinates (\href{http://docs.astropy.org/en/latest/api/astropy.coordinates.SkyCoord.html\#astropy.coordinates.SkyCoord}{\code{SkyCoord}})
\end{fulllineitems}
\index{radec (gammapy.obs.DataStoreIndexTable attribute)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.obs.DataStoreIndexTable:gammapy.obs.DataStoreIndexTable.radec}\pysigline{\bfcode{radec}}
ICRS sky coordinates (\href{http://docs.astropy.org/en/latest/api/astropy.coordinates.SkyCoord.html\#astropy.coordinates.SkyCoord}{\code{SkyCoord}})
\end{fulllineitems}
\paragraph{Methods Documentation}
\index{info() (gammapy.obs.DataStoreIndexTable method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.obs.DataStoreIndexTable:gammapy.obs.DataStoreIndexTable.info}\pysiglinewithargsret{\bfcode{info}}{}{}
\end{fulllineitems}
\index{read() (gammapy.obs.DataStoreIndexTable static method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.obs.DataStoreIndexTable:gammapy.obs.DataStoreIndexTable.read}\pysiglinewithargsret{\strong{static }\bfcode{read}}{\emph{*args}, \emph{**kwargs}}{}
Read from FITS file. See \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table.read}{\code{read}}.
\end{fulllineitems}
\end{fulllineitems}
\paragraph{ObservationTable}
\label{api/gammapy.obs.ObservationTable:astropy}\label{api/gammapy.obs.ObservationTable::doc}\label{api/gammapy.obs.ObservationTable:observationtable}\index{ObservationTable (class in gammapy.obs)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.obs.ObservationTable:gammapy.obs.ObservationTable}\pysiglinewithargsret{\strong{class }\code{gammapy.obs.}\bfcode{ObservationTable}}{\emph{data=None}, \emph{masked=None}, \emph{names=None}, \emph{dtype=None}, \emph{meta=None}, \emph{copy=True}, \emph{rows=None}}{}
Bases: \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{astropy.table.Table}}
Observation table (a.k.a. run list).
This is an \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}} sub-class, with a few
convenience methods. The format of the observation table
is described in {\hyperref[dataformats/observation_lists:dataformats-observation-lists]{\emph{\DUspan{}{Observation lists}}}}.
\paragraph{Methods Summary}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
\end{longtable}
\paragraph{Methods Documentation}
\index{info() (gammapy.obs.ObservationTable method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.obs.ObservationTable:gammapy.obs.ObservationTable.info}\pysiglinewithargsret{\bfcode{info}}{}{}
\end{fulllineitems}
\index{select\_linspace\_subset() (gammapy.obs.ObservationTable method)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.obs.ObservationTable:gammapy.obs.ObservationTable.select_linspace_subset}\pysiglinewithargsret{\bfcode{select\_linspace\_subset}}{\emph{num}}{}
Select subset of observations.
This is mostly useful for testing, if you want to make
the analysis run faster.
TODO: implement more methods to subset and split observation lists
as well as functions to summarise differences between
observation lists and e.g. select the common subset.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{num} : int
\begin{quote}
Number of samples to select.
\end{quote}
\item[{Returns}] \leavevmode
\textbf{table} : {\hyperref[api/gammapy.obs.ObservationTable:gammapy.obs.ObservationTable]{\emph{\code{ObservationTable}}}}
\begin{quote}
Subset observation table (a copy).
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\end{fulllineitems}
\chapter{Spectrum estimation and modeling (\texttt{gammapy.spectrum})}
\label{spectrum/index:spectrum-estimation-and-modeling-gammapy-spectrum}\label{spectrum/index:astropy}\label{spectrum/index::doc}\label{spectrum/index:spectrum}
\section{Introduction}
\label{spectrum/index:introduction}
{\hyperref[spectrum/index:module-gammapy.spectrum]{\emph{\code{gammapy.spectrum}}}} holds functions and classes to fit spectral models and compute flux points.
Physical radiative models (synchrotron, inverse Compton and pion-decay emission)
for arbitrary cosmic ray particle spectra are available in the \href{http://naima.readthedocs.org/en/latest/}{naima} package.
Explain spectrum estimation basics.
Define vocabulary.
A good reference for the forward-folding on-off likelihood fitting methods is Section 7.5 ``Spectra and Light Curves'' in \phantomsection\label{spectrum/index:id1}{\hyperref[references:naurois2012]{\emph{{[}Naurois2012{]}}}},
in publications usually the reference \phantomsection\label{spectrum/index:id2}{\hyperref[references:piron2001]{\emph{{[}Piron2001{]}}}} is used.
A standard reference for the unfolding method is \phantomsection\label{spectrum/index:id3}{\hyperref[references:albert2007]{\emph{{[}Albert2007{]}}}}.
\section{Getting Started}
\label{spectrum/index:getting-started}
TODO
Hello World
\section{Reference/API}
\label{spectrum/index:reference-api}
\subsection{gammapy.spectrum Package}
\label{spectrum/index:gammapy-spectrum-package}\label{spectrum/index:module-gammapy.spectrum}\index{gammapy.spectrum (module)}
Spectrum estimation and modeling methods.
\subsubsection{Functions}
\label{spectrum/index:functions}
\begin{longtable}{ll}
\hline
\endfirsthead
\multicolumn{2}{c}%
{{\textsf{\tablename\ \thetable{} -- continued from previous page}}} \\
\hline
\endhead
\hline \multicolumn{2}{|r|}{{\textsf{Continued on next page}}} \\ \hline
\endfoot
\endlastfoot
{\hyperref[api/gammapy.spectrum.add_spec:gammapy.spectrum.add_spec]{\emph{\code{add\_spec}}}}(frame, model, xlim{[}, npoints{]})
&
Add a spectral component to a frame.
\\
\hline
{\hyperref[api/gammapy.spectrum.compute_differential_flux_points:gammapy.spectrum.compute_differential_flux_points]{\emph{\code{compute\_differential\_flux\_points}}}}({[}x\_method, ...{]})
&
Creates differential flux points table from integral flux points table.
\\
\hline
{\hyperref[api/gammapy.spectrum.cosmic_ray_flux:gammapy.spectrum.cosmic_ray_flux]{\emph{\code{cosmic\_ray\_flux}}}}(energy{[}, particle{]})
&
Cosmic ray flux at Earth.
\\
\hline
{\hyperref[api/gammapy.spectrum.crab_flux:gammapy.spectrum.crab_flux]{\emph{\code{crab\_flux}}}}({[}energy, reference{]})
&
Differential Crab flux.
\\
\hline
{\hyperref[api/gammapy.spectrum.crab_integral_flux:gammapy.spectrum.crab_integral_flux]{\emph{\code{crab\_integral\_flux}}}}({[}energy\_min, energy\_max, ...{]})
&
Integral Crab flux.
\\
\hline
{\hyperref[api/gammapy.spectrum.crab_spectral_index:gammapy.spectrum.crab_spectral_index]{\emph{\code{crab\_spectral\_index}}}}({[}energy, reference{]})
&
Spectral index (positive number) at a given energy.
\\
\hline
{\hyperref[api/gammapy.spectrum.cube_sed:gammapy.spectrum.cube_sed]{\emph{\code{cube\_sed}}}}(cube{[}, mask, flux\_type, counts, ...{]})
&
Creates SED from SpectralCube within given lat and lon range.
\\
\hline
{\hyperref[api/gammapy.spectrum.diffuse_gamma_ray_flux:gammapy.spectrum.diffuse_gamma_ray_flux]{\emph{\code{diffuse\_gamma\_ray\_flux}}}}(energy{[}, component{]})
&
Diffuse gamma ray flux.
\\
\hline
{\hyperref[api/gammapy.spectrum.energy_bin_centers_log_spacing:gammapy.spectrum.energy_bin_centers_log_spacing]{\emph{\code{energy\_bin\_centers\_log\_spacing}}}}(energy\_bounds)
&
Compute energy log bin centers.
\\
\hline
{\hyperref[api/gammapy.spectrum.energy_bounds_equal_log_spacing:gammapy.spectrum.energy_bounds_equal_log_spacing]{\emph{\code{energy\_bounds\_equal\_log\_spacing}}}}(energy\_band)
&
Make energy bounds array with equal-log spacing.
\\
\hline
{\hyperref[api/gammapy.spectrum.np_to_pha:gammapy.spectrum.np_to_pha]{\emph{\code{np\_to\_pha}}}}(channel, counts, exposure, dstart, ...)
&
Create PHA FITS table extension from numpy arrays.
\\
\hline\end{longtable}
\paragraph{add\_spec}
\label{api/gammapy.spectrum.add_spec::doc}\label{api/gammapy.spectrum.add_spec:add-spec}\index{add\_spec() (in module gammapy.spectrum)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.spectrum.add_spec:gammapy.spectrum.add_spec}\pysiglinewithargsret{\code{gammapy.spectrum.}\bfcode{add\_spec}}{\emph{frame}, \emph{model}, \emph{xlim}, \emph{npoints=100}, \emph{**plot\_params}}{}
Add a spectral component to a frame.
frame = matplotlib.Axes object
model = {[}function, parameters, constants{]}
xlim = {[}xmin, xmax{]}
\end{fulllineitems}
\paragraph{compute\_differential\_flux\_points}
\label{api/gammapy.spectrum.compute_differential_flux_points:astropy}\label{api/gammapy.spectrum.compute_differential_flux_points::doc}\label{api/gammapy.spectrum.compute_differential_flux_points:compute-differential-flux-points}\index{compute\_differential\_flux\_points() (in module gammapy.spectrum)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.spectrum.compute_differential_flux_points:gammapy.spectrum.compute_differential_flux_points}\pysiglinewithargsret{\code{gammapy.spectrum.}\bfcode{compute\_differential\_flux\_points}}{\emph{x\_method='lafferty'}, \emph{y\_method='power\_law'}, \emph{table=None}, \emph{model=None}, \emph{spectral\_index=None}, \emph{energy\_min=None}, \emph{energy\_max=None}, \emph{int\_flux=None}, \emph{int\_flux\_err=None}}{}
Creates differential flux points table from integral flux points table.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{table} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Integral flux data table in energy bins, including columns
`ENERGY\_MIN', `ENERGY\_MAX', `INT\_FLUX', `INT\_FLUX\_ERR'
\end{quote}
\textbf{energy\_min} : float, array\_like
\begin{quote}
If table not defined, minimum energy of bin(s) may be input
directly as either a float or array.
\end{quote}
\textbf{energy\_max} : float, array\_like
\begin{quote}
If table not defined, maximum energy of bin(s) input directly.
\end{quote}
\textbf{int\_flux} : float, array\_like
\begin{quote}
If table not defined, integral flux in bin(s) input directly. If array,
energy\_min, energy\_max must be either arrays of the same shape
(for differing energy bins) or floats (for the same energy bin).
\end{quote}
\textbf{int\_flux\_err} : float, array\_like
\begin{quote}
Type must be the same as for int\_flux
\end{quote}
\textbf{x\_method} : \{`lafferty', `log\_center', `table'\}
\begin{quote}
Flux point energy computation method; either Lafferty \& Wyatt
model-based positioning, log bin center positioning
or user-defined \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}} positioning
using column heading {[}'ENERGY'{]}
\end{quote}
\textbf{y\_method} : \{`power\_law', `model'\}
\begin{quote}
Flux computation method assuming PowerLaw or user defined model function
\end{quote}
\textbf{model} : callable
\begin{quote}
User-defined model function
\end{quote}
\textbf{spectral\_index} : float, array\_like
\begin{quote}
Spectral index if default power law model is used. Either a float
or array\_like (in which case, energy\_min, energy\_max and int\_flux
must be floats to avoid ambiguity)
\end{quote}
\item[{Returns}] \leavevmode
\textbf{differential\_flux\_table} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
Input table with appended columns `ENERGY', `DIFF\_FLUX', `DIFF\_FLUX\_ERR'
\end{quote}
\end{description}\end{quote}
\paragraph{Notes}
For usage, see this tutorial: {\hyperref[tutorials/flux_point/index:tutorials-flux-point]{\emph{\DUspan{}{Where to stick your Spectral Points?}}}}.
\end{fulllineitems}
\paragraph{cosmic\_ray\_flux}
\label{api/gammapy.spectrum.cosmic_ray_flux:cosmic-ray-flux}\label{api/gammapy.spectrum.cosmic_ray_flux:astropy}\label{api/gammapy.spectrum.cosmic_ray_flux::doc}\index{cosmic\_ray\_flux() (in module gammapy.spectrum)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.spectrum.cosmic_ray_flux:gammapy.spectrum.cosmic_ray_flux}\pysiglinewithargsret{\code{gammapy.spectrum.}\bfcode{cosmic\_ray\_flux}}{\emph{energy}, \emph{particle='proton'}}{}
Cosmic ray flux at Earth.
These are the spectra assumed in this CTA study:
Table 3 in \href{http://adsabs.harvard.edu/abs/2013APh....43..171B}{http://adsabs.harvard.edu/abs/2013APh....43..171B}
The hadronic spectra are simple power-laws, the electron spectrum
is the sum of a power law and a log-normal component to model the
``Fermi shoulder''.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energy} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Particle energy
\end{quote}
\textbf{particle} : \{`electron', `proton', `He', `N', `Si', `Fe'\}
\begin{quote}
Particle type
\end{quote}
\item[{Returns}] \leavevmode
\textbf{flux} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Cosmic ray flux in unit \code{m\textasciicircum{}-2 s\textasciicircum{}-1 TeV\textasciicircum{}-1 sr\textasciicircum{}-1}
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{crab\_flux}
\label{api/gammapy.spectrum.crab_flux:astropy}\label{api/gammapy.spectrum.crab_flux::doc}\label{api/gammapy.spectrum.crab_flux:crab-flux}\index{crab\_flux() (in module gammapy.spectrum)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.spectrum.crab_flux:gammapy.spectrum.crab_flux}\pysiglinewithargsret{\code{gammapy.spectrum.}\bfcode{crab\_flux}}{\emph{energy=1}, \emph{reference='meyer'}}{}
Differential Crab flux.
See the \code{gammapy.spectrum.crab} module docstring for a description
of the available reference spectra.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energy} : array\_like
\begin{quote}
Energy (TeV)
\end{quote}
\textbf{reference} : \{\{`hegra', `hess\_pl', `hess\_ecpl', `meyer'\}\}
\begin{quote}
Published Crab reference spectrum
\end{quote}
\item[{Returns}] \leavevmode
\textbf{flux} : array
\begin{quote}
Differential flux (cm\textasciicircum{}-2 s\textasciicircum{}-1 TeV\textasciicircum{}-1) at \code{energy}
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{crab\_integral\_flux}
\label{api/gammapy.spectrum.crab_integral_flux:astropy}\label{api/gammapy.spectrum.crab_integral_flux::doc}\label{api/gammapy.spectrum.crab_integral_flux:crab-integral-flux}\index{crab\_integral\_flux() (in module gammapy.spectrum)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.spectrum.crab_integral_flux:gammapy.spectrum.crab_integral_flux}\pysiglinewithargsret{\code{gammapy.spectrum.}\bfcode{crab\_integral\_flux}}{\emph{energy\_min=1}, \emph{energy\_max=10000.0}, \emph{reference='meyer'}}{}
Integral Crab flux.
See the \code{gammapy.spectrum.crab} module docstring for a description
of the available reference spectra.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energy\_min, energy\_max} : array\_like
\begin{quote}
Energy band (TeV)
\end{quote}
\textbf{reference} : \{\{`hegra', `hess\_pl', `hess\_ecpl', `meyer'\}\}
\begin{quote}
Published Crab reference spectrum
\end{quote}
\item[{Returns}] \leavevmode
\textbf{flux} : array
\begin{quote}
Integral flux (cm\textasciicircum{}-2 s\textasciicircum{}-1) in energy band \code{energy\_min} to \code{energy\_max}
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{crab\_spectral\_index}
\label{api/gammapy.spectrum.crab_spectral_index:astropy}\label{api/gammapy.spectrum.crab_spectral_index::doc}\label{api/gammapy.spectrum.crab_spectral_index:crab-spectral-index}\index{crab\_spectral\_index() (in module gammapy.spectrum)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.spectrum.crab_spectral_index:gammapy.spectrum.crab_spectral_index}\pysiglinewithargsret{\code{gammapy.spectrum.}\bfcode{crab\_spectral\_index}}{\emph{energy=1}, \emph{reference='meyer'}}{}
Spectral index (positive number) at a given energy.
See the \code{gammapy.spectrum.crab} module docstring for a description
of the available reference spectra.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energy} : array\_like
\begin{quote}
Energy (TeV)
\end{quote}
\textbf{reference} : \{\{`hegra', `hess\_pl', `hess\_ecpl', `meyer'\}\}
\begin{quote}
Published Crab reference spectrum
\end{quote}
\item[{Returns}] \leavevmode
\textbf{spectral\_index} : array
\begin{quote}
Spectral index at \code{energy}
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{cube\_sed}
\label{api/gammapy.spectrum.cube_sed:astropy}\label{api/gammapy.spectrum.cube_sed::doc}\label{api/gammapy.spectrum.cube_sed:cube-sed}\index{cube\_sed() (in module gammapy.spectrum)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.spectrum.cube_sed:gammapy.spectrum.cube_sed}\pysiglinewithargsret{\code{gammapy.spectrum.}\bfcode{cube\_sed}}{\emph{cube}, \emph{mask=None}, \emph{flux\_type='differential'}, \emph{counts=None}, \emph{errors=False}, \emph{standard\_error=0.1}, \emph{spectral\_index=2.3}}{}
Creates SED from SpectralCube within given lat and lon range.
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{cube} : {\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube]{\emph{\code{SpectralCube}}}}
\begin{quote}
Spectral cube of either differential or integral fluxes (specified
with flux\_type)
\end{quote}
\textbf{mask} : array\_like, optional
\begin{quote}
2D mask array, matching spatial dimensions of input cube.
A mask value of True indicates a value that should be ignored,
while a mask value of False indicates a valid value.
\end{quote}
\textbf{flux\_type} : \{`differential', `integral'\}
\begin{quote}
Specify whether input cube includes differential or integral fluxes.
\end{quote}
\textbf{counts} : {\hyperref[api/gammapy.data.SpectralCube:gammapy.data.SpectralCube]{\emph{\code{SpectralCube}}}}, optional
\begin{quote}
Counts cube to allow Poisson errors to be calculated. If not provided,
a standard\_error should be provided, or zero errors will be returned.
\end{quote}
\textbf{errors} : bool
\begin{quote}
If True, computes errors, if possible, according to provided inputs.
If False (default), returns all errors as zero.
\end{quote}
\textbf{standard\_error} : float
\begin{quote}
If counts cube not provided, but error values required, this specifies
a standard fractional error to be applied to values. Default = 0.1.
\end{quote}
\textbf{spectral\_index} : float
\begin{quote}
If integral flux is provided, this is used to calculate differential
fluxes and energies (according to the Lafferty \& Wyatt model-based
method, assuming a power-law model).
\end{quote}
\item[{Returns}] \leavevmode
\textbf{table} : \href{http://docs.astropy.org/en/latest/api/astropy.table.Table.html\#astropy.table.Table}{\code{Table}}
\begin{quote}
A spectral energy table of energies, differential fluxes and
differential flux errors. Units as those input.
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{diffuse\_gamma\_ray\_flux}
\label{api/gammapy.spectrum.diffuse_gamma_ray_flux:diffuse-gamma-ray-flux}\label{api/gammapy.spectrum.diffuse_gamma_ray_flux:astropy}\label{api/gammapy.spectrum.diffuse_gamma_ray_flux::doc}\index{diffuse\_gamma\_ray\_flux() (in module gammapy.spectrum)}
\begin{fulllineitems}
\phantomsection\label{api/gammapy.spectrum.diffuse_gamma_ray_flux:gammapy.spectrum.diffuse_gamma_ray_flux}\pysiglinewithargsret{\code{gammapy.spectrum.}\bfcode{diffuse\_gamma\_ray\_flux}}{\emph{energy}, \emph{component='isotropic'}}{}
Diffuse gamma ray flux.
TODO: describe available spectra.
References:
* `isotropic': \href{http://adsabs.harvard.edu/abs/2010PhRvL.104j1101A}{http://adsabs.harvard.edu/abs/2010PhRvL.104j1101A}
\begin{quote}\begin{description}
\item[{Parameters}] \leavevmode
\textbf{energy} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Gamma-ray energy
\end{quote}
\textbf{component} : \{`isotropic', `bubble', `galactic\_fermi2', `galactic\_fermi4'\}
\begin{quote}
Diffuse model component
\end{quote}
\item[{Returns}] \leavevmode
\textbf{flux} : \href{http://docs.astropy.org/en/latest/api/astropy.units.Quantity.html\#astropy.units.Quantity}{\code{Quantity}}
\begin{quote}
Gamma-ray flux in unit \code{m\textasciicircum{}-2 s\textasciicircum{}-1 TeV\textasciicircum{}-1 sr\textasciicircum{}-1}
\end{quote}
\end{description}\end{quote}
\end{fulllineitems}
\paragraph{energy\_bin\_centers\_log\_spacing}
\label{api/gammapy.spectrum.energy_bin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment