Skip to content

Commit

Permalink
ruff --select C419
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-rakowski committed Nov 10, 2023
1 parent 857715a commit 7892191
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 66 deletions.
4 changes: 2 additions & 2 deletions py4DSTEM/braggvectors/threshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def threshold_Braggpeaks(
pattern
"""
assert all(
[item in pointlistarray.dtype.fields for item in ["qx", "qy", "intensity"]]
item in pointlistarray.dtype.fields for item in ["qx", "qy", "intensity"]
), "pointlistarray must include the coordinates 'qx', 'qy', and 'intensity'."
for Rx, Ry in tqdmnd(
pointlistarray.shape[0],
Expand Down Expand Up @@ -113,7 +113,7 @@ def universal_threshold(
assert isinstance(pointlistarray, PointListArray)
assert metric in ("maximum", "average", "median", "manual")
assert all(
[item in pointlistarray.dtype.fields for item in ["qx", "qy", "intensity"]]
item in pointlistarray.dtype.fields for item in ["qx", "qy", "intensity"]
), "pointlistarray must include the coordinates 'qx', 'qy', and 'intensity'."
_pointlistarray = pointlistarray.copy()
if name is None:
Expand Down
10 changes: 5 additions & 5 deletions py4DSTEM/data/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def get_origin(self, rx=None, ry=None):
qx0 = self._get_value("qx0", rx, ry)
qy0 = self._get_value("qy0", rx, ry)
ans = (qx0, qy0)
if any([x is None for x in ans]):
if any(x is None for x in ans):
ans = None
return ans

Expand All @@ -518,7 +518,7 @@ def get_origin_shift(self, rx=None, ry=None):
qx0 = self._get_value("qx0_shift", rx, ry)
qy0 = self._get_value("qy0_shift", rx, ry)
ans = (qx0, qy0)
if any([x is None for x in ans]):
if any(x is None for x in ans):
ans = None
return ans

Expand All @@ -540,7 +540,7 @@ def get_origin_meas(self, rx=None, ry=None):
qx0 = self._get_value("qx0_meas", rx, ry)
qy0 = self._get_value("qy0_meas", rx, ry)
ans = (qx0, qy0)
if any([x is None for x in ans]):
if any(x is None for x in ans):
ans = None
return ans

Expand Down Expand Up @@ -615,7 +615,7 @@ def get_ellipse(self, rx=None, ry=None):
b = self.get_b(rx, ry)
theta = self.get_theta(rx, ry)
ans = (a, b, theta)
if any([x is None for x in ans]):
if any(x is None for x in ans):
ans = None
return ans

Expand Down Expand Up @@ -778,7 +778,7 @@ def get_probe_param(self):
qx0 = self._get_value("qx0")
qy0 = self._get_value("qy0")
ans = (probe_semiangle, qx0, qy0)
if any([x is None for x in ans]):
if any(x is None for x in ans):
ans = None
return ans

Expand Down
4 changes: 2 additions & 2 deletions py4DSTEM/io/legacy/legacy12/read_v0_12.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def read_v0_12(fp, **kwargs):
), "Error: data must be specified with strings or integers only."
if not isinstance(data_id, (int, np.int_, str)):
assert all(
[isinstance(d, (int, np.int_, str)) for d in data_id]
isinstance(d, (int, np.int_, str)) for d in data_id
), "Error: data must be specified with strings or integers only."

# Parse optional arguments
Expand Down Expand Up @@ -250,7 +250,7 @@ def get_data_from_str(filepath, tg, data_id, mem="RAM", binfactor=1, bindtype=No
def get_data_from_list(filepath, tg, data_id, mem="RAM", binfactor=1, bindtype=None):
"""Accepts a filepath to a valid py4DSTEM file and a list or tuple specifying data, and returns the data."""
assert isinstance(data_id, (list, tuple))
assert all([isinstance(d, (int, np.int_, str)) for d in data_id])
assert all(isinstance(d, (int, np.int_, str)) for d in data_id)
data = []
for el in data_id:
if isinstance(el, (int, np.int_)):
Expand Down
4 changes: 2 additions & 2 deletions py4DSTEM/io/legacy/legacy12/read_v0_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def read_v0_5(fp, **kwargs):
), "Error: data must be specified with strings or integers only."
if not isinstance(data_id, (int, str)):
assert all(
[isinstance(d, (int, str)) for d in data_id]
isinstance(d, (int, str)) for d in data_id
), "Error: data must be specified with strings or integers only."

# Parse optional arguments
Expand Down Expand Up @@ -248,7 +248,7 @@ def get_data_from_str(fp, tg, data_id, mem="RAM", binfactor=1, bindtype=None):
def get_data_from_list(fp, tg, data_id, mem="RAM", binfactor=1, bindtype=None):
"""Accepts a fp to a valid py4DSTEM file and a list or tuple specifying data, and returns the data."""
assert isinstance(data_id, (list, tuple))
assert all([isinstance(d, (int, str)) for d in data_id])
assert all(isinstance(d, (int, str)) for d in data_id)
data = []
for el in data_id:
if isinstance(el, int):
Expand Down
4 changes: 2 additions & 2 deletions py4DSTEM/io/legacy/legacy12/read_v0_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def read_v0_6(fp, **kwargs):
), "Error: data must be specified with strings or integers only."
if not isinstance(data_id, (int, str)):
assert all(
[isinstance(d, (int, str)) for d in data_id]
isinstance(d, (int, str)) for d in data_id
), "Error: data must be specified with strings or integers only."

# Parse optional arguments
Expand Down Expand Up @@ -248,7 +248,7 @@ def get_data_from_str(fp, tg, data_id, mem="RAM", binfactor=1, bindtype=None):
def get_data_from_list(fp, tg, data_id, mem="RAM", binfactor=1, bindtype=None):
"""Accepts a fp to a valid py4DSTEM file and a list or tuple specifying data, and returns the data."""
assert isinstance(data_id, (list, tuple))
assert all([isinstance(d, (int, str)) for d in data_id])
assert all(isinstance(d, (int, str)) for d in data_id)
data = []
for el in data_id:
if isinstance(el, int):
Expand Down
4 changes: 2 additions & 2 deletions py4DSTEM/io/legacy/legacy12/read_v0_7.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def read_v0_7(fp, **kwargs):
), "Error: data must be specified with strings or integers only."
if not isinstance(data_id, (int, str)):
assert all(
[isinstance(d, (int, str)) for d in data_id]
isinstance(d, (int, str)) for d in data_id
), "Error: data must be specified with strings or integers only."

# Parse optional arguments
Expand Down Expand Up @@ -248,7 +248,7 @@ def get_data_from_str(fp, tg, data_id, mem="RAM", binfactor=1, bindtype=None):
def get_data_from_list(fp, tg, data_id, mem="RAM", binfactor=1, bindtype=None):
"""Accepts a fp to a valid py4DSTEM file and a list or tuple specifying data, and returns the data."""
assert isinstance(data_id, (list, tuple))
assert all([isinstance(d, (int, str)) for d in data_id])
assert all(isinstance(d, (int, str)) for d in data_id)
data = []
for el in data_id:
if isinstance(el, int):
Expand Down
4 changes: 2 additions & 2 deletions py4DSTEM/io/legacy/legacy12/read_v0_9.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def read_v0_9(fp, **kwargs):
), "Error: data must be specified with strings or integers only."
if not isinstance(data_id, (int, np.int_, str)):
assert all(
[isinstance(d, (int, np.int_, str)) for d in data_id]
isinstance(d, (int, np.int_, str)) for d in data_id
), "Error: data must be specified with strings or integers only."

# Parse optional arguments
Expand Down Expand Up @@ -255,7 +255,7 @@ def get_data_from_str(filepath, tg, data_id, mem="RAM", binfactor=1, bindtype=No
def get_data_from_list(filepath, tg, data_id, mem="RAM", binfactor=1, bindtype=None):
"""Accepts a filepath to a valid py4DSTEM file and a list or tuple specifying data, and returns the data."""
assert isinstance(data_id, (list, tuple))
assert all([isinstance(d, (int, np.int_, str)) for d in data_id])
assert all(isinstance(d, (int, np.int_, str)) for d in data_id)
data = []
for el in data_id:
if isinstance(el, (int, np.int_)):
Expand Down
2 changes: 1 addition & 1 deletion py4DSTEM/io/legacy/legacy13/v13_emd_classes/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def Metadata_to_h5(metadata, group):
dset.attrs["type"] = np.string_("tuple")

# of tuples
elif any([isinstance(v[i], tuple) for i in range(len(v))]):
elif any(isinstance(v[i], tuple) for i in range(len(v))):
dset_grp = grp.create_group(k)
dset_grp.attrs["type"] = np.string_("tuple_of_tuples")
dset_grp.attrs["length"] = len(v)
Expand Down
2 changes: 1 addition & 1 deletion py4DSTEM/io/legacy/read_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def is_py4DSTEM_version13(filepath):
if "emd_group_type" in f[k].attrs:
if f[k].attrs["emd_group_type"] == "root":
if all(
[x in f[k].attrs for x in ("version_major", "version_minor")]
x in f[k].attrs for x in ("version_major", "version_minor")
):
if (
int(f[k].attrs["version_major"]),
Expand Down
16 changes: 6 additions & 10 deletions py4DSTEM/process/phase/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,12 @@ def evaluate_chi(
alpha = xp.array(alpha)

array = xp.zeros(alpha.shape, dtype=np.float32)
if any([p[symbol] != 0.0 for symbol in ("C10", "C12", "phi12")]):
if any(p[symbol] != 0.0 for symbol in ("C10", "C12", "phi12")):
array += (
1 / 2 * alpha2 * (p["C10"] + p["C12"] * xp.cos(2 * (phi - p["phi12"])))
)

if any([p[symbol] != 0.0 for symbol in ("C21", "phi21", "C23", "phi23")]):
if any(p[symbol] != 0.0 for symbol in ("C21", "phi21", "C23", "phi23")):
array += (
1
/ 3
Expand All @@ -312,7 +312,7 @@ def evaluate_chi(
)

if any(
[p[symbol] != 0.0 for symbol in ("C30", "C32", "phi32", "C34", "phi34")]
p[symbol] != 0.0 for symbol in ("C30", "C32", "phi32", "C34", "phi34")
):
array += (
1
Expand All @@ -326,10 +326,8 @@ def evaluate_chi(
)

if any(
[
p[symbol] != 0.0
p[symbol] != 0.0
for symbol in ("C41", "phi41", "C43", "phi43", "C45", "phi41")
]
):
array += (
1
Expand All @@ -344,10 +342,8 @@ def evaluate_chi(
)

if any(
[
p[symbol] != 0.0
p[symbol] != 0.0
for symbol in ("C50", "C52", "phi52", "C54", "phi54", "C56", "phi56")
]
):
array += (
1
Expand Down Expand Up @@ -1048,7 +1044,7 @@ def fourier_rotate_real_volume(array, angle, axes=(0, 1), xp=np):
if len(axes) != 2:
raise ValueError("axes should contain exactly two values")

if not all([float(ax).is_integer() for ax in axes]):
if not all(float(ax).is_integer() for ax in axes):
raise ValueError("axes should contain only integer values")

if axes[0] < 0:
Expand Down
2 changes: 1 addition & 1 deletion py4DSTEM/process/wholepatternfit/wpf.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def _finalize_model(self):
self.upper_bound = np.array([param.upper_bound for param in unique_params])
self.lower_bound = np.array([param.lower_bound for param in unique_params])

self.hasJacobian = all([m.hasJacobian for m in self.model])
self.hasJacobian = all(m.hasJacobian for m in self.model)

self.nParams = self.x0.shape[0]

Expand Down
Loading

0 comments on commit 7892191

Please sign in to comment.