Skip to content

Commit

Permalink
Merge pull request #24 from bmorris3/fix-apodize
Browse files Browse the repository at this point in the history
Fixing apodize bug
  • Loading branch information
Brett M. Morris committed Nov 23, 2016
2 parents e38521d + fd7261d commit dbc0c44
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions shampoo/reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
RANDOM_SEED = 42
TWO_TO_N = [2**i for i in range(13)]


def rebin_image(a, binning_factor):
# Courtesy of J.F. Sebastian: http://stackoverflow.com/a/8090605
if binning_factor == 1:
Expand Down Expand Up @@ -107,6 +108,7 @@ def _load_hologram(hologram_path):
except ImportError:
return np.array(imread(hologram_path), dtype=np.float64)


def _find_peak_centroid(image, gaussian_width=10):
"""
Smooth the image, find centroid of peak in the image.
Expand Down Expand Up @@ -388,13 +390,13 @@ def get_digital_phase_mask(self, psi, plots=False):

return digital_phase_mask

def apodize(self, arr, alpha=0.075):
def apodize(self, array, alpha=0.075):
"""
Force the magnitude of an array to go to zero at the boundaries.
Parameters
----------
arr : `~numpy.ndarray`
array : `~numpy.ndarray`
Array to apodize
alpha : float between zero and one
Alpha parameter for the Tukey window function. For best results,
Expand All @@ -407,12 +409,9 @@ def apodize(self, arr, alpha=0.075):
"""
x, y = self.mgrid
n = len(x[0])
if not self.hologram_apodized:
tukey_window = tukey(n, alpha)
arr *= tukey_window[:, np.newaxis] * tukey_window

self.hologram_apodized = True
return arr
tukey_window = tukey(n, alpha)
apodized_array = array * tukey_window[:, np.newaxis] * tukey_window
return apodized_array

def fourier_trans_of_impulse_resp_func(self, propagation_distance):
"""
Expand Down
4 changes: 2 additions & 2 deletions shampoo/tests/test_hologram.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def test_multiple_reconstructions():
w2 = holo.reconstruct(0.8)
h_apodized2 = holo.hologram.copy()

# check hologram gets modified in place first time
assert not np.all(h_raw == h_apodized1)
# check hologram doesn't get modified in place first time
assert np.all(h_raw == h_apodized1)

# check hologram doesn't get modified again
assert np.all(h_apodized1 == h_apodized2)
Expand Down

0 comments on commit dbc0c44

Please sign in to comment.