Skip to content

Commit 039b5e0

Browse files
authored
Merge pull request #590 from smribet/STO_dev
Small plotting changes
2 parents bd1bb4b + c39351f commit 039b5e0

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

py4DSTEM/datacube/virtualimage.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,8 @@ def make_bragg_mask(
681681
origin,
682682
max_q,
683683
return_sum=True,
684+
include_origin=True,
685+
rotation_deg=0,
684686
**kwargs,
685687
):
686688
"""
@@ -696,12 +698,21 @@ def make_bragg_mask(
696698
return_sum (bool): if False, return a 3D array, where each
697699
slice contains a single disk; if False, return a single
698700
2D masks of all disks
701+
include_origin (bool) : if False, removes origin disk
702+
rotation_deg (float) : rotate g1 and g2 vectors
699703
700704
Returns:
701705
(2 or 3D array) the mask
702706
"""
703-
nas = np.asarray
704-
g1, g2, origin = nas(g1), nas(g2), nas(origin)
707+
g1, g2, origin = np.asarray(g1), np.asarray(g2), np.asarray(origin)
708+
709+
rotation_rad = np.deg2rad(rotation_deg)
710+
cost = np.cos(rotation_rad)
711+
sint = np.sin(rotation_rad)
712+
rotation_matrix = np.array(((cost, sint), (-sint, cost)))
713+
714+
g1 = np.dot(g1, rotation_matrix)
715+
g2 = np.dot(g2, rotation_matrix)
705716

706717
# Get N,M, the maximum indices to tile out to
707718
L1 = np.sqrt(np.sum(g1**2))
@@ -722,15 +733,18 @@ def make_bragg_mask(
722733
N = 0
723734
for h in range(-H, H + 1):
724735
for k in range(-K, K + 1):
725-
v = h * g1 + k * g2
726-
if np.sqrt(v.dot(v)) < max_q:
727-
center = origin + v
728-
mask[:, :, N] = self.make_detector(
729-
Qshape,
730-
mode="circle",
731-
geometry=(center, radius),
732-
)
733-
N += 1
736+
if h == 0 and k == 0 and include_origin is False:
737+
continue
738+
else:
739+
v = h * g1 + k * g2
740+
if np.sqrt(v.dot(v)) < max_q:
741+
center = origin + v
742+
mask[:, :, N] = self.make_detector(
743+
Qshape,
744+
mode="circle",
745+
geometry=(center, radius),
746+
)
747+
N += 1
734748

735749
if return_sum:
736750
mask = np.sum(mask, axis=2)

py4DSTEM/process/strain/strain.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
import matplotlib.pyplot as plt
77
from matplotlib.patches import Circle
88
from matplotlib.collections import PatchCollection
9-
from mpl_toolkits.axes_grid1 import make_axes_locatable
109
import numpy as np
1110
from py4DSTEM import PointList, PointListArray, tqdmnd
1211
from py4DSTEM.braggvectors import BraggVectors
1312
from py4DSTEM.data import Data, RealSlice
1413
from py4DSTEM.preprocess.utils import get_maxima_2D
1514
from py4DSTEM.process.strain.latticevectors import (
16-
add_indices_to_braggvectors,
1715
fit_lattice_vectors_all_DPs,
1816
get_reference_g1g2,
1917
get_rotated_strain_map,
@@ -25,8 +23,6 @@
2523
add_bragg_index_labels,
2624
add_pointlabels,
2725
add_vector,
28-
ax_addaxes,
29-
ax_addaxes_QtoR,
3026
)
3127

3228

@@ -583,6 +579,7 @@ def get_strain(
583579
amount, in degrees
584580
returncal : bool
585581
It True, returns rotated map
582+
**kwargs: keywords passed to py4DSTEM show function
586583
"""
587584
# confirm that the calstate hasn't changed
588585
assert (
@@ -681,6 +678,7 @@ def show_strain(
681678
layout="square",
682679
figsize=None,
683680
returnfig=False,
681+
**kwargs,
684682
):
685683
"""
686684
Display a strain map, showing the 4 strain components
@@ -738,11 +736,12 @@ def show_strain(
738736
Scaling for the legend g-vectors relative to the coordinate axes
739737
layout : int
740738
Determines the layout of the grid which the strain components
741-
will be plotted in. Must be in (0,1,2). 0=(2x2), 1=(1x4), 2=(4x1).
739+
will be plotted in. Options are "square", "horizontal", "vertical."
742740
figsize : length 2 tuple of numbers
743741
Size of the figure
744742
returnfig : bool
745743
Toggles returning the figure
744+
**kwargs: keywords passed to py4DSTEM show function
746745
"""
747746

748747
from py4DSTEM.visualize import show_strain
@@ -776,6 +775,7 @@ def show_strain(
776775
layout=layout,
777776
figsize=figsize,
778777
returnfig=True,
778+
**kwargs,
779779
)
780780

781781
# show/return

py4DSTEM/visualize/vis_special.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,7 @@ def show_strain(
926926
layout="square",
927927
figsize=None,
928928
returnfig=False,
929+
**kwargs,
929930
):
930931
"""
931932
Display a strain map, showing the 4 strain components
@@ -988,11 +989,12 @@ def show_strain(
988989
Scaling for the legend g-vectors relative to the coordinate axes
989990
layout : int
990991
Determines the layout of the grid which the strain components
991-
will be plotted in. Must be in (0,1,2). 0=(2x2), 1=(1x4), 2=(4x1).
992+
will be plotted in. Options are "square", "horizontal", "vertical."
992993
figsize : length 2 tuple of numbers
993994
Size of the figure
994995
returnfig : bool
995996
Toggles returning the figure
997+
**kwargs: keywords passed to py4DSTEM show function
996998
"""
997999
# Lookup table for different layouts
9981000
assert layout in ("square", "horizontal", "vertical")
@@ -1099,6 +1101,7 @@ def show_strain(
10991101
cmap=cmap,
11001102
mask_color=mask_color,
11011103
returncax=True,
1104+
**kwargs,
11021105
)
11031106
cax12 = show(
11041107
e_yy,
@@ -1109,6 +1112,7 @@ def show_strain(
11091112
cmap=cmap,
11101113
mask_color=mask_color,
11111114
returncax=True,
1115+
**kwargs,
11121116
)
11131117
cax21 = show(
11141118
e_xy,
@@ -1119,6 +1123,7 @@ def show_strain(
11191123
cmap=cmap,
11201124
mask_color=mask_color,
11211125
returncax=True,
1126+
**kwargs,
11221127
)
11231128
cax22 = show(
11241129
theta,
@@ -1129,6 +1134,7 @@ def show_strain(
11291134
cmap=cmap_theta,
11301135
mask_color=mask_color,
11311136
returncax=True,
1137+
**kwargs,
11321138
)
11331139
ax11.set_title(r"$\epsilon_{xx}$", size=titlesize)
11341140
ax12.set_title(r"$\epsilon_{yy}$", size=titlesize)

0 commit comments

Comments
 (0)