Skip to content

Commit 3a01d1a

Browse files
committed
Merge pull request #4 from satra/enh/py3k-fix
Enh/py3k fix
2 parents 750e9af + 9b52c9d commit 3a01d1a

File tree

624 files changed

+1454
-1360
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

624 files changed

+1454
-1360
lines changed

examples/fmri_ants_openfmri.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"""
1414
from __future__ import division
1515
from builtins import range
16-
from past.utils import old_div
1716

1817
from nipype import config
1918
config.enable_provenance()
@@ -79,7 +78,7 @@ def median(in_files):
7978
average = data
8079
else:
8180
average = average + data
82-
median_img = nb.Nifti1Image(old_div(average,float(idx + 1)),
81+
median_img = nb.Nifti1Image(average / float(idx + 1),
8382
img.get_affine(), img.get_header())
8483
filename = os.path.join(os.getcwd(), 'median.nii.gz')
8584
median_img.to_filename(filename)
@@ -574,7 +573,7 @@ def get_subjectinfo(subject_id, base_dir, task_id, model_id):
574573
import json
575574
with open(json_info, 'rt') as fp:
576575
data = json.load(fp)
577-
TR = old_div(data['global']['const']['RepetitionTime'],1000.)
576+
TR = data['global']['const']['RepetitionTime'] / 1000.
578577
else:
579578
task_scan_key = os.path.join(base_dir, subject_id, 'BOLD',
580579
'task%03d_run%03d' % (task_id, run_ids[task_id - 1][0]),
@@ -714,7 +713,7 @@ def analyze_openfmri_dataset(data_dir, subject=None, model_id=None,
714713
])
715714

716715
def get_highpass(TR, hpcutoff):
717-
return old_div(hpcutoff, (2 * TR))
716+
return hpcutoff / (2. * TR)
718717
gethighpass = pe.Node(niu.Function(input_names=['TR', 'hpcutoff'],
719718
output_names=['highpass'],
720719
function=get_highpass),
@@ -773,7 +772,8 @@ def check_behav_list(behav, run_id, conds):
773772
behav = [behav]
774773
behav_array = np.array(behav).flatten()
775774
num_elements = behav_array.shape[0]
776-
return behav_array.reshape(old_div(num_elements,num_conds), num_conds).tolist()
775+
return behav_array.reshape(int(num_elements / num_conds),
776+
num_conds).tolist()
777777

778778
reshape_behav = pe.Node(niu.Function(input_names=['behav', 'run_id', 'conds'],
779779
output_names=['behav'],
@@ -836,8 +836,10 @@ def sort_copes(copes, varcopes, contrasts):
836836
n_runs = len(copes)
837837
all_copes = np.array(copes).flatten()
838838
all_varcopes = np.array(varcopes).flatten()
839-
outcopes = all_copes.reshape(old_div(len(all_copes),num_copes), num_copes).T.tolist()
840-
outvarcopes = all_varcopes.reshape(old_div(len(all_varcopes),num_copes), num_copes).T.tolist()
839+
outcopes = all_copes.reshape(int(len(all_copes) / num_copes),
840+
num_copes).T.tolist()
841+
outvarcopes = all_varcopes.reshape(int(len(all_varcopes) / num_copes),
842+
num_copes).T.tolist()
841843
return outcopes, outvarcopes, n_runs
842844

843845
cope_sorter = pe.Node(niu.Function(input_names=['copes', 'varcopes',

examples/fmri_fsl.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from __future__ import print_function
1818
from __future__ import division
1919
from builtins import range
20-
from past.utils import old_div
2120

2221
import os # system functions
2322

@@ -108,7 +107,7 @@ def getmiddlevolume(func):
108107
if isinstance(func, list):
109108
funcfile = func[0]
110109
_,_,_,timepoints = load(funcfile).get_shape()
111-
return (old_div(timepoints,2))-1
110+
return int(timepoints / 2) - 1
112111

113112
preproc.connect(inputnode, ('func', getmiddlevolume), extract_ref, 't_min')
114113

@@ -290,7 +289,7 @@ def getusans(x):
290289
"""
291290

292291
def getinormscale(medianvals):
293-
return ['-mul %.10f'%(old_div(10000.,val)) for val in medianvals]
292+
return ['-mul %.10f' % (10000. / val) for val in medianvals]
294293
preproc.connect(medianval, ('out_stat', getinormscale), intnorm, 'op_string')
295294

