Git Product home page Git Product logo

gammapy's Introduction

Licence

image

image

Latest release

PyPI - Downloads

image

image

image

image

image

image

Gammapy

A Python Package for Gamma-ray Astronomy.

Gammapy is an open-source Python package for gamma-ray astronomy built on Numpy, Scipy and Astropy. It is used as core library for the Science Analysis tools of the Cherenkov Telescope Array (CTA), recommended by the H.E.S.S. collaboration to be used for Science publications, and is already widely used in the analysis of existing gamma-ray instruments, such as MAGIC, VERITAS and HAWC.

Contributing Code, Documentation, or Feedback

The Gammapy Project is made both by and for its users, so we welcome and encourage contributions of many kinds. Our goal is to keep this a positive, inclusive, successful, and growing community by abiding with the Gammapy Community Code of Conduct.

The Gammapy project uses a mechanism known as a Developer Certificate of Origin (DCO). The DCO is a binding statement that asserts that you are the creator of your contribution, and that you wish to allow Gammapy to use your work to cite you as contributor. More detailed information on contributing to the project or submitting feedback can be found on the Contributing page.

Licence

Gammapy is licensed under a 3-clause BSD style license - see the LICENSE.rst file.

Supporting the project

The Gammapy project is not sponsored and the development is made by the staff of the institutes supporting the project over their research time. Any contribution is then encouraged, as punctual or regular contributor.

Status shields

(mostly useful for developers)

  • Codacy
  • GitHub actions CI
  • image

Note if you cloned this repository before Oct 7th 2022

The primary branch was renamed main. See the following instructions: https://github.com/gammapy/gammapy/wiki/Changing-master-branch-to-main

gammapy's People

Contributors

aaguasca avatar actions-user avatar adonath avatar astrofrog avatar atreyees avatar bkhelifi avatar bsipocz avatar bultako avatar cdeil avatar cgalelli avatar cnachi avatar dimitripapadopoulos avatar fabiopintore avatar facero avatar jaleleddine avatar joleroi avatar jonathandharris avatar katrinstreil avatar lauraolivera avatar lmohrmann avatar mapazarr avatar maxnoe avatar morcuended avatar mregeard avatar olgavorokh avatar paulakx avatar qremy avatar registerrier avatar stfroese avatar woodmd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gammapy's Issues

Implement simplexy in detect

Implement Observation and Observations class

Implement some book-keeping classes:

RunInfo:
- livetime
- RA, DEC
- mean_zenith

and a RunList class which is a list of RunInfos.

Both should have read / write e.g. in JSON or ??? format.

There is already a gammapy.obs module, but it's currently almost empty. See here and here.

Implement image <-> table conversion functions

Implement image_to_table and table_to_image conversion functions.
They should take a mask of pixels of interest and optionally give pixel and / or world coordinate columns.
The WCS info will be lost in the table of course.

AttributeError in test_SNR_Truelove

@adonath Could you please fix the following error?

_______________________________________________________________________________ test_SNR_Truelove ________________________________________________________________________________

    def test_SNR_Truelove():
        snr = SNR_Truelove()
        assert_approx_equal(snr.L(1e3), 1.0768456645602824e+33)
>       assert_approx_equal(snr.r_out(1e3), 42)

tevpy/astro/tests/test_snr.py:14: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <tevpy.astro.snr.SNR_Truelove object at 0x10bedb8d0>, t = 31557600000.000004

    def r_out(self, t):
        """Outer shell radius (pc) at age t (yr).
            """
        t = YEAR_TO_SEC * t
        # Sedov Taylor Phase
        t_ST = 0.52 * self.t_c
>       R_FE = self.r_reverse_free_expansion(t_ST)
E       AttributeError: 'SNR_Truelove' object has no attribute 'r_reverse_free_expansion'

tevpy/astro/snr.py:166: AttributeError

Document scripts in docs

The help output from the command line tools ("scripts") as well as examples should be included in the docs for end-users that don't want to use Python or know how it works.
#230 makes this possible ... the script functions (but not their command line tool help output) are now listed here: https://gammapy.readthedocs.org/en/latest/scripts/index.html

