From ddc72281cf7874f7af4489c5194699f8d8e31e98 Mon Sep 17 00:00:00 2001 From: ChengranAA Date: Sun, 10 Dec 2023 08:32:39 +0100 Subject: [PATCH 1/2] update method for reading affine and slice timing arrays --- bvbabel/fmr.py | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/bvbabel/fmr.py b/bvbabel/fmr.py index 85c57b6..8fcd0a3 100644 --- a/bvbabel/fmr.py +++ b/bvbabel/fmr.py @@ -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='\n').reshape(4, 4) + info_tra["Transformation matrix"] = affine_matrix # ----------------------------------------------------------------- # This part only contains a single information elif content[0] == "LeftRightConvention": @@ -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": From ab51891cf5043210b750960b9ed8974b27eb3a53 Mon Sep 17 00:00:00 2001 From: ChengranAA Date: Sun, 10 Dec 2023 08:42:26 +0100 Subject: [PATCH 2/2] minor fix method for reading affine array --- bvbabel/fmr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bvbabel/fmr.py b/bvbabel/fmr.py index 8fcd0a3..625acb7 100644 --- a/bvbabel/fmr.py +++ b/bvbabel/fmr.py @@ -196,7 +196,7 @@ def read_fmr(filename, rearrange_data_axes=True): info_tra[content[0]] = content[1] elif content[0] == "NrOfTransformationValues": info_tra[content[0]] = content[1] - affine_matrix = np.fromstring(''.join(lines[j + 1 : j + 1 + (int(content[1]) + 3) // 4 ]), sep='\n').reshape(4, 4) + 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