コード例 #1
0
ファイル: test_afni.py プロジェクト: Shotgunosine/fitlins
def test_get_afni_design_matrix():
    contrast_info = [{
        "entities": {
            "space": "MNI152NLin2009cAsym",
            "subject": "01",
            "task": "rhymejudgment",
        },
        "name":
        "a_test",
        "type":
        "F",
        "weights": [
            {
                "trial_type.pseudoword": 2,
                "trial_type.word": 5
            },
            {
                "trial_type.pseudoword": 1,
                "trial_type.word": -5
            },
        ],
    }]
    design = pd.DataFrame({
        "trial_type.pseudoword": [11.2, 1],
        "trial_type.word": [20, -1],
        "noise": [7, 7],
        "drift": [1, 2],
    })
    contrasts = prepare_contrasts(contrast_info, design.columns.tolist())
    t_r = 2
    stim_labels = ["trial_type.pseudoword", "trial_type.word"]
    stim_labels_with_tag = ['stim_' + sl for sl in stim_labels]
    test_info = create_glt_test_info(design, contrasts)
    design_vals = design.to_csv(sep=" ", index=False, header=False)
    cols = "; ".join(design.columns)

    expected = f"""\
        # <matrix
        # ni_type = "{design.shape[1]}*double"
        # ni_dimen = "{design.shape[0]}"
        # RowTR = "{t_r}"
        # GoodList = "0..{design.shape[0] - 1}"
        # NRowFull = "{design.shape[0]}"
        # CommandLine = "{' '.join(sys.argv)}"
        # ColumnLabels = "{cols}"
        # {test_info}
        # Nstim = 2
        # StimBots = "0; 1"
        # StimTops = "0; 1"
        # StimLabels = "{'; '.join(stim_labels_with_tag)}"
        # >
        {design_vals}
        # </matrix>
        """
    expected = "\n".join([x.lstrip() for x in expected.splitlines()])
    assert expected == get_afni_design_matrix(design, contrasts, stim_labels,
                                              t_r)
コード例 #2
0
ファイル: test_nistats.py プロジェクト: poldracklab/fitlins
def test_prepare_contrasts():
    contrasts = [
        {
            "name": "a",
            "conditions": ["x", "y"],
            "weights": [1, -1],
            "test": "t",
            "entities": {},
        },
        {
            "name": "b",
            "conditions": ["y", "z"],
            "weights": [1, -1],
            "test": "t",
            "entities": {},
        },
        {
            "name": "c",
            "conditions": ["x", "z"],
            "weights": [[1, 0], [0, 1]],
            "test": "F",
            "entities": {},
        },
        {
            "name": "d",
            "conditions": ["z", "y", "x"],
            "weights": [-0.5, -0.5, 1],
            "test": "t",
            "entities": {},
        },
    ]
    all_regressors = ["x", "y", "z"]
    ret = prepare_contrasts(contrasts, all_regressors)
    assert len(ret) == 4
    assert ret[0][::3] == ("a", "t")
    assert ret[1][::3] == ("b", "t")
    assert ret[2][::3] == ("c", "F")
    assert ret[3][::3] == ("d", "t")
    # Adding columns
    assert np.array_equal(ret[0][1], np.array([[1, -1, 0]]))
    assert np.array_equal(ret[1][1], np.array([[0, 1, -1]]))
    assert np.array_equal(ret[2][1], np.array([[1, 0, 0], [0, 0, 1]]))
    # Reordering columns
    assert np.array_equal(ret[3][1], np.array([[1, -0.5, -0.5]]))
コード例 #3
0
ファイル: test_afni.py プロジェクト: Shotgunosine/fitlins
def test_create_glt_test_info():

    contrast_info = [{
        "entities": {
            "space": "MNI152NLin2009cAsym",
            "subject": "01",
            "task": "rhymejudgment",
        },
        "name":
        "a_test",
        "type":
        "F",
        "weights": [
            {
                "trial_type.pseudoword": 2,
                "trial_type.word": 5
            },
            {
                "trial_type.pseudoword": 1,
                "trial_type.word": -5
            },
        ],
    }]
    design = pd.DataFrame({
        "trial_type.pseudoword": [11.2, 1],
        "trial_type.word": [20, -1],
        "noise": [7, 7],
        "drift": [1, 2],
    })
    contrasts = prepare_contrasts(contrast_info, design.columns.tolist())

    expected = """
# Nglt = "1"
# GltLabels = "a_test"
# GltMatrix_000000 = "2; 4; 2; 5; 0; 0; 1; -5; 0; 0; "\
"""
    assert expected == create_glt_test_info(design, contrasts)
コード例 #4
0
def test_create_glt_test_info():

    entities = {
        "space": "MNI152NLin2009cAsym",
        "subject": "01",
        "task": "rhymejudgment",
    }

    contrast_info = [
        ContrastInfo(
            'a_test',
            ['trial_type.pseudoword', 'trial_type.word'],
            [[2, 5], [1, -5]],
            'F',
            entities,
        )
    ]

    design = pd.DataFrame(
        {
            "trial_type.pseudoword": [11.2, 1],
            "trial_type.word": [20, -1],
            "noise": [7, 7],
            "drift": [1, 2],
        }
    )

    contrast_info = [c._asdict().copy() for c in contrast_info]
    contrasts = prepare_contrasts(contrast_info, design.columns.tolist())

    expected = """
# Nglt = "1"
# GltLabels = "a_test"
# GltMatrix_000000 = "2; 4; 2; 5; 0; 0; 1; -5; 0; 0; "\
"""
    assert expected == create_glt_test_info(design, contrasts)