From 4eb7151bc902908fe3273e302b6c0e2a8ff71c8c Mon Sep 17 00:00:00 2001 From: Sylwester Arabas Date: Sat, 9 Sep 2023 23:33:00 +0200 Subject: [PATCH] cleaning up code triggering redefined-outer-name pylint warning (pytest fixtures; function definitions within notebooks) (#1133) --- .github/workflows/tests+artifacts+pypi.yml | 2 +- .../Arabas_et_al_2023/aida.ipynb | 12 +- .../Arabas_et_al_2023/copula_hello.ipynb | 24 ++-- .../Arabas_et_al_2023/fig_11.ipynb | 8 +- .../Arabas_et_al_2023/fig_2.ipynb | 4 +- .../Arabas_et_al_2023/fig_convergence.ipynb | 12 +- .../figs_3_and_7_and_8.ipynb | 18 +-- .../Arabas_et_al_2023/figs_5_and_6.ipynb | 96 +++++++------- .../Berry_1967/figs_5_8_10.ipynb | 20 +-- .../figure_1.ipynb | 16 +-- .../figure_2.ipynb | 16 +-- .../Lowe_et_al_2019/fig_3.ipynb | 49 +------- .../Shima_et_al_2009/fig_2.ipynb | 16 +-- .../Yang_et_al_2018/fig_2.ipynb | 40 +++--- .../figs_10_11_12_13.ipynb | 118 +++++++++--------- .../test_fig_6.py | 1 - .../test_fig_8.py | 1 - .../test_1d_exporters.py | 6 +- .../test_adaptive_displacement.py | 1 - .../arabas_et_al_2015/test_freezing.py | 1 - .../kreidenweis_et_al_2003/test_fig_1.py | 7 +- .../{constants.py => conftest.py} | 4 +- .../parcel/lowe_et_al_2019/test_fig_1.py | 31 ++--- .../parcel/lowe_et_al_2019/test_fig_2.py | 40 ++++-- .../test_surface_tension_models.py | 4 - .../backends/storage/test_setitem.py | 1 - .../{__parametrisation__.py => conftest.py} | 12 +- .../dynamics/collisions/test_efficiencies.py | 2 +- .../collisions/test_sdm_multi_cell.py | 2 +- .../collisions/test_sdm_single_cell.py | 20 +-- .../test_equilibrate_wet_radii.py | 1 - tests/unit_tests/products/test_impl.py | 6 +- 32 files changed, 264 insertions(+), 327 deletions(-) rename tests/smoke_tests/parcel/lowe_et_al_2019/{constants.py => conftest.py} (89%) rename tests/unit_tests/dynamics/collisions/{__parametrisation__.py => conftest.py} (90%) diff --git a/.github/workflows/tests+artifacts+pypi.yml b/.github/workflows/tests+artifacts+pypi.yml index da99fb7b0..661355787 100644 --- a/.github/workflows/tests+artifacts+pypi.yml +++ b/.github/workflows/tests+artifacts+pypi.yml @@ -109,7 +109,7 @@ jobs: pylint --max-module-lines=550 --unsafe-load-any-extension=y --disable=fixme,too-many-function-args,unsubscriptable-object,consider-using-with,protected-access,too-many-statements,too-many-public-methods,too-many-branches,duplicate-code,invalid-name,missing-function-docstring,missing-module-docstring,missing-class-docstring,too-many-locals,too-many-instance-attributes,too-few-public-methods,too-many-arguments,c-extension-no-member $(git ls-files '*.py' | grep ^examples) - run: | # TODO #682 - nbqa pylint --unsafe-load-any-extension=y --disable=fixme,duplicate-code,invalid-name,trailing-whitespace,line-too-long,missing-function-docstring,wrong-import-position,missing-module-docstring,wrong-import-order,ungrouped-imports,no-member,too-many-locals,redefined-outer-name,unnecessary-lambda-assignment $(git ls-files '*.ipynb') + nbqa pylint --unsafe-load-any-extension=y --disable=fixme,duplicate-code,invalid-name,trailing-whitespace,line-too-long,missing-function-docstring,wrong-import-position,missing-module-docstring,wrong-import-order,ungrouped-imports,no-member,too-many-locals,unnecessary-lambda-assignment $(git ls-files '*.ipynb') zenodo_json: runs-on: ubuntu-latest diff --git a/examples/PySDM_examples/Arabas_et_al_2023/aida.ipynb b/examples/PySDM_examples/Arabas_et_al_2023/aida.ipynb index c4bcdcbae..4f99be360 100644 --- a/examples/PySDM_examples/Arabas_et_al_2023/aida.ipynb +++ b/examples/PySDM_examples/Arabas_et_al_2023/aida.ipynb @@ -236,17 +236,17 @@ "source": [ "d_dry, conc = spectral_sampling.ConstantMultiplicity(dNdD).sample(common['n_sd'])\n", "\n", - "attributes = {\n", + "ATTRIBUTES = {\n", " 'n': conc * common['volume'],\n", " 'dry volume': common['formulae'].trivia.volume(radius=d_dry / 2)\n", "}\n", "\n", "outputs = []\n", - "settings = [\n", - " Settings(**common, attributes=dict(attributes), singular=False),\n", - " Settings(**common, attributes=dict(attributes), singular=True),\n", + "SETTINGS = [\n", + " Settings(**common, attributes=dict(ATTRIBUTES), singular=False),\n", + " Settings(**common, attributes=dict(ATTRIBUTES), singular=True),\n", "]\n", - "for setting in settings:\n", + "for setting in SETTINGS:\n", " simulation = Simulation(setting)\n", " outputs.append(simulation.run())" ] @@ -267,7 +267,7 @@ "fig, axs = pyplot.subplots(4, 2, figsize=(10, 10), sharex=True)\n", "for i, output in enumerate(outputs):\n", " axT = axs[0, i]\n", - " axT.set_title(f\"singular={settings[i].singular}\")\n", + " axT.set_title(f\"singular={SETTINGS[i].singular}\")\n", " axT.grid()\n", " axT.set_ylim(805, 1015)\n", " axT.plot(output['time'], output['ambient pressure'], color='black', label='p')\n", diff --git a/examples/PySDM_examples/Arabas_et_al_2023/copula_hello.ipynb b/examples/PySDM_examples/Arabas_et_al_2023/copula_hello.ipynb index eee3c348d..f14f9388c 100644 --- a/examples/PySDM_examples/Arabas_et_al_2023/copula_hello.ipynb +++ b/examples/PySDM_examples/Arabas_et_al_2023/copula_hello.ipynb @@ -90,14 +90,14 @@ "\n", "grid = np.meshgrid(T, A)\n", "\n", - "def pdf(T, A):\n", - " return formulae.freezing_temperature_spectrum.pdf(T, A) * spectrum.pdf(A)\n", + "def pdf(T_arg, A_arg):\n", + " return formulae.freezing_temperature_spectrum.pdf(T_arg, A_arg) * spectrum.pdf(A_arg)\n", "\n", - "def cdfA(A):\n", - " return spectrum.cdf(A)\n", + "def cdfA(A_arg):\n", + " return spectrum.cdf(A_arg)\n", "\n", - "def cdfT(T):\n", - " return formulae.freezing_temperature_spectrum.cdf(T, spectrum.median)\n", + "def cdfT(T_arg):\n", + " return formulae.freezing_temperature_spectrum.cdf(T_arg, spectrum.median)\n", "\n", "def invcdfA(x):\n", " return spectrum.percentiles(x)\n", @@ -105,14 +105,14 @@ "def invcdfT(x):\n", " return formulae.freezing_temperature_spectrum.invcdf(x, spectrum.median)\n", "\n", - "def _T_to_01(T):\n", - " return (T - T_range[0]) / np.diff(T_range)\n", + "def _T_to_01(T_arg):\n", + " return (T_arg - T_range[0]) / np.diff(T_range)\n", "\n", "def _01_to_T(x):\n", " return x * np.diff(T_range) + T_range[0]\n", "\n", - "def _A_to_01(A):\n", - " return (A - A_range[0]) / np.diff(A_range)\n", + "def _A_to_01(A_arg):\n", + " return (A_arg - A_range[0]) / np.diff(A_range)\n", " \n", "def _01_to_A(x):\n", " return x * np.diff(A_range) + A_range[0]\n", @@ -182,8 +182,8 @@ "metadata": {}, "outputs": [], "source": [ - "def jointplot(data, title=''):\n", - " h = seaborn.jointplot(x=data[:, 0], y=data[:, 1], kind='hex', label=title)\n", + "def jointplot(data_arg, title=''):\n", + " h = seaborn.jointplot(x=data_arg[:, 0], y=data_arg[:, 1], kind='hex', label=title)\n", " h.set_axis_labels(label_T, label_A)\n", " if title != '':\n", " pyplot.legend(loc='upper right')" diff --git a/examples/PySDM_examples/Arabas_et_al_2023/fig_11.ipynb b/examples/PySDM_examples/Arabas_et_al_2023/fig_11.ipynb index d80ba0fe1..150b8be9f 100644 --- a/examples/PySDM_examples/Arabas_et_al_2023/fig_11.ipynb +++ b/examples/PySDM_examples/Arabas_et_al_2023/fig_11.ipynb @@ -384,12 +384,12 @@ "metadata": {}, "outputs": [], "source": [ - "def label(settings):\n", - " lbl = str({k.replace('condensation_', ''):\n", + "def label(settings_arg):\n", + " tmp = str({k.replace('condensation_', ''):\n", " f\"{v:.1e}\" if isinstance(v, float) else\n", " str(v).zfill(2) if isinstance(v, int) else\n", - " v for k, v in settings.items()})\n", - " return lbl\\\n", + " v for k, v in settings_arg.items()})\n", + " return tmp\\\n", " .replace('{', '')\\\n", " .replace('}', '')\\\n", " .replace(\"'\", '')\\\n", diff --git a/examples/PySDM_examples/Arabas_et_al_2023/fig_2.ipynb b/examples/PySDM_examples/Arabas_et_al_2023/fig_2.ipynb index 34ae65809..3ecd568ab 100644 --- a/examples/PySDM_examples/Arabas_et_al_2023/fig_2.ipynb +++ b/examples/PySDM_examples/Arabas_et_al_2023/fig_2.ipynb @@ -50,8 +50,8 @@ "svp = Formulae(saturation_vapour_pressure='FlatauWalkoCotton').saturation_vapour_pressure\n", "T = np.linspace(*TEMP_RANGE) * si.K\n", "\n", - "def _T(T):\n", - " return (T/si.K).to_base_units().magnitude\n", + "def _T(TK):\n", + " return (TK/si.K).to_base_units().magnitude\n", "\n", "a_w_ice = svp.ice_Celsius(_T(T) - const.T0) / svp.pvs_Celsius(_T(T) - const.T0)" ] diff --git a/examples/PySDM_examples/Arabas_et_al_2023/fig_convergence.ipynb b/examples/PySDM_examples/Arabas_et_al_2023/fig_convergence.ipynb index 6c9ecae37..95b457cf2 100644 --- a/examples/PySDM_examples/Arabas_et_al_2023/fig_convergence.ipynb +++ b/examples/PySDM_examples/Arabas_et_al_2023/fig_convergence.ipynb @@ -28,20 +28,20 @@ "metadata": {}, "outputs": [], "source": [ - "def _plot_fit(fit_x, fit_y, low, hgh, total_time):\n", + "def _plot_fit(fit_x_arg, fit_y_arg, low_arg, hgh_arg, total_time_arg):\n", " pyplot.plot(\n", - " fit_x, fit_y, color=\"black\", linestyle=\"--\", label=\"theory\", linewidth=5\n", + " fit_x_arg, fit_y_arg, color=\"black\", linestyle=\"--\", label=\"theory\", linewidth=5\n", " )\n", " pyplot.plot(\n", - " fit_x, hgh(fit_x), color=\"black\", linestyle=\":\", label=\"assert upper bound\"\n", + " fit_x_arg, hgh_arg(fit_x_arg), color=\"black\", linestyle=\":\", label=\"assert upper bound\"\n", " )\n", " pyplot.plot(\n", - " fit_x, low(fit_x), color=\"black\", linestyle=\":\", label=\"assert lower bound\"\n", + " fit_x_arg, low_arg(fit_x_arg), color=\"black\", linestyle=\":\", label=\"assert lower bound\"\n", " )\n", " pyplot.legend()\n", " pyplot.yscale(\"log\")\n", - " pyplot.ylim(fit_y[-1], fit_y[0])\n", - " pyplot.xlim(None, total_time)\n", + " pyplot.ylim(fit_y_arg[-1], fit_y_arg[0])\n", + " pyplot.xlim(None, total_time_arg)\n", " pyplot.xlabel(\"time [s]\")\n", " pyplot.ylabel(\"unfrozen fraction\")\n", " pyplot.grid()" diff --git a/examples/PySDM_examples/Arabas_et_al_2023/figs_3_and_7_and_8.ipynb b/examples/PySDM_examples/Arabas_et_al_2023/figs_3_and_7_and_8.ipynb index cd8c3aa54..777085ee1 100644 --- a/examples/PySDM_examples/Arabas_et_al_2023/figs_3_and_7_and_8.ipynb +++ b/examples/PySDM_examples/Arabas_et_al_2023/figs_3_and_7_and_8.ipynb @@ -46,8 +46,8 @@ " constants=constants\n", ")\n", "\n", - "def A_spec(ln_s_geom):\n", - " return Lognormal(norm_factor=1, m_mode=LOGNORMAL_MODE_SURF_A, s_geom=np.exp(ln_s_geom))" + "def A_spec(ln_s_geom_arg):\n", + " return Lognormal(norm_factor=1, m_mode=LOGNORMAL_MODE_SURF_A, s_geom=np.exp(ln_s_geom_arg))" ] }, { @@ -17394,7 +17394,7 @@ " drop_v_um3,\n", " ln10_drop_n,\n", " ln10_vol_m3,\n", - " ln_s_geom,\n", + " ln_s_geom_arg,\n", " times,\n", " temps\n", " ):\n", @@ -17411,12 +17411,12 @@ " )\n", " assert temperature_profile.x[0] == 0\n", " \n", - " params = {\n", + " common_params = {\n", " 'droplet_volume': drop_v_um3 * si.um**3,\n", " 'total_particle_number': 10**ln10_drop_n,\n", " 'volume': 10**ln10_vol_m3\n", " }\n", - " surf_spec=A_spec(ln_s_geom)\n", + " surf_spec=A_spec(ln_s_geom_arg)\n", " \n", " output = []\n", " for singular in (True, False):\n", @@ -17430,7 +17430,7 @@ " seed=seed,\n", " shima_T_fz=formulae.freezing_temperature_spectrum.__name__,\n", " ABIFM_spec=surf_spec,\n", - " **params\n", + " **common_params\n", " )\n", " output.append({\n", " **run_simulation(particulator, temperature_profile, n_steps),\n", @@ -17447,7 +17447,7 @@ " output, \n", " formulae, \n", " surf_spec=surf_spec,\n", - " **params,\n", + " **common_params,\n", " cooling_rate_K_min=cooling_rate_K_min\n", " )\n", " show_plot(f'fig2-c={cooling_rate_K_min}_K_per_min-ln_s_geom={ln_s_geom}.pdf')" @@ -28354,7 +28354,7 @@ "for ln_s_geom in (BEST_FIT_LN_S_GEOM, 5*BEST_FIT_LN_S_GEOM, 10*BEST_FIT_LN_S_GEOM): \n", " run_and_plot(\n", " **params,\n", - " ln_s_geom=ln_s_geom,\n", + " ln_s_geom_arg=ln_s_geom,\n", " times=np.asarray([0, dT / base_cooling_rate]),\n", " temps=np.asarray(list(TEMP_RANGE))\n", " )" @@ -39258,7 +39258,7 @@ "for cooling_rate in COOLING_RATES:\n", " run_and_plot(\n", " **params,\n", - " ln_s_geom=BEST_FIT_LN_S_GEOM,\n", + " ln_s_geom_arg=BEST_FIT_LN_S_GEOM,\n", " times=np.asarray([0, dT / cooling_rate]),\n", " temps=np.asarray(list(TEMP_RANGE))\n", " )" diff --git a/examples/PySDM_examples/Arabas_et_al_2023/figs_5_and_6.ipynb b/examples/PySDM_examples/Arabas_et_al_2023/figs_5_and_6.ipynb index 968a842c3..7345f6ebe 100644 --- a/examples/PySDM_examples/Arabas_et_al_2023/figs_5_and_6.ipynb +++ b/examples/PySDM_examples/Arabas_et_al_2023/figs_5_and_6.ipynb @@ -99,17 +99,17 @@ "outputs": [], "source": [ "output = {}\n", - "for label, temperature_profile in temperature_profiles.items():\n", - " output[label] = {}\n", - " for singular in (True, False):\n", - " output[label][singular] = []\n", + "for lbl, temperature_profile in temperature_profiles.items():\n", + " output[lbl] = {}\n", + " for singular_flag in (True, False):\n", + " output[lbl][singular_flag] = []\n", " for seed in range(ensemble_n):\n", " particulator = make_particulator(\n", " constants=constants,\n", " n_sd=n_sd, \n", " dt=temperature_profile.x[-1]/n_steps,\n", " initial_temperature = temperature_profile(0),\n", - " singular=singular,\n", + " singular=singular_flag,\n", " seed=seed,\n", " shima_T_fz=formulae.freezing_temperature_spectrum.__name__,\n", " ABIFM_spec=A_spec,\n", @@ -118,7 +118,7 @@ " volume=volume,\n", " thaw=True\n", " )\n", - " output[label][singular].append({\n", + " output[lbl][singular_flag].append({\n", " **run_simulation(particulator, temperature_profile, n_steps)\n", " })" ] @@ -131,19 +131,19 @@ "outputs": [], "source": [ "def setup_subplots():\n", - " fig, axs = pyplot.subplots(\n", + " fig, axes = pyplot.subplots(\n", " len(temperature_profiles)//2, 2,\n", " figsize=(12,9),\n", " sharex=True,\n", " tight_layout=True\n", " )\n", - " for axss in axs:\n", + " for axss in axes:\n", " for ax in axss:\n", " ax.set_xticks((0, 15, 30, 45, T_end_min))\n", " ax.grid()\n", - " for ax in (axs[-1][0], axs[-1][1]):\n", + " for ax in (axes[-1][0], axes[-1][1]):\n", " ax.set_xlabel(\"time [min]\") \n", - " return fig, axs" + " return fig, axes" ] }, { @@ -153,12 +153,12 @@ "metadata": {}, "outputs": [], "source": [ - "def plot_ff(ax, data, singular, label):\n", - " ax.grid()\n", - " ax.set_ylabel(\"frozen fraction [1]\", loc='bottom')\n", - " ax.set_ylim(-.05,1.5)\n", - " ax.set_yticks((0, .25, .5, .75, 1))\n", - " ax.plot(\n", + "def plot_ff(axes, data, singular, label):\n", + " axes.grid()\n", + " axes.set_ylabel(\"frozen fraction [1]\", loc='bottom')\n", + " axes.set_ylim(-.05,1.5)\n", + " axes.set_yticks((0, .25, .5, .75, 1))\n", + " axes.plot(\n", " np.asarray(data[\"products\"][\"t\"]) / si.min,\n", " [ff.qi2ff(qi) for qi in data[\"products\"][\"qi\"]],\n", " label=\"\" if not label else \"singular\" if singular else \"time-dependent\",\n", @@ -168,8 +168,8 @@ " markersize=1.5\n", " )\n", "\n", - "def plot_T(ax, data, label=\"\"):\n", - " twin = ax.twinx()\n", + "def plot_T(axes, data, label=\"\"):\n", + " twin = axes.twinx()\n", " twin.set_ylabel(\"T [K]\", color='red', loc='top')\n", " ticks = (240, 260, 280)\n", " twin.set_yticks(ticks=ticks, labels=[str(t) for t in ticks], color='red')\n", @@ -13257,18 +13257,18 @@ } ], "source": [ - "fig, axs = setup_subplots()\n", + "_, axs = setup_subplots()\n", "\n", - "for i, label in enumerate(temperature_profiles.keys()):\n", + "for i, lbl in enumerate(temperature_profiles.keys()):\n", " rr, cc = i // 2, i % 2\n", - " for singular in (True, False):\n", - " for r in range(len(output[label][singular])):\n", - " plot_ff(axs[rr, cc], output[label][singular][r], singular, label=r==0)\n", + " for singular_flag in (True, False):\n", + " for r in range(len(output[lbl][singular_flag])):\n", + " plot_ff(axs[rr, cc], output[lbl][singular_flag][r], singular_flag, label=r==0)\n", " \n", - " plot_T(axs[rr, cc], output[label][singular][0])\n", + " plot_T(axs[rr, cc], output[lbl][singular_flag][0])\n", " axs[rr, cc].text(\n", " -.12, .9,\n", - " '('+label+')',\n", + " '('+lbl+')',\n", " transform=axs[rr, cc].transAxes,\n", " size=15,\n", " weight='bold'\n", @@ -27006,7 +27006,7 @@ ], "source": [ "focus_realisation = 0\n", - "fig, axs = pyplot.subplots(\n", + "_, axs = pyplot.subplots(\n", " 3, 1,\n", " figsize=(12, 7.5),\n", " sharex=True,\n", @@ -27020,8 +27020,8 @@ "axs[_SIN].set_xlim(0, 70)\n", "axs[_SIN].set_xticks(np.linspace(0, T_end_min, 13, endpoint=True))\n", "axs[_SIN].set_xlabel(\"time [min]\")\n", - "\n", - "time = np.asarray(output['f'][singular][0][\"products\"][\"t\"]) / si.min\n", + "any_bool_value = True\n", + "time = np.asarray(output['f'][any_bool_value][0][\"products\"][\"t\"]) / si.min\n", "dt = time[1] - time[0]\n", "\n", "axs[_SIN].set_ylim(234, 247)\n", @@ -27041,25 +27041,25 @@ " axs[_SIN].twiny(),\n", " axs[_CNT].twiny()\n", ")\n", - "for ax in mlt:\n", - " ax.set_xlim(-21, 3.5)\n", + "for axis in mlt:\n", + " axis.set_xlim(-21, 3.5)\n", "mlt[0].set_xticks([])\n", "mlt[1].set_xticks((1, 2, 3))\n", "mlt[1].set_xlabel(\" \" * 212 + \"realisation\")\n", "\n", - "for ax in axs:\n", - " ax.axvline(x=T_end_min, color='black', linewidth=.75)\n", + "for axis in axs:\n", + " axis.axvline(x=T_end_min, color='black', linewidth=.75)\n", "\n", - "for singular in (True, False):\n", - " col = 0 if singular else 1\n", - " color = 'black' if singular else 'teal'\n", - " for r in range(len(output['f'][singular])):\n", - " data = output['f'][singular][r]\n", - " frozen = np.asarray(data[\"frozen\"]).T\n", + "for singular_flag in (True, False):\n", + " col = 0 if singular_flag else 1\n", + " color = 'black' if singular_flag else 'teal'\n", + " for r in range(len(output['f'][singular_flag])):\n", + " datum = output['f'][singular_flag][r]\n", + " frozen = np.asarray(datum[\"frozen\"]).T\n", " X = (\n", - " data['spectrum'][\"freezing temperature\"] \n", - " if singular else\n", - " data['spectrum'][\"immersed surface area\"] / si.um**2\n", + " datum['spectrum'][\"freezing temperature\"] \n", + " if singular_flag else\n", + " datum['spectrum'][\"immersed surface area\"] / si.um**2\n", " )\n", " \n", " mlt[col].scatter(\n", @@ -27084,20 +27084,20 @@ " for i in range(n_sd):\n", " Xi = np.repeat(X[i], len(time))\n", " for frz in (True, False):\n", - " axs[_SIN if singular else _CNT].plot(\n", + " axs[_SIN if singular_flag else _CNT].plot(\n", " time,\n", " np.where(frozen[i, :], Xi, np.nan) if frz else Xi,\n", " color=color,\n", " linewidth=1.5 if frz else .5\n", " )\n", " \n", - "def add_marginal(ax, spec, unit, color):\n", - " _y = np.linspace(*ax.get_ylim())\n", + "def add_marginal(axes, spec, unit, color_arg):\n", + " _y = np.linspace(*axes.get_ylim())\n", " _x = spec(_y * unit)\n", - " ax.plot(\n", - " T_end_min + _x * .95 * (ax.get_xlim()[1] - T_end_min) / max(_x),\n", + " axes.plot(\n", + " T_end_min + _x * .95 * (axes.get_xlim()[1] - T_end_min) / max(_x),\n", " _y,\n", - " color=color,\n", + " color=color_arg,\n", " linewidth=1.5,\n", " linestyle='--'\n", " )\n", @@ -27115,7 +27115,7 @@ " \n", "plot_ff(axs[_TFF], output['f'][True][focus_realisation], singular=True, label=True)\n", "plot_ff(axs[_TFF], output['f'][False][focus_realisation], singular=False, label=True)\n", - "plot_T(axs[_TFF], data)\n", + "plot_T(axs[_TFF], datum)\n", "axs[_TFF].grid(False)\n", "\n", "handles, labels = axs[_TFF].get_legend_handles_labels()\n", diff --git a/examples/PySDM_examples/Berry_1967/figs_5_8_10.ipynb b/examples/PySDM_examples/Berry_1967/figs_5_8_10.ipynb index 6aefd531a..36a8c892a 100644 --- a/examples/PySDM_examples/Berry_1967/figs_5_8_10.ipynb +++ b/examples/PySDM_examples/Berry_1967/figs_5_8_10.ipynb @@ -64,17 +64,17 @@ "metadata": {}, "outputs": [], "source": [ - "def demo(*, freezer, n_SD, n_step, n_plot, kernel, adaptive, smooth, gpu):\n", - " with freezer:\n", + "def demo(**kwargs):\n", + " with kwargs['freezer']:\n", " with errstate(all='raise'):\n", - " settings = Settings(steps=[i * (n_step // n_plot) for i in range(n_plot + 1)])\n", - " backend = GPU if gpu else CPU\n", - " settings.n_sd = 2 ** n_SD\n", - " settings.adaptive = adaptive\n", - " settings.dt = 10 if adaptive else settings.dt\n", - " if kernel == 'geometric sweep-out':\n", + " settings = Settings(steps=[i * (kwargs['n_step'] // kwargs['n_plot']) for i in range(kwargs['n_plot'] + 1)])\n", + " backend = GPU if kwargs['gpu'] else CPU\n", + " settings.n_sd = 2 ** kwargs['n_SD']\n", + " settings.adaptive = kwargs['adaptive']\n", + " settings.dt = 10 if settings.adaptive else settings.dt\n", + " if kwargs['kernel'] == 'geometric sweep-out':\n", " settings.kernel = Geometric()\n", - " elif kernel == 'electric field 3000V/cm':\n", + " elif kwargs['kernel'] == 'electric field 3000V/cm':\n", " settings.kernel = Electric()\n", " else:\n", " settings.kernel = Hydrodynamic()\n", @@ -83,7 +83,7 @@ "\n", " with errstate(invalid='ignore'):\n", " plotter = SpectrumPlotter(settings)\n", - " plotter.smooth = smooth\n", + " plotter.smooth = kwargs['smooth']\n", " for step, state in states.items():\n", " plotter.plot(state, step * settings.dt)\n", " plotter.show()" diff --git a/examples/PySDM_examples/Grabowski_and_Pawlowska_2023/figure_1.ipynb b/examples/PySDM_examples/Grabowski_and_Pawlowska_2023/figure_1.ipynb index 16e5353da..f3a518ead 100644 --- a/examples/PySDM_examples/Grabowski_and_Pawlowska_2023/figure_1.ipynb +++ b/examples/PySDM_examples/Grabowski_and_Pawlowska_2023/figure_1.ipynb @@ -126,52 +126,52 @@ ], "source": [ "# pylint: disable=too-many-arguments\n", - "def plot_R(ax,output_vol,output_crit_vol,output_z,k):\n", + "def plot_R(axes, output_vol, output_crit_vol, output_z, k):\n", " for drop_id, volume in enumerate(output_vol):\n", " if drop_id%k==0:\n", " if TRIVIA.radius(volume=volume)[10]>0.03*si.um:\n", " crit_volume=output_crit_vol[drop_id]\n", " if np.all(volume0.03*si.um:\n", " if np.all(volume0.03*si.um:\n", " crit_volume=output_crit_vol[drop_id]\n", " if np.all(volume0.03*si.um:\n", " if np.all(volume r_cr)\", color='black')\n", - " ax[i].plot(output['t'], output[\"r_mean_gt_1_um\"], label=\"r_mean (r > 1 um)\", linestyle='--', color='gray')\n", + " ax[i].plot(out['t'], out[\"r_act\"], label=\"r_mean (r > r_cr)\", color='black')\n", + " ax[i].plot(out['t'], out[\"r_mean_gt_1_um\"], label=\"r_mean (r > 1 um)\", linestyle='--', color='gray')\n", " ax[i].legend(loc='best')\n", " ax[i].grid()\n", " plt.tight_layout()\n", diff --git a/examples/PySDM_examples/deJong_Mackay_et_al_2023/figs_10_11_12_13.ipynb b/examples/PySDM_examples/deJong_Mackay_et_al_2023/figs_10_11_12_13.ipynb index 201edd921..40f70dae5 100644 --- a/examples/PySDM_examples/deJong_Mackay_et_al_2023/figs_10_11_12_13.ipynb +++ b/examples/PySDM_examples/deJong_Mackay_et_al_2023/figs_10_11_12_13.ipynb @@ -68,13 +68,13 @@ "\n", "if restore_saved_data:\n", " settings = {}\n", - " for breakup in (False, True):\n", - " for stochastic_breakup in (True, False) if breakup else (False,):\n", - " key = gen_key(breakup=breakup, stochastic_breakup=stochastic_breakup)\n", + " for breakup_flag in (False, True):\n", + " for stochastic_breakup_flag in (True, False) if breakup_flag else (False,):\n", + " key = gen_key(breakup=breakup_flag, stochastic_breakup=stochastic_breakup_flag)\n", " settings[key] = Settings1D(\n", " **common_params,\n", - " breakup=breakup,\n", - " stochastic_breakup=stochastic_breakup\n", + " breakup=breakup_flag,\n", + " stochastic_breakup=stochastic_breakup_flag\n", " )\n", " import pickle as pkl\n", " with open('data1d.pkl','rb') as file:\n", @@ -83,13 +83,13 @@ " output = {}\n", " settings = {}\n", " simulation = {}\n", - " for breakup in (False, True):\n", - " for stochastic_breakup in (True, False) if breakup else (False,):\n", - " key = gen_key(breakup=breakup, stochastic_breakup=stochastic_breakup)\n", + " for breakup_flag in (False, True):\n", + " for stochastic_breakup_flag in (True, False) if breakup_flag else (False,):\n", + " key = gen_key(breakup=breakup_flag, stochastic_breakup=stochastic_breakup_flag)\n", " settings[key] = Settings1D(\n", " **common_params,\n", - " breakup=breakup,\n", - " stochastic_breakup=stochastic_breakup\n", + " breakup=breakup_flag,\n", + " stochastic_breakup=stochastic_breakup_flag\n", " )\n", " simulation[key] = Simulation1D(settings[key])\n", " output[key] = simulation[key].run().products\n", @@ -149,9 +149,9 @@ " ax[1][0].text(-750, 0.5, f'{rates[1]} Rate [{rate_unit}]', rotation='vertical', weight='bold')\n", " ax[2][0].text(-750, 0.5, f'{rates[2]} Rate [{rate_unit}]', rotation='vertical', weight='bold')\n", "\n", - "def plot_spectra(ax, key, t_sel):\n", + "def plot_spectra(ax, key_arg, t_sel):\n", " spct_step = common_params['save_spec_at'].index(t_sel)\n", - " ax.step(settings[key].r_bins_edges[0:-1] / si.um, output[key]['dvdlnr'].mean(axis=0)[:,spct_step] / si.cm**3,label=str(spct_step))\n", + " ax.step(settings[key_arg].r_bins_edges[0:-1] / si.um, output[key_arg]['dvdlnr'].mean(axis=0)[:,spct_step] / si.cm**3,label=str(spct_step))\n", " ax.set_xscale('log')\n", " ax.set_xlim([1e0, 1e4])\n", " ax.set_xlabel(r\"particle radius ($\\mu$m)\")\n", @@ -175,25 +175,25 @@ "outputs": [], "source": [ "# Hydrometeors\n", - "(fig, ax) = fig_ax()\n", + "fig, axes = fig_ax()\n", "\n", "key = gen_key(breakup=False, stochastic_breakup=False)\n", - "plot_ax(ax[0][0], output=output[key], **kwargs['cloud water mixing ratio'])\n", - "plot_ax(ax[1][0], output=output[key], **kwargs['rain water mixing ratio'])\n", - "plot_ax(ax[2][0], output=output[key], **kwargs['na'])\n", + "plot_ax(axes[0][0], output=output[key], **kwargs['cloud water mixing ratio'])\n", + "plot_ax(axes[1][0], output=output[key], **kwargs['rain water mixing ratio'])\n", + "plot_ax(axes[2][0], output=output[key], **kwargs['na'])\n", "\n", "key = gen_key(breakup=True, stochastic_breakup=False)\n", - "plot_ax(ax[0][1], output=output[key], **kwargs['cloud water mixing ratio'])\n", - "plot_ax(ax[1][1], output=output[key], **kwargs['rain water mixing ratio'])\n", - "plot_ax(ax[2][1], output=output[key], **kwargs['na'])\n", + "plot_ax(axes[0][1], output=output[key], **kwargs['cloud water mixing ratio'])\n", + "plot_ax(axes[1][1], output=output[key], **kwargs['rain water mixing ratio'])\n", + "plot_ax(axes[2][1], output=output[key], **kwargs['na'])\n", "\n", "key = gen_key(breakup=True, stochastic_breakup=True)\n", - "plot_ax(ax[0][2], output=output[key], **kwargs['cloud water mixing ratio'])\n", - "plot_ax(ax[1][2], output=output[key], **kwargs['rain water mixing ratio'])\n", - "plot_ax(ax[2][2], output=output[key], **kwargs['na'])\n", + "plot_ax(axes[0][2], output=output[key], **kwargs['cloud water mixing ratio'])\n", + "plot_ax(axes[1][2], output=output[key], **kwargs['rain water mixing ratio'])\n", + "plot_ax(axes[2][2], output=output[key], **kwargs['na'])\n", "\n", - "add_ylabels_qn(ax)\n", - "add_titles(ax)\n", + "add_ylabels_qn(axes)\n", + "add_titles(axes)\n", "plt.tight_layout()\n", "show_plot(\"fig10_hydrometeors.pdf\", inline_format=inline_format)" ] @@ -205,25 +205,21 @@ "outputs": [], "source": [ "# Spectra\n", - "(fig, ax) = fig_ax_spectra()\n", + "fig, axes = fig_ax_spectra()\n", "\n", - "for breakup in (False, True):\n", - " for stochastic_breakup in (False, True) if breakup else (False,):\n", - " key = gen_key(breakup=breakup, stochastic_breakup=stochastic_breakup)\n", + "for breakup_flag in (False, True):\n", + " for stochastic_breakup_flag in (False, True) if breakup_flag else (False,):\n", + " key = gen_key(breakup=breakup_flag, stochastic_breakup=stochastic_breakup_flag)\n", "\n", - " t_sel = 600 * si.s\n", - " plot_spectra(ax[0][0], key, t_sel)\n", + " plot_spectra(axes[0][0], key, t_sel=600 * si.s)\n", "\n", - " t_sel = 900 * si.s\n", - " plot_spectra(ax[0][1], key, t_sel)\n", + " plot_spectra(axes[0][1], key, t_sel=900 * si.s)\n", "\n", - " t_sel = 1200 * si.s\n", - " plot_spectra(ax[1][0], key, t_sel)\n", + " plot_spectra(axes[1][0], key, t_sel=1200 * si.s)\n", "\n", - " t_sel = 1800 * si.s\n", - " plot_spectra(ax[1][1], key, t_sel)\n", + " plot_spectra(axes[1][1], key, t_sel=1800 * si.s)\n", "\n", - "add_spectra_legend(ax[0][0])\n", + "add_spectra_legend(axes[0][0])\n", "plt.tight_layout()\n", "show_plot('fig11_spectra_from_1d.pdf', inline_format = inline_format)" ] @@ -235,25 +231,25 @@ "outputs": [], "source": [ "# Rates\n", - "(fig, ax) = fig_ax()\n", + "fig, axes = fig_ax()\n", "\n", "key = gen_key(breakup=False, stochastic_breakup=False)\n", - "plot_ax(ax[0][0], output=output[key], **contour_args, **kwargs['coll_rate'])\n", - "plot_ax(ax[1][0], output=output[key], **contour_args, **kwargs['coal_rate'])\n", - "plot_zeros_ax(ax[2][0], output=output[key], **kwargs['brkp_zero'])\n", + "plot_ax(axes[0][0], output=output[key], **contour_args, **kwargs['coll_rate'])\n", + "plot_ax(axes[1][0], output=output[key], **contour_args, **kwargs['coal_rate'])\n", + "plot_zeros_ax(axes[2][0], output=output[key], **kwargs['brkp_zero'])\n", "\n", "key = gen_key(breakup=True, stochastic_breakup=False)\n", - "plot_ax(ax[0][1], output=output[key], **contour_args, **kwargs['coll_rate'])\n", - "plot_ax(ax[1][1], output=output[key], **contour_args, **kwargs['coal_rate'])\n", - "plot_ax(ax[2][1], output=output[key], **contour_args, **kwargs['brkp_rate'])\n", + "plot_ax(axes[0][1], output=output[key], **contour_args, **kwargs['coll_rate'])\n", + "plot_ax(axes[1][1], output=output[key], **contour_args, **kwargs['coal_rate'])\n", + "plot_ax(axes[2][1], output=output[key], **contour_args, **kwargs['brkp_rate'])\n", "\n", "key = gen_key(breakup=True, stochastic_breakup=True)\n", - "plot_ax(ax[0][2], output=output[key], **contour_args, **kwargs['coll_rate'])\n", - "plot_ax(ax[1][2], output=output[key], **contour_args, **kwargs['coal_rate'])\n", - "plot_ax(ax[2][2], output=output[key], **contour_args, **kwargs['brkp_rate'])\n", + "plot_ax(axes[0][2], output=output[key], **contour_args, **kwargs['coll_rate'])\n", + "plot_ax(axes[1][2], output=output[key], **contour_args, **kwargs['coal_rate'])\n", + "plot_ax(axes[2][2], output=output[key], **contour_args, **kwargs['brkp_rate'])\n", "\n", - "add_ylabels_rates(ax, ('Collision', 'Coalescence', 'Breakup'))\n", - "add_titles(ax)\n", + "add_ylabels_rates(axes, ('Collision', 'Coalescence', 'Breakup'))\n", + "add_titles(axes)\n", "plt.tight_layout()\n", "show_plot(\"fig12_collision_rates.pdf\", inline_format=inline_format)" ] @@ -265,25 +261,25 @@ "outputs": [], "source": [ "# Aerosol rates\n", - "(fig, ax) = fig_ax()\n", + "fig, axes = fig_ax()\n", "\n", "key = gen_key(breakup=False, stochastic_breakup=False)\n", - "plot_ax(ax[0][0], output=output[key], **contour_args, **kwargs['rpng_rate'])\n", - "plot_ax(ax[1][0], output=output[key], **contour_args, **kwargs['actv_rate'])\n", - "plot_ax(ax[2][0], output=output[key], **contour_args, **kwargs['dctv_rate'])\n", + "plot_ax(axes[0][0], output=output[key], **contour_args, **kwargs['rpng_rate'])\n", + "plot_ax(axes[1][0], output=output[key], **contour_args, **kwargs['actv_rate'])\n", + "plot_ax(axes[2][0], output=output[key], **contour_args, **kwargs['dctv_rate'])\n", "\n", "key = gen_key(breakup=True, stochastic_breakup=False)\n", - "plot_ax(ax[0][1], output=output[key], **contour_args, **kwargs['rpng_rate'])\n", - "plot_ax(ax[1][1], output=output[key], **contour_args, **kwargs['actv_rate'])\n", - "plot_ax(ax[2][1], output=output[key], **contour_args, **kwargs['dctv_rate'])\n", + "plot_ax(axes[0][1], output=output[key], **contour_args, **kwargs['rpng_rate'])\n", + "plot_ax(axes[1][1], output=output[key], **contour_args, **kwargs['actv_rate'])\n", + "plot_ax(axes[2][1], output=output[key], **contour_args, **kwargs['dctv_rate'])\n", "\n", "key = gen_key(breakup=True, stochastic_breakup=True)\n", - "plot_ax(ax[0][2], output=output[key], **contour_args, **kwargs['rpng_rate'])\n", - "plot_ax(ax[1][2], output=output[key], **contour_args, **kwargs['actv_rate'])\n", - "plot_ax(ax[2][2], output=output[key], **contour_args, **kwargs['dctv_rate'])\n", + "plot_ax(axes[0][2], output=output[key], **contour_args, **kwargs['rpng_rate'])\n", + "plot_ax(axes[1][2], output=output[key], **contour_args, **kwargs['actv_rate'])\n", + "plot_ax(axes[2][2], output=output[key], **contour_args, **kwargs['dctv_rate'])\n", "\n", - "add_ylabels_rates(ax, ('Ripening', 'Activating', 'Deactivating'))\n", - "add_titles(ax)\n", + "add_ylabels_rates(axes, ('Ripening', 'Activating', 'Deactivating'))\n", + "add_titles(axes)\n", "plt.tight_layout()\n", "show_plot(\"fig13_aerosol_rates.pdf\", inline_format=inline_format)" ] diff --git a/tests/smoke_tests/box/dejong_and_mackay_et_al_2023/test_fig_6.py b/tests/smoke_tests/box/dejong_and_mackay_et_al_2023/test_fig_6.py index 71fcc1497..70bb7df5f 100644 --- a/tests/smoke_tests/box/dejong_and_mackay_et_al_2023/test_fig_6.py +++ b/tests/smoke_tests/box/dejong_and_mackay_et_al_2023/test_fig_6.py @@ -17,7 +17,6 @@ N_SD = 2**10 -# pylint: disable=redefined-outer-name @pytest.mark.parametrize( "backend_class", (CPU, pytest.param(GPU, marks=pytest.mark.xfail(strict=True))), # TODO #987 diff --git a/tests/smoke_tests/box/dejong_and_mackay_et_al_2023/test_fig_8.py b/tests/smoke_tests/box/dejong_and_mackay_et_al_2023/test_fig_8.py index a650a7334..483e5015d 100644 --- a/tests/smoke_tests/box/dejong_and_mackay_et_al_2023/test_fig_8.py +++ b/tests/smoke_tests/box/dejong_and_mackay_et_al_2023/test_fig_8.py @@ -11,7 +11,6 @@ from PySDM.physics import si -# pylint: disable=redefined-outer-name @pytest.mark.parametrize( "backend_class", (CPU, pytest.param(GPU, marks=pytest.mark.xfail(strict=True))), # TODO #987 diff --git a/tests/smoke_tests/kinematic_1d/shipway_and_hill_2012/test_1d_exporters.py b/tests/smoke_tests/kinematic_1d/shipway_and_hill_2012/test_1d_exporters.py index 57a5796fd..f712ff7f2 100644 --- a/tests/smoke_tests/kinematic_1d/shipway_and_hill_2012/test_1d_exporters.py +++ b/tests/smoke_tests/kinematic_1d/shipway_and_hill_2012/test_1d_exporters.py @@ -1,4 +1,4 @@ -# pylint: disable = missing-module-docstring,missing-class-docstring,missing-function-docstring,redefined-outer-name +# pylint: disable = missing-module-docstring,missing-class-docstring,missing-function-docstring import os import platform from tempfile import TemporaryDirectory @@ -13,8 +13,8 @@ from PySDM.physics import si -@pytest.fixture -def simulation_1d(): +@pytest.fixture(name="simulation_1d") +def simulation_1d_fixture(): n_sd_per_gridbox = 16 settings = Settings( n_sd_per_gridbox=n_sd_per_gridbox, diff --git a/tests/smoke_tests/kinematic_2d/arabas_et_al_2015/test_adaptive_displacement.py b/tests/smoke_tests/kinematic_2d/arabas_et_al_2015/test_adaptive_displacement.py index 989123f86..01e1f8c8c 100644 --- a/tests/smoke_tests/kinematic_2d/arabas_et_al_2015/test_adaptive_displacement.py +++ b/tests/smoke_tests/kinematic_2d/arabas_et_al_2015/test_adaptive_displacement.py @@ -22,7 +22,6 @@ pytest.param(1e-2), ), ) -# pylint: disable=redefined-outer-name def test_adaptive_displacement(rtol, plot=False): # Arrange settings = Settings(formulae=Formulae(seed=666)) diff --git a/tests/smoke_tests/kinematic_2d/arabas_et_al_2015/test_freezing.py b/tests/smoke_tests/kinematic_2d/arabas_et_al_2015/test_freezing.py index 3aac470bc..744fd645c 100644 --- a/tests/smoke_tests/kinematic_2d/arabas_et_al_2015/test_freezing.py +++ b/tests/smoke_tests/kinematic_2d/arabas_et_al_2015/test_freezing.py @@ -17,7 +17,6 @@ pytest.param(True, id="singular: True"), ), ) -# pylint: disable=redefined-outer-name def test_freezing(singular): # Arrange settings = Settings( diff --git a/tests/smoke_tests/parcel/kreidenweis_et_al_2003/test_fig_1.py b/tests/smoke_tests/parcel/kreidenweis_et_al_2003/test_fig_1.py index 7efdd54dc..78522c969 100644 --- a/tests/smoke_tests/parcel/kreidenweis_et_al_2003/test_fig_1.py +++ b/tests/smoke_tests/parcel/kreidenweis_et_al_2003/test_fig_1.py @@ -8,8 +8,8 @@ from PySDM.physics import si -@pytest.fixture(scope="session") -def example_output(): +@pytest.fixture(scope="session", name="example_output") +def example_output_fixture(): settings = Settings(n_sd=16, dt=1 * si.s, n_substep=5) simulation = Simulation(settings) output = simulation.run() @@ -21,7 +21,6 @@ def example_output(): class TestFig1: @staticmethod - # pylint: disable=redefined-outer-name def test_a(example_output, plot=False): # Plot if plot: @@ -37,7 +36,6 @@ def test_a(example_output, plot=False): assert (np.diff(example_output["liquid water mixing ratio"]) >= 0).all() @staticmethod - # pylint: disable=redefined-outer-name def test_b(example_output, plot=False): # Plot if plot: @@ -81,7 +79,6 @@ def test_b(example_output, plot=False): ) @staticmethod - # pylint: disable=redefined-outer-name def test_c(example_output, plot=False): if plot: pyplot.plot( diff --git a/tests/smoke_tests/parcel/lowe_et_al_2019/constants.py b/tests/smoke_tests/parcel/lowe_et_al_2019/conftest.py similarity index 89% rename from tests/smoke_tests/parcel/lowe_et_al_2019/constants.py rename to tests/smoke_tests/parcel/lowe_et_al_2019/conftest.py index 4d6cfca68..9f4322e22 100644 --- a/tests/smoke_tests/parcel/lowe_et_al_2019/constants.py +++ b/tests/smoke_tests/parcel/lowe_et_al_2019/conftest.py @@ -6,8 +6,8 @@ from PySDM.physics.surface_tension import compressed_film_ovadnevaite -@pytest.fixture() -def constants(): +@pytest.fixture(name="constants") +def constants_fixture(): compressed_film_ovadnevaite.sgm_org = 40 * si.mN / si.m # TODO #604 0.2 in the paper, but 0.1 matches the paper plots compressed_film_ovadnevaite.delta_min = 0.1 * si.nm diff --git a/tests/smoke_tests/parcel/lowe_et_al_2019/test_fig_1.py b/tests/smoke_tests/parcel/lowe_et_al_2019/test_fig_1.py index c89d71e9c..a1218f2e9 100644 --- a/tests/smoke_tests/parcel/lowe_et_al_2019/test_fig_1.py +++ b/tests/smoke_tests/parcel/lowe_et_al_2019/test_fig_1.py @@ -1,17 +1,13 @@ # pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import numpy as np import pytest -from PySDM_examples.Lowe_et_al_2019 import aerosol +from PySDM_examples.Lowe_et_al_2019 import aerosol as paper_aerosol from scipy import signal from PySDM import Formulae from PySDM.physics import constants_defaults as const from PySDM.physics import si -from .constants import constants - -assert hasattr(constants, "_pytestfixturefunction") - TRIVIA = Formulae().trivia R_WET = np.logspace(np.log(150 * si.nm), np.log(3000 * si.nm), base=np.e, num=100) R_DRY = 50 * si.nm @@ -40,12 +36,12 @@ def test_bulk_surface_tension_is_sgm_w(): @pytest.mark.parametrize( "aerosol, cutoff", ( - (aerosol.AerosolBoreal(), 560 * si.nm), - (aerosol.AerosolMarine(), 380 * si.nm), - (aerosol.AerosolNascent(), 500 * si.nm), + (paper_aerosol.AerosolBoreal(), 560 * si.nm), + (paper_aerosol.AerosolMarine(), 380 * si.nm), + (paper_aerosol.AerosolNascent(), 500 * si.nm), ), ) - # pylint: disable=redefined-outer-name,unused-argument + # pylint: disable=unused-argument def test_kink_location(constants, aerosol, cutoff): # arrange formulae = Formulae( @@ -68,25 +64,25 @@ def test_kink_location(constants, aerosol, cutoff): @pytest.mark.parametrize( "aerosol, surface_tension, maximum_x, maximum_y, bimodal", ( - (aerosol.AerosolBoreal(), "Constant", 320 * si.nm, 0.217, False), - (aerosol.AerosolMarine(), "Constant", 420 * si.nm, 0.164, False), - (aerosol.AerosolNascent(), "Constant", 360 * si.nm, 0.194, False), + (paper_aerosol.AerosolBoreal(), "Constant", 320 * si.nm, 0.217, False), + (paper_aerosol.AerosolMarine(), "Constant", 420 * si.nm, 0.164, False), + (paper_aerosol.AerosolNascent(), "Constant", 360 * si.nm, 0.194, False), ( - aerosol.AerosolBoreal(), + paper_aerosol.AerosolBoreal(), "CompressedFilmOvadnevaite", 360 * si.nm, 0.108, True, ), ( - aerosol.AerosolMarine(), + paper_aerosol.AerosolMarine(), "CompressedFilmOvadnevaite", 600 * si.nm, 0.115, False, ), ( - aerosol.AerosolNascent(), + paper_aerosol.AerosolNascent(), "CompressedFilmOvadnevaite", 670 * si.nm, 0.104, @@ -94,10 +90,7 @@ def test_kink_location(constants, aerosol, cutoff): ), ), ) - # pylint: disable=redefined-outer-name,unused-argument - def test_koehler_maxima( - *, constants, aerosol, surface_tension, maximum_x, maximum_y, bimodal - ): + def test_koehler_maxima(*, aerosol, surface_tension, maximum_x, maximum_y, bimodal): # arrange formulae = Formulae( surface_tension=surface_tension, diff --git a/tests/smoke_tests/parcel/lowe_et_al_2019/test_fig_2.py b/tests/smoke_tests/parcel/lowe_et_al_2019/test_fig_2.py index b9bb73665..e80b32554 100644 --- a/tests/smoke_tests/parcel/lowe_et_al_2019/test_fig_2.py +++ b/tests/smoke_tests/parcel/lowe_et_al_2019/test_fig_2.py @@ -1,33 +1,47 @@ # pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import numpy as np import pytest -from PySDM_examples.Lowe_et_al_2019 import Settings, Simulation, aerosol +from PySDM_examples.Lowe_et_al_2019 import Settings, Simulation +from PySDM_examples.Lowe_et_al_2019 import aerosol as paper_aerosol from PySDM.initialisation.sampling import spectral_sampling from PySDM.physics import si -from .constants import constants - -assert hasattr(constants, "_pytestfixturefunction") - class TestFig2: # pylint: disable=too-few-public-methods @staticmethod @pytest.mark.parametrize( "aerosol, surface_tension, s_max, s_100m, n_100m", ( - (aerosol.AerosolMarine(), "Constant", 0.271, 0.081, 148), - (aerosol.AerosolMarine(), "CompressedFilmOvadnevaite", 0.250, 0.075, 169), - (aerosol.AerosolBoreal(), "Constant", 0.182, 0.055, 422), - (aerosol.AerosolBoreal(), "CompressedFilmOvadnevaite", 0.137, 0.055, 525), - (aerosol.AerosolNascent(), "Constant", 0.407, 0.122, 68), - (aerosol.AerosolNascent(), "CompressedFilmOvadnevaite", 0.314, 0.076, 166), + (paper_aerosol.AerosolMarine(), "Constant", 0.271, 0.081, 148), + ( + paper_aerosol.AerosolMarine(), + "CompressedFilmOvadnevaite", + 0.250, + 0.075, + 169, + ), + (paper_aerosol.AerosolBoreal(), "Constant", 0.182, 0.055, 422), + ( + paper_aerosol.AerosolBoreal(), + "CompressedFilmOvadnevaite", + 0.137, + 0.055, + 525, + ), + (paper_aerosol.AerosolNascent(), "Constant", 0.407, 0.122, 68), + ( + paper_aerosol.AerosolNascent(), + "CompressedFilmOvadnevaite", + 0.314, + 0.076, + 166, + ), ), ) @pytest.mark.xfail(strict=True) # TODO #604 - # pylint: disable=redefined-outer-name,unused-argument def test_peak_supersaturation_and_final_concentration( - *, constants, aerosol, surface_tension, s_max, s_100m, n_100m + *, aerosol, surface_tension, s_max, s_100m, n_100m ): # arrange dt = 1 * si.s diff --git a/tests/smoke_tests/parcel/lowe_et_al_2019/test_surface_tension_models.py b/tests/smoke_tests/parcel/lowe_et_al_2019/test_surface_tension_models.py index 778a7b372..49289ce34 100644 --- a/tests/smoke_tests/parcel/lowe_et_al_2019/test_surface_tension_models.py +++ b/tests/smoke_tests/parcel/lowe_et_al_2019/test_surface_tension_models.py @@ -6,10 +6,6 @@ from PySDM.physics import constants_defaults as const from PySDM.physics import si -from .constants import constants - -assert hasattr(constants, "_pytestfixturefunction") - TRIVIA = Formulae().trivia R_WET = np.logspace(np.log(150 * si.nm), np.log(3000 * si.nm), base=np.e, num=100) R_DRY = 50 * si.nm diff --git a/tests/unit_tests/backends/storage/test_setitem.py b/tests/unit_tests/backends/storage/test_setitem.py index 758ac54ce..99e19b6f4 100644 --- a/tests/unit_tests/backends/storage/test_setitem.py +++ b/tests/unit_tests/backends/storage/test_setitem.py @@ -8,7 +8,6 @@ @pytest.mark.parametrize( "backend", (pytest.param(GPU, marks=pytest.mark.xfail(strict=True)), CPU) ) -# pylint: disable=redefined-outer-name def test_setitem(backend): # arrange arr = backend.Storage.from_ndarray(np.zeros(3)) diff --git a/tests/unit_tests/dynamics/collisions/__parametrisation__.py b/tests/unit_tests/dynamics/collisions/conftest.py similarity index 90% rename from tests/unit_tests/dynamics/collisions/__parametrisation__.py rename to tests/unit_tests/dynamics/collisions/conftest.py index 2e9c26251..710e950d7 100644 --- a/tests/unit_tests/dynamics/collisions/__parametrisation__.py +++ b/tests/unit_tests/dynamics/collisions/conftest.py @@ -63,13 +63,13 @@ def get_dummy_particulator_and_coalescence( } -@pytest.fixture(params=[__x__["ones_2"], __x__["random_2"]]) -def v_2(request): +@pytest.fixture(params=[__x__["ones_2"], __x__["random_2"]], name="v_2") +def v_2_fixture(request): return request.param -@pytest.fixture(params=[__x__["ones_2"], __x__["random_2"]]) -def T_2(request): +@pytest.fixture(params=[__x__["ones_2"], __x__["random_2"]], name="T_2") +def T_2_fixture(request): return request.param @@ -80,6 +80,6 @@ def T_2(request): } -@pytest.fixture(params=[__n__["1_1"], __n__["5_1"], __n__["5_3"]]) -def n_2(request): +@pytest.fixture(params=[__n__["1_1"], __n__["5_1"], __n__["5_3"]], name="n_2") +def n_2_fixture(request): return request.param diff --git a/tests/unit_tests/dynamics/collisions/test_efficiencies.py b/tests/unit_tests/dynamics/collisions/test_efficiencies.py index 3e3f36e71..b924df7c2 100644 --- a/tests/unit_tests/dynamics/collisions/test_efficiencies.py +++ b/tests/unit_tests/dynamics/collisions/test_efficiencies.py @@ -64,7 +64,7 @@ def test_efficiency_fn_call(efficiency, backend_class=CPU): ], ) def test_efficiency_dist(efficiency, backend_class=CPU, plot=False): - # pylint: disable=redefined-outer-name, too-many-locals, unnecessary-lambda-assignment + # pylint: disable=too-many-locals, unnecessary-lambda-assignment # arrange n_per = 20 diff --git a/tests/unit_tests/dynamics/collisions/test_sdm_multi_cell.py b/tests/unit_tests/dynamics/collisions/test_sdm_multi_cell.py index 0f879387a..140796890 100644 --- a/tests/unit_tests/dynamics/collisions/test_sdm_multi_cell.py +++ b/tests/unit_tests/dynamics/collisions/test_sdm_multi_cell.py @@ -8,7 +8,7 @@ from PySDM.impl.mesh import Mesh from PySDM.initialisation.sampling.spatial_sampling import Pseudorandom -from .__parametrisation__ import get_dummy_particulator_and_coalescence +from .conftest import get_dummy_particulator_and_coalescence class TestSDMMultiCell: # pylint: disable=too-few-public-methods diff --git a/tests/unit_tests/dynamics/collisions/test_sdm_single_cell.py b/tests/unit_tests/dynamics/collisions/test_sdm_single_cell.py index c4d8826ad..3bf824e43 100644 --- a/tests/unit_tests/dynamics/collisions/test_sdm_single_cell.py +++ b/tests/unit_tests/dynamics/collisions/test_sdm_single_cell.py @@ -8,24 +8,12 @@ from PySDM.backends.impl_common.pair_indicator import make_PairIndicator from PySDM.dynamics import Coalescence -from .__parametrisation__ import ( - T_2, - backend_fill, - get_dummy_particulator_and_coalescence, - n_2, - v_2, -) - -assert hasattr(v_2, "_pytestfixturefunction") -assert hasattr(T_2, "_pytestfixturefunction") -assert hasattr(n_2, "_pytestfixturefunction") +from .conftest import backend_fill, get_dummy_particulator_and_coalescence class TestSDMSingleCell: @staticmethod - def test_single_collision( - backend_class, v_2, T_2, n_2 - ): # pylint: disable=redefined-outer-name + def test_single_collision(backend_class, v_2, T_2, n_2): # Arrange const = 1.0 particulator, sut = get_dummy_particulator_and_coalescence( @@ -114,9 +102,7 @@ def test_single_collision_same_n(backend_class, n_in, n_out): pytest.param(7), ], ) - def test_multi_collision( - backend_class, v_2, n_2, p - ): # pylint: disable=redefined-outer-name + def test_multi_collision(backend_class, v_2, n_2, p): # Arrange particulator, sut = get_dummy_particulator_and_coalescence( backend_class, len(n_2) diff --git a/tests/unit_tests/initialisation/test_equilibrate_wet_radii.py b/tests/unit_tests/initialisation/test_equilibrate_wet_radii.py index d476e51b0..82881ea6e 100644 --- a/tests/unit_tests/initialisation/test_equilibrate_wet_radii.py +++ b/tests/unit_tests/initialisation/test_equilibrate_wet_radii.py @@ -14,7 +14,6 @@ @pytest.mark.parametrize( "surface_tension", ("Constant", "CompressedFilmOvadnevaite", "SzyszkowskiLangmuir") ) -# pylint: disable=unused-argument,redefined-outer-name def test_equilibrate_wet_radii(r_dry, surface_tension, plot=False): # Arrange T = 280.0 diff --git a/tests/unit_tests/products/test_impl.py b/tests/unit_tests/products/test_impl.py index 4779e7e95..bdc1079f6 100644 --- a/tests/unit_tests/products/test_impl.py +++ b/tests/unit_tests/products/test_impl.py @@ -74,15 +74,15 @@ params=( pytest.param(p[1], id=p[0]) for p in inspect.getmembers(sys.modules[products.__name__], inspect.isclass) - ) + ), + name="product", ) -def product(request): +def product_fixture(request): return request.param class TestProducts: @staticmethod - # pylint: disable=redefined-outer-name def test_instantiate_all(product): product(**(_ARGUMENTS[product] if product in _ARGUMENTS else {}))