From b57b2396ef68d3a1340dc5490e97693e3626c188 Mon Sep 17 00:00:00 2001 From: Stephanie Ribet Date: Thu, 30 Nov 2023 18:22:53 -0500 Subject: [PATCH 1/7] minor plotting changes --- py4DSTEM/datacube/virtualimage.py | 23 ++++++++++++++--------- py4DSTEM/process/strain/strain.py | 2 ++ py4DSTEM/visualize/vis_special.py | 5 +++++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/py4DSTEM/datacube/virtualimage.py b/py4DSTEM/datacube/virtualimage.py index 87aeae8b1..b026bfd62 100644 --- a/py4DSTEM/datacube/virtualimage.py +++ b/py4DSTEM/datacube/virtualimage.py @@ -681,6 +681,7 @@ def make_bragg_mask( origin, max_q, return_sum=True, + include_origin=True, **kwargs, ): """ @@ -696,6 +697,7 @@ def make_bragg_mask( return_sum (bool): if False, return a 3D array, where each slice contains a single disk; if False, return a single 2D masks of all disks + include_origin (bool) : if False, removes origin disk Returns: (2 or 3D array) the mask @@ -722,15 +724,18 @@ def make_bragg_mask( N = 0 for h in range(-H, H + 1): for k in range(-K, K + 1): - v = h * g1 + k * g2 - if np.sqrt(v.dot(v)) < max_q: - center = origin + v - mask[:, :, N] = self.make_detector( - Qshape, - mode="circle", - geometry=(center, radius), - ) - N += 1 + if h == 0 and k == 0 and include_origin is False: + continue + else: + v = h * g1 + k * g2 + if np.sqrt(v.dot(v)) < max_q: + center = origin + v + mask[:, :, N] = self.make_detector( + Qshape, + mode="circle", + geometry=(center, radius), + ) + N += 1 if return_sum: mask = np.sum(mask, axis=2) diff --git a/py4DSTEM/process/strain/strain.py b/py4DSTEM/process/strain/strain.py index 621fc820e..ab8169378 100644 --- a/py4DSTEM/process/strain/strain.py +++ b/py4DSTEM/process/strain/strain.py @@ -681,6 +681,7 @@ def show_strain( layout="square", figsize=None, returnfig=False, + **kwargs, ): """ Display a strain map, showing the 4 strain components @@ -776,6 +777,7 @@ def show_strain( layout=layout, figsize=figsize, returnfig=True, + **kwargs, ) # show/return diff --git a/py4DSTEM/visualize/vis_special.py b/py4DSTEM/visualize/vis_special.py index 125a2ce67..35d7a27cf 100644 --- a/py4DSTEM/visualize/vis_special.py +++ b/py4DSTEM/visualize/vis_special.py @@ -926,6 +926,7 @@ def show_strain( layout="square", figsize=None, returnfig=False, + **kwargs, ): """ Display a strain map, showing the 4 strain components @@ -1099,6 +1100,7 @@ def show_strain( cmap=cmap, mask_color=mask_color, returncax=True, + **kwargs, ) cax12 = show( e_yy, @@ -1109,6 +1111,7 @@ def show_strain( cmap=cmap, mask_color=mask_color, returncax=True, + **kwargs, ) cax21 = show( e_xy, @@ -1119,6 +1122,7 @@ def show_strain( cmap=cmap, mask_color=mask_color, returncax=True, + **kwargs, ) cax22 = show( theta, @@ -1129,6 +1133,7 @@ def show_strain( cmap=cmap_theta, mask_color=mask_color, returncax=True, + **kwargs, ) ax11.set_title(r"$\epsilon_{xx}$", size=titlesize) ax12.set_title(r"$\epsilon_{yy}$", size=titlesize) From 09a1d2894a11c921e723f76cf97c2dd43b5ec2ed Mon Sep 17 00:00:00 2001 From: Stephanie Ribet Date: Thu, 30 Nov 2023 18:27:09 -0500 Subject: [PATCH 2/7] removing extra imports --- py4DSTEM/process/strain/strain.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/py4DSTEM/process/strain/strain.py b/py4DSTEM/process/strain/strain.py index ab8169378..497fbd49b 100644 --- a/py4DSTEM/process/strain/strain.py +++ b/py4DSTEM/process/strain/strain.py @@ -6,14 +6,12 @@ import matplotlib.pyplot as plt from matplotlib.patches import Circle from matplotlib.collections import PatchCollection -from mpl_toolkits.axes_grid1 import make_axes_locatable import numpy as np from py4DSTEM import PointList, PointListArray, tqdmnd from py4DSTEM.braggvectors import BraggVectors from py4DSTEM.data import Data, RealSlice from py4DSTEM.preprocess.utils import get_maxima_2D from py4DSTEM.process.strain.latticevectors import ( - add_indices_to_braggvectors, fit_lattice_vectors_all_DPs, get_reference_g1g2, get_rotated_strain_map, @@ -25,8 +23,6 @@ add_bragg_index_labels, add_pointlabels, add_vector, - ax_addaxes, - ax_addaxes_QtoR, ) From d669df366d86bf47a882d7b666e136fb470b6ea1 Mon Sep 17 00:00:00 2001 From: Stephanie Ribet Date: Fri, 1 Dec 2023 15:56:38 -0800 Subject: [PATCH 3/7] rotation option --- py4DSTEM/datacube/virtualimage.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/py4DSTEM/datacube/virtualimage.py b/py4DSTEM/datacube/virtualimage.py index b026bfd62..c63911d2c 100644 --- a/py4DSTEM/datacube/virtualimage.py +++ b/py4DSTEM/datacube/virtualimage.py @@ -682,6 +682,7 @@ def make_bragg_mask( max_q, return_sum=True, include_origin=True, + rotation_deg=0, **kwargs, ): """ @@ -698,6 +699,7 @@ def make_bragg_mask( slice contains a single disk; if False, return a single 2D masks of all disks include_origin (bool) : if False, removes origin disk + rotation_deg (float) : rotate g1 and g2 vectors Returns: (2 or 3D array) the mask @@ -705,6 +707,14 @@ def make_bragg_mask( nas = np.asarray g1, g2, origin = nas(g1), nas(g2), nas(origin) + rotation_rad = np.deg2rad(rotation_deg) + cost = np.cos(rotation_rad) + sint = np.sin(rotation_rad) + rotation_matrix = np.array(((cost, sint), (-sint, cost))) + + g1 = np.dot(g1, rotation_matrix) + g2 = np.dot(g2, rotation_matrix) + # Get N,M, the maximum indices to tile out to L1 = np.sqrt(np.sum(g1**2)) H = int(max_q / L1) + 1 From 0c7e7956a805738c64ededec9aeda238ae18d4e4 Mon Sep 17 00:00:00 2001 From: Stephanie Ribet Date: Wed, 6 Dec 2023 11:08:58 -0800 Subject: [PATCH 4/7] reformat --- py4DSTEM/datacube/virtualimage.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/py4DSTEM/datacube/virtualimage.py b/py4DSTEM/datacube/virtualimage.py index c63911d2c..627223d23 100644 --- a/py4DSTEM/datacube/virtualimage.py +++ b/py4DSTEM/datacube/virtualimage.py @@ -704,8 +704,7 @@ def make_bragg_mask( Returns: (2 or 3D array) the mask """ - nas = np.asarray - g1, g2, origin = nas(g1), nas(g2), nas(origin) + g1, g2, origin = np.asarray(g1), np.asarray(g2), np.asarray(origin) rotation_rad = np.deg2rad(rotation_deg) cost = np.cos(rotation_rad) From 9638fe5671c685bb716d4ceee00d28f657c58058 Mon Sep 17 00:00:00 2001 From: Stephanie Ribet Date: Mon, 18 Dec 2023 14:05:22 -0800 Subject: [PATCH 5/7] doc strains for visualize strain --- py4DSTEM/process/strain/strain.py | 2 +- py4DSTEM/visualize/vis_special.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/py4DSTEM/process/strain/strain.py b/py4DSTEM/process/strain/strain.py index 497fbd49b..9646ec390 100644 --- a/py4DSTEM/process/strain/strain.py +++ b/py4DSTEM/process/strain/strain.py @@ -735,7 +735,7 @@ def show_strain( Scaling for the legend g-vectors relative to the coordinate axes layout : int Determines the layout of the grid which the strain components - will be plotted in. Must be in (0,1,2). 0=(2x2), 1=(1x4), 2=(4x1). + will be plotted in. Options are "square", "horizontal", "vertical". figsize : length 2 tuple of numbers Size of the figure returnfig : bool diff --git a/py4DSTEM/visualize/vis_special.py b/py4DSTEM/visualize/vis_special.py index 35d7a27cf..beacdb8f5 100644 --- a/py4DSTEM/visualize/vis_special.py +++ b/py4DSTEM/visualize/vis_special.py @@ -989,7 +989,7 @@ def show_strain( Scaling for the legend g-vectors relative to the coordinate axes layout : int Determines the layout of the grid which the strain components - will be plotted in. Must be in (0,1,2). 0=(2x2), 1=(1x4), 2=(4x1). + will be plotted in. Options are "square", "horizontal", "vertical"/ figsize : length 2 tuple of numbers Size of the figure returnfig : bool From 8969b803f970e291f2df7d889a40f45babdbb7b1 Mon Sep 17 00:00:00 2001 From: Stephanie Ribet Date: Mon, 18 Dec 2023 14:15:18 -0800 Subject: [PATCH 6/7] bugs --- py4DSTEM/process/strain/strain.py | 2 +- py4DSTEM/visualize/vis_special.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/py4DSTEM/process/strain/strain.py b/py4DSTEM/process/strain/strain.py index 9646ec390..8165b6558 100644 --- a/py4DSTEM/process/strain/strain.py +++ b/py4DSTEM/process/strain/strain.py @@ -735,7 +735,7 @@ def show_strain( Scaling for the legend g-vectors relative to the coordinate axes layout : int Determines the layout of the grid which the strain components - will be plotted in. Options are "square", "horizontal", "vertical". + will be plotted in. Options are "square", "horizontal", "vertical." figsize : length 2 tuple of numbers Size of the figure returnfig : bool diff --git a/py4DSTEM/visualize/vis_special.py b/py4DSTEM/visualize/vis_special.py index beacdb8f5..78bf5a124 100644 --- a/py4DSTEM/visualize/vis_special.py +++ b/py4DSTEM/visualize/vis_special.py @@ -989,7 +989,7 @@ def show_strain( Scaling for the legend g-vectors relative to the coordinate axes layout : int Determines the layout of the grid which the strain components - will be plotted in. Options are "square", "horizontal", "vertical"/ + will be plotted in. Options are "square", "horizontal", "vertical." figsize : length 2 tuple of numbers Size of the figure returnfig : bool From 0c78c5d89afc0a50e617fa3b85cc478539e58879 Mon Sep 17 00:00:00 2001 From: Stephanie Ribet Date: Wed, 20 Dec 2023 08:05:02 -0800 Subject: [PATCH 7/7] doc string update --- py4DSTEM/process/strain/strain.py | 2 ++ py4DSTEM/visualize/vis_special.py | 1 + 2 files changed, 3 insertions(+) diff --git a/py4DSTEM/process/strain/strain.py b/py4DSTEM/process/strain/strain.py index 8165b6558..25162180f 100644 --- a/py4DSTEM/process/strain/strain.py +++ b/py4DSTEM/process/strain/strain.py @@ -579,6 +579,7 @@ def get_strain( amount, in degrees returncal : bool It True, returns rotated map + **kwargs: keywords passed to py4DSTEM show function """ # confirm that the calstate hasn't changed assert ( @@ -740,6 +741,7 @@ def show_strain( Size of the figure returnfig : bool Toggles returning the figure + **kwargs: keywords passed to py4DSTEM show function """ from py4DSTEM.visualize import show_strain diff --git a/py4DSTEM/visualize/vis_special.py b/py4DSTEM/visualize/vis_special.py index 78bf5a124..88b7d7815 100644 --- a/py4DSTEM/visualize/vis_special.py +++ b/py4DSTEM/visualize/vis_special.py @@ -994,6 +994,7 @@ def show_strain( Size of the figure returnfig : bool Toggles returning the figure + **kwargs: keywords passed to py4DSTEM show function """ # Lookup table for different layouts assert layout in ("square", "horizontal", "vertical")