Skip to content

Instantly share code, notes, and snippets.

@cdeil
Created November 29, 2017 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdeil/50b29850f074af1c898e1c663f7dac88 to your computer and use it in GitHub Desktop.
Save cdeil/50b29850f074af1c898e1c663f7dac88 to your computer and use it in GitHub Desktop.
________________________________________________________ test_cta_sensitivity _________________________________________________________
@requires_dependency('scipy')
@requires_data('gammapy-extra')
def test_cta_sensitivity():
"""Run sensitivity estimation for one CTA IRF example."""
# TODO: change the test case to something simple that's easy to understand?
# E.g. a step function in AEFF and a very small Gaussian EDISP?
filename = '$GAMMAPY_EXTRA/datasets/cta/perf_prod2/point_like_non_smoothed/South_5h.fits.gz'
irf = CTAPerf.read(filename)
sens = SensitivityEstimator(irf=irf, livetime=5.0 * u.h)
sens.run()
table = sens.diff_sensi_table
assert len(table) == 21
# Assert on relevant values in three energy bins
# TODO: add asserts on other quantities: excess, exposure
assert_allclose(table['ENERGY'][0], 0.015848932787775993)
> assert_allclose(table['FLUX'][0], 1.2234342551880124e-10)
E AssertionError:
E Not equal to tolerance rtol=1e-07, atol=0
E
E (mismatch 100.0%)
E x: array(1.265689381204479e-10)
E y: array(1.2234342551880124e-10)
gammapy/scripts/tests/test_cta_sensitivity.py:29: AssertionError
_________________________________________________________ test_cta_simulation _________________________________________________________
@requires_data('gammapy-extra')
@requires_dependency('scipy')
def test_cta_simulation():
text = str(cta_simu())
assert '*** Observation summary report ***' in text
stats = cta_simu().total_stats
> assert_allclose(stats.sigma, 36.51439765644547)
E AssertionError:
E Not equal to tolerance rtol=1e-07, atol=0
E
E (mismatch 100.0%)
E x: array(36.404120931670384)
E y: array(36.51439765644547)
gammapy/scripts/tests/test_cta_utils.py:87: AssertionError
_____________________________________________________ test_spectrum_analysis_iact _____________________________________________________
tmpdir = local('/private/var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/pytest-of-deil/pytest-42/test_spectrum_analysis_iact0')
@requires_data('gammapy-extra')
@requires_dependency('scipy')
@requires_dependency('sherpa')
def test_spectrum_analysis_iact(tmpdir):
config = get_config()
config['outdir'] = tmpdir
analysis = SpectrumAnalysisIACT(observations=obs_list(), config=config)
analysis.run()
flux_points = analysis.flux_point_estimator.flux_points
print(flux_points)
print(flux_points.table)
actual = flux_points.table['dnde'].quantity[0]
desired = 7.987394752616973e-12 * u.Unit('cm-2 s-1 TeV-1')
> assert_quantity_allclose(actual, desired)
gammapy/scripts/tests/test_spectrum_pipe.py:45:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
actual = <Quantity 7.986780772924239e-12 1 / (cm2 s TeV)>, desired = <Quantity 7.987394752616973e-12 1 / (cm2 s TeV)>, rtol = 1e-07
atol = None, kwargs = {}
np = <module 'numpy' from '/Users/deil/software/anaconda3/anaconda3/lib/python3.6/site-packages/numpy/__init__.py'>
def assert_quantity_allclose(actual, desired, rtol=1.e-7, atol=None,
**kwargs):
"""
Raise an assertion if two objects are not equal up to desired tolerance.
This is a :class:`~astropy.units.Quantity`-aware version of
:func:`numpy.testing.assert_allclose`.
"""
import numpy as np
np.testing.assert_allclose(*_unquantify_allclose_arguments(actual, desired,
rtol, atol),
> **kwargs)
E AssertionError:
E Not equal to tolerance rtol=1e-07, atol=0
E
E (mismatch 100.0%)
E x: array(7.986780772924239e-12)
E y: array(7.987394752616973e-12)
/Users/deil/software/anaconda3/anaconda3/lib/python3.6/site-packages/astropy/tests/helper.py:473: AssertionError
-------------------------------------------------------- Captured stdout call ---------------------------------------------------------
FluxPoints(sed_type="dnde", n_points=4)
e_ref e_min e_max ... dnde_errp dnde_errn
TeV TeV TeV ... 1 / (cm2 s TeV) 1 / (cm2 s TeV)
------------- ------------- ------------- ... --------------- ---------------
1.56474814166 1.0 2.44843674682 ... nan nan
4.08423865267 2.44843674682 6.81292069058 ... nan nan
10.6605049898 6.81292069058 16.681005372 ... nan nan
27.8255940221 16.681005372 46.4158883361 ... nan nan
-------------------------------------------------------- Captured stderr call ---------------------------------------------------------
INFO Running SpectrumAnalysisIACT [gammapy.scripts.spectrum_pipe]
INFO Running ReflectedRegionsBackgroundEstimator
Region: CircleSkyRegion
center: <SkyCoord (ICRS): (ra, dec) in deg
( 83.63, 22.01)>
radius: 0.11 deg
ObservationList
Number of observations: 2
Info for OBS_ID = 23523
- Start time: 51545.12
- Pointing pos: RA 83.63 deg / Dec 21.51 deg
- Observation duration: 1687.0 s
- Dead-time fraction: 6.240 %
Info for OBS_ID = 23526
- Start time: 51545.12
- Pointing pos: RA 83.63 deg / Dec 22.51 deg
- Observation duration: 1683.0 s
- Dead-time fraction: 6.555 %
<gammapy.background.reflected.ReflectedRegionsFinder object at 0x1c4d94d630> [gammapy.background.reflected]
INFO Processing observation Info for OBS_ID = 23523
- Start time: 51545.12
- Pointing pos: RA 83.63 deg / Dec 21.51 deg
- Observation duration: 1687.0 s
- Dead-time fraction: 6.240 %
[gammapy.background.reflected]
INFO Found 12 reflected regions [gammapy.background.reflected]
INFO Processing observation Info for OBS_ID = 23526
- Start time: 51545.12
- Pointing pos: RA 83.63 deg / Dec 22.51 deg
- Observation duration: 1683.0 s
- Dead-time fraction: 6.555 %
[gammapy.background.reflected]
INFO Found 12 reflected regions [gammapy.background.reflected]
INFO Running <gammapy.spectrum.extract.SpectrumExtraction object at 0x1c554d8b38> [gammapy.spectrum.extract]
INFO Process observation
Info for OBS_ID = 23523
- Start time: 51545.12
- Pointing pos: RA 83.63 deg / Dec 21.51 deg
- Observation duration: 1687.0 s
- Dead-time fraction: 6.240 %
[gammapy.spectrum.extract]
INFO Update observation meta info [gammapy.spectrum.extract]
INFO Offset : 0.49556530655298986 deg
[gammapy.spectrum.extract]
INFO Fill events [gammapy.spectrum.extract]
INFO Extract IRFs [gammapy.spectrum.extract]
INFO Process observation
Info for OBS_ID = 23526
- Start time: 51545.12
- Pointing pos: RA 83.63 deg / Dec 22.51 deg
- Observation duration: 1683.0 s
- Dead-time fraction: 6.555 %
[gammapy.spectrum.extract]
INFO Update observation meta info [gammapy.spectrum.extract]
INFO Offset : 0.5044537720592762 deg
[gammapy.spectrum.extract]
INFO Fill events [gammapy.spectrum.extract]
INFO Extract IRFs [gammapy.spectrum.extract]
INFO Writing OGIP files to /private/var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/pytest-of-deil/pytest-42/test_spectrum_analysis_iact0/ogip_data [gammapy.spectrum.extract]
INFO Running SpectrumFit
Source model PowerLaw
Parameters:
name value error unit min max frozen
--------- --------- ----- --------------- --- --- ------
index 2.000e+00 nan nan nan False
amplitude 1.000e-11 nan 1 / (cm2 s TeV) nan nan False
reference 1.000e+00 nan TeV nan nan True
Stat wstat
Forward Folded True
Fit range None
Backend sherpa
Error Backend sherpa [gammapy.spectrum.fit]
INFO Writing /private/var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/pytest-of-deil/pytest-42/test_spectrum_analysis_iact0/fit_result_PowerLaw.yaml [gammapy.spectrum.fit]
============================= 3 failed, 1103 passed, 32 skipped, 38 xfailed, 13 xpassed in 383.48 seconds =============================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment