Exemple #1
0
def test_rapidtide2x_phase3(debug=False):
    recalculate = True
    if recalculate:
        # create outputdir if it doesn't exist
        create_dir(get_test_temp_path())

        # trigger the usage function
        rapidtide2x_workflow.usage()

        # and launch the processing
        theargs = ["rapidtide2x"]
        theargs += [os.path.join(get_examples_path(), "fmri.nii.gz")]
        theargs += [
            os.path.join(get_test_temp_path(), "rapidtide2x_phase3output")
        ]
        theargs += ["--nowindow"]
        theargs += ["--windowfunc=hamming"]
        theargs += ["--liang", "--eckart", "--phat"]
        theargs += ["--usesp"]
        theargs += ["--preservefiltering"]
        theargs += ["--corrmaskthresh=0.25"]
        theargs += ["-I", "-B", "-a", "-M", "-m"]
        theargs += ["-C", "-R", "-L", "-V", "-F", "0.01,0.08"]
        theargs += ["-v", "--debug"]
        theargs += ["--globalmaskmethod=mean"]
        theargs += ["--mklthreads=1"]
        theargs += ["--nosharedmem"]
        theargs += ["-S"]
        rapidtide2x_workflow.rapidtide_main(theargs)
    assert True
def test_rapidtide2x_phase3(debug=False):
    recalculate = True
    if recalculate:
        # create outputdir if it doesn't exist
        create_dir(get_test_temp_path())

        # trigger the usage function
        rapidtide2x_workflow.usage()

        # and launch the processing
        theargs = ['rapidtide2x']
        theargs += [os.path.join(get_examples_path(), 'fmri.nii.gz')]
        theargs += [
            os.path.join(get_test_temp_path(), 'rapidtide2x_phase3output')
        ]
        theargs += ['--nowindow']
        theargs += ['--windowfunc=hamming']
        theargs += ['--liang', '--eckart', '--phat']
        theargs += ['--usesp']
        theargs += ['--preservefiltering']
        theargs += ['--corrmaskthresh=0.25']
        theargs += ['-I', '-B', '-a', '-M', '-m']
        theargs += ['-C', '-R', '-L', '-V', '-F', '0.01,0.08']
        theargs += ['-v', '--debug']
        theargs += ['--globalmaskmethod=mean']
        theargs += ['--mklthreads=1']
        theargs += ['--nosharedmem']
        theargs += ['-S']
        rapidtide2x_workflow.rapidtide_main(theargs)
    assert True
Exemple #3
0
def test_rapidtide2x(debug=False):
    recalculate = True
    if recalculate:
        # create outputdir if it doesn't exist
        create_dir(get_test_temp_path())

        # and launch the processing
        theargs = ["rapidtide2x"]
        theargs += [os.path.join(get_examples_path(), "fmri.nii.gz")]
        theargs += [
            os.path.join(get_test_temp_path(), "rapidtide2x_phase2output")
        ]
        theargs += [
            "--regressor=" +
            os.path.join(get_test_data_path(),
                         "rapidtide2x_phase1target_reference_fmrires.txt")
        ]
        theargs += ["--regressortstep=1.5"]
        theargs += ["--limitoutput"]
        theargs += ["-s", "25.0"]
        theargs += ["-L"]
        theargs += ["-r", "-20,20"]
        theargs += ["-f", "2"]
        theargs += ["--passes=3"]
        theargs += ["--refineoffset"]
        theargs += ["--despecklepasses=4"]
        theargs += ["--accheck"]
        theargs += ["--nprocs=2"]
        theargs += ["--saveoptionsasjson"]
        theargs += ["--detrendorder=3"]
        theargs += ["--pickleft"]
        theargs += [
            "--corrmask=" +
            os.path.join(get_examples_path(), "quartermask.nii.gz")
        ]
        theargs += ["--noglm"]
        rapidtide2x_workflow.rapidtide_main(theargs)

    diffmaps = tide_util.comparerapidtideruns(
        os.path.join(get_test_temp_path(), "rapidtide2x_phase2output"),
        os.path.join(get_test_target_path(), "rapidtide2x_phase2target"),
    )

    for mapname, maps in diffmaps.items():
        print("checking", mapname)
        print("\trelmindiff", maps["relmindiff"])
        print("\trelmaxdiff", maps["relmaxdiff"])
        print("\trelmeandiff", maps["relmeandiff"])
        print("\trelmse", maps["relmse"])
        assert maps["relmindiff"] < 1e2
        assert maps["relmaxdiff"] < 1e2
        assert maps["relmeandiff"] < 1e-2
        assert maps["relmse"] < 1e2
