Example #1
0
def test_idxiter():
    n_channels = data.shape[0]
    # Upper-triangular part, including diag
    idx0, idx1 = np.triu_indices(n_channels)
    triu_indices = np.array([np.arange(idx0.size), idx0, idx1])
    triu_indices2 = np.array(list(_idxiter(n_channels, include_diag=True)))
    # Upper-triangular part, without diag
    idx2, idx3 = np.triu_indices(n_channels, 1)
    triu_indices_nodiag = np.array([np.arange(idx2.size), idx2, idx3])
    triu_indices2_nodiag = np.array(list(_idxiter(n_channels,
                                                  include_diag=False)))
    assert_almost_equal(triu_indices, triu_indices2.transpose())
    assert_almost_equal(triu_indices_nodiag, triu_indices2_nodiag.transpose())
    # Upper and lower-triangular parts, without diag
    expected = [(i, j) for _, (i, j) in
                enumerate(np.ndindex((n_channels, n_channels))) if i != j]
    assert_equal(np.array([(i, j) for _, i, j in _idxiter(n_channels,
                                                          triu=False)]),
                 expected)
Example #2
0
def test_channel_naming_bivariate(selected_func, include_diag):
    ch_names = ['CHANNEL%s' % i for i in range(n_channels)]
    ch_names[:4] = ['Cz', 'FCz', 'P1', 'CP1']
    func_params = {selected_func + '__include_diag': include_diag}
    df = extract_features(
        data, sfreq, [selected_func], func_params, ch_names=ch_names,
        return_as_df=True)
    expected_col_names = [
        (selected_func, ch_names[i] + '-' + ch_names[j])
        for s, i, j in _idxiter(n_channels, include_diag=include_diag)]

    assert df.columns.values.tolist() == expected_col_names
Example #3
0
def test_channel_naming_pow_freq_bands():
    ch_names = ['CHANNEL%s' % i for i in range(n_channels)]
    ch_names[:4] = ['Cz', 'FCz', 'P1', 'CP1']
    selected_funcs = ['pow_freq_bands']
    func_params = {
        'pow_freq_bands__freq_bands': np.array([[0, 2], [10, 20]]),
        'pow_freq_bands__ratios': 'only'
    }
    df = extract_features(
        data, sfreq, selected_funcs, func_params, ch_names=ch_names,
        return_as_df=True)

    expected_col_names = [
        ('pow_freq_bands', f'{ch_name}_band{i}/band{j}')
        for ch_name in ch_names for _, i, j in _idxiter(2, triu=False)]
    assert df.columns.values.tolist() == expected_col_names