Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error running xagnfitter.py: Hard limit on sigma for Sherpa Gaussian models #37

Closed
thatastroguy opened this issue May 17, 2022 · 2 comments

Comments

@thatastroguy
Copy link

I am running BXA 4.0.5, UltraNest 3.4.4, Python 3.8.13, Sherpa 4.14.0, on MacOS High Sierra 10.13.6.

I just installed BXA over the weekend and was trying out the xagnfitter.py script, but ran into an error early in the process. After setting up the environment as well as the input files (filenames.txt, the galNH and redshift files), and linking the model directory, I ran the script as directed using 'python xagnfitter.py'. The code crashed somewhere around the 'except' statement on line 262 of the script. Below I've included a partial log of the terminal output and the traceback.

Increasing parameters again...
3 parameters, aic=297.37
4 parameters, aic=297.45
5 parameters, aic=296.76
Final choice: 2 parameters, aic=295.52

Adding Gaussian#1
largest remaining discrepancy at 8.660keV[99], need 447 counts
placing gaussian at 8.66keV, with power 0.01026600881157122
Traceback (most recent call last):
  File "xagnfitter.py", line 259, in <module>
    bkg_model = CachedModel(get_bkg_model(id))
  File "<string>", line 1, in get_bkg_model
  File "/anaconda3/envs/ciao-4.14/lib/python3.8/site-packages/sherpa/astro/ui/utils.py", line 9374, in get_bkg_model
    raise ModelErr('nobkg', bkg_id, id)
sherpa.utils.err.ModelErr: background model 1 for data set 1 has not been set

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "xagnfitter.py", line 265, in <module>
    bkg_model = auto_background(id)
  File "/anaconda3/envs/ciao-4.14/lib/python3.8/site-packages/bxa/sherpa/background/pca.py", line 416, in auto_background
    bkgmodel.fit()
  File "/anaconda3/envs/ciao-4.14/lib/python3.8/site-packages/bxa/sherpa/background/pca.py", line 385, in fit
    g.Sigma.max = x[-1] - x[0]
  File "/anaconda3/envs/ciao-4.14/lib/python3.8/site-packages/sherpa/utils/__init__.py", line 171, in __setattr__
    object.__setattr__(self, name, val)
  File "/anaconda3/envs/ciao-4.14/lib/python3.8/site-packages/sherpa/models/parameter.py", line 230, in _set_limit
    raise ParameterErr('edge', self.fullname,
sherpa.utils.err.ParameterErr: parameter g_1_99.Sigma has a hard maximum of 20

I spoke to Peter Boorman about this, and he ran into the same issue described above with a separate set of data and bxa installation when diagnosing this issue. He discovered a workaround in the pca.py file (/anaconda3/envs/ciao-4.14/lib/python3.8/site-packages/bxa/sherpa/background/pca.py). Changing in pca.py the line:

g.Sigma.max = x[-1] - x[0]

to:

if x[-1] - x[0] >= 20.:
	g.Sigma.max = 20.
else:
	g.Sigma.max = x[-1] - x[0]

seems to work for both of us and bypasses what appears to be a hard limit for the sigma maximum for the Gaussian model in Sherpa. After implementing the workaround, the xagnfitter.py script executes properly and produces the desired plots.

@JohannesBuchner
Copy link
Owner

Hmm, interesting.

x[-1] - x[0] is the difference between highest and lowest channel. That's the maximum width I wanted to allow. 20 channels may be narrow or wide, depending on the detector.

I think a more generic solution would be to set just above that line

g.Sigma.hard_max = 1e10

Could you test if that also solves the issue?

@JohannesBuchner
Copy link
Owner

Please test whether this is resolved with the latest release. If not, please reopen the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants