diff --git a/py4DSTEM/datacube/virtualimage.py b/py4DSTEM/datacube/virtualimage.py index 98c71f3d9..d93daea5e 100644 --- a/py4DSTEM/datacube/virtualimage.py +++ b/py4DSTEM/datacube/virtualimage.py @@ -535,7 +535,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/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) diff --git a/py4DSTEM/process/polar/polar_peaks.py b/py4DSTEM/process/polar/polar_peaks.py index 16d0531db..c5f319404 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 @@ -310,12 +313,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( @@ -780,6 +800,7 @@ def model_radial_background( refine_model=True, plot_result=True, figsize=(8, 4), + returnfig=False, ): """ User provided radial background model, of the form: @@ -883,11 +904,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( diff --git a/py4DSTEM/visualize/show.py b/py4DSTEM/visualize/show.py index cf7254bf1..a1500f8bb 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],