Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test_image_filter test error #6624

Merged
merged 3 commits into from
Jun 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion monai/transforms/utility/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,22 @@ def _check_filter_format(self, filter: str | NdarrayOrTensor | nn.Module, filter
"`class 'torch.nn.modules.module.Module'`, `class 'monai.transforms.Transform'`"
)

def _check_kwargs_are_present(self, filter, **kwargs):
def _check_kwargs_are_present(self, filter: str | NdarrayOrTensor | nn.Module, **kwargs: Any) -> None:
"""
Perform sanity checks on the kwargs if the filter contains the required keys.
If the filter is ``gauss``, kwargs should contain ``sigma``.
If the filter is ``savitzky_golay``, kwargs should contain ``order``.

Args:
filter: A string specifying the filter, a custom filter as ``torch.Tenor`` or ``np.ndarray`` or a ``nn.Module``.
kwargs: additional arguments defining the filter.

Raises:
KeyError if the filter doesn't contain the requirement key.
"""

if not isinstance(filter, str):
return
if filter == "gauss" and "sigma" not in kwargs.keys():
raise KeyError("`filter='gauss', requires the additional keyword argument `sigma`")
if filter == "savitzky_golay" and "order" not in kwargs.keys():
Expand Down