From 885174f851410e98d1a7c43d0409ae45c7f7b59c Mon Sep 17 00:00:00 2001 From: Kimoon Han Date: Tue, 9 Jul 2024 18:43:54 +0900 Subject: [PATCH] style: enforce ruff E501 --- docs/source/conf.py | 13 ++- pyproject.toml | 5 +- src/erlab/accessors/fit.py | 4 +- src/erlab/accessors/kspace.py | 4 +- src/erlab/analysis/fit/minuit.py | 3 +- src/erlab/analysis/image.py | 4 +- .../imagetool/_deprecated/imagetool_mpl.py | 16 +-- .../imagetool/_deprecated/imagetool_old.py | 107 +++++++++--------- src/erlab/interactive/imagetool/core.py | 3 +- src/erlab/interactive/masktool.py | 6 +- src/erlab/io/plugins/ssrl52.py | 12 +- src/erlab/io/utils.py | 9 +- tests/io/test_dataloader.py | 10 +- 13 files changed, 103 insertions(+), 93 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index bf5ebfa8..5111b406 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -466,9 +466,18 @@ def get_inproceedings_template(self, e): "url": "https://github.com/kmnhan/erlabpy", "html": """ - + - """, + """, # noqa: E501 "class": "", }, ], diff --git a/pyproject.toml b/pyproject.toml index 4b3f219a..358efb13 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -142,13 +142,12 @@ indent-width = 4 [tool.ruff.lint] select = [ "F", - "E4", - "E7", - "E9", + "E", "W", "I", "D", "UP", + "YTT", "B", "C4", "FA", diff --git a/src/erlab/accessors/fit.py b/src/erlab/accessors/fit.py index 29a2fbab..679e6d59 100644 --- a/src/erlab/accessors/fit.py +++ b/src/erlab/accessors/fit.py @@ -298,8 +298,8 @@ def __call__( unexpected = set(params.dims) - set(preserved_dims) if unexpected: raise ValueError( - f"Parameters object has unexpected dimensions {tuple(unexpected)}. It " - "should only have dimensions that are in data dimensions " + f"Parameters object has unexpected dimensions {tuple(unexpected)}. " + "It should only have dimensions that are in data dimensions " f"{preserved_dims}." ) diff --git a/src/erlab/accessors/kspace.py b/src/erlab/accessors/kspace.py index d456e01b..3370cb6b 100644 --- a/src/erlab/accessors/kspace.py +++ b/src/erlab/accessors/kspace.py @@ -499,7 +499,9 @@ def best_kp_resolution(self) -> float: The resolution is estimated with the kinetic energy and angular resolution: - .. math:: \Delta k_{\parallel} \sim \sqrt{2 m_e E_k/\hbar^2} \cos(\alpha) \Delta\alpha + .. math:: + + \Delta k_{\parallel} \sim \sqrt{2 m_e E_k/\hbar^2} \cos(\alpha) \Delta\alpha """ min_Ek = np.amin(self.kinetic_energy.values) diff --git a/src/erlab/analysis/fit/minuit.py b/src/erlab/analysis/fit/minuit.py index 0df8199f..4097f863 100644 --- a/src/erlab/analysis/fit/minuit.py +++ b/src/erlab/analysis/fit/minuit.py @@ -161,7 +161,8 @@ def from_lmfit( if par.expr is not None: if par.vary: raise ValueError( - "Parameters constrained with expressions are not supported by Minuit." + "Parameters constrained with expressions " + "are not supported by iminuit" ) else: continue diff --git a/src/erlab/analysis/image.py b/src/erlab/analysis/image.py index 538bd6d0..b6a7fb43 100644 --- a/src/erlab/analysis/image.py +++ b/src/erlab/analysis/image.py @@ -689,7 +689,9 @@ def scaled_laplace( derivatives, taking the different scaling for each axis into account. .. math:: - \Delta f \sim \frac{\partial^2 f}{\partial x^2} \left(\frac{\Delta x}{\Delta y}\right)^{\!2} + \frac{\partial^2 f}{\partial y^2} + + \Delta f \sim \frac{\partial^2 f}{\partial x^2} + \left(\frac{\Delta x}{\Delta y}\right)^{\!2} + \frac{\partial^2 f}{\partial y^2} See Ref. :cite:p:`zhang2011curvature` for more information. diff --git a/src/erlab/interactive/imagetool/_deprecated/imagetool_mpl.py b/src/erlab/interactive/imagetool/_deprecated/imagetool_mpl.py index df16c621..132efcdc 100644 --- a/src/erlab/interactive/imagetool/_deprecated/imagetool_mpl.py +++ b/src/erlab/interactive/imagetool/_deprecated/imagetool_mpl.py @@ -170,9 +170,8 @@ def setColor(self, color): self._color = color self.colorChanged.emit(color.getRgbF()) if self._color: - self.setStyleSheet( - f"QWidget {{ background-color: {self._color.name(QtGui.QColor.HexArgb)}; border: 0; }}" - ) + clr = self._color.name(QtGui.QColor.HexArgb) + self.setStyleSheet(f"QWidget {{ background-color: {clr}; border: 0; }}") else: self.setStyleSheet("") @@ -961,13 +960,6 @@ def _update(self): self.canvas.restore_region(self.background) if self.parallel: raise NotImplementedError - # self.pool(delayed(self.axes[i].draw_artist)(art) for i, art in list(zip( - # (0, 4, 5, 1, 2, 3, 1, 2, 3), - # self.maps + self.hists + (self.axes[1].yaxis, - # self.axes[2].xaxis, - # self.axes[3].yaxis)))) - # self.pool(delayed(self.axes[i].draw_artist)(art) for i, art in list(zip( - # (0, 1, 4, 0, 2, 5, 3, 5, 4), self.cursors))) else: for i, art in list( zip(self.ax_index, self.all + self.scaling_axes, strict=True) @@ -1349,7 +1341,9 @@ def zoom_new(self, *args): # self.pathtab = QtWidgets.QWidget() # pathtabcontent = QtWidgets.QHBoxLayout() - # pathlabel = QtWidgets.QLabel('Add point: `space`\nRemove point: `delete`\nFinish selection: `enter`') + # pathlabel = QtWidgets.QLabel( + # "Add point: `space`\nRemove point: `delete`\nFinish selection: `enter`" + # ) # pathstart = QtWidgets.QPushButton() # pathstart.clicked.connect(self.itool._drawpath) # pathtabcontent.addWidget(pathlabel) diff --git a/src/erlab/interactive/imagetool/_deprecated/imagetool_old.py b/src/erlab/interactive/imagetool/_deprecated/imagetool_old.py index 10c7ec1d..198d1a15 100644 --- a/src/erlab/interactive/imagetool/_deprecated/imagetool_old.py +++ b/src/erlab/interactive/imagetool/_deprecated/imagetool_old.py @@ -264,13 +264,11 @@ def change_style(style_name): QtWidgets.QApplication.setStyle(QtWidgets.QStyleFactory.create(style_name)) -# @numba.njit(nogil=True, cache=True, fastmath={'nnan','ninf', 'nsz', 'contract', 'reassoc', 'afn', 'arcp'}) @numba.njit( nogil=True, cache=True, fastmath={"ninf", "nsz", "contract", "reassoc", "afn", "arcp"}, ) -# @numba.njit(nogil=True, cache=True) def move_mean1d(a, window, min_count): out = np.empty_like(a) asum = 0.0 @@ -367,9 +365,8 @@ def setColor(self, color): self._color = color self.colorChanged.emit(color.getRgbF()) if self._color: - self.setStyleSheet( - f"QWidget {{ background-color: {self._color.name(QtGui.QColor.HexArgb)}; border: 0; }}" - ) + clr = self._color.name(QtGui.QColor.HexArgb) + self.setStyleSheet(f"QWidget {{ background-color: {clr}; border: 0; }}") else: self.setStyleSheet("") @@ -1711,7 +1708,9 @@ def _binned_profile(self, avg_axis): slices = tuple(self._get_bin_slice(ax) for ax in avg_axis) return self._block_slice_avg(avg_axis, slices) # self._slice_block = self._block_slicer(avg_axis, slices) - # return _general_nanmean_func(self._slice_block, axis=[(ax - 1) for ax in avg_axis]) + # return _general_nanmean_func( + # self._slice_block, axis=[(ax - 1) for ax in avg_axis] + # ) def _block_slice_avg(self, axis=None, slices=None): axis = [(ax - 1) % self.data_ndim for ax in axis] @@ -1924,19 +1923,17 @@ def _refresh_data(self, i): self._refresh_data_4d(i) self.sigIndexChanged.emit(self._last_ind, self.cursor_pos) - # def get_levels(self, i): - # if self.clim_locked: - # if self.zero_centered: - - # else: - # return self.clim_list[i] - # else: - # self.all[i].getLevels() # def _refresh_histograms(self): - # self.hists[0].setData(self.data_coords[0], self.maps[0].image[self._last_ind[1], :]) - # self.hists[1].setData(self.maps[0].image[:, self._last_ind[0]], self.data_coords[1]) + # self.hists[0].setData( + # self.data_coords[0], self.maps[0].image[self._last_ind[1], :] + # ) + # self.hists[1].setData( + # self.maps[0].image[:, self._last_ind[0]], self.data_coords[1] + # ) # if self.data_ndim == 3: - # self.hists[2].setData(self.data_coords[2], self.maps[1].image[:, self._last_ind[0]]) + # self.hists[2].setData( + # self.data_coords[2], self.maps[1].image[:, self._last_ind[0]] + # ) def _refresh_data_2d(self, i): if i == 0: @@ -2132,43 +2129,41 @@ def __init__(self, parent): self.setWindowTitle("Colors") raise NotImplementedError - # self.cursor_default = color_to_QColor(self.parent.itool.cursor_kw["color"]) - # self.line_default = color_to_QColor(self.parent.itool.profile_kw["color"]) - # self.cursor_current = color_to_QColor(self.parent.itool.cursors[0].get_color()) - # self.line_current = color_to_QColor(self.parent.itool.hists[0].get_color()) - - # if (self.cursor_default.getRgbF() == self.cursor_current.getRgbF()) & ( - # self.line_default.getRgbF() == self.line_current.getRgbF() - # ): - # buttons = QtWidgets.QDialogButtonBox( - # QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel - # ) - # else: - # buttons = QtWidgets.QDialogButtonBox( - # QtWidgets.QDialogButtonBox.RestoreDefaults - # | QtWidgets.QDialogButtonBox.Ok - # | QtWidgets.QDialogButtonBox.Cancel - # ) - # buttons.button(QtWidgets.QDialogButtonBox.RestoreDefaults).clicked.connect( - # self.reset_colors - # ) - # buttons.rejected.connect(self.reject) - # buttons.accepted.connect(self.accept) - - # cursorlabel = QtWidgets.QLabel("Cursors:") - # linelabel = QtWidgets.QLabel("Lines:") - # self.cursorpicker = ColorButton(color=self.cursor_current) - # self.cursorpicker.colorChanged.connect(self.parent.itool.set_cursor_color) - # self.linepicker = ColorButton(color=self.line_current) - # self.linepicker.colorChanged.connect(self.parent.itool.set_line_color) - - # layout = QtWidgets.QGridLayout() - # layout.addWidget(cursorlabel, 0, 0) - # layout.addWidget(self.cursorpicker, 0, 1) - # layout.addWidget(linelabel, 1, 0) - # layout.addWidget(self.linepicker, 1, 1) - # layout.addWidget(buttons) - # self.setLayout(layout) + # self.cursor_default = color_to_QColor(self.parent.itool.cursor_kw["color"]) + # self.line_default = color_to_QColor(self.parent.itool.profile_kw["color"]) + # self.cursor_current = color_to_QColor(self.parent.itool.cursors[0].get_color()) + # self.line_current = color_to_QColor(self.parent.itool.hists[0].get_color()) + + # if (self.cursor_default.getRgbF() == self.cursor_current.getRgbF()) & ( + # self.line_default.getRgbF() == self.line_current.getRgbF() + # ): + # buttons = QtWidgets.QDialogButtonBox( + # QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel + # ) + # else: + # buttons = QtWidgets.QDialogButtonBox( + # QtWidgets.QDialogButtonBox.RestoreDefaults + # | QtWidgets.QDialogButtonBox.Ok + # | QtWidgets.QDialogButtonBox.Cancel + # ) + # buttons.button(QtWidgets.QDialogButtonBox.RestoreDefaults).clicked.connect( + # self.reset_colors + # ) + # buttons.rejected.connect(self.reject) + # buttons.accepted.connect(self.accept) + # cursorlabel = QtWidgets.QLabel("Cursors:") + # linelabel = QtWidgets.QLabel("Lines:") + # self.cursorpicker = ColorButton(color=self.cursor_current) + # self.cursorpicker.colorChanged.connect(self.parent.itool.set_cursor_color) + # self.linepicker = ColorButton(color=self.line_current) + # self.linepicker.colorChanged.connect(self.parent.itool.set_line_color) + # layout = QtWidgets.QGridLayout() + # layout.addWidget(cursorlabel, 0, 0) + # layout.addWidget(self.cursorpicker, 0, 1) + # layout.addWidget(linelabel, 1, 0) + # layout.addWidget(self.linepicker, 1, 1) + # layout.addWidget(buttons) + # self.setLayout(layout) # def reject(self): # self.cursorpicker.setColor(self.cursor_current) @@ -2416,7 +2411,9 @@ def generatePath(self): data = self.data lines = fast_isocurve(data, self.level, self.connected, self.extendToEdge) - # lines = pg.functions.isocurve(data, self.level, connected=True, extendToEdge=True) + # lines = pg.functions.isocurve( + # data, self.level, connected=True, extendToEdge=True + # ) self.path = QtGui.QPainterPath() for line in lines: self.path.moveTo(*line[0]) diff --git a/src/erlab/interactive/imagetool/core.py b/src/erlab/interactive/imagetool/core.py index 6c648415..f0da09bf 100644 --- a/src/erlab/interactive/imagetool/core.py +++ b/src/erlab/interactive/imagetool/core.py @@ -319,7 +319,8 @@ def convert_args( if axis is None: raise ValueError( - "Axis argument not found in decorated method with `indices=True`" + "Axis argument not found in method decorated " + "with the `indices=True` argument" ) args["value"] = self.convert_index(source, target, axis, index, steps) diff --git a/src/erlab/interactive/masktool.py b/src/erlab/interactive/masktool.py index d3891e0e..5eeb8671 100644 --- a/src/erlab/interactive/masktool.py +++ b/src/erlab/interactive/masktool.py @@ -78,8 +78,8 @@ def update_cursor(self, change): self.images[0].setDataArray(new_arr.T) else: self.images[0].setDataArray(new_arr) - # else: - # self.images[0].setDataArray(new_arr) - # self.images[0].setImage(self.data.isel({dim_z:self.cursor.widgets["slider"].value()}).values) + # self.images[0].setImage( + # self.data.isel({dim_z: self.cursor.widgets["slider"].value()}).values + # ) # self.cursor.values["slider"] diff --git a/src/erlab/io/plugins/ssrl52.py b/src/erlab/io/plugins/ssrl52.py index b276cfe4..4e75acda 100644 --- a/src/erlab/io/plugins/ssrl52.py +++ b/src/erlab/io/plugins/ssrl52.py @@ -123,11 +123,15 @@ def load_single(self, file_path: str | os.PathLike) -> xr.DataArray: ) continue is_hvdep = True + # For hv dep scans, EKin is given for each scan data = data.rename({ax["label"]: "Binding Energy"}) ax["label"] = "Binding Energy" - # ax['offset'] will be something like "MapInfo:Data:Axes0:Offset" + + # ax['offset'] will be something like: + # "MapInfo:Data:Axes0:Offset" offset_key: str = ax["offset"][8:] + # Take first kinetic energy offset = np.array(ncf["MapInfo"][offset_key])[0] @@ -180,9 +184,9 @@ def load_single(self, file_path: str | os.PathLike) -> xr.DataArray: if len(same_length_indices) != 1: # Multiple dimensions with the same length, ambiguous warnings.warn( - f"Ambiguous length for {k}. This was not taken into account " - "while writing the loader code. Please report this issue. " - "Resulting data may be incorrect", + f"Ambiguous length for {k}. This was not taken into " + "account while writing the loader code. Please report this " + "issue. Resulting data may be incorrect", stacklevel=1, ) idx = same_length_indices[-1] diff --git a/src/erlab/io/utils.py b/src/erlab/io/utils.py index b3f6b8b2..22680dfa 100644 --- a/src/erlab/io/utils.py +++ b/src/erlab/io/utils.py @@ -187,10 +187,11 @@ def save_as_hdf5( filename Target file name. igor_compat - (*Experimental*) Make the resulting file compatible with Igor's `HDF5OpenFile` for DataArrays - with up to 4 dimensions. A convenient Igor procedure is `included in the - repository `_. - Default is `True`. + (*Experimental*) Make the resulting file compatible with Igor's `HDF5OpenFile` + for DataArrays with up to 4 dimensions. A convenient Igor procedure is `included + in the repository + `_. Default is + `True`. **kwargs Extra arguments to `xarray.DataArray.to_netcdf`: refer to the `xarray` documentation for a list of all possible arguments. diff --git a/tests/io/test_dataloader.py b/tests/io/test_dataloader.py index d9dade8a..efcc43de 100644 --- a/tests/io/test_dataloader.py +++ b/tests/io/test_dataloader.py @@ -120,11 +120,11 @@ class ExampleLoader(LoaderBase): "polarization", "photon_flux", ) - # Attributes to be used as coordinates. Place all attributes that we don't want to - # lose when merging multiple file scans here. + # Attributes to be used as coordinates. Place all attributes that we don't want + # to lose when merging multiple file scans here. additional_attrs: ClassVar[dict] = { - "configuration": 1, # Experimental geometry. Required for momentum conversion + "configuration": 1, # Experimental geometry required for kspace conversion "sample_workfunction": 4.3, } # Any additional metadata you want to add to the data @@ -166,8 +166,8 @@ def identify(self, num, data_dir): def load_single(self, file_path): data = erlab.io.load_hdf5(file_path) - # To prevent conflicts when merging multiple scans, we rename the coordinates - # prior to concatenation + # To prevent conflicts when merging multiple scans, we rename the + # coordinates prior to concatenation return self.process_keys(data) def infer_index(self, name):