Skip to content

Commit d686bde

Browse files
committed
fix np.savetxt with format
1 parent c4f1a52 commit d686bde

File tree

8 files changed

+25
-21
lines changed

8 files changed

+25
-21
lines changed

examples/rsfmri_vol_surface_preprocessing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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=str("%.10f").encode())
192+
np.savetxt(filename, out_params2, fmt=b"%.10f")
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=str("%.10f").encode())
240+
np.savetxt(filename, out_params, fmt=b"%.10f")
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=str("%.10f").encode())
289+
np.savetxt(components_file, components, fmt=b"%.10f")
290290
return components_file
291291

292292

examples/rsfmri_vol_surface_preprocessing_nipy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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=str("%.10f").encode())
182+
np.savetxt(filename, out_params2, fmt=b"%.10f")
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=str("%.10f").encode())
227+
np.savetxt(filename, out_params, fmt=b"%.10f")
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=str("%.10f").encode())
272+
np.savetxt(components_file, components, fmt=b"%.10f")
273273
return components_file
274274

275275

nipype/algorithms/modelgen.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
"""
2121
from __future__ import print_function, division, unicode_literals, absolute_import
22-
from builtins import range, str, bytes
22+
from builtins import range, str, bytes, int
2323

2424
from copy import deepcopy
2525
import os
@@ -541,16 +541,20 @@ def _generate_design(self, infolist=None):
541541
outliers = [[]]
542542
for i, filename in enumerate(self.inputs.outlier_files):
543543
try:
544-
out = np.loadtxt(filename, dtype=int)
544+
out = np.loadtxt(filename)
545545
except IOError:
546+
iflogger.warn('Error reading outliers file %s', filename)
546547
out = np.array([])
548+
547549
if out.size > 0:
550+
iflogger.debug('fname=%s, out=%s, nscans=%s', filename, out, repr(sum(nscans[0:i])))
551+
sumscans = out.astype(int) + sum(nscans[0:i])
552+
548553
if out.size == 1:
549-
outliers[0].extend([(np.array(out) +
550-
sum(nscans[0:i])).tolist()])
554+
outliers[0]+= [np.array(sumscans, dtype=int).tolist()]
551555
else:
552-
outliers[0].extend((np.array(out) +
553-
sum(nscans[0:i])).tolist())
556+
outliers[0]+= np.array(sumscans, dtype=int).tolist()
557+
554558
self._sessinfo = self._generate_standard_design(concatlist,
555559
functional_runs=functional_runs,
556560
realignment_parameters=realignment_parameters,

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=str('%d').encode(), delimiter=' ')
472-
np.savetxt(intensityfile, g, fmt=str('%.2f').encode(), delimiter=' ')
471+
np.savetxt(artifactfile, outliers, fmt=b'%d', delimiter=' ')
472+
np.savetxt(intensityfile, g, fmt=b'%.2f', delimiter=' ')
473473
if self.inputs.use_norm:
474-
np.savetxt(normfile, normval, fmt=str('%.4f').encode(), delimiter=' ')
474+
np.savetxt(normfile, normval, fmt=b'%.4f', delimiter=' ')
475475

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

nipype/interfaces/fsl/epi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def _generate_encfile(self):
296296
line = [float(val[0] == encdir[0]) * direction
297297
for val in ['x', 'y', 'z']] + [durations[idx]]
298298
lines.append(line)
299-
np.savetxt(out_file, np.array(lines), fmt=str('%d %d %d %.8f').encode())
299+
np.savetxt(out_file, np.array(lines), fmt=b'%d %d %d %.8f')
300300
return out_file
301301

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

nipype/workflows/dmri/fsl/epi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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=str('%0.15f').encode())
684+
np.savetxt(out_file, np.array(new_bvecs).T, fmt=b'%0.15f')
685685
return out_file
686686

687687

nipype/workflows/dmri/fsl/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ def rotate_bvecs(in_bvec, in_matrix):
499499
newbvec = invrot.dot(bvec)
500500
new_bvecs.append((newbvec / np.linalg.norm(newbvec)))
501501

502-
np.savetxt(out_file, np.array(new_bvecs).T, fmt=str('%0.15f').encode())
502+
np.savetxt(out_file, np.array(new_bvecs).T, fmt=b'%0.15f')
503503
return out_file
504504

505505

@@ -549,7 +549,7 @@ def eddy_rotate_bvecs(in_bvec, eddy_params):
549549
newbvec = invrot.dot(bvec)
550550
new_bvecs.append(newbvec / np.linalg.norm(newbvec))
551551

552-
np.savetxt(out_file, np.array(new_bvecs).T, fmt=str('%0.15f').encode())
552+
np.savetxt(out_file, np.array(new_bvecs).T, fmt=b'%0.15f')
553553
return out_file
554554

555555

@@ -711,7 +711,7 @@ def reorient_bvecs(in_dwi, old_dwi, in_bvec):
711711
R = RS / S
712712

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

717717

nipype/workflows/rsfmri/fsl/resting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def extract_noise_components(realigned_file, noise_mask_file, num_components):
3636
else:
3737
components = np.hstack((components, u[:, :num_components]))
3838
components_file = os.path.join(os.getcwd(), 'noise_components.txt')
39-
np.savetxt(components_file, components, fmt=str("%.10f").encode())
39+
np.savetxt(components_file, components, fmt=b"%.10f")
4040
return components_file
4141

4242

0 commit comments

Comments
 (0)