Пример #1
0
 def test_s(self):
     """Test the s() function."""
     x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
     y = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
     CL = ru.centerline(x, y)
     sss = CL.s()
     # make assertions
     assert np.all(sss == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
Пример #2
0
def test_long_sine_CLinfs():
    """Long sine wave into CL and using infs function."""
    xs = np.linspace(0, 10000, 10001)
    ys = 20 * (np.sin(xs / 1000) + 50)
    CL = ru.centerline(xs, ys)
    CL.infs(40)
    # make assertion
    assert CL.infs_os[-1] == 10000
Пример #3
0
 def test_ds(self):
     """Test the ds() function."""
     x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
     y = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
     CL = ru.centerline(x, y)
     dss = CL.ds()
     # make assertions
     assert np.all(dss == [1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])
Пример #4
0
 def test_init(self):
     """Init the class."""
     x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
     y = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
     CL = ru.centerline(x, y)
     # make assertions
     assert np.all(CL.xo == x)
     assert np.all(CL.yo == y)
Пример #5
0
 def test_C(self):
     """Test the C() function."""
     x = [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0]
     y = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
     CL = ru.centerline(x, y)
     Cs = CL.C()
     # make assertions
     assert pytest.approx(Cs == np.array(
         [-0., 0., 0., 0., 0., 1.57079633, 1.57079633, 0., 0., 0., 0.]))
Пример #6
0
def test_sine_csmooth():
    """Use a sine wave to compute curvature."""
    xs = np.linspace(0, 100, 101)
    ys = np.sin(xs) + 5
    CL = ru.centerline(xs, ys)
    CL.window_C = 11
    # smooth the centerline
    Cs = CL.Csmooth()
    # check that the smoothed shape is what we expect
    assert Cs.shape == (101, )
Пример #7
0
 def test_get_xy(self):
     """Test get xy function."""
     x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
     y = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
     CL = ru.centerline(x, y)
     x, y, vers = CL._centerline__get_x_and_y()
     # make assertions
     assert np.all(x == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
     assert np.all(y == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
     assert vers == 'original'
Пример #8
0
 def test_init_attr(self):
     """Init with attribute list."""
     x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
     y = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
     attribs = {}
     attribs['width'] = np.ones((11, )) * 10
     CL = ru.centerline(x, y, attribs)
     # make assertions
     assert np.all(CL.xo == x)
     assert np.all(CL.yo == y)
     assert np.all(CL.width == np.ones((11, )) * 10)
Пример #9
0
 def test_init_const_attr(self):
     """Init with constant attribute."""
     x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
     y = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
     attribs = {}
     attribs['width'] = 10.
     CL = ru.centerline(x, y, attribs)
     # make assertions
     assert np.all(CL.xo == x)
     assert np.all(CL.yo == y)
     assert CL.width == 10.0
Пример #10
0
def test_csmooth_nowindow():
    """csmooth() without providing a window."""
    xs = np.linspace(0, 100, 101)
    ys = np.sin(xs) + 5
    CL = ru.centerline(xs, ys)
    # set up capture string
    capturedOutput = io.StringIO()
    sys.stdout = capturedOutput
    # smooth the centerline
    Cs = CL.Csmooth()
    # grab output
    sys.stdout = sys.__stdout__
    # assert output
    assert capturedOutput.getvalue()[:-1] == 'Must provide a smoothing window.'
Пример #11
0
def test_zs_noinflection():
    """zs_plot without inflection points."""
    xs = np.linspace(0, 100, 101)
    ys = np.sin(xs) + 5
    CL = ru.centerline(xs, ys)
    # set up capture string
    capturedOutput = io.StringIO()
    sys.stdout = capturedOutput
    # call plot
    CL.zs_plot()
    # grab output
    sys.stdout = sys.__stdout__
    # assert output
    assert capturedOutput.getvalue(
    )[:-1] == 'Must compute inflection points first.'
Пример #12
0
 def test_get_xy_sm(self):
     """Test get xy function with xs."""
     x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
     y = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
     xs = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
     ys = [11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11]
     attribs = {}
     attribs['xs'] = xs
     attribs['ys'] = ys
     CL = ru.centerline(x, y, attribs=attribs)
     x, y, vers = CL._centerline__get_x_and_y()
     # make assertions
     assert np.all(x == [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20])
     assert np.all(y == [11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11])
     assert vers == 'smooth'
Пример #13
0
def test_zs_nomigrates():
    """zs_plot without migration rates."""
    xs = np.linspace(0, 100, 101)
    ys = np.sin(xs) + 5
    CL = ru.centerline(xs, ys)
    CL.infs_os = [1]
    CL.ints = [2]
    # set up capture string
    capturedOutput = io.StringIO()
    sys.stdout = capturedOutput
    # call plot
    CL.zs_plot()
    # grab output
    sys.stdout = sys.__stdout__
    # assert output
    assert capturedOutput.getvalue(
    )[:-1] == 'Must compute migration rates first.'
Пример #14
0
def test_sine_plot():
    """Use sine wave to test plotting of CenterLine."""
    xs = np.linspace(0, 100, 101)
    ys = np.sin(xs) + 5
    CL = ru.centerline(xs, ys)
    CL.plot()
    plt.savefig(
        os.path.join(
            basepath,
            os.path.normpath('tests/results/synthetic_cycles/sinewave.png')))
    plt.close()
    # assert file exists now
    assert os.path.isfile(
        os.path.join(
            basepath,
            os.path.normpath(
                'tests/results/synthetic_cycles/sinewave.png'))) == True
Пример #15
0
def test_plot_withattrs():
    """Testing CenterLine plotting with various attributes."""
    xs = np.linspace(0, 100, 101)
    ys = np.sin(xs) + 5
    CL = ru.centerline(xs, ys)
    CL.infs_os = [0]
    CL.ints_all = [1]
    CL.ints = [2]
    CL.plot()
    plt.savefig(
        os.path.join(
            basepath,
            os.path.normpath(
                'tests/results/synthetic_cycles/sinewaveattrs.png')))
    plt.close()
    # assert file exists now
    assert os.path.isfile(
        os.path.join(
            basepath,
            os.path.normpath(
                'tests/results/synthetic_cycles/sinewaveattrs.png'))) == True
Пример #16
0
def test_sine_curvature():
    """Use a sine wave to compute curvature."""
    xs = np.linspace(0, 100, 101)
    ys = np.sin(xs) + 5
    C, Areturn, sdist = ru.curvars(xs, ys)
    # make some simple assertions about shape of outputs
    assert C.shape == (100, )
    assert Areturn.shape == (100, )
    assert sdist.shape == (100, )
    # now define this as a centerline
    CL = ru.centerline(xs, ys)
    # smooth the centerline
    CL.window_cl = 10
    CL.smooth(n=2)
    # make some assertions about the smoothing
    assert CL.xs.shape == (101, )
    assert CL.ys.shape == (101, )
    assert np.sum(CL.xs != xs) > 0
    assert np.sum(CL.ys != ys) > 0
    # resample the centerline to 50 points
    CL.resample(50)
    # assert resampled dimensions are as expected
    assert CL.xrs.shape == (50, )
    assert CL.yrs.shape == (50, )