Skip to content

Commit 4f94438

Browse files
oestebanmgxd
andcommitted
enh: use regex to parse suffix (@mgxd's suggestion)
Co-authored-by: Mathias Goncalves <[email protected]>
1 parent a882d6c commit 4f94438

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

sdcflows/fieldmaps.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Utilities for fieldmap estimation."""
22
from pathlib import Path
33
from enum import Enum, auto
4+
import re
45
import attr
56
from json import loads
67
from bids.layout import BIDSFile, parse_file_entities
@@ -171,7 +172,7 @@ def check_path(self, attribute, value):
171172
if not str(value).endswith((".nii", ".nii.gz")):
172173
raise ValueError(f"File path <{value}> does not look like a NIfTI file.")
173174

174-
suffix = str(value).rpartition(".nii")[0].rpartition("_")[-1]
175+
suffix = re.search(r"(?<=_)\w+(?=\.nii)", value.name).group()
175176
if suffix not in tuple(MODALITIES.keys()):
176177
raise ValueError(
177178
f"File path <{value}> with suffix <{suffix}> is not a valid "

0 commit comments

Comments
 (0)