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

28 return filter name in execute iteratively method #29

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions pyradise/process/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,14 +566,14 @@ def add_logger(self, logger: logging.Logger) -> None:
"""
self.logger = logger

def execute_iteratively(self, subject: Subject) -> GeneratorExit(Subject):
def execute_iteratively(self, subject: Subject) -> GeneratorExit(Subject, str):
"""Execute iteratively in the filter pipeline on the provided :class:`~pyradise.data.subject.Subject` instance.

Args:
subject (Subject): The :class:`~pyradise.data.subject.Subject` instance to be processed by the pipeline.

Returns:
Subject: The currently processed Subject iteration.
tuple: (Subject: The currently processed Subject iteration, String: Currently executed filter name)
"""
if len(self.filters) != len(self.params):
raise ValueError(
Expand All @@ -593,7 +593,7 @@ def execute_iteratively(self, subject: Subject) -> GeneratorExit(Subject):
filter_.set_warning_on_non_invertible(False)

subject = filter_.execute(subject, param)
yield subject
yield subject, filter_.__class__.__name__

def execute(self, subject: Subject) -> Subject:
"""Execute the filter pipeline on the provided :class:`~pyradise.data.subject.Subject` instance.
Expand All @@ -604,5 +604,5 @@ def execute(self, subject: Subject) -> Subject:
Returns:
Subject: The processed subject.
"""
*_, subject = self.execute_iteratively(subject) # iterate over the generator and get the last subject
*_, (subject, _) = self.execute_iteratively(subject) # iterate over the generator and get the last subject
return subject
6 changes: 4 additions & 2 deletions tests/unit/process/base/test_filter_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ def test_execute_iteratively_1(img_file_nii):
image = IntensityImage(sitk.ReadImage(img_file_nii), "modality_0")
input_subject = Subject("test_name", [image])
filter_pipeline = FilterPipeline((filter_, filter_), (params_0, params_1), False)
for index, subject in enumerate(filter_pipeline.execute_iteratively(input_subject)):
for index, (subject, filter_name) in enumerate(filter_pipeline.execute_iteratively(input_subject)):
assert index < 2
assert isinstance(subject, Subject)
assert filter_name == "ZScoreNormFilter"


def test_execute_iteratively_2(img_file_nii):
Expand All @@ -143,9 +144,10 @@ def test_execute_iteratively_2(img_file_nii):
filter_pipeline = FilterPipeline((filter_, filter_), (params_0, params_1), True)
logger = logging.getLogger("name1")
filter_pipeline.add_logger(logger)
for index, subject in enumerate(filter_pipeline.execute_iteratively(input_subject)):
for index, (subject, filter_name) in enumerate(filter_pipeline.execute_iteratively(input_subject)):
assert index < 2
assert isinstance(subject, Subject)
assert filter_name == "ZScoreNormFilter"


def test_execute_iteratively_3(img_file_nii):
Expand Down