Skip to content

Commit

Permalink
[ENH] use non-linear alignment as default (#234)
Browse files Browse the repository at this point in the history
* use non linear alignment as default

* update changelog

* fix misc
  • Loading branch information
Remi-Gau authored Aug 12, 2024
1 parent 391274b commit a4a98f9
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 80 deletions.
4 changes: 3 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ workflows:
- DOCKER_HUB
requires:
- test

filters:
tags:
only: /.*/


# VS Code Extension Version: 1.5.1
34 changes: 4 additions & 30 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,26 @@ on:
tags:
- '*'

defaults:
run:
shell: bash

jobs:
package:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')

# Build packages and upload
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
python-version: '3.11'

runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- name: Set up Python ${{ matrix.python-version }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

python-version: 3.11
- name: Display Python version
run: python -c "import sys; print(sys.version)"

- name: Install build
run: python -m pip install build

- name: Build sdist and wheel
run: python -m build

- name: Test PyPI upload
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
skip_existing: true

- name: Upload to PyPI (on tags)
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test_and_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
matrix:
os: [ubuntu-latest, macOS-latest] # windows-latest: do not work. antspyx is not available for windows
python-version: ['3.9', '3.10', '3.11']
exclude:
- os: macOS-latest # anstpyx install is messed up with macOS and python 3.9
python-version: '3.9'
# exclude:
# - os: macOS-latest # anstpyx install is messed up with macOS and python 3.9
# python-version: '3.9'
fail-fast: false

steps:
Expand Down
7 changes: 3 additions & 4 deletions .sourcery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ ignore: # A list of paths or files which Sourcery will ignore.
- .tox
- node_modules
- vendor
- vendor
- bidsmreye/_version.py

rule_settings:
Expand All @@ -32,7 +31,7 @@ rule_settings:
- refactoring
- suggestion
- comment
python_version: '3.8' # A string specifying the lowest Python version your project supports. Sourcery will not suggest refactorings requiring a higher Python version.
python_version: '3.9'

# rules: # A list of custom rules Sourcery will include in its analysis.
# - id: no-print-statements
Expand All @@ -52,8 +51,8 @@ rule_settings:

# rule_tags: {} # Additional rule tags.

# metrics:
# quality_threshold: 25.0
metrics:
quality_threshold: 25.0

# github:
# labels: []
Expand Down
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,20 @@ clean-test: ## remove test and coverage artifacts
rm -fr htmlcov/
rm -fr .pytest_cache


## INSTALL

install_dev: clean ## install the package and development dependencies to the active Python's site-packages
pip install -e .[dev]
make models

release: dist ## package and upload a release
twine upload dist/*

dist: clean ## builds source and wheel package
python -m build
ls -l dist

release: dist ## package and upload a release
twine upload dist/*


## PRE-TRAINED MODELS
.PHONY: models
Expand All @@ -83,6 +84,7 @@ models/dataset4_pursuit.h5:
models/dataset5_free_viewing.h5:
bidsmreye_model --model 5_free_viewing


## DOC
.PHONY: docs docs/source/FAQ.md

Expand Down Expand Up @@ -129,7 +131,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"]

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)

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")

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"
}
13 changes: 6 additions & 7 deletions docs/source/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* [ENH] Extra metadata have been added to the output of the `generalize` step to better align with BIDS BEP20 @Remi-Gau in https://github.com/cpp-lln-lab/bidsMReye/pull/232
* [ENH] Extra metadata have been added to the output of the `generalize` step to better align with BIDS BEP20 by @Remi-Gau in https://github.com/cpp-lln-lab/bidsMReye/pull/232

### Changed

* [ENH] Output filenames of the prepare step has been changed to use the `timeseries` suffix and the output of the `generalize` step now include the name of the Deepmreye model used to compute them @Remi-Gau in https://github.com/cpp-lln-lab/bidsMReye/pull/232
* [ENH] Output filenames of the prepare step has been changed to use the `timeseries` suffix and the output of the `generalize` step now include the name of the Deepmreye model used to compute them by @Remi-Gau in https://github.com/cpp-lln-lab/bidsMReye/pull/232

### Deprecated
* [ENH] use non-linear alignment as default by @Remi-Gau in https://github.com/cpp-lln-lab/bidsMReye/pull/234

### Removed

### Fixed

* [FIX] do not apply run found for one task to all tasks by @Remi-Gau in https://github.com/cpp-lln-lab/bidsMReye/pull/228
* [ENH] the `--non_linear_coreg` CLI argument was replaced by the `--linear_coreg` by @Remi-Gau in https://github.com/cpp-lln-lab/bidsMReye/pull/234

### Security
### Fixed

* [FIX] do not apply `run` found for one task to all tasks by @Remi-Gau in https://github.com/cpp-lln-lab/bidsMReye/pull/228

## [0.4.0] - 20234-08-05

Expand Down
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
Loading

0 comments on commit a4a98f9

Please sign in to comment.