Skip to content

Commit c4f1a52

Browse files
committed
unicode fixes, np.savetxt does not take unicode fmt
1 parent 74c93ec commit c4f1a52

File tree

8 files changed

+27
-26
lines changed

8 files changed

+27
-26
lines changed

examples/rsfmri_vol_surface_preprocessing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"""
4545

4646
from __future__ import division, unicode_literals
47-
from builtins import open, range
47+
from builtins import open, range, str
4848

4949
import os
5050

@@ -189,7 +189,7 @@ def motion_regressors(motion_params, order=0, derivatives=1):
189189
for i in range(2, order + 1):
190190
out_params2 = np.hstack((out_params2, np.power(out_params, i)))
191191
filename = os.path.join(os.getcwd(), "motion_regressor%02d.txt" % idx)
192-
np.savetxt(filename, out_params2, fmt="%.10f")
192+
np.savetxt(filename, out_params2, fmt=str("%.10f").encode())
193193
out_files.append(filename)
194194
return out_files
195195

@@ -237,7 +237,7 @@ def build_filter1(motion_params, comp_norm, outliers, detrend_poly=None):
237237
i + 1)(np.linspace(-1, 1, timepoints))[:, None]))
238238
out_params = np.hstack((out_params, X))
239239
filename = os.path.join(os.getcwd(), "filter_regressor%02d.txt" % idx)
240-
np.savetxt(filename, out_params, fmt="%.10f")
240+
np.savetxt(filename, out_params, fmt=str("%.10f").encode())
241241
out_files.append(filename)
242242
return out_files
243243

@@ -286,7 +286,7 @@ def extract_noise_components(realigned_file, mask_file, num_components=5,
286286
regressors = np.genfromtxt(extra_regressors)
287287
components = np.hstack((components, regressors))
288288
components_file = os.path.join(os.getcwd(), 'noise_components.txt')
289-
np.savetxt(components_file, components, fmt="%.10f")
289+
np.savetxt(components_file, components, fmt=str("%.10f").encode())
290290
return components_file
291291

292292

examples/rsfmri_vol_surface_preprocessing_nipy.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"""
4646

4747
from __future__ import division, unicode_literals
48-
from builtins import open, range
48+
from builtins import open, range, str
4949

5050
import os
5151

@@ -179,7 +179,7 @@ def motion_regressors(motion_params, order=0, derivatives=1):
179179
for i in range(2, order + 1):
180180
out_params2 = np.hstack((out_params2, np.power(out_params, i)))
181181
filename = os.path.join(os.getcwd(), "motion_regressor%02d.txt" % idx)
182-
np.savetxt(filename, out_params2, fmt="%.10f")
182+
np.savetxt(filename, out_params2, fmt=str("%.10f").encode())
183183
out_files.append(filename)
184184
return out_files
185185

@@ -224,7 +224,7 @@ def build_filter1(motion_params, comp_norm, outliers, detrend_poly=None):
224224
i + 1)(np.linspace(-1, 1, timepoints))[:, None]))
225225
out_params = np.hstack((out_params, X))
226226
filename = os.path.join(os.getcwd(), "filter_regressor%02d.txt" % idx)
227-
np.savetxt(filename, out_params, fmt="%.10f")
227+
np.savetxt(filename, out_params, fmt=str("%.10f").encode())
228228
out_files.append(filename)
229229
return out_files
230230

