Skip to content

Commit

Permalink
enh: use custom error BadFFTFilterError for interfere base input
Browse files Browse the repository at this point in the history
  • Loading branch information
Eoghan O'Connell committed Jan 21, 2025
1 parent 24c5588 commit 5f92921
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions qpretrieve/interfere/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa: F401
from .base import BadFFTFilterError
from .if_oah import OffAxisHologram
from .if_qlsi import QLSInterferogram
10 changes: 7 additions & 3 deletions qpretrieve/interfere/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
from ..data_input import check_data_input_format, revert_to_data_input_format


class BadFFTFilterError(ValueError):
pass


class BaseInterferogram(ABC):
default_pipeline_kws = {
"filter_name": "disk",
Expand Down Expand Up @@ -57,18 +61,18 @@ def __init__(self, data, fft_interface: str | FFTFilter = "auto",
"""
if fft_interface is None:
raise ValueError(
raise BadFFTFilterError(
"`fft_interface` is set to None. If you want qpretrieve to "
"find the best FFT interface, set it to 'auto'. "
"If you trying to use `FFTFilterPyFFTW`, "
"If you are trying to use `FFTFilterPyFFTW`, "
"you must first install the pyfftw package.")
if fft_interface == 'auto':
self.ff_iface = get_best_interface()
else:
if fft_interface in get_available_interfaces():
self.ff_iface = fft_interface
else:
raise ValueError(
raise BadFFTFilterError(
f"User-chosen FFT Interface '{fft_interface}' is not "
f"available. The available interfaces are: "
f"{get_available_interfaces()}.\n"
Expand Down
8 changes: 7 additions & 1 deletion tests/test_fourier_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,16 @@ def test_scale_to_filter_oah():


def test_bad_fft_interface_input():
"""Fails because inputting PyFFTW without installing defaults to None"""
data = np.load(data_path / "hologram_cell.npz")
image = data["data"]

with pytest.raises(ValueError):
with pytest.raises(
interfere.BadFFTFilterError,
match="`fft_interface` is set to None. If you want qpretrieve to "
"find the best FFT interface, set it to 'auto'. "
"If you are trying to use `FFTFilterPyFFTW`, "
"you must first install the pyfftw package."):
interfere.OffAxisHologram(image, fft_interface=None)


Expand Down
7 changes: 5 additions & 2 deletions tests/test_interfere_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ def test_interfere_base_choose_interface():

def test_interfere_base_bad_interface():
edata = np.load(data_path / "hologram_cell.npz")
bad_name = "MyReallyCoolFFTInterface"

with pytest.raises(ValueError):
with pytest.raises(
qpretrieve.interfere.BadFFTFilterError,
match=f"User-chosen FFT Interface '{bad_name}' is not available."):
_ = qpretrieve.OffAxisHologram(
data=edata["data"],
fft_interface="MyReallyCoolFFTInterface")
fft_interface=bad_name)


def test_interfere_base_orig_data_fmt():
Expand Down

0 comments on commit 5f92921

Please sign in to comment.