Skip to content

Commit

Permalink
Merge pull request #280 from Shotgunosine/fix_afni_tsnr
Browse files Browse the repository at this point in the history
FIX: AFNI TSNR calculation, ADD: BlurToFWHM,  ADD: testing outputs against reference
  • Loading branch information
effigies authored Feb 25, 2021
2 parents 01eeaef + 7a8cece commit abcdf6b
Show file tree
Hide file tree
Showing 11 changed files with 397 additions and 94 deletions.
116 changes: 58 additions & 58 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,26 @@ jobs:
path: /tmp/src
- restore_cache:
keys:
- ds003-v0-{{ .Branch }}-
- ds003-v0-master-
- ds003-v0-
- ds003-v1-{{ .Branch }}-
- ds003-v1-master-
- ds003-v1-
- run:
name: Set git ID
command: |
git config --global user.name 'FitLins CircleCI User'
git config --global user.email 'crn.poldracklab@gmail.com'
- run:
name: Install fMRIPrep derivatives of ds000003
name: Install fMRIPrep derivatives of ds000003 and reference data
command: |
datalad install -r ///labs/poldrack/ds003_fmriprep
datalad update ds003_fmriprep/
datalad get ds003_fmriprep/sub-0{1,2,3}/func/*_space-MNI152NLin2009cAsym_desc-*.nii.gz \
ds003_fmriprep/sub-0{1,2,3}/func/*_desc-confounds_*.tsv \
ds003_fmriprep/dataset_description.json \
ds003_fmriprep/sub-*/*/*.json
- run:
name: Download a model for ds000003
command: |
mkdir -p ds003_models
cp /tmp/src/examples/models/ds000003/models/model-001_smdl.json ds003_models/
datalad install -r -s https://gin.g-node.org/shotgunosine/fitlins_tests
datalad update --merge fitlins_tests
datalad get fitlins_tests/ds003/ds003_fmriprep/sub-0{1,2,3}/func/*_space-MNI152NLin2009cAsym_desc-*.nii.gz \
fitlins_tests/ds003/ds003_fmriprep/sub-0{1,2,3}/func/*_desc-confounds_*.tsv \
fitlins_tests/ds003/ds003_fmriprep/dataset_description.json \
fitlins_tests/ds003/ds003_fmriprep/sub-*/*/*.json
datalad get -r fitlins_tests/ds003/nistats_smooth/ fitlins_tests/ds003/afni_smooth/ fitlins_tests/ds003/afni_blurto/ fitlins_tests/ds003/nistats_blurto/
- save_cache:
key: ds003-v0-{{ .Branch }}-{{ .BuildNum }}
key: ds003-v1-{{ .Branch }}-{{ .BuildNum }}
paths:
- /tmp/data

Expand Down Expand Up @@ -153,7 +149,9 @@ jobs:
-e COVERAGE_FILE=/scratch/.coverage.pytest \
--entrypoint="/neurodocker/startup.sh" \
poldracklab/fitlins:latest \
pytest --cov=fitlins --cov-report xml:/scratch/cov_pytest.xml /src/fitlins
pytest --cov=fitlins --cov-report xml:/scratch/cov_pytest.xml \
--cov-config /src/fitlins/docker/multiproc.coveragerc \
--ignore-glob=/src/fitlins/fitlins/tests/* /src/fitlins
- run:
name: Submit pytest coverage
command: |
Expand All @@ -164,7 +162,7 @@ jobs:
test_ds003:
parameters:
estimator:
test_name:
type: string
machine:
image: circleci/classic:201711-01
Expand All @@ -177,9 +175,9 @@ jobs:
- docker-v0-{{ .Branch }}-{{ .Revision }}
- restore_cache:
keys:
- ds003-v0-{{ .Branch }}-
- ds003-v0-master-
- ds003-v0-
- ds003-v1-{{ .Branch }}-
- ds003-v1-master-
- ds003-v1-
- run:
name: Load Docker image layer cache
no_output_timeout: 30m
Expand All @@ -193,40 +191,36 @@ jobs:
fi
- run:
name: Run FitLins
no_output_timeout: 2h
no_output_timeout: 4h
command: |
mkdir -p /tmp/ds003/work /tmp/ds003/derivatives
chmod 777 /tmp/ds003/work /tmp/ds003/derivatives
export CONDA_PREFIX=/opt/miniconda-latest/envs/neuro
docker run --rm -v /tmp/data/ds003_fmriprep:/data:ro \
docker run --rm -v /tmp/data/fitlins_tests:/data:ro \
-v /tmp/ds003/derivatives:/out \
-v /tmp/ds003/work:/scratch \
-v /tmp/data/ds003_models:/models \
-e COVERAGE_FILE=/scratch/.coverage \
-e COVERAGE_FILE=/scratch/.coverage_<< parameters.test_name >> \
--entrypoint="/neurodocker/startup.sh" \
poldracklab/fitlins:latest \
coverage run \
--rcfile /src/fitlins/docker/multiproc.coveragerc \
$CONDA_PREFIX/bin/fitlins /data/sourcedata /out dataset \
-d /data -m /models/model-001_smdl.json -w /scratch \
--participant-label 01 02 03 --space MNI152NLin2009cAsym \
--estimator << parameters.estimator >> \
--n-cpus 2 --mem-gb 4 -vv
pytest --cov=fitlins \
--cov-config /src/fitlins/docker/multiproc.coveragerc \
--cov-report xml:/scratch/.coverage_pytest_<< parameters.test_name >>.xml \
$CONDA_PREFIX/lib/python3.6/site-packages/fitlins/tests \
--fitlins-path=$CONDA_PREFIX/bin/fitlins \
--bids-dir=/data/ds003/ds003_fmriprep/sourcedata \
--output-dir=/out \
--derivatives=/data/ds003/ds003_fmriprep \
--model=/data/ds003/models/model-001_smdl.json \
--work-dir=/scratch \
--test-name=<< parameters.test_name >> \
--database-path=/out/ds003_database \
--reference-dir=/data/ds003
- run:
name: Combine coverage and submit
command: |
# combine coverage
docker run --rm \
-v /tmp/ds003/work:/scratch \
-w /scratch \
--entrypoint="/neurodocker/startup.sh" \
poldracklab/fitlins:latest \
bash -c "coverage combine /scratch/.coverage* \
&& coverage xml"
# submit coverage
bash <(curl --retry 5 -s https://codecov.io/bash) \
-f /tmp/ds003/work/coverage.xml \
-F << parameters.estimator >> \
-f /tmp/ds003/work/.coverage_pytest_<< parameters.test_name >>.xml \
-F << parameters.test_name >> \
-e CIRCLE_JOB
- store_artifacts:
path: /tmp/ds003
Expand All @@ -243,9 +237,9 @@ jobs:
- docker-v0-{{ .Branch }}-{{ .Revision }}
- restore_cache:
keys:
- ds003-v0-{{ .Branch }}-
- ds003-v0-master-
- ds003-v0-
- ds003-v1-{{ .Branch }}-
- ds003-v1-master-
- ds003-v1-
- run:
name: Load Docker image layer cache
no_output_timeout: 30m
Expand All @@ -264,10 +258,10 @@ jobs:
mkdir -p /tmp/ds003/work /tmp/ds003/derivatives
chmod 777 /tmp/ds003/work /tmp/ds003/derivatives
export CONDA_PREFIX=/opt/miniconda-latest/envs/neuro
docker run --rm -v /tmp/data/ds003_fmriprep:/data \
docker run --rm -v /tmp/data/fitlins_tests/ds003/ds003_fmriprep:/data:ro \
-v /tmp/ds003/derivatives:/out \
-v /tmp/ds003/work:/scratch \
-v /tmp/data/ds003_models:/models \
-v /tmp/data/fitlins_tests/ds003/models:/models \
-e COVERAGE_FILE=/scratch/.coverage.database-file-new \
--entrypoint="/neurodocker/startup.sh" \
poldracklab/fitlins:latest \
Expand All @@ -282,10 +276,10 @@ jobs:
no_output_timeout: 2h
command: |
export CONDA_PREFIX=/opt/miniconda-latest/envs/neuro
docker run --rm -v /tmp/data/ds003_fmriprep:/data \
docker run --rm -v /tmp/data/fitlins_tests/ds003/ds003_fmriprep:/data:ro \
-v /tmp/ds003/derivatives:/out \
-v /tmp/ds003/work:/scratch \
-v /tmp/data/ds003_models:/models \
-v /tmp/data/fitlins_tests/ds003/models:/models \
-e COVERAGE_FILE=/scratch/.coverage.database-file-exists \
--entrypoint="/neurodocker/startup.sh" \
poldracklab/fitlins:latest \
Expand Down Expand Up @@ -484,10 +478,10 @@ workflows:
tags:
only: /.*/
- test_ds003:
name: test_ds003_<< matrix.estimator >>
name: test_ds003_<< matrix.test_name >>
matrix:
parameters:
estimator: ["afni", "nistats"]
test_name: ["afni_smooth", "nistats_smooth", "afni_blurto", "nistats_blurto"]
requires:
- build
- cache_test_data
Expand All @@ -506,15 +500,19 @@ workflows:
only: /.*/
- deploy_master:
requires:
- test_ds003_nistats
- test_ds003_afni
- test_ds003_nistats_smooth
- test_ds003_nistats_blurto
- test_ds003_afni_smooth
- test_ds003_afni_blurto
filters:
branches:
only: master
- deploy_docker:
requires:
- test_ds003_nistats
- test_ds003_afni
- test_ds003_nistats_smooth
- test_ds003_nistats_blurto
- test_ds003_afni_smooth
- test_ds003_afni_blurto
- build_docs
filters:
branches:
Expand All @@ -523,8 +521,10 @@ workflows:
only: /.*/
- deploy_pypi:
requires:
- test_ds003_nistats
- test_ds003_afni
- test_ds003_nistats_smooth
- test_ds003_nistats_blurto
- test_ds003_afni_smooth
- test_ds003_afni_blurto
- build_docs
- test_packaging
filters:
Expand Down
20 changes: 12 additions & 8 deletions fitlins/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ def get_parser():
"Optional analysis LEVEL (default: l1) may be specified numerically "
"(e.g., `l1`) or by name (`run`, `subject`, `session` or `dataset`). "
"Optional smoothing TYPE (default: iso) must be one of: "
" `iso` (isotropic). e.g., `--smoothing 5:dataset:iso` will perform "
" `iso` (isotropic additive smoothing), `isoblurto` (isotropic "
"smoothing progressivley applied till "
"the target smoothness is reached). "
"e.g., `--smoothing 5:dataset:iso` will perform "
"a 5mm FWHM isotropic smoothing on subject-level maps, "
"before evaluating the dataset level.")