We still have to programatically get at the help output and integrate this in the Sphinx build somehow ...

array cdf random sampling

The current GeneralRandom class should be improved (work with n-dim arrays, rename, document, unit tests).

I think this can be implemented better with np.choice when passing a=pdf and p=pdf.

It would also be nice to add functions that consider the array a discretised version of a continuous function and then sample that continuous function, similar to what is available in ROOT:
http://root.cern.ch/root/html/src/TF2.cxx.html#QsZi6C

I've made a feature request for this in scipy: scipy/scipy#3747

Implement run list format

Implement some book-keeping classes:

RunInfo:
- livetime
- RA, DEC
- mean_zenith

and a RunList class which is a list of RunInfos.

Both should have read / write e.g. in JSON format.

Spectrum file formats and interop with other tools

In Gammapy we should support existing spectrum file formats.
Also we should make it easy to use other existing tools.

These might be useful for visualisation or even analysis, there might be more:

I think these all work on spectra = flux points, I'm not sure if any know about effective areas or other IRFs and counts spectra.

And there's of course the X-ray PHA, ARF, RMF standards and tools like Sherpa, Fermi Science tools and Gammalib and Naima that support those or other slightly different formats.

Overall it's pretty difficult to decide what exactly should go in gammapy.spectrum and what is needed is both code to handle the most useful formats, as well as high-level documentation which formats we support (e.g. write this page and which other tools can be useful for SED modeling / analysis / fitting.

@joleroi, @ignasi-reichardt, @registerrier – Maybe we can have a telcon and hash out a proposal what exactly we want next week?

cython not found by setup.py

I am trying to add Cython files to this package which I forked from astropy/package-template, but for some reason setup.py doesn't find cython:

$ python setup.py build
running build
running build_py
running build_ext
error: tevpy/example_c.c: Could not find C file tevpy/example_c.c for Cython file tevpy/example_c.pyx when building extension tevpy.example_c. Cython must be installed to build from a git checkout

To reproduce:

git clone https://github.com/gammapy/tevpy.git
cd tevpy
curl -L https://raw.github.com/astropy/package-template/master/packagename/example_c.pyx > tevpy/example_c.pyx
python setup.py build

@astrofrog @iguananaut I don't understand why this works for other affiliated packages (I tried with package-template and astroquery), but not in tevpy! Can one of you please have a look?

Add visibility computation / plot functionality

We should add basic data and methods for TeV telescope observer calculations.

E.g. TeVCat has for each TeV telescope location and TeV target the "Vis-plot this source" and "vis-plot full year" plots ... see e.g. the Crab as an example.

Since astropy.coordinates doesn't contain Sky-to-horizon coordinate transformations yet, we can use PyEphem as shown in this example to do the computations.

Other examples worth looking at are the Python observer or visibility-map packages and observation apps like iobserve.

Reproducing the TeVCat plots mentioned above should be easy as a start and then we can ask for user feature requests.

Reflected background method

We should implement the reflected background method.

It's not clear to me yet what a good API (class or function?) and implementation (cartesian FOV or spherical sky coordinate system?) for this is.

Some code that computes reflected regions is available already in gammapy/background/reflected.py

It would probably be best to start with a concrete use case, e.g. compute n_on and n_off spectra for XSPEC-style analysis using eventlists and exclusion regions as input.

Add XSPEC example dataset from Fermi LAT

After #68 is merged, we should add an XSPEC example to gammapy.data and example plots of the response and analysis as a tutorial.

A Fermi observation of a GRB would be nice:

