コード例 #1
0
ファイル: test_stats.py プロジェクト: oxpeter/scikit-allel
 def test_patterson_d(self):
     aca = [[0, 2],
            [2, 0],
            [2, 0],
            [1, 1],
            [0, 0]]
     acb = [[0, 2],
            [0, 2],
            [0, 2],
            [1, 1],
            [0, 2]]
     acc = [[2, 0],
            [2, 0],
            [0, 2],
            [1, 1],
            [0, 2]]
     acd = [[2, 0],
            [0, 2],
            [2, 0],
            [1, 1],
            [0, 2]]
     num, den = allel.stats.patterson_d(aca, acb, acc, acd)
     expect_num = [0., 1., -1., 0., np.nan]
     expect_den = [0., 1., 1., 0.25, np.nan]
     assert_array_nanclose(expect_num, num)
     assert_array_nanclose(expect_den, den)
コード例 #2
0
ファイル: test_stats.py プロジェクト: quank/scikit-allel
 def test_patterson_d(self):
     aca = [[0, 2],
            [2, 0],
            [2, 0],
            [1, 1],
            [0, 0]]
     acb = [[0, 2],
            [0, 2],
            [0, 2],
            [1, 1],
            [0, 2]]
     acc = [[2, 0],
            [2, 0],
            [0, 2],
            [1, 1],
            [0, 2]]
     acd = [[2, 0],
            [0, 2],
            [2, 0],
            [1, 1],
            [0, 2]]
     num, den = allel.patterson_d(aca, acb, acc, acd)
     expect_num = [0., 1., -1., 0., np.nan]
     expect_den = [0., 1., 1., 0.25, np.nan]
     assert_array_nanclose(expect_num, num)
     assert_array_nanclose(expect_den, den)
コード例 #3
0
def test_nsl01_scan_int8_c():

    h = np.array([[0, 0, 1], [0, 1, 1], [1, 1, 0], [1, 0, 0]], dtype='i1')
    nsl0, nsl1 = nsl01_scan_int8(h)
    expect_nsl0 = [1, np.nan, np.nan, 1]
    assert_array_nanclose(expect_nsl0, nsl0)
    expect_nsl1 = [np.nan, 1, 1, np.nan]
    assert_array_nanclose(expect_nsl1, nsl1)
コード例 #4
0
def test_nsl01_scan_b():

    h = np.array([[0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0], [1, 0, 0, 0]])
    nsl0, nsl1 = nsl01_scan(h)
    expect_nsl0 = [1, 4 / 3, 4 / 3, 4 / 3]
    assert_array_nanclose(expect_nsl0, nsl0)
    expect_nsl1 = [np.nan, np.nan, np.nan, np.nan]
    assert_array_nanclose(expect_nsl1, nsl1)
コード例 #5
0
def test_nsl01_scan_a():

    h = np.array([[0, 0, 0, 1, 1, 1], [0, 0, 0, 1, 1, 1], [0, 0, 0, 1, 1, 1],
                  [0, 0, 0, 1, 1, 1]])
    nsl0, nsl1 = nsl01_scan(h)
    expect_nsl0 = [1, 2, 3, 4]
    assert_array_nanclose(expect_nsl0, nsl0)
    expect_nsl1 = [1, 2, 3, 4]
    assert_array_nanclose(expect_nsl1, nsl1)
コード例 #6
0
def test_nsl01_scan_int8_a():

    h = np.array([[0, 0, 0, 1, 1, 1], [0, 0, 0, 1, 1, 1], [0, 0, 0, 1, 1, 1],
                  [0, 0, 0, 1, 1, 1]],
                 dtype='i1')
    nsl0, nsl1 = nsl01_scan_int8(h)
    expect_nsl0 = [1, 2, 3, 4]
    assert_array_nanclose(expect_nsl0, nsl0)
    expect_nsl1 = [1, 2, 3, 4]
    assert_array_nanclose(expect_nsl1, nsl1)
