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

Example bayesian workflow -- small fixes #56

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions examples/xspec/bayesian-workflow/plot_bxa.py
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,7 @@ def _plot_posterior_statistic(self,solvers,
# loop over the models and create a predictive plot for each
if type(axs) is not np.ndarray:
axs = (axs,)
self.posterior_flux_unc = [] # define for first use or clear for new use
for ii,s in enumerate(solvers):
# re-activate model and point solver to new instance
if models is not None:
Expand All @@ -1536,7 +1537,6 @@ def _plot_posterior_statistic(self,solvers,
else:
mname = None
if stat == 'flux':
self.posterior_flux_unc = [] # define for first use or clear for new use
# plot the flux distributions based on the posteriors
self._posterior_flux_single_model(axs[ii],s,
npost=nsample,
Expand Down Expand Up @@ -1595,7 +1595,7 @@ def _posterior_flux_single_model(self,ax,solver,
for row in solver.posterior[:npost]:
bxa.solver.set_parameters(values=row,transformations=solver.transformations)
xspec.AllModels.calcFlux(frange)
d += [xspec.AllData(1).flux[0]*1e12] # in units of 10^12 erg cm^-2 s^-1
d += [xspec.AllData(1).flux[0]*1e12] # in units of 10^-12 erg cm^-2 s^-1
# plot the data
c,b = np.histogram(d,bins=np.minimum(int(len(d)/10),20),
density=True)
Expand All @@ -1616,13 +1616,13 @@ def _posterior_flux_single_model(self,ax,solver,
mname = solver.transformations[1]['model'].expression
if printq:
print(f'For model {mname}:')
print(f'Mean={np.mean(d):.3f} (+){q_high:.3f} (-){q_low:.3f} (10^12 erg cm^-2 s^-1)')
print(f'Mean={np.mean(d):.3f} (+){q_high:.3f} (-){q_low:.3f} (10^-12 erg cm^-2 s^-1)')
print(f'With uncertainties estimated for +/- {q*100:.1f}%\n')
self.posterior_flux_unc += [[mname,fluxrange,np.mean(d),q_high,q_low]]
# plot details
lblkw = dict( (('fontsize',20),('fontweight','bold')) )
rngstr = f'Flux {fluxrange[0]:.1f}-{fluxrange[1]:.1f} keV'
unitstr = r' ($10^{12}$ erg cm$^{-2}$ s$^{-1}$)'
unitstr = r' ($10^{-12}$ erg cm$^{-2}$ s$^{-1}$)'
ax.set_xlabel(rngstr+unitstr,**lblkw)
ax.set_ylabel('Probability Density',**lblkw)
ax.set_ylim(yl)
Expand Down Expand Up @@ -2001,7 +2001,7 @@ def _plot_bayes_factor_test(self,
return
if mnames is None:
print('If loading existing data, please specify the model names')
return
return (None,None)
m1name,m2name = mnames
logz1, logz2 = [], []
fitd1, fitd2 = [], []
Expand Down
2 changes: 1 addition & 1 deletion examples/xspec/bayesian-workflow/plot_xspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def _get_xspec_data(self,model=True,plottype='folded',
maxBins=rebinbnum,
groupNum=-1)
else:
xspec.Plot.setRebin(minSig=0,maxBins=-1,groupNum=-1)
xspec.Plot.setRebin(minSig=0,maxBins=1,groupNum=-1)
if plottype == 'folded':
plttype = 'data'
elif plottype == 'counts':
Expand Down
Loading