Skip to content

Commit

Permalink
Merge pull request #19 from 36000/scalar_name_fix
Browse files Browse the repository at this point in the history
[FIX] smarter automatic scalar names
  • Loading branch information
arokem authored Nov 13, 2024
2 parents bb622a6 + aa6470a commit 228d77b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
9 changes: 6 additions & 3 deletions AFQ/definitions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@ def _arglist_to_string(args, get_attr=None):
def name_from_path(path):
file_name = op.basename(path) # get file name
file_name = drop_extension(file_name) # remove extension
if "-" in file_name:
file_name = file_name.split("-")[-1] # get suffix if exists
return file_name
if "desc-" in file_name: # get desc if exists
return file_name.split("desc-")[-1].split("_")[0]
elif "_" in file_name:
return file_name.split("_")[-1] # get suffix if exists
else:
return file_name


def _ff_helper(required, err_msg):
Expand Down
10 changes: 10 additions & 0 deletions AFQ/tests/test_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from AFQ.definitions.image import * # interprets images from eval
from AFQ.definitions.mapping import * # interprets mappings from eval
from AFQ.tests.test_api import create_dummy_bids_path
from AFQ.definitions.utils import name_from_path


def test_str_instantiates_mixin():
Expand All @@ -23,6 +24,15 @@ def test_str_instantiates_mixin():
thresh_image_from_str.upper_bound)


def test_name_from_path():
path = "/data/sub-01/ses-01/dwi/sub-01_ses-01_desc-icvf_dwi.nii.gz"
assert name_from_path(path) == "icvf"
path = "/data/sub-01/ses-01/dwi/sub-01_ses-01_desc-od_dwi.nii.gz"
assert name_from_path(path) == "od"
path = "/data/sub-01/ses-01/anat/sub-01_ses-01_T1w.nii.gz"
assert name_from_path(path) == "T1w"


def test_resample_image():
image_data = np.zeros((2, 2, 2), dtype=bool)
image_data[0] = True
Expand Down

0 comments on commit 228d77b

Please sign in to comment.