Skip to content

Commit

Permalink
style: sort __all__ and change linter configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
kmnhan committed Apr 10, 2024
1 parent b0d2d01 commit c07262e
Show file tree
Hide file tree
Showing 31 changed files with 141 additions and 117 deletions.
2 changes: 1 addition & 1 deletion docs/source/user-guide/io.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
"file path or a sequence number:\n",
"\n",
".. image:: ../images/flowchart_single.pdf\n",
" :align9: center\n",
" :align: center\n",
"\n",
"However, there are some setups where data for a single scan is saved over\n",
"multiple files. In this case, the files will look like ``file_0001_0001.h5``,\n",
Expand Down
12 changes: 11 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,20 @@ select = [
"FA",
"ICN",
"PIE",
"PT",
"Q",
"RSE",
"TID",
"TCH",
# "PTH",
# "FIX",
"TRY",
"FLY",
"NPY",
"PERF",
"RUF",
]
ignore = ["B905", "ICN001", "RUF001", "RUF002", "RUF003", "RUF012"]
ignore = ["B905", "ICN001", "TRY003", "RUF001", "RUF002", "RUF003", "RUF012"]
extend-select = [
"UP", # pyupgrade
]
Expand All @@ -213,4 +221,6 @@ docstring-code-line-length = "dynamic"
profile = "black"

[tool.pytest.ini_options]
addopts = ["--import-mode=importlib"]
pythonpath = "src"
testpaths = "tests"
4 changes: 2 additions & 2 deletions src/erlab/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
"""

__all__ = [
"PlotAccessor",
"ImageToolAccessor",
"SelectionAccessor",
"MomentumAccessor",
"OffsetView",
"PlotAccessor",
"SelectionAccessor",
]

import functools
Expand Down
4 changes: 2 additions & 2 deletions src/erlab/analysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
"""

__all__ = [
"correct_with_edge",
"mask_with_hex_bz",
"mask_with_polygon",
"polygon_mask",
"polygon_mask_points",
"mask_with_hex_bz",
"rotateinplane",
"rotatestackinplane",
"correct_with_edge",
]

from erlab.analysis import correlation, fit, gold, interpolate, kspace # noqa: F401
Expand Down
2 changes: 1 addition & 1 deletion src/erlab/analysis/correlation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Macros for correlation analysis."""

__all__ = ["acf2stack", "acf2", "match_dims", "xcorr1d"]
__all__ = ["acf2", "acf2stack", "match_dims", "xcorr1d"]


import itertools
Expand Down
4 changes: 2 additions & 2 deletions src/erlab/analysis/fit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

__all__ = [
"ExtendedAffineBroadenedFD",
"PolynomialModel",
"MultiPeakModel",
"LeastSq",
"Minuit",
"MultiPeakModel",
"PolynomialModel",
]

from erlab.analysis.fit.minuit import LeastSq, Minuit
Expand Down
12 changes: 6 additions & 6 deletions src/erlab/analysis/fit/functions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@

__all__ = [
"TINY",
"FermiEdge2dFunction",
"MultiPeakFunction",
"PolynomialFunction",
"do_convolve",
"do_convolve_y",
"gaussian_wh",
"lorentzian_wh",
"fermi_dirac",
"fermi_dirac_linbkg",
"fermi_dirac_linbkg_broad",
"step_linbkg_broad",
"gaussian_wh",
"lorentzian_wh",
"step_broad",
"PolynomialFunction",
"MultiPeakFunction",
"FermiEdge2dFunction",
"step_linbkg_broad",
]

from erlab.analysis.fit.functions.dynamic import (
Expand Down
6 changes: 3 additions & 3 deletions src/erlab/analysis/fit/functions/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"""

__all__ = [
"get_args_kwargs",
"DynamicFunction",
"PolynomialFunction",
"MultiPeakFunction",
"FermiEdge2dFunction",
"MultiPeakFunction",
"PolynomialFunction",
"get_args_kwargs",
]
import functools
import inspect
Expand Down
6 changes: 3 additions & 3 deletions src/erlab/analysis/fit/functions/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
"TINY",
"do_convolve",
"do_convolve_y",
"gaussian_wh",
"lorentzian_wh",
"fermi_dirac",
"fermi_dirac_linbkg",
"fermi_dirac_linbkg_broad",
"step_linbkg_broad",
"gaussian_wh",
"lorentzian_wh",
"step_broad",
"step_linbkg_broad",
]

