Example #1
0
def test_fslreorient2std():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(
            bin=('fslreorient2std', )) as fsldir:
        r2std = op.join(fsldir, 'bin', 'fslreorient2std')
        result = fw.fslreorient2std('input', 'output')
        expected = r2std + ' input output'
        assert result.stdout[0] == expected
Example #2
0
def test_fslstats_cmdline():
    with tempdir.tempdir(), run.dryrun(), mockFSLDIR(1) as fsldir:

        make_random_image('image')
        cmd = op.join(fsldir, 'bin', 'fslstats')

        result = fw.fslstats('image').m.r.mask('mask').k('mask').r.run(True)
        expected = cmd + ' image -m -r -k mask -k mask -r'
        assert result[0] == expected

        result = fw.fslstats('image', t=True,
                             K='mask').m.R.u(123).s.volume.run(True)
        expected = cmd + ' -t -K mask image -m -R -u 123 -s -v'
        assert result[0] == expected

        result = fw.fslstats('image', K='mask').n.V.p(1).run(True)
        expected = cmd + ' -K mask image -n -V -p 1'
        assert result[0] == expected

        result = fw.fslstats('image', t=True).H(10, 1, 99).d('diff').run(True)
        expected = cmd + ' -t image -H 10 1 99 -d diff'
        assert result[0] == expected

        # unknown option
        with pytest.raises(AttributeError):
            fw.fslstats('image').Q
Example #3
0
def test_tbss():
    exes = {
        'preproc': 'tbss_1_preproc',
        'reg': 'tbss_2_reg',
        'postreg': 'tbss_3_postreg',
        'prestats': 'tbss_4_prestats',
        'non_FA': 'tbss_non_FA',
        'fill': 'tbss_fill'
    }

    with asrt.disabled(), \
         run.dryrun(), \
         mockFSLDIR(bin=exes.values()) as fsldir:
        for k in exes:
            exes[k] = op.join(fsldir, 'bin', exes[k])

        assert fw.tbss.preproc('1',
                               '2')[0] == ' '.join([exes['preproc'], '1', '2'])
        assert fw.tbss.reg(T=True)[0] == ' '.join([exes['reg'], '-T'])
        assert fw.tbss.reg(n=True)[0] == ' '.join([exes['reg'], '-n'])
        assert fw.tbss.reg(t='target')[0] == ' '.join(
            [exes['reg'], '-t', 'target'])
        assert fw.tbss.postreg(S=True)[0] == ' '.join([exes['postreg'], '-S'])
        assert fw.tbss.postreg(T=True)[0] == ' '.join([exes['postreg'], '-T'])
        assert fw.tbss.prestats(0.3)[0] == ' '.join([exes['prestats'], '0.3'])
        assert fw.tbss.non_FA('alt')[0] == ' '.join([exes['non_FA'], 'alt'])
        assert fw.tbss.fill('stat', 0.4, 'mean_fa', 'output', n=True).stdout[0] == \
            ' '.join([exes['fill'], 'stat', '0.4', 'mean_fa', 'output', '-n'])
Example #4
0
def test_fast():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('fast', )) as fsldir:

        cmd = op.join(fsldir, 'bin', 'fast')

        result = fw.fast('input', 'myseg', n_classes=3)
        expected = [cmd, '--out=myseg', '--class=3', 'input']

        assert result.stdout[0] == ' '.join(expected)

        result = fw.fast(('in1', 'in2', 'in3'), 'myseg', n_classes=3)
        expected = [cmd, '--out=myseg', '--class=3', 'in1', 'in2', 'in3']
        assert result.stdout[0] == ' '.join(expected)

        result = fw.fast(('in1', 'in2', 'in3'),
                         'myseg',
                         n_classes=3,
                         verbose=True)
        expected = [
            cmd, '--out=myseg', '--class=3', '--verbose', 'in1', 'in2', 'in3'
        ]
        assert result.stdout[0] == ' '.join(expected)

        result = fw.fast(('in1', 'in2', 'in3'),
                         'myseg',
                         n_classes=3,
                         a='reg.mat',
                         A=('csf', 'gm', 'wm'),
                         Prior=True)
        expected = [
            cmd, '--out=myseg', '--class=3', '-a', 'reg.mat', '-A', 'csf',
            'gm', 'wm', '--Prior', 'in1', 'in2', 'in3'
        ]
        assert result.stdout[0] == ' '.join(expected)
