Skip to content

Commit

Permalink
diffraction space is looking better but real space is worse
Browse files Browse the repository at this point in the history
  • Loading branch information
smribet committed Aug 31, 2024
1 parent b6181eb commit ad04ac6
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions py4DSTEM/tomography/tomography.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,14 +652,14 @@ def _make_diffraction_masks(self, q_max_inv_A):

self._ind_diffraction = ind_diffraction
self._ind_diffraction_ravel = ind_diffraction.ravel()
self._q_length = np.unique(self._ind_diffraction).shape[0] + 1
self._q_length = np.unique(self._ind_diffraction).shape[0]

# pixels to remove
q_max_px = q_max_inv_A / self._datacube_Q_pixel_size_inv_A

x = np.arange(s[-1]) - ((s[-1] - 1) / 2)
y = np.arange(s[-1]) - ((s[-1] - 1) / 2)
xx, yy = np.meshgrid(x, y)
xx, yy = np.meshgrid(x, y, indexing = "ij")
circular_mask = ((xx) ** 2 + (yy) ** 2) ** 0.5 < q_max_px

self._circular_mask = circular_mask
Expand Down Expand Up @@ -986,8 +986,8 @@ def _forward(
tilt = xp.deg2rad(tilt_deg)

# solve for real space coordinates
line_z = xp.linspace(0, 1, num_points) * (s[2] - 1)
line_y = line_z * xp.tan(tilt)
line_y = xp.linspace(0, 1, num_points) * (s[2] - 1)
line_z = line_y * xp.tan(tilt)
offset = xp.arange(s[1], dtype="int")

yF = xp.floor(line_y).astype("int")
Expand All @@ -997,19 +997,19 @@ def _forward(

ind0 = np.hstack(
(
xp.tile(yF, (s[1], 1)) + offset[:, None],
xp.tile(yF + 1, (s[1], 1)) + offset[:, None],
xp.tile(yF, (s[1], 1)) + offset[:, None],
xp.tile(yF + 1, (s[1], 1)) + offset[:, None],
xp.tile(yF, (s[1], 1)),
xp.tile(yF + 1, (s[1], 1)) ,
xp.tile(yF, (s[1], 1)),
xp.tile(yF + 1, (s[1], 1)),
)
)

ind1 = np.hstack(
(
xp.tile(zF, (s[1], 1)),
xp.tile(zF, (s[1], 1)),
xp.tile(zF + 1, (s[1], 1)),
xp.tile(zF + 1, (s[1], 1)),
xp.tile(zF, (s[1], 1)) + offset[:, None],
xp.tile(zF, (s[1], 1)) + offset[:, None],
xp.tile(zF + 1, (s[1], 1)) + offset[:, None],
xp.tile(zF + 1, (s[1], 1)) + offset[:, None],
)
)

Expand Down Expand Up @@ -1037,23 +1037,23 @@ def _forward(

qx = xp.arange(s[-1])
qy = xp.arange(s[-1])
qxx, qyy = xp.meshgrid(qx, qy)
qxx, qyy = xp.meshgrid(qx, qy, indexing="ij")

ind0_diff = np.hstack(
(
xp.repeat(yF_diff, s[-1]),
xp.repeat(yF_diff + 1, s[-1]),
xp.repeat(yF_diff, s[-1]),
xp.repeat(yF_diff + 1, s[-1]),
xp.tile(yF_diff, s[-1]),
xp.tile(yF_diff + 1, s[-1]),
xp.tile(yF_diff, s[-1]),
xp.tile(yF_diff + 1, s[-1]),
)
)

ind1_diff = np.hstack(
(
xp.repeat(zF_diff, s[-1]),
xp.repeat(zF_diff, s[-1]),
xp.repeat(zF_diff + 1, s[-1]),
xp.repeat(zF_diff + 1, s[-1]),
xp.tile(zF_diff, s[-1]),
xp.tile(zF_diff, s[-1]),
xp.tile(zF_diff + 1, s[-1]),
xp.tile(zF_diff + 1, s[-1]),
)
)

Expand All @@ -1068,8 +1068,8 @@ def _forward(

ind_diff = xp.ravel_multi_index(
(
ind0_diff.ravel(),
xp.tile(qxx.ravel(), 4),
ind0_diff.ravel(),
ind1_diff.ravel(),
),
(s[-1], s[-1], s[-1]),
Expand Down Expand Up @@ -1097,6 +1097,9 @@ def _forward(
minlength=self._q_length * s[1],
).reshape(s[1], self._q_length)[:, self._circular_mask_bincount]

# from pdb import set_trace
# set_trace()

self._ind0 = ind0
self._ind1 = ind1
self._weights_real = weights_real
Expand Down Expand Up @@ -1204,7 +1207,8 @@ def _calculate_update(
)[:, None]
)
diffraction_patterns_resampled = diffraction_patterns_resampled[ind]
update = diffraction_patterns_resampled - object_sliced
update = diffraction_patterns_resampled
# - object_sliced

error = xp.mean(update.ravel() ** 2) / xp.mean(
diffraction_patterns_projected.ravel() ** 2
Expand Down

0 comments on commit ad04ac6

Please sign in to comment.