コード例 #7
0
def test_nsl01_scan_int8_a():

    h = np.array([[0, 0, 0, 1, 1, 1],
                  [0, 0, 0, 1, 1, 1],
                  [0, 0, 0, 1, 1, 1],
                  [0, 0, 0, 1, 1, 1]], dtype='i1')
    nsl0, nsl1 = nsl01_scan_int8(h)
    expect_nsl0 = [1, 2, 3, 4]
    assert_array_nanclose(expect_nsl0, nsl0)
    expect_nsl1 = [1, 2, 3, 4]
    assert_array_nanclose(expect_nsl1, nsl1)
コード例 #8
0
def test_nsl01_scan_int8_c():

    h = np.array([[0, 0, 1],
                  [0, 1, 1],
                  [1, 1, 0],
                  [1, 0, 0]], dtype='i1')
    nsl0, nsl1 = nsl01_scan_int8(h)
    expect_nsl0 = [1, np.nan, np.nan, 1]
    assert_array_nanclose(expect_nsl0, nsl0)
    expect_nsl1 = [np.nan, 1, 1, np.nan]
    assert_array_nanclose(expect_nsl1, nsl1)
コード例 #9
0
ファイル: test_stats.py プロジェクト: oxpeter/scikit-allel
 def test_patterson_f2(self):
     aca = [[0, 2],
            [2, 0],
            [1, 1],
            [0, 0]]
     acb = [[0, 2],
            [0, 2],
            [0, 2],
            [0, 2]]
     expect = [0., 1., 0., np.nan]
     actual = allel.stats.patterson_f2(aca, acb)
     assert_array_nanclose(expect, actual)
コード例 #10
0
def test_ihh_scan_d():
    # edge case: start from 0 haplotype homozygosity
    gaps = np.array([10], dtype='f8')
    h = np.array([[0, 1], [1, 0]])

    expect = [0, 0]
    actual = ihh_scan(h, gaps, min_ehh=0, include_edges=False)
    assert_array_nanclose(expect, actual)

    expect = [0, 0]
    actual = ihh_scan(h, gaps, min_ehh=0, include_edges=True)
    assert_array_nanclose(expect, actual)
コード例 #11
0
ファイル: test_stats.py プロジェクト: quank/scikit-allel
 def test_patterson_f2(self):
     aca = [[0, 2],
            [2, 0],
            [1, 1],
            [0, 0]]
     acb = [[0, 2],
            [0, 2],
            [0, 2],
            [0, 2]]
     expect = [0., 1., 0., np.nan]
     actual = allel.patterson_f2(aca, acb)
     assert_array_nanclose(expect, actual)
コード例 #12
0
def test_ihh_scan_int8_d():
    # edge case: start from 0 haplotype homozygosity
    gaps = np.array([10], dtype='f8')
    h = np.array([[0, 1],
                  [1, 0]], dtype='i1')

    expect = [0, 0]
    actual = ihh_scan_int8(h, gaps, min_ehh=0, include_edges=False)
    assert_array_nanclose(expect, actual)

    expect = [0, 0]
    actual = ihh_scan_int8(h, gaps, min_ehh=0, include_edges=True)
    assert_array_nanclose(expect, actual)
コード例 #13
0
def test_ihh_scan_a():
    # simple case: 1 haplotype pair, haplotype homozygosity over all variants
    gaps = np.array([10, 10], dtype='f8')
    h = np.array([[0, 0], [0, 0], [0, 0]])

    # do not include edges
    expect = [np.nan, np.nan, np.nan]
    actual = ihh_scan(h, gaps, min_ehh=0, include_edges=False)
    assert_array_nanclose(expect, actual)

    # include edges
    expect = [0, 10, 20]
    actual = ihh_scan(h, gaps, min_ehh=0, include_edges=True)
    assert_array_nanclose(expect, actual)
コード例 #14
0
def test_ihh_scan_c():
    # simple case: 1 haplotype pair, haplotype homozygosity decays
    gaps = np.array([10, 10], dtype='f8')
    h = np.array([[0, 1], [0, 0], [0, 0]])

    # do not include edges
    expect = [0, 5, 15]
    actual = ihh_scan(h, gaps, min_ehh=0, include_edges=False)
    assert_array_nanclose(expect, actual)

    # include edges
    expect = [0, 5, 15]
    actual = ihh_scan(h, gaps, min_ehh=0, include_edges=True)
    assert_array_nanclose(expect, actual)