Example #5
0
def test_gps():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('gps', )) as fsldir:
        gps = op.join(fsldir, 'bin', 'gps')
        result = fw.gps('bvecs', 128, optws=True, ranseed=123)
        expected = (gps + ' --ndir=128 --out=bvecs', ('--optws',
                                                      '--ranseed=123'))
        assert checkResult(result.stdout[0], *expected)
Example #6
0
def test_fugue():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('fugue', )) as fsldir:
        fugue = op.join(fsldir, 'bin', 'fugue')
        result = fw.fugue(input='input', warp='warp', median=True, dwell=10)
        expected = (fugue, ('--in=input', '--warp=warp', '--median',
                            '--dwell=10'))
        assert checkResult(result.stdout[0], *expected)
Example #7
0
def test_robustfov():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(
            bin=('robustfov', )) as fsldir:
        rfov = op.join(fsldir, 'bin', 'robustfov')
        result = fw.robustfov('input', 'output', b=180)
        expected = (rfov + ' -i input', ('-r output', '-b 180'))
        assert checkResult(result.stdout[0], *expected)
Example #8
0
def test_concatxfm():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(
            bin=('convert_xfm', )) as fsldir:
        cnvxfm = op.join(fsldir, 'bin', 'convert_xfm')
        result = fw.concatxfm('mat1', 'mat2', 'output')
        expected = cnvxfm + ' -omat output -concat mat2 mat1'
        assert result.stdout[0] == expected
Example #9
0
def test_epi_reg():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(
            bin=('epi_reg', )) as fsldir:
        epi_reg = op.join(fsldir, 'bin', 'epi_reg')
        result = fw.epi_reg('epi', 't1', 't1brain', 'out')
        expected = epi_reg + ' --epi=epi --t1=t1 --t1brain=t1brain --out=out'
        assert result.stdout[0] == expected
Example #10
0
def test_flirt():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('flirt', )) as fsldir:
        flirt = op.join(fsldir, 'bin', 'flirt')
        result = fw.flirt('src', 'ref', usesqform=True, anglerep='euler')
        expected = (flirt + ' -in src -ref ref', ('-usesqform',
                                                  '-anglerep euler'))
        assert checkResult(result.stdout[0], *expected)
Example #11
0
def test_melodic():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(
            bin=('melodic', )) as fsldir:
        melodic = op.join(fsldir, 'bin', 'melodic')
        result = fw.melodic('input', dim=50, mask='mask', Oall=True)
        expected = (melodic + ' --in=input', ('--dim=50', '--mask=mask',
                                              '--Oall'))
        assert checkResult(result.stdout[0], *expected)
Example #12
0
def test_sigloss():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(
            bin=('sigloss', )) as fsldir:
        sigloss = op.join(fsldir, 'bin', 'sigloss')
        result = fw.sigloss('input', 'sigloss', mask='mask', te=0.5)
        expected = (sigloss + ' --in input --sigloss sigloss', ('--mask mask',
                                                                '--te 0.5'))
        assert checkResult(result.stdout[0], *expected)
Example #13
0
def test_convertwarp():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(
            bin=('convertwarp', )) as fsldir:
        cnvwarp = op.join(fsldir, 'bin', 'convertwarp')
        result = fw.convertwarp('out', 'ref', absout=True, jacobian='jacobian')
        expected = (cnvwarp + ' --ref=ref --out=out', ('--absout',
                                                       '--jacobian=jacobian'))
        assert checkResult(result.stdout[0], *expected)
Example #14
0
def test_invwarp():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(
            bin=('invwarp', )) as fsldir:
        invwarp = op.join(fsldir, 'bin', 'invwarp')
        result = fw.invwarp('warp', 'ref', 'out', rel=True, noconstraint=True)
        expected = (invwarp + ' --warp=warp --ref=ref --out=out',
                    ('--rel', '--noconstraint'))
        assert checkResult(result.stdout[0], *expected)
