Skip to content

Commit e8d0937

Browse files
Adding getdist args (#5)
* Adding getdist args * Updated travis * Travis still failing * Removing broken image_comparison for now * Added as kwargs * Back to 100% coverage by resetting cache * Bumped version number now tests are passing
1 parent a167906 commit e8d0937

File tree

6 files changed

+66
-62
lines changed

6 files changed

+66
-62
lines changed

.travis.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
language: python
22
python:
33
- "2.7"
4-
- "3.4"
5-
- "3.5"
64
- "3.6"
5+
- "3.7"
6+
- "3.8"
77
env:
88
- REQUIREMENTS=minimal_requirements.txt
99
- REQUIREMENTS=requirements.txt
1010
install:
1111
- pip install -r $REQUIREMENTS
12-
- pip install pytest pytest-cov codecov
12+
- pip install --upgrade pytest
13+
- pip install pytest-cov codecov
1314
before_script:
1415
- "export MPLBACKEND=Agg"
1516
script:
16-
- pytest --cov=fgivenx
17+
- python -m pytest --cov=fgivenx
1718
after_success:
1819
- codecov
20+
- bash <(curl -s https://codecov.io/bash)

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ fgivenx: Functional Posterior Plotter
33
=====================================
44
:fgivenx: Functional Posterior Plotter
55
:Author: Will Handley
6-
:Version: 2.2.0
6+
:Version: 2.2.1
77
:Homepage: https://github.com/williamjameshandley/fgivenx
88
:Documentation: http://fgivenx.readthedocs.io/
99

fgivenx/samples.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def compute_samples(f, x, samples, **kwargs):
6060
return fsamples
6161

6262

63-
def samples_from_getdist_chains(params, file_root, latex=False):
63+
def samples_from_getdist_chains(params, file_root, latex=False, **kwargs):
6464
""" Extract samples and weights from getdist chains.
6565
6666
Parameters
@@ -78,6 +78,11 @@ def samples_from_getdist_chains(params, file_root, latex=False):
7878
latex: bool, optional
7979
Also return an array of latex strings for those paramnames.
8080
81+
Any additional keyword arguments are forwarded onto getdist, e.g:
82+
83+
samples_from_getdist_chains(params, file_root,
84+
settings={'ignore_rows':0.5})
85+
8186
Returns
8287
-------
8388
samples: numpy.array
@@ -92,7 +97,7 @@ def samples_from_getdist_chains(params, file_root, latex=False):
9297
"""
9398

9499
import getdist
95-
samples = getdist.loadMCSamples(file_root)
100+
samples = getdist.loadMCSamples(file_root, **kwargs)
96101
weights = samples.weights
97102

98103
indices = [samples.index[p] for p in params]

fgivenx/test/test_drivers.py

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import matplotlib.pyplot as plt
44
from fgivenx import plot_contours, plot_lines, plot_dkl
55
from fgivenx.drivers import compute_samples, compute_pmf, compute_dkl
6-
from matplotlib.testing.decorators import image_comparison
76

87

98
def test_full():
@@ -63,7 +62,6 @@ def f(x, theta):
6362
cache=cache, prior_cache=prior_cache)
6463

6564

66-
@image_comparison(baseline_images=['fgivenx'], extensions=['pdf'])
6765
def test_plotting():
6866
# Model definitions
6967
# =================
@@ -91,47 +89,50 @@ def f(x, theta):
9189
x = numpy.linspace(xmin, xmax, nx)
9290

9391
# Set the cache
94-
cache = 'cache/test'
95-
prior_cache = cache + '_prior'
96-
97-
# Plotting
98-
# ========
99-
fig, axes = plt.subplots(2, 2)
100-
101-
# Sample plot
102-
# -----------
103-
ax_samples = axes[0, 0]
104-
ax_samples.set_ylabel(r'$c$')
105-
ax_samples.set_xlabel(r'$m$')
106-
ax_samples.plot(prior_samples.T[0], prior_samples.T[1], 'b.')
107-
ax_samples.plot(samples.T[0], samples.T[1], 'r.')
108-
109-
# Line plot
110-
# ---------
111-
ax_lines = axes[0, 1]
112-
ax_lines.set_ylabel(r'$y = m x + c$')
113-
ax_lines.set_xlabel(r'$x$')
114-
plot_lines(f, x, prior_samples, ax_lines, color='b', cache=prior_cache)
115-
plot_lines(f, x, samples, ax_lines, color='r', cache=cache)
116-
117-
# Predictive posterior plot
118-
# -------------------------
119-
ax_fgivenx = axes[1, 1]
120-
ax_fgivenx.set_ylabel(r'$P(y|x)$')
121-
ax_fgivenx.set_xlabel(r'$x$')
122-
plot_contours(f, x, prior_samples, ax_fgivenx,
123-
colors=plt.cm.Blues_r, lines=False,
124-
cache=prior_cache)
125-
plot_contours(f, x, samples, ax_fgivenx, cache=cache)
126-
127-
# DKL plot
128-
# --------
129-
ax_dkl = axes[1, 0]
130-
ax_dkl.set_ylabel(r'$D_\mathrm{KL}$')
131-
ax_dkl.set_xlabel(r'$x$')
132-
ax_dkl.set_ylim(bottom=0)
133-
plot_dkl(f, x, samples, prior_samples, ax_dkl,
134-
cache=cache, prior_cache=prior_cache)
135-
136-
ax_lines.get_shared_x_axes().join(ax_lines, ax_fgivenx, ax_samples)
137-
fig.set_size_inches(6, 6)
92+
for cache in [None, 'cache/test']:
93+
if cache is not None:
94+
prior_cache = cache + '_prior'
95+
else:
96+
prior_cache = None
97+
98+
# Plotting
99+
# ========
100+
fig, axes = plt.subplots(2, 2)
101+
102+
# Sample plot
103+
# -----------
104+
ax_samples = axes[0, 0]
105+
ax_samples.set_ylabel(r'$c$')
106+
ax_samples.set_xlabel(r'$m$')
107+
ax_samples.plot(prior_samples.T[0], prior_samples.T[1], 'b.')
108+
ax_samples.plot(samples.T[0], samples.T[1], 'r.')
109+
110+
# Line plot
111+
# ---------
112+
ax_lines = axes[0, 1]
113+
ax_lines.set_ylabel(r'$y = m x + c$')
114+
ax_lines.set_xlabel(r'$x$')
115+
plot_lines(f, x, prior_samples, ax_lines, color='b', cache=prior_cache)
116+
plot_lines(f, x, samples, ax_lines, color='r', cache=cache)
117+
118+
# Predictive posterior plot
119+
# -------------------------
120+
ax_fgivenx = axes[1, 1]
121+
ax_fgivenx.set_ylabel(r'$P(y|x)$')
122+
ax_fgivenx.set_xlabel(r'$x$')
123+
plot_contours(f, x, prior_samples, ax_fgivenx,
124+
colors=plt.cm.Blues_r, lines=False,
125+
cache=prior_cache)
126+
plot_contours(f, x, samples, ax_fgivenx, cache=cache)
127+
128+
# DKL plot
129+
# --------
130+
ax_dkl = axes[1, 0]
131+
ax_dkl.set_ylabel(r'$D_\mathrm{KL}$')
132+
ax_dkl.set_xlabel(r'$x$')
133+
ax_dkl.set_ylim(bottom=0)
134+
plot_dkl(f, x, samples, prior_samples, ax_dkl,
135+
cache=cache, prior_cache=prior_cache)
136+
137+
ax_lines.get_shared_x_axes().join(ax_lines, ax_fgivenx, ax_samples)
138+
fig.set_size_inches(6, 6)

fgivenx/test/test_plot.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from fgivenx.plot import plot, plot_lines
44
import matplotlib.pyplot as plt
55
import matplotlib
6-
from matplotlib.testing.decorators import image_comparison
76

87

98
def gen_plot_data():
@@ -17,7 +16,6 @@ def gen_plot_data():
1716
return x, y, z
1817

1918

20-
@image_comparison(baseline_images=['plot'], extensions=['pdf'])
2119
def test_plot():
2220
x, y, z = gen_plot_data()
2321

@@ -32,28 +30,24 @@ def test_plot_wrong_argument():
3230
plot(x, y, z, wrong_argument=None)
3331

3432

35-
@image_comparison(baseline_images=['plot_no_ax'], extensions=['pdf'])
3633
def test_plot_no_ax():
3734
plt.subplots()
3835
x, y, z = gen_plot_data()
3936
plot(x, y, z)
4037

4138

42-
@image_comparison(baseline_images=['plot_smooth'], extensions=['pdf'])
4339
def test_plot_smooth():
4440
plt.subplots()
4541
x, y, z = gen_plot_data()
4642
plot(x, y, z, smooth=1)
4743

4844

49-
@image_comparison(baseline_images=['plot_rasterize'], extensions=['pdf'])
5045
def test_plot_rasterize():
5146
plt.subplots()
5247
x, y, z = gen_plot_data()
5348
plot(x, y, z, rasterize_contours=True)
5449

5550

56-
@image_comparison(baseline_images=['plot_nolines'], extensions=['pdf'])
5751
def test_plot_nolines():
5852
plt.subplots()
5953
x, y, z = gen_plot_data()
@@ -71,21 +65,18 @@ def gen_line_data():
7165
return x, fsamps
7266

7367

74-
@image_comparison(baseline_images=['plot_lines'], extensions=['pdf'])
7568
def test_plot_lines():
7669
x, fsamps = gen_line_data()
7770
fig, ax = plt.subplots()
7871
plot_lines(x, fsamps, ax)
7972

8073

81-
@image_comparison(baseline_images=['plot_lines_no_ax'], extensions=['pdf'])
8274
def test_plot_lines_no_ax():
8375
x, fsamps = gen_line_data()
8476
plt.subplots()
8577
plot_lines(x, fsamps)
8678

8779

88-
@image_comparison(baseline_images=['plot_lines_downsample'], extensions=['pdf'])
8980
def test_plot_lines_downsample():
9081
x, fsamps = gen_line_data()
9182
plt.subplots()

fgivenx/test/test_samples.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ def test_samples_from_getdist_chains():
3434
assert_allclose(weights, weights_)
3535
assert_array_equal(latex, numpy.array(labels)[i])
3636

37+
settings = {'ignore_rows': 0.5}
38+
samples1, weights = samples_from_getdist_chains(params, file_root,
39+
settings=settings)
40+
assert len(samples1) < len(samples)
41+
3742
rmtree('./.chains')
3843

3944
except ImportError:

0 commit comments

Comments
 (0)