From 460386017ce38eb1a187d55d398fcb93068e650b Mon Sep 17 00:00:00 2001 From: bsavitzky Date: Tue, 14 Nov 2023 12:23:18 -0800 Subject: [PATCH 01/16] fixes polar transform docstring --- py4DSTEM/process/polar/polar_datacube.py | 36 ++++++++++++++++++------ 1 file changed, 28 insertions(+), 8 deletions(-) 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 From 079d4b989bb73799d69cd747c920022a5b2953c3 Mon Sep 17 00:00:00 2001 From: Stephanie Ribet Date: Tue, 14 Nov 2023 18:02:03 -0800 Subject: [PATCH 02/16] filter_2D_maxima --- py4DSTEM/preprocess/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py4DSTEM/preprocess/utils.py b/py4DSTEM/preprocess/utils.py index 829f66608..752e2f81c 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: tooClose = ( (maxima["x"] - maxima["x"][i]) ** 2 + (maxima["y"] - maxima["y"][i]) ** 2 From d0c8a2a8b35d91218045b275e6fbefe9b873bf7b Mon Sep 17 00:00:00 2001 From: alex-rakowski Date: Tue, 14 Nov 2023 18:38:47 -0800 Subject: [PATCH 03/16] deletemask[i] == False --- py4DSTEM/braggvectors/diskdetection_aiml_cuda.py | 2 +- py4DSTEM/braggvectors/diskdetection_cuda.py | 2 +- py4DSTEM/braggvectors/threshold.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) 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..4cc4c98ec 100644 --- a/py4DSTEM/braggvectors/threshold.py +++ b/py4DSTEM/braggvectors/threshold.py @@ -52,7 +52,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 +160,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 From 2481818f487a0a0710d510c53756ffd644946707 Mon Sep 17 00:00:00 2001 From: alex-rakowski Date: Tue, 14 Nov 2023 21:45:40 -0800 Subject: [PATCH 04/16] more is to == errors --- py4DSTEM/braggvectors/threshold.py | 4 ++-- py4DSTEM/process/calibration/ellipse.py | 4 ++-- py4DSTEM/process/calibration/qpixelsize.py | 2 +- py4DSTEM/process/classification/braggvectorclassification.py | 4 ++-- py4DSTEM/process/classification/featurization.py | 2 +- py4DSTEM/process/diffraction/crystal_phase.py | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/py4DSTEM/braggvectors/threshold.py b/py4DSTEM/braggvectors/threshold.py index 4cc4c98ec..472d57d19 100644 --- a/py4DSTEM/braggvectors/threshold.py +++ b/py4DSTEM/braggvectors/threshold.py @@ -1,7 +1,7 @@ # Bragg peaks thresholding fns import numpy as np - +import numpy.typing as npt from emdfile import tqdmnd, PointListArray @@ -158,7 +158,7 @@ def universal_threshold( # Remove peaks that are too close together if maxNumPeaks is not False: r2 = minPeakSpacing**2 - deletemask = np.zeros(pointlist.length, dtype=bool) + deletemask: npt.NDArray = np.zeros(pointlist.length, dtype=bool) for i in range(pointlist.length): if deletemask[i] == False: # noqa: E712 tooClose = ( diff --git a/py4DSTEM/process/calibration/ellipse.py b/py4DSTEM/process/calibration/ellipse.py index e6a216cf1..0cf4c1ed1 100644 --- a/py4DSTEM/process/calibration/ellipse.py +++ b/py4DSTEM/process/calibration/ellipse.py @@ -63,8 +63,8 @@ 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 - xs, ys = np.nonzero(_mask) + _mask *= mask == False # noqa: E712 + xs, ys = np.nonzero(_mask) vals = ar[_mask] # Get initial parameters guess 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 From de42ddc96fb4a2eb689eaef240f3935540e7f140 Mon Sep 17 00:00:00 2001 From: alex-rakowski Date: Tue, 14 Nov 2023 21:47:08 -0800 Subject: [PATCH 05/16] black --- py4DSTEM/process/calibration/ellipse.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/py4DSTEM/process/calibration/ellipse.py b/py4DSTEM/process/calibration/ellipse.py index 0cf4c1ed1..2954de377 100644 --- a/py4DSTEM/process/calibration/ellipse.py +++ b/py4DSTEM/process/calibration/ellipse.py @@ -63,8 +63,8 @@ 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 == False # noqa: E712 - xs, ys = np.nonzero(_mask) + _mask *= mask == False # noqa: E712 + xs, ys = np.nonzero(_mask) vals = ar[_mask] # Get initial parameters guess From 497438ffb7b0c9907a3033e8008d7a156c0e9656 Mon Sep 17 00:00:00 2001 From: alex-rakowski Date: Tue, 14 Nov 2023 22:04:43 -0800 Subject: [PATCH 06/16] this commit looks like it went wrong --- py4DSTEM/preprocess/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 497b7d278b05f28754e5821e14b0fe11d05593f6 Mon Sep 17 00:00:00 2001 From: bsavitzky Date: Wed, 15 Nov 2023 12:03:14 -0800 Subject: [PATCH 07/16] fixes flake options syntax --- .github/linters/.flake8 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/linters/.flake8 b/.github/linters/.flake8 index e30e76b99..97dbb6614 100644 --- a/.github/linters/.flake8 +++ b/.github/linters/.flake8 @@ -1,2 +1,14 @@ [flake8] -select: "F402,F404,F812,F823,F831,F821,F822,E112,E113,E901,E902,E999" +select: + F402 + F404 + F812 + F823 + F831 + F821 + F822 + E112 + E113 + E901 + E902 + E999 From 06f3a4369fc4790283757ecf12f665591303c804 Mon Sep 17 00:00:00 2001 From: bsavitzky Date: Wed, 15 Nov 2023 12:04:57 -0800 Subject: [PATCH 08/16] fixes flake options syntax --- .github/linters/.flake8 | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/.github/linters/.flake8 b/.github/linters/.flake8 index 97dbb6614..736dd1bd9 100644 --- a/.github/linters/.flake8 +++ b/.github/linters/.flake8 @@ -1,14 +1,15 @@ [flake8] select: - F402 - F404 - F812 - F823 - F831 - F821 - F822 - E112 - E113 - E901 - E902 - E999 + F402, + F404, + F812, + F823, + F831, + F821, + F822, + E112, + E113, + E901, + E902, + E999, + From ac9c0d144f712fbc592bdc6085a6c3687d6c7dfe Mon Sep 17 00:00:00 2001 From: bsavitzky Date: Wed, 15 Nov 2023 12:10:35 -0800 Subject: [PATCH 09/16] moves .flake9 config --- .github/linters/.flake8 => .flake8 | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/linters/.flake8 => .flake8 (100%) diff --git a/.github/linters/.flake8 b/.flake8 similarity index 100% rename from .github/linters/.flake8 rename to .flake8 From afcc531c4a1f18236b8fe2f605a26a1bdac71b74 Mon Sep 17 00:00:00 2001 From: bsavitzky Date: Thu, 16 Nov 2023 08:48:22 -0800 Subject: [PATCH 10/16] reverts accidental merge --- .flake8 | 15 --------------- .github/linters/.flake8 | 2 ++ 2 files changed, 2 insertions(+), 15 deletions(-) delete mode 100644 .flake8 create mode 100644 .github/linters/.flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 736dd1bd9..000000000 --- a/.flake8 +++ /dev/null @@ -1,15 +0,0 @@ -[flake8] -select: - F402, - F404, - F812, - F823, - F831, - F821, - F822, - E112, - E113, - E901, - E902, - E999, - diff --git a/.github/linters/.flake8 b/.github/linters/.flake8 new file mode 100644 index 000000000..e30e76b99 --- /dev/null +++ b/.github/linters/.flake8 @@ -0,0 +1,2 @@ +[flake8] +select: "F402,F404,F812,F823,F831,F821,F822,E112,E113,E901,E902,E999" From 564742ddb4c86846a27b88490aeff12fd83da4df Mon Sep 17 00:00:00 2001 From: alex-rakowski Date: Thu, 16 Nov 2023 22:50:11 -0800 Subject: [PATCH 11/16] is to == --- py4DSTEM/io/filereaders/read_K2.py | 14 +++++++------- py4DSTEM/preprocess/radialbkgrd.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) 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] From 683d7c39947a7809ecbcb6ba1ab1d34758bb87d0 Mon Sep 17 00:00:00 2001 From: alex-rakowski Date: Thu, 16 Nov 2023 22:50:23 -0800 Subject: [PATCH 12/16] removing type hint --- py4DSTEM/braggvectors/threshold.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/py4DSTEM/braggvectors/threshold.py b/py4DSTEM/braggvectors/threshold.py index 472d57d19..7e19404b1 100644 --- a/py4DSTEM/braggvectors/threshold.py +++ b/py4DSTEM/braggvectors/threshold.py @@ -1,7 +1,6 @@ # Bragg peaks thresholding fns import numpy as np -import numpy.typing as npt from emdfile import tqdmnd, PointListArray @@ -158,7 +157,7 @@ def universal_threshold( # Remove peaks that are too close together if maxNumPeaks is not False: r2 = minPeakSpacing**2 - deletemask: npt.NDArray = np.zeros(pointlist.length, dtype=bool) + deletemask = np.zeros(pointlist.length, dtype=bool) for i in range(pointlist.length): if deletemask[i] == False: # noqa: E712 tooClose = ( From b573c1c1349d7e845ca0199b1737a95496c0679a Mon Sep 17 00:00:00 2001 From: alex-rakowski Date: Mon, 20 Nov 2023 13:52:52 -0800 Subject: [PATCH 13/16] bug fix to __init__ func --- py4DSTEM/process/wholepatternfit/wp_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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." ) From d823606db7d0f1b832e08896e0efceeebc12ba6f Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 20 Nov 2023 14:16:09 -0800 Subject: [PATCH 14/16] Removing the extra factor of 2/pi --- py4DSTEM/process/polar/polar_analysis.py | 1 - 1 file changed, 1 deletion(-) diff --git a/py4DSTEM/process/polar/polar_analysis.py b/py4DSTEM/process/polar/polar_analysis.py index 4f053dcfa..5050a7d46 100644 --- a/py4DSTEM/process/polar/polar_analysis.py +++ b/py4DSTEM/process/polar/polar_analysis.py @@ -411,7 +411,6 @@ 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 From 9a037082a2a188a3f923740b14ea4bed8169c267 Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 20 Nov 2023 14:17:48 -0800 Subject: [PATCH 15/16] Making positivity optional --- py4DSTEM/process/polar/polar_analysis.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/py4DSTEM/process/polar/polar_analysis.py b/py4DSTEM/process/polar/polar_analysis.py index 5050a7d46..67c623ce5 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 @@ -416,7 +419,8 @@ def calculate_pair_dist_function( # 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 From 00fb124e2f5388c24407b6d854c99fe6735cc4c3 Mon Sep 17 00:00:00 2001 From: SE Zeltmann Date: Mon, 20 Nov 2023 18:29:01 -0500 Subject: [PATCH 16/16] format with black --- py4DSTEM/process/polar/polar_analysis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py4DSTEM/process/polar/polar_analysis.py b/py4DSTEM/process/polar/polar_analysis.py index 67c623ce5..7df00a235 100644 --- a/py4DSTEM/process/polar/polar_analysis.py +++ b/py4DSTEM/process/polar/polar_analysis.py @@ -282,7 +282,7 @@ 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: + 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