diff --git a/py4DSTEM/braggvectors/diskdetection_aiml_cuda.py b/py4DSTEM/braggvectors/diskdetection_aiml_cuda.py index d23770586..95e1ef0cb 100644 --- a/py4DSTEM/braggvectors/diskdetection_aiml_cuda.py +++ b/py4DSTEM/braggvectors/diskdetection_aiml_cuda.py @@ -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 diff --git a/py4DSTEM/braggvectors/diskdetection_cuda.py b/py4DSTEM/braggvectors/diskdetection_cuda.py index 670361b3b..19e1d0c10 100644 --- a/py4DSTEM/braggvectors/diskdetection_cuda.py +++ b/py4DSTEM/braggvectors/diskdetection_cuda.py @@ -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 diff --git a/py4DSTEM/braggvectors/threshold.py b/py4DSTEM/braggvectors/threshold.py index c6c1c4afc..7e19404b1 100644 --- a/py4DSTEM/braggvectors/threshold.py +++ b/py4DSTEM/braggvectors/threshold.py @@ -1,7 +1,6 @@ # Bragg peaks thresholding fns import numpy as np - from emdfile import tqdmnd, PointListArray @@ -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 @@ -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 diff --git a/py4DSTEM/io/filereaders/read_K2.py b/py4DSTEM/io/filereaders/read_K2.py index e0a5dae1f..5df91f2dc 100644 --- a/py4DSTEM/io/filereaders/read_K2.py +++ b/py4DSTEM/io/filereaders/read_K2.py @@ -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) @@ -358,7 +358,7 @@ 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}..." @@ -366,12 +366,12 @@ 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][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) @@ -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?") @@ -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"] diff --git a/py4DSTEM/preprocess/radialbkgrd.py b/py4DSTEM/preprocess/radialbkgrd.py index da225ed74..1fcb859cd 100644 --- a/py4DSTEM/preprocess/radialbkgrd.py +++ b/py4DSTEM/preprocess/radialbkgrd.py @@ -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] diff --git a/py4DSTEM/preprocess/utils.py b/py4DSTEM/preprocess/utils.py index 829f66608..dcd890ef8 100644 --- a/py4DSTEM/preprocess/utils.py +++ b/py4DSTEM/preprocess/utils.py @@ -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 diff --git a/py4DSTEM/process/calibration/ellipse.py b/py4DSTEM/process/calibration/ellipse.py index e6a216cf1..2954de377 100644 --- a/py4DSTEM/process/calibration/ellipse.py +++ b/py4DSTEM/process/calibration/ellipse.py @@ -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] diff --git a/py4DSTEM/process/calibration/qpixelsize.py b/py4DSTEM/process/calibration/qpixelsize.py index 0510fad06..d59d5a45c 100644 --- a/py4DSTEM/process/calibration/qpixelsize.py +++ b/py4DSTEM/process/calibration/qpixelsize.py @@ -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 diff --git a/py4DSTEM/process/classification/braggvectorclassification.py b/py4DSTEM/process/classification/braggvectorclassification.py index 4956f7630..c3e36273f 100644 --- a/py4DSTEM/process/classification/braggvectorclassification.py +++ b/py4DSTEM/process/classification/braggvectorclassification.py @@ -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: diff --git a/py4DSTEM/process/classification/featurization.py b/py4DSTEM/process/classification/featurization.py index b462ea1eb..126583413 100644 --- a/py4DSTEM/process/classification/featurization.py +++ b/py4DSTEM/process/classification/featurization.py @@ -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, diff --git a/py4DSTEM/process/diffraction/crystal_phase.py b/py4DSTEM/process/diffraction/crystal_phase.py index bac1cf8c7..d28616aa9 100644 --- a/py4DSTEM/process/diffraction/crystal_phase.py +++ b/py4DSTEM/process/diffraction/crystal_phase.py @@ -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 diff --git a/py4DSTEM/process/polar/polar_analysis.py b/py4DSTEM/process/polar/polar_analysis.py index 4f053dcfa..7df00a235 100644 --- a/py4DSTEM/process/polar/polar_analysis.py +++ b/py4DSTEM/process/polar/polar_analysis.py @@ -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, @@ -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 @@ -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 diff --git a/py4DSTEM/process/polar/polar_datacube.py b/py4DSTEM/process/polar/polar_datacube.py index 56071c534..4c06d4c09 100644 --- a/py4DSTEM/process/polar/polar_datacube.py +++ b/py4DSTEM/process/polar/polar_datacube.py @@ -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 diff --git a/py4DSTEM/process/wholepatternfit/wp_models.py b/py4DSTEM/process/wholepatternfit/wp_models.py index 3d53c1743..c0907a11e 100644 --- a/py4DSTEM/process/wholepatternfit/wp_models.py +++ b/py4DSTEM/process/wholepatternfit/wp_models.py @@ -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." )