Exemple #4
0
def test_stcorrelate(debug=False):
    tr = 0.72
    testlen = 800
    shiftdist = 5
    windowtime = 30.0
    stepsize = 5.0
    corrweighting = "None"
    outfilename = op.join(get_test_temp_path(), "stcorrtest")

    # create outputdir if it doesn't exist
    create_dir(get_test_temp_path())

    dodetrend = True
    timeaxis = np.arange(0.0, 1.0 * testlen) * tr

    testfilter = NoncausalFilter(filtertype="lfo")
    sig1 = testfilter.apply(1.0 / tr, np.random.random(testlen))
    sig2 = np.float64(np.roll(sig1, int(shiftdist)))

    if debug:
        plt.figure()
        plt.plot(sig1)
        plt.plot(sig2)
        legend = ["Original", "Shifted"]
        plt.show()

    times, corrpertime, ppertime = shorttermcorr_1D(sig1,
                                                    sig2,
                                                    tr,
                                                    windowtime,
                                                    samplestep=int(stepsize //
                                                                   tr),
                                                    detrendorder=0)
    plength = len(times)
    times, xcorrpertime, Rvals, delayvals, valid = shorttermcorr_2D(
        sig1,
        sig2,
        tr,
        windowtime,
        samplestep=int(stepsize // tr),
        weighting=corrweighting,
        detrendorder=0,
        display=False,
    )
    xlength = len(times)
    writenpvecs(corrpertime, outfilename + "_pearson.txt")
    writenpvecs(ppertime, outfilename + "_pvalue.txt")
    writenpvecs(Rvals, outfilename + "_Rvalue.txt")
    writenpvecs(delayvals, outfilename + "_delay.txt")
    writenpvecs(valid, outfilename + "_mask.txt")
def test_rapidtide2x(debug=False):
    recalculate = True
    if recalculate:
        # create outputdir if it doesn't exist
        create_dir(get_test_temp_path())
    
        # and launch the processing
        theargs = ['rapidtide2x']
        theargs += [os.path.join(get_examples_path(), 'fmri.nii.gz')]
        theargs += [os.path.join(get_test_temp_path(), 'rapidtide2x_phase2output')]
        theargs += ['--regressor=' + os.path.join(get_test_data_path(), 'rapidtide2x_phase1target_reference_fmrires.txt')]
        theargs += ['--regressortstep=1.5']
        theargs += ['--limitoutput']
        theargs += ['-s', '25.0']
        theargs += ['-L']
        theargs += ['-r', '-20,20']
        theargs += ['-f', '2']
        theargs += ['--passes=3']
        theargs += ['--refineoffset']
        theargs += ['--despecklepasses=4']
        theargs += ['--accheck']
        theargs += ['--nprocs=2']
        theargs += ['--saveoptionsasjson']
        theargs += ['--detrendorder=3']
        theargs += ['--pickleft']
        theargs += ['--corrmask=' + os.path.join(get_examples_path(), 'quartermask.nii.gz')]
        theargs += ['--noglm']
        rapidtide2x_workflow.rapidtide_main(theargs)
    
    diffmaps = tide_util.comparerapidtideruns(os.path.join(get_test_temp_path(), 'rapidtide2x_phase2output'), os.path.join(get_test_target_path(), 'rapidtide2x_phase2target'))

    for mapname, maps in diffmaps.items():
        print('checking', mapname)
        print('\trelmindiff', maps['relmindiff'])
        print('\trelmaxdiff', maps['relmaxdiff'])
        print('\trelmeandiff', maps['relmeandiff'])
        print('\trelmse', maps['relmse'])
        assert maps['relmindiff'] < 1e2
        assert maps['relmaxdiff'] < 1e2
        assert maps['relmeandiff'] < 1e-2
        assert maps['relmse'] < 1e2
Exemple #6
0
def test_happy_phase1(debug=False):
    recalculate = True
    if recalculate:
        # create outputdir if it doesn't exist
        create_dir(get_test_temp_path())

        # and launch the processing
        theargs = ["happy"]
        theargs += [os.path.join(get_examples_path(), "happyfmri.nii.gz")]
        theargs += [os.path.join(get_examples_path(), "happyfmri.json")]
        theargs += [os.path.join(get_test_temp_path(), "happy_output")]
        theargs += ["--dodlfilter"]
        theargs += ["--saveinfoasjson"]
        theargs += ["--glm"]
        theargs += ["--numskip=0"]
        theargs += ["--gridbins=2.0"]
        theargs += ["--gridkernel=kaiser"]
        theargs += ["--model=model_revised"]
        print(" ".join(theargs))
        happy_workflow.happy_main(theargs)

    diffmaps = tide_util.comparehappyruns(
        os.path.join(get_test_temp_path(), "happy_output"),
        os.path.join(get_test_target_path(), "happy_target"),
        debug=debug,
    )

    for mapname, maps in diffmaps.items():
        print("checking", mapname)
        print("\trelmindiff", maps["relmindiff"])
        print("\trelmaxdiff", maps["relmaxdiff"])
        print("\trelmeandiff", maps["relmeandiff"])
        print("\trelmse", maps["relmse"])
        assert maps["relmindiff"] < 1e2
        assert maps["relmaxdiff"] < 1e2
        assert maps["relmeandiff"] < 1e-2
        assert maps["relmse"] < 1e2
Exemple #7
0
def test_io(debug=True, display=False):

    # create outputdir if it doesn't exist
    create_dir(get_test_temp_path())

    # test checkifnifti
    assert tide_io.checkifnifti("test.nii") == True
    assert tide_io.checkifnifti("test.nii.gz") == True
    assert tide_io.checkifnifti("test.txt") == False

    # test checkiftext
    assert tide_io.checkiftext("test.nii") == False
    assert tide_io.checkiftext("test.nii.gz") == False
    assert tide_io.checkiftext("test.txt") == True

    # test getniftiroot
    assert tide_io.getniftiroot("test.nii") == "test"
    assert tide_io.getniftiroot("test.nii.gz") == "test"
    assert tide_io.getniftiroot("test.txt") == "test.txt"

    # test fmritimeinfo
    fmritimeinfothresh = 1e-2
    tr, timepoints = tide_io.fmritimeinfo(
        os.path.join(get_examples_path(), "sub-HAPPYTEST.nii.gz"))
    assert np.fabs(tr - 1.16) < fmritimeinfothresh
    assert timepoints == 110
    tr, timepoints = tide_io.fmritimeinfo(
        os.path.join(get_examples_path(), "sub-RAPIDTIDETEST.nii.gz"))
    assert np.fabs(tr - 1.5) < fmritimeinfothresh
    assert timepoints == 260

    # test niftifile reading
    sizethresh = 1e-3
    happy_img, happy_data, happy_hdr, happydims, happysizes = tide_io.readfromnifti(
        os.path.join(get_examples_path(), "sub-HAPPYTEST.nii.gz"))
    fmri_img, fmri_data, fmri_hdr, fmridims, fmrisizes = tide_io.readfromnifti(
        os.path.join(get_examples_path(), "sub-RAPIDTIDETEST.nii.gz"))
    targetdims = [4, 65, 89, 64, 110, 1, 1, 1]
    targetsizes = [-1.00, 2.39583, 2.395830, 2.4, 1.16, 0.00, 0.00, 0.00]
    if debug:
        print("happydims:", happydims)
        print("targetdims:", targetdims)
        print("happysizes:", happysizes)
        print("targetsizes:", targetsizes)
    for i in range(len(targetdims)):
        assert targetdims[i] == happydims[i]
    assert mse(np.array(targetsizes), np.array(happysizes)) < sizethresh

    # test file writing
    datathresh = 2e-3  # relaxed threshold because sub-RAPIDTIDETEST has been converted to INT16
    tide_io.savetonifti(
        fmri_data, fmri_hdr,
        os.path.join(get_test_temp_path(), "sub-RAPIDTIDETEST_copy.nii.gz"))
    (
        fmricopy_img,
        fmricopy_data,
        fmricopy_hdr,
        fmricopydims,
        fmricopysizes,
    ) = tide_io.readfromnifti(
        os.path.join(get_test_temp_path(), "sub-RAPIDTIDETEST_copy.nii.gz"))
    assert tide_io.checkspacematch(fmri_hdr, fmricopy_hdr)
    assert tide_io.checktimematch(fmridims, fmridims)
    assert mse(fmri_data, fmricopy_data) < datathresh

    # test file header comparisons
    assert tide_io.checkspacematch(happy_hdr, happy_hdr)
    assert not tide_io.checkspacematch(happy_hdr, fmri_hdr)
    assert tide_io.checktimematch(happydims, happydims)
    assert not tide_io.checktimematch(happydims, fmridims)