Skip to content

Commit

Permalink
FEAT: export averaged polarimeter vectors as JSON (#228)
Browse files Browse the repository at this point in the history
* DOC: render all systematic averaged alpha values
* DOC: render all systematic averaged values in polar coordinates
  • Loading branch information
redeboer authored Oct 20, 2022
1 parent 9d2df74 commit fda3e03
Showing 1 changed file with 127 additions and 13 deletions.
140 changes: 127 additions & 13 deletions docs/uncertainties.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"import jax.numpy as jnp\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pandas as pd\n",
"import plotly.graph_objects as go\n",
"import sympy as sp\n",
"import yaml\n",
Expand Down Expand Up @@ -1699,7 +1698,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Difference between each model and nominal value (computed with the default model):"
"Averaged polarimeter values for each model (and the difference with the nominal model):"
]
},
{
Expand All @@ -1710,22 +1709,78 @@
"source_hidden": true
},
"tags": [
"full-width",
"hide-input"
]
},
"outputs": [],
"source": [
"pd.DataFrame(\n",
" {\n",
" title: (f\"{x:+.4f}\", f\"{y:+.4f}\", f\"{z:+.4f}\", f\"{norm:+.4f}\")\n",
" for title, x, y, z, norm in zip(\n",
" models,\n",
" *syst_weighted_alpha_diff,\n",
" syst_weighted_alpha_norm_diff,\n",
" )\n",
" }\n",
").transpose().rename(columns={0: \"ɑx\", 1: \"ɑy\", 2: \"ɑz\", 3: \"|ɑ|\"})"
"src = R\"\"\"\n",
"\\begin{array}{r|rrrr|rrrr}\n",
" \\textbf{Model}\n",
" & \\overline{\\alpha}_x & \\overline{\\alpha}_y & \\overline{\\alpha}_z & \\overline{\\left|\\alpha\\right|}\n",
" & \\Delta\\overline{\\alpha}_x & \\Delta\\overline{\\alpha}_y & \\Delta\\overline{\\alpha}_z\n",
" & \\Delta\\overline{\\left|\\alpha\\right|} \\\\\n",
" \\hline\n",
"\"\"\"\n",
"for i, title in enumerate(models):\n",
" α = 1e3 * syst_weighted_alpha[:, i]\n",
" abs_α = 1e3 * syst_weighted_alpha_norm[i]\n",
" Δα = 1e3 * syst_weighted_alpha_diff[:, i]\n",
" abs_Δα = 1e3 * syst_weighted_alpha_norm_diff[i]\n",
" src += Rf\" \\textbf{{{i}}}\"\n",
" src += Rf\" & {α[0]:+.1f} & {α[1]:+.1f} & {α[2]:+.1f} & {abs_α:+.1f}\"\n",
" if i != 0:\n",
" src += Rf\" & {Δα[0]:+.1f} & {Δα[1]:+.1f} & {Δα[2]:+.1f} & {abs_Δα:+.1f}\"\n",
" src += R\" \\\\\" \"\\n\"\n",
" del i, title, α, abs_α, Δα, abs_Δα\n",
"src += R\"\\end{array}\"\n",
"Latex(src)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
"source_hidden": true
},
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"src = R\"\"\"\n",
"\\begin{array}{r|rrr|rrr}\n",
" \\textbf{Model}\n",
" & 10^3 \\cdot \\left|\\overline{\\alpha}\\right|\n",
" & \\theta\\left(\\overline{\\alpha}\\right) / \\pi\n",
" & \\phi\\left(\\overline{\\alpha}\\right) / \\pi\n",
" & 10^3 \\cdot \\Delta\\left|\\overline{\\alpha}\\right|\n",
" & \\Delta\\theta\\left(\\overline{\\alpha}\\right) / \\pi\n",
" & \\Delta\\phi\\left(\\overline{\\alpha}\\right) / \\pi \\\\\n",
" \\hline\n",
"\"\"\"\n",
"for i, title in enumerate(models):\n",
" α, θ, φ = syst_weighted_alpha_polar[:, i]\n",
" Δα, Δθ, Δφ = syst_weighted_alpha_diff_polar[:, i]\n",
" src += Rf\" \\textbf{{{i}}}\"\n",
" src += Rf\" & {1e3*α:+.1f} & {θ/np.pi:+.3f} & {φ/np.pi:+.3f}\"\n",
" if i != 0:\n",
" src += Rf\" & {1e3*Δα:+.1f} & {Δθ/np.pi:+.3f} & {Δφ/np.pi:+.3f}\"\n",
" src += R\" \\\\\" \"\\n\"\n",
" del i, title, α, θ, φ, Δα, Δθ, Δφ\n",
"src += R\"\\end{array}\"\n",
"Latex(src)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
":::{tip}\n",
"These values can be downloaded in serialized JSON format under {ref}`uncertainties:Exported distributions`.\n",
":::"
]
},
{
Expand Down Expand Up @@ -2102,6 +2157,59 @@
"## Exported distributions"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
"source_hidden": true
},
"mystnb": {
"code_prompt_show": "Export averaged polarimeter vectors"
},
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"json_data = {\n",
" \"file description\": \"Averaged polarimeter vector for each alternative model\",\n",
" \"model descriptions\": list(models),\n",
" \"reference subsystem\": reference_subsystem,\n",
" \"systematics\": {\n",
" \"cartesian\": {\n",
" \"x\": syst_weighted_alpha[0].tolist(),\n",
" \"y\": syst_weighted_alpha[1].tolist(),\n",
" \"z\": syst_weighted_alpha[2].tolist(),\n",
" \"norm\": syst_weighted_alpha.tolist(),\n",
" },\n",
" \"polar\": {\n",
" \"norm\": syst_weighted_alpha_polar[0].tolist(),\n",
" \"phi\": syst_weighted_alpha_polar[1].tolist(),\n",
" \"theta\": syst_weighted_alpha_polar[2].tolist(),\n",
" },\n",
" },\n",
" \"statistics\": {\n",
" \"cartesian\": {\n",
" \"x\": stat_weighted_alpha[0].tolist(),\n",
" \"y\": stat_weighted_alpha[1].tolist(),\n",
" \"z\": stat_weighted_alpha[2].tolist(),\n",
" \"norm\": stat_weighted_alpha.tolist(),\n",
" },\n",
" \"polar\": {\n",
" \"norm\": stat_weighted_alpha_polar[0].tolist(),\n",
" \"phi\": stat_weighted_alpha_polar[1].tolist(),\n",
" \"theta\": stat_weighted_alpha_polar[2].tolist(),\n",
" },\n",
" },\n",
"}\n",
"json_averaged = \"_static/export/averaged-polarimeter-vectors.json\"\n",
"with open(json_averaged, \"w\") as f:\n",
" json.dump(json_data, f, indent=2)\n",
"del json_data"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -2280,10 +2388,16 @@
":::\n",
"\"\"\"\n",
"\n",
"bytes_averaged = os.path.getsize(json_averaged)\n",
"bytes_json = os.path.getsize(json_file)\n",
"bytes_tar = os.path.getsize(tar_file)\n",
"src += f\"\"\"\n",
":::{{card}} All data combined can be downloaded here\n",
"```{{button-link}} {json_averaged}\n",
":color: primary\n",
":outline:\n",
"{{octicon}}`file-code` **{os.path.basename(json_averaged)}** ({1e-3*bytes_averaged:,.1f} kB)\n",
"```\n",
"```{{button-link}} {json_file}\n",
":color: primary\n",
":outline:\n",
Expand Down

0 comments on commit fda3e03

Please sign in to comment.