Example #15
0
def test_mcflirt():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(
            bin=('mcflirt', )) as fsldir:
        mcflirt = op.join(fsldir, 'bin', 'mcflirt')
        result = fw.mcflirt('input', out='output', cost='normcorr', dof=12)
        expected = (mcflirt + ' -in input', ('-out output', '-cost normcorr',
                                             '-dof 12'))
        assert checkResult(result.stdout[0], *expected)
Example #16
0
def test_applyxfm():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('flirt', )) as fsldir:
        flirt = op.join(fsldir, 'bin', 'flirt')
        result = fw.applyxfm('src', 'ref', 'mat', 'out', interp='trilinear')
        expected = (flirt + ' -in src -ref ref',
                    ('-applyxfm', '-out out', '-init mat',
                     '-interp trilinear'))
        assert checkResult(result.stdout[0], *expected)
Example #17
0
def test_cluster():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(
            bin=('cluster', )) as fsldir:
        cluster = op.join(fsldir, 'bin', 'cluster')
        result = fw.cluster('input', 'thresh', fractional=True, osize='osize')
        expected = (cluster + ' --in=input --thresh=thresh', ('--fractional',
                                                              '--osize=osize'))
        assert checkResult(result.stdout[0], *expected)
Example #18
0
def test_cmdwrapper():
    @wutils.cmdwrapper
    def func(a, b):
        return ['func', str(a), str(b)]

    with run.dryrun():
        assert func(1, 2)[0] == 'func 1 2'

    assert func(1, 2, cmdonly=True) == ['func', '1', '2']
Example #19
0
def test_fslwrapper():
    @wutils.fslwrapper
    def func(a, b):
        return ['func', str(a), str(b)]

    with mockFSLDIR(bin=('func', )) as fsldir:
        expected = '{} 1 2'.format(op.join(fsldir, 'bin', 'func'))
        with run.dryrun():
            assert func(1, 2)[0] == expected

        assert func(1, 2, cmdonly=True) == list(shlex.split(expected))
Example #20
0
def test_fnirt():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('fnirt', )) as fsldir:
        fnirt = op.join(fsldir, 'bin', 'fnirt')
        result = fw.fnirt('src',
                          ref='ref',
                          iout='iout',
                          fout='fout',
                          subsamp=(8, 6, 4, 2))
        expected = (fnirt + ' --in=src', ('--ref=ref', '--iout=iout',
                                          '--fout=fout', '--subsamp=8,6,4,2'))
        assert checkResult(result.stdout[0], *expected)
Example #21
0
def test_fsl_prepare_fieldmap():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(
            bin=('fsl_prepare_fieldmap', )) as fsldir:
        fpf = op.join(fsldir, 'bin', 'fsl_prepare_fieldmap')
        result = fw.fsl_prepare_fieldmap(phase_image='ph',
                                         magnitude_image='mag',
                                         out_image='out',
                                         deltaTE=2.46,
                                         nocheck=True)
        expected = (fpf, ('SIEMENS', 'ph', 'mag', 'out', '2.46', '--nocheck'))
        assert checkResult(result.stdout[0], *expected)
Example #22
0
def test_prelude():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(
            bin=('prelude', )) as fsldir:
        prelude = op.join(fsldir, 'bin', 'prelude')
        result = fw.prelude(complex='complex',
                            out='out',
                            labelslices=True,
                            start=5)
        expected = (prelude, ('--complex=complex', '--out=out',
                              '--labelslices', '--start=5'))
        assert checkResult(result.stdout[0], *expected)
Example #23
0
def test_fsl_anat():
    with asrt.disabled(), \
         run.dryrun(), \
         mockFSLDIR(bin=('fsl_anat',)) as fsldir:

        cmd = op.join(fsldir, 'bin', 'fsl_anat')

        result = fw.fsl_anat('t1', out='fsl_anat', bias_smoothing=25)
        expected = [cmd, '-i', 't1', '-o', 'fsl_anat', '-t', 'T1', '-s', '25']

        assert result.stdout[0] == ' '.join(expected)