@@ -269,7 +269,7 @@ def extract_noise_components(realigned_file, mask_file, num_components=5,
269269
regressors = np.genfromtxt(extra_regressors)
270270
components = np.hstack((components, regressors))
271271
components_file = os.path.join(os.getcwd(), 'noise_components.txt')
272-
np.savetxt(components_file, components, fmt="%.10f")
272+
np.savetxt(components_file, components, fmt=str("%.10f").encode())
273273
return components_file
274274

275275

nipype/algorithms/rapidart.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,10 +468,10 @@ def _detect_outliers_core(self, imgfile, motionfile, runidx, cwd=None):
468468
outliers = np.unique(np.union1d(iidx, np.union1d(tidx, ridx)))
469469

470470
# write output to outputfile
471-
np.savetxt(artifactfile, outliers, fmt='%d', delimiter=' ')
472-
np.savetxt(intensityfile, g, fmt='%.2f', delimiter=' ')
471+
np.savetxt(artifactfile, outliers, fmt=str('%d').encode(), delimiter=' ')
472+
np.savetxt(intensityfile, g, fmt=str('%.2f').encode(), delimiter=' ')
473473
if self.inputs.use_norm:
474-
np.savetxt(normfile, normval, fmt='%.4f', delimiter=' ')
474+
np.savetxt(normfile, normval, fmt=str('%.4f').encode(), delimiter=' ')
475475

476476
if isdefined(self.inputs.save_plot) and self.inputs.save_plot:
477477
import matplotlib

nipype/interfaces/fsl/epi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
>>> os.chdir(datadir)
1414
"""
1515
from __future__ import print_function, division, unicode_literals, absolute_import
16+
from builtins import str
1617

1718
import os
1819
import numpy as np
@@ -295,7 +296,7 @@ def _generate_encfile(self):
295296
line = [float(val[0] == encdir[0]) * direction
296297
for val in ['x', 'y', 'z']] + [durations[idx]]
297298
lines.append(line)
298-
np.savetxt(out_file, np.array(lines), fmt='%d %d %d %.8f')
299+
np.savetxt(out_file, np.array(lines), fmt=str('%d %d %d %.8f').encode())
299300
return out_file
300301

301302
def _overload_extension(self, value, name=None):

nipype/interfaces/spm/base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
__docformat__ = 'restructuredtext'
3737
logger = logging.getLogger('interface')
3838

39-
__docformat__ = 'restructuredtext'
40-
4139

4240
def func_is_3d(in_file):
4341
"""Checks if input functional files are 3d."""
@@ -421,8 +419,11 @@ def _generate_job(self, prefix='', contents=None):
421419
if isinstance(val, np.ndarray):
422420
jobstring += self._generate_job(prefix=None,
423421
contents=val)
422+
elif isinstance(val, list):
423+
val_format = ', '.join(['\'{}\''] * len(val)).format
424+
jobstring += '[{}];...\n'.format(val_format(*val))
424425
elif isinstance(val, (str, bytes)):
425-
jobstring += '\'%s\';...\n' % (val)
426+
jobstring += '\'{}\';...\n'.format(val)
426427
else:
427428
jobstring += '%s;...\n' % str(val)
428429
jobstring += '};\n'

nipype/workflows/dmri/fsl/epi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
# coding: utf-8
33
from __future__ import print_function, division, unicode_literals, absolute_import
4-
from builtins import open
4+
from builtins import open, str
55

66
import warnings
77

@@ -681,7 +681,7 @@ def _rotate_bvecs(in_bvec, in_matrix):
681681
bvec = np.matrix(bvecs[:, i])
682682
rot = np.matrix(np.loadtxt(vol_matrix)[0:3, 0:3])
683683
new_bvecs[i] = (np.array(rot * bvec.T).T)[0] # fill each volume with x,y,z as we go along
684-
np.savetxt(out_file, np.array(new_bvecs).T, fmt='%0.15f')
684+
np.savetxt(out_file, np.array(new_bvecs).T, fmt=str('%0.15f').encode())
685685
return out_file
686686

687687

nipype/workflows/dmri/fsl/utils.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
44
# vi: set ft=python sts=4 ts=4 sw=4 et:
55

6-
from __future__ import division
7-
from builtins import zip
8-
from builtins import next
9-
from builtins import range
6+
from __future__ import print_function, division, unicode_literals, absolute_import
7+
from builtins import zip, next, range, str
108

119
from ....pipeline import engine as pe
1210
from ....interfaces import utility as niu
@@ -501,7 +499,7 @@ def rotate_bvecs(in_bvec, in_matrix):
501499
newbvec = invrot.dot(bvec)
502500
new_bvecs.append((newbvec / np.linalg.norm(newbvec)))
503501

504-
np.savetxt(out_file, np.array(new_bvecs).T, fmt='%0.15f')
502+
np.savetxt(out_file, np.array(new_bvecs).T, fmt=str('%0.15f').encode())
505503
return out_file
506504

507505

@@ -551,7 +549,7 @@ def eddy_rotate_bvecs(in_bvec, eddy_params):
551549
newbvec = invrot.dot(bvec)
552550
new_bvecs.append(newbvec / np.linalg.norm(newbvec))
553551

554-
np.savetxt(out_file, np.array(new_bvecs).T, fmt='%0.15f')
552+
np.savetxt(out_file, np.array(new_bvecs).T, fmt=str('%0.15f').encode())
555553
return out_file
556554

557555

@@ -713,7 +711,7 @@ def reorient_bvecs(in_dwi, old_dwi, in_bvec):
713711
R = RS / S
714712

715713
new_bvecs = [R.dot(b) for b in bvecs]
716-
np.savetxt(out_file, np.array(new_bvecs).T, fmt='%0.15f')
714+
np.savetxt(out_file, np.array(new_bvecs).T, fmt=str('%0.15f').encode())
717715
return out_file
718716

719717

nipype/workflows/rsfmri/fsl/resting.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# -*- coding: utf-8 -*-
22
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
33
# vi: set ft=python sts=4 ts=4 sw=4 et:
4-
from __future__ import division
4+
from __future__ import print_function, division, unicode_literals, absolute_import
5+
from builtins import str
56

67
from ....interfaces import fsl as fsl # fsl
78
from ....interfaces import utility as util # utility
@@ -35,7 +36,7 @@ def extract_noise_components(realigned_file, noise_mask_file, num_components):
3536
else:
3637
components = np.hstack((components, u[:, :num_components]))
3738
components_file = os.path.join(os.getcwd(), 'noise_components.txt')
38-
np.savetxt(components_file, components, fmt="%.10f")
39+
np.savetxt(components_file, components, fmt=str("%.10f").encode())
3940
return components_file
4041

4142

0 commit comments

Comments
 (0)