예제 #1
0
파일: test_viz.py 프로젝트: scikit-hep/pyhf
def test_plot_results_no_axis(datadir):
    data = json.load(open(datadir.join("hypotest_results.json")))

    matplotlib.use("agg")  # Use non-gui backend
    fig, ax = plt.subplots()
    ax.set_yscale("log")  # Also test log y detection
    brazil.plot_results(data["testmus"], data["results"], test_size=0.05)

    return fig
예제 #2
0
파일: test_viz.py 프로젝트: scikit-hep/pyhf
def test_plot_results_components(datadir):
    data = json.load(open(datadir.join("tail_probs_hypotest_results.json")))

    fig = Figure()
    ax = fig.subplots()
    brazil.plot_results(data["testmus"],
                        data["results"],
                        test_size=0.05,
                        ax=ax,
                        components=True)
    return fig
예제 #3
0
파일: test_viz.py 프로젝트: scikit-hep/pyhf
def test_plot_results_components_data_structure(datadir):
    """
    test results should have format of: [CLs_obs, [CLsb, CLb], [CLs_exp band]]
    """
    data = json.load(open(datadir.join("hypotest_results.json")))

    fig = Figure()
    ax = fig.subplots()
    with pytest.raises(ValueError):
        brazil.plot_results(data["testmus"],
                            data["results"],
                            test_size=0.05,
                            ax=ax,
                            components=True)
예제 #4
0
파일: test_viz.py 프로젝트: scikit-hep/pyhf
def test_plot_results(datadir):
    data = json.load(open(datadir.join("hypotest_results.json")))

    fig = Figure()
    ax = fig.subplots()
    brazil_band_collection = brazil.plot_results(data["testmus"],
                                                 data["results"],
                                                 test_size=0.05,
                                                 ax=ax)
    assert brazil_band_collection.axes == ax

    return fig
예제 #5
0
파일: test_viz.py 프로젝트: scikit-hep/pyhf
def test_brazil_band_collection(datadir):
    data = json.load(open(datadir.join("hypotest_results.json")))

    fig = Figure()
    ax = fig.subplots()
    brazil_band_collection = brazil.plot_results(data["testmus"],
                                                 data["results"],
                                                 test_size=0.05,
                                                 ax=ax)

    assert brazil_band_collection.cls_obs is not None
    assert brazil_band_collection.cls_exp is not None
    assert len(brazil_band_collection.cls_exp) == 5
    assert brazil_band_collection.one_sigma_band is not None
    assert brazil_band_collection.two_sigma_band is not None
    assert brazil_band_collection.test_size is not None
    assert brazil_band_collection.clsb is None
    assert brazil_band_collection.clb is None
    assert brazil_band_collection.axes == ax

    data = json.load(open(datadir.join("tail_probs_hypotest_results.json")))

    fig = Figure()
    ax = fig.subplots()
    brazil_band_collection = brazil.plot_results(data["testmus"],
                                                 data["results"],
                                                 test_size=0.05,
                                                 ax=ax,
                                                 components=True)

    assert brazil_band_collection.cls_obs is not None
    assert brazil_band_collection.cls_exp is not None
    assert len(brazil_band_collection.cls_exp) == 5
    assert brazil_band_collection.one_sigma_band is not None
    assert brazil_band_collection.two_sigma_band is not None
    assert brazil_band_collection.test_size is not None
    assert brazil_band_collection.clsb is not None
    assert brazil_band_collection.clb is not None
    assert brazil_band_collection.axes == ax
예제 #6
0
파일: test_viz.py 프로젝트: scikit-hep/pyhf
def test_plot_results_components_no_clb(datadir):
    data = json.load(open(datadir.join("tail_probs_hypotest_results.json")))

    fig = Figure()
    ax = fig.subplots()
    brazil_band_collection = brazil.plot_results(
        data["testmus"],
        data["results"],
        test_size=0.05,
        ax=ax,
        components=True,
        no_clb=True,
    )

    assert brazil_band_collection.clsb is not None
    assert brazil_band_collection.clb is None
    return fig
예제 #7
0
    model = workspace.model()
    data = workspace.data(model)

    n_points = 4
    test_mus = np.linspace(1.0, 1.2, n_points)
    fit_results = [
        pyhf.infer.hypotest(mu,
                            data,
                            model,
                            return_expected_set=True,
                            calctype="toybased",
                            ntoys=ntoys) for mu in test_mus
    ]

    fig, ax = plt.subplots()
    brazil.plot_results(test_mus, fit_results, ax=ax)
    _buffer = 0.02
    ax.set_xlim(1.0 - _buffer, 1.2 + _buffer)
    ax.set_ylim(0.0, 0.2)

    extensions = ["pdf", "png"]
    for ext in extensions:
        fig.savefig(f"poi_scan_pyhf.{ext}")

    ax.set_ylim(1e-3, 0.2)
    ax.semilogy()

    for ext in extensions:
        fig.savefig(f"poi_scan_logy_pyhf.{ext}")

예제 #8
0
def test_brazil():
    data = json.load(open('tests/contrib/hypotestresults.json'))
    fig, ax = plt.subplots(1, 1)
    brazil.plot_results(ax, data['testmus'], data['results'], test_size=0.05)
    return fig
예제 #9
0
    model = workspace.model()
    data = workspace.data(model)

    n_points = 4
    test_mus = np.linspace(1.0, 1.2, n_points)
    fit_results = [
        pyhf.infer.hypotest(mu,
                            data,
                            model,
                            return_expected_set=True,
                            calctype="toybased",
                            ntoys=ntoys) for mu in test_mus
    ]

    fig, ax = plt.subplots()
    brazil.plot_results(ax, test_mus, fit_results)
    ax.set_xlabel(r"$\mu$")
    ax.set_ylabel(r"$\mathrm{CL}_{s}$")
    _buffer = 0.02
    ax.set_xlim(1.0 - _buffer, 1.2 + _buffer)
    ax.set_ylim(0.0, 0.2)

    extensions = ["pdf", "png"]
    for ext in extensions:
        fig.savefig(f"poi_scan_pyhf.{ext}")

    ax.set_ylim(1e-3, 0.2)
    ax.semilogy()

    for ext in extensions:
        fig.savefig(f"poi_scan_logy_pyhf.{ext}")