The Fermi tools generate RSP files (see here which are the produce of the ARF and RMF. We need a gammapy reader or class for this.

Implement fast, accurate integrator for power-law type functions

I've had problems getting accurate results when numerically integrating power-law type functions (spectral models like curved or exponential cutoff power law) using scipy.quad or other integrators.

I think using a log(x) spacing instead of x and using a simple integration method that takes vectors of x and y as input like cumtrapz or scipy.simps
should give good results.

Also check all GammaLib results for flux and eflux and compare speed / accuracy. Usage example:

from gammalib import GModelSpectralPlaw, GModelSpectralPlaw2, GModelSpectralExpPlaw, GModelSpectralLogParabola
from gammalib import GEnergy, GTime
model = GModelSpectralPlaw(1, 2, GEnergy(1, 'TeV'))
print model.eval(gammalib.GEnergy(10, 'TeV'), gammalib.GTime(1, 's'))
print model.flux(GEnergy(1, 'TeV'), GEnergy(10, 'TeV'))
print model.eflux(GEnergy(1, 'TeV'), GEnergy(10, 'TeV'))

Links:

Implement toy background simulation

There should be a tool to simulate background event lists to generate test data sets.

What I have in mind is a simple analytical formula

background_rate(zenith, offset, mscw)

that gives the background rate in units counts / second / deg ^ 2 for a given zenith angle, offset in the FOV and mean scaled width mscw parameter.

The point is not to have a very realistic model, just any model so that all the background methods can be tested.

Proposal:

  • total rate (for all offsets, mscw) is a simple polynomial in zenith.
  • FOV distribution is 2D Gauss and mscw distribution 1D Gauss with varying widths (how?)

Sphinx build warnings with `astropy.utils.data.get_pkg_data_filename`

I'm using astropy.utils.data.get_pkg_data_filename in a few places in tevpy (see here).

This causes four tevpy Sphinx build warnings:

building [html]: all source files
updating environment: 126 added, 0 changed, 0 removed
reading sources... [100%] tevpy/utils/index                                    rocity
/Users/deil/code/tevpy/docs/tevpy/detect/index.rst:85: WARNING: toctree references unknown document u'_generated/astropy.utils.data.get_pkg_data_filename'
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] tevpy/utils/index                                     ocity
None:None: WARNING: toctree contains reference to nonexisting document '_generated/astropy.utils.data.get_pkg_data_filename'
<autosummary>:None: WARNING: toctree contains reference to nonexisting document '_generated/astropy.utils.data.get_pkg_data_filename'
None:None: WARNING: toctree contains reference to nonexisting document '_generated/astropy.utils.data.get_pkg_data_filename'
writing additional files... (31 module code pages) _modules/index
 genindex py-modindex np-modindex search
copying static files... done
dumping search index... done
dumping object inventory... done
build succeeded, 4 warnings.

It's annoying because it makes the travis-ci sphinx build fail:
https://travis-ci.org/gammapy/tevpy/jobs/9869684#L686

@eteq @astrofrog @iguananaut Do you know why this is happening? How can I fix it?

Docs build error on readthedocs related to `astropy.wcs`

The tevpy docs build now fails because of a problem with astropy.wcs (see below and here.
I don't see this error on my local machine.

@mdboom Do you know what the problem is? Is this a problem in astropy or am I doing something wrong?

Obtaining astropy from git+http://github.com/astropy/astropy.git#egg=astropy (from -r docs/rtd-pip-requirements.txt (line 4))
  Updating /home/docs/checkouts/readthedocs.org/user_builds/tevpy/envs/latest/src/astropy clone
  Running setup.py egg_info for package astropy
    Traceback (most recent call last):
      File "<string>", line 16, in <module>
      File "/home/docs/checkouts/readthedocs.org/user_builds/tevpy/envs/latest/src/astropy/setup.py", line 82, in <module>
        package_dirs)
      File "astropy/setup_helpers.py", line 1028, in update_package_files
        extensions.extend(setuppkg.get_extensions())
      File "astropy/wcs/setup_package.py", line 206, in get_extensions
        generate_c_docstrings()
      File "astropy/wcs/setup_package.py", line 122, in generate_c_docstrings
        from astropy.wcs import docstrings
      File "astropy/wcs/__init__.py", line 27, in <module>
        from .wcs import *
      File "astropy/wcs/wcs.py", line 82, in <module>
        WcsError = _wcs.WcsError
    AttributeError: 'module' object has no attribute 'WcsError'
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 16, in <module>

  File "/home/docs/checkouts/readthedocs.org/user_builds/tevpy/envs/latest/src/astropy/setup.py", line 82, in <module>

    package_dirs)

  File "astropy/setup_helpers.py", line 1028, in update_package_files

    extensions.extend(setuppkg.get_extensions())

  File "astropy/wcs/setup_package.py", line 206, in get_extensions

    generate_c_docstrings()

  File "astropy/wcs/setup_package.py", line 122, in generate_c_docstrings

    from astropy.wcs import docstrings

  File "astropy/wcs/__init__.py", line 27, in <module>

    from .wcs import *

  File "astropy/wcs/wcs.py", line 82, in <module>

    WcsError = _wcs.WcsError