296295
"""
@@ -555,9 +554,9 @@ def num_copes(files):
555554
smoothnode.iterables = ('fwhm', [5.,10.])
556555

557556
hpcutoff = 120
558-
TR = 3.
557+
TR = 3. # ensure float
559558
firstlevel.inputs.preproc.highpass.suffix = '_hpf'
560-
firstlevel.inputs.preproc.highpass.op_string = '-bptf %d -1'%(old_div(hpcutoff,TR))
559+
firstlevel.inputs.preproc.highpass.op_string = '-bptf %d -1' % (hpcutoff / TR)
561560

562561

563562
"""
@@ -572,7 +571,7 @@ def num_copes(files):
572571
def subjectinfo(subject_id):
573572
from nipype.interfaces.base import Bunch
574573
from copy import deepcopy
575-
print("Subject ID: %s\n"%str(subject_id))
574+
print("Subject ID: %s\n" % str(subject_id))
576575
output = []
577576
names = ['Task-Odd','Task-Even']
578577
for r in range(4):

examples/fmri_fsl_feeds.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"""
1515
from __future__ import division
1616
from builtins import range
17-
from past.utils import old_div
1817

1918
import os # system functions
2019

@@ -72,7 +71,7 @@
7271
preproc = create_featreg_preproc(whichvol='first')
7372
TR = 3.
7473
preproc.inputs.inputspec.fwhm = 5
75-
preproc.inputs.inputspec.highpass = old_div(100,TR)
74+
preproc.inputs.inputspec.highpass = 100. / TR
7675

7776
modelspec = pe.Node(interface=model.SpecifyModel(),
7877
name="modelspec")

examples/fmri_fsl_reuse.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from __future__ import print_function
1818
from __future__ import division
1919
from builtins import range
20-
from past.utils import old_div
2120

2221
import os # system functions
2322

@@ -29,8 +28,8 @@
2928
import nipype.algorithms.rapidart as ra # artifact detection
3029

3130
from nipype.workflows.fmri.fsl import (create_featreg_preproc,
32-
create_modelfit_workflow,
33-
create_fixed_effects_flow)
31+
create_modelfit_workflow,
32+
create_fixed_effects_flow)
3433

3534

3635
"""
@@ -185,7 +184,7 @@ def num_copes(files):
185184

186185
hpcutoff = 120.
187186
TR = 3.
188-
inputnode.inputs.highpass = old_div(hpcutoff,(2*TR))
187+
inputnode.inputs.highpass = hpcutoff / (2. * TR)
189188

190189
"""
191190
Setup a function that returns subject-specific information about the

examples/fmri_openfmri.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"""
1414
from __future__ import division
1515
from builtins import range
16-
from past.utils import old_div
1716

1817

1918
from glob import glob
@@ -187,7 +186,7 @@ def analyze_openfmri_dataset(data_dir, subject=None, model_id=None,
187186
])
188187

