Skip to content

Commit

Permalink
Tweaks for pylint testing
Browse files Browse the repository at this point in the history
- Fixed issues in blend and convert_bruker scripts
- Added bypass comments to prevent pylint erros in specific locations where the behaviour is intended; this includes library functions that are not invoked within that particular library file, but may be used elsewhere.
- Minor tweaks to run_pylint script.
  • Loading branch information
Lestropie committed Aug 16, 2017
1 parent ccaf0cd commit f2e91c8
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 45 deletions.
34 changes: 15 additions & 19 deletions bin/blend
@@ -1,14 +1,12 @@
#!/usr/bin/env python2
import os
import sys
import string
import math

if len(sys.argv) <= 1:
print ('A script to blend two sets of movie frames together with a desired overlap.')
print ('The input arguments are two folders containing the movie frames (eg. output from the MRview screenshot tool), and the desired number of overlapping frames.')
print ('eg: blend folder1 folder2 20 output_folder')
sys.exit(1)
print ('A script to blend two sets of movie frames together with a desired overlap.')
print ('The input arguments are two folders containing the movie frames (eg. output from the MRview screenshot tool), and the desired number of overlapping frames.')
print ('eg: blend folder1 folder2 20 output_folder')
sys.exit(1)

input_folder1 = sys.argv[1]
input_folder2 = sys.argv[2]
Expand All @@ -18,19 +16,17 @@ num_overlap = int(sys.argv[3])
output_folder = sys.argv[4]

if not os.path.exists(output_folder):
os.mkdir(output_folder)
os.mkdir(output_folder)

total_num_output_frames = len(file_list1) + len(file_list2) - num_overlap
for i in range(total_num_output_frames):
file_name = 'frame' + '%0*d' % (5, i) + '.png'
if (i <= (len(file_list1) - num_overlap)):
os.system('cp -L ' + input_folder1 + '/' + file_list1[i] + ' ' + output_folder + '/' + file_name)
if (i > (len(file_list1) - num_overlap)) and (i < (len(file_list1))):
i2 = i - (len(file_list1) - num_overlap) - 1
blend_amount = 100 * float(i2 + 1) / float(num_overlap)
os.system('convert ' + input_folder1 + '/' + file_list1[i] + ' ' + input_folder2 + '/' + file_list2[i2] + ' -alpha on -compose blend -define compose:args=' + str(blend_amount) + ' -gravity South -composite ' + output_folder + '/' + file_name)
if (i >= (len(file_list1))):
i2 = i - (len(file_list1) - num_overlap) - 1
os.system('cp -L ' + input_folder2 + '/' + file_list2[i2] + ' ' + output_folder + '/' + file_name)


file_name = 'frame' + '%0*d' % (5, i) + '.png'
if i <= (len(file_list1) - num_overlap):
os.system('cp -L ' + input_folder1 + '/' + file_list1[i] + ' ' + output_folder + '/' + file_name)
if i > (len(file_list1) - num_overlap) and i < (len(file_list1)):
i2 = i - (len(file_list1) - num_overlap) - 1
blend_amount = 100 * float(i2 + 1) / float(num_overlap)
os.system('convert ' + input_folder1 + '/' + file_list1[i] + ' ' + input_folder2 + '/' + file_list2[i2] + ' -alpha on -compose blend -define compose:args=' + str(blend_amount) + ' -gravity South -composite ' + output_folder + '/' + file_name)
if i >= (len(file_list1)):
i2 = i - (len(file_list1) - num_overlap) - 1
os.system('cp -L ' + input_folder2 + '/' + file_list2[i2] + ' ' + output_folder + '/' + file_name)
24 changes: 16 additions & 8 deletions bin/convert_bruker
Expand Up @@ -62,13 +62,15 @@ with open (sys.argv[2], 'w') as f:
f.write (',' + str(mat_size[2]))
else:
try:
dummy = nslices
#pylint: disable=pointless-statement
nslices
f.write (',' + str(nslices))
except:
pass

try:
dummy = nacq
#pylint: disable=pointless-statement
nacq
f.write (',' + str(nacq))
except:
pass
Expand All @@ -78,12 +80,14 @@ with open (sys.argv[2], 'w') as f:
f.write (',' + str(res[2]))
else:
try:
dummy = slicethick
#pylint: disable=pointless-statement
slicethick
f.write (',' + str(slicethick))
except:
pass
try:
dummy = nacq
#pylint: disable=pointless-statement
nacq
f.write (',')
except:
pass
Expand All @@ -101,21 +105,25 @@ with open (sys.argv[2], 'w') as f:

f.write ('\nlayout: +0,+1')
try:
dummy = nslices
#pylint: disable=pointless-statement
nslices
f.write (',+2')
except:
pass
try:
dummy = nacq
#pylint: disable=pointless-statement
nacq
f.write (',+3')
except:
pass

f.write ('\nfile: ' + sys.argv[1] + '\n')

