Skip to content

Commit

Permalink
use non linear alignment as default
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Gau committed Aug 12, 2024
1 parent 391274b commit 9255c10
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ prepare: tests/data/moae_fmriprep ## demo: prepares the data of MOAE dataset
prepare \
-vv \
--reset_database \
--non_linear_coreg
--linear_coreg

generalize: ## demo: predicts labels of MOAE dataset
bidsmreye $$PWD/tests/data/moae_fmriprep \
Expand Down
2 changes: 1 addition & 1 deletion bidsmreye/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def cli(argv: Any = sys.argv) -> None:
model_weights_file=model_weights_file,
reset_database=args.reset_database,
bids_filter_file=args.bids_filter_file,
non_linear_coreg=bool(getattr(args, "non_linear_coreg", False)),
linear_coreg=bool(getattr(args, "linear_coreg", False)),
log_level_name=log_level_name,
force=bool(getattr(args, "force", False)),
)
Expand Down
15 changes: 10 additions & 5 deletions bidsmreye/_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,13 @@ def common_parser(formatter_class: type[HelpFormatter] = HelpFormatter) -> Argum
prepare_parser = _add_common_arguments(prepare_parser)
# TODO make it possible to pass path to a model ?
prepare_parser.add_argument(
"--non_linear_coreg",
"--linear_coreg",
help="""
Uses a more aggressive (and non-linear) alignment procedure
to the deepmreye template.""",
Uses a less aggressive (and linear) alignment procedure
to the deepmreye template.
May lead to worse results so check your outputs.
""",
action="store_true",
)

Expand Down Expand Up @@ -190,10 +193,12 @@ def common_parser(formatter_class: type[HelpFormatter] = HelpFormatter) -> Argum
all_parser = _add_common_arguments(all_parser)
# TODO make it possible to pass path to a model ?
all_parser.add_argument(
"--non_linear_coreg",
"--linear_coreg",
help="""
Uses a more aggressive (and non-linear) alignment procedure
Uses a less aggressive (and linear) alignment procedure
to the deepmreye template.
May lead to worse results so check your outputs.
""",
action="store_true",
)
Expand Down
4 changes: 2 additions & 2 deletions bidsmreye/bidsmreye.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def bidsmreye(
model_weights_file: str | None = None,
reset_database: bool | None = None,
bids_filter_file: str | None = None,
non_linear_coreg: bool = False,
linear_coreg: bool = False,
log_level_name: str | None = None,
force: bool = False,
) -> None:
Expand All @@ -50,7 +50,7 @@ def bidsmreye(
model_weights_file=model_weights_file,
reset_database=reset_database,
bids_filter=bids_filter,
non_linear_coreg=non_linear_coreg,
linear_coreg=linear_coreg,
force=force,
) # type: ignore

Expand Down
2 changes: 1 addition & 1 deletion bidsmreye/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _check_input_dir(self, attribute: str, value: Path) -> None:

debug: str | bool | None = field(kw_only=True, default=None)
reset_database: bool = field(kw_only=True, default=False)
non_linear_coreg: bool = field(kw_only=True, default=False)
linear_coreg: bool = field(kw_only=True, default=False)
force: bool = field(kw_only=True, default=False)

has_GPU: bool = False
Expand Down
10 changes: 5 additions & 5 deletions bidsmreye/prepare_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
log = bidsmreye_log(name="bidsmreye")


def coregister_and_extract_data(img: str, non_linear_coreg: bool = False) -> None:
def coregister_and_extract_data(img: str, linear_coreg: bool = False) -> None:
"""Coregister image to eye template and extract data from eye mask for one image.
:param img: Image to coregister and extract data from
Expand All @@ -49,7 +49,7 @@ def coregister_and_extract_data(img: str, non_linear_coreg: bool = False) -> Non
z_edges,
) = preprocess.get_masks()

transforms = ["Affine", "Affine", "SyNAggro"] if non_linear_coreg else None
transforms = None if linear_coreg else ["Affine", "Affine", "SyNAggro"]

Check warning on line 52 in bidsmreye/prepare_data.py

View check run for this annotation

Codecov / codecov/patch

bidsmreye/prepare_data.py#L52

Added line #L52 was not covered by tests

