From d338acc57f9fde09c5f8dcc251937f00236d3f52 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Thu, 7 May 2020 13:16:38 -0400 Subject: [PATCH] [FIX] Fix t2smap optimal combination (#566) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix t2smap optcom Introduced when I changed make_optcom’s arg from mask to adaptive mask in #358. * Add t2smap integration test. --- .circleci/config.yml | 28 +++++++++++++++ Makefile | 5 ++- .../data/nih_five_echo_outputs_t2smap.txt | 5 +++ tedana/tests/test_integration.py | 34 +++++++++++++++++++ tedana/workflows/t2smap.py | 2 +- 5 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 tedana/tests/data/nih_five_echo_outputs_t2smap.txt diff --git a/.circleci/config.yml b/.circleci/config.yml index 5a1dc17ef..d3a2a2fb9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -202,6 +202,30 @@ jobs: paths: - src/coverage/.coverage.five-echo + t2smap: + docker: + - image: continuumio/miniconda3 + working_directory: /tmp/src/tedana + steps: + - checkout + - restore_cache: + key: conda-py37-v1-{{ checksum "dev_requirements.txt" }}-{{ checksum "requirements.txt" }} + - run: + name: Run integration tests + no_output_timeout: 40m + command: | + apt-get install -yqq make + source activate tedana_py37 # depends on makeenv_37 + make t2smap + mkdir /tmp/src/coverage + mv /tmp/src/tedana/.coverage /tmp/src/coverage/.coverage.t2smap + - store_artifacts: + path: /tmp/data + - persist_to_workspace: + root: /tmp + paths: + - src/coverage/.coverage.t2smap + merge_coverage: working_directory: /tmp/src/tedana docker: @@ -247,6 +271,9 @@ workflows: - five-echo: requires: - makeenv_37 + - t2smap: + requires: + - makeenv_37 - merge_coverage: requires: - unittest_35 @@ -255,3 +282,4 @@ workflows: - three-echo - four-echo - five-echo + - t2smap diff --git a/Makefile b/Makefile index 0ea412bc7..0fba6759c 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: all lint -all_tests: lint unittest three-echo five-echo +all_tests: lint unittest three-echo four-echo five-echo t2smap help: @echo "Please use 'make ' where is one of:" @@ -8,6 +8,7 @@ help: @echo " unittest to run unit tests on tedana" @echo " three-echo to run the three-echo test set on tedana" @echo " five-echo to run the five-echo test set on tedana" + @echo " t2smap to run the t2smap integration test set on tedana" @echo " all_tests to run 'lint', 'unittest', and 'integration'" lint: @@ -25,3 +26,5 @@ four-echo: five-echo: @py.test --cov-append --cov-report term-missing --cov=tedana -k test_integration_five_echo tedana/tests/test_integration.py +t2smap: + @py.test --cov-append --cov-report term-missing --cov=tedana -k test_integration_t2smap tedana/tests/test_integration.py diff --git a/tedana/tests/data/nih_five_echo_outputs_t2smap.txt b/tedana/tests/data/nih_five_echo_outputs_t2smap.txt new file mode 100644 index 000000000..1d2c6c46b --- /dev/null +++ b/tedana/tests/data/nih_five_echo_outputs_t2smap.txt @@ -0,0 +1,5 @@ +desc-full_S0map.nii.gz +desc-full_T2starmap.nii.gz +desc-optcom_bold.nii.gz +S0map.nii.gz +T2starmap.nii.gz diff --git a/tedana/tests/test_integration.py b/tedana/tests/test_integration.py index 6d61cbc52..f245362ea 100644 --- a/tedana/tests/test_integration.py +++ b/tedana/tests/test_integration.py @@ -16,6 +16,7 @@ import pandas as pd from tedana.workflows import tedana as tedana_cli +from tedana.workflows import t2smap as t2smap_cli from tedana import io @@ -183,3 +184,36 @@ def test_integration_three_echo(skip_integration): fn = resource_filename('tedana', 'tests/data/cornell_three_echo_outputs.txt') check_integration_outputs(fn, out_dir) + + +def test_integration_t2smap(skip_integration): + """Integration test of the full t2smap workflow using five-echo test data + """ + if skip_integration: + pytest.skip('Skipping t2smap integration test') + out_dir = '/tmp/data/five-echo/t2smap_five-echo' + if os.path.exists(out_dir): + shutil.rmtree(out_dir) + + # download data and run the test + download_test_data('https://osf.io/9c42e/download', + os.path.dirname(out_dir)) + prepend = '/tmp/data/five-echo/p06.SBJ01_S09_Task11_e' + suffix = '.sm.nii.gz' + datalist = [prepend + str(i + 1) + suffix for i in range(5)] + echo_times = [15.4, 29.7, 44.0, 58.3, 72.6] + args = (['-d'] + datalist + ['-e'] + [str(te) for te in echo_times] + + ['--out-dir', out_dir, '--fittype', 'curvefit']) + t2smap_cli._main(args) + + # compare the generated output files + fname = resource_filename('tedana', + 'tests/data/nih_five_echo_outputs_t2smap.txt') + # Gets filepaths generated by integration test + existing = [os.path.relpath(f, out_dir) for f in + glob.glob(os.path.join(out_dir, '**'), recursive=True)[1:]] + + # Compares remaining files with those expected + with open(fname, 'r') as f: + tocheck = f.read().splitlines() + assert sorted(tocheck) == sorted(existing) diff --git a/tedana/workflows/t2smap.py b/tedana/workflows/t2smap.py index 85ab44d3d..d6ab8ca75 100644 --- a/tedana/workflows/t2smap.py +++ b/tedana/workflows/t2smap.py @@ -227,7 +227,7 @@ def t2smap_workflow(data, tes, out_dir='.', mask=None, LGR.info('Computing optimal combination') # optimally combine data - OCcatd = combine.make_optcom(catd, tes, mask, t2s=t2s_full, + OCcatd = combine.make_optcom(catd, tes, masksum, t2s=t2s_full, combmode=combmode) # clean up numerical errors