From 79b25590e1df24132660d8bee816b68638ebb329 Mon Sep 17 00:00:00 2001 From: alex-rakowski Date: Fri, 10 Nov 2023 00:44:31 -0800 Subject: [PATCH] E721 --- py4DSTEM/datacube/datacube.py | 2 +- .../legacy/legacy13/v13_py4dstem_classes/datacube.py | 6 +++--- py4DSTEM/preprocess/preprocess.py | 12 +++++++++--- py4DSTEM/process/diffraction/tdesign.py | 4 +++- py4DSTEM/visualize/vis_grid.py | 2 +- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/py4DSTEM/datacube/datacube.py b/py4DSTEM/datacube/datacube.py index 4d87afdd5..62da23e1e 100644 --- a/py4DSTEM/datacube/datacube.py +++ b/py4DSTEM/datacube/datacube.py @@ -653,7 +653,7 @@ def get_probe_size( "dp_mean" in self.treekeys ), "calculate .get_dp_mean() or pass a `dp` arg" DP = self.tree("dp_mean").data - elif type(dp) == str: + elif isinstance(dp, str): assert dp in self.treekeys, f"mode {dp} not found in the tree" DP = self.tree(dp) elif type(dp) == np.ndarray: diff --git a/py4DSTEM/io/legacy/legacy13/v13_py4dstem_classes/datacube.py b/py4DSTEM/io/legacy/legacy13/v13_py4dstem_classes/datacube.py index 422d47bc6..979579d49 100644 --- a/py4DSTEM/io/legacy/legacy13/v13_py4dstem_classes/datacube.py +++ b/py4DSTEM/io/legacy/legacy13/v13_py4dstem_classes/datacube.py @@ -108,7 +108,7 @@ def R_pixel_size(self): @R_pixel_size.setter def R_pixel_size(self, x): - if type(x) is not list: + if not isinstance(x, list): x = [x, x] self.set_dim(0, [0, x[0]]) self.set_dim(1, [0, x[1]]) @@ -120,7 +120,7 @@ def R_pixel_units(self): @R_pixel_units.setter def R_pixel_units(self, x): - if type(x) is not list: + if not isinstance(x, list): x = [x, x] self.dim_units[0] = x[0] self.dim_units[1] = x[1] @@ -133,7 +133,7 @@ def Q_pixel_size(self): @Q_pixel_size.setter def Q_pixel_size(self, x): - if type(x) is not list: + if not isinstance(x, list): x = [x, x] self.set_dim(2, [0, x[0]]) self.set_dim(3, [0, x[1]]) diff --git a/py4DSTEM/preprocess/preprocess.py b/py4DSTEM/preprocess/preprocess.py index fb4983622..9febf229a 100644 --- a/py4DSTEM/preprocess/preprocess.py +++ b/py4DSTEM/preprocess/preprocess.py @@ -166,7 +166,9 @@ def bin_data_diffraction(datacube, bin_factor, dtype=None): """ # validate inputs - assert type(bin_factor) is int, f"Error: binning factor {bin_factor} is not an int." + assert isinstance( + bin_factor, int + ), f"Error: binning factor {bin_factor} is not an int." if bin_factor == 1: return datacube if dtype is None: @@ -225,7 +227,9 @@ def bin_data_mmap(datacube, bin_factor, dtype=np.float32): """ # validate inputs - assert type(bin_factor) is int, f"Error: binning factor {bin_factor} is not an int." + assert isinstance( + bin_factor, int + ), f"Error: binning factor {bin_factor} is not an int." if bin_factor == 1: return datacube @@ -268,7 +272,9 @@ def bin_data_real(datacube, bin_factor): Performs diffraction space binning of data by bin_factor. """ # validate inputs - assert type(bin_factor) is int, f"Bin factor {bin_factor} is not an int." + assert isinstance( + bin_factor, int + ), f"Error: binning factor {bin_factor} is not an int." if bin_factor <= 1: return datacube diff --git a/py4DSTEM/process/diffraction/tdesign.py b/py4DSTEM/process/diffraction/tdesign.py index 1a0a81fb6..79edae315 100644 --- a/py4DSTEM/process/diffraction/tdesign.py +++ b/py4DSTEM/process/diffraction/tdesign.py @@ -35,7 +35,9 @@ def tdesign(degree): assert degree <= 21, "Degree must be 21 or less." assert degree >= 1, "Degree should be at least 1." - assert type(degree) is int, "Degree should be an integer." + assert isinstance( + degree, int + ), f"Degree should be an integer, {type(degree)} passed." vecs = _tdesigns[degree - 1] diff --git a/py4DSTEM/visualize/vis_grid.py b/py4DSTEM/visualize/vis_grid.py index d24b0b8d8..ef318c021 100644 --- a/py4DSTEM/visualize/vis_grid.py +++ b/py4DSTEM/visualize/vis_grid.py @@ -285,7 +285,7 @@ def show_image_grid( ) except IndexError: ax.axis("off") - if type(title) == str: + if isinstance(title, str): fig.suptitle(title) if suptitle: fig.suptitle(suptitle)