preprocess.run_participant(
img,
Expand Down Expand Up @@ -168,7 +168,7 @@ def prepapre_image(

log.info(f"Processing file: {Path(img_path).name}")

coregister_and_extract_data(img_path, non_linear_coreg=cfg.non_linear_coreg)
coregister_and_extract_data(img_path, linear_coreg=cfg.linear_coreg)

Check warning on line 171 in bidsmreye/prepare_data.py

View check run for this annotation

Codecov / codecov/patch

bidsmreye/prepare_data.py#L171

Added line #L171 was not covered by tests

deepmreye_mask_report = get_deepmreye_filename(
layout_in, img=img_path, filetype="report"
Expand Down Expand Up @@ -205,8 +205,8 @@ def prepare_data(cfg: Config) -> None:
subjects = list_subjects(cfg, layout_in)

text = "PREPARING DATA"
if cfg.non_linear_coreg:
log.info("Using non-linear coregistration")
if cfg.linear_coreg:
log.info("Using linear coregistration")

Check warning on line 209 in bidsmreye/prepare_data.py

View check run for this annotation

Codecov / codecov/patch

bidsmreye/prepare_data.py#L208-L209

Added lines #L208 - L209 were not covered by tests

with progress_bar(text=text) as progress:
subject_loop = progress.add_task(
Expand Down
18 changes: 8 additions & 10 deletions boutiques/bidsmreye_0.4.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "bids app using deepMReye to decode eye motion for fMRI time series data",
"tool-version": "0.4.0",
"schema-version": "0.5",
"command-line": "bidsmreye [VERSION] [BIDS_DIR] [OUTPUT_DIR] [ANALYSIS_LEVEL] [COMMAND] [PARTICIPANT_LABEL] [TASK] [RUN] [SPACE] [LOG_LEVEL] [DEBUG] [RESET_DATABASE] [BIDS_FILTER_FILE] [FORCE] [NON_LINEAR_COREG] [MODEL]",
"command-line": "bidsmreye [VERSION] [BIDS_DIR] [OUTPUT_DIR] [ANALYSIS_LEVEL] [COMMAND] [PARTICIPANT_LABEL] [TASK] [RUN] [SPACE] [LOG_LEVEL] [DEBUG] [RESET_DATABASE] [BIDS_FILTER_FILE] [FORCE] [LINEAR_COREG] [MODEL]",
"inputs": [
{
"name": "version",
Expand Down Expand Up @@ -132,13 +132,13 @@
"value-key": "[FORCE]"
},
{
"name": "non_linear_coreg",
"id": "non_linear_coreg",
"description": "Uses a more aggressive (and non-linear) alignment procedure to the deepmreye template.",
"name": "linear_coreg",
"id": "linear_coreg",
"description": "Uses a less aggressive (linear) alignment procedure to the deepmreye template.",
"type": "Flag",
"optional": true,
"command-line-flag": "--non_linear_coreg",
"value-key": "[NON_LINEAR_COREG]"
"command-line-flag": "--linear_coreg",
"value-key": "[LINEAR_COREG]"
},
{
"name": "model",
Expand Down Expand Up @@ -187,7 +187,7 @@
"reset_database",
"debug",
"force",
"non_linear_coreg",
"linear_coreg",
"log_level",
"run",
"space",
Expand All @@ -199,7 +199,6 @@
"reset_database",
"debug",
"force",
"non_linear_coreg",
"log_level",
"model",
"run",
Expand All @@ -212,13 +211,12 @@
"reset_database",
"debug",
"force",
"non_linear_coreg",
"linear_coreg",
"log_level",
"model",
"run",
"space",
"bids_filter_file",
"participant_label",
"task"
]
}
Expand Down
2 changes: 1 addition & 1 deletion boutiques/invocation.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"debug": false,
"reset_database": true,
"force": false,
"non_linear_coreg": true,
"linear_coreg": true,
"model": "1_guided_fixations"
}
2 changes: 1 addition & 1 deletion tests/data/derivatives/bidsmreye/dataset_description.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
},
"debug": false,
"reset_database": false,
"non_linear_coreg": false
"linear_coreg": false
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_Config(data_dir, pybids_test_dataset):
data_dir,
)
assert not cfg.debug
assert not cfg.non_linear_coreg
assert not cfg.linear_coreg
assert cfg.input_dir == pybids_test_dataset
assert cfg.output_dir == data_dir / "bidsmreye"
assert sorted(cfg.subjects) == ["01", "02", "03", "04", "05"]
Expand Down
6 changes: 3 additions & 3 deletions tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def test_parser() -> None:
"--task",
"foo",
"bar",
"--non_linear_coreg",
"--linear_coreg",
]
)

assert args.task == ["foo", "bar"]
assert args.non_linear_coreg
assert args.linear_coreg


def test_parser_basic() -> None:
Expand All @@ -43,7 +43,7 @@ def test_parser_basic() -> None:
)

assert args.task == ["foo", "bar"]
assert args.non_linear_coreg is False
assert args.linear_coreg is False


def test_download_parser():
Expand Down
2 changes: 1 addition & 1 deletion tools/create_boutiques_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"$PWD/outputs/moae_fmriprep/derivatives "
"participant "
"all "
"--reset_database --non_linear_coreg --model 1_guided_fixations -vv"
"--reset_database --linear_coreg --model 1_guided_fixations -vv"
)
cmd = cmd.split(" ")

Expand Down

0 comments on commit 9255c10

Please sign in to comment.