Skip to content
Draft
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
150 changes: 150 additions & 0 deletions docs/examples/synchrotron_radiation.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "38c2f28c",
"metadata": {},
"source": [
"# Synchrotron Radiation\n",
"\n",
"Minimal demonstration of the synchrotron radiation functions."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5164e37f",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"from pmd_beamphysics.radiation.synchrotron_radiation import (\n",
" S_fast,\n",
" S_exact,\n",
" S_benchmarking,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d0a11272",
"metadata": {},
"outputs": [],
"source": [
"S_exact(1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f32cd482",
"metadata": {},
"outputs": [],
"source": [
"# Single value\n",
"S_fast(1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2c90c40c",
"metadata": {},
"outputs": [],
"source": [
"# Array input\n",
"xi = 2 ** np.linspace(-10, 3, 100)\n",
"s0 = S_exact(xi)\n",
"s1 = S_fast(xi)\n",
"rel_err = s1 / s0 - 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e7602053",
"metadata": {},
"outputs": [],
"source": [
"%%timeit\n",
"S_exact(xi)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0fc9a1c5",
"metadata": {},
"outputs": [],
"source": [
"%%timeit\n",
"S_fast(xi)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cc97851d",
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots()\n",
"ax.plot(xi, s0, label=\"exact\")\n",
"ax.plot(xi, s1, \"--\", label=\"fast\")\n",
"ax.legend()\n",
"\n",
"ax2 = ax.twinx()\n",
"ax2.plot(xi, rel_err)\n",
"\n",
"ax.set_xlabel(r\"$\\xi$\")\n",
"ax.set_ylabel(r\"$S(\\xi)$\")\n",
"\n",
"ax2.set_yscale(\"log\")\n",
"ax.set_xscale(\"log\")\n",
"ax.set_yscale(\"log\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9e53496e",
"metadata": {},
"outputs": [],
"source": [
"S_benchmarking()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c9cdd98f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "pmd_beamphysics-dev",
"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.13.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading
Loading