Skip to content

Commit 1432243

Browse files
committed
final linting rules and fixes
1 parent 7521c99 commit 1432243

File tree

17 files changed

+92
-66
lines changed

17 files changed

+92
-66
lines changed

examples/demo_lhc_setup.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@
8383
opticsfile="acc-models-lhc/operation/optics/R2022a_A30cmC30cmA10mL200cm.madx",
8484
stdout=False,
8585
)
86-
df = twiss.get_twiss_tfs(madx)
87-
ips = get_lhc_ips_positions(df)
86+
twiss_df = twiss.get_twiss_tfs(madx)
87+
ips = get_lhc_ips_positions(twiss_df)
8888

8989
with plt.rc_context(_SPHINX_GALLERY_PARAMS):
9090
fig, ax = plt.subplots(figsize=(18, 10))
91-
ax.plot(df.S, df.BETX / 1e3, label=r"$\beta_x$")
92-
ax.plot(df.S, df.BETY / 1e3, label=r"$\beta_y$")
91+
ax.plot(twiss_df.S, twiss_df.BETX / 1e3, label=r"$\beta_x$")
92+
ax.plot(twiss_df.S, twiss_df.BETY / 1e3, label=r"$\beta_y$")
9393
draw_ip_locations(ips)
9494
ax.set_xlabel("Longitudinal location [m]")
9595
ax.set_ylabel(r"$\beta_{x,y}$ [km]")
@@ -111,13 +111,13 @@
111111
# above becomes:
112112

113113
with lhc.LHCSetup(run=3, opticsfile="R2022a_A30cmC30cmA10mL200cm.madx", stdout=False) as madx:
114-
df = twiss.get_twiss_tfs(madx)
115-
ips = get_lhc_ips_positions(df)
114+
twiss_df = twiss.get_twiss_tfs(madx)
115+
ips = get_lhc_ips_positions(twiss_df)
116116

117117
with plt.rc_context(_SPHINX_GALLERY_PARAMS):
118118
fig, ax = plt.subplots(figsize=(18, 10))
119-
ax.plot(df.S, df.BETX / 1e3, label=r"$\beta_x$")
120-
ax.plot(df.S, df.BETY / 1e3, label=r"$\beta_y$")
119+
ax.plot(twiss_df.S, twiss_df.BETX / 1e3, label=r"$\beta_x$")
120+
ax.plot(twiss_df.S, twiss_df.BETY / 1e3, label=r"$\beta_y$")
121121
draw_ip_locations(ips)
122122
ax.set_xlabel("Longitudinal location [m]")
123123
ax.set_ylabel(r"$\beta_{x,y}$ [km]")
@@ -133,8 +133,8 @@
133133
# IP5 for two different optics. Here below for the 2022 proton injection optics:
134134

135135
with lhc.LHCSetup(run=3, opticsfile="R2022a_A11mC11mA10mL10m.madx", stdout=False) as madx:
136-
df = twiss.get_twiss_tfs(madx)
137-
ips = get_lhc_ips_positions(df)
136+
twiss_df = twiss.get_twiss_tfs(madx)
137+
ips = get_lhc_ips_positions(twiss_df)
138138
limits = (ips["IP5"] - 500, ips["IP5"] + 500)
139139

140140
with plt.rc_context(_SPHINX_GALLERY_PARAMS):
@@ -172,8 +172,8 @@
172172
madx.call("lhc/aperture.b1.madx")
173173
madx.call("lhc/aper_tol.b1.madx")
174174

175-
df = twiss.get_twiss_tfs(madx)
176-
ips = get_lhc_ips_positions(df)
175+
twiss_df = twiss.get_twiss_tfs(madx)
176+
ips = get_lhc_ips_positions(twiss_df)
177177
limits = (ips["IP5"] - 350, ips["IP5"] + 350)
178178

179179
with plt.rc_context(_SPHINX_GALLERY_PARAMS):

