@@ -153,15 +153,14 @@ def encode_value_in_name(value, name, max_name_len=20):
153
153
`value`, padded with ``\x00 `` bytes.
154
154
"""
155
155
if len (name ) > max_name_len :
156
- msg = ("Data information named '{0 }' is too long"
157
- " (max {1 } characters.)" ). format ( name , max_name_len )
156
+ msg = (f "Data information named '{ name } ' is too long"
157
+ f " (max { max_name_len } characters.)" )
158
158
raise ValueError (msg )
159
159
encoded_name = name if value <= 1 else name + '\x00 ' + str (value )
160
160
if len (encoded_name ) > max_name_len :
161
- msg = ("Data information named '{0}' is too long (need to be less"
162
- " than {1} characters when storing more than one value"
163
- " for a given data information."
164
- ).format (name , max_name_len - (len (str (value )) + 1 ))
161
+ msg = (f"Data information named '{ name } ' is too long (need to be less"
162
+ f" than { max_name_len - (len (str (value )) + 1 )} characters "
163
+ f"when storing more than one value for a given data information." )
165
164
raise ValueError (msg )
166
165
# Fill to the end with zeros
167
166
return encoded_name .ljust (max_name_len , '\x00 ' ).encode ('latin1' )
@@ -196,8 +195,8 @@ def decode_value_from_name(encoded_name):
196
195
value = int (splits [1 ]) # Decode value.
197
196
elif len (splits ) > 2 :
198
197
# The remaining bytes are not \x00, raising.
199
- msg = ("Wrong scalar_name or property_name: '{0 }'."
200
- " Unused characters should be \\ x00." ). format ( encoded_name )
198
+ msg = (f "Wrong scalar_name or property_name: '{ encoded_name } '."
199
+ f " Unused characters should be \\ x00." )
201
200
raise HeaderError (msg )
202
201
203
202
return name , value
@@ -473,9 +472,9 @@ def save(self, fileobj):
473
472
# Update field 'property_name' using 'data_per_streamline'.
474
473
data_for_streamline = first_item .data_for_streamline
475
474
if len (data_for_streamline ) > MAX_NB_NAMED_PROPERTIES_PER_STREAMLINE :
476
- msg = ("Can only store {0 } named data_per_streamline (also "
477
- " known as 'properties' in the TRK format). "
478
- ). format ( MAX_NB_NAMED_SCALARS_PER_POINT )
475
+ msg = (f "Can only store { MAX_NB_NAMED_SCALARS_PER_POINT } named "
476
+ f"data_per_streamline (also known as 'properties' in the "
477
+ f"TRK format)." )
479
478
raise ValueError (msg )
480
479
481
480
data_for_streamline_keys = sorted (data_for_streamline .keys ())
@@ -491,9 +490,9 @@ def save(self, fileobj):
491
490
# Update field 'scalar_name' using 'tractogram.data_per_point'.
492
491
data_for_points = first_item .data_for_points
493
492
if len (data_for_points ) > MAX_NB_NAMED_SCALARS_PER_POINT :
494
- msg = ("Can only store {0} named data_per_point (also known "
495
- " as 'scalars' in the TRK format). "
496
- ). format ( MAX_NB_NAMED_SCALARS_PER_POINT )
493
+ msg = (f "Can only store { MAX_NB_NAMED_SCALARS_PER_POINT } "
494
+ f"named data_per_point (also known as 'scalars' in "
495
+ f"the TRK format)." )
497
496
raise ValueError (msg )
498
497
499
498
data_for_points_keys = sorted (data_for_points .keys ())
@@ -588,9 +587,9 @@ def _read_header(fileobj):
588
587
# Swap byte order
589
588
header_rec = header_rec .newbyteorder ()
590
589
if header_rec ['hdr_size' ] != TrkFile .HEADER_SIZE :
591
- msg = "Invalid hdr_size: {0} instead of {1} "
592
- raise HeaderError ( msg . format ( header_rec [ 'hdr_size' ],
593
- TrkFile . HEADER_SIZE ) )
590
+ msg = ( f "Invalid hdr_size: { header_rec [ 'hdr_size' ] } "
591
+ f"instead of { TrkFile . HEADER_SIZE } " )
592
+ raise HeaderError ( msg )
594
593
595
594
if header_rec ['version' ] == 1 :
596
595
# There is no 4x4 matrix for voxel to RAS transformation.
@@ -616,9 +615,9 @@ def _read_header(fileobj):
616
615
# able to determine the axis directions.
617
616
axcodes = aff2axcodes (header [Field .VOXEL_TO_RASMM ])
618
617
if None in axcodes :
619
- msg = ("The 'vox_to_ras' affine is invalid! Could not"
620
- " determine the axis directions from it.\n {0} "
621
- ). format ( header [Field .VOXEL_TO_RASMM ])
618
+ msg = (f "The 'vox_to_ras' affine is invalid! Could not"
619
+ f " determine the axis directions from it.\n "
620
+ f" { header [Field .VOXEL_TO_RASMM ]} " )
622
621
raise HeaderError (msg )
623
622
624
623
# By default, the voxel order is LPS.
0 commit comments