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
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
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)
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
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
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
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}")
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
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}")