From 5e89a4876b72f68e28044aa304d1b27f160e6ff4 Mon Sep 17 00:00:00 2001 From: David Homan Date: Sat, 11 May 2024 21:01:35 -0400 Subject: [PATCH 1/3] fix typo in the label of the flux-distribution plots. Fluxes are in units of 10**-12 ergs/cm**2/s. --- examples/xspec/bayesian-workflow/plot_bxa.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/xspec/bayesian-workflow/plot_bxa.py b/examples/xspec/bayesian-workflow/plot_bxa.py index 2ea398e..cd34919 100644 --- a/examples/xspec/bayesian-workflow/plot_bxa.py +++ b/examples/xspec/bayesian-workflow/plot_bxa.py @@ -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) @@ -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) From 985d57823feacdfb305872694546b492b27f2e93 Mon Sep 17 00:00:00 2001 From: David Homan Date: Sun, 12 May 2024 09:59:43 +0200 Subject: [PATCH 2/3] prevent type1 test convenience function from throwing an error, if no model names are specified. --- examples/xspec/bayesian-workflow/plot_bxa.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/xspec/bayesian-workflow/plot_bxa.py b/examples/xspec/bayesian-workflow/plot_bxa.py index cd34919..86782f8 100644 --- a/examples/xspec/bayesian-workflow/plot_bxa.py +++ b/examples/xspec/bayesian-workflow/plot_bxa.py @@ -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 = [], [] From 440ac9e7543b23fa159d3f4be476bdfd1b79ef8d Mon Sep 17 00:00:00 2001 From: David Homan Date: Tue, 14 May 2024 09:40:05 +0200 Subject: [PATCH 3/3] Bayesian workflow: prevent warning from XSpec about binning and ensure values are returned for all solvers when calculating the posterior distribution(s) of the flux. --- examples/xspec/bayesian-workflow/plot_bxa.py | 2 +- examples/xspec/bayesian-workflow/plot_xspec.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/xspec/bayesian-workflow/plot_bxa.py b/examples/xspec/bayesian-workflow/plot_bxa.py index 86782f8..44f3a0c 100644 --- a/examples/xspec/bayesian-workflow/plot_bxa.py +++ b/examples/xspec/bayesian-workflow/plot_bxa.py @@ -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: @@ -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, diff --git a/examples/xspec/bayesian-workflow/plot_xspec.py b/examples/xspec/bayesian-workflow/plot_xspec.py index abfd7d5..91422ec 100644 --- a/examples/xspec/bayesian-workflow/plot_xspec.py +++ b/examples/xspec/bayesian-workflow/plot_xspec.py @@ -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':