Skip to content

Commit

Permalink
style: enforce ruff E501
Browse files Browse the repository at this point in the history
  • Loading branch information
kmnhan committed Jul 9, 2024
1 parent 018a0e3 commit 885174f
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 93 deletions.
13 changes: 11 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,18 @@ def get_inproceedings_template(self, e):
"url": "https://github.com/kmnhan/erlabpy",
"html": """
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path>
<path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53
5.47 7.59.4.07.55-.17.55-.38
0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01
1.08.58 1.23.82.72 1.21 1.87.87
2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95
0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21
2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82
2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87
3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0
.21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path>
</svg>
""",
""", # noqa: E501
"class": "",
},
],
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,12 @@ indent-width = 4
[tool.ruff.lint]
select = [
"F",
"E4",
"E7",
"E9",
"E",
"W",
"I",
"D",
"UP",
"YTT",
"B",
"C4",
"FA",
Expand Down
4 changes: 2 additions & 2 deletions src/erlab/accessors/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}."
)

Expand Down
4 changes: 3 additions & 1 deletion src/erlab/accessors/kspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/erlab/analysis/fit/minuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/erlab/analysis/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 5 additions & 11 deletions src/erlab/interactive/imagetool/_deprecated/imagetool_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("")

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
107 changes: 52 additions & 55 deletions src/erlab/interactive/imagetool/_deprecated/imagetool_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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("")

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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])
Expand Down
3 changes: 2 additions & 1 deletion src/erlab/interactive/imagetool/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/erlab/interactive/masktool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
12 changes: 8 additions & 4 deletions src/erlab/io/plugins/ssrl52.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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]
Expand Down
9 changes: 5 additions & 4 deletions src/erlab/io/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/kmnhan/erlabpy/blob/main/PythonInterface.ipf>`_.
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
<https://github.com/kmnhan/erlabpy/blob/main/PythonInterface.ipf>`_. Default is
`True`.
**kwargs
Extra arguments to `xarray.DataArray.to_netcdf`: refer to the `xarray`
documentation for a list of all possible arguments.
Expand Down
10 changes: 5 additions & 5 deletions tests/io/test_dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 885174f

Please sign in to comment.