Skip to content

Commit

Permalink
pipeline can now warn on error instead of raising exception
Browse files Browse the repository at this point in the history
Former-commit-id: 35e686d
  • Loading branch information
mkazmier committed Apr 21, 2020
1 parent 3804728 commit b1a595e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 4 additions & 2 deletions examples/radcure_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ def __init__(self,
spacing=(1., 1., 0.),
n_jobs=-1,
missing_strategy="drop",
show_progress=False):
show_progress=False,
warn_on_error=False):
super().__init__(
n_jobs=n_jobs,
missing_strategy=missing_strategy,
show_progress=show_progress)
show_progress=show_progress,
warn_on_error=warn_on_error)

# pipeline configuration
self.input_directory = input_directory
Expand Down
9 changes: 7 additions & 2 deletions imgtools/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Pipeline:
the `process_one_case` method, which defines the processing steps for one
case (i.e. one subject_id from data loaders).
"""
def __init__(self, n_jobs=1, missing_strategy="drop", show_progress=True):
def __init__(self, n_jobs=1, missing_strategy="drop", show_progress=True, warn_on_error=False):
"""Initialize the base class.
Parameters
Expand All @@ -26,6 +26,7 @@ def __init__(self, n_jobs=1, missing_strategy="drop", show_progress=True):
self.n_jobs = n_jobs
self.missing_strategy = missing_strategy.lower()
self.show_progress = show_progress
self.warn_on_error = warn_on_error
if self.missing_strategy not in ["drop", "pass"]:
raise ValueError(f"missing_strategy must be either of 'drop' or 'pass', got {missing_strategy}")

Expand Down Expand Up @@ -85,7 +86,11 @@ def _process_wrapper(self, subject_id):
try:
self.process_one_subject(subject_id)
except Exception as e:
raise RuntimeError(f"{type(e).__name__} while processing subject {subject_id}: " + str(e)) from e
message = f"{type(e).__name__} while processing subject {subject_id}: " + str(e)
if self.warn_on_error:
warnings.warn(message, category=RuntimeWarning)
else:
raise RuntimeError(message) from e

def run(self):
"""Execute the pipeline, possibly in parallel.
Expand Down

0 comments on commit b1a595e

Please sign in to comment.