Skip to content

Commit

Permalink
Add a function to check if TE values are in ms, otherwise update them (
Browse files Browse the repository at this point in the history
…ME-ICA#1151)

Co-authored-by: Dan Handwerker <[email protected]>
  • Loading branch information
eurunuela and handwerkerd authored Nov 22, 2024
1 parent 7041e95 commit dddf251
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tedana/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,13 @@ def test_millisec2sec():
assert utils.millisec2sec(np.array([5000])) == np.array([5])


def test_check_te_values():
"""Ensure that check_te_values returns the correct values."""
assert utils.check_te_values([2, 3, 4]) == [2, 3, 4]
assert utils.check_te_values([0.15, 0.35, 0.55]) == [150, 350, 550]
# Check that the error is raised when TE values are in different units
with pytest.raises(ValueError):
utils.check_te_values([0.5, 1, 2.5])


# TODO: "BREAK" AND UNIT TESTS
24 changes: 24 additions & 0 deletions tedana/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,3 +634,27 @@ def get_system_version_info():
"Python": sys.version,
"Python_Libraries": python_libraries,
}


def check_te_values(te_values):
"""Check if all TE values are in ms by checking if they are higher than 1.
Parameters
----------
te_values : list
TE values to check.
Returns
-------
list
TE values in milliseconds.
"""
te_values = np.array(te_values)
if all(te_values > 1):
return te_values.tolist()
elif all((te_values > 0) & (te_values < 1)):
# Raise a warning and convert to ms by multiplying by 1000
LGR.warning("Assuming the provided TE values are in seconds. Converting to ms.")
return (te_values * 1000).tolist()
else:
raise ValueError("TE values must be positive and in milliseconds.")
1 change: 1 addition & 0 deletions tedana/workflows/tedana.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ def tedana_workflow(

# ensure tes are in appropriate format
tes = [float(te) for te in tes]
tes = utils.check_te_values(tes)
n_echos = len(tes)

# Coerce gscontrol to list
Expand Down

0 comments on commit dddf251

Please sign in to comment.