From e3f4c9cef6bd3c4d811fbe610a4ccc0d34ad2914 Mon Sep 17 00:00:00 2001 From: cophus Date: Tue, 22 Oct 2024 16:01:52 -0700 Subject: [PATCH 1/6] Minor fix to fig,ax inputs --- py4DSTEM/process/polar/polar_peaks.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/py4DSTEM/process/polar/polar_peaks.py b/py4DSTEM/process/polar/polar_peaks.py index 16d0531db..d64270823 100644 --- a/py4DSTEM/process/polar/polar_peaks.py +++ b/py4DSTEM/process/polar/polar_peaks.py @@ -310,12 +310,29 @@ def find_peaks_single_pattern( ct = np.cos(t) st = np.sin(t) - fig, ax = plt.subplots(figsize=figsize) - cmap = kwargs.pop("cmap", "gray") vmax = kwargs.pop("vmax", 1) vmin = kwargs.pop("vmin", 0) - show(im_plot, figax=(fig, ax), cmap=cmap, vmax=vmax, vmin=vmin, **kwargs) + + if 'figax' in kwargs: + fig,ax = kwargs['figax'] + show( + im_plot, + cmap=cmap, + vmax=vmax, + vmin=vmin, + **kwargs, + ) + else: + fig, ax = plt.subplots(figsize=figsize) + show( + im_plot, + figax=(fig, ax), + cmap=cmap, + vmax=vmax, + vmin=vmin, + **kwargs, + ) # peaks ax.scatter( From b9225043842bd17442e87c1fa4bb247ba1536808 Mon Sep 17 00:00:00 2001 From: cophus Date: Wed, 23 Oct 2024 10:22:51 -0700 Subject: [PATCH 2/6] minor fix --- py4DSTEM/process/diffraction/flowlines.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/py4DSTEM/process/diffraction/flowlines.py b/py4DSTEM/process/diffraction/flowlines.py index 5af64f73e..2fe7ee393 100644 --- a/py4DSTEM/process/diffraction/flowlines.py +++ b/py4DSTEM/process/diffraction/flowlines.py @@ -800,7 +800,7 @@ def make_flowline_rainbow_image( def make_flowline_rainbow_legend( im_size=np.array([256, 256]), sym_rotation_order=2, - theta_offset=0.0, + theta_offset_degrees=0.0, white_background=False, return_image=False, radial_range=np.array([0.45, 0.9]), @@ -813,7 +813,7 @@ def make_flowline_rainbow_legend( Args: im_size (np.array): Size of legend image in pixels. sym_rotation_order (int): rotational symmety for colouring - theta_offset (float): Offset the anglular coloring by this value in radians. + theta_offset_degrees (float): Offset the anglular coloring by this value in radians. white_background (bool): For either color or greyscale output, switch to white background (from black). return_image (bool): Return the image array. radial_range (np.array): Inner and outer radius for the legend ring. @@ -827,9 +827,9 @@ def make_flowline_rainbow_legend( # Coordinates x = np.linspace(-1, 1, im_size[0]) y = np.linspace(-1, 1, im_size[1]) - ya, xa = np.meshgrid(-y, x) + ya, xa = np.meshgrid(y, x) ra = np.sqrt(xa**2 + ya**2) - ta = np.arctan2(ya, xa) + theta_offset + ta = np.arctan2(ya, xa) + np.deg2rad(theta_offset_degrees) ta_sym = ta * sym_rotation_order # mask @@ -837,7 +837,7 @@ def make_flowline_rainbow_legend( # rgb image z = mask * np.exp(1j * ta_sym) - hue_start = -90 + hue_start = 0 amp = np.abs(z) vmin = np.min(amp) vmax = np.max(amp) From c2eeb59d88a12435c66d6c849ea77906c3593664 Mon Sep 17 00:00:00 2001 From: cophus Date: Wed, 23 Oct 2024 11:09:24 -0700 Subject: [PATCH 3/6] removing assers --- py4DSTEM/datacube/virtualimage.py | 2 +- py4DSTEM/visualize/show.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/py4DSTEM/datacube/virtualimage.py b/py4DSTEM/datacube/virtualimage.py index d4fe15241..1c8646352 100644 --- a/py4DSTEM/datacube/virtualimage.py +++ b/py4DSTEM/datacube/virtualimage.py @@ -536,7 +536,7 @@ def get_calibrated_detector_geometry( ), "No calibration found - set a calibration or set `centered` and `calibrated` to False" return g else: - assert isinstance(calibration, Calibration) + # assert isinstance(calibration, Calibration) cal = calibration # Get calibration metadata diff --git a/py4DSTEM/visualize/show.py b/py4DSTEM/visualize/show.py index dcb1cf285..0ca112f44 100644 --- a/py4DSTEM/visualize/show.py +++ b/py4DSTEM/visualize/show.py @@ -426,7 +426,7 @@ def show( ): cal = ar.calibration er = ".calibration attribute must be a Calibration instance" - assert isinstance(cal, Calibration), er + # assert isinstance(cal, Calibration), er if isinstance(ar, DiffractionSlice): scalebar = { "Nx": ar.data.shape[0], From b291ecb2ceb1e23227e1e64eeee5710d03a088e4 Mon Sep 17 00:00:00 2001 From: cophus Date: Wed, 23 Oct 2024 11:11:52 -0700 Subject: [PATCH 4/6] adding returnfig --- py4DSTEM/process/polar/polar_peaks.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/py4DSTEM/process/polar/polar_peaks.py b/py4DSTEM/process/polar/polar_peaks.py index d64270823..7df764ecc 100644 --- a/py4DSTEM/process/polar/polar_peaks.py +++ b/py4DSTEM/process/polar/polar_peaks.py @@ -797,6 +797,7 @@ def model_radial_background( refine_model=True, plot_result=True, figsize=(8, 4), + returnfig=False, ): """ User provided radial background model, of the form: @@ -900,11 +901,20 @@ def background_model(q, *coefs): # plotting if plot_result: - self.plot_radial_background( - q_pixel_units=False, - plot_background_model=True, - figsize=figsize, - ) + if returnfig: + fig,ax = self.plot_radial_background( + q_pixel_units=False, + plot_background_model=True, + figsize=figsize, + returnfig=returnfig, + ) + return fig, ax + else: + self.plot_radial_background( + q_pixel_units=False, + plot_background_model=True, + figsize=figsize, + ) def refine_peaks( From 8c26c3eb351bcad3f16d084fb69f0c9f4088579d Mon Sep 17 00:00:00 2001 From: Colin Ophus Date: Fri, 31 Jul 2026 20:04:59 -0500 Subject: [PATCH 5/6] Fix polar peak prominences under numpy 2 scipy's peak_prominences returns length-1 arrays for a single peak; numpy >= 2.0 no longer allows assigning a size-1 array to a scalar element, so find_peaks_single_pattern raised ValueError. Index into the prominence arrays explicitly (works identically on numpy 1.x). With this fix the full tutorial API surface (disk detection, calibration, polar peaks/flowlines, ACOM, CrystalPhase, StrainMap, save/read) runs under numpy 2.5 with no downgrade. Co-Authored-By: Claude Fable 5 --- py4DSTEM/process/polar/polar_peaks.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/py4DSTEM/process/polar/polar_peaks.py b/py4DSTEM/process/polar/polar_peaks.py index 7df764ecc..cc882c487 100644 --- a/py4DSTEM/process/polar/polar_peaks.py +++ b/py4DSTEM/process/polar/polar_peaks.py @@ -208,9 +208,12 @@ def find_peaks_single_pattern( ) # output - peaks_prom[a0, 0] = p_annular[0] + # scipy's peak_prominences returns length-1 arrays here; index into + # them explicitly, since numpy >= 2.0 no longer allows assigning a + # size-1 array to a scalar element. + peaks_prom[a0, 0] = p_annular[0][0] peaks_prom[a0, 1] = sigma_annular[0] - peaks_prom[a0, 2] = p_radial[0] + peaks_prom[a0, 2] = p_radial[0][0] peaks_prom[a0, 3] = sigma_radial[0] # if needed, remove peaks using prominance criteria From e0d49b05c4be76855368848b040e240acb718cb3 Mon Sep 17 00:00:00 2001 From: cophus Date: Fri, 31 Jul 2026 20:18:04 -0500 Subject: [PATCH 6/6] black format --- py4DSTEM/process/polar/polar_peaks.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/py4DSTEM/process/polar/polar_peaks.py b/py4DSTEM/process/polar/polar_peaks.py index cc882c487..c5f319404 100644 --- a/py4DSTEM/process/polar/polar_peaks.py +++ b/py4DSTEM/process/polar/polar_peaks.py @@ -317,23 +317,23 @@ def find_peaks_single_pattern( vmax = kwargs.pop("vmax", 1) vmin = kwargs.pop("vmin", 0) - if 'figax' in kwargs: - fig,ax = kwargs['figax'] + if "figax" in kwargs: + fig, ax = kwargs["figax"] show( - im_plot, - cmap=cmap, - vmax=vmax, - vmin=vmin, + im_plot, + cmap=cmap, + vmax=vmax, + vmin=vmin, **kwargs, ) else: fig, ax = plt.subplots(figsize=figsize) show( - im_plot, - figax=(fig, ax), - cmap=cmap, - vmax=vmax, - vmin=vmin, + im_plot, + figax=(fig, ax), + cmap=cmap, + vmax=vmax, + vmin=vmin, **kwargs, ) @@ -905,7 +905,7 @@ def background_model(q, *coefs): # plotting if plot_result: if returnfig: - fig,ax = self.plot_radial_background( + fig, ax = self.plot_radial_background( q_pixel_units=False, plot_background_model=True, figsize=figsize, @@ -917,7 +917,7 @@ def background_model(q, *coefs): q_pixel_units=False, plot_background_model=True, figsize=figsize, - ) + ) def refine_peaks(