-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deploying to gh-pages from @ 225f888 🚀
- Loading branch information
Showing
97 changed files
with
31,787 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Sphinx build info version 1 | ||
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. | ||
config: a71338dbc41bde02cdd4e7b6cbe6ae59 | ||
tags: 645f666f9bcd5a90fca523b33c5a78b7 |
43 changes: 43 additions & 0 deletions
43
_downloads/464b65b24fdedc416eded46199f2935d/export_charts.ipynb
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Export Accelerator Timeline\n\nThis is an example script to generate static plots of the accelerator data via \nmatplotlib.\nTo run the script, make sure your environment has the requirements \nof `requirements_export_charts.txt` installed.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\nfrom pathlib import Path\n\nimport matplotlib as mpl\nimport matplotlib.ticker as plticker\nimport numpy as np\nimport pandas as pd\nfrom matplotlib import pyplot as plt\nfrom matplotlib.figure import Figure\n\nfrom utilities.csv_reader import Column, import_collider_data\nfrom utilities.plot_helper import (PARTICLE_TYPES, PLOTLY_MPL_SYMBOL_MAP, EnergyConfiguration,\n LuminosityConfiguration, LuminosityOverEnergyConfiguration,\n PlotConfiguration, assign_textposition)\nfrom utilities.sphinx_helper import get_gallery_dir, is_sphinx_build\n\n\ndef plot(data: pd.DataFrame, configuration: PlotConfiguration) -> Figure:\n \"\"\"Generate interactive plots with matplotlib, based on the given configuration, \n which defines the columns to use, labels and the text positions.\n\n Args:\n data (pd.DataFrame): DataFrame containing the (modified) accelerator timeline data\n configuration (PlotConfiguration): See :class:`utilities.plot_helper.PlotConfiguration`\n\n Returns:\n Figure: Matplotlib figure \n \"\"\"\n fig, ax = plt.subplots()\n \n pad = mpl.rcParams[\"lines.markersize\"]/3\n vmap = {\"top\": pad, \"middle\": 0, \"bottom\": -pad}\n hmap = {\"left\": -pad*2, \"center\": 0, \"right\": pad*2}\n alignment_map = {\n \"left\": \"right\", \"center\": \"center\", \"right\": \"left\", \n \"top\": \"bottom\", \"middle\": \"center\", \"bottom\": \"top\"\n }\n\n for particle_type in PARTICLE_TYPES:\n mask = data[Column.TYPE] == particle_type.shorthand\n marker = PLOTLY_MPL_SYMBOL_MAP[particle_type.symbol]\n\n for has_been_built in (True, False):\n if has_been_built:\n builtmask, fillstyle, legend_prefix = data[Column.BUILT], \"full\", \"\"\n else:\n builtmask, fillstyle, legend_prefix = ~data[Column.BUILT], \"none\", \"_\"\n\n ax.plot(\n data.loc[mask & builtmask, configuration.xcolumn], \n data.loc[mask & builtmask, configuration.ycolumn],\n linestyle=\"none\",\n marker=marker, fillstyle=fillstyle,\n color=particle_type.color,\n label=f\"{legend_prefix}{particle_type.latex}\",\n )\n\n for x, y, text, textposition in zip(data.loc[mask, configuration.xcolumn], \n data.loc[mask, configuration.ycolumn], \n data.loc[mask, Column.NAME], \n data.loc[mask, configuration.textposition]):\n v, h = textposition.split(\" \")\n ax.annotate(text, xy=(x, y), \n xytext=(hmap[h], vmap[v]), \n textcoords=\"offset pixels\", \n ha=alignment_map[h], va=alignment_map[v]\n )\n\n ax.set_xlabel(configuration.xlabel)\n ax.set_ylabel(configuration.ylabel)\n for axis in (\"x\", \"y\"):\n if axis in configuration.logscale:\n getattr(ax, f\"set_{axis}scale\")(\"log\")\n lim = getattr(ax, f\"get_{axis}lim\")()\n numticks = int(np.log10(lim[1]/lim[0])) + 1\n getattr(ax, f\"{axis}axis\").set_major_locator(plticker.LogLocator(base=10.0, numticks=numticks))\n getattr(ax, f\"{axis}axis\").set_minor_locator(plticker.LogLocator(base=10.0, subs=np.arange(2, 10)))\n getattr(ax, f\"{axis}axis\").set_minor_formatter(plticker.NullFormatter())\n else:\n getattr(ax, f\"set_{axis}scale\")(\"linear\")\n getattr(ax, f\"{axis}axis\").set_major_locator(plticker.MultipleLocator(base=10.0))\n getattr(ax, f\"{axis}axis\").set_minor_locator(plticker.MultipleLocator(base=1.0))\n\n\n ax.legend(loc='upper left', bbox_to_anchor=(1, 1), borderaxespad=0., title='Particles', ncol=1)\n return fig \n\n\nif __name__ == \"__main__\":\n if is_sphinx_build():\n MAIN_DIR = Path()\n output_dir = get_gallery_dir()\n else:\n MAIN_DIR = Path(__file__).parent\n output_dir = MAIN_DIR / \"images\"\n\n plt.style.use(MAIN_DIR / \"utilities\" / \"chart.mplstyle\")\n\n data = import_collider_data()\n data = assign_textposition(data)\n \n fig_com = plot(data, EnergyConfiguration)\n fig_com.savefig(output_dir / \"energy.pdf\")\n fig_com.savefig(output_dir / \"energy.png\")\n\n fig_lumi = plot(data, LuminosityConfiguration)\n fig_lumi.savefig(output_dir / \"luminosity.pdf\")\n fig_lumi.savefig(output_dir / \"luminosity.png\")\n\n fig_lumi_vs_com = plot(data, LuminosityOverEnergyConfiguration)\n fig_lumi_vs_com.savefig(output_dir / \"luminosity-vs-energy.pdf\")\n fig_lumi_vs_com.savefig(output_dir / \"luminosity-vs-energy.png\")\n \n # plt.show()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.17" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
122 changes: 122 additions & 0 deletions
122
_downloads/4b4f2203ddc9d489e59223854d32d17e/interactive_charts.ipynb
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 |
---|---|---|
@@ -0,0 +1,122 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"\n# Interactive Accelerator Timeline\n\nThis script allows you to interactively explore the accelerator data,\neither by running the script and viewing the plots in a browser,\nby running the script in interactive-mode e.g. in vscode \nor by checking the from this script generated gallery.\n\nTo run the script, make sure your environment has the requirements \nof `requirements_interactive_charts.txt` installed.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Preparations \n\nImport modules and define plotting function.\nThis code is omitted in the interactive gallery, so that you can immediately enjoy the interactive plots below.\nCheck [interactive.py](https://github.com/pylhc/accelerator_timeline/blob/master/interactive.py) \nfor the full example code.\n\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# No code to see here in the interactive gallery or the generated jupyter notebook." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Energy Timeline\n\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"fig_com = plot(data, EnergyConfiguration)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Luminosity timeline\n\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"fig_lumi = plot(data, LuminosityConfiguration)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Luminosity vs. Energy \n\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"fig_lumi_energy = plot(data, LuminosityOverEnergyConfiguration)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Save plots\n\nSave the plots as PDF and PNG.\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"output_dir = Path(\"images\")\n\nplotly.io.write_image(fig_com, output_dir / \"energy-plotly.pdf\", format=\"pdf\")\nplotly.io.write_image(fig_com, output_dir / \"energy-plotly.png\", format=\"png\")\nplotly.io.write_image(fig_lumi, output_dir / \"luminosity-plotly.pdf\", format=\"pdf\")\nplotly.io.write_image(fig_lumi, output_dir / \"luminosity-plotly.png\", format=\"png\")\nplotly.io.write_image(fig_lumi_energy, output_dir / \"luminosity-vs-energy-plotly.pdf\", format=\"pdf\")\nplotly.io.write_image(fig_lumi_energy, output_dir / \"luminosity-vs-energy-plotly.png\", format=\"png\")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.17" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
125 changes: 125 additions & 0 deletions
125
_downloads/a3e0be0bf8d99a8bc1746d8344c38a82/export_charts.py
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 |
---|---|---|
@@ -0,0 +1,125 @@ | ||
""" | ||
Export Accelerator Timeline | ||
*************************** | ||
This is an example script to generate static plots of the accelerator data via | ||
matplotlib. | ||
To run the script, make sure your environment has the requirements | ||
of `requirements_export_charts.txt` installed. | ||
""" | ||
import os | ||
from pathlib import Path | ||
|
||
import matplotlib as mpl | ||
import matplotlib.ticker as plticker | ||
import numpy as np | ||
import pandas as pd | ||
from matplotlib import pyplot as plt | ||
from matplotlib.figure import Figure | ||
|
||
from utilities.csv_reader import Column, import_collider_data | ||
from utilities.plot_helper import (PARTICLE_TYPES, PLOTLY_MPL_SYMBOL_MAP, EnergyConfiguration, | ||
LuminosityConfiguration, LuminosityOverEnergyConfiguration, | ||
PlotConfiguration, assign_textposition) | ||
from utilities.sphinx_helper import get_gallery_dir, is_sphinx_build | ||
|
||
|
||
def plot(data: pd.DataFrame, configuration: PlotConfiguration) -> Figure: | ||
"""Generate interactive plots with matplotlib, based on the given configuration, | ||
which defines the columns to use, labels and the text positions. | ||
Args: | ||
data (pd.DataFrame): DataFrame containing the (modified) accelerator timeline data | ||
configuration (PlotConfiguration): See :class:`utilities.plot_helper.PlotConfiguration` | ||
Returns: | ||
Figure: Matplotlib figure | ||
""" | ||
fig, ax = plt.subplots() | ||
|
||
pad = mpl.rcParams["lines.markersize"]/3 | ||
vmap = {"top": pad, "middle": 0, "bottom": -pad} | ||
hmap = {"left": -pad*2, "center": 0, "right": pad*2} | ||
alignment_map = { | ||
"left": "right", "center": "center", "right": "left", | ||
"top": "bottom", "middle": "center", "bottom": "top" | ||
} | ||
|
||
for particle_type in PARTICLE_TYPES: | ||
mask = data[Column.TYPE] == particle_type.shorthand | ||
marker = PLOTLY_MPL_SYMBOL_MAP[particle_type.symbol] | ||
|
||
for has_been_built in (True, False): | ||
if has_been_built: | ||
builtmask, fillstyle, legend_prefix = data[Column.BUILT], "full", "" | ||
else: | ||
builtmask, fillstyle, legend_prefix = ~data[Column.BUILT], "none", "_" | ||
|
||
ax.plot( | ||
data.loc[mask & builtmask, configuration.xcolumn], | ||
data.loc[mask & builtmask, configuration.ycolumn], | ||
linestyle="none", | ||
marker=marker, fillstyle=fillstyle, | ||
color=particle_type.color, | ||
label=f"{legend_prefix}{particle_type.latex}", | ||
) | ||
|
||
for x, y, text, textposition in zip(data.loc[mask, configuration.xcolumn], | ||
data.loc[mask, configuration.ycolumn], | ||
data.loc[mask, Column.NAME], | ||
data.loc[mask, configuration.textposition]): | ||
v, h = textposition.split(" ") | ||
ax.annotate(text, xy=(x, y), | ||
xytext=(hmap[h], vmap[v]), | ||
textcoords="offset pixels", | ||
ha=alignment_map[h], va=alignment_map[v] | ||
) | ||
|
||
ax.set_xlabel(configuration.xlabel) | ||
ax.set_ylabel(configuration.ylabel) | ||
for axis in ("x", "y"): | ||
if axis in configuration.logscale: | ||
getattr(ax, f"set_{axis}scale")("log") | ||
lim = getattr(ax, f"get_{axis}lim")() | ||
numticks = int(np.log10(lim[1]/lim[0])) + 1 | ||
getattr(ax, f"{axis}axis").set_major_locator(plticker.LogLocator(base=10.0, numticks=numticks)) | ||
getattr(ax, f"{axis}axis").set_minor_locator(plticker.LogLocator(base=10.0, subs=np.arange(2, 10))) | ||
getattr(ax, f"{axis}axis").set_minor_formatter(plticker.NullFormatter()) | ||
else: | ||
getattr(ax, f"set_{axis}scale")("linear") | ||
getattr(ax, f"{axis}axis").set_major_locator(plticker.MultipleLocator(base=10.0)) | ||
getattr(ax, f"{axis}axis").set_minor_locator(plticker.MultipleLocator(base=1.0)) | ||
|
||
|
||
ax.legend(loc='upper left', bbox_to_anchor=(1, 1), borderaxespad=0., title='Particles', ncol=1) | ||
return fig | ||
|
||
|
||
if __name__ == "__main__": | ||
if is_sphinx_build(): | ||
MAIN_DIR = Path() | ||
output_dir = get_gallery_dir() | ||
else: | ||
MAIN_DIR = Path(__file__).parent | ||
output_dir = MAIN_DIR / "images" | ||
|
||
plt.style.use(MAIN_DIR / "utilities" / "chart.mplstyle") | ||
|
||
data = import_collider_data() | ||
data = assign_textposition(data) | ||
|
||
fig_com = plot(data, EnergyConfiguration) | ||
fig_com.savefig(output_dir / "energy.pdf") | ||
fig_com.savefig(output_dir / "energy.png") | ||
|
||
fig_lumi = plot(data, LuminosityConfiguration) | ||
fig_lumi.savefig(output_dir / "luminosity.pdf") | ||
fig_lumi.savefig(output_dir / "luminosity.png") | ||
|
||
fig_lumi_vs_com = plot(data, LuminosityOverEnergyConfiguration) | ||
fig_lumi_vs_com.savefig(output_dir / "luminosity-vs-energy.pdf") | ||
fig_lumi_vs_com.savefig(output_dir / "luminosity-vs-energy.png") | ||
|
||
# plt.show() | ||
|
||
# sphinx_gallery_thumbnail_path = 'gallery/luminosity-vs-energy.png' |
Oops, something went wrong.