Skip to content

Commit

Permalink
gaussian filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
smribet committed Dec 6, 2024
1 parent cb79f0e commit 8989b29
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions py4DSTEM/tomography/tomography.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ def reconstruct(
progress_bar: bool = True,
zero_edges: bool = True,
baseline_thresh: float = 0.9,
diffraction_gaussian_filter: float = 0,
):
"""
Main loop for reconstruct
Expand All @@ -312,6 +313,8 @@ def reconstruct(
If True, zero edges along y and z
baseline_thresh: float
If not None, data is cropped below threshold. Value is percentile of object.
diffraction_gaussian_filter: float
Gaussian filter sigma for diffraction space (in pixels)
"""
device = self._device

Expand Down Expand Up @@ -365,6 +368,7 @@ def reconstruct(
self._constraints(
zero_edges=zero_edges,
baseline_thresh=baseline_thresh,
diffraction_gaussian_filter=diffraction_gaussian_filter,
)

self.error_iterations.append(error_iteration)
Expand Down Expand Up @@ -448,10 +452,6 @@ def _prepare_datacube(
)
)

from pdb import set_trace

set_trace()

if self._force_q_to_r_rotation_deg is not None:
for a0 in range(datacube.shape[0]):
for a1 in range(datacube.shape[1]):
Expand Down Expand Up @@ -803,17 +803,6 @@ def _make_diffraction_masks(self, q_max_inv_A):
ind_diffraction_rotate_transpose = (
ind_diffraction_rotate_transpose.swapaxes(-1, -2)
)
# if self._force_q_to_r_rotation_deg is not None:
# ind_diffraction_rotate_transpose = np.clip(
# rotate(
# ind_diffraction_rotate_transpose,
# -self._force_q_to_r_rotation_deg, # negative makes this rotation consistant with phase contrast module rotation
# reshape=False,
# order=0,
# ),
# 0,
# np.max(ind_diffraction),
# )

self._ind_diffraction = ind_diffraction
self._ind_diffraction_ravel = ind_diffraction.ravel()
Expand Down Expand Up @@ -1408,7 +1397,12 @@ def _back(

self._object[x_index, yy, zz] += copy_to_device(update_r_summed, storage)

def _constraints(self, zero_edges: bool, baseline_thresh: float):
def _constraints(
self,
zero_edges: bool,
baseline_thresh: float,
diffraction_gaussian_filter: float,
):
"""
Constrains for object
TODO: add constrains and break into multiple functions possibly
Expand All @@ -1419,6 +1413,8 @@ def _constraints(self, zero_edges: bool, baseline_thresh: float):
If True, zero edges along y and z
baseline_thresh: float
If not None, data is cropped below threshold. Value is percentile of object.
diffraction_gaussian_filter: float
Gaussian filter sigma for diffraction space (in pixels)
"""
if zero_edges:
xp = self._xp_storage
Expand All @@ -1441,6 +1437,19 @@ def _constraints(self, zero_edges: bool, baseline_thresh: float):
xp = self._xp_storage
self._object = xp.clip(self._object - vmin, 0, np.inf)

if diffraction_gaussian_filter > 0:
if self._storage == "cpu":
from scipy.ndimage import gaussian_filter
else:
from cp.scipy.ndimage import gaussian_filter

s = self._object.shape

obj_6D = self.object_6D
obj_6D = gaussian_filter(obj_6D, diffraction_gaussian_filter, axes = (-1,-2,-3))

self._object = obj_6D.reshape(s)

def set_storage(self, storage):
"""
Sets storage device.
Expand Down

0 comments on commit 8989b29

Please sign in to comment.