コード例 #15
0
def test_ihh_scan_b():
    # 1 haplotype pair, haplotype homozygosity over all variants
    # handling of large gap (encoded as -1)
    gaps = np.array([10, -1], dtype='f8')
    h = np.array([[0, 0], [0, 0], [0, 0]])

    # do not include edges
    expect = [np.nan, np.nan, np.nan]
    actual = ihh_scan(h, gaps, min_ehh=0, include_edges=False)
    assert_array_nanclose(expect, actual)

    # include edges
    expect = [0, 10, np.nan]
    actual = ihh_scan(h, gaps, min_ehh=0, include_edges=True)
    assert_array_nanclose(expect, actual)
コード例 #16
0
def test_ihh_scan_int8_c():
    # simple case: 1 haplotype pair, haplotype homozygosity decays
    gaps = np.array([10, 10], dtype='f8')
    h = np.array([[0, 1],
                  [0, 0],
                  [0, 0]], dtype='i1')

    # do not include edges
    expect = [0, 5, 15]
    actual = ihh_scan_int8(h, gaps, min_ehh=0, include_edges=False)
    assert_array_nanclose(expect, actual)

    # include edges
    expect = [0, 5, 15]
    actual = ihh_scan_int8(h, gaps, min_ehh=0, include_edges=True)
    assert_array_nanclose(expect, actual)
コード例 #17
0
def test_ihh_scan_int8_b():
    # 1 haplotype pair, haplotype homozygosity over all variants
    # handling of large gap (encoded as -1)
    gaps = np.array([10, -1], dtype='f8')
    h = np.array([[0, 0],
                  [0, 0],
                  [0, 0]], dtype='i1')

    # do not include edges
    expect = [np.nan, np.nan, np.nan]
    actual = ihh_scan_int8(h, gaps, min_ehh=0, include_edges=False)
    assert_array_nanclose(expect, actual)

    # include edges
    expect = [0, 10, np.nan]
    actual = ihh_scan_int8(h, gaps, min_ehh=0, include_edges=True)
    assert_array_nanclose(expect, actual)
コード例 #18
0
ファイル: test_stats.py プロジェクト: quank/scikit-allel
 def test_patterson_f3(self):
     aca = [[0, 2],
            [2, 0],
            [0, 2],
            [0, 2],
            [0, 0]]
     acb = [[2, 0],
            [0, 2],
            [0, 2],
            [0, 2],
            [0, 2]]
     acc = [[1, 1],
            [1, 1],
            [0, 2],
            [2, 0],
            [1, 1]]
     expect_f3 = [-.5, -.5, 0., 1., np.nan]
     actual_f3, actual_hzc = allel.patterson_f3(acc, aca, acb)
     assert_array_nanclose(expect_f3, actual_f3)
     expect_hzc = [1., 1., 0., 0., 1.]
     assert_array_nanclose(expect_hzc, actual_hzc)
コード例 #19
0
ファイル: test_stats.py プロジェクト: oxpeter/scikit-allel
 def test_patterson_f3(self):
     aca = [[0, 2],
            [2, 0],
            [0, 2],
            [0, 2],
            [0, 0]]
     acb = [[2, 0],
            [0, 2],
            [0, 2],
            [0, 2],
            [0, 2]]
     acc = [[1, 1],
            [1, 1],
            [0, 2],
            [2, 0],
            [1, 1]]
     expect_f3 = [-.5, -.5, 0., 1., np.nan]
     actual_f3, actual_hzc = allel.stats.patterson_f3(acc, aca, acb)
     assert_array_nanclose(expect_f3, actual_f3)
     expect_hzc = [1., 1., 0., 0., 1.]
     assert_array_nanclose(expect_hzc, actual_hzc)
