-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Eoghan O'Connell
committed
Aug 26, 2024
1 parent
4446d0d
commit f09a64f
Showing
10 changed files
with
146 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Fourier Transform options available | ||
This example visualizes the different backends and packages available to the | ||
user for performing Fourier transforms. | ||
""" | ||
import matplotlib.pylab as plt | ||
import numpy as np | ||
import qpretrieve | ||
from skimage.restoration import unwrap_phase | ||
|
||
# load the experimental data | ||
edata = np.load("./data/hologram_cell.npz") | ||
|
||
# get the available fft interfaces | ||
interfaces_available = qpretrieve.fourier.get_available_interfaces() | ||
|
||
prange = (-1, 5) | ||
frange = (0, 12) | ||
|
||
results = {} | ||
|
||
for fft_interface in interfaces_available: | ||
holo = qpretrieve.OffAxisHologram(data=edata["data"], | ||
fft_interface=fft_interface) | ||
holo.run_pipeline(filter_name="disk", filter_size=1/2) | ||
bg = qpretrieve.OffAxisHologram(data=edata["bg_data"]) | ||
bg.process_like(holo) | ||
phase = unwrap_phase(holo.phase - bg.phase) | ||
mask = np.log(1 + np.abs(holo.fft_filtered)) | ||
results[fft_interface.__name__] = mask, phase | ||
|
||
num_filters = len(results) | ||
|
||
# plot the properties of `qpi` | ||
fig = plt.figure(figsize=(8, 22)) | ||
|
||
for row, name in enumerate(results): | ||
ax1 = plt.subplot(num_filters, 2, 2*row+1) | ||
ax1.set_title(name, loc="left") | ||
ax1.imshow(results[name][0], vmin=frange[0], vmax=frange[1]) | ||
|
||
ax2 = plt.subplot(num_filters, 2, 2*row+2) | ||
map2 = ax2.imshow(results[name][1], cmap="coolwarm", | ||
vmin=prange[0], vmax=prange[1]) | ||
plt.colorbar(map2, ax=ax2, fraction=.046, pad=0.02, label="phase [rad]") | ||
|
||
ax1.axis("off") | ||
ax2.axis("off") | ||
|
||
plt.tight_layout() | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
matplotlib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import scipy as sp | ||
|
||
|
||
from .base import FFTFilter | ||
|
||
|
||
class FFTFilterScipy(FFTFilter): | ||
"""Wraps the scipy Fourier transform | ||
""" | ||
# always available, because scipy is a dependency | ||
is_available = True | ||
|
||
def _init_fft(self, data): | ||
"""Perform initial Fourier transform of the input data | ||
Parameters | ||
---------- | ||
data: 2d real-valued np.ndarray | ||
Input field to be refocused | ||
Returns | ||
------- | ||
fft_fdata: 2d complex-valued ndarray | ||
Fourier transform `data` | ||
""" | ||
return sp.fft.fft2(data) | ||
|
||
def _ifft(self, data): | ||
"""Perform inverse Fourier transform""" | ||
return sp.fft.ifft2(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import numpy as np | ||
import scipy as sp | ||
|
||
from qpretrieve import fourier | ||
|
||
|
||
def test_fft_correct(): | ||
image = np.arange(100).reshape(10, 10) | ||
ff = fourier.FFTFilterScipy(image, subtract_mean=False, padding=False) | ||
assert np.allclose( | ||
sp.fft.ifft2(np.fft.ifftshift(ff.fft_origin)).real, | ||
image, | ||
rtol=0, | ||
atol=1e-8 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import numpy as np | ||
|
||
import qpretrieve | ||
|
||
|
||
def test_interfere_base_best_interface(): | ||
edata = np.load("./data/hologram_cell.npz") | ||
|
||
holo = qpretrieve.OffAxisHologram(data=edata["data"]) | ||
assert holo.ff_iface.is_available | ||
assert issubclass(holo.ff_iface, qpretrieve.fourier.base.FFTFilter) | ||
assert issubclass(holo.ff_iface, qpretrieve.fourier.ff_numpy.FFTFilterNumpy) |