Skip to content

Commit a0ad562

Browse files
authored
Merge pull request #725 from cophus/diffraction
Diffraction module updates
2 parents e31c9d5 + fd5b180 commit a0ad562

File tree

11 files changed

+1029
-267
lines changed

11 files changed

+1029
-267
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
> :warning: **py4DSTEM version 0.14 update** :warning: Warning: this is a major update and we expect some workflows to break. You can still install previous versions of py4DSTEM [as discussed here](#legacyinstall)
32
43
> :warning: **Phase retrieval refactor version 0.14.9** :warning: Warning: The phase-retrieval modules in py4DSTEM (DPC, parallax, and ptychography) underwent a major refactor in version 0.14.9 and as such older tutorial notebooks will not work as expected. Notably, class names have been pruned to remove the trailing "Reconstruction" (`DPCReconstruction` -> `DPC` etc.), and regularization functions have dropped the `_iter` suffix (and are instead specified as boolean flags). See the [updated tutorials](https://github.com/py4dstem/py4DSTEM_tutorials) for more information.

py4DSTEM/process/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@
1919
except (ImportError, ModuleNotFoundError) as exc:
2020
if not is_package_lite:
2121
raise exc
22+
23+
from py4DSTEM.process.utils import Cluster

py4DSTEM/process/diffraction/crystal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def __init__(
9797
# [a a a 90 90 90]
9898
# [a b c 90 90 90]
9999
# [a b c alpha beta gamma]
100-
cell = np.asarray(cell, dtype="float_")
100+
cell = np.array(cell, dtype="float")
101101
if np.size(cell) == 1:
102102
self.cell = np.hstack([cell, cell, cell, 90, 90, 90])
103103
elif np.size(cell) == 3:
@@ -653,7 +653,7 @@ def calculate_structure_factors(
653653
# Calculate single atom scattering factors
654654
# Note this can be sped up a lot, but we may want to generalize to allow non-1.0 occupancy in the future.
655655
f_all = np.zeros(
656-
(np.size(self.g_vec_leng, 0), self.positions.shape[0]), dtype="float_"
656+
(np.size(self.g_vec_leng, 0), self.positions.shape[0]), dtype="float"
657657
)
658658
for a0 in range(self.positions.shape[0]):
659659
atom_sf = single_atom_scatter([self.numbers[a0]], [1], self.g_vec_leng, "A")

py4DSTEM/process/diffraction/crystal_phase.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def quantify_single_pattern(
102102
plot_correlation_radius=False,
103103
scale_markers_experiment=40,
104104
scale_markers_calculated=200,
105+
max_marker_size=400,
105106
crystal_inds_plot=None,
106107
phase_colors=None,
107108
figsize=(10, 7),
@@ -615,16 +616,22 @@ def quantify_single_pattern(
615616
qy0,
616617
qx0,
617618
# s = scale_markers_experiment * intensity0,
618-
s=scale_markers_experiment
619-
* bragg_peaks.data["intensity"][np.logical_not(keep)],
619+
s=np.minimum(
620+
scale_markers_experiment
621+
* bragg_peaks.data["intensity"][np.logical_not(keep)],
622+
max_marker_size,
623+
),
620624
marker="o",
621625
facecolor=[0.7, 0.7, 0.7],
622626
)
623627
ax.scatter(
624628
qy,
625629
qx,
626630
# s = scale_markers_experiment * intensity,
627-
s=scale_markers_experiment * bragg_peaks.data["intensity"][keep],
631+
s=np.minimum(
632+
scale_markers_experiment * bragg_peaks.data["intensity"][keep],
633+
max_marker_size,
634+
),
628635
marker="o",
629636
facecolor=[0.7, 0.7, 0.7],
630637
)
@@ -799,6 +806,7 @@ def quantify_phase(
799806
strain_max=0.02,
800807
include_false_positives=True,
801808
weight_false_positives=1.0,
809+
weight_unmatched_peaks=1.0,
802810
progress_bar=True,
803811
):
804812
"""
@@ -899,6 +907,7 @@ def quantify_phase(
899907
strain_max=strain_max,
900908
include_false_positives=include_false_positives,
901909
weight_false_positives=weight_false_positives,
910+
weight_unmatched_peaks=weight_unmatched_peaks,
902911
plot_result=False,
903912
verbose=False,
904913
returnfig=False,
@@ -1220,6 +1229,7 @@ def plot_dominant_phase(
12201229
self,
12211230
use_correlation_scores=False,
12221231
reliability_range=(0.0, 1.0),
1232+
normalize_exp_intensity=True,
12231233
sigma=0.0,
12241234
phase_colors=None,
12251235
ticks=True,
@@ -1302,6 +1312,11 @@ def plot_dominant_phase(
13021312
sigma=sigma,
13031313
mode="nearest",
13041314
)
1315+
self.phase_sig = phase_sig
1316+
1317+
# # normalize the signal by the intensity of each experimental pattern
1318+
# if normalize_exp_intensity:
1319+
# phase_sig /= self.int_total[None,:,:]
13051320

13061321
# find highest correlation score for each crystal and match index
13071322
for a0 in range(self.num_crystals):
@@ -1327,6 +1342,11 @@ def plot_dominant_phase(
13271342

13281343
# Estimate the reliability
13291344
phase_rel = phase_corr - phase_corr_2nd
1345+
1346+
# normalize the reliability by the intensity of each experimental pattern
1347+
if normalize_exp_intensity:
1348+
phase_rel /= self.int_total
1349+
13301350
phase_scale = np.clip(
13311351
(phase_rel - reliability_range[0])
13321352
/ (reliability_range[1] - reliability_range[0]),
@@ -1351,6 +1371,8 @@ def plot_dominant_phase(
13511371
sub = phase_map == a0
13521372
for a1 in range(3):
13531373
self.phase_rgb[:, :, a1][sub] = phase_colors[a0, a1] * phase_scale[sub]
1374+
1375+
self.phase_scale = phase_scale
13541376
# normalize
13551377
# self.phase_rgb = np.clip(
13561378
# (self.phase_rgb - rel_range[0]) / (rel_range[1] - rel_range[0]),

0 commit comments

Comments
 (0)