Skip to content

Commit

Permalink
--tedpca option: Forbid floating-point value of 1.0
Browse files Browse the repository at this point in the history
Partial reversion of 55aee07 as discussed in #1066.
These changes forbid the request to preserve 100% of variance by specifying "--tedpca 1.0"; it is intended to in the future facilitate this sort of operation through other means.
  • Loading branch information
Lestropie committed Apr 16, 2024
1 parent ba79dce commit 5fa9cb3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion tedana/decomposition/pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def tedpca(
(stationary Gaussian) process and are ordered from most to least aggressive
(see :footcite:p:`li2007estimating`).
If a float is provided, then it is assumed to represent percentage of variance
explained (0.0-1.0] to retain from PCA.
explained (0.0-1.0) to retain from PCA.
If an int is provided, then it is assumed to be the number of components
to select
Default is 'aic'.
Expand Down
18 changes: 10 additions & 8 deletions tedana/tests/test_workflows_parser_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ def test_check_tedpca_value():
check_tedpca_value("hello", is_parser=False)

with pytest.raises(argparse.ArgumentTypeError):
check_tedpca_value("1.5", is_parser=True)
check_tedpca_value("1.0", is_parser=True)

with pytest.raises(argparse.ArgumentTypeError):
check_tedpca_value("1.", is_parser=True)

with pytest.raises(ValueError):
check_tedpca_value(1.5, is_parser=False)
check_tedpca_value(1.0, is_parser=False)

with pytest.raises(argparse.ArgumentTypeError):
check_tedpca_value("0.0", is_parser=True)

with pytest.raises(ValueError):
check_tedpca_value(0.0, is_parser=False)
Expand All @@ -30,13 +36,9 @@ def test_check_tedpca_value():
with pytest.raises(ValueError):
check_tedpca_value(0, is_parser=False)

assert check_tedpca_value(0.95) == 0.95
assert check_tedpca_value(0.95, is_parser=False) == 0.95
assert check_tedpca_value("0.95") == 0.95
assert check_tedpca_value("mdl") == "mdl"
assert check_tedpca_value(52) == 52

assert check_tedpca_value(1, is_parser=False) == 1
assert check_tedpca_value(1.0, is_parser=False) == 1.0
assert check_tedpca_value("1.0") == 1.0
assert check_tedpca_value("1.") == 1.0
assert check_tedpca_value("1") == 1
assert check_tedpca_value(52, is_parser=False) == 52
6 changes: 3 additions & 3 deletions tedana/workflows/parser_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def check_tedpca_value(value, is_parser=True):

def check_float(floatvalue):
assert isinstance(floatvalue, float)
if not (0.0 < floatvalue <= 1.0):
msg = f"Floating-point argument to {dashes}tedpca must be in the range (0.0, 1.0]."
if not (0.0 < floatvalue < 1.0):
msg = f"Floating-point argument to {dashes}tedpca must be in the range (0.0, 1.0)."
raise error(msg)
return floatvalue

Expand All @@ -40,7 +40,7 @@ def check_int(intvalue):
try:
floatvalue = float(value)
except ValueError:
msg = f"Argument to {dashes}tedpca must be a number or one of: {', '.join(valid_options)}"
msg = f"Argument to {dashes}tedpca must be either a number, or one of: {', '.join(valid_options)}"
raise error(msg)

try:
Expand Down
6 changes: 3 additions & 3 deletions tedana/workflows/tedana.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def _get_parser():
"Method by which to select number of components in TEDPCA. "
"This can be one of the following: "
"String ('mdl', 'kic', 'aic', 'kundu', or 'kundu-stabilize'); "
"floating-point value (in the range (0.0, 1.0]); "
"floating-point value in the range (0.0, 1.0); "
"positive integer value. "
"PCA decomposition with the mdl, kic and aic options "
"are based on a Moving Average (stationary Gaussian) process, "
Expand Down Expand Up @@ -405,7 +405,7 @@ def tedana_workflow(
tedpca : {'mdl', 'aic', 'kic', 'kundu', 'kundu-stabilize', float, int}, optional
Method with which to select components in TEDPCA.
If a float is provided, then it is assumed to represent percentage of variance
explained (0.0-1.0] to retain from PCA. If an int is provided, it will output
explained (0.0-1.0) to retain from PCA. If an int is provided, it will output
a fixed number of components defined by the integer; must be between 1 and the
number of time points.
Default is 'aic'.
Expand Down Expand Up @@ -512,7 +512,7 @@ def tedana_workflow(
gscontrol = [gscontrol]

# Check value of tedpca *if* it is a predefined string,
# a float in (0.0, 1.0] or an int >= 1
# a float in (0.0, 1.0) or an int >= 1
tedpca = check_tedpca_value(tedpca, is_parser=False)

# For z-catted files, make sure it's a list of size 1
Expand Down

0 comments on commit 5fa9cb3

Please sign in to comment.