Skip to content

Commit

Permalink
Adding ArviZ support (#145)
Browse files Browse the repository at this point in the history
* adding arviz support

* import order

* actually install arviz version

* imports for dev arviz

* adding pre-commit config

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* updating dist build

* adding test for arviz plotting

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
dfm and pre-commit-ci[bot] committed Mar 7, 2021
1 parent 35be332 commit b224f0c
Show file tree
Hide file tree
Showing 12 changed files with 306 additions and 79 deletions.
29 changes: 15 additions & 14 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ on:

jobs:
tests:
name: "py${{ matrix.python-version }} on ${{ matrix.os }}"
runs-on: ${{ matrix.os }}
name: "py${{ matrix.python-version }}; ${{ matrix.arviz-version }}"
runs-on: "ubuntu-latest"
strategy:
matrix:
python-version: [3.7, 3.8]
os: [ubuntu-latest, macos-latest]
python-version: [3.9]
arviz-version:
- "arviz~=0.9"
- "arviz~=0.10"
- "arviz~=0.11"
- "https://github.com/arviz-devs/arviz/archive/main.zip"

steps:
- uses: actions/checkout@v2
Expand All @@ -27,14 +31,10 @@ jobs:
- name: Install dependencies
run: |
python -m pip install -U pip
python -m pip install $ARVIZ
python -m pip install ".[test]"
- name: Check the style
run: |
isort -c src/corner
isort -c tests
black --check src/corner
black --check tests
env:
ARVIZ: ${{ matrix.arviz-version }}

- name: Run the unit tests
run: python -m pytest -v tests
Expand All @@ -53,12 +53,13 @@ jobs:
- uses: actions/setup-python@v2
name: Install Python
with:
python-version: "3.8"
python-version: "3.9"

- name: Build
run: |
python -m pip install -U pip pep517 twine setuptools_scm
python -m pep517.build .
python -m pip install -U pip
python -m pip install -U build
python -m build .
- name: Test the sdist
run: |
Expand Down
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
exclude_types: [json, binary]
- repo: https://github.com/PyCQA/isort
rev: "5.7.0"
hooks:
- id: isort
additional_dependencies: [toml]
exclude: docs/tutorials
- repo: https://github.com/psf/black
rev: "20.8b1"
hooks:
- id: black
39 changes: 27 additions & 12 deletions demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,34 @@
ndim, nsamples = 3, 50000

# Generate some fake data.
data1 = np.random.randn(ndim * 4 * nsamples / 5).reshape([4 * nsamples / 5,
ndim])
data2 = (4 * np.random.rand(ndim)[None, :] +
np.random.randn(ndim * nsamples / 5).reshape([nsamples / 5, ndim]))
data1 = np.random.randn(ndim * 4 * nsamples / 5).reshape(
[4 * nsamples / 5, ndim]
)
data2 = 4 * np.random.rand(ndim)[None, :] + np.random.randn(
ndim * nsamples / 5
).reshape([nsamples / 5, ndim])
data = np.vstack([data1, data2])

# Plot it.
figure = corner.corner(data, labels=[r"$x$", r"$y$", r"$\log \alpha$",
r"$\Gamma \, [\mathrm{parsec}]$"],
quantiles=[0.16, 0.5, 0.84],
show_titles=True, title_kwargs={"fontsize": 12})
figure.gca().annotate("a demo corner plot",
xy=(1.0, 1.0), xycoords="figure fraction",
xytext=(-20, -10), textcoords="offset points",
ha="right", va="top")
figure = corner.corner(
data,
labels=[
r"$x$",
r"$y$",
r"$\log \alpha$",
r"$\Gamma \, [\mathrm{parsec}]$",
],
quantiles=[0.16, 0.5, 0.84],
show_titles=True,
title_kwargs={"fontsize": 12},
)
figure.gca().annotate(
"a demo corner plot",
xy=(1.0, 1.0),
xycoords="figure fraction",
xytext=(-20, -10),
textcoords="offset points",
ha="right",
va="top",
)
figure.savefig("demo.png", dpi=300)
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
if not on_rtd:
import sphinx_rtd_theme

html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

Expand Down
15 changes: 7 additions & 8 deletions docs/pages/custom.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ another randomly sampled mode:
import corner
import numpy as np
ndim, nsamples = 4, 50000
np.random.seed(1234)
data1 = np.random.randn(ndim * 4 * nsamples // 5).reshape([4 * nsamples // 5, ndim])
mean = 4*np.random.rand(ndim)
data2 = (mean[None, :] + np.random.randn(ndim * nsamples // 5).reshape([nsamples // 5, ndim]))
samples = np.vstack([data1, data2])
figure = corner.corner(samples)
Expand All @@ -47,22 +47,22 @@ of the second mode.
# This is the true mean of the second mode that we used above:
value1 = mean
# This is the empirical mean of the sample:
value2 = np.mean(samples, axis=0)
# Make the base corner plot
figure = corner.corner(samples)
# Extract the axes
axes = np.array(figure.axes).reshape((ndim, ndim))
# Loop over the diagonal
for i in range(ndim):
ax = axes[i, i]
ax.axvline(value1[i], color="g")
ax.axvline(value2[i], color="r")
# Loop over the histograms
for yi in range(ndim):
for xi in range(yi):
Expand All @@ -81,4 +81,3 @@ of the second mode.

A similar procedure could be used to add anything to the axes that you
can normally do with matplotlib.

7 changes: 3 additions & 4 deletions docs/pages/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ its simplest form, you use it like this:
import corner
import numpy as np
ndim, nsamples = 2, 10000
np.random.seed(42)
samples = np.random.randn(ndim * nsamples).reshape([nsamples, ndim])
Expand All @@ -34,13 +34,13 @@ The following snippet demonstrates a few more bells and whistles:
# Set up the parameters of the problem.
ndim, nsamples = 3, 50000
# Generate some fake data.
np.random.seed(42)
data1 = np.random.randn(ndim * 4 * nsamples // 5).reshape([4 * nsamples // 5, ndim])
data2 = (4*np.random.rand(ndim)[None, :] + np.random.randn(ndim * nsamples // 5).reshape([nsamples // 5, ndim]))
data = np.vstack([data1, data2])
# Plot it.
figure = corner.corner(data, labels=[r"$x$", r"$y$", r"$\log \alpha$", r"$\Gamma \, [\mathrm{parsec}]$"],
quantiles=[0.16, 0.5, 0.84],
Expand All @@ -53,4 +53,3 @@ The following snippet demonstrates a few more bells and whistles:

The `API documentation <../api.html>`__ gives more details about all the
arguments available for customization.

4 changes: 1 addition & 3 deletions docs/pages/sigmas.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ We can visualize the difference between sigma definitions:
import corner
import numpy as np
import matplotlib.pyplot as pl
# Generate some fake data from a Gaussian
np.random.seed(42)
x = np.random.randn(50000, 2)
Expand Down Expand Up @@ -67,5 +67,3 @@ contour compares to the marginalized 68% quantile:
.. image:: sigmas_files/sigmas_6_0.png


6 changes: 1 addition & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@
"Programming Language :: Python",
"Programming Language :: Python :: 3",
]
INSTALL_REQUIRES = [
"matplotlib>=2.1"
]
INSTALL_REQUIRES = ["arviz>=0.9"]
EXTRA_REQUIRE = {
"test": [
"pytest>=3.6",
"pytest-cov>=2.6.1",
"black",
"isort",
"toml",
"scipy",
"pandas",
],
"docs": ["sphinx>=1.7.5", "pandoc"],
}
Expand Down
2 changes: 1 addition & 1 deletion src/corner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
__uri__ = "https://corner.readthedocs.io"
__license__ = "BSD"
__description__ = "Make some beautiful corner plots"
__copyright__ = "Copyright 2013-2020 Daniel Foreman-Mackey"
__copyright__ = "Copyright 2013-2021 Daniel Foreman-Mackey"
__contributors__ = "https://github.com/dfm/corner.py/graphs/contributors"
__bibtex__ = __citation__ = """
@article{corner,
Expand Down

0 comments on commit b224f0c

Please sign in to comment.