Skip to content

Commit ca91455

Browse files
authored
Merge pull request #2276 from tsalo/logger
[REF] Fix use of logging module in utils, algorithms and interfaces.
2 parents f38f021 + ab91510 commit ca91455

28 files changed

+204
-201
lines changed

nipype/algorithms/confounds.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from ..utils import NUMPY_MMAP
3131
from ..utils.misc import normalize_mc_params
3232

33-
IFLOG = logging.getLogger('interface')
33+
IFLOGGER = logging.getLogger('interface')
3434

3535

3636
class ComputeDVARSInputSpec(BaseInterfaceInputSpec):
@@ -286,7 +286,7 @@ def _run_interface(self, runtime):
286286
tr = self.inputs.series_tr
287287

288288
if self.inputs.normalize and tr is None:
289-
IFLOG.warn('FD plot cannot be normalized if TR is not set')
289+
IFLOGGER.warn('FD plot cannot be normalized if TR is not set')
290290

291291
self._results['out_figure'] = op.abspath(self.inputs.out_figure)
292292
fig = plot_confound(fd_res, self.inputs.figsize, 'FD', units='mm',
@@ -601,8 +601,8 @@ def _process_masks(self, mask_images, timeseries=None):
601601
# save mask
602602
mask_file = os.path.abspath('mask_{:03d}.nii.gz'.format(i))
603603
out_image.to_filename(mask_file)
604-
IFLOG.debug('tCompcor computed and saved mask of shape {} to '
605-
'mask_file {}'.format(mask.shape, mask_file))
604+
IFLOGGER.debug('tCompcor computed and saved mask of shape %s to '
605+
'mask_file %s', str(mask.shape), mask_file)
606606
self._mask_files.append(mask_file)
607607
out_images.append(out_image)
608608
return out_images
@@ -919,7 +919,8 @@ def regress_poly(degree, data, remove_mean=True, axis=-1):
919919
:param int axis: numpy array axes along which regression is performed
920920
921921
"""
922-
IFLOG.debug('Performing polynomial regression on data of shape ' + str(data.shape))
922+
IFLOGGER.debug('Performing polynomial regression on data of shape %s',
923+
str(data.shape))
923924

924925
datashape = data.shape
925926
timepoints = datashape[axis]
@@ -1147,7 +1148,7 @@ def _full_rank(X, cmax=1e15):
11471148
c = smax / smin
11481149
if c < cmax:
11491150
return X, c
1150-
IFLOG.warn('Matrix is singular at working precision, regularizing...')
1151+
IFLOGGER.warn('Matrix is singular at working precision, regularizing...')
11511152
lda = (smax - cmax * smin) / (cmax - 1)
11521153
s = s + lda
11531154
X = np.dot(U, np.dot(np.diag(s), V))

nipype/algorithms/misc.py

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -362,26 +362,23 @@ def _run_interface(self, runtime):
362362
if isinstance(in_dict[key][0], np.ndarray):
363363
saved_variables.append(key)
364364
else:
365-
iflogger.info('One of the keys in the input file, {k}, is not a Numpy array'.format(k=key))
365+
iflogger.info('One of the keys in the input file, %s, is '
366+
'not a Numpy array', key)
366367

367368
if len(saved_variables) > 1:
368-
iflogger.info(
369-
'{N} variables found:'.format(N=len(saved_variables)))
369+
iflogger.info('%i variables found:', len(saved_variables))
370370
iflogger.info(saved_variables)
371371
for variable in saved_variables:
372-
iflogger.info(
373-
'...Converting {var} - type {ty} - to\
374-
CSV'.format(var=variable, ty=type(in_dict[variable]))
375-
)
376-
matlab2csv(
377-
in_dict[variable], variable, self.inputs.reshape_matrix)
372+
iflogger.info('...Converting %s - type %s - to CSV',
373+
variable, type(in_dict[variable]))
374+
matlab2csv(in_dict[variable], variable, self.inputs.reshape_matrix)
378375
elif len(saved_variables) == 1:
379376
_, name, _ = split_filename(self.inputs.in_file)
380377
variable = saved_variables[0]
381-
iflogger.info('Single variable found {var}, type {ty}:'.format(
382-
var=variable, ty=type(in_dict[variable])))
383-
iflogger.info('...Converting {var} to CSV from {f}'.format(
384-
var=variable, f=self.inputs.in_file))
378+
iflogger.info('Single variable found %s, type %s:', variable,
379+
type(in_dict[variable]))
380+
iflogger.info('...Converting %s to CSV from %s', variable,
381+
self.inputs.in_file)
385382
matlab2csv(in_dict[variable], name, self.inputs.reshape_matrix)
386383
else:
387384
iflogger.error('No values in the MATLAB file?!')
@@ -396,8 +393,8 @@ def _list_outputs(self):
396393
if isinstance(in_dict[key][0], np.ndarray):
397394
saved_variables.append(key)
398395
else:
399-
iflogger.error('One of the keys in the input file, {k}, is\
400-
not a Numpy array'.format(k=key))
396+
iflogger.error('One of the keys in the input file, %s, is '
397+
'not a Numpy array', key)
401398

402399
if len(saved_variables) > 1:
403400
outputs['csv_files'] = replaceext(saved_variables, '.csv')
@@ -555,28 +552,25 @@ def _run_interface(self, runtime):
555552
iflogger.info('Column headings have been provided:')
556553
headings = self.inputs.column_headings
557554
else:
558-
iflogger.info(
559-
'Column headings not provided! Pulled from input filenames:')
555+
iflogger.info('Column headings not provided! Pulled from input filenames:')
560556
headings = remove_identical_paths(self.inputs.in_files)
561557

562558
if isdefined(self.inputs.extra_field):
563559
if isdefined(self.inputs.extra_column_heading):
564560
extraheading = self.inputs.extra_column_heading
565-
iflogger.info('Extra column heading provided: {col}'.format(
566-
col=extraheading))
561+
iflogger.info('Extra column heading provided: %s', extraheading)
567562
else:
568563
extraheading = 'type'
569-
iflogger.info(
570-
'Extra column heading was not defined. Using "type"')
564+
iflogger.info('Extra column heading was not defined. Using "type"')
571565
headings.append(extraheading)
572566
extraheadingBool = True
573567

574568
if len(self.inputs.in_files) == 1:
575569
iflogger.warn('Only one file input!')
576570

577571
if isdefined(self.inputs.row_headings):
578-
iflogger.info('Row headings have been provided. Adding "labels"\
579-
column header.')
572+
iflogger.info('Row headings have been provided. Adding "labels"'
573+
'column header.')
580574
prefix = '"{p}","'.format(p=self.inputs.row_heading_title)
581575
csv_headings = prefix + '","'.join(itertools.chain(
582576
headings)) + '"\n'
@@ -1310,7 +1304,7 @@ def merge_rois(in_files, in_idxs, in_ref,
13101304
# to avoid memory errors
13111305
if op.splitext(in_ref)[1] == '.gz':
13121306
try:
1313-
iflogger.info('uncompress %i' % in_ref)
1307+
iflogger.info('uncompress %i', in_ref)
13141308
sp.check_call(['gunzip', in_ref], stdout=sp.PIPE, shell=True)
13151309
in_ref = op.splitext(in_ref)[0]
13161310
except:

nipype/algorithms/modelgen.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,9 @@ def _generate_standard_design(self, infolist, functional_runs=None,
374374
for f in filename_to_list(sessinfo[i]['scans']):
375375
shape = load(f, mmap=NUMPY_MMAP).shape
376376
if len(shape) == 3 or shape[3] == 1:
377-
iflogger.warning(('You are using 3D instead of 4D '
378-
'files. Are you sure this was '
379-
'intended?'))
377+
iflogger.warning('You are using 3D instead of 4D '
378+
'files. Are you sure this was '
379+
'intended?')
380380
numscans += 1
381381
else:
382382
numscans += shape[3]
@@ -686,7 +686,7 @@ def _gen_regress(self, i_onsets, i_durations, i_amplitudes, nscans):
686686

687687
if dt < 1:
688688
raise Exception('Time multiple less than 1 ms')
689-
iflogger.info('Setting dt = %d ms\n' % dt)
689+
iflogger.info('Setting dt = %d ms\n', dt)
690690
npts = int(np.ceil(total_time / dt))
691691
times = np.arange(0, total_time, dt) * 1e-3
692692
timeline = np.zeros((npts))
@@ -705,9 +705,9 @@ def _gen_regress(self, i_onsets, i_durations, i_amplitudes, nscans):
705705
if isdefined(self.inputs.model_hrf) and self.inputs.model_hrf:
706706
response = np.convolve(boxcar, hrf)
707707
reg_scale = 1.0 / response.max()
708-
iflogger.info('response sum: %.4f max: %.4f' % (response.sum(),
709-
response.max()))
710-
iflogger.info('reg_scale: %.4f' % reg_scale)
708+
iflogger.info('response sum: %.4f max: %.4f', response.sum(),
709+
response.max())
710+
iflogger.info('reg_scale: %.4f', reg_scale)
711711

712712
for i, t in enumerate(onsets):
713713
idx = int(np.round(t / dt))

nipype/interfaces/ants/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from ... import logging, LooseVersion
1212
from ..base import (CommandLine, CommandLineInputSpec, traits, isdefined,
1313
PackageInfo)
14-
logger = logging.getLogger('interface')
14+
iflogger = logging.getLogger('interface')
1515

1616
# -Using -1 gives primary responsibilty to ITKv4 to do the correct
1717
# thread limitings.

nipype/interfaces/ants/registration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ class Registration(ANTSCommand):
672672
673673
One can use multiple similarity metrics in a single registration stage.The Node below first
674674
performs a linear registation using only the Mutual Information ('Mattes')-metric.
675-
In a second stage, it performs a non-linear registration ('Syn') using both a
675+
In a second stage, it performs a non-linear registration ('Syn') using both a
676676
Mutual Information and a local cross-correlation ('CC')-metric. Both metrics are weighted
677677
equally ('metric_weight' is .5 for both). The Mutual Information- metric uses 32 bins.
678678
The local cross-correlations (correlations between every voxel's neighborhoods) is computed

0 commit comments

Comments
 (0)