try:
dummy = bvec
dummy = bval
#pylint: disable=pointless-statement
bvec
#pylint: disable=pointless-statement
bval
for n in range (0, len (bval)):
f.write ('dw_scheme: ' + bvec[3*n] + ',' + bvec[3*n+1] + ',' + str(-float(bvec[3*n+2])) + ',' + bval[n] + '\n')
except:
Expand Down
4 changes: 3 additions & 1 deletion lib/mrtrix3/algorithm.py
Expand Up @@ -14,6 +14,7 @@ def _algorithmsPath():


# This function needs to be safe to run in order to populate the help page; that is, no app initialisation has been run
#pylint: disable=unused-variable
def getList():
import os
from mrtrix3 import app
Expand All @@ -32,6 +33,7 @@ def getList():
# Note: This function essentially duplicates the current state of app.cmdline in order for command-line
# options common to all algorithms of a particular script to be applicable once any particular sub-parser
# is invoked. Therefore this function must be called _after_ all such options are set up.
#pylint: disable=unused-variable
def initialise():
import importlib, pkgutil
from mrtrix3 import app, path
Expand All @@ -46,7 +48,7 @@ def initialise():




#pylint: disable=unused-variable
def getModule(name):
import sys
from mrtrix3 import path
Expand Down
22 changes: 18 additions & 4 deletions lib/mrtrix3/app.py
Expand Up @@ -27,6 +27,7 @@
args = ''
cmdline = None
config = { }
#pylint: disable=unused-variable
force = False


Expand All @@ -44,7 +45,9 @@
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
For more details, see http://www.mrtrix.org/.'''
#pylint: disable=unused-variable
_lastFile = ''
#pylint: disable=unused-variable
_nthreads = None
_tempDir = ''
_verbosity = 1 # 0 = quiet; 1 = default; 2 = info; 3 = debug
Expand Down Expand Up @@ -73,7 +76,7 @@




#pylint: disable=unused-variable
def init(author, synopsis):
import os, signal
global cmdline, config
Expand Down Expand Up @@ -103,6 +106,7 @@ def init(author, synopsis):



#pylint: disable=unused-variable
def parse():
import os, sys
global args, cmdline
Expand Down Expand Up @@ -166,7 +170,7 @@ def parse():




#pylint: disable=unused-variable
def checkOutputPath(path):
import os
global args, force
Expand All @@ -188,7 +192,7 @@ def checkOutputPath(path):




#pylint: disable=unused-variable
def makeTempDir():
import os, random, string, sys
global args, config
Expand Down Expand Up @@ -224,6 +228,7 @@ def makeTempDir():



#pylint: disable=unused-variable
def gotoTempDir():
import os
global _tempDir
Expand All @@ -235,6 +240,7 @@ def gotoTempDir():



#pylint: disable=unused-variable
def complete():
import os, shutil, sys
global _cleanup, _tempDir, _workingDir
Expand All @@ -257,7 +263,6 @@ def complete():




# A set of functions and variables for printing various information at the command-line.
clearLine = ''
colourClear = ''
Expand All @@ -267,13 +272,15 @@ def complete():
colourExec = ''
colourWarn = ''

#pylint: disable=unused-variable
def console(text):
import os, sys
global colourClear, colourConsole
global _verbosity
if _verbosity:
sys.stderr.write(os.path.basename(sys.argv[0]) + ': ' + colourConsole + text + colourClear + '\n')

#pylint: disable=unused-variable
def debug(text):
import inspect, os, sys
global colourClear, colourDebug
Expand All @@ -299,6 +306,7 @@ def debug(text):
origin = funcname + ' (from ' + os.path.basename(caller.filename) + ':' + str(caller.lineno) + ')'
sys.stderr.write(os.path.basename(sys.argv[0]) + ': ' + colourDebug + '[DEBUG] ' + origin + ': ' + text + colourClear + '\n')

#pylint: disable=unused-variable
def error(text):
import os, sys
global colourClear, colourError
Expand All @@ -308,6 +316,7 @@ def error(text):
complete()
sys.exit(1)

#pylint: disable=unused-variable
def warn(text):
import os, sys
global colourClear, colourWarn
Expand Down Expand Up @@ -368,18 +377,22 @@ def __init__(self, *args_in, **kwargs_in):
standard_options.add_argument('-debug', action='store_true', help='Display additional debugging information over and above the output of -info')
self.flagMutuallyExclusiveOptions( [ 'quiet', 'info', 'debug' ] )

#pylint: disable=unused-variable
def addCitation(self, condition, reference, is_external):
self._citationList.append( (condition, reference) )
if is_external:
self._externalCitations = True

#pylint: disable=unused-variable
def addDescription(self, text):
self._description.append(text)

#pylint: disable=unused-variable
def setCopyright(self, text):
self._copyright = text