pyhdtoolkit/cpymadtools/coupling.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,10 @@ def _filter_outlier_bpms_from_coupling_rdts(twiss_df: TfsDataFrame, stdev: float
397397
The `~tfs.TfsDataFrame` with the filtered BPMs.
398398
"""
399399
logger.debug("Filtering out outlier BPMs based on coupling RDTs")
400-
df = twiss_df.copy(deep=True)
401-
df = df[np.abs(stats.zscore(df.F1001.abs())) < stdev]
402-
df = df[np.abs(stats.zscore(df.F1010.abs())) < stdev]
403-
removed = len(twiss_df) - len(df)
400+
twiss_df = twiss_df.copy(deep=True)
401+
twiss_df = twiss_df[np.abs(stats.zscore(twiss_df.F1001.abs())) < stdev]
402+
twiss_df = twiss_df[np.abs(stats.zscore(twiss_df.F1010.abs())) < stdev]
403+
removed = len(twiss_df) - len(twiss_df)
404404
if removed > 0:
405405
logger.debug(f"{removed} BPMs removed due to outlier coupling RDTs")
406-
return df
406+
return twiss_df

pyhdtoolkit/cpymadtools/lhc/_routines.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ def do_kmodulation(
101101
for powering in k_powerings:
102102
logger.trace(f"Modulation of '{element}' - Setting '{powering_variable}' to {powering}")
103103
madx.globals[powering_variable] = powering
104-
df = get_ir_twiss(madx, ir=ir, centre=True, columns=["k1l", "l"], **kwargs)
105-
results.loc[powering].K = df.loc[element.lower()].k1l / df.loc[element.lower()].l # Store K
104+
twiss_df = get_ir_twiss(madx, ir=ir, centre=True, columns=["k1l", "l"], **kwargs)
105+
results.loc[powering].K = twiss_df.loc[element.lower()].k1l / twiss_df.loc[element.lower()].l # Store K
106106
results.loc[powering].TUNEX = madx.table.summ.q1[0] # Store Qx
107107
results.loc[powering].TUNEY = madx.table.summ.q2[0] # Store Qy
108108

pyhdtoolkit/cpymadtools/tune.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def get_v_tune(self, ampl: int, angl: int) -> float:
358358
return self._tunes[ampl][len(self._tunes[ampl]) - 1]["V"]
359359
return self._tunes[ampl][angl]["V"]
360360

361-
def get_plottable(self) -> tuple[list[float], list[float]]:
361+
def get_plottable(self) -> tuple[list[float], list[float]]: # noqa: PLR0912
362362
qxs, qys = [], []
363363
for i in np.arange(0, self._nampl - 1, 2):
364364
for j in np.arange(self._maxnangl):

pyhdtoolkit/plotting/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
from . import aperture, crossing, envelope, lattice, phasespace, tune, utils # noqa: TID252
66

7-
__all__ = ["aperture", "envelope", "crossing", "lattice", "phasespace", "tune", "utils"]
7+
__all__ = ["aperture", "crossing", "envelope", "lattice", "phasespace", "tune", "utils"]

pyhdtoolkit/plotting/aperture.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def _get_positions_and_real_apertures(
377377
if twiss_df[apercol].iloc[i] != 0:
378378
new_aper.insert(i, twiss_df[apercol].iloc[i])
379379
indices.append(i)
380-
indices = list(reversed(indices))
380+
indices.reverse()
381381

382382
logger.trace("Extrapolating data at beginning of elements")
383383
# counter keeps track of exact position in new array with counter

pyhdtoolkit/plotting/layout.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from pandas import DataFrame
3030

3131

32-
def plot_machine_layout(
32+
def plot_machine_layout( # noqa: PLR0912 (function branches justified)
3333
madx: Madx,
3434
/,
3535
title: str | None = None,
@@ -191,7 +191,7 @@ def plot_machine_layout(
191191
dipole_patches_axis = axis.twinx()
192192
dipole_patches_axis.set_ylabel("$\\theta=K_{0}L$ $[rad]$", color="royalblue") # dipoles in blue
193193
dipole_patches_axis.tick_params(axis="y", labelcolor="royalblue")
194-
if np.nan not in k0l_lim:
194+
if np.nan not in k0l_lim: # noqa: PLW0177 (not a comparison to NaN)
195195
dipole_patches_axis.set_ylim(k0l_lim)
196196
dipole_patches_axis.grid(visible=False)
197197

pyhdtoolkit/plotting/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ def _matplotlib_svg_scraper(*args, **kwargs): # pragma: no cover
636636
A dummy scraper to import and set for the sphinx-gallery
637637
configuration, in docs/conf.py.
638638
"""
639-
from sphinx_gallery.scrapers import matplotlib_scraper
639+
from sphinx_gallery.scrapers import matplotlib_scraper # noqa: PLC0415
640640

641641
kwargs.pop("format", None)
642642
return matplotlib_scraper(*args, format="svg", **kwargs)

pyhdtoolkit/utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from . import cmdline, contexts, decorators, htc_monitor, logging # noqa: TID252
22

3-
__all__ = ["cmdline", "decorators", "contexts", "htc_monitor", "logging"]
3+
__all__ = ["cmdline", "contexts", "decorators", "htc_monitor", "logging"]

pyhdtoolkit/utils/decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def calculations(x, y):
103103
return (x + y) / (x - y)
104104
"""
105105
try:
106-
from numba import jit
106+
from numba import jit # noqa: PLC0415
107107

108108
return jit(func, **kwargs)
109109
except ImportError:

0 commit comments

Comments
 (0)