Skip to content

Commit 1df9501

Browse files
committed
PEP8
1 parent 7a5532f commit 1df9501

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

nibabel/streamlines/tck.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,14 @@ def save(self, fileobj):
206206

207207
for t in tractogram:
208208
s = t.streamline.astype(dtype)
209-
f.write(asbytes(np.r_[s.astype('<f4'), self.FIBER_DELIMITER].tostring()))
209+
f.write(asbytes(np.r_[s.astype('<f4'),
210+
self.FIBER_DELIMITER].tostring()))
210211
nb_streamlines += 1
211212

212-
# Add the EOF_DELIMITER.
213-
f.write(asbytes(self.EOF_DELIMITER.tostring()))
214-
215213
header[Field.NB_STREAMLINES] = nb_streamlines
216214

217-
## Overwrite the streamlines count in the header.
218-
#self.file.seek(self.count_offset, os.SEEK_SET)
219-
#self.file.write(asbytes("count: {0:010}\n".format(self.header[Field.NB_STREAMLINES])))
215+
# Add the EOF_DELIMITER.
216+
f.write(asbytes(self.EOF_DELIMITER.tostring()))
220217

221218
# Overwrite header with updated one.
222219
f.seek(beginning, os.SEEK_SET)
@@ -233,26 +230,29 @@ def _write_header(fileobj, header):
233230
from the beginning of the TCK header).
234231
"""
235232
# Fields to exclude
236-
exclude = [Field.MAGIC_NUMBER, Field.NB_STREAMLINES, "datatype", "file"]
233+
exclude = [Field.MAGIC_NUMBER, Field.NB_STREAMLINES,
234+
"datatype", "file"]
237235

238236
lines = []
239237
lines.append(header[Field.MAGIC_NUMBER])
240238
lines.append("count: {0:010}".format(header[Field.NB_STREAMLINES]))
241-
lines.append("datatype: Float32LE") # We always use Float32LE to save TCK files.
242-
lines.extend(["{0}: {1}".format(k, v) for k, v in header.items() if k not in exclude])
239+
lines.append("datatype: Float32LE") # Always Float32LE.
240+
lines.extend(["{0}: {1}".format(k, v)
241+
for k, v in header.items() if k not in exclude])
243242
lines.append("file: . ") # Manually add this last field.
244243
out = "\n".join((asstr(line).replace('\n', '\t') for line in lines))
245244
fileobj.write(asbytes(out))
246245

247-
# Compute offset to the beginning of the binary data
248-
tentative_offset = len(out) + 5 # +5 is for "\nEND\n" added just before the data.
246+
# Compute offset to the beginning of the binary data.
247+
# We add 5 for "\nEND\n" that will be added just before the data.
248+
tentative_offset = len(out) + 5
249249

250-
# Take in account the number of characters needed to write 'offset' in ASCII.
250+
# Count the number of characters needed to write the offset in ASCII.
251251
offset = tentative_offset + len(str(tentative_offset))
252252

253-
# Corner case: the new 'offset' needs one more character to write it in ASCII
253+
# The new offset might need one more character to write it in ASCII.
254254
# e.g. offset = 98 (i.e. 2 char.), so offset += 2 = 100 (i.e. 3 char.)
255-
# thus the final offset = 101.
255+
# thus the final offset = 101.
256256
if len(str(tentative_offset)) != len(str(offset)):
257257
offset += 1 # +1, we need one more character for that new digit.
258258

0 commit comments

Comments
 (0)