189188
def get_highpass(TR, hpcutoff):
190-
return old_div(hpcutoff, (2 * TR))
189+
return hpcutoff / (2. * TR)
191190
gethighpass = pe.Node(niu.Function(input_names=['TR', 'hpcutoff'],
192191
output_names=['highpass'],
193192
function=get_highpass),

examples/fmri_spm_face.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
Import necessary modules from nipype."""
1919
from __future__ import division
2020
from builtins import range
21-
from past.utils import old_div
2221

2322
import nipype.interfaces.io as nio # Data i/o
2423
import nipype.interfaces.spm as spm # spm
@@ -327,9 +326,9 @@ def makelist(item):
327326
slice_timingref = l1pipeline.inputs.preproc.slice_timing
328327
slice_timingref.num_slices = num_slices
329328
slice_timingref.time_repetition = TR
330-
slice_timingref.time_acquisition = TR - old_div(TR,float(num_slices))
329+
slice_timingref.time_acquisition = TR - TR / float(num_slices)
331330
slice_timingref.slice_order = list(range(num_slices,0,-1))
332-
slice_timingref.ref_slice = int(old_div(num_slices,2))
331+
slice_timingref.ref_slice = int(num_slices / 2)
333332

334333
l1pipeline.inputs.preproc.smooth.fwhm = [8, 8, 8]
335334

examples/rsfmri_vol_surface_preprocessing.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
"""
4545
from __future__ import division
4646
from builtins import range
47-
from past.utils import old_div
48-
4947

5048
import os
5149

@@ -99,7 +97,7 @@ def get_info(dicom_files):
9997
meta = default_extractor(read_file(filename_to_list(dicom_files)[0],
10098
stop_before_pixels=True,
10199
force=True))
102-
return (old_div(meta['RepetitionTime'],1000.), meta['CsaImage.MosaicRefAcqTimes'],
100+
return (meta['RepetitionTime'] / 1000., meta['CsaImage.MosaicRefAcqTimes'],
103101
meta['SpacingBetweenSlices'])
104102

105103

@@ -126,7 +124,7 @@ def median(in_files):
126124
average = data
127125
else:
128126
average = average + data
129-
median_img = nb.Nifti1Image(old_div(average,float(idx + 1)),
127+
median_img = nb.Nifti1Image(average / float(idx + 1),
130128
img.get_affine(), img.get_header())
131129
filename = os.path.join(os.getcwd(), 'median.nii.gz')
132130
median_img.to_filename(filename)
@@ -153,7 +151,7 @@ def bandpass_filter(files, lowpass_freq, highpass_freq, fs):
153151
img = nb.load(filename)
154152
timepoints = img.shape[-1]
155153
F = np.zeros((timepoints))
156-
lowidx = old_div(timepoints,2) + 1
154+
lowidx = int(timepoints / 2) + 1
157155
if lowpass_freq > 0:
158156
lowidx = np.round(lowpass_freq / fs * timepoints)
159157
highidx = 0
@@ -278,7 +276,7 @@ def extract_noise_components(realigned_file, mask_file, num_components=5,
278276
stdX[stdX == 0] = 1.
279277
stdX[np.isnan(stdX)] = 1.
280278
stdX[np.isinf(stdX)] = 1.
281-
X = old_div((X - np.mean(X, axis=0)),stdX)
279+
X = (X - np.mean(X, axis=0)) / stdX
282280
u, _, _ = svd(X, full_matrices=False)
283281
if components is None:
284282
components = u[:, :num_components]
@@ -610,9 +608,9 @@ def create_workflow(files,
610608
slice_timing = Node(interface=spm.SliceTiming(), name="slice_timing")
611609
slice_timing.inputs.num_slices = num_slices
612610
slice_timing.inputs.time_repetition = TR
613-
slice_timing.inputs.time_acquisition = TR - old_div(TR,float(num_slices))
611+
slice_timing.inputs.time_acquisition = TR - TR / float(num_slices)
614612
slice_timing.inputs.slice_order = (np.argsort(slice_times) + 1).tolist()
615-
slice_timing.inputs.ref_slice = int(old_div(num_slices,2))
613+
slice_timing.inputs.ref_slice = int(num_slices / 2)
616614

617615
# Comute TSNR on realigned data regressing polynomials upto order 2
618616
tsnr = MapNode(TSNR(regress_poly=2), iterfield=['in_file'], name='tsnr')
@@ -745,7 +743,7 @@ def merge_files(in1, in2):
745743
function=bandpass_filter,
746744
imports=imports),
747745
name='bandpass_unsmooth')
748-
bandpass.inputs.fs = old_div(1.,TR)
746+
bandpass.inputs.fs = 1. / TR
749747
bandpass.inputs.highpass_freq = highpass_freq
750748
bandpass.inputs.lowpass_freq = lowpass_freq
751749
wf.connect(filter2, 'out_res', bandpass, 'files')
@@ -951,7 +949,7 @@ def create_resting_workflow(args, name=None):
951949
slice_times = args.slice_times
952950
if args.dicom_file:
953951
TR, slice_times, slice_thickness = get_info(args.dicom_file)
954-
slice_times = (old_div(np.array(slice_times),1000.)).tolist()
952+
slice_times = (np.array(slice_times) / 1000.).tolist()
955953
if name is None:
956954
name = 'resting_' + args.subject_id
957955
kwargs = dict(files=[os.path.abspath(filename) for filename in args.files],

examples/rsfmri_vol_surface_preprocessing_nipy.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
"""
4646
from __future__ import division
4747
from builtins import range
48-
from past.utils import old_div
4948

5049
import os
5150

@@ -94,7 +93,7 @@ def get_info(dicom_files):
9493
meta = default_extractor(read_file(filename_to_list(dicom_files)[0],
9594
stop_before_pixels=True,
9695
force=True))
97-
return (old_div(meta['RepetitionTime'],1000.), meta['CsaImage.MosaicRefAcqTimes'],
96+
return (meta['RepetitionTime'] / 1000., meta['CsaImage.MosaicRefAcqTimes'],
9897
meta['SpacingBetweenSlices'])
9998

10099

@@ -119,7 +118,7 @@ def median(in_files):
119118
average = data
120119
else:
121120
average = average + data
122-
median_img = nb.Nifti1Image(old_div(average,float(idx + 1)),
121+
median_img = nb.Nifti1Image(average / float(idx + 1),
123122
img.get_affine(), img.get_header())
124123
filename = os.path.join(os.getcwd(), 'median.nii.gz')
125124
median_img.to_filename(filename)
@@ -143,7 +142,7 @@ def bandpass_filter(files, lowpass_freq, highpass_freq, fs):
143142
img = nb.load(filename)
144143
timepoints = img.shape[-1]
145144
F = np.zeros((timepoints))
146-
lowidx = old_div(timepoints,2) + 1
145+
lowidx = int(timepoints / 2) + 1
147146
if lowpass_freq > 0:
148147
lowidx = np.round(float(lowpass_freq) / fs * timepoints)
149148
highidx = 0
@@ -260,7 +259,7 @@ def extract_noise_components(realigned_file, mask_file, num_components=5,
260259
stdX[stdX == 0] = 1.
261260
stdX[np.isnan(stdX)] = 1.
262261
stdX[np.isinf(stdX)] = 1.
263-
X = old_div((X - np.mean(X, axis=0)),stdX)
262+
X = (X - np.mean(X, axis=0)) / stdX
264263
u, _, _ = sp.linalg.svd(X, full_matrices=False)
265264
if components is None:
266265
components = u[:, :num_components]
@@ -735,7 +734,7 @@ def merge_files(in1, in2):
735734
function=bandpass_filter,
736735
imports=imports),
737736
name='bandpass_unsmooth')
738-
bandpass.inputs.fs = old_div(1.,TR)
737+
bandpass.inputs.fs = 1. / TR
739738
bandpass.inputs.highpass_freq = highpass_freq
740739
bandpass.inputs.lowpass_freq = lowpass_freq
741740
wf.connect(filter2, 'out_res', bandpass, 'files')
@@ -961,7 +960,7 @@ def create_resting_workflow(args, name=None):
961960
slice_times = args.slice_times
962961
if args.dicom_file:
963962
TR, slice_times, slice_thickness = get_info(args.dicom_file)
964-
slice_times = (old_div(np.array(slice_times),1000.)).tolist()
963+
slice_times = (np.array(slice_times) / 1000.).tolist()
965964

966965
if name is None:
967966
name = 'resting_' + args.subject_id

examples/test_spm.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import division
22
from builtins import range
3-
from past.utils import old_div
43
import nipype.pipeline.engine as pe
54
from nipype.interfaces import spm
65
from nipype.interfaces import fsl
@@ -15,7 +14,7 @@
1514
stc = pe.Node(interface=spm.SliceTiming(), name='stc')
1615
stc.inputs.num_slices = 21
1716
stc.inputs.time_repetition = 1.0
18-
stc.inputs.time_acquisition = 2. - old_div(2.,32)
17+
stc.inputs.time_acquisition = 2. - 2. / 32
1918
stc.inputs.slice_order = list(range(21,0,-1))
2019
stc.inputs.ref_slice = 10
2120

@@ -50,7 +49,7 @@
5049
stc = pe.Node(interface=spm.SliceTiming(), name='stc')
5150
stc.inputs.num_slices = 21
5251
stc.inputs.time_repetition = 1.0
53-
stc.inputs.time_acquisition = 2. - old_div(2.,32)
52+
stc.inputs.time_acquisition = 2. - 2. / 32
5453
stc.inputs.slice_order = list(range(21,0,-1))
5554
stc.inputs.ref_slice = 10
5655

nipype/algorithms/icc.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import division
22
from builtins import range
3-
from past.utils import old_div
43
from numpy import ones, kron, mean, eye, hstack, dot, tile
54
from scipy.linalg import pinv
65
from ..interfaces.base import BaseInterfaceInputSpec, TraitedSpec, \
@@ -110,22 +109,22 @@ def ICC_rep_anova(Y):
110109

111110
residuals.shape = Y.shape
112111

113-
MSE = old_div(SSE, dfe)
112+
MSE = SSE / dfe
114113

115114
# Sum square session effect - between colums/sessions
116115
SSC = ((mean(Y, 0) - mean_Y) ** 2).sum() * nb_subjects
117116
MSC = SSC / dfc / nb_subjects
118117

119-
session_effect_F = old_div(MSC, MSE)
118+
session_effect_F = MSC / MSE
120119

121120
# Sum Square subject effect - between rows/subjects
122121
SSR = SST - SSC - SSE
123-
MSR = old_div(SSR, dfr)
122+
MSR = SSR / dfr
124123

125124
# ICC(3,1) = (mean square subjeT - mean square error) / (mean square subjeT + (k-1)*-mean square error)
126-
ICC = old_div((MSR - MSE), (MSR + dfc * MSE))
125+
ICC = (MSR - MSE) / (MSR + dfc * MSE)
127126

128-
e_var = MSE #variance of error
129-
r_var = old_div((MSR - MSE),nb_conditions) #variance between subjects
127+
e_var = MSE # variance of error
128+
r_var = (MSR - MSE) / nb_conditions # variance between subjects
130129

131130
return ICC, r_var, e_var, session_effect_F, dfc, dfe

0 commit comments

Comments
 (0)