Skip to content

Commit

Permalink
fix for even arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
smribet committed Sep 12, 2024
1 parent c9a6371 commit 8a9222c
Showing 1 changed file with 46 additions and 19 deletions.
65 changes: 46 additions & 19 deletions py4DSTEM/tomography/tomography.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ def preprocess(
bin_real_space: int
factor for binnning in real space
crop_reciprocal_space: float
if not None, crops reciprocal space on all sides by integer
if not None, crops reciprocal space on all sides by integer.
Can pass an single integer of a 4-tuple
q_max_inv_A: int
maximum q in inverse angstroms
force_q_to_r_rotation_deg:float
Expand Down Expand Up @@ -343,7 +344,8 @@ def _prepare_datacube(
masks_real_space: list of np.ndarray or np.ndarray
mask for real space. can be the same for each datacube of individually specified.
crop_reciprocal_space: float
if not None, crops reciprocal space on all sides by integer
if not None, crops reciprocal space on all sides by integer.
Can pass an single integer of a 4-tuple
q_max_inv_A: int
maximum q in inverse angtroms
"""
Expand Down Expand Up @@ -372,14 +374,25 @@ def _prepare_datacube(
mask_real_space = None

if crop_reciprocal_space is not None:
datacube.crop_Q(
(
crop_reciprocal_space,
-crop_reciprocal_space,
crop_reciprocal_space,
-crop_reciprocal_space,
if np.isscalar(crop_reciprocal_space):
datacube.crop_Q(
(
crop_reciprocal_space,
-crop_reciprocal_space,
crop_reciprocal_space,
-crop_reciprocal_space,
)
)
else:
datacube.crop_Q(
(
crop_reciprocal_space[0],
-crop_reciprocal_space[1],
crop_reciprocal_space[2],
-crop_reciprocal_space,
[3],
)
)
)

# resize diffraction space
if diffraction_intensities_shape is not None:
Expand Down Expand Up @@ -1283,17 +1296,31 @@ def _back(
i[a] = xp.arange(a.size)
i = xp.tile(i, 4) + xp.repeat(xp.arange(4), i.shape[0]) * (i.shape[0])

normalize = xp.ones((xp.repeat(update, 2, axis=1)[:, 1:]).shape) * 2
normalize[:, 0] = 1
if s[-1] % 2 > 0:
normalize = xp.ones((xp.repeat(update, 2, axis=1)[:, 1:]).shape) * 2
normalize[:, 0] = 1

update_reshaped = xp.repeat(
(
(xp.tile(xp.repeat(update, 2, axis=1)[:, 1:] / normalize, (4)))[:, i]
* (self._weights_diff[ind_update])
),
4 * num_points,
axis=0,
) / (num_points)
update_reshaped = xp.repeat(
(
(xp.tile(xp.repeat(update, 2, axis=1)[:, 1:] / normalize, (4)))[
:, i
]
* (self._weights_diff[ind_update])
),
4 * num_points,
axis=0,
) / (num_points)
else:
normalize = xp.ones((xp.repeat(update, 2, axis=1)).shape) * 2

update_reshaped = xp.repeat(
(
(xp.tile(xp.repeat(update, 2, axis=1) / normalize, (4)))[:, i]
* (self._weights_diff[ind_update])
),
4 * num_points,
axis=0,
) / (num_points)

real_index = xp.ravel_multi_index(
(self._ind0.ravel(), self._ind1.ravel()), (s[1], s[2]), mode="clip"
Expand Down

0 comments on commit 8a9222c

Please sign in to comment.