コード例 #20
0
def test_ihh01_scan_a():
    gaps = np.array([10, 10, 10], dtype='f8')
    h = np.array([[0, 0, 1], [0, 1, 1], [1, 1, 0], [1, 0, 0]])

    ihh0, ihh1 = ihh01_scan(h, gaps, min_ehh=0.05, include_edges=False)
    expect_ihh0 = [np.nan, np.nan, np.nan, 5]
    assert_array_nanclose(expect_ihh0, ihh0)
    expect_ihh1 = [np.nan, 5, 5, np.nan]
    assert_array_nanclose(expect_ihh1, ihh1)

    ihh0, ihh1 = ihh01_scan(h, gaps, min_ehh=0, include_edges=True)
    expect_ihh0 = [0, np.nan, np.nan, 5]
    assert_array_nanclose(expect_ihh0, ihh0)
    expect_ihh1 = [np.nan, 5, 5, np.nan]
    assert_array_nanclose(expect_ihh1, ihh1)
コード例 #21
0
def test_ihh01_scan_int8_c():
    gaps = np.array([10, 10, 10], dtype='f8')
    h = np.array([[0, 0, 0, 1, 1, 1], [0, 0, 0, 1, 1, 1], [0, 0, 0, 1, 1, 1],
                  [0, 0, 0, 1, 1, 1]],
                 dtype='i1')

    ihh0, ihh1 = ihh01_scan_int8(h, gaps, min_ehh=0.05)
    expect_ihh0 = [np.nan, np.nan, np.nan, np.nan]
    assert_array_nanclose(expect_ihh0, ihh0)
    expect_ihh1 = [np.nan, np.nan, np.nan, np.nan]
    assert_array_nanclose(expect_ihh1, ihh1)

    ihh0, ihh1 = ihh01_scan_int8(h, gaps, min_ehh=0, include_edges=True)
    expect_ihh0 = [0, 10, 20, 30]
    assert_array_nanclose(expect_ihh0, ihh0)
    expect_ihh1 = [0, 10, 20, 30]
    assert_array_nanclose(expect_ihh1, ihh1)
コード例 #22
0
def test_ihh01_scan_int8_c():
    gaps = np.array([10, 10, 10], dtype='f8')
    h = np.array([[0, 0, 0, 1, 1, 1],
                  [0, 0, 0, 1, 1, 1],
                  [0, 0, 0, 1, 1, 1],
                  [0, 0, 0, 1, 1, 1]], dtype='i1')

    ihh0, ihh1 = ihh01_scan_int8(h, gaps, min_ehh=0.05)
    expect_ihh0 = [np.nan, np.nan, np.nan, np.nan]
    assert_array_nanclose(expect_ihh0, ihh0)
    expect_ihh1 = [np.nan, np.nan, np.nan, np.nan]
    assert_array_nanclose(expect_ihh1, ihh1)

    ihh0, ihh1 = ihh01_scan_int8(h, gaps, min_ehh=0, include_edges=True)
    expect_ihh0 = [0, 10, 20, 30]
    assert_array_nanclose(expect_ihh0, ihh0)
    expect_ihh1 = [0, 10, 20, 30]
    assert_array_nanclose(expect_ihh1, ihh1)
コード例 #23
0
def test_ihh01_scan_int8_e():
    # min_maf
    gaps = np.array([10, 10], dtype='f8')
    h = np.array([[0, 0, 1],
                  [0, 0, 1],
                  [0, 0, 1]], dtype='i1')

    expect_ihh0 = [0, 10, 20]
    expect_ihh1 = [np.nan, np.nan, np.nan]
    ihh0, ihh1 = ihh01_scan_int8(h, gaps, min_ehh=0,
                                 min_maf=0, include_edges=True)
    assert_array_nanclose(expect_ihh0, ihh0)
    assert_array_nanclose(expect_ihh1, ihh1)

    expect_ihh0 = [np.nan, np.nan, np.nan]
    expect_ihh1 = [np.nan, np.nan, np.nan]
    ihh0, ihh1 = ihh01_scan_int8(h, gaps, min_ehh=0,
                                 min_maf=0.4, include_edges=True)
    assert_array_nanclose(expect_ihh0, ihh0)
    assert_array_nanclose(expect_ihh1, ihh1)
