Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Fix download method of probability models archive in pull plot notebook #1724

Merged
merged 2 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions docs/examples/notebooks/pullplot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,26 @@
"source": [
"import pyhf\n",
"import json\n",
"import copy\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Download the Model"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For this example we'll download the archive of probability models for the ATLAS analysis [JHEP 12 (2019) 060, 2019](https://inspirehep.net/literature/1748602) from its [HEPData page](https://www.hepdata.net/record/ins1748602) using its [specific DOI](https://www.hepdata.net/record/resource/1935437?landing_page=true). You can download this multiple ways, but for simplicity we'll download it using the `pyhf contrib download` command"
]
},
{
"cell_type": "code",
"execution_count": 2,
Expand All @@ -24,19 +37,32 @@
"name": "stdout",
"output_type": "stream",
"text": [
"RegionA/BkgOnly.json\n"
"\u001b[01;34m1Lbb-probability-models\u001b[00m\n",
"├── README.md\n",
"├── \u001b[01;34mRegionA\u001b[00m\n",
"│   ├── BkgOnly.json\n",
"│   └── patchset.json\n",
"├── \u001b[01;34mRegionB\u001b[00m\n",
"│   ├── BkgOnly.json\n",
"│   └── patchset.json\n",
"└── \u001b[01;34mRegionC\u001b[00m\n",
" ├── BkgOnly.json\n",
" └── patchset.json\n",
"\n",
"3 directories, 7 files\n"
]
}
],
"source": [
"!curl -sL https://doi.org/10.17182/hepdata.89408.v1/r2 | tar -O -xzv RegionA/BkgOnly.json > lhood.json"
"! pyhf contrib download https://doi.org/10.17182/hepdata.89408.v3/r2 1Lbb-probability-models\n",
"! tree 1Lbb-probability-models"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Create the Model and Fit it\n"
"## Create the Model and Fit it\n"
]
},
{
Expand All @@ -46,8 +72,7 @@
"outputs": [],
"source": [
"def make_model(channel_list):\n",
" spec = json.load(open(\"lhood.json\"))\n",
" spec = copy.copy(spec)\n",
" spec = json.load(open(\"1Lbb-probability-models/RegionA/BkgOnly.json\"))\n",
" spec[\"channels\"] = [c for c in spec[\"channels\"] if c[\"name\"] in channel_list]\n",
" spec[\"measurements\"][0][\"config\"][\"poi\"] = \"lumi\"\n",
"\n",
Expand Down Expand Up @@ -186,7 +211,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -200,7 +225,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.5"
"version": "3.9.6"
}
},
"nbformat": 4,
Expand Down
6 changes: 5 additions & 1 deletion tests/test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ def test_multibinpois(common_kwargs):


def test_pullplot(common_kwargs):
pm.execute_notebook('docs/examples/notebooks/pullplot.ipynb', **common_kwargs)
# Change directories to make users not have to worry about paths to follow example
cwd = os.getcwd()
os.chdir(os.path.join(cwd, "docs/examples/notebooks"))
pm.execute_notebook("pullplot.ipynb", **common_kwargs)
os.chdir(cwd)


def test_impactplot(common_kwargs):
Expand Down