Example #24
0
def test_fsl_regfilt():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(
            bin=('fsl_regfilt', )) as fsldir:
        regfilt = op.join(fsldir, 'bin', 'fsl_regfilt')
        result = fw.fsl_regfilt('input',
                                'output',
                                'design',
                                filter=(1, 2, 3, 4),
                                vn=True)
        expected = (regfilt + ' --in=input --out=output --design=design',
                    ('--filter=1,2,3,4', '--vn'))
        assert checkResult(result.stdout[0], *expected)
Example #25
0
def test_fsl_sub():
    with run.dryrun(), mockFSLDIR(bin=('fsl_sub', )) as fsldir:
        expected = [
            op.join(fsldir, 'bin', 'fsl_sub'), '--jobhold', '123', '--queue',
            'long.q', 'some_command', '--some_arg'
        ]

        result = fw.fsl_sub('some_command',
                            '--some_arg',
                            jobhold='123',
                            queue='long.q')
        assert shlex.split(result[0]) == expected
Example #26
0
def test_applywarp():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(
            bin=('applywarp', )) as fsldir:
        applywarp = op.join(fsldir, 'bin', 'applywarp')
        result = fw.applywarp('src',
                              'ref',
                              'out',
                              warp='warp',
                              abs=True,
                              super=True)
        expected = (applywarp + ' --in=src --ref=ref --out=out',
                    ('--warp=warp', '--abs', '--super'))
        assert checkResult(result.stdout[0], *expected)
Example #27
0
def test_applyxfm4D():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(
            bin=('applyxfm4D', )) as fsldir:
        applyxfm = op.join(fsldir, 'bin', 'applyxfm4D')
        result = fw.applyxfm4D('src',
                               'ref',
                               'out',
                               'mat',
                               fourdigit=True,
                               userprefix='boo')
        expected = (applyxfm + ' src ref out mat', ('-fourdigit',
                                                    '-userprefix boo'))
        assert checkResult(result.stdout[0], *expected)
Example #28
0
def test_fast():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('fast', )) as fsldir:

        cmd = op.join(fsldir, 'bin', 'fast')

        result = fw.fast('input', 'myseg', n_classes=3)
        expected = [cmd, '-v', '--out=myseg', '--class=3', 'input']

        assert result.stdout[0] == ' '.join(expected)

        result = fw.fast(('in1', 'in2', 'in3'), 'myseg', n_classes=3)
        expected = [cmd, '-v', '--out=myseg', '--class=3', 'in1', 'in2', 'in3']

        assert result.stdout[0] == ' '.join(expected)
Example #29
0
def test_fslroi():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(bin=('fslroi', )) as fsldir:
        fslroi = op.join(fsldir, 'bin', 'fslroi')

        result = fw.fslroi('input', 'output', 1, 10)
        expected = fslroi + ' input output 1 10'
        assert result.stdout[0] == expected

        result = fw.fslroi('input', 'output', 1, 10, 2, 20, 3, 30)
        expected = fslroi + ' input output 1 10 2 20 3 30'
        assert result.stdout[0] == expected

        result = fw.fslroi('input', 'output', 1, 10, 2, 20, 3, 30, 4, 40)
        expected = fslroi + ' input output 1 10 2 20 3 30 4 40'
        assert result.stdout[0] == expected
Example #30
0
def test_eddy_cuda():
    with asrt.disabled(), run.dryrun(), mockFSLDIR(
            bin=('eddy_cuda', )) as fsldir:
        eddy = op.join(fsldir, 'bin', 'eddy_cuda')
        result = fw.eddy_cuda('imain',
                              'mask',
                              'index',
                              'acqp',
                              'bvecs',
                              'bvals',
                              'out',
                              dont_mask_output=True)
        expected = (eddy, ('--imain=imain', '--mask=mask', '--index=index',
                           '--acqp=acqp', '--bvecs=bvecs', '--bvals=bvals',
                           '--out=out', '--dont_mask_output'))

        assert checkResult(result.stdout[0], *expected)