From 83b510c33a8a4fbf9e0cd2c534e10b29c070b851 Mon Sep 17 00:00:00 2001 From: Joost van Griethuysen Date: Mon, 12 Nov 2018 11:32:27 +0100 Subject: [PATCH] STYL: Fix flake8 errors Add ignores for 504 and 605 (new line after binary operator and invalid escape sequence, both were giving false positives) Fix Regex match pattern errors (missing `r` prefix to the pattern strings). --- .flake8 | 3 +++ labs/pyradiomics-dcm/pyradiomics-dcm.py | 19 ++++++------------- radiomics/featureextractor.py | 2 +- radiomics/imageoperations.py | 2 +- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/.flake8 b/.flake8 index 7916a372..02fe528b 100644 --- a/.flake8 +++ b/.flake8 @@ -33,6 +33,9 @@ ignore: E701, # .has_key() is deprecated, use 'in' W601, + # line break after binary operator + W504, + select: C,E,W,F,I # flake8-import-order application-import-names: radiomics,testUtils diff --git a/labs/pyradiomics-dcm/pyradiomics-dcm.py b/labs/pyradiomics-dcm/pyradiomics-dcm.py index 9b4f0939..b355852c 100644 --- a/labs/pyradiomics-dcm/pyradiomics-dcm.py +++ b/labs/pyradiomics-dcm/pyradiomics-dcm.py @@ -210,15 +210,15 @@ def prefix2codes(self, prefix): "modifierValue": self.makePrivateCode("Exponent transformation")}) # parameterized processing operations - elif re.match("wavelet-([HL]{2,3})", prefix): - match = re.match("wavelet-([HL]{2,3})", prefix) + elif re.match(r"wavelet-([HL]{2,3})", prefix): + match = re.match(r"wavelet-([HL]{2,3})", prefix) modifiers.append({"modifier": imageTransformationConcept, "modifierValue": self.makePrivateCode("Wavelet transformation")}) modifiers.append({"modifier": self.makePrivateCode("Wavelet sub-band"), "modifierValue": self.makePrivateCode(match.group(1))}) - elif re.match("log-sigma-([\d]+)-([\d]+)-([a-z]+)", prefix): - match = re.match("log-sigma-([\d]+)-([\d]+)-([a-z]+)", prefix) + elif re.match(r"log-sigma-([\d]+)-([\d]+)-([a-z]+)", prefix): + match = re.match(r"log-sigma-([\d]+)-([\d]+)-([a-z]+)", prefix) units = match.group(3) if units == "mm": @@ -286,11 +286,7 @@ def addMeasurement( quantityCode) return except Exception as e: - scriptlogger.error( - "Exception checking for NaN: " + - str(e) + - " " + - value) + scriptlogger.error("Exception checking for NaN: %s %s", str(e), value) return measurement["value"] = '%E' % Decimal(value) @@ -559,10 +555,7 @@ def main(): dcm = pydicom.read_file(outputSRTempFile) shutil.move( outputSRTempFile, - os.path.join( - args.outputDir, - dcm.SOPInstanceUID + - ".dcm")) + os.path.join(args.outputDir, dcm.SOPInstanceUID + ".dcm")) except BaseException: scriptlogger.error("Failed to move output SR!") diff --git a/radiomics/featureextractor.py b/radiomics/featureextractor.py index 630b0475..e60bb278 100644 --- a/radiomics/featureextractor.py +++ b/radiomics/featureextractor.py @@ -532,7 +532,7 @@ def loadImage(self, ImageFilePath, MaskFilePath): return image, mask def computeFeatures(self, image, mask, imageTypeName, **kwargs): - """ + r""" Compute signature using image, mask, \*\*kwargs settings. This function computes the signature for just the passed image (original or derived), it does not preprocess or diff --git a/radiomics/imageoperations.py b/radiomics/imageoperations.py index 2ae3e177..7bf2bcd3 100644 --- a/radiomics/imageoperations.py +++ b/radiomics/imageoperations.py @@ -539,7 +539,7 @@ def normalizeImage(image, **kwargs): def resegmentMask(imageNode, maskNode, **kwargs): - """ + r""" Resegment the Mask based on the range specified by the threshold(s) in ``resegmentRange``. Either 1 or 2 thresholds can be defined. In case of 1 threshold, all values equal to or higher than that threshold are included. If there are 2 thresholds, all voxels with a value inside the closed-range defined by these thresholds is included