def test_label_connnectivity(): labels = _generate_labels([np.arange(12), np.arange(12)], 4) pairs = [[0, 0, 1, 2], [1, 2, 3, 3]] data = [0, 0.5, 0.75, 1] # Incorrect input with pytest.raises(ValueError): LabelConnectivity(data, pairs, labels[0]) label_con = LabelConnectivity(data, pairs, labels) assert label_con.n_sources == 4 assert_array_equal(label_con.source_degree, ([2, 1, 1, 0], [0, 1, 1, 2])) # Test set state state = { 'data': np.array([1, 1, 1]), 'pairs': [[0, 0, 1], [1, 2, 2]], 'labels': [[np.arange(4), None, None, 'lh', '', 'Label1'], [np.arange(4, 8), None, None, 'lh', '', 'Label2'], [np.arange(8, 12), None, None, 'lh', '', 'Label3']], 'n_sources': 3, 'subject': None, 'directed': False } label_con.__setstate__(state) assert label_con.n_sources == 3 assert_array_equal(label_con.labels[0].vertices, np.arange(4))
def test_compatibility(): """Test _iscombatible function""" baseCon = _make_base_connectivity() all_con = _make_alltoall_connectivity() label_con = _make_label_connectivity() # Test BaseConnectivity assert not baseCon.is_compatible(label_con) assert not baseCon.is_compatible(all_con) baseCon2 = _BaseConnectivity(np.array([6, 7, 8, 9, 10]), baseCon.pairs, baseCon.n_sources) assert baseCon.is_compatible(baseCon2) # Test VertexConnectivity assert not all_con.is_compatible(label_con) all_con2 = VertexConnectivity(np.array([4, 5, 6]), all_con.pairs, all_con.vertices) assert all_con.is_compatible(all_con2) # Test label_connectivity assert not label_con.is_compatible(all_con) label_con2 = LabelConnectivity(np.array([3, 4, 5]), pairs=label_con.pairs, labels=label_con.labels) assert label_con.is_compatible(label_con2)
def _make_label_connectivity(): labels = [Label(vertices=np.arange(3), hemi='lh', name='Label1'), Label(vertices=np.arange(3, 6), hemi='lh', name='Label2'), Label(vertices=np.arange(6, 9), hemi='lh', name='Label3')] pairs = [[0, 0, 1], [1, 2, 2]] data = np.arange(len(pairs[1])) return LabelConnectivity(data, pairs, labels)