# Mutually exclusive options need to be added before the command-line input is parsed
#pylint: disable=unused-variable
def flagMutuallyExclusiveOptions(self, options, required=False):
import sys
if not isinstance(options, list) or not isinstance(options[0], str):
Expand Down Expand Up @@ -820,6 +833,7 @@ def done(self):


# Return a boolean flag to indicate whether or not script is being run on a Windows machine
#pylint: disable=unused-variable
def isWindows():
import platform
system = platform.system().lower()
Expand Down
4 changes: 4 additions & 0 deletions lib/mrtrix3/file.py
Expand Up @@ -6,6 +6,7 @@
# that is no longer required by the script. If the script has been instructed to retain
# all temporaries, the resource will be retained; if not, it will be deleted (in particular
# to dynamically free up storage space used by the script).
#pylint: disable=unused-variable
def delTemporary(path):
import shutil, os
from mrtrix3 import app
Expand All @@ -30,6 +31,7 @@ def delTemporary(path):


# Make a directory if it doesn't exist; don't do anything if it does already exist
#pylint: disable=unused-variable
def makeDir(path):
import errno, os
from mrtrix3 import app
Expand All @@ -45,6 +47,7 @@ def makeDir(path):

# Get an appropriate location and name for a new temporary file
# Note: Doesn't actually create a file; just gives a unique name that won't over-write anything
#pylint: disable=unused-variable
def newTempFile(suffix):
import os, random, string, sys
from mrtrix3 import app
Expand Down Expand Up @@ -87,6 +90,7 @@ def newTempFile(suffix):
# Initially, checks for the file once every 1/1000th of a second; this gradually
# increases if the file still doesn't exist, until the program is only checking
# for the file once a minute.
#pylint: disable=unused-variable
def waitFor(path):
import os, time
from mrtrix3 import app
Expand Down
4 changes: 4 additions & 0 deletions lib/mrtrix3/fsl.py
Expand Up @@ -6,6 +6,7 @@
# this depends on both whether or not the user has requested that the CUDA
# version of eddy be used, and the various names that this command could
# conceivably be installed as.
#pylint: disable=unused-variable
def eddyBinary(cuda):
import os
from mrtrix3 import app
Expand Down Expand Up @@ -53,6 +54,7 @@ def eddyBinary(cuda):
# makes it more convenient to locate these commands.
# Note that if FSL 4 and 5 are installed side-by-side, the approach taken in this
# function will select the version 5 executable.
#pylint: disable=unused-variable
def exeName(name):
from mrtrix3 import app
from distutils.spawn import find_executable
Expand All @@ -71,6 +73,7 @@ def exeName(name):
# FSL commands will generate based on the suffix() function, the FSL binaries themselves
# ignore the FSLOUTPUTTYPE environment variable. Therefore, the safest approach is:
# Whenever receiving an output image from an FSL command, explicitly search for the path
#pylint: disable=unused-variable
def findImage(name):
import os
from mrtrix3 import app
Expand All @@ -90,6 +93,7 @@ def findImage(name):
# stored in 'FSLOUTPUTTYPE'. This may even override a filename extension provided
# to the relevant command. Therefore use this function to 'guess' what the names
# of images provided by FSL commands will be.
#pylint: disable=unused-variable
def suffix():
import os
from mrtrix3 import app
Expand Down
5 changes: 5 additions & 0 deletions lib/mrtrix3/image.py
Expand Up @@ -3,6 +3,7 @@
# data, rather than trying to duplicate support for all possible image formats natively
# in Python.

#pylint: disable=unused-variable
def check3DNonunity(image_path):
from mrtrix3 import app
dim = header(image_path).size
Expand Down Expand Up @@ -43,6 +44,7 @@ def __init__(self, image_path):
self.format or not self.datatype or not self.transform:
app.error('Error in reading header information from file \'' + image_path + '\'')

#pylint: disable=unused-variable
def header(image_path):
result = _Header(image_path)
return result
Expand All @@ -54,6 +56,7 @@ def header(image_path):
# Therefore, provide this function to execute mrinfo and get just the information of
# interest. Note however that parsing the output of mrinfo e.g. into list / numerical
# form is not performed by this function.
#pylint: disable=unused-variable
def mrinfo(image_path, field):
import subprocess
from mrtrix3 import app, run
Expand All @@ -71,6 +74,7 @@ def mrinfo(image_path, field):

# Check to see whether the fundamental header properties of two images match
# Inputs can be either _Header class instances, or file paths
#pylint: disable=unused-variable
def match(image_one, image_two):
import math
from mrtrix3 import app
Expand Down Expand Up @@ -107,6 +111,7 @@ def match(image_one, image_two):

# TODO Change mask_path to instead receive a string of additional command-line options
# (that way, -allvolumes can be used)
#pylint: disable=unused-variable
def statistic(image_path, stat, mask_path = ''):
import subprocess
from mrtrix3 import app, run
Expand Down

0 comments on commit f2e91c8

Please sign in to comment.