From d9d80695a7e28038389aa0caace5b95295aab479 Mon Sep 17 00:00:00 2001 From: Katy Scott Date: Wed, 25 Sep 2024 15:28:50 -0400 Subject: [PATCH 1/2] feat(feature_extraction): add logging for error raised when cropping CT and segmentation --- src/readii/feature_extraction.py | 59 +++++++++++++++++--------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/src/readii/feature_extraction.py b/src/readii/feature_extraction.py index bbc6bc9..dfa3aa0 100644 --- a/src/readii/feature_extraction.py +++ b/src/readii/feature_extraction.py @@ -90,35 +90,38 @@ def singleRadiomicFeatureExtraction( if correctedROIImage is not None: alignedROIImage = correctedROIImage + try: + if negativeControl != None: + logger.info(f"Generating {negativeControl} negative control for CT.") + # Split negative control type into negative control and region of interest + try: + if "non_roi" in negativeControl: + negativeControlType = negativeControl.rsplit("_", 2)[0] + negativeControlRegion = "non_roi" + else: + negativeControlComponents = negativeControl.rsplit("_", 1) + negativeControlType = negativeControlComponents[0] + negativeControlRegion = negativeControlComponents[1] + logger.debug(f"Negative control region: {negativeControlRegion}") + logger.debug(f"Negative control type: {negativeControlType}") + # Make negative control version of ctImage + ctImage_nc: sitk.Image | np.ndarray = applyNegativeControl( + baseImage=ctImage, + negativeControlType=negativeControlType, + negativeControlRegion=negativeControlRegion, + roiMask=alignedROIImage, + randomSeed=randomSeed + ) + except Exception as e: + logger.error(f"Error generating {negativeControl} negative control for CT: {e}") - if negativeControl != None: - logger.info(f"Generating {negativeControl} negative control for CT.") - # Split negative control type into negative control and region of interest - try: - if "non_roi" in negativeControl: - negativeControlType = negativeControl.rsplit("_", 2)[0] - negativeControlRegion = "non_roi" - else: - negativeControlComponents = negativeControl.rsplit("_", 1) - negativeControlType = negativeControlComponents[0] - negativeControlRegion = negativeControlComponents[1] - logger.debug(f"Negative control region: {negativeControlRegion}") - logger.debug(f"Negative control type: {negativeControlType}") - # Make negative control version of ctImage - ctImage_nc: sitk.Image | np.ndarray = applyNegativeControl( - baseImage=ctImage, - negativeControlType=negativeControlType, - negativeControlRegion=negativeControlRegion, - roiMask=alignedROIImage, - randomSeed=randomSeed - ) - except Exception as e: - logger.error(f"Error generating {negativeControl} negative control for CT: {e}") - - croppedCT, croppedROI = imageoperations.cropToTumorMask(ctImage_nc, alignedROIImage, segBoundingBox) - else: - # Crop the image and mask to a bounding box around the mask to reduce volume size to process - croppedCT, croppedROI = imageoperations.cropToTumorMask(ctImage, alignedROIImage, segBoundingBox) + croppedCT, croppedROI = imageoperations.cropToTumorMask(ctImage_nc, alignedROIImage, segBoundingBox) + else: + # Crop the image and mask to a bounding box around the mask to reduce volume size to process + croppedCT, croppedROI = imageoperations.cropToTumorMask(ctImage, alignedROIImage, segBoundingBox) + except Exception as e: + logger.error(f"Error cropping image and mask: {e}") + raise # Load PyRadiomics feature extraction parameters to use # Initialize feature extractor with parameters From e1a98884308e16055db04846932ce133c34779e0 Mon Sep 17 00:00:00 2001 From: Katy Scott Date: Wed, 25 Sep 2024 15:29:20 -0400 Subject: [PATCH 2/2] fix(feature_extraction): actually raise an exception for negative control creation --- src/readii/feature_extraction.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/readii/feature_extraction.py b/src/readii/feature_extraction.py index dfa3aa0..a7cabe7 100644 --- a/src/readii/feature_extraction.py +++ b/src/readii/feature_extraction.py @@ -114,6 +114,7 @@ def singleRadiomicFeatureExtraction( ) except Exception as e: logger.error(f"Error generating {negativeControl} negative control for CT: {e}") + raise croppedCT, croppedROI = imageoperations.cropToTumorMask(ctImage_nc, alignedROIImage, segBoundingBox) else: