diff --git a/docs/source/user-guide/io.ipynb b/docs/source/user-guide/io.ipynb index a561ad43..65a8e59b 100644 --- a/docs/source/user-guide/io.ipynb +++ b/docs/source/user-guide/io.ipynb @@ -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", diff --git a/pyproject.toml b/pyproject.toml index ae85d3a8..a4cd4280 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 ] @@ -213,4 +221,6 @@ docstring-code-line-length = "dynamic" profile = "black" [tool.pytest.ini_options] +addopts = ["--import-mode=importlib"] +pythonpath = "src" testpaths = "tests" diff --git a/src/erlab/accessors.py b/src/erlab/accessors.py index acc73642..cdadc992 100644 --- a/src/erlab/accessors.py +++ b/src/erlab/accessors.py @@ -8,11 +8,11 @@ """ __all__ = [ - "PlotAccessor", "ImageToolAccessor", - "SelectionAccessor", "MomentumAccessor", "OffsetView", + "PlotAccessor", + "SelectionAccessor", ] import functools diff --git a/src/erlab/analysis/__init__.py b/src/erlab/analysis/__init__.py index d971a3e9..dd69146b 100644 --- a/src/erlab/analysis/__init__.py +++ b/src/erlab/analysis/__init__.py @@ -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 diff --git a/src/erlab/analysis/correlation.py b/src/erlab/analysis/correlation.py index bf06845f..c3c65ae5 100644 --- a/src/erlab/analysis/correlation.py +++ b/src/erlab/analysis/correlation.py @@ -1,6 +1,6 @@ """Macros for correlation analysis.""" -__all__ = ["acf2stack", "acf2", "match_dims", "xcorr1d"] +__all__ = ["acf2", "acf2stack", "match_dims", "xcorr1d"] import itertools diff --git a/src/erlab/analysis/fit/__init__.py b/src/erlab/analysis/fit/__init__.py index 0eaddcca..87189751 100644 --- a/src/erlab/analysis/fit/__init__.py +++ b/src/erlab/analysis/fit/__init__.py @@ -17,10 +17,10 @@ __all__ = [ "ExtendedAffineBroadenedFD", - "PolynomialModel", - "MultiPeakModel", "LeastSq", "Minuit", + "MultiPeakModel", + "PolynomialModel", ] from erlab.analysis.fit.minuit import LeastSq, Minuit diff --git a/src/erlab/analysis/fit/functions/__init__.py b/src/erlab/analysis/fit/functions/__init__.py index a8f91f6d..af011f02 100644 --- a/src/erlab/analysis/fit/functions/__init__.py +++ b/src/erlab/analysis/fit/functions/__init__.py @@ -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 ( diff --git a/src/erlab/analysis/fit/functions/dynamic.py b/src/erlab/analysis/fit/functions/dynamic.py index c37b58b5..748ee5a0 100644 --- a/src/erlab/analysis/fit/functions/dynamic.py +++ b/src/erlab/analysis/fit/functions/dynamic.py @@ -5,11 +5,11 @@ """ __all__ = [ - "get_args_kwargs", "DynamicFunction", - "PolynomialFunction", - "MultiPeakFunction", "FermiEdge2dFunction", + "MultiPeakFunction", + "PolynomialFunction", + "get_args_kwargs", ] import functools import inspect diff --git a/src/erlab/analysis/fit/functions/general.py b/src/erlab/analysis/fit/functions/general.py index 0f5cff68..73b7e4ca 100644 --- a/src/erlab/analysis/fit/functions/general.py +++ b/src/erlab/analysis/fit/functions/general.py @@ -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 diff --git a/src/erlab/analysis/fit/models.py b/src/erlab/analysis/fit/models.py index c71a0a4b..1fee1be7 100644 --- a/src/erlab/analysis/fit/models.py +++ b/src/erlab/analysis/fit/models.py @@ -2,10 +2,10 @@ __all__ = [ "ExtendedAffineBroadenedFD", - "StepEdgeModel", - "PolynomialModel", - "MultiPeakModel", "FermiEdge2dModel", + "MultiPeakModel", + "PolynomialModel", + "StepEdgeModel", ] import lmfit @@ -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) diff --git a/src/erlab/analysis/gold.py b/src/erlab/analysis/gold.py index bf1e0444..f39d807d 100644 --- a/src/erlab/analysis/gold.py +++ b/src/erlab/analysis/gold.py @@ -4,9 +4,9 @@ "edge", "poly", "poly_from_edge", - "spline_from_edge", "resolution", "resolution_roi", + "spline_from_edge", ] from collections.abc import Sequence diff --git a/src/erlab/analysis/image.py b/src/erlab/analysis/image.py index 016d974e..c3d09bf2 100644 --- a/src/erlab/analysis/image.py +++ b/src/erlab/analysis/image.py @@ -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)) @@ -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)) @@ -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)) diff --git a/src/erlab/analysis/mask/__init__.py b/src/erlab/analysis/mask/__init__.py index 5abc6f8b..c54032c0 100644 --- a/src/erlab/analysis/mask/__init__.py +++ b/src/erlab/analysis/mask/__init__.py @@ -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 diff --git a/src/erlab/analysis/utilities.py b/src/erlab/analysis/utilities.py index 81678146..5ae3d4dc 100644 --- a/src/erlab/analysis/utilities.py +++ b/src/erlab/analysis/utilities.py @@ -1,4 +1,4 @@ -__all__ = ["shift", "correct_with_edge"] +__all__ = ["correct_with_edge", "shift"] import itertools from collections.abc import Callable diff --git a/src/erlab/interactive/bzplot.py b/src/erlab/interactive/bzplot.py index 9482ba95..6b3829f7 100644 --- a/src/erlab/interactive/bzplot.py +++ b/src/erlab/interactive/bzplot.py @@ -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 @@ -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", ) diff --git a/src/erlab/interactive/colors.py b/src/erlab/interactive/colors.py index 163b8ff2..4ef61e41 100644 --- a/src/erlab/interactive/colors.py +++ b/src/erlab/interactive/colors.py @@ -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", ] diff --git a/src/erlab/interactive/derivative.py b/src/erlab/interactive/derivative.py index 8137ad2c..471b270f 100644 --- a/src/erlab/interactive/derivative.py +++ b/src/erlab/interactive/derivative.py @@ -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" diff --git a/src/erlab/interactive/imagetool/__init__.py b/src/erlab/interactive/imagetool/__init__.py index 10b1f884..3e76a92e 100644 --- a/src/erlab/interactive/imagetool/__init__.py +++ b/src/erlab/interactive/imagetool/__init__.py @@ -17,7 +17,7 @@ from __future__ import annotations -__all__ = ["itool", "ImageTool"] +__all__ = ["ImageTool", "itool"] import gc import sys diff --git a/src/erlab/interactive/imagetool/_deprecated/imagetool_old.py b/src/erlab/interactive/imagetool/_deprecated/imagetool_old.py index 8c0c5314..5189482c 100644 --- a/src/erlab/interactive/imagetool/_deprecated/imagetool_old.py +++ b/src/erlab/interactive/imagetool/_deprecated/imagetool_old.py @@ -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 diff --git a/src/erlab/interactive/imagetool/controls.py b/src/erlab/interactive/imagetool/controls.py index 631d53c6..12b4515a 100644 --- a/src/erlab/interactive/imagetool/controls.py +++ b/src/erlab/interactive/imagetool/controls.py @@ -1,10 +1,10 @@ from __future__ import annotations __all__ = [ - "ItoolCrosshairControls", "ColorControls", - "ItoolColormapControls", "ItoolBinningControls", + "ItoolColormapControls", + "ItoolCrosshairControls", ] from typing import TYPE_CHECKING diff --git a/src/erlab/interactive/kspace.py b/src/erlab/interactive/kspace.py index 260d84dd..f2f5ad5d 100644 --- a/src/erlab/interactive/kspace.py +++ b/src/erlab/interactive/kspace.py @@ -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]}, + ), ) ) @@ -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 diff --git a/src/erlab/interactive/utilities.py b/src/erlab/interactive/utilities.py index c5f0487d..2d47b87b 100644 --- a/src/erlab/interactive/utilities.py +++ b/src/erlab/interactive/utilities.py @@ -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", ] diff --git a/src/erlab/io/__init__.py b/src/erlab/io/__init__.py index 8d25e4c1..cc547360 100644 --- a/src/erlab/io/__init__.py +++ b/src/erlab/io/__init__.py @@ -41,19 +41,19 @@ """ __all__ = [ - "loaders", - "set_loader", - "loader_context", - "set_data_dir", "load", - "summarize", "load_experiment", - "load_wave", + "load_hdf5", "load_live", + "load_wave", + "loader_context", + "loaders", "open_hdf5", - "load_hdf5", "save_as_hdf5", "save_as_netcdf", + "set_data_dir", + "set_loader", + "summarize", ] import warnings diff --git a/src/erlab/io/igor.py b/src/erlab/io/igor.py index b5f3e49e..28eda63b 100644 --- a/src/erlab/io/igor.py +++ b/src/erlab/io/igor.py @@ -18,7 +18,7 @@ stacklevel=1, ) -__all__ = ["load_experiment", "load_h5", "load_wave", "load_pxp", "load_ibw"] +__all__ = ["load_experiment", "load_h5", "load_ibw", "load_pxp", "load_wave"] def _load_experiment_raw( diff --git a/src/erlab/io/plugins/ssrl52.py b/src/erlab/io/plugins/ssrl52.py index 3c16a4d1..8cbd35f3 100644 --- a/src/erlab/io/plugins/ssrl52.py +++ b/src/erlab/io/plugins/ssrl52.py @@ -196,7 +196,10 @@ def generate_summary( data = self.load(path) data_info.append( - [datetime.datetime.fromtimestamp(data.attrs["CreationTimeStamp"]), name] + [ + datetime.datetime.fromtimestamp(data.attrs["CreationTimeStamp"]), + name, + ] ) for k, v in summary_attrs.items(): diff --git a/src/erlab/io/utilities.py b/src/erlab/io/utilities.py index 0e8145d8..89ed9937 100644 --- a/src/erlab/io/utilities.py +++ b/src/erlab/io/utilities.py @@ -1,10 +1,10 @@ __all__ = [ - "showfitsinfo", "get_files", - "open_hdf5", "load_hdf5", + "open_hdf5", "save_as_hdf5", "save_as_netcdf", + "showfitsinfo", ] import os diff --git a/src/erlab/lattice.py b/src/erlab/lattice.py index b5f81f2b..43af654a 100644 --- a/src/erlab/lattice.py +++ b/src/erlab/lattice.py @@ -5,7 +5,7 @@ """ -__all__ = ["angle_between", "abc2avec", "avec2abc", "to_reciprocal", "to_real"] +__all__ = ["abc2avec", "angle_between", "avec2abc", "to_real", "to_reciprocal"] import numpy as np diff --git a/src/erlab/plotting/colors.py b/src/erlab/plotting/colors.py index 9bdda578..8be43817 100644 --- a/src/erlab/plotting/colors.py +++ b/src/erlab/plotting/colors.py @@ -26,22 +26,22 @@ """ __all__ = [ - "InversePowerNorm", - "TwoSlopePowerNorm", + "CenteredInversePowerNorm", "CenteredPowerNorm", + "InversePowerNorm", "TwoSlopeInversePowerNorm", - "CenteredInversePowerNorm", - "get_mappable", - "unify_clim", - "proportional_colorbar", - "nice_colorbar", + "TwoSlopePowerNorm", + "axes_textcolor", + "close_to_white", + "color_distance", "flatten_transparency", "gen_2d_colormap", - "color_distance", - "close_to_white", - "prominent_color", + "get_mappable", "image_is_light", - "axes_textcolor", + "nice_colorbar", + "prominent_color", + "proportional_colorbar", + "unify_clim", ] from collections.abc import Iterable, Sequence diff --git a/src/erlab/plotting/erplot.py b/src/erlab/plotting/erplot.py index 6dd83797..27f382ae 100644 --- a/src/erlab/plotting/erplot.py +++ b/src/erlab/plotting/erplot.py @@ -1,41 +1,41 @@ """Convenient access to various plotting functions.""" __all__ = [ + "CenteredInversePowerNorm", + "CenteredPowerNorm", + "InversePowerNorm", + "TwoSlopeInversePowerNorm", + "TwoSlopePowerNorm", + "autoscale_to", "copy_mathtext", "fancy_labels", + "fermiline", + "figwh", + "flatten_transparency", + "get_bz_edge", + "get_mappable", + "gradient_fill", + "image_is_light", "label_subplot_properties", "label_subplots", "label_subplots_nature", "mark_points", "mark_points_outside", + "nice_colorbar", + "place_inset", + "plot_array", + "plot_array_2d", + "plot_hex_bz", "plot_hv_text", + "plot_slices", "property_label", + "proportional_colorbar", "scale_units", "set_titles", "set_xlabels", "set_ylabels", "sizebar", - "get_bz_edge", - "plot_hex_bz", - "InversePowerNorm", - "TwoSlopePowerNorm", - "CenteredPowerNorm", - "TwoSlopeInversePowerNorm", - "CenteredInversePowerNorm", - "get_mappable", "unify_clim", - "flatten_transparency", - "image_is_light", - "nice_colorbar", - "proportional_colorbar", - "fermiline", - "figwh", - "autoscale_to", - "place_inset", - "plot_array", - "plot_array_2d", - "gradient_fill", - "plot_slices", ] import numpy as np diff --git a/src/erlab/plotting/general.py b/src/erlab/plotting/general.py index 244055a0..193998d5 100644 --- a/src/erlab/plotting/general.py +++ b/src/erlab/plotting/general.py @@ -3,16 +3,16 @@ from __future__ import annotations __all__ = [ - "figwh", + "LabeledCursor", "autoscale_off", "autoscale_to", - "LabeledCursor", + "fermiline", + "figwh", + "gradient_fill", "place_inset", "plot_array", "plot_array_2d", - "gradient_fill", "plot_slices", - "fermiline", ] import contextlib diff --git a/tests/test_kspace.py b/tests/test_kspace.py index f0822617..7a3f82b9 100644 --- a/tests/test_kspace.py +++ b/tests/test_kspace.py @@ -59,7 +59,7 @@ def angle_data(): def test_offsets(angle_data): angle_data.kspace.offsets.reset() angle_data.kspace.offsets = {"xi": 10.0} - answer = {k: 0.0 for k in angle_data.kspace.valid_offset_keys} + answer = dict.fromkeys(angle_data.kspace.valid_offset_keys, 0.0) answer["xi"] = 10.0 assert dict(angle_data.kspace.offsets) == answer