Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TST] Add tests for the workflow CLIs #538

Merged
merged 5 commits into from
Mar 14, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 19 additions & 23 deletions tedana/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import requests
import pandas as pd

from tedana.workflows import tedana_workflow
from tedana.workflows import tedana as tedana_cli
from tedana import io


Expand Down Expand Up @@ -86,9 +86,10 @@ def test_integration_five_echo(skip_integration):
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)]
tedana_workflow(
echo_times = [15.4, 29.7, 44.0, 58.3, 72.6]
tedana_cli.tedana_workflow(
data=datalist,
tes=[15.4, 29.7, 44.0, 58.3, 72.6],
tes=echo_times,
out_dir=out_dir,
tedpca='aic',
fittype='curvefit',
Expand All @@ -100,19 +101,15 @@ def test_integration_five_echo(skip_integration):
df = io.load_comptable(comptable)
assert isinstance(df, pd.DataFrame)

# Test re-running, but use the CLI
out_dir2 = '/tmp/data/five-echo/TED.five-echo-manual'
acc_comps = df.loc[df['classification'] == 'accepted'].index.values
mixing = os.path.join(out_dir, 'ica_mixing.tsv')
tedana_workflow(
data=datalist,
tes=[15.4, 29.7, 44.0, 58.3, 72.6],
out_dir=out_dir2,
debug=True,
verbose=True,
manacc=','.join(acc_comps.astype(str)),
ctab=comptable,
mixm=mixing,
)
args = (['-d'] + datalist + ['-e'] + [str(te) for te in echo_times] +
['--out-dir', out_dir2, '--debug', '--verbose',
'--manacc', ','.join(acc_comps.astype(str)),
'--ctab', comptable, '--mix', mixing])
tedana_cli._main(args)

# compare the generated output files
fn = resource_filename('tedana',
Expand All @@ -137,7 +134,7 @@ def test_integration_four_echo(skip_integration):
prepend += 'sub-PILOT_ses-01_task-localizerDetection_run-01_echo-'
suffix = '_space-sbref_desc-preproc_bold+orig.HEAD'
datalist = [prepend + str(i + 1) + suffix for i in range(4)]
tedana_workflow(
tedana_cli.tedana_workflow(
data=datalist,
tes=[11.8, 28.04, 44.28, 60.52],
out_dir=out_dir,
Expand Down Expand Up @@ -166,21 +163,20 @@ def test_integration_three_echo(skip_integration):
# download data and run the test
download_test_data('https://osf.io/rqhfc/download',
os.path.dirname(out_dir))
tedana_workflow(
tedana_cli.tedana_workflow(
data='/tmp/data/three-echo/three_echo_Cornell_zcat.nii.gz',
tes=[14.5, 38.5, 62.5],
out_dir=out_dir,
low_mem=True,
tedpca='mdl')

# test rerunning the workflow
tedana_workflow(
data='/tmp/data/three-echo/three_echo_Cornell_zcat.nii.gz',
tes=[14.5, 38.5, 62.5],
out_dir=out_dir2,
mixm=os.path.join(out_dir, 'ica_mixing.tsv'),
ctab=os.path.join(out_dir, 'ica_decomposition.json'),
no_png=True)
# Test re-running, but use the CLI
args = (['-d', '/tmp/data/three-echo/three_echo_Cornell_zcat.nii.gz',
'-e', '14.5', '38.5', '62.5',
'--out-dir', out_dir2, '--debug', '--verbose',
'--ctab', os.path.join(out_dir, 'ica_decomposition.json'),
'--mix', os.path.join(out_dir, 'ica_mixing.tsv')])
tedana_cli._main(args)

# compare the generated output files
fn = resource_filename('tedana',
Expand Down
29 changes: 27 additions & 2 deletions tedana/tests/test_t2smap.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ def test_basic_t2smap4(self):
"""
A very simple test, to confirm that t2smap creates output
files when combmode is set to 'paid' and fitmode is set to 'ts'.

Not sure why this fails.
"""
data_dir = get_test_data_path()
data = [op.join(data_dir, 'echo1.nii.gz'),
Expand All @@ -118,6 +116,33 @@ def test_basic_t2smap4(self):
img = nib.load(op.join(out_dir, 'ts_OC.nii.gz'))
assert len(img.shape) == 4

def test_t2smap_cli(self):
"""
Run test_basic_t2smap1, but use the CLI method.
"""
data_dir = get_test_data_path()
data = [op.join(data_dir, 'echo1.nii.gz'),
op.join(data_dir, 'echo2.nii.gz'),
op.join(data_dir, 'echo3.nii.gz')]
args = (['-d'] + data +
['-e', '14.5', '38.5', '62.5', '--combmode', 't2s',
'--fitmode', 'all', '--label', 't2smap'])
workflows.t2smap._main(args)
out_dir = 'TED.echo1.t2smap'

# Check outputs
assert op.isfile(op.join(out_dir, 'ts_OC.nii.gz'))
tsalo marked this conversation as resolved.
Show resolved Hide resolved
img = nib.load(op.join(out_dir, 't2sv.nii.gz'))
tsalo marked this conversation as resolved.
Show resolved Hide resolved
assert len(img.shape) == 3
img = nib.load(op.join(out_dir, 's0v.nii.gz'))
assert len(img.shape) == 3
img = nib.load(op.join(out_dir, 't2svG.nii.gz'))
assert len(img.shape) == 3
img = nib.load(op.join(out_dir, 's0vG.nii.gz'))
assert len(img.shape) == 3
img = nib.load(op.join(out_dir, 'ts_OC.nii.gz'))
assert len(img.shape) == 4

def teardown_method(self):
# Clean up folders
rmtree('TED.echo1.t2smap')