示例#1
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 = centerline(xs, ys)
    CL.infs(40)
    # make assertion
    assert CL.infs_os[-1] == 10000
示例#2
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 = centerline(x, y)
     dss = CL.ds()
     # make assertions
     assert np.all(dss == [1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])
示例#3
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 = centerline(x, y)
     # make assertions
     assert np.all(CL.xo == x)
     assert np.all(CL.yo == y)
示例#4
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 = centerline(x, y)
     sss = CL.s()
     # make assertions
     assert np.all(sss == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
示例#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 = 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_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 = 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'
示例#7
0
def test_sine_csmooth():
    """Use a sine wave to compute curvature."""
    xs = np.linspace(0, 100, 101)
    ys = np.sin(xs) + 5
    CL = 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,)
示例#8
0
def test_sine_plot(tmp_path):
    """Use sine wave to test plotting of CenterLine."""
    xs = np.linspace(0, 100, 101)
    ys = np.sin(xs) + 5
    CL = centerline(xs, ys)
    CL.plot()
    plt.savefig(os.path.join(tmp_path, 'sinewave.png'))
    plt.close()
    # assert file exists now
    assert os.path.isfile(os.path.join(tmp_path, 'sinewave.png')) == True
示例#9
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 = 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)
示例#10
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 = centerline(x, y, attribs)
     # make assertions
     assert np.all(CL.xo == x)
     assert np.all(CL.yo == y)
     assert CL.width == 10.0
示例#11
0
def test_plot_withattrs(tmp_path):
    """Testing CenterLine plotting with various attributes."""
    xs = np.linspace(0, 100, 101)
    ys = np.sin(xs) + 5
    CL = centerline(xs, ys)
    CL.infs_os = [0]
    CL.ints_all = [1]
    CL.ints = [2]
    CL.plot()
    plt.savefig(os.path.join(tmp_path,'sinewaveattrs.png'))
    plt.close()
    # assert file exists now
    assert os.path.isfile(os.path.join(tmp_path, 'sinewaveattrs.png')) == True
示例#12
0
def test_csmooth_nowindow():
    """csmooth() without providing a window."""
    xs = np.linspace(0, 100, 101)
    ys = np.sin(xs) + 5
    CL = 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.'
示例#13
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 = 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'
示例#14
0
def test_zs_noinflection():
    """zs_plot without inflection points."""
    xs = np.linspace(0, 100, 101)
    ys = np.sin(xs) + 5
    CL = 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.'
示例#15
0
 def test_get_xy_rs(self):
     """Test get xy function with rs."""
     x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
     y = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  1]
     xrs = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
     yrs = [11, 11, 11, 11, 11, 11, 11, 11, 11, 11,  11]
     attribs = {}
     attribs['xrs'] = xrs
     attribs['yrs'] = yrs
     CL = 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 == 'resampled'
示例#16
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 = 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
示例#17
0
def test_zs_nomigrates():
    """zs_plot without migration rates."""
    xs = np.linspace(0, 100, 101)
    ys = np.sin(xs) + 5
    CL = 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.'
示例#18
0
def test_plot_withattrs():
    """Testing CenterLine plotting with various attributes."""
    xs = np.linspace(0, 100, 101)
    ys = np.sin(xs) + 5
    CL = 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
示例#19
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 = cu.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 = 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,)