Skip to content

Commit

Permalink
Merge f800053 into accb829
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelwood100 committed Jul 29, 2020
2 parents accb829 + f800053 commit f2a8b78
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 3 additions & 3 deletions diffsims/generators/diffraction_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def calculate_profile_data(
# Use Miller-Bravais indices for hexagonal lattices.
hkl = (hkl[0], hkl[1], -hkl[0] - hkl[1], hkl[2])

peaks[g_hkl] = [i_hkl, [tuple(hkl)], d_hkl]
peaks[tuple(hkl)] = [i_hkl, g_hkl, d_hkl]

# Scale intensities so that the max intensity is 100.
max_intensity = max([v[0] for v in peaks.values()])
Expand All @@ -280,9 +280,9 @@ def calculate_profile_data(
d_hkls = []
for k in sorted(peaks.keys()):
v = peaks[k]
fam = get_unique_families(v[1])
fam = get_unique_families([k])
if v[0] / max_intensity * 100 > minimum_intensity:
x.append(k)
x.append(v[1])
y.append(v[0])
hkls.append(fam)
d_hkls.append(v[2])
Expand Down
16 changes: 11 additions & 5 deletions diffsims/sims/diffraction_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import numpy as np
from scipy import ndimage as ndi

from diffsims.utils.sim_utils import get_unique_families


class DiffractionSimulation:
"""Holds the result of a kinematic diffraction pattern simulation.
Expand Down Expand Up @@ -148,16 +150,17 @@ def get_diffraction_pattern(self, size=512, sigma=10):
the order of 0.5nm and a the default size and sigma are used.
"""
side_length = np.min(np.multiply((size / 2), self.calibration))
mask_for_sides = np.all((np.abs(self.coordinates[:, 0:2]) < side_length), axis=1)

mask_for_sides = np.all(
(np.abs(self.coordinates[:, 0:2]) < side_length), axis=1
)

spot_coords = np.add(
self.calibrated_coordinates[mask_for_sides], size / 2
).astype(int)
spot_intens = self.intensities[mask_for_sides]
pattern = np.zeros([size, size])
#checks that we have some spots
if spot_intens.shape[0]==0:
# checks that we have some spots
if spot_intens.shape[0] == 0:
return pattern
else:
pattern[spot_coords[:, 0], spot_coords[:, 1]] = spot_intens
Expand Down Expand Up @@ -200,10 +203,13 @@ def get_plot(self, g_max, annotate_peaks=True, with_labels=True, fontsize=12):
fontsize : integer
Fontsize for peak labels.
"""

label_hkl = get_unique_families(self.hkls.keys())

ax = plt.gca()
for g, i, hkls in zip(self.magnitudes, self.intensities, self.hkls):
if g <= g_max:
label = ", ".join([str(hkl) for hkl in hkls.keys()])
label = ", ".join([str(hkl) for hkl in label_hkl.keys()])
ax.plot([g, g], [0, i], color="k", linewidth=3, label=label)
if annotate_peaks:
ax.annotate(label, xy=[g, i], xytext=[g, i], fontsize=fontsize)
Expand Down

0 comments on commit f2a8b78

Please sign in to comment.