Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into phase_contrast
Browse files Browse the repository at this point in the history
  • Loading branch information
gvarnavi committed Nov 21, 2023
2 parents 6984594 + 244f360 commit 2a3a4a8
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 31 deletions.
2 changes: 1 addition & 1 deletion py4DSTEM/braggvectors/diskdetection_aiml_cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ def get_maxima_2D_cp(
if minSpacing > 0:
deletemask = np.zeros(len(maxima), dtype=bool)
for i in range(len(maxima)):
if deletemask[i] is False:
if deletemask[i] == False: # noqa: E712
tooClose = (
(maxima["x"] - maxima["x"][i]) ** 2
+ (maxima["y"] - maxima["y"][i]) ** 2
Expand Down
2 changes: 1 addition & 1 deletion py4DSTEM/braggvectors/diskdetection_cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def get_maxima_2D(
if minSpacing > 0:
deletemask = np.zeros(len(maxima), dtype=bool)
for i in range(len(maxima)):
if deletemask[i] is False:
if deletemask[i] == False: # noqa: E712
tooClose = (
(maxima["x"] - maxima["x"][i]) ** 2
+ (maxima["y"] - maxima["y"][i]) ** 2
Expand Down
5 changes: 2 additions & 3 deletions py4DSTEM/braggvectors/threshold.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Bragg peaks thresholding fns

import numpy as np

from emdfile import tqdmnd, PointListArray


Expand Down Expand Up @@ -52,7 +51,7 @@ def threshold_Braggpeaks(
r2 = minPeakSpacing**2
deletemask = np.zeros(pointlist.length, dtype=bool)
for i in range(pointlist.length):
if deletemask[i] is False:
if deletemask[i] == False: # noqa: E712
tooClose = (
(pointlist.data["qx"] - pointlist.data["qx"][i]) ** 2
+ (pointlist.data["qy"] - pointlist.data["qy"][i]) ** 2
Expand Down Expand Up @@ -160,7 +159,7 @@ def universal_threshold(
r2 = minPeakSpacing**2
deletemask = np.zeros(pointlist.length, dtype=bool)
for i in range(pointlist.length):
if deletemask[i] is False:
if deletemask[i] == False: # noqa: E712
tooClose = (
(pointlist.data["qx"] - pointlist.data["qx"][i]) ** 2
+ (pointlist.data["qy"] - pointlist.data["qy"][i]) ** 2
Expand Down
14 changes: 7 additions & 7 deletions py4DSTEM/io/filereaders/read_K2.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,9 @@ def _find_offsets(self):
for i in range(8):
sync = False
frame = 0
while sync is False:
while sync == False: # noqa: E712
sync = self._bin_files[i][frame]["block"] == block_id
if sync is False:
if sync == False: # noqa: E712
frame += 1
self._shutter_offsets[i] += frame
print("Offsets are currently ", self._shutter_offsets)
Expand All @@ -358,20 +358,20 @@ def _find_offsets(self):
sync = False
next_frame = stripe[j]["frame"]

if sync is False:
if sync == False: # noqa: E712
# the first frame is incomplete, so we need to seek the next one
print(
f"First frame ({first_frame}) incomplete, seeking frame {next_frame}..."
)
for i in range(8):
sync = False
frame = 0
while sync is False:
while sync == False: # noqa: E712
sync = (
self._bin_files[i][self._shutter_offsets[i] + frame]["frame"]
== next_frame
)
if sync is False:
if sync == False: # noqa: E712
frame += 1
self._shutter_offsets[i] += frame
print("Offsets are now ", self._shutter_offsets)
Expand All @@ -387,7 +387,7 @@ def _find_offsets(self):
]
if np.any(stripe[:]["frame"] != first_frame):
sync = False
if sync is True:
if sync == True: # noqa: E712
print("New frame is complete!")
else:
print("Next frame also incomplete!!!! Data may be corrupt?")
Expand All @@ -397,7 +397,7 @@ def _find_offsets(self):
for i in range(8):
shutter = False
frame = 0
while shutter is False:
while shutter == False: # noqa: E712
offset = self._shutter_offsets[i] + (frame * 32)
stripe = self._bin_files[i][offset : offset + 32]
shutter = stripe[0]["shutter"]
Expand Down
2 changes: 1 addition & 1 deletion py4DSTEM/preprocess/radialbkgrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def get_1D_polar_background(
# Crop polar data to maximum distance which contains information from original image
if (polarData.mask.sum(axis=(0)) == polarData.shape[0]).any():
ii = polarData.data.shape[1] - 1
while polarData.mask[:, ii].all() is True:
while polarData.mask[:, ii].all() == True: # noqa: E712
ii = ii - 1
maximalDistance = ii
polarData = polarData[:, 0:maximalDistance]
Expand Down
2 changes: 1 addition & 1 deletion py4DSTEM/preprocess/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def filter_2D_maxima(
if minSpacing > 0:
deletemask = np.zeros(len(maxima), dtype=bool)
for i in range(len(maxima)):
if deletemask[i] is False:
if deletemask[i] == False: # noqa: E712
tooClose = (
(maxima["x"] - maxima["x"][i]) ** 2
+ (maxima["y"] - maxima["y"][i]) ** 2
Expand Down
2 changes: 1 addition & 1 deletion py4DSTEM/process/calibration/ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def fit_ellipse_1D(ar, center=None, fitradii=None, mask=None):
rr = np.sqrt((xx - x0) ** 2 + (yy - y0) ** 2)
_mask = (rr > ri) * (rr <= ro)
if mask is not None:
_mask *= mask is False
_mask *= mask == False # noqa: E712
xs, ys = np.nonzero(_mask)
vals = ar[_mask]

Expand Down
2 changes: 1 addition & 1 deletion py4DSTEM/process/calibration/qpixelsize.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ def get_dq_from_indexed_peaks(qs, hkl, a):
# Get pixel size
dq = 1 / (c * a)
qs_fit = d_inv[mask] / a
hkl_fit = [hkl[i] for i in range(len(hkl)) if mask[i] is True]
hkl_fit = [hkl[i] for i in range(len(hkl)) if mask[i] == True] # noqa: E712

return dq, qs_fit, hkl_fit
4 changes: 2 additions & 2 deletions py4DSTEM/process/classification/braggvectorclassification.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,8 @@ def merge_iterative(self, threshBPs=0.1, threshScanPosition=0.1):
W_merge = W_merge[:, 1:]
H_merge = H_merge[1:, :]

W_ = np.hstack((W_[:, merged is False], W_merge))
H_ = np.vstack((H_[merged is False, :], H_merge))
W_ = np.hstack((W_[:, merged == False], W_merge)) # noqa: E712
H_ = np.vstack((H_[merged == False, :], H_merge)) # noqa: E712
Nc_ = W_.shape[1]

if len(merge_candidates) == 0:
Expand Down
2 changes: 1 addition & 1 deletion py4DSTEM/process/classification/featurization.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def from_braggvectors(
(pointlist.data["qy"] / q_pixel_size) + Q_Ny / 2
).astype(int),
]
is False
== False # noqa: E712
),
True,
False,
Expand Down
2 changes: 1 addition & 1 deletion py4DSTEM/process/diffraction/crystal_phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def quantify_phase_pointlist(
if len(pointlist["qx"]) > 0:
if mask_peaks is not None:
for i in range(len(mask_peaks)):
if mask_peaks[i] is None:
if mask_peaks[i] == None: # noqa: E711
continue
inds_mask = np.where(
pointlist_peak_intensity_matches[:, mask_peaks[i]] != 0
Expand Down
7 changes: 5 additions & 2 deletions py4DSTEM/process/polar/polar_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ def calculate_pair_dist_function(
r_max=20.0,
r_step=0.02,
damp_origin_fluctuations=True,
enforce_positivity=True,
density=None,
plot_background_fits=False,
plot_sf_estimate=False,
Expand Down Expand Up @@ -281,6 +282,8 @@ def calculate_pair_dist_function(
The value of the PDF approaching the origin should be zero, however numerical
instability may result in non-physical finite values there. This flag toggles
damping the value of the PDF to zero near the origin.
enforce_positivity:
Force all pdf values to be >0.
density : number or None
The density of the sample, if known. If this is not provided, only the
reduced PDF is calculated. If this value is provided, the PDF is also
Expand Down Expand Up @@ -411,13 +414,13 @@ def calculate_pair_dist_function(
if density is not None:
pdf = pdf_reduced.copy()
pdf[1:] /= 4 * np.pi * density * r[1:] * (r[1] - r[0])
pdf *= 2 / np.pi
pdf += 1

# damp and clip values below zero
if damp_origin_fluctuations:
pdf *= r_mask
pdf = np.maximum(pdf, 0.0)
if enforce_positivity:
pdf = np.maximum(pdf, 0.0)

# store results
self.pdf = pdf
Expand Down
36 changes: 28 additions & 8 deletions py4DSTEM/process/polar/polar_datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,36 @@ def transform(self):
these values directly. Length 2 list of ints uses the calibrated
origin value at this scan position. None uses the calibrated mean
origin.
ellipse : tuple or None
Variable behavior depending on the arg type. Length 3 tuples uses
these values directly (a,b,theta). None uses the calibrated value.
mask : boolean array or None
A mask applied to the data before transformation. The value of
masked pixels (0's) in the output is determined by `returnval`. Note
that this mask is applied in combination with any mask at
PolarData.mask.
returnval : 'masked' or 'nan' or None
Controls the returned data. 'masked' returns a numpy masked array.
'nan' returns a normal numpy array with masked pixels set to np.nan.
None returns a 2-tuple of numpy arrays - the transformed data with
masked pixels set to 0, and the transformed mask.
masked pixels in the output is determined by `returnval`. Note that
this mask is applied in combination with any mask at PolarData.mask.
mask_thresh : number
Pixels in the transformed mask with values below this number are
considered masked, and will be populated by the values specified
by `returnval`.
returnval : 'masked' or 'nan' or 'all' or 'zeros' or 'all_zeros'
Controls the returned data, including how un-sampled points
are handled.
- 'masked' returns a numpy masked array.
- 'nan' returns a normal numpy array with unsampled pixels set to
np.nan.
- 'all' returns a 4-tuple of numpy arrays - the transformed data
with unsampled pixels set to 'nan', the normalization array, the
normalization array scaled to account for the q-dependent
sampling density, and the polar boolean mask
- 'zeros' returns a normal numpy with unsampled pixels set to 0
- 'all_zeros' returns the same 4-tuple as 'all', but with unsampled
pixels in the transformed data array set to zeros.
Returns
--------
variable
see `returnval`, above. Default is a masked array representing
the polar transformed data.
"""
return self._polar_data_getter._transform

Expand Down
2 changes: 1 addition & 1 deletion py4DSTEM/process/wholepatternfit/wp_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ def __init__(
name="Complex Overlapped Disk Lattice",
verbose=False,
):
return NotImplementedError(
raise NotImplementedError(
"This model type has not been updated for use with the new architecture."
)

Expand Down

0 comments on commit 2a3a4a8

Please sign in to comment.