Skip to content

Commit

Permalink
MAINT: address Ruff issues
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Aug 1, 2024
1 parent d9cb508 commit 515b005
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 58 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ version.py
.ipynb_checkpoints/
.mypy*/
.pytest_cache/
.virtual_documents/
__pycache__/
htmlcov/
node_modules/
Expand Down
72 changes: 17 additions & 55 deletions docs/widget.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,45 +51,35 @@
"slide_type": ""
},
"tags": [
"hide-input"
"hide-input",
"scroll-input"
]
},
"outputs": [],
"source": [
"from __future__ import annotations\n",
"\n",
"from collections import defaultdict\n",
"\n",
"import ipywidgets as w\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import sympy as sp\n",
"from ampform.io import aslatex\n",
"from ampform.sympy import PoolSum\n",
"from ampform.sympy import (\n",
" PoolSum,\n",
" UnevaluatedExpression,\n",
" create_expression,\n",
" implement_doit_method,\n",
")\n",
"from IPython.display import Math\n",
"from sympy.functions.special.spherical_harmonics import Ynm"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"editable": true,
"jupyter": {
"source_hidden": true
},
"mystnb": {
"code_prompt_show": "Match SymPy LaTeX rendering"
},
"slideshow": {
"slide_type": ""
},
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"from qrules.quantum_numbers import arange\n",
"from sympy.functions.special.spherical_harmonics import Ynm\n",
"from sympy.printing.precedence import PRECEDENCE\n",
"from sympy.printing.printer import Printer\n",
"\n",
"\n",
"def _print_Indexed_latex(self, printer, *args):\n",
"def _print_Indexed_latex(self, printer, *args): # noqa: N802\n",
" base = printer._print(self.base)\n",
" indices = \", \".join(map(printer._print, self.indices))\n",
" return f\"{base}_{{{indices}}}\"\n",
Expand Down Expand Up @@ -144,9 +134,6 @@
"execution_count": null,
"metadata": {
"editable": true,
"jupyter": {
"source_hidden": true
},
"mystnb": {
"code_prompt_show": "Define symbolic Zlm class"
},
Expand All @@ -159,13 +146,6 @@
},
"outputs": [],
"source": [
"from ampform.sympy import (\n",
" UnevaluatedExpression,\n",
" create_expression,\n",
" implement_doit_method,\n",
")\n",
"\n",
"\n",
"@implement_doit_method\n",
"class Znm(UnevaluatedExpression):\n",
" is_commutative = True\n",
Expand Down Expand Up @@ -231,9 +211,6 @@
"execution_count": null,
"metadata": {
"editable": true,
"jupyter": {
"source_hidden": true
},
"slideshow": {
"slide_type": ""
},
Expand All @@ -245,9 +222,6 @@
},
"outputs": [],
"source": [
"from qrules.quantum_numbers import arange\n",
"\n",
"\n",
"def create_range(__min, __max) -> tuple[sp.Rational, ...]:\n",
" return tuple(sp.Rational(x) for x in arange(__min, __max + 1))\n",
"\n",
Expand Down Expand Up @@ -425,8 +399,6 @@
},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"cos_theta_array, phi_array = np.meshgrid(\n",
" np.linspace(-1, +1, num=200),\n",
" np.linspace(0, 2 * np.pi, num=400),\n",
Expand Down Expand Up @@ -467,9 +439,6 @@
"execution_count": null,
"metadata": {
"editable": true,
"jupyter": {
"source_hidden": true
},
"mystnb": {
"code_prompt_show": "Define widget sliders"
},
Expand All @@ -483,10 +452,6 @@
},
"outputs": [],
"source": [
"from collections import defaultdict\n",
"\n",
"import ipywidgets as w\n",
"\n",
"# Create sliders for each symbol/argument\n",
"sliders = dict(\n",
" Phi_val=w.FloatSlider(\n",
Expand Down Expand Up @@ -569,9 +534,6 @@
"outputs": [],
"source": [
"%matplotlib widget\n",
"\n",
"import matplotlib.pyplot as plt\n",
"\n",
"fig, ax = plt.subplots(figsize=(7, 4))\n",
"ax.set_xlabel(R\"$\\phi$\")\n",
"ax.set_ylabel(R\"$\\cos\\theta$\")\n",
Expand Down Expand Up @@ -656,7 +618,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.9.19"
}
},
"nbformat": 4,
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,19 @@ split-on-trailing-comma = false
[tool.ruff.lint.per-file-ignores]
"*.ipynb" = [
"B018",
"C408",
"C90",
"D",
"E703",
"E741",
"N803",
"N806",
"N816",
"PLR09",
"PLR2004",
"PLW0602",
"PLW0603",
"RUF001",
"S101",
"T20",
"TCH00",
Expand All @@ -145,6 +149,8 @@ split-on-trailing-comma = false
"S101",
"S113",
]
"script/*" = ["D100", "INP001"]
"widget.ipynb" = ["S307"]

[tool.ruff.lint.pydocstyle]
convention = "google"
Expand Down
6 changes: 3 additions & 3 deletions script/makeComparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
with open(".print_amplitudes.log") as file:
for line in file:
if "INTENSITY =" in line:
line = re.sub(" +", " ", line.rstrip().lstrip())
line = re.sub(" +", " ", line.rstrip().lstrip()) # noqa: PLW2901
intensities.append(float(line.split()[2]))
intensities = np.array(intensities)

assert len(intensities) == len(data["cosTheta_eta_hel_thrown"])
assert len(intensities) == len(data["cosTheta_eta_hel_thrown"]) # noqa: S101

# Rename dictionary keys
data["intensity"] = intensities
Expand All @@ -33,6 +33,6 @@
# Standardize the data to be angles in radians
DEGREE_TO_RADIAN = np.pi / 180.0
data["theta"] = np.arccos(data["theta"])
data["Phi"] = data["Phi"] * DEGREE_TO_RADIAN
data["Phi"] *= DEGREE_TO_RADIAN

data.to_csv("comparison.csv", index=False, sep=",")

0 comments on commit 515b005

Please sign in to comment.