Expand Down Expand Up @@ -140,7 +143,7 @@ def get_parser():
default=None, choices=["polynomial", "cosine", None])
g_other.add_argument("--error-ts", action='store_true', default=False,
help='save error time series for first level models.'
' Currently only implemented for afni estimator.')
' Currently only implemented for afni estimator.')

return parser

Expand All @@ -162,7 +165,6 @@ def run_fitlins(argv=None):
# Iterate over empty tuple if undefined
for ign in opts.ignore or ()]


log_level = 25 + 5 * (opts.quiet - opts.verbose)
logger.setLevel(log_level)
nlogging.getLogger('nipype.workflow').setLevel(log_level)
Expand Down Expand Up @@ -204,18 +206,20 @@ def run_fitlins(argv=None):
# TODO - fix neuroscout
derivatives = derivatives[0].split(" ")

if opts.error_ts and opts.estimator != 'afni':
raise NotImplementedError("Saving the error time series is only implmented for"
" the afni estimator. If this is a feature you want"
f" for {opts.estimator} please let us know on github.")
if opts.estimator != 'afni':
if opts.error_ts:
raise NotImplementedError("Saving the error time series is only implmented for"
" the afni estimator. If this is a feature you want"
f" for {opts.estimator} please let us know on github.")

pipeline_name = 'fitlins'
if opts.derivative_label:
pipeline_name += '_' + opts.derivative_label
deriv_dir = op.join(opts.output_dir, pipeline_name)
os.makedirs(deriv_dir, exist_ok=True)
fub.write_derivative_description(
opts.bids_dir, deriv_dir, vars(opts))
opts.bids_dir, deriv_dir, vars(opts)
)

work_dir = mkdtemp() if opts.work_dir is None else opts.work_dir

Expand Down
2 changes: 2 additions & 0 deletions fitlins/interfaces/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class FirstLevelEstimatorInputSpec(TraitedSpec):
design_matrix = File(exists=True, mandatory=True)
contrast_info = traits.List(traits.Dict)
smoothing_fwhm = traits.Float(desc='Full-width half max (FWHM) in mm for smoothing in mask')
smoothing_type = traits.Enum('iso', 'isoblurto', desc='Type of smoothing (iso or isoblurto)')


class EstimatorOutputSpec(TraitedSpec):
Expand All @@ -61,6 +62,7 @@ class SecondLevelEstimatorInputSpec(TraitedSpec):
stat_metadata = traits.List(traits.List(traits.Dict), mandatory=True)
contrast_info = traits.List(traits.Dict, mandatory=True)
smoothing_fwhm = traits.Float(desc='Full-width half max (FWHM) in mm for smoothing in mask')
smoothing_type = traits.Enum('iso', 'isoblurto', desc='Type of smoothing (iso or isoblurto)')


class SecondLevelEstimatorOutputSpec(EstimatorOutputSpec):
Expand Down
Loading

0 comments on commit abcdf6b

Please sign in to comment.