Skip to content

Commit

Permalink
Merge pull request #2348 from cdeil/gammapy.modeling
Browse files Browse the repository at this point in the history
Add models to gammapy.modeling.models
  • Loading branch information
cdeil committed Sep 9, 2019
2 parents ed50a58 + d558acd commit 35d5237
Show file tree
Hide file tree
Showing 100 changed files with 558 additions and 513 deletions.
6 changes: 3 additions & 3 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,9 @@ learn about the new maps classes, see the ``intro_maps`` tutorial at

The new ``gammapy.utils.fitting`` contains a simple modeling and fitting
framework, that allows the use of ``iminuit`` and ``sherpa`` optimisers as
"backends" for any fit in Gammapy. The classes in `gammapy.spectrum.models` (1D
spectrum models) are updated, and `gammapy.image.models` (2D spatial models) and
`gammapy.cube.models` (3D cube models) was added. The ``SpectrumFit`` class was
"backends" for any fit in Gammapy. The classes in ``gammapy.spectrum.models`` (1D
spectrum models) are updated, and ``gammapy.image.models`` (2D spatial models) and
``gammapy.cube.models`` (3D cube models) was added. The ``SpectrumFit`` class was
updated and a ``MapFit`` to fit models to maps was added. This part of Gammapy
remains work in progress, some changes and major improvements are planned for
the coming months.
Expand Down
4 changes: 2 additions & 2 deletions docs/catalog/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ The ``SourceCatalog`` class mostly handles data file loading, as well as source
access by integer row index or source name. The ``SourceCatalogObject`` class
implements in ``__str__`` a pretty-printed version of ``source.data``, so that
you can ``print(source)``, as well as factory methods to create Gammapy objects
such as `gammapy.spectrum.models.SpectralModel` or
``gammapy.image.models.SkySpatialModel`` or `gammapy.spectrum.FluxPoints`
such as `gammapy.modeling.models.SpectralModel` or
`gammapy.modeling.models.SkySpatialModel` or `gammapy.spectrum.FluxPoints`
representing spatial and spectral models, or spectral points, which you can then
print or plot or use for simulation and analysis.

Expand Down
4 changes: 0 additions & 4 deletions docs/cube/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,3 @@ Reference/API
.. automodapi:: gammapy.cube
:no-inheritance-diagram:
:include-all-objects:

.. automodapi:: gammapy.cube.models
:no-inheritance-diagram:
:include-all-objects:
2 changes: 1 addition & 1 deletion docs/development/pigs/pig-016.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Introduce gammapy.modeling
Currently our fitting and modeling framework is in gammapy.utils.fitting,
and the built-in models in Gammapy are distributed like this:

* gammapy.spectrum.models -- 1D spectral models
* gammapy.modeling.models -- 1D spectral models
* gammapy.image.models -- 2D spatial models
* gammapy.cube.models -- 3D cube models
* gammapy.time.models -- 1D time models
Expand Down
20 changes: 0 additions & 20 deletions docs/image/index.rst

This file was deleted.

2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ To get started with Gammapy, follow the installation and setup instructions in
data/index
irf/index
maps/index
image/index
modeling/index
cube/index
detect/index
spectrum/index
Expand Down
35 changes: 35 additions & 0 deletions docs/modeling/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.. include:: ../references.txt

.. _modeling:

*****************************
modeling - Models and fitting
*****************************

.. currentmodule:: gammapy.modeling

Introduction
============

tbd

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

tbd

Using `gammapy.modeling`
========================

tbd

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

.. automodapi:: gammapy.modeling
:no-inheritance-diagram:
:include-all-objects:

.. automodapi:: gammapy.modeling.models
:no-inheritance-diagram:
:include-all-objects:
2 changes: 1 addition & 1 deletion docs/spectrum/fitting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ simulated crab runs using the `~gammapy.utils.fitting.Fit` class.
from gammapy.spectrum import SpectrumDatasetOnOff
from gammapy.utils.fitting import Fit
from gammapy.spectrum.models import PowerLaw
from gammapy.modeling.models import PowerLaw
import matplotlib.pyplot as plt
path = "$GAMMAPY_DATA/joint-crab/spectra/hess/"
Expand Down
6 changes: 1 addition & 5 deletions docs/spectrum/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ OGIP format and fit a spectral model.
from gammapy.spectrum import SpectrumDatasetOnOff
from gammapy.utils.fitting import Fit
from gammapy.spectrum.models import PowerLaw
from gammapy.modeling.models import PowerLaw
filename = '$GAMMAPY_DATA/joint-crab/spectra/hess/pha_obs23523.fits'
dataset = SpectrumDatasetOnOff.from_ogip_files(filename)
Expand Down Expand Up @@ -95,7 +95,3 @@ Reference/API
.. automodapi:: gammapy.spectrum
:no-inheritance-diagram:
:include-all-objects:

