-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve draw tests, revert adding locator argument to draw_mncontour (#…
…681)
- Loading branch information
1 parent
204381b
commit 9877511
Showing
4 changed files
with
67 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,3 +47,5 @@ MANIFEST | |
htmlcov | ||
cover | ||
coverage.xml | ||
|
||
tests/fig/*.svg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,88 @@ | ||
import pytest | ||
from iminuit import Minuit | ||
from pathlib import Path | ||
import numpy as np | ||
|
||
|
||
mpl = pytest.importorskip("matplotlib") | ||
plt = pytest.importorskip("matplotlib.pyplot") | ||
mpl.use("Agg") | ||
|
||
|
||
def f1(x, y): | ||
return (1 - x) ** 2 + 100 * (y - 1) ** 2 | ||
|
||
|
||
def f2(par): | ||
return f1(par[0], par[1]) | ||
return (1 - x) ** 2 + np.exp((y - 1) ** 2) | ||
|
||
|
||
f1.errordef = 1 | ||
f2.errordef = 1 | ||
|
||
|
||
@pytest.fixture(params=("normal", "numpy")) | ||
def minuit(request): | ||
if request.param == "normal": | ||
m = Minuit(f1, x=0, y=0) | ||
else: | ||
m = Minuit(f2, (0, 0), name=("x", "y")) | ||
@pytest.fixture | ||
def minuit(): | ||
m = Minuit(f1, x=0, y=0) | ||
m.migrad() | ||
return m | ||
|
||
|
||
def test_profile(minuit): | ||
minuit.draw_profile("x") # plots with hesse errors | ||
@pytest.fixture | ||
def fig(request): | ||
fig = plt.figure() | ||
yield fig | ||
p = Path(__file__).parent / "fig" | ||
if not p.exists(): | ||
p.mkdir() | ||
fig.savefig(p / (request.node.name + ".svg")) | ||
del fig | ||
|
||
|
||
@pytest.mark.parametrize("arg", ("x", "y")) | ||
def test_profile_1(fig, minuit, arg): | ||
# plots with hesse errors | ||
minuit.draw_profile(arg) | ||
plt.ylim(0, 5) | ||
|
||
|
||
@pytest.mark.parametrize("arg", ("x", "y")) | ||
def test_profile_2(fig, minuit, arg): | ||
# plots with minos errors | ||
minuit.minos() | ||
minuit.draw_profile("x") # plots with minos errors | ||
minuit.draw_profile(arg) | ||
plt.ylim(0, 5) | ||
|
||
|
||
def test_mnprofile(minuit): | ||
minuit.draw_mnprofile("x") # plots with hesse errors | ||
@pytest.mark.parametrize("arg", ("x", "y")) | ||
def test_mnprofile_1(fig, minuit, arg): | ||
# plots with hesse errors | ||
minuit.draw_mnprofile(arg) | ||
plt.ylim(0, 5) | ||
|
||
|
||
@pytest.mark.parametrize("arg", ("x", "y")) | ||
def test_mnprofile_2(fig, minuit, arg): | ||
# plots with minos errors | ||
minuit.minos() | ||
minuit.draw_mnprofile("x") # plots with minos errors | ||
minuit.draw_mnprofile(arg) | ||
plt.ylim(0, 5) | ||
|
||
|
||
def test_mncontour_1(minuit): | ||
def test_mncontour_1(fig, minuit): | ||
minuit.draw_mncontour("x", "y") | ||
|
||
|
||
def test_mncontour_2(minuit): | ||
def test_mncontour_2(fig, minuit): | ||
minuit.draw_mncontour("x", "y", cl=0.68) | ||
|
||
|
||
def test_mncontour_3(minuit): | ||
def test_mncontour_3(fig, minuit): | ||
minuit.draw_mncontour("x", "y", cl=[0.68, 0.9]) | ||
|
||
|
||
def test_drawcontour(minuit): | ||
def test_contour_1(fig, minuit): | ||
minuit.draw_contour("x", "y") | ||
minuit.draw_contour("x", "x", size=20, bound=2) | ||
minuit.draw_contour("x", "x", size=20, bound=((-10, 10), (-10, 10))) | ||
|
||
|
||
def test_contour_2(fig, minuit): | ||
minuit.draw_contour("x", "y", size=20, bound=2) | ||
|
||
|
||
def test_contour_3(fig, minuit): | ||
minuit.draw_contour("x", "y", size=100, bound=((-0.5, 2.5), (-1, 3))) |