コード例 #24
0
def test_ihh01_scan_e():
    # min_maf
    gaps = np.array([10, 10], dtype='f8')
    h = np.array([[0, 0, 1], [0, 0, 1], [0, 0, 1]])

    expect_ihh0 = [0, 10, 20]
    expect_ihh1 = [np.nan, np.nan, np.nan]
    ihh0, ihh1 = ihh01_scan(h, gaps, min_ehh=0, min_maf=0, include_edges=True)
    assert_array_nanclose(expect_ihh0, ihh0)
    assert_array_nanclose(expect_ihh1, ihh1)

    expect_ihh0 = [np.nan, np.nan, np.nan]
    expect_ihh1 = [np.nan, np.nan, np.nan]
    ihh0, ihh1 = ihh01_scan(h,
                            gaps,
                            min_ehh=0,
                            min_maf=0.4,
                            include_edges=True)
    assert_array_nanclose(expect_ihh0, ihh0)
    assert_array_nanclose(expect_ihh1, ihh1)
コード例 #25
0
def test_ihh_scan_int8_e():
    # edge case: start from haplotype homozygosity below min_ehh
    gaps = np.array([10], dtype='f8')
    h = np.array([[0, 0, 1], [0, 1, 0]], dtype='i1')

    expect = [np.nan, 10 / 6]
    actual = ihh_scan_int8(h, gaps, min_ehh=0, include_edges=False)
    assert_array_nanclose(expect, actual)

    expect = [0, 10 / 6]
    actual = ihh_scan_int8(h, gaps, min_ehh=0, include_edges=True)
    assert_array_nanclose(expect, actual)

    expect = [0, 0]
    actual = ihh_scan_int8(h, gaps, min_ehh=0.5, include_edges=False)
    assert_array_nanclose(expect, actual)

    expect = [0, 0]
    actual = ihh_scan_int8(h, gaps, min_ehh=0.5, include_edges=True)
    assert_array_nanclose(expect, actual)
コード例 #26
0
ファイル: test_stats.py プロジェクト: oxpeter/scikit-allel
    def test_ihh01_scan_int8(self):
        from allel.opt.stats import ihh01_scan_int8
        pos = [10, 20, 30, 40]

        # case 1
        h = np.array([[0, 0, 1],
                      [0, 1, 1],
                      [1, 1, 0],
                      [1, 0, 0]], dtype='i1')

        ihh0, ihh1 = ihh01_scan_int8(h, pos, min_ehh=0.05)
        expect_ihh0 = [np.nan, np.nan, np.nan, 0]
        assert_array_nanclose(expect_ihh0, ihh0)
        expect_ihh1 = [np.nan, np.nan, 0, np.nan]
        assert_array_nanclose(expect_ihh1, ihh1)

        ihh0, ihh1 = ihh01_scan_int8(h, pos, min_ehh=None)
        expect_ihh0 = [0, np.nan, np.nan, 0]
        assert_array_nanclose(expect_ihh0, ihh0)
        expect_ihh1 = [np.nan, 0, 0, np.nan]
        assert_array_nanclose(expect_ihh1, ihh1)

        # case 2
        h = np.array([[0, 0, 0, 1],
                      [0, 0, 1, 0],
                      [0, 1, 0, 0],
                      [1, 0, 0, 0]], dtype='i1')

        ihh0, ihh1 = ihh01_scan_int8(h, pos, min_ehh=0.05)
        expect_ihh0 = [np.nan, np.nan, np.nan, 10*2/3]
        assert_array_nanclose(expect_ihh0, ihh0)
        expect_ihh1 = [np.nan, np.nan, np.nan, np.nan]
        assert_array_nanclose(expect_ihh1, ihh1)

        ihh0, ihh1 = ihh01_scan_int8(h, pos, min_ehh=None)
        expect_ihh0 = [0, 10*2/3, 10*2/3, 10*2/3]
        assert_array_nanclose(expect_ihh0, ihh0)
        expect_ihh1 = [np.nan, np.nan, np.nan, np.nan]
        assert_array_nanclose(expect_ihh1, ihh1)

        # case 3
        h = np.array([[0, 0, 0, 1, 1, 1],
                      [0, 0, 0, 1, 1, 1],
                      [0, 0, 0, 1, 1, 1],
                      [0, 0, 0, 1, 1, 1]], dtype='i1')

        ihh0, ihh1 = ihh01_scan_int8(h, pos, min_ehh=0.05)
        expect_ihh0 = [np.nan, np.nan, np.nan, np.nan]
        assert_array_nanclose(expect_ihh0, ihh0)
        expect_ihh1 = [np.nan, np.nan, np.nan, np.nan]
        assert_array_nanclose(expect_ihh1, ihh1)

        ihh0, ihh1 = ihh01_scan_int8(h, pos, min_ehh=None)
        expect_ihh0 = [0, 10, 20, 30]
        assert_array_nanclose(expect_ihh0, ihh0)
        expect_ihh1 = [0, 10, 20, 30]
        assert_array_nanclose(expect_ihh1, ihh1)

        # case 4
        h = np.array([[0, 0, 1, 1, 1, 0],
                      [0, 1, 0, 1, 0, 1],
                      [1, 0, 0, 0, 1, 1],
                      [0, 0, 0, 1, 1, 1]], dtype='i1')

        ihh0, ihh1 = ihh01_scan_int8(h, pos, min_ehh=0.05)
        expect_ihh0 = [np.nan, np.nan, np.nan, 10*2/3]
        assert_array_nanclose(expect_ihh0, ihh0)
        expect_ihh1 = [np.nan, np.nan, np.nan, 10*2/3]
        assert_array_nanclose(expect_ihh1, ihh1)

        ihh0, ihh1 = ihh01_scan_int8(h, pos, min_ehh=None)
        expect_ihh0 = [0, 10*2/3, 10*2/3, 10*2/3]
        assert_array_nanclose(expect_ihh0, ihh0)
        expect_ihh1 = [0, 10*2/3, 10*2/3, 10*2/3]
        assert_array_nanclose(expect_ihh1, ihh1)