.. automodapi:: gammapy.spectrum.models
:no-inheritance-diagram:
:include-all-objects:
4 changes: 0 additions & 4 deletions docs/time/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,3 @@ Reference/API
.. automodapi:: gammapy.time
:no-inheritance-diagram:
:include-all-objects:

.. automodapi:: gammapy.time.models
:no-inheritance-diagram:
:include-all-objects:
10 changes: 4 additions & 6 deletions examples/example_2_gauss.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import matplotlib.pyplot as plt
import numpy as np
import astropy.units as u
from astropy.coordinates import SkyCoord
import matplotlib.pyplot as plt
from gammapy.cube import MapEvaluator, make_map_exposure_true_energy
from gammapy.irf import EffectiveAreaTable2D
from gammapy.maps import WcsGeom, MapAxis, WcsNDMap
from gammapy.spectrum.models import PowerLaw
from gammapy.image.models import SkyGaussian
from gammapy.maps import MapAxis, WcsGeom, WcsNDMap
from gammapy.modeling.models import PowerLaw, SkyGaussian, SkyModel
from gammapy.utils.random import get_random_state
from gammapy.cube import make_map_exposure_true_energy, MapEvaluator
from gammapy.cube.models import SkyModel

filename = "$GAMMAPY_DATA/cta-1dc/caldb/data/cta/1dc/bcf/South_z20_50h/irf_file.fits"
aeff = EffectiveAreaTable2D.read(filename, hdu="EFFECTIVE AREA")
Expand Down
24 changes: 12 additions & 12 deletions gammapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
::
`astro` --- Astrophysical source and population models
`catalog` --- Source catalog tools
`cube` --- Cube analysis
`data` --- Data and observation handling
`detect` --- Source detection tools
`image` --- Image processing and analysis tools
`irf` --- Instrument response functions (IRFs)
`maps` --- Sky map data structures
`spectrum` --- Spectrum estimation and modeling
`stats` --- Statistics tools
`time` --- Time handling and analysis
`utils` --- Utility functions and classes
astro --- Astrophysical source and population models
catalog --- Source catalog tools
cube --- Cube analysis
data --- Data and observation handling
detect --- Source detection tools
irf --- Instrument response functions (IRFs)
maps --- Sky map data structures
modeling --- Models and fitting
spectrum --- Spectrum estimation and modeling
stats --- Statistics tools
time --- Time handling and analysis
utils --- Utility functions and classes
"""

__all__ = ["__version__", "test", "song"]
Expand Down
4 changes: 2 additions & 2 deletions gammapy/astro/darkmatter/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import abc
import numpy as np
import astropy.units as u
from gammapy.spectrum import integrate_spectrum
from gammapy.modeling.models.spectrum.utils import integrate_spectrum
from gammapy.utils.fitting import Parameter, Parameters

__all__ = [
Expand Down Expand Up @@ -52,7 +52,7 @@ def integral(self, rmin, rmax, **kwargs):
rmin, rmax : `~astropy.units.Quantity`
Lower and upper bound of integration range.
**kwargs : dict
Keyword arguments passed to :func:`~gammapy.spectrum.integrate_spectrum`
Keyword arguments passed to :func:`~gammapy.modeling.models.integrate_spectrum`
"""
integral = integrate_spectrum(self._eval_squared, rmin, rmax, **kwargs)
return integral.to("GeV2 / cm5")
Expand Down
8 changes: 4 additions & 4 deletions gammapy/astro/darkmatter/spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import astropy.units as u
from astropy.table import Table
from gammapy.spectrum.models import SpectralModel, TableModel
from gammapy.modeling.models import SpectralModel, TableModel
from gammapy.utils.fitting import Parameter
from gammapy.utils.scripts import make_path

Expand All @@ -16,7 +16,7 @@ class PrimaryFlux:
Based on the precomputed models by Cirelli et al. (2016). All available
annihilation channels can be found there. The dark matter mass will be set
to the nearest available value. The spectra will be available as
`~gammapy.spectrum.models.TableModel` for a chosen dark matter mass and
`~gammapy.modeling.models.TableModel` for a chosen dark matter mass and
annihilation channel.
References
Expand Down Expand Up @@ -114,7 +114,7 @@ def channel(self, channel):

