Skip to content

Commit

Permalink
Merge pull request #177 from renecotyfanboy/v0.1.0
Browse files Browse the repository at this point in the history
V0.1.0
  • Loading branch information
renecotyfanboy authored Aug 16, 2024
2 parents a2daa71 + 7e0dd25 commit 9d04566
Show file tree
Hide file tree
Showing 27 changed files with 579 additions and 107,208 deletions.
12 changes: 6 additions & 6 deletions docs/examples/background.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ approach is equivalent to subtract the background to the observed spectrum when
``` python
from jaxspec.model.background import SubtractedBackground

forward = NUTSFitter(model, obs, background_model=SubtractedBackground())
result = forward.fit(prior, num_chains=4, num_warmup=1000, num_samples=1000, mcmc_kwargs={"progress_bar": True})
fitter = NUTSFitter(model, prior, obs, background_model=SubtractedBackground())
result = fitter.fit(num_chains=4, num_warmup=1000, num_samples=1000, mcmc_kwargs={"progress_bar": True})

result.plot_ppc()
```
Expand All @@ -28,8 +28,8 @@ it is to consider each background bin as a Poisson realisation of a counting pro
``` python
from jaxspec.model.background import BackgroundWithError

forward = NUTSFitter(model, obs, background_model=BackgroundWithError())
result = forward.fit(prior, num_chains=4, num_warmup=1000, num_samples=1000, mcmc_kwargs={"progress_bar": True})
fitter = NUTSFitter(model, prior, obs, background_model=BackgroundWithError())
result = fitter.fit(num_chains=4, num_warmup=1000, num_samples=1000, mcmc_kwargs={"progress_bar": True})

result.plot_ppc()
```
Expand All @@ -43,8 +43,8 @@ nodes will drive the flexibility of the Gaussian process, and it should always b
``` python
from jaxspec.model.background import GaussianProcessBackground

forward = NUTSFitter(model, obs, background_model=GaussianProcessBackground(e_min=0.3, e_max=8, n_nodes=20))
result = forward.fit(prior, num_chains=4, num_warmup=1000, num_samples=1000, mcmc_kwargs={"progress_bar": True})
forward = NUTSFitter(model, prior, obs, background_model=GaussianProcessBackground(e_min=0.3, e_max=8, n_nodes=20))
result = forward.fit(num_chains=4, num_warmup=1000, num_samples=1000, mcmc_kwargs={"progress_bar": True})

result.plot_ppc()
```
Expand Down
310 changes: 310 additions & 0 deletions docs/examples/external_samplers.ipynb

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions docs/examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,11 @@

Add a custom model to `jaxspec`

- [__Interface with other frameworks__](external_samplers.ipynb)

---

Use `jaxspec` likelihood in other packages


</div>
Binary file modified docs/examples/statics/background_gp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/examples/statics/subtract_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/examples/statics/subtract_background_with_errors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ nav:
- Add a background : examples/background.md
- Work with arviz : examples/result_analysis.ipynb
- Build a custom model : examples/build_custom_model.ipynb
- Interface with other frameworks : examples/external_samplers.ipynb
#- Models:
# - models/index.md
# - APEC: models/apec.md
Expand Down
13 changes: 10 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
[tool.poetry]
name = "jaxspec"
version = "0.0.8"
version = "0.1.0"
description = "jaxspec is a bayesian spectral fitting library for X-ray astronomy."
authors = ["sdupourque <sdupourque@irap.omp.eu>"]
license = "MIT"
readme = "README.md"
homepage = "https://github.com/renecotyfanboy/jaxspec"
documentation = "https://jaxspec.readthedocs.io/en/latest/"


[tool.poetry.dependencies]
python = ">=3.10,<3.12"
Expand All @@ -13,12 +16,12 @@ jaxlib = "^0.4.30"
numpy = "<2.0.0"
pandas = "^2.2.0"
astropy = "^6.0.0"
numpyro = "^0.15.0"
numpyro = "^0.15.2"
dm-haiku = ">=0.0.11,<0.0.13"
networkx = "^3.1"
matplotlib = "^3.8.0"
arviz = ">=0.17.1,<0.20.0"
chainconsumer = "^1.0.0"
chainconsumer = "^1.1.2"
simpleeval = "^0.9.13"
cmasher = "^1.6.3"
gpjax = "^0.8.0"
Expand All @@ -34,6 +37,7 @@ pyzmq = "<27"
jaxns = "^2.5.1"
pooch = "^1.8.2"
interpax = "^0.3.3"
watermark = "^2.4.3"


[tool.poetry.group.docs.dependencies]
Expand Down Expand Up @@ -112,3 +116,6 @@ lines-between-types = 1
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.scripts]
jaxspec-debug-info = "jaxspec.scripts.debug:debug_info"
28 changes: 28 additions & 0 deletions src/jaxspec/analysis/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,17 @@ def plot_ppc(
y_observed_bkg = (
obsconf.folded_background.data * u.photon / (denominator * ratio)
).to(y_units)
y_observed_bkg_low = (
nbinom.ppf(percentile[0] / 100, obsconf.folded_background.data, 0.5)
* u.photon
/ (denominator * ratio)
).to(y_units)
y_observed_bkg_high = (
nbinom.ppf(percentile[1] / 100, obsconf.folded_background.data, 0.5)
* u.photon
/ (denominator * ratio)
).to(y_units)

legend_plots += _plot_binned_samples_with_error(
ax[0],
xbins.value,
Expand All @@ -626,6 +637,23 @@ def plot_ppc(

legend_labels.append("Model (bkg)")

true_bkg_plot = ax[0].errorbar(
np.sqrt(xbins.value[0] * xbins.value[1]),
y_observed_bkg.value,
xerr=np.abs(xbins.value - np.sqrt(xbins.value[0] * xbins.value[1])),
yerr=[
y_observed_bkg.value - y_observed_bkg_low.value,
y_observed_bkg_high.value - y_observed_bkg.value,
],
color="black",
linestyle="none",
alpha=0.3,
capsize=2,
)

legend_plots.append((true_bkg_plot,))
legend_labels.append("Observed (bkg)")

residual_samples = (obsconf.folded_counts.data - count) / np.diff(
np.percentile(count, percentile, axis=0), axis=0
)
Expand Down
Binary file removed src/jaxspec/data/example_data/MOS1.arf
Binary file not shown.
Loading

0 comments on commit 9d04566

Please sign in to comment.