コード例 #1
0
def dummy_test(infile, expfile):

    ifile = open(infile, "br")
    Din = pickle.load(ifile)
    ifile.close()

    Y = Din["Y"]
    M = Din["M"]

    # Convert M to a true BrainStat model
    fixed_effects = FixedEffect(M[:, Din["n_random"]:])
    if Din["n_random"] != 0:
        mixed_effects = MixedEffect(
            M[:, :Din["n_random"]],
            name_ran=["f" + str(x) for x in range(Din["n_random"])],
        )
        M = fixed_effects + mixed_effects
    else:
        M = fixed_effects

    # assign slm params
    slm = SLM(M, FixedEffect(1), surf=Din["surf"])

    # here we go --> run the linear model
    slm._linear_model(Y)

    ofile = open(expfile, "br")
    Dout = pickle.load(ofile)
    ofile.close()

    # compare...
    testout = []

    for k, v in Dout.items():
        if k == "surf":
            # Surface data is only stored for reconstruction in MATLAB.
            continue

        a = getattr(slm, k)

        comp = np.allclose(a, v, rtol=1e-05, equal_nan=True)
        testout.append(comp)
    assert all(testout)
コード例 #2
0
ファイル: test_t_test.py プロジェクト: MICA-MNI/BrainStat
def dummy_test(infile, expfile):

    # load input test data
    ifile = open(infile, "br")
    idic = pickle.load(ifile)
    ifile.close()

    model = array2effect(idic["M"], idic["n_random"])
    contrast = -idic["M"][:, -1]

    # run _t_test
    slm = SLM(model, contrast, idic["surf"])
    slm._linear_model(idic["Y"])
    slm._t_test()

    # load expected outout data
    efile = open(expfile, "br")
    expdic = pickle.load(efile)
    efile.close()

    testout = []
    for key in expdic.keys():
        if isinstance(expdic[key], dict):
            slm_sub_dict = getattr(slm, key)
            exp_sub_dict = expdic[key]
            comp = np.all([
                np.allclose(slm_sub_dict[x], exp_sub_dict[x])
                for x in exp_sub_dict.keys()
            ])
        else:
            comp = np.allclose(getattr(slm, key),
                               expdic[key],
                               rtol=1e-05,
                               equal_nan=True)
            testout.append(comp)

    assert all(flag == True for (flag) in testout)