Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrix reader for affine and slice timings in fmr.py using numpy.fromstring method #48

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 3 additions & 27 deletions bvbabel/fmr.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,24 +196,8 @@ def read_fmr(filename, rearrange_data_axes=True):
info_tra[content[0]] = content[1]
elif content[0] == "NrOfTransformationValues":
info_tra[content[0]] = content[1]

# NOTE(Faruk): I dont like this matrix reader but I don't see a
# more elegant way for now.
nr_values = int(content[1])
affine = []
v = 0 # Counter for values
n = 1 # Counter for lines
while v < nr_values:
line = lines[j + n]
content = line.strip()
content = content.split()
for val in content:
affine.append(float(val))
v += len(content) # Count values
n += 1 # Iterate line
affine = np.reshape(np.asarray(affine), (4, 4))
info_tra["Transformation matrix"] = affine

affine_matrix = np.fromstring(' '.join(lines[j + 1 : j + 1 + (int(content[1]) + 3) // 4 ]), sep=' ').reshape(4, 4)
info_tra["Transformation matrix"] = affine_matrix
# -----------------------------------------------------------------
# This part only contains a single information
elif content[0] == "LeftRightConvention":
Expand All @@ -229,15 +213,7 @@ def read_fmr(filename, rearrange_data_axes=True):
info_multiband[content[0]] = content[1]
elif content[0] == "SliceTimingTableSize":
info_multiband[content[0]] = int(content[1])

# NOTE(Faruk): I dont like this matrix reader but I don't see a
# more elegant way for now.
nr_values = int(content[1])
slice_timings = []
for n in range(1, nr_values+1):
line = lines[j + n]
content = line.strip()
slice_timings.append(float(content))
slice_timings = np.ndarray.tolist(np.fromstring(''.join(lines[j + 1 : j + 1 + int(content[1])]), sep='\n'))
info_multiband["Slice timings"] = slice_timings

elif content[0] == "AcqusitionTime":
Expand Down