Skip to content

Commit

Permalink
switching to non-vectorized datacube resampling
Browse files Browse the repository at this point in the history
  • Loading branch information
gvarnavi committed Mar 6, 2024
1 parent b9ac79d commit 84bbc04
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions py4DSTEM/preprocess/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,10 @@ def resample_data_diffraction(
if resampling_factor.shape == ():
resampling_factor = np.tile(resampling_factor, 2)

output_size = np.round(
resampling_factor * np.array(datacube.shape[-2:])
).astype("int")

else:
if output_size is None:
raise ValueError(
Expand All @@ -630,12 +634,25 @@ def resample_data_diffraction(

resampling_factor = np.array(output_size) / np.array(datacube.shape[-2:])

resampling_factor = np.concatenate(((1, 1), resampling_factor))
datacube.data = zoom(
datacube.data, resampling_factor, order=1, mode="grid-wrap", grid_mode=True
)
output_data = np.zeros(datacube.Rshape + tuple(output_size))
for Rx, Ry in tqdmnd(
datacube.shape[0],
datacube.shape[1],
desc="Resampling 4D datacube",
unit="DP",
unit_scale=True,
):
output_data[Rx, Ry] = zoom(
datacube.data[Rx, Ry].astype(np.float32),
resampling_factor,
order=1,
mode="grid-wrap",
grid_mode=True,
)

datacube.data = output_data
datacube.calibration.set_Q_pixel_size(
datacube.calibration.get_Q_pixel_size() / resampling_factor[2]
datacube.calibration.get_Q_pixel_size() / resampling_factor[0]
)

else:
Expand Down

0 comments on commit 84bbc04

Please sign in to comment.