From 515b005c7a90fc1b63f10077a938b19fc338b318 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Thu, 1 Aug 2024 15:35:41 +0200 Subject: [PATCH] MAINT: address Ruff issues --- .gitignore | 1 + docs/widget.ipynb | 72 ++++++++++------------------------------ pyproject.toml | 6 ++++ script/makeComparison.py | 6 ++-- 4 files changed, 27 insertions(+), 58 deletions(-) diff --git a/.gitignore b/.gitignore index 9743366..762160c 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ version.py .ipynb_checkpoints/ .mypy*/ .pytest_cache/ +.virtual_documents/ __pycache__/ htmlcov/ node_modules/ diff --git a/docs/widget.ipynb b/docs/widget.ipynb index 741f7f1..70f9a49 100644 --- a/docs/widget.ipynb +++ b/docs/widget.ipynb @@ -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", @@ -144,9 +134,6 @@ "execution_count": null, "metadata": { "editable": true, - "jupyter": { - "source_hidden": true - }, "mystnb": { "code_prompt_show": "Define symbolic Zlm class" }, @@ -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", @@ -231,9 +211,6 @@ "execution_count": null, "metadata": { "editable": true, - "jupyter": { - "source_hidden": true - }, "slideshow": { "slide_type": "" }, @@ -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", @@ -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", @@ -467,9 +439,6 @@ "execution_count": null, "metadata": { "editable": true, - "jupyter": { - "source_hidden": true - }, "mystnb": { "code_prompt_show": "Define widget sliders" }, @@ -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", @@ -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", @@ -656,7 +618,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.12" + "version": "3.9.19" } }, "nbformat": 4, diff --git a/pyproject.toml b/pyproject.toml index dfdf2ee..484ccfb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", @@ -145,6 +149,8 @@ split-on-trailing-comma = false "S101", "S113", ] +"script/*" = ["D100", "INP001"] +"widget.ipynb" = ["S307"] [tool.ruff.lint.pydocstyle] convention = "google" diff --git a/script/makeComparison.py b/script/makeComparison.py index 888b45e..49f62eb 100644 --- a/script/makeComparison.py +++ b/script/makeComparison.py @@ -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 @@ -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=",")