Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
__________________________________________________________________________ TestFit.test_cash ___________________________________________________________________________
self = <gammapy.spectrum.tests.test_fit.TestFit object at 0x1c486af4e0>
def test_cash(self):
"""Simple CASH fit to the on vector"""
obs = SpectrumObservation(on_vector=self.src)
obs_list = SpectrumObservationList([obs])
fit = SpectrumFit(obs_list=obs_list, model=self.source_model,
stat='cash', forward_folded=False)
assert 'Spectrum' in str(fit)
fit.predict_counts()
assert_allclose(fit.predicted_counts[0][5], 660.5171280778071)
fit.calc_statval()
assert_allclose(np.sum(fit.statval[0]), -107346.5291329714)
self.source_model.parameters['index'].value = 1.12
fit.fit()
# These values are check with sherpa fits, do not change
assert_allclose(fit.result[0].model.parameters['index'].value,
> 1.996753564321903)
E AssertionError:
E Not equal to tolerance rtol=1e-07, atol=0
E
E (mismatch 100.0%)
E x: array(1.995525)
E y: array(1.996754)
gammapy/spectrum/tests/test_fit.py:77: AssertionError
------------------------------------------------------------------------- Captured stdout call -------------------------------------------------------------------------
**************************************************
* MIGRAD *
**************************************************
**********************************************************************
---------------------------------------------------------------------------------------
fval = -107347.13594992284 | total call = 90 | ncalls = 90
edm = 9.404623501271023e-06 (Goal: 1e-05) | up = 1.0
---------------------------------------------------------------------------------------
| Valid | Valid Param | Accurate Covar | Posdef | Made Posdef |
---------------------------------------------------------------------------------------
| True | True | True | True | False |
---------------------------------------------------------------------------------------
| Hesse Fail | Has Cov | Above EDM | | Reach calllim |
---------------------------------------------------------------------------------------
| False | True | False | '' | False |
---------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
| | Name | Value | Para Err | Err- | Err+ | Limit- | Limit+ | |
--------------------------------------------------------------------------------------------------
| 0 | index = 1.996 | 0.01128 | | | | | |
| 1 | amplitude = 1.002E+05 | 1476 | | | | | |
| 2 | reference = 0.1 | 1 | | | | 0 | FIXED |
--------------------------------------------------------------------------------------------------
**********************************************************************
__________________________________________________________________________ TestFit.test_wstat __________________________________________________________________________
self = <gammapy.spectrum.tests.test_fit.TestFit object at 0x1c487102b0>
def test_wstat(self):
"""WStat with on source and background spectrum"""
on_vector = self.src.copy()
on_vector.data.data += self.bkg.data.data
obs = SpectrumObservation(on_vector=on_vector, off_vector=self.off)
obs_list = SpectrumObservationList([obs])
self.source_model.parameters.index = 1.12 * u.Unit('')
fit = SpectrumFit(obs_list=obs_list, model=self.source_model,
stat='wstat', forward_folded=False)
fit.fit()
assert_allclose(fit.result[0].model.parameters['index'].value,
> 1.9973633924241248)
E AssertionError:
E Not equal to tolerance rtol=1e-07, atol=0
E
E (mismatch 100.0%)
E x: array(1.997342)
E y: array(1.997363)
gammapy/spectrum/tests/test_fit.py:94: AssertionError
------------------------------------------------------------------------- Captured stdout call -------------------------------------------------------------------------
**************************************************
* MIGRAD *
**************************************************
**********************************************************************
---------------------------------------------------------------------------------------
fval = 30.022315891879657 | total call = 33 | ncalls = 33
edm = 2.8005662737047593e-07 (Goal: 1e-05) | up = 1.0
---------------------------------------------------------------------------------------
| Valid | Valid Param | Accurate Covar | Posdef | Made Posdef |
---------------------------------------------------------------------------------------
| True | True | True | True | False |
---------------------------------------------------------------------------------------
| Hesse Fail | Has Cov | Above EDM | | Reach calllim |
---------------------------------------------------------------------------------------
| False | True | False | '' | False |
---------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
| | Name | Value | Para Err | Err- | Err+ | Limit- | Limit+ | |
--------------------------------------------------------------------------------------------------
| 0 | index = 1.997 | 0.01149 | | | | | |
| 1 | amplitude = 1.002E+05 | 1529 | | | | | |
| 2 | reference = 0.1 | 1 | | | | 0 | FIXED |
--------------------------------------------------------------------------------------------------
**********************************************************************
__________________________________________________________________________ TestFit.test_joint __________________________________________________________________________
self = <gammapy.spectrum.tests.test_fit.TestFit object at 0x1c48710240>
def test_joint(self):
"""Test joint fit for obs with different energy binning"""
obs1 = SpectrumObservation(on_vector=self.src)
src_rebinned = self.src.rebin(2)
obs2 = SpectrumObservation(on_vector=src_rebinned)
fit = SpectrumFit(obs_list=[obs1, obs2], stat='cash',
model=self.source_model, forward_folded=False)
fit.fit()
assert_allclose(fit.result[0].model.parameters['index'].value,
> 1.9977254068253105)
E AssertionError:
E Not equal to tolerance rtol=1e-07, atol=0
E
E (mismatch 100.0%)
E x: array(1.996456)
E y: array(1.997725)
gammapy/spectrum/tests/test_fit.py:109: AssertionError
------------------------------------------------------------------------- Captured stdout call -------------------------------------------------------------------------
**************************************************
* MIGRAD *
**************************************************
**********************************************************************
---------------------------------------------------------------------------------------
fval = -228482.05150400207 | total call = 39 | ncalls = 39
edm = 6.83404648216739e-06 (Goal: 1e-05) | up = 1.0
---------------------------------------------------------------------------------------
| Valid | Valid Param | Accurate Covar | Posdef | Made Posdef |
---------------------------------------------------------------------------------------
| True | True | True | True | False |
---------------------------------------------------------------------------------------
| Hesse Fail | Has Cov | Above EDM | | Reach calllim |
---------------------------------------------------------------------------------------
| False | True | False | '' | False |
---------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
| | Name | Value | Para Err | Err- | Err+ | Limit- | Limit+ | |
--------------------------------------------------------------------------------------------------
| 0 | index = 1.996 | 0.007998 | | | | | |
| 1 | amplitude = 1.003E+05 | 1045 | | | | | |
| 2 | reference = 0.1 | 1 | | | | 0 | FIXED |
--------------------------------------------------------------------------------------------------
**********************************************************************
____________________________________________________________________ TestSpectralFit.test_compound _____________________________________________________________________
self = <gammapy.spectrum.tests.test_fit.TestSpectralFit object at 0x1c487a4630>
def test_compound(self):
fit = SpectrumFit(self.obs_list[0], self.pwl * 2)
fit.fit()
result = fit.result[0]
pars = result.model.parameters
assert_quantity_allclose(pars['index'].value, 2.254163434607357)
# amplitude should come out roughly * 0.5
assert_quantity_allclose(pars['amplitude'].quantity,
> 1.0338057602337021e-07 * u.Unit('m-2 s-1 TeV-1'))
gammapy/spectrum/tests/test_fit.py:219:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
actual = <Quantity 1.0309631e-11 1 / (cm2 s TeV)>, desired = <Quantity 1.03380576e-07 1 / (m2 s TeV)>, rtol = 1e-07, atol = None, kwargs = {}
args = (1.0309630976762582e-11, 1.033805760233702e-11, 1e-07, 0.0)
def assert_quantity_allclose(actual, desired, rtol=1.e-7, atol=None, **kwargs):
# TODO: change this later to explicitly check units are the same!
# assert actual.unit == desired.unit
args = _unquantify_allclose_arguments(actual, desired, rtol, atol)
> assert_allclose(*args, **kwargs)
E AssertionError:
E Not equal to tolerance rtol=1e-07, atol=0
E
E (mismatch 100.0%)
E x: array(1.030963e-11)
E y: array(1.033806e-11)
gammapy/utils/testing.py:170: AssertionError
------------------------------------------------------------------------- Captured stdout call -------------------------------------------------------------------------
**************************************************
* MIGRAD *
**************************************************
**********************************************************************
---------------------------------------------------------------------------------------
fval = 32.83872103683574 | total call = 164 | ncalls = 164
edm = 4.447426676585369e-06 (Goal: 1e-05) | up = 1.0
---------------------------------------------------------------------------------------
| Valid | Valid Param | Accurate Covar | Posdef | Made Posdef |
---------------------------------------------------------------------------------------
| True | True | False | False | True |
---------------------------------------------------------------------------------------
| Hesse Fail | Has Cov | Above EDM | | Reach calllim |
---------------------------------------------------------------------------------------
| False | True | False | '' | False |
---------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
| | Name | Value | Para Err | Err- | Err+ | Limit- | Limit+ | |
--------------------------------------------------------------------------------------------------
| 0 | index = 2.254 | 0.09761 | | | | | |
| 1 | amplitude = 1.031E-11 | 1.282E-11 | | | | | |
| 2 | reference = 1 | 1 | | | | 0 | FIXED |
| 3 | const = 1.948 | 2.423 | | | | | |
--------------------------------------------------------------------------------------------------
**********************************************************************
------------------------------------------------------------------------- Captured stderr call -------------------------------------------------------------------------
/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/numpy/core/_methods.py:32: RuntimeWarning: overflow encountered in reduce
return umr_sum(a, axis, dtype, out, keepdims)
____________________________________________________________________ TestSpectralFit.test_ecpl_fit _____________________________________________________________________
self = <gammapy.spectrum.tests.test_fit.TestSpectralFit object at 0x1c487a4be0>
def test_ecpl_fit(self):
self.ecpl.parameters.set_parameter_errors(
{'amplitude' : 1e-11 * u.Unit('cm-2 s-1 TeV-1'),
'lambda' : 0.1 / u.TeV}
)
fit = SpectrumFit(self.obs_list[0], self.ecpl)
fit.fit()
actual = fit.result[0].model.parameters['lambda_'].quantity
> assert_quantity_allclose(actual, 0.0342866790304526 / u.TeV)
gammapy/spectrum/tests/test_fit.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
actual = <Quantity 0.03424147 1 / TeV>, desired = <Quantity 0.03428668 1 / TeV>, rtol = 1e-07, atol = None, kwargs = {}
args = (0.03424147318078291, 0.0342866790304526, 1e-07, 0.0)
def assert_quantity_allclose(actual, desired, rtol=1.e-7, atol=None, **kwargs):
# TODO: change this later to explicitly check units are the same!
# assert actual.unit == desired.unit
args = _unquantify_allclose_arguments(actual, desired, rtol, atol)
> assert_allclose(*args, **kwargs)
E AssertionError:
E Not equal to tolerance rtol=1e-07, atol=0
E
E (mismatch 100.0%)
E x: array(0.034241)
E y: array(0.034287)
gammapy/utils/testing.py:170: AssertionError
------------------------------------------------------------------------- Captured stdout call -------------------------------------------------------------------------
**************************************************
* MIGRAD *
**************************************************
**********************************************************************
---------------------------------------------------------------------------------------
fval = 31.53997315836555 | total call = 249 | ncalls = 249
edm = 2.7287882816091134e-06 (Goal: 1e-05) | up = 1.0
---------------------------------------------------------------------------------------
| Valid | Valid Param | Accurate Covar | Posdef | Made Posdef |
---------------------------------------------------------------------------------------
| True | True | True | True | False |
---------------------------------------------------------------------------------------
| Hesse Fail | Has Cov | Above EDM | | Reach calllim |
---------------------------------------------------------------------------------------
| False | True | False | '' | False |
---------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
| | Name | Value | Para Err | Err- | Err+ | Limit- | Limit+ | |
--------------------------------------------------------------------------------------------------
| 0 | index = 2.087 | 0.185 | | | | | |
| 1 | amplitude = 2.009E-11 | 2.276E-12 | | | | | |
| 2 | reference = 1 | 0 | | | | | FIXED |
| 3 | lambda_ = 0.03424 | 0.03478 | | | | | |
--------------------------------------------------------------------------------------------------
**********************************************************************
------------------------------------------------------------------------- Captured stderr call -------------------------------------------------------------------------
/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/numpy/core/_methods.py:32: RuntimeWarning: overflow encountered in reduce
return umr_sum(a, axis, dtype, out, keepdims)
____________________________________________________________________ TestSpectralFit.test_joint_fit ____________________________________________________________________
self = <gammapy.spectrum.tests.test_fit.TestSpectralFit object at 0x1c488106a0>
def test_joint_fit(self):
self.pwl.parameters.set_parameter_errors(
{'amplitude' : 1e-11 * u.Unit('cm-2 s-1 TeV-1')}
)
fit = SpectrumFit(self.obs_list, self.pwl)
fit.fit()
actual = fit.result[0].model.parameters['index'].quantity
> assert_quantity_allclose(actual, 2.212498637800248)
gammapy/spectrum/tests/test_fit.py:288:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
actual = <Quantity 2.21224974>, desired = 2.212498637800248, rtol = 1e-07, atol = None, kwargs = {}, args = (2.2122497363318097, 2.212498637800248, 1e-07, 0.0)
def assert_quantity_allclose(actual, desired, rtol=1.e-7, atol=None, **kwargs):
# TODO: change this later to explicitly check units are the same!
# assert actual.unit == desired.unit
args = _unquantify_allclose_arguments(actual, desired, rtol, atol)
> assert_allclose(*args, **kwargs)
E AssertionError:
E Not equal to tolerance rtol=1e-07, atol=0
E
E (mismatch 100.0%)
E x: array(2.21225)
E y: array(2.212499)
gammapy/utils/testing.py:170: AssertionError
------------------------------------------------------------------------- Captured stdout call -------------------------------------------------------------------------
**************************************************
* MIGRAD *
**************************************************
**********************************************************************
---------------------------------------------------------------------------------------
fval = 92.0094627161531 | total call = 111 | ncalls = 111
edm = 3.521148808839948e-06 (Goal: 1e-05) | up = 1.0
---------------------------------------------------------------------------------------
| Valid | Valid Param | Accurate Covar | Posdef | Made Posdef |
---------------------------------------------------------------------------------------
| True | True | True | True | False |
---------------------------------------------------------------------------------------
| Hesse Fail | Has Cov | Above EDM | | Reach calllim |
---------------------------------------------------------------------------------------
| False | True | False | '' | False |
---------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
| | Name | Value | Para Err | Err- | Err+ | Limit- | Limit+ | |
--------------------------------------------------------------------------------------------------
| 0 | index = 2.212 | 0.06392 | | | | | |
| 1 | amplitude = 2.362E-11 | 1.72E-12 | | | | | |
| 2 | reference = 1 | 0 | | | | 0 | FIXED |
--------------------------------------------------------------------------------------------------
**********************************************************************
___________________________________________________________________ TestSpectralFit.test_stacked_fit ___________________________________________________________________
self = <gammapy.spectrum.tests.test_fit.TestSpectralFit object at 0x1c48835eb8>
def test_stacked_fit(self):
stacked_obs = self.obs_list.stack()
obs_list = SpectrumObservationList([stacked_obs])
fit = SpectrumFit(obs_list, self.pwl)
fit.fit()
pars = fit.result[0].model.parameters
> assert_quantity_allclose(pars['index'].value, 2.2133885226771)
gammapy/spectrum/tests/test_fit.py:299:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
actual = 2.2132113269084566, desired = 2.2133885226771, rtol = 1e-07, atol = None, kwargs = {}, args = (2.2132113269084566, 2.2133885226771, 1e-07, 0.0)
def assert_quantity_allclose(actual, desired, rtol=1.e-7, atol=None, **kwargs):
# TODO: change this later to explicitly check units are the same!
# assert actual.unit == desired.unit
args = _unquantify_allclose_arguments(actual, desired, rtol, atol)
> assert_allclose(*args, **kwargs)
E AssertionError:
E Not equal to tolerance rtol=1e-07, atol=0
E
E (mismatch 100.0%)
E x: array(2.213211)
E y: array(2.213389)
gammapy/utils/testing.py:170: AssertionError
------------------------------------------------------------------------- Captured stdout call -------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.