Skip to content

Commit

Permalink
STYLE: Fix registration id string creation floating point formatting
Browse files Browse the repository at this point in the history
Fix formatting of numbers that can be floats when creating the
registration id string: when transitioning to f-strings (commit
ac6040f), it was assumed that `sigma` and `grid_resolution` would be
integers, based on the existing formatting. However, these attributes
can be set to non-integer values. The pre-f-string transition solution, e.g.:
```
"(...)_sigma_%03d_grid_%03d" % (subject_idx, iteration_count, sigma, grid_resolution)
```

trimmed the decimal part, and thus, for e.g. `sigma` 7.5 and
`grid_resolution` 1.5, it would produce:
```
'(...)_sigma_007_grid_001'
```

With the introduction of f-strings, i.e.
```
f"(...)_sigma_{sigma:03d}_grid_{grid_resolution:03d}"
```

this would produce an error, since the `sigma` and `grid_resolution`
floating point value cannot be formatted as an integer:
```
{ValueError}ValueError("Unknown format code 'd' for object of type
'float'")
```

This patch set fixes the error by adopting the previous behavior: it
trims the decimal part.

Left behind in commit d7c6bd8.
  • Loading branch information
jhlegarreta committed Jul 6, 2024
1 parent 364c501 commit 1ead182
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions whitematteranalysis/congeal_multisubject.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def congeal_multisubject_inner_loop(mean, subject, initial_transform, mode, sigm
# Set up registration objects and parameters that are specific to affine vs nonrigid
if mode == "Affine" or mode == "Rigid":
register = wma.register_two_subjects.RegisterTractography()
register.process_id_string = f"_subject_{subject_idx:05d}_iteration_{iteration_count:05d}_sigma_{sigma:03d}"
register.process_id_string = f"_subject_{subject_idx:05d}_iteration_{iteration_count:05d}_sigma_{int(sigma):03d}"
if mode == "Rigid":
register.mode = [1, 1, 0, 0]
# Make sure the initial iterations are performed with Cobyla.
Expand All @@ -488,7 +488,7 @@ def congeal_multisubject_inner_loop(mean, subject, initial_transform, mode, sigm
register = wma.register_two_subjects_nonrigid_bsplines.RegisterTractographyNonrigid()
register.nonrigid_grid_resolution = grid_resolution
register.initialize_nonrigid_grid()
register.process_id_string = f"_subject_{subject_idx:05d}_iteration_{iteration_count:05d}_sigma_{sigma:03d}_grid_{grid_resolution:03d}"
register.process_id_string = f"_subject_{subject_idx:05d}_iteration_{iteration_count:05d}_sigma_{int(sigma):03d}_grid_{int(grid_resolution):03d}"

else:
print("ERROR: Unknown registration mode")
Expand Down

0 comments on commit 1ead182

Please sign in to comment.