Skip to content

Commit

Permalink
refactoring the way warn_only is passed qurit#64
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhack47 authored and asim-shrestha committed Jan 8, 2023
1 parent d5fdbeb commit 539b8e7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions rt_utils/rtstruct_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RTStructBuilder:
"""

@staticmethod
def create_new(dicom_series_path: str, warn_only: bool = False) -> RTStruct:
def create_new(dicom_series_path: str) -> RTStruct:
"""
Method to generate a new rt struct from a DICOM series
"""
Expand All @@ -23,15 +23,15 @@ def create_new(dicom_series_path: str, warn_only: bool = False) -> RTStruct:
return RTStruct(series_data, ds, warn_only=warn_only)

@staticmethod
def create_from(dicom_series_path: str, rt_struct_path: str) -> RTStruct:
def create_from(dicom_series_path: str, rt_struct_path: str, warn_only: bool = False) -> RTStruct:
"""
Method to load an existing rt struct, given related DICOM series and existing rt struct
"""

series_data = image_helper.load_sorted_image_series(dicom_series_path)
ds = dcmread(rt_struct_path)
RTStructBuilder.validate_rtstruct(ds)
RTStructBuilder.validate_rtstruct_series_references(ds, series_data)
RTStructBuilder.validate_rtstruct_series_references(ds, series_data, warn_only)

# TODO create new frame of reference? Right now we assume the last frame of reference created is suitable
return RTStruct(series_data, ds)
Expand All @@ -51,7 +51,7 @@ def validate_rtstruct(ds: Dataset):
raise Exception("Please check that the existing RTStruct is valid")

@staticmethod
def validate_rtstruct_series_references(ds: Dataset, series_data: List[Dataset]):
def validate_rtstruct_series_references(ds: Dataset, series_data: List[Dataset], warn_only: bool = False):
"""
Method to validate RTStruct only references dicom images found within the input series_data
"""
Expand All @@ -64,7 +64,7 @@ def validate_rtstruct_series_references(ds: Dataset, series_data: List[Dataset])
for rt_refd_series in rt_refd_study.RTReferencedSeriesSequence:
for contour_image in rt_refd_series.ContourImageSequence:
RTStructBuilder.validate_contour_image_in_series_data(
contour_image, series_data
contour_image, series_data, warn_only
)

@staticmethod
Expand All @@ -79,8 +79,8 @@ def validate_contour_image_in_series_data(
return

# ReferencedSOPInstanceUID is NOT available
msg = f"Loaded RTStruct references image(s) that are not contained in input series data. "
+ f"Problematic image has SOP Instance Id: {contour_image.ReferencedSOPInstanceUID}"
msg = f"Loaded RTStruct references image(s) that are not contained in input series data. " \
f"Problematic image has SOP Instance Id: {contour_image.ReferencedSOPInstanceUID}"
if warning_only:
warnings.warn(msg)
else:
Expand Down

0 comments on commit 539b8e7

Please sign in to comment.