@property
def table_model(self):
"""Spectrum as `~gammapy.spectrum.models.TableModel`."""
"""Spectrum as `~gammapy.modeling.models.TableModel`."""
subtable = self.table[self.table["mDM"] == self.mDM.value]
energies = (10 ** subtable["Log[10,x]"]) * self.mDM
channel_name = self.channel_registry[self.channel]
Expand Down Expand Up @@ -142,7 +142,7 @@ class DMAnnihilation(SpectralModel):
scale : float
Scale parameter for model fitting
jfactor : `~astropy.units.Quantity`
Integrated J-Factor needed when `~gammapy.image.models.SkyPointSource` spatial model is used
Integrated J-Factor needed when `~gammapy.modeling.models.SkyPointSource` spatial model is used
z: float
Redshift value
k: int
Expand Down
29 changes: 16 additions & 13 deletions gammapy/catalog/fermi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
import astropy.units as u
from astropy.table import Column, Table
from astropy.time import Time
from gammapy.cube.models import SkyModel
from gammapy.image.models import SkyDiffuseMap, SkyDisk, SkyGaussian, SkyPointSource
from gammapy.maps import Map
from gammapy.spectrum import FluxPoints
from gammapy.spectrum.models import (
from gammapy.modeling.models import (
ExponentialCutoffPowerLaw3FGL,
LogParabola,
PLSuperExpCutoff3FGL,
PLSuperExpCutoff4FGL,
PowerLaw,
PowerLaw2,
SkyDiffuseMap,
SkyDisk,
SkyGaussian,
SkyModel,
SkyPointSource,
)
from gammapy.spectrum import FluxPoints
from gammapy.time import LightCurve
from gammapy.utils.scripts import make_path
from gammapy.utils.table import table_standardise_units_inplace
Expand Down Expand Up @@ -52,7 +55,7 @@ class SourceCatalogObject4FGL(SourceCatalogObject):

@property
def spectral_model(self):
"""Best fit spectral model (`~gammapy.spectrum.models.SpectralModel`)."""
"""Best fit spectral model (`~gammapy.modeling.models.SpectralModel`)."""
spec_type = self.data["SpectrumType"].strip()

pars, errs = {}, {}
Expand Down Expand Up @@ -332,7 +335,7 @@ def _info_lightcurve(self):

@property
def spectral_model(self):
"""Best fit spectral model (`~gammapy.spectrum.models.SpectralModel`)."""
"""Best fit spectral model (`~gammapy.modeling.models.SpectralModel`)."""
spec_type = self.data["SpectrumType"].strip()

pars, errs = {}, {}
Expand Down Expand Up @@ -375,7 +378,7 @@ def spectral_model(self):
@property
def spatial_model(self):
"""
Source spatial model (`~gammapy.image.models.SkySpatialModel`).
Source spatial model (`~gammapy.modeling.models.SkySpatialModel`).
"""
d = self.data

Expand Down Expand Up @@ -409,7 +412,7 @@ def spatial_model(self):

@property
def sky_model(self):
"""Source sky model (`~gammapy.cube.models.SkyModel`)."""
"""Source sky model (`~gammapy.modeling.models.SkyModel`)."""
spatial_model = self.spatial_model
spectral_model = self.spectral_model
return SkyModel(spatial_model, spectral_model, name=self.name)
Expand Down Expand Up @@ -564,7 +567,7 @@ def flux_points(self):

@property
def spectral_model(self):
"""Best fit spectral model `~gammapy.spectrum.models.SpectralModel`."""
"""Best fit spectral model `~gammapy.modeling.models.SpectralModel`."""
pars, errs = {}, {}
pars["amplitude"] = self.data["Flux"]
pars["emin"], pars["emax"] = self.energy_range
Expand Down Expand Up @@ -636,7 +639,7 @@ def flux_points(self):

@property
def spectral_model(self):
"""Best fit spectral model (`~gammapy.spectrum.models.SpectralModel`)."""
"""Best fit spectral model (`~gammapy.modeling.models.SpectralModel`)."""
pars, errs = {}, {}
pars["amplitude"] = self.data["Flux50"]
pars["emin"], pars["emax"] = self.energy_range
Expand Down Expand Up @@ -850,7 +853,7 @@ def _info_other(self):

@property
def spectral_model(self):
"""Best fit spectral model (`~gammapy.spectrum.models.SpectralModel`)."""
"""Best fit spectral model (`~gammapy.modeling.models.SpectralModel`)."""
d = self.data
spec_type = self.data["SpectrumType"].strip()

Expand Down Expand Up @@ -913,7 +916,7 @@ def flux_points(self):

@property
def spatial_model(self):
"""Source spatial model (`~gammapy.image.models.SkySpatialModel`)."""
"""Source spatial model (`~gammapy.modeling.models.SkySpatialModel`)."""
d = self.data

pars = {}
Expand Down Expand Up @@ -946,7 +949,7 @@ def spatial_model(self):

@property
def sky_model(self):
"""Source sky model (`~gammapy.cube.models.SkyModel`)."""
"""Source sky model (`~gammapy.modeling.models.SkyModel`)."""
spatial_model = self.spatial_model
spectral_model = self.spectral_model
return SkyModel(spatial_model, spectral_model, name=self.name)
Expand Down

0 comments on commit 35d5237

Please sign in to comment.