from collections.abc import Callable
Expand Down
12 changes: 8 additions & 4 deletions src/erlab/analysis/fit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

__all__ = [
"ExtendedAffineBroadenedFD",
"StepEdgeModel",
"PolynomialModel",
"MultiPeakModel",
"FermiEdge2dModel",
"MultiPeakModel",
"PolynomialModel",
"StepEdgeModel",
]

import lmfit
Expand Down Expand Up @@ -161,7 +161,11 @@ def guess(self, data, x, **kwargs):
class StepEdgeModel(lmfit.Model):
def __init__(self, independent_vars=("x",), prefix="", missing="raise", **kwargs):
kwargs.update(
{"prefix": prefix, "missing": missing, "independent_vars": independent_vars}
{
"prefix": prefix,
"missing": missing,
"independent_vars": independent_vars,
}
)
super().__init__(step_linbkg_broad, **kwargs)
self.set_param_hint("sigma", min=0.0)
Expand Down
2 changes: 1 addition & 1 deletion src/erlab/analysis/gold.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"edge",
"poly",
"poly_from_edge",
"spline_from_edge",
"resolution",
"resolution_roi",
"spline_from_edge",
]

from collections.abc import Sequence
Expand Down
6 changes: 3 additions & 3 deletions src/erlab/analysis/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def gaussian_filter(
"""
if np.isscalar(sigma):
sigma = {d: sigma for d in darr.dims}
sigma = dict.fromkeys(darr.dims, sigma)
elif not isinstance(sigma, dict):
sigma = dict(zip(darr.dims, sigma))

Expand All @@ -117,7 +117,7 @@ def gaussian_filter(
raise ValueError("`radius` does not match dimensions of `sigma`")

if np.isscalar(radius):
radius = {d: radius for d in sigma.keys()}
radius = dict.fromkeys(sigma.keys(), radius)
elif not isinstance(radius, dict):
radius = dict(zip(sigma.keys(), radius))

Expand Down Expand Up @@ -196,7 +196,7 @@ def gaussian_laplace(
filter.
"""
if np.isscalar(sigma):
sigma = {d: sigma for d in darr.dims}
sigma = dict.fromkeys(darr.dims, sigma)
elif not isinstance(sigma, dict):
sigma = dict(zip(darr.dims, sigma))

Expand Down
4 changes: 2 additions & 2 deletions src/erlab/analysis/mask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
"""

__all__ = [
"hex_bz_mask_points",
"mask_with_hex_bz",
"mask_with_polygon",
"polygon_mask",
"polygon_mask_points",
"mask_with_hex_bz",
"hex_bz_mask_points",
]

import numba
Expand Down
2 changes: 1 addition & 1 deletion src/erlab/analysis/utilities.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__all__ = ["shift", "correct_with_edge"]
__all__ = ["correct_with_edge", "shift"]

import itertools
from collections.abc import Callable
Expand Down
10 changes: 5 additions & 5 deletions src/erlab/interactive/bzplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,12 @@ def set_latt(self, a, b, c, alpha, beta, gamma):

def set_avec(self, avec):
self.params_avec.set_values(
**{f"a{i+1}{('x', 'y', 'z')[j]}": v for (i, j), v in np.ndenumerate(avec)}
**{f"a{i + 1}{('x', 'y', 'z')[j]}": v for (i, j), v in np.ndenumerate(avec)}
)

def set_bvec(self, bvec):
self.params_bvec.set_values(
**{f"b{i+1}{('x', 'y', 'z')[j]}": v for (i, j), v in np.ndenumerate(bvec)}
**{f"b{i + 1}{('x', 'y', 'z')[j]}": v for (i, j), v in np.ndenumerate(bvec)}
)

@property
Expand Down Expand Up @@ -368,11 +368,11 @@ def __init__(self, bvec):
# plot reciprocal lattice vectors
self._bvecs = []
for i, b in enumerate(bvec):
p = self.ax.plot(*[(0, bi) for bi in b], "-", c=f"C{i+1}", clip_on=False)
p = self.ax.plot(*[(0, bi) for bi in b], "-", c=f"C{i + 1}", clip_on=False)
t = self.ax.text(
*(b + 0.15 * b / np.linalg.norm(b)),
f"$b_{i+1}$",
c=f"C{i+1}",
f"$b_{i + 1}$",
c=f"C{i + 1}",
ha="center",
va="center_baseline",
)
Expand Down
6 changes: 3 additions & 3 deletions src/erlab/interactive/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from __future__ import annotations

__all__ = [
"BetterColorBarItem",
"BetterImageItem",
"ColorMapComboBox",
"ColorMapGammaWidget",
"BetterImageItem",
"BetterColorBarItem",
"color_to_QColor",
"pg_colormap_names",
"pg_colormap_from_name",
"pg_colormap_names",
"pg_colormap_powernorm",
"pg_colormap_to_QPixmap",
]
Expand Down
24 changes: 13 additions & 11 deletions src/erlab/interactive/derivative.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,19 @@ def copy_code(self):
}
lines.append(f"_processed = {data_name}.copy()")
data_name = "_processed"
lines.append(f"for _ in range({self.sn_spin.value()}):")
lines.append(
"\t"
+ gen_function_code(
copy=False,
**{
"_processed = era.image.gaussian_filter": [
f"|{data_name}|",
arg_dict,
]
},
lines.extend(
(
f"for _ in range({self.sn_spin.value()}):",
"\t"
+ gen_function_code(
copy=False,
**{
"_processed = era.image.gaussian_filter": [
f"|{data_name}|",
arg_dict,
]
},
),
)
)
data_name = "_processed"
Expand Down
2 changes: 1 addition & 1 deletion src/erlab/interactive/imagetool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from __future__ import annotations

__all__ = ["itool", "ImageTool"]
__all__ = ["ImageTool", "itool"]

import gc
import sys
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1845,7 +1845,7 @@ def onMouseDrag(self, evt):
for i in range(self.data_ndim):
if D[i]:
ind = self.get_index_of_value(i, V[i])
if self.snap and (ind == self._last_ind[i]) or self.axis_locked[i]:
if (self.snap and (ind == self._last_ind[i])) or self.axis_locked[i]:
D[i] = False
else:
self._last_ind[i] = ind
Expand Down
4 changes: 2 additions & 2 deletions src/erlab/interactive/imagetool/controls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import annotations

__all__ = [
"ItoolCrosshairControls",
"ColorControls",
"ItoolColormapControls",
"ItoolBinningControls",
"ItoolColormapControls",
"ItoolCrosshairControls",
]

from typing import TYPE_CHECKING
Expand Down
17 changes: 11 additions & 6 deletions src/erlab/interactive/kspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,13 @@ def copy_code(self):
f"{input_name}.kspace.inner_potential"
f" = {self._offset_spins['V0'].value()}"
)
out_lines.append(f"{input_name}.kspace.offsets = {self.offset_dict}")
out_lines.append(
gen_function_code(
copy=False,
**{f"{input_name}_kconv = {input_name}.kspace.convert": [arg_dict]},
out_lines.extend(
(
f"{input_name}.kspace.offsets = {self.offset_dict}",
gen_function_code(
copy=False,
**{f"{input_name}_kconv = {input_name}.kspace.convert": [arg_dict]},
),
)
)

Expand Down Expand Up @@ -397,7 +399,10 @@ def get_bz_lines(

if rot != 0.0:
rotmat = np.array(
[[np.cos(rot), -np.sin(rot)], [np.sin(rot), np.cos(rot)]]
[
[np.cos(rot), -np.sin(rot)],
[np.sin(rot), np.cos(rot)],
]
)
lines = (rotmat @ lines.transpose(1, 2, 0)).transpose(2, 0, 1)
vertices = (rotmat @ vertices.T).T
Expand Down
16 changes: 8 additions & 8 deletions src/erlab/interactive/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
from erlab.interactive.colors import BetterImageItem, pg_colormap_powernorm

__all__ = [
"parse_data",
"copy_to_clipboard",
"gen_single_function_code",
"gen_function_code",
"BetterSpinBox",
"BetterAxisItem",
"xImageItem",
"ParameterGroup",
"AnalysisWidgetBase",
"AnalysisWindow",
"BetterAxisItem",
"BetterSpinBox",
"DictMenuBar",
"ParameterGroup",
"copy_to_clipboard",
"gen_function_code",
"gen_single_function_code",
"parse_data",
"xImageItem",
]


Expand Down
Loading

0 comments on commit c07262e

Please sign in to comment.