AttributeError: 'module' object has no attribute 'WcsError'

----------------------------------------
Command python setup.py egg_info failed with error code 1 in /home/docs/checkouts/readthedocs.org/user_builds/tevpy/envs/latest/src/astropy

FOV- to Sky projection

Some background modelling is sometimes done in the FOV and then projected on a spherical coordinate system at the end.
Exclusion regions are often defined on the sky and need to be projected to the FOV system to be used there.
Implement a method to project back and forth (TAN WCS projection).

Some references ... I plan to work on this next week:

Check against Gammalib / ctools:

_lookup_pix should optionally ignore positions outside the array

Here's an example showing the problem:

/home/eowen/.local/lib/python2.7/site-packages/gammapy-0.1-py2.7.egg/gammapy/image/utils.pyc in _lookup_world(image, lon, lat)
    136     wcs = WCS(image.header)
    137     x, y = wcs.wcs_world2pix(lon, lat, 0)
--> 138     return _lookup_pix(image.data, x, y)
    139 
    140 

/home/eowen/.local/lib/python2.7/site-packages/gammapy-0.1-py2.7.egg/gammapy/image/utils.pyc in _lookup_pix(image, x, y)
    124     # Return it's value

    125     # Note that numpy has index order (y, x)

--> 126     values = image[y_int, x_int]
    127     return values
    128 

IndexError: index (9400) out of range (0<=index<9399) in dimension 1

Fix and test spectrum integral flux methods

The numerical integration to compute integral fluxes doesn't seem to work well ... I had this note:

    # @todo there are integration problems with e2=1e6.
    # test and use the integrator that works in log space!!!
    """
    In [36]: spec.crab.int_flux(0.2, 1e4, reference='hess_ecpl')
[  2.43196827e-10] [  2.61476507e-18]
Out[36]: array([  2.43196827e-10])

In [37]: spec.crab.int_flux(0.2, 1e5, reference='hess_ecpl')
Warning: The algorithm does not converge.  Roundoff error is detected
  in the extrapolation table.  It is assumed that the requested tolerance
  cannot be achieved, and that the returned result (if full_output = 1) is
  the best which can be obtained.
[  2.43283459e-10] [  4.37319063e-10]
Out[37]: array([  2.43283459e-10])

In [38]: spec.crab.int_flux(0.2, 1e6, reference='hess_ecpl')
[  6.40098358e-48] [  1.27271100e-47]
Out[38]: array([  6.40098358e-48])
    """
  • Make the integration method robust
  • Add several unit tests

python setup.py install doesn't install Python files

@astrofrog @eteq I can't figure out what I did wrong with the astropy affiliated package template so that now python setup.py install doesn't install any Python files:

warning: install_lib: 'build/lib' does not exist -- no Python modules to install

Indeed build/lib doesn't exist, it's called build/lib.macosx-10.7-x86_64-2.7.
Full log here: https://gist.github.com/cdeil/5586877

FYI: I am using the astropy affiliated package template for this project just to get the build / test / docs infrastructure, I most likely won't develop this into an astropy affiliated package, it's just a prototype for a proper implementation in the C++ library gammalib.

Utility function to compute IAU-style source name

Add a utility function that computes a source name string in these formats:

  • HESS J0534+220
  • 2FGL JHHMM.m+DDMM, constructed according to IAU Specifications for Nomenclature; m is decimal minutes of R.A.; in the name R.A. and decl. are truncated at 0.1 decimal minutes and 1, respectively

This should probably be in astropy ... check first if it already is or make PR there.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.