@@ -153,15 +153,14 @@ def encode_value_in_name(value, name, max_name_len=20):
153153 `value`, padded with ``\x00 `` bytes.
154154 """
155155 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.)" )
158158 raise ValueError (msg )
159159 encoded_name = name if value <= 1 else name + '\x00 ' + str (value )
160160 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." )
165164 raise ValueError (msg )
166165 # Fill to the end with zeros
167166 return encoded_name .ljust (max_name_len , '\x00 ' ).encode ('latin1' )
@@ -196,8 +195,8 @@ def decode_value_from_name(encoded_name):
196195 value = int (splits [1 ]) # Decode value.
197196 elif len (splits ) > 2 :
198197 # 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." )
201200 raise HeaderError (msg )
202201
203202 return name , value
@@ -473,9 +472,9 @@ def save(self, fileobj):
473472 # Update field 'property_name' using 'data_per_streamline'.
474473 data_for_streamline = first_item .data_for_streamline
475474 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)." )
479478 raise ValueError (msg )
480479
481480 data_for_streamline_keys = sorted (data_for_streamline .keys ())
@@ -491,9 +490,9 @@ def save(self, fileobj):
491490 # Update field 'scalar_name' using 'tractogram.data_per_point'.
492491 data_for_points = first_item .data_for_points
493492 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)." )
497496 raise ValueError (msg )
498497
499498 data_for_points_keys = sorted (data_for_points .keys ())
@@ -588,9 +587,9 @@ def _read_header(fileobj):
588587 # Swap byte order
589588 header_rec = header_rec .newbyteorder ()
590589 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 )
594593
595594 if header_rec ['version' ] == 1 :
596595 # There is no 4x4 matrix for voxel to RAS transformation.
@@ -616,9 +615,9 @@ def _read_header(fileobj):
616615 # able to determine the axis directions.
617616 axcodes = aff2axcodes (header [Field .VOXEL_TO_RASMM ])
618617 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 ]} " )
622621 raise HeaderError (msg )
623622
624623 # By default, the voxel order is LPS.
0 commit comments