Skip to content

Commit

Permalink
more tolerant testing for background
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesBuchner committed May 26, 2024
1 parent bac0c60 commit b1e857b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
1 change: 0 additions & 1 deletion bxa/sherpa/background/pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ def fit(self, max_lines=10):
imax = 2
g.Sigma = (x[imax + 1] - x[imax - 1])
g.Sigma.min = (x[imax + 1] - x[imax - 1])/3
g.Sigma.hard_max = 1e10
g.Sigma.max = x[-1] - x[0]
g.norm.min = power * 1e-6
g.norm.val = power
Expand Down
16 changes: 7 additions & 9 deletions examples/sherpa/test_auto_background.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def test_chandra_pcabkg():

filename = "chandra/179_pcabkg.json"
bkgmodel = auto_background(1, max_lines=0)
_test_pca_params(filename, bkgmodel)
# _save_pca_params(bkgmodel, filename)
_test_pca_params(filename, bkgmodel)

def test_chandra_detect_line():
_reset_sherpa()
Expand All @@ -35,8 +35,8 @@ def test_swift_pcabkg():

filename = "swift/interval0pc_pcabkg.json"
bkgmodel = auto_background(1, max_lines=0)
_test_pca_params(filename, bkgmodel)
# _save_pca_params(bkgmodel, filename)
_test_pca_params(filename, bkgmodel)

def test_swift_detect_line():
_reset_sherpa()
Expand All @@ -59,8 +59,8 @@ def test_xmmpn_pcabkg():

filename = "xmm/pn_pcabkg.json"
bkgmodel = auto_background(1, max_lines=0)
_test_pca_params(filename, bkgmodel)
# _save_pca_params(bkgmodel, filename)
_test_pca_params(filename, bkgmodel)

def test_xmmpn_detect_line():
_reset_sherpa()
Expand Down Expand Up @@ -88,8 +88,8 @@ def test_xmmmos_pcabkg():

filename = "xmm/mos_pcabkg.json"
bkgmodel = auto_background(1, max_lines=0)
_test_pca_params(filename, bkgmodel)
# _save_pca_params(bkgmodel, filename)
_test_pca_params(filename, bkgmodel)

def test_xmmmos_detect_line():
_reset_sherpa()
Expand Down Expand Up @@ -117,8 +117,8 @@ def test_nustar_pcabkg():

filename = "nustar/nu60360003002A01_pcabkg.json"
bkgmodel = auto_background(1, max_lines=0)
_test_pca_params(filename, bkgmodel)
# _save_pca_params(bkgmodel, filename)
_test_pca_params(filename, bkgmodel)

def test_nustar_detect_line():
_reset_sherpa()
Expand Down Expand Up @@ -205,9 +205,7 @@ def _save_pca_params(bkgmodel, filename):

def _load_pca_params(filename):
with open(filename, "r") as fp:
params = json.load(fp)

return params
return json.load(fp)


def _test_pca_params(filename, bkgmodel):
Expand All @@ -219,7 +217,7 @@ def _test_pca_params(filename, bkgmodel):

for p in bkgmodel.pars:
assert p.name in test_pca_params
assert np.isclose(p.val, test_pca_params[p.name])
assert np.isclose(p.val, test_pca_params[p.name], rtol=0.05, atol=0.02), (p.name, p.val, test_pca_params[p.name])


def _inject_count_excess(bkgdata):
Expand Down

0 comments on commit b1e857b

Please sign in to comment.