コード例 #27
0
def test_ihh01_scan_d():
    gaps = np.array([10, 10, 10], dtype='f8')
    h = np.array([[0, 0, 1, 1, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 0, 0, 1, 1],
                  [0, 0, 0, 1, 1, 1]])

    ihh0, ihh1 = ihh01_scan(h, gaps, min_ehh=0.05)
    x = (10 * (1 + 1 / 3) / 2) + (10 * (1 / 3 + 0) / 2)
    expect_ihh0 = [np.nan, np.nan, x, x]
    assert_array_nanclose(expect_ihh0, ihh0)
    expect_ihh1 = [np.nan, np.nan, x, x]
    assert_array_nanclose(expect_ihh1, ihh1)

    ihh0, ihh1 = ihh01_scan(h, gaps, min_ehh=0)
    expect_ihh0 = [np.nan, np.nan, x, x]
    assert_array_nanclose(expect_ihh0, ihh0)
    expect_ihh1 = [np.nan, np.nan, x, x]
    assert_array_nanclose(expect_ihh1, ihh1)

    ihh0, ihh1 = ihh01_scan(h, gaps, min_ehh=0, include_edges=True)
    expect_ihh0 = [0, 10 * 2 / 3, x, x]
    assert_array_nanclose(expect_ihh0, ihh0)
    expect_ihh1 = [0, 10 * 2 / 3, x, x]
    assert_array_nanclose(expect_ihh1, ihh1)
コード例 #28
0
def test_ihh01_scan_int8_d():
    gaps = np.array([10, 10, 10], dtype='f8')
    h = np.array([[0, 0, 1, 1, 1, 0],
                  [0, 1, 0, 1, 0, 1],
                  [1, 0, 0, 0, 1, 1],
                  [0, 0, 0, 1, 1, 1]], dtype='i1')

    ihh0, ihh1 = ihh01_scan_int8(h, gaps, min_ehh=0.05)
    x = (10 * (1 + 1 / 3) / 2) + (10 * (1 / 3 + 0) / 2)
    expect_ihh0 = [np.nan, np.nan, x, x]
    assert_array_nanclose(expect_ihh0, ihh0)
    expect_ihh1 = [np.nan, np.nan, x, x]
    assert_array_nanclose(expect_ihh1, ihh1)

    ihh0, ihh1 = ihh01_scan_int8(h, gaps, min_ehh=0)
    expect_ihh0 = [np.nan, np.nan, x, x]
    assert_array_nanclose(expect_ihh0, ihh0)
    expect_ihh1 = [np.nan, np.nan, x, x]
    assert_array_nanclose(expect_ihh1, ihh1)

    ihh0, ihh1 = ihh01_scan_int8(h, gaps, min_ehh=0, include_edges=True)
    expect_ihh0 = [0, 10 * 2 / 3, x, x]
    assert_array_nanclose(expect_ihh0, ihh0)
    expect_ihh1 = [0, 10 * 2 / 3, x, x]
    assert_array_nanclose(expect_ihh1, ihh1)
コード例 #29
0
ファイル: test_stats.py プロジェクト: oxpeter/scikit-allel
    def test_ssl01_scan_int8(self):
        from allel.opt.stats import nsl01_scan_int8

        h = np.array([[0, 0, 0, 1, 1, 1],
                      [0, 0, 0, 1, 1, 1],
                      [0, 0, 0, 1, 1, 1],
                      [0, 0, 0, 1, 1, 1]], dtype='i1')
        nsl0, nsl1 = nsl01_scan_int8(h)
        expect_nsl0 = [1, 2, 3, 4]
        assert_array_nanclose(expect_nsl0, nsl0)
        expect_nsl1 = [1, 2, 3, 4]
        assert_array_nanclose(expect_nsl1, nsl1)

        h = np.array([[0, 0, 0, 1],
                      [0, 0, 1, 0],
                      [0, 1, 0, 0],
                      [1, 0, 0, 0]], dtype='i1')
        nsl0, nsl1 = nsl01_scan_int8(h)
        expect_nsl0 = [1, 4/3, 4/3, 4/3]
        assert_array_nanclose(expect_nsl0, nsl0)
        expect_nsl1 = [np.nan, np.nan, np.nan, np.nan]
        assert_array_nanclose(expect_nsl1, nsl1)

        h = np.array([[0, 0, 1],
                      [0, 1, 1],
                      [1, 1, 0],
                      [1, 0, 0]], dtype='i1')
        nsl0, nsl1 = nsl01_scan_int8(h)
        expect_nsl0 = [1, np.nan, np.nan, 1]
        assert_array_nanclose(expect_nsl0, nsl0)
        expect_nsl1 = [np.nan, 1, 1, np.nan]
        assert_array_nanclose(expect_nsl1, nsl1)
コード例 #30
0
def test_ihh01_scan_int8_b():
    gaps = np.array([10, 10, 10], dtype='f8')
    h = np.array([[0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0], [1, 0, 0, 0]],
                 dtype='i1')

    ihh0, ihh1 = ihh01_scan_int8(h, gaps, min_ehh=0.05, include_edges=False)
    x = (10 * (1 + 1 / 3) / 2) + (10 * (1 / 3 + 0) / 2)
    expect_ihh0 = [np.nan, np.nan, x, x]
    assert_array_nanclose(expect_ihh0, ihh0)
    expect_ihh1 = [np.nan, np.nan, np.nan, np.nan]
    assert_array_nanclose(expect_ihh1, ihh1)

    ihh0, ihh1 = ihh01_scan_int8(h, gaps, min_ehh=0, include_edges=False)
    expect_ihh0 = [np.nan, np.nan, x, x]
    assert_array_nanclose(expect_ihh0, ihh0)
    expect_ihh1 = [np.nan, np.nan, np.nan, np.nan]
    assert_array_nanclose(expect_ihh1, ihh1)

    ihh0, ihh1 = ihh01_scan_int8(h, gaps, min_ehh=0, include_edges=True)
    expect_ihh0 = [0, 10 * (1 + 1 / 3) / 2, x, x]
    assert_array_nanclose(expect_ihh0, ihh0)
    expect_ihh1 = [np.nan, np.nan, np.nan, np.nan]
    assert_array_nanclose(expect_ihh1, ihh1)