Skip to content

Commit

Permalink
[ENH] turn --action into subcommands (#215)
Browse files Browse the repository at this point in the history
* speed up CLI and pin docker dependencies

* add more flake8

* update CLI

* split parser and cli

* use sub commands

* fix doc

* fix imports

* update linting

* fixes

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix

* fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix

* fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Remi-Gau and pre-commit-ci[bot] authored Aug 2, 2024
1 parent de73e5b commit 4f40c49
Show file tree
Hide file tree
Showing 26 changed files with 1,034 additions and 373 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ jobs:
/bids_dataset \
/outputs \
participant \
all \
--participant_label 302 307 \
--space MNI152NLin2009cAsym \
--reset_database \
--action all \
-vv
no_output_timeout: 6h
- store_artifacts:
Expand Down
14 changes: 5 additions & 9 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
[flake8]
max-line-length = 90
count = True
show-source = True
statistics = True
exclude =
*build
.git
__pycache__
tests/*
_version.py
versioneer.py
tests_.*.py
version.*.py
setup.py
max-complexity = 10
ignore = D100, D103, W503
per-file-ignores =
setup.py:E121
max-line-length = 90
max_complexity = 15
max_function_length = 150
max_parameters_amount = 15
max_returns_amount = 5
4 changes: 4 additions & 0 deletions .github/workflows/system_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

# Force to use color
env:
FORCE_COLOR: true

jobs:
system_test:

Expand Down
19 changes: 4 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ repos:
- id: pyupgrade
args: [--py38-plus]

- repo: https://github.com/ikamensh/flynt/
rev: 1.0.1
hooks:
- id: flynt

- repo: https://github.com/seddonym/import-linter
rev: v2.0
hooks:
Expand All @@ -46,7 +41,7 @@ repos:
rev: 5.13.2
hooks:
- id: isort
args: [--profile, black]
args: [--settings-path, pyproject.toml]

- repo: https://github.com/adamchainz/blacken-docs
rev: 1.18.0
Expand All @@ -59,7 +54,7 @@ repos:
rev: 24.4.2
hooks:
- id: black
args: [--config=pyproject.toml, --verbose]
args: [--config=pyproject.toml]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.0
Expand All @@ -76,19 +71,13 @@ repos:
args: [--toml=pyproject.toml]
additional_dependencies: [tomli]

- repo: https://github.com/jendrikseipp/vulture
rev: v2.11
hooks:
- id: vulture

- repo: https://github.com/pycqa/flake8
rev: 7.1.0
hooks:
- id: flake8
exclude: tests_.*.py|version.*.py|setup.py # ignore tests and versioneer related code
args: [--verbose]
additional_dependencies: [flake8-docstrings]

args: [--config, .flake8, --verbose]
additional_dependencies: [flake8-docstrings, flake8-use-fstring, flake8-functions, flake8-bugbear]

ci:
autoupdate_commit_msg: 'chore: update pre-commit hooks'
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10.9-bullseye
FROM python:3.11.9-slim-bullseye@sha256:8850f5e6e8da9081a6d156252a11161aa22f04d6ed1723c57ca2d5a5d48132bc

ARG DEBIAN_FRONTEND="noninteractive"

Expand All @@ -12,11 +12,12 @@ WORKDIR /home/neuro/bidsMReye

COPY [".", "/home/neuro/bidsMReye"]
RUN pip install --upgrade pip && \
pip3 install -e .
pip3 install -r requirements.txt && \
pip3 install .

RUN bidsmreye_model

ENTRYPOINT [ "//home/neuro/bidsMReye/entrypoint.sh" ]
ENTRYPOINT [ "/home/neuro/bidsMReye/entrypoint.sh" ]
COPY ["./docker/entrypoint.sh", \
"//home/neuro/bidsMReye/entrypoint.sh"]
"/home/neuro/bidsMReye/entrypoint.sh"]
RUN chmod +x /home/neuro/bidsMReye/entrypoint.sh
38 changes: 15 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,6 @@ models/dataset4_pursuit.h5:
models/dataset5_free_viewing.h5:
bidsmreye_model --model_name 5_free_viewing


## STYLE

lint/flake8: ## check style with flake8
flake8 bidsmreye tests
lint/black: ## check style with black
black bidsmreye tests
lint/mypy: ## check style with mypy
mypy bidsmreye

lint: lint/black lint/mypy lint/flake8 ## check style

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

Expand Down Expand Up @@ -139,7 +127,7 @@ prepare: tests/data/moae_fmriprep ## demo: prepares the data of MOAE dataset
bidsmreye $$PWD/tests/data/moae_fmriprep \
$$PWD/outputs/moae_fmriprep/derivatives \
participant \
--action prepare \
prepare \
-vv \
--reset_database \
--non_linear_coreg
Expand All @@ -148,12 +136,11 @@ generalize: ## demo: predicts labels of MOAE dataset
bidsmreye $$PWD/tests/data/moae_fmriprep \
$$PWD/outputs/moae_fmriprep/derivatives \
participant \
--action generalize \
-vv \
--non_linear_coreg
generalize \
-vv


## Openneuro data
## ds002799
.PHONY: get_ds002799_dat

clean-ds002799:
Expand All @@ -170,7 +157,7 @@ ds002799_prepare: get_ds002799
bidsmreye $$PWD/tests/data/ds002799/derivatives/fmriprep \
$$PWD/outputs/ds002799/derivatives \
participant \
--action prepare \
prepare \
--participant_label 302 307 \
--space MNI152NLin2009cAsym \
--reset_database \
Expand All @@ -181,7 +168,7 @@ ds002799_generalize:
bidsmreye $$PWD/tests/data/ds002799/derivatives/fmriprep \
$$PWD/outputs/ds002799/derivatives \
participant \
--action generalize \
generalize \
--participant_label 302 307 \
--space MNI152NLin2009cAsym \
--run 1 2
Expand All @@ -191,13 +178,18 @@ ds002799: clean-ds002799 get_ds002799
bidsmreye $$PWD/tests/data/ds002799/derivatives/fmriprep \
$$PWD/outputs/ds002799/derivatives \
participant \
--action all \
all \
--participant_label 302 307 \
--space MNI152NLin2009cAsym \
--run 1 2 \
--reset_database \
-vv

## ds002799
get_ds000114:
datalad install -s ///openneuro-derivatives/ds000114-fmriprep tests/data/ds000114-fmriprep
cd tests/data/ds000114-fmriprep && datalad get sub-0[1-2]/ses-*/func/*MNI*desc-preproc*bold.nii.gz -J 12

## DOCKER
.PHONY:

Expand All @@ -219,7 +211,7 @@ docker_prepare_data:
/home/neuro/data/ \
/home/neuro/outputs/ \
participant \
--action prepare \
prepare \
--reset_database

docker_generalize:
Expand All @@ -230,7 +222,7 @@ docker_generalize:
/home/neuro/data/ \
/home/neuro/outputs/ \
participant \
--action generalize
generalize

docker_ds002799: get_ds002799
# datalad unlock $$PWD/tests/data/ds002799/derivatives/fmriprep/sub-30[27]/ses-*/func/*run-*preproc*bold*
Expand All @@ -241,7 +233,7 @@ docker_ds002799: get_ds002799
/home/neuro/data/ \
/home/neuro/outputs/ \
participant \
--action all \
all \
--participant_label 302 307 \
--space MNI152NLin2009cAsym \
--run 1 2 \
Expand Down
28 changes: 9 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,48 +156,38 @@ bidsmreye --help

## Preparing the data

`--action prepapre` means that bidsmreye will extract the data coming from the
`prepapre` means that bidsmreye will extract the data coming from the
eyes from the fMRI images.

If your data is not in MNI space, bidsmreye will also register the data to MNI.

```bash
bidsmreye --action prepare \
bids_dir \
output_dir \
participant
bidsmreye bids_dir output_dir participant prepare
```

## Computing the eye movements

`--action generalize` use the extracted timeseries to predict the eye movements
`generalize` use the extracted timeseries to predict the eye movements
using the default pre-trained model of deepmreye.

This will also generate a quality control report of the decoded eye movements.

```bash
bidsmreye --action generalize \
bids_dir \
output_dir \
participant
bidsmreye bids_dir output_dir participant generalize
```
## Doing it all at once

`--action all` does "prepare" then "generalize".
`all` does "prepare" then "generalize".

```bash
bidsmreye --action all \
bids_dir \
output_dir \
participant
bidsmreye bids_dir output_dir participant all
```

## Group level summary

bidsmreye --action qc \
bids_dir \
output_dir \
group
```
bidsmreye bids_dir output_dir group qc
```

## Demo

Expand Down
71 changes: 71 additions & 0 deletions bidsmreye/_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""Define the command line interface."""

from __future__ import annotations

import sys
from typing import Any

from rich_argparse import RichHelpFormatter

from bidsmreye._parsers import common_parser, download_parser
from bidsmreye.bidsmreye import bidsmreye
from bidsmreye.defaults import default_log_level, log_levels
from bidsmreye.download import download
from bidsmreye.logging import bidsmreye_log

log = bidsmreye_log(name="bidsmreye")


def cli(argv: Any = sys.argv) -> None:
"""Run the bids app.
:param argv: _description_, defaults to sys.argv
:type argv: _type_, optional
"""
parser = common_parser(formatter_class=RichHelpFormatter)

args = parser.parse_args(argv[1:])

log.debug(f"args:\n{args}")

# TODO integrate as part of base config
# https://stackoverflow.com/a/53293042/14223310
log_level = log_levels().index(default_log_level())
# For each "-v" flag, adjust the logging verbosity accordingly
# making sure to clamp off the value from 0 to 4, inclusive of both
for adjustment in args.log_level or ():
log_level = min(len(log_levels()) - 1, max(log_level + adjustment, 0))
log_level_name = log_levels()[log_level]

model_weights_file = None
if getattr(args, "model", None) is not None:
model_weights_file = str(getattr(args, "model"))

bidsmreye(
bids_dir=args.bids_dir[0],
output_dir=args.output_dir[0],
analysis_level=args.analysis_level[0],
action=args.command,
participant_label=args.participant_label or None,
space=args.space or None,
task=args.task or None,
run=args.run or None,
debug=args.debug,
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)),
log_level_name=log_level_name,
)


def cli_download(argv: Any = sys.argv) -> None:
"""Download the models from OSF.
:return: _description_
:rtype: _type_
"""
parser = download_parser(formatter_class=RichHelpFormatter)
args = parser.parse_args(argv[1:])

download(model_name=args.model_name, output_dir=args.output_dir)
Loading

0 comments on commit 4f40c49

Please sign in to comment.