Skip to content

Commit 41c80c4

Browse files
authored
Remove non-alphanumeric characters from variant values (#443)
Update utils.py
1 parent 38c3ac2 commit 41c80c4

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

cubids/utils.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55

66
import json
7+
import re
78
from pathlib import Path
89

910
import numpy as np
@@ -901,8 +902,9 @@ def assign_variants(summary, rename_cols):
901902
Notes
902903
-----
903904
Variant names are constructed using the following rules:
904-
1. Basic parameters use their actual values (e.g., VARIANTFlipAngle75)
905-
2. Clustered parameters use their cluster numbers (e.g., VARIANTEchoTime2)
905+
1. Basic parameters use their actual values (e.g., VARIANTFlipAngle75),
906+
with non-alphanumeric characters removed.
907+
2. Clustered parameters use their cluster numbers prefixed with "C" (e.g., VARIANTEchoTimeC2)
906908
3. Special parameters like HasFieldmap use predefined strings (e.g., VARIANTNoFmap)
907909
4. Multiple parameters are concatenated (e.g., VARIANTEchoTime2FlipAngle75)
908910
"""
@@ -972,6 +974,13 @@ def assign_variants(summary, rename_cols):
972974
# If the value is an actual float
973975
elif isinstance(val, float):
974976
val = str(val).replace(".", "p")
977+
if val.endswith("p0"):
978+
# Remove the trailing "p0"
979+
val = val[:-2]
980+
981+
# Filter out non-alphanumeric characters
982+
val = re.sub(r"[^a-zA-Z0-9]", "", val)
983+
975984
acq_str += f"{col}{val}"
976985

977986
if acq_str == "VARIANT":

0 commit comments

Comments
 (0)