示例#1
0
from __future__ import absolute_import, division, print_function
import os
import numpy as np
from numpy.testing import assert_allclose
from astropy.tests.helper import pytest
from astropy.table import Table
from fermipy.tests.utils import requires_dependency, requires_st_version
from fermipy import spectrum

try:
    from fermipy import gtanalysis
except ImportError:
    pass

# Skip tests in this file if Fermi ST aren't available
pytestmark = requires_dependency('Fermi ST')


@pytest.fixture(scope='module')
def create_draco_analysis(request, tmpdir_factory):
    path = tmpdir_factory.mktemp('draco')
    url = 'https://raw.githubusercontent.com/fermiPy/fermipy-extras/master/data/fermipy_test_draco.tar.gz'
    outfile = path.join('fermipy_test_draco.tar.gz')
    dirname = path.join()
    os.system('curl -o %s -OL %s' % (outfile, url))
    os.system('cd %s;tar xzf %s' % (dirname, outfile))
    request.addfinalizer(lambda: path.remove(rec=1))

    cfgfile = path.join('fermipy_test_draco', 'config.yaml')
    gta = gtanalysis.GTAnalysis(str(cfgfile))
    gta.setup()
示例#2
0
from __future__ import absolute_import, division, print_function
import os
import numpy as np
from numpy.testing import assert_allclose
from astropy.tests.helper import pytest
from astropy.coordinates import SkyCoord
from fermipy.tests.utils import requires_dependency
from fermipy import spectrum

try:
    from fermipy import irfs
except ImportError:
    pass

# Skip tests in this file if Fermi ST aren't available
pytestmark = requires_dependency('Fermi ST')


def test_calc_exp():

    ltc = irfs.LTCube.create_from_obs_time(3.1536E8)
    c = SkyCoord(10.0, 10.0, unit='deg')
    egy = 10**np.linspace(1.0, 6.0, 6)
    cth_bins = np.array([0.2, 0.6, 1.0])

    exp = irfs.calc_exp(c, ltc, 'P8R2_SOURCE_V6', ['FRONT', 'BACK'],
                        egy, cth_bins)

    assert_allclose(exp,
                    np.array([[1.99488297e+07,   1.19873696e+08],
                              [2.62408989e+10,   1.45160418e+11],