Skip to content

Commit

Permalink
off by one
Browse files Browse the repository at this point in the history
  • Loading branch information
smribet committed Jan 25, 2025
1 parent a02ed87 commit 1ab7c20
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions py4DSTEM/tomography/tomography.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,16 +1000,16 @@ def _solve_for_indicies(
# solve for real space coordinates
y = np.arange(s[1])
z = np.arange(s[2])
yy, zz = np.meshgrid(y, z, indexing="ij")
yy, zz = np.meshgrid(y, z)
sin = np.sin(tilt)
cos = np.cos(tilt)
r = [[cos, sin], [-sin, cos]]
points = np.array((yy.ravel(), zz.ravel())).T
points = points @ r
line_y = points[:, 0]
line_z = points[:, 1]
line_y -= np.mean(line_y) - s[1] / 2
line_z -= np.mean(line_z) - s[2] / 2
line_y -= np.mean(line_y) - (s[1] - 1) / 2
line_z -= np.mean(line_z) - (s[2] - 1) / 2

yF = np.floor(line_y).astype("int")
zF = np.floor(line_z).astype("int")
Expand All @@ -1034,8 +1034,8 @@ def _solve_for_indicies(
# solve for diffraction space coordinates
line_y_diff = np.arange(s[-1]) * np.cos(tilt)
line_z_diff = np.arange(s[-1]) * np.sin(tilt)
line_y_diff -= np.mean(line_y_diff) - s[-1] / 2
line_z_diff -= np.mean(line_z_diff) - s[-1] / 2
line_y_diff -= np.mean(line_y_diff) - (s[-1] - 1) / 2
line_z_diff -= np.mean(line_z_diff) - (s[-1] - 1) / 2

yF_diff = np.floor(line_y_diff).astype("int")
zF_diff = np.floor(line_z_diff).astype("int")
Expand Down Expand Up @@ -1346,7 +1346,7 @@ def _forward(
).reshape((-1, self._q_length))[:, self._circular_mask_bincount]

obj_projected = (obj_q_summed[ind_real] * weights_real[:, :, :, None]).sum(
(0, 1)
(0, 2)
)

return obj_projected
Expand Down Expand Up @@ -1521,17 +1521,17 @@ def _back(
diff_shape = ind_diff.shape[0]

bincount_diff = (
xp.tile(ind_diff, s[2])
+ (xp.repeat(xp.arange(s[2]), diff_shape)) * diff_max
xp.tile(ind_diff, s[1])
+ (xp.repeat(xp.arange(s[1]), diff_shape)) * diff_max
)

update_q_summed = xp.bincount(
bincount_diff,
update_reshaped.ravel(),
minlength=((diff_max) * s[2]),
).reshape((s[2], -1))[:, ind_diff_bincount > 0]
minlength=((diff_max) * s[1]),
).reshape((s[1], -1))[:, ind_diff_bincount > 0]

update_q_summed = xp.tile(update_q_summed, (s[1] * 4, 1)) / (s[1])
update_q_summed = xp.tile(update_q_summed, (s[2] * 4, 1)) / (s[2])

diff_shape_bin = update_q_summed.shape[-1]

Expand Down

0 comments on commit 1ab7c20

Please sign in to comment.