diff --git a/.travis.yml b/.travis.yml index 1d62506..7631b5a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,20 @@ language: python python: - "2.7" - - "3.4" - - "3.5" - "3.6" + - "3.7" + - "3.8" env: - REQUIREMENTS=minimal_requirements.txt - REQUIREMENTS=requirements.txt install: - pip install -r $REQUIREMENTS - - pip install pytest pytest-cov codecov + - pip install --upgrade pytest + - pip install pytest-cov codecov before_script: - "export MPLBACKEND=Agg" script: - - pytest --cov=fgivenx + - python -m pytest --cov=fgivenx after_success: - codecov + - bash <(curl -s https://codecov.io/bash) diff --git a/README.rst b/README.rst index c968134..b95ef39 100644 --- a/README.rst +++ b/README.rst @@ -3,7 +3,7 @@ fgivenx: Functional Posterior Plotter ===================================== :fgivenx: Functional Posterior Plotter :Author: Will Handley -:Version: 2.2.0 +:Version: 2.2.1 :Homepage: https://github.com/williamjameshandley/fgivenx :Documentation: http://fgivenx.readthedocs.io/ diff --git a/fgivenx/samples.py b/fgivenx/samples.py index 5ec0784..345daad 100644 --- a/fgivenx/samples.py +++ b/fgivenx/samples.py @@ -60,7 +60,7 @@ def compute_samples(f, x, samples, **kwargs): return fsamples -def samples_from_getdist_chains(params, file_root, latex=False): +def samples_from_getdist_chains(params, file_root, latex=False, **kwargs): """ Extract samples and weights from getdist chains. Parameters @@ -78,6 +78,11 @@ def samples_from_getdist_chains(params, file_root, latex=False): latex: bool, optional Also return an array of latex strings for those paramnames. + Any additional keyword arguments are forwarded onto getdist, e.g: + + samples_from_getdist_chains(params, file_root, + settings={'ignore_rows':0.5}) + Returns ------- samples: numpy.array @@ -92,7 +97,7 @@ def samples_from_getdist_chains(params, file_root, latex=False): """ import getdist - samples = getdist.loadMCSamples(file_root) + samples = getdist.loadMCSamples(file_root, **kwargs) weights = samples.weights indices = [samples.index[p] for p in params] diff --git a/fgivenx/test/test_drivers.py b/fgivenx/test/test_drivers.py index 3242407..2845078 100644 --- a/fgivenx/test/test_drivers.py +++ b/fgivenx/test/test_drivers.py @@ -3,7 +3,6 @@ import matplotlib.pyplot as plt from fgivenx import plot_contours, plot_lines, plot_dkl from fgivenx.drivers import compute_samples, compute_pmf, compute_dkl -from matplotlib.testing.decorators import image_comparison def test_full(): @@ -63,7 +62,6 @@ def f(x, theta): cache=cache, prior_cache=prior_cache) -@image_comparison(baseline_images=['fgivenx'], extensions=['pdf']) def test_plotting(): # Model definitions # ================= @@ -91,47 +89,50 @@ def f(x, theta): x = numpy.linspace(xmin, xmax, nx) # Set the cache - cache = 'cache/test' - prior_cache = cache + '_prior' - - # Plotting - # ======== - fig, axes = plt.subplots(2, 2) - - # Sample plot - # ----------- - ax_samples = axes[0, 0] - ax_samples.set_ylabel(r'$c$') - ax_samples.set_xlabel(r'$m$') - ax_samples.plot(prior_samples.T[0], prior_samples.T[1], 'b.') - ax_samples.plot(samples.T[0], samples.T[1], 'r.') - - # Line plot - # --------- - ax_lines = axes[0, 1] - ax_lines.set_ylabel(r'$y = m x + c$') - ax_lines.set_xlabel(r'$x$') - plot_lines(f, x, prior_samples, ax_lines, color='b', cache=prior_cache) - plot_lines(f, x, samples, ax_lines, color='r', cache=cache) - - # Predictive posterior plot - # ------------------------- - ax_fgivenx = axes[1, 1] - ax_fgivenx.set_ylabel(r'$P(y|x)$') - ax_fgivenx.set_xlabel(r'$x$') - plot_contours(f, x, prior_samples, ax_fgivenx, - colors=plt.cm.Blues_r, lines=False, - cache=prior_cache) - plot_contours(f, x, samples, ax_fgivenx, cache=cache) - - # DKL plot - # -------- - ax_dkl = axes[1, 0] - ax_dkl.set_ylabel(r'$D_\mathrm{KL}$') - ax_dkl.set_xlabel(r'$x$') - ax_dkl.set_ylim(bottom=0) - plot_dkl(f, x, samples, prior_samples, ax_dkl, - cache=cache, prior_cache=prior_cache) - - ax_lines.get_shared_x_axes().join(ax_lines, ax_fgivenx, ax_samples) - fig.set_size_inches(6, 6) + for cache in [None, 'cache/test']: + if cache is not None: + prior_cache = cache + '_prior' + else: + prior_cache = None + + # Plotting + # ======== + fig, axes = plt.subplots(2, 2) + + # Sample plot + # ----------- + ax_samples = axes[0, 0] + ax_samples.set_ylabel(r'$c$') + ax_samples.set_xlabel(r'$m$') + ax_samples.plot(prior_samples.T[0], prior_samples.T[1], 'b.') + ax_samples.plot(samples.T[0], samples.T[1], 'r.') + + # Line plot + # --------- + ax_lines = axes[0, 1] + ax_lines.set_ylabel(r'$y = m x + c$') + ax_lines.set_xlabel(r'$x$') + plot_lines(f, x, prior_samples, ax_lines, color='b', cache=prior_cache) + plot_lines(f, x, samples, ax_lines, color='r', cache=cache) + + # Predictive posterior plot + # ------------------------- + ax_fgivenx = axes[1, 1] + ax_fgivenx.set_ylabel(r'$P(y|x)$') + ax_fgivenx.set_xlabel(r'$x$') + plot_contours(f, x, prior_samples, ax_fgivenx, + colors=plt.cm.Blues_r, lines=False, + cache=prior_cache) + plot_contours(f, x, samples, ax_fgivenx, cache=cache) + + # DKL plot + # -------- + ax_dkl = axes[1, 0] + ax_dkl.set_ylabel(r'$D_\mathrm{KL}$') + ax_dkl.set_xlabel(r'$x$') + ax_dkl.set_ylim(bottom=0) + plot_dkl(f, x, samples, prior_samples, ax_dkl, + cache=cache, prior_cache=prior_cache) + + ax_lines.get_shared_x_axes().join(ax_lines, ax_fgivenx, ax_samples) + fig.set_size_inches(6, 6) diff --git a/fgivenx/test/test_plot.py b/fgivenx/test/test_plot.py index 878e4b6..a7d3762 100644 --- a/fgivenx/test/test_plot.py +++ b/fgivenx/test/test_plot.py @@ -3,7 +3,6 @@ from fgivenx.plot import plot, plot_lines import matplotlib.pyplot as plt import matplotlib -from matplotlib.testing.decorators import image_comparison def gen_plot_data(): @@ -17,7 +16,6 @@ def gen_plot_data(): return x, y, z -@image_comparison(baseline_images=['plot'], extensions=['pdf']) def test_plot(): x, y, z = gen_plot_data() @@ -32,28 +30,24 @@ def test_plot_wrong_argument(): plot(x, y, z, wrong_argument=None) -@image_comparison(baseline_images=['plot_no_ax'], extensions=['pdf']) def test_plot_no_ax(): plt.subplots() x, y, z = gen_plot_data() plot(x, y, z) -@image_comparison(baseline_images=['plot_smooth'], extensions=['pdf']) def test_plot_smooth(): plt.subplots() x, y, z = gen_plot_data() plot(x, y, z, smooth=1) -@image_comparison(baseline_images=['plot_rasterize'], extensions=['pdf']) def test_plot_rasterize(): plt.subplots() x, y, z = gen_plot_data() plot(x, y, z, rasterize_contours=True) -@image_comparison(baseline_images=['plot_nolines'], extensions=['pdf']) def test_plot_nolines(): plt.subplots() x, y, z = gen_plot_data() @@ -71,21 +65,18 @@ def gen_line_data(): return x, fsamps -@image_comparison(baseline_images=['plot_lines'], extensions=['pdf']) def test_plot_lines(): x, fsamps = gen_line_data() fig, ax = plt.subplots() plot_lines(x, fsamps, ax) -@image_comparison(baseline_images=['plot_lines_no_ax'], extensions=['pdf']) def test_plot_lines_no_ax(): x, fsamps = gen_line_data() plt.subplots() plot_lines(x, fsamps) -@image_comparison(baseline_images=['plot_lines_downsample'], extensions=['pdf']) def test_plot_lines_downsample(): x, fsamps = gen_line_data() plt.subplots() diff --git a/fgivenx/test/test_samples.py b/fgivenx/test/test_samples.py index d08a7a4..0c97d95 100644 --- a/fgivenx/test/test_samples.py +++ b/fgivenx/test/test_samples.py @@ -34,6 +34,11 @@ def test_samples_from_getdist_chains(): assert_allclose(weights, weights_) assert_array_equal(latex, numpy.array(labels)[i]) + settings = {'ignore_rows': 0.5} + samples1, weights = samples_from_getdist_chains(params, file_root, + settings=settings) + assert len(samples1) < len(samples) + rmtree('./.chains') except ImportError: