Skip to content

Commit

Permalink
style: enforce ruff A
Browse files Browse the repository at this point in the history
  • Loading branch information
kmnhan committed Jul 9, 2024
1 parent b242f44 commit c6aa21c
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


project = "ERLab"
copyright = "2023, Kimoon Han"
copyright = "2023, Kimoon Han" # noqa: A001
author = "Kimoon Han"
release = importlib.metadata.version("erlab")
version = release
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ select = [
"D",
"UP",
"YTT",
"ASYNC",
"B",
"A",
"C4",
"FA",
"ICN",
Expand Down
8 changes: 4 additions & 4 deletions src/erlab/analysis/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ def _calc_savgol(values_ptr, len_values, result, data) -> int:


def gradient_magnitude(
input: npt.NDArray[np.float64],
arr: npt.NDArray[np.float64],
dx: np.float64,
dy: np.float64,
mode: str = "nearest",
Expand Down Expand Up @@ -588,7 +588,7 @@ def _kernel(values_ptr, len_values, result, data) -> int:
_kernel.ctypes, signature="int (double *, npy_intp, double *, void *)"
)

return scipy.ndimage.generic_filter(input, func, size=(3, 3), mode=mode, cval=cval)
return scipy.ndimage.generic_filter(arr, func, size=(3, 3), mode=mode, cval=cval)


def laplace(
Expand Down Expand Up @@ -741,8 +741,8 @@ def scaled_laplace(
if isinstance(mode, dict):
mode = tuple(mode[d] for d in darr.dims)

def d2_scaled(input, axis, output, mode, cval):
out = scipy.ndimage.correlate1d(input, [1, -2, 1], axis, output, mode, cval, 0)
def d2_scaled(arr, axis, output, mode, cval):
out = scipy.ndimage.correlate1d(arr, [1, -2, 1], axis, output, mode, cval, 0)
if axis == 1:
out *= weight
return out
Expand Down
8 changes: 4 additions & 4 deletions src/erlab/analysis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ def shift(
slices: tuple[slice | int, ...] = tuple(_slices)

# Initialize arguments to `scipy.ndimage.shift`
input = out[slices]
shifts: list[float] = [0.0] * input.ndim
arr = out[slices]
shifts: list[float] = [0.0] * arr.ndim
shift_val: float = float(shift.isel(dict(zip(shift.dims, idxs, strict=True))))
shifts[cast(int, input.get_axis_num(along))] = shift_val
shifts[cast(int, arr.get_axis_num(along))] = shift_val

# Apply shift
out[slices] = scipy.ndimage.shift(input.values, shifts, **shift_kwargs)
out[slices] = scipy.ndimage.shift(arr.values, shifts, **shift_kwargs)

return out

Expand Down
6 changes: 3 additions & 3 deletions src/erlab/interactive/imagetool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,10 @@ def refreshMenus(self) -> None:

cmap_props = self.slicer_area.colormap_properties
for ca, k in zip(
self.colorAct, ["reversed", "high_contrast", "zero_centered"], strict=True
self.colorAct, ["reverse", "high_contrast", "zero_centered"], strict=True
):
k = cast(
Literal["reversed", "high_contrast", "zero_centered"], k
Literal["reverse", "high_contrast", "zero_centered"], k
) # for mypy
ca.blockSignals(True)
ca.setChecked(cmap_props[k])
Expand All @@ -529,7 +529,7 @@ def refreshEditMenus(self) -> None:

def _set_colormap_options(self) -> None:
self.slicer_area.set_colormap(
reversed=self.colorAct[0].isChecked(),
reverse=self.colorAct[0].isChecked(),
high_contrast=self.colorAct[1].isChecked(),
zero_centered=self.colorAct[2].isChecked(),
)
Expand Down
4 changes: 2 additions & 2 deletions src/erlab/interactive/imagetool/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def update_content(self) -> None:
self.btn_lock.blockSignals(True)

props = self.slicer_area.colormap_properties
self.btn_reverse.setChecked(props["reversed"])
self.btn_reverse.setChecked(props["reverse"])
self.btn_contrast.setChecked(props["high_contrast"])
self.btn_zero.setChecked(props["zero_centered"])
self.btn_lock.setChecked(props["levels_locked"])
Expand All @@ -603,7 +603,7 @@ def update_content(self) -> None:

def update_colormap(self) -> None:
self.slicer_area.set_colormap(
reversed=self.btn_reverse.isChecked(),
reverse=self.btn_reverse.isChecked(),
high_contrast=self.btn_contrast.isChecked(),
zero_centered=self.btn_zero.isChecked(),
)
Expand Down
12 changes: 6 additions & 6 deletions src/erlab/interactive/imagetool/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
class ColorMapState(TypedDict):
cmap: str | pg.ColorMap
gamma: float
reversed: bool
reverse: bool
high_contrast: bool
zero_centered: bool
levels_locked: bool
Expand Down Expand Up @@ -505,7 +505,7 @@ def __init__(
self._colormap_properties: ColorMapState = {
"cmap": cmap,
"gamma": gamma,
"reversed": cmap_reversed,
"reverse": cmap_reversed,
"high_contrast": False,
"zero_centered": zero_centered,
"levels_locked": False,
Expand Down Expand Up @@ -1145,7 +1145,7 @@ def set_colormap(
self,
cmap: str | pg.ColorMap | None = None,
gamma: float | None = None,
reversed: bool | None = None,
reverse: bool | None = None,
high_contrast: bool | None = None,
zero_centered: bool | None = None,
levels_locked: bool | None = None,
Expand All @@ -1160,8 +1160,8 @@ def set_colormap(
self._colormap_properties["cmap"] = cmap
if gamma is not None:
self._colormap_properties["gamma"] = gamma
if reversed is not None:
self._colormap_properties["reversed"] = reversed
if reverse is not None:
self._colormap_properties["reverse"] = reverse
if high_contrast is not None:
self._colormap_properties["high_contrast"] = high_contrast
if zero_centered is not None:
Expand All @@ -1174,7 +1174,7 @@ def set_colormap(
cmap = pg_colormap_powernorm(
self._colormap_properties["cmap"],
self._colormap_properties["gamma"],
self._colormap_properties["reversed"],
self._colormap_properties["reverse"],
high_contrast=self._colormap_properties["high_contrast"],
zero_centered=self._colormap_properties["zero_centered"],
)
Expand Down
2 changes: 1 addition & 1 deletion src/erlab/interactive/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def setValue(self, val) -> None:
line.setText(self.text())
self.textChanged.emit(self.text())

def fixup(self, input):
def fixup(self, _):
# Called when the spinbox loses focus with an invalid or intermediate string
return self.textFromValue(self._lastvalue)

Expand Down
2 changes: 1 addition & 1 deletion tests/interactive/test_imagetool.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_itool(qtbot):

# Set colormap and gamma
win.slicer_area.set_colormap(
"ColdWarm", gamma=1.5, reversed=True, high_contrast=True, zero_centered=True
"ColdWarm", gamma=1.5, reverse=True, high_contrast=True, zero_centered=True
)

# Lock levels
Expand Down

0 comments on commit c6aa21c

Please sign in to comment.