def test_fourier_power(self): filepath = path.realpath(path.join(os.getcwd(), path.dirname(__file__))) filepath = path.join(filepath, 'example_data.shp') s = spatial_efd.LoadGeometries(filepath) x, y, _ = spatial_efd.ProcessGeometryNorm(s[2]) coeffs = spatial_efd.CalculateEFD(x, y, 500) n = spatial_efd.FourierPower(coeffs, x) self.assertEqual(n, 19)
def test_calculate_dc_coefficients(self): filepath = path.realpath(path.join(os.getcwd(), path.dirname(__file__))) filepath = path.join(filepath, 'example_data.shp') s = spatial_efd.LoadGeometries(filepath) x, y, _ = spatial_efd.ProcessGeometryNorm(s[2]) coeffs = spatial_efd.CalculateEFD(x, y, 10) dc = spatial_efd.calculate_dc_coefficients(x, y) self.assertTupleEqual(dc, (0.34071444143386936, 0.56752000996605101))
def test_calculate_efd(self): filepath = path.realpath(path.join(os.getcwd(), path.dirname(__file__))) filepath = path.join(filepath, 'example_data.shp') s = spatial_efd.LoadGeometries(filepath) x, y, _ = spatial_efd.ProcessGeometryNorm(s[2]) coeffs = spatial_efd.CalculateEFD(x, y, 10) ntest.assert_almost_equal( coeffs[6].tolist(), [-0.00134937648, -0.000604478718, 0.0003257416778, 0.001951924972])
def test_normalize_efd(self): filepath = path.realpath(path.join(os.getcwd(), path.dirname(__file__))) filepath = path.join(filepath, 'example_data.shp') s = spatial_efd.LoadGeometries(filepath) x, y, _ = spatial_efd.ProcessGeometryNorm(s[0]) coeffs = spatial_efd.CalculateEFD(x, y, 10) coeffs, rotation = spatial_efd.normalize_efd(coeffs) ntest.assert_almost_equal(coeffs[9].tolist(), [ -0.004300377673482293, 0.00884561305918755, -0.013450240117972431, -0.0029657314108907686 ]) self.assertAlmostEqual(rotation, 14.5510829786)
def test_plotting_savefig(self): matplotlib.pyplot.clf() path_ = path.realpath(path.join(os.getcwd(), path.dirname(__file__))) filepath = path.join(path_, 'example_data.shp') figpath = path.join(path_, 'Test') s = spatial_efd.LoadGeometries(filepath) x, y, _ = spatial_efd.ProcessGeometryNorm(s[2]) coeffs = spatial_efd.CalculateEFD(x, y, 10) a, b = spatial_efd.inverse_transform(coeffs) ax = spatial_efd.InitPlot() spatial_efd.PlotEllipse(ax, a, b, color='k', width=1.) spatial_efd.SavePlot(ax, 5, figpath, 'png') self.assertTrue(path.isfile('{0}_5.png'.format(figpath))) os.remove('{0}_5.png'.format(figpath))
def test_inverse_transform_locus(self): filepath = path.realpath(path.join(os.getcwd(), path.dirname(__file__))) filepath = path.join(filepath, 'example_data.shp') s = spatial_efd.LoadGeometries(filepath) x, y, _ = spatial_efd.ProcessGeometryNorm(s[2]) coeffs = spatial_efd.CalculateEFD(x, y, 10) a, b = spatial_efd.inverse_transform(coeffs, locus=(0.5, 0.9)) self.assertListEqual(a[:5].tolist(), [ 0.1789922960130197, 0.17981434191563422, 0.181307199085701, 0.18345170841767827, 0.1862205795930986 ]) self.assertListEqual(b[:5].tolist(), [ 1.3174800975360959, 1.3180142260117702, 1.317775492831905, 1.3167543803935242, 1.3149533885200781 ])
def test_inverse_transform(self): filepath = path.realpath(path.join(os.getcwd(), path.dirname(__file__))) filepath = path.join(filepath, 'example_data.shp') s = spatial_efd.LoadGeometries(filepath) x, y, _ = spatial_efd.ProcessGeometryNorm(s[2]) coeffs = spatial_efd.CalculateEFD(x, y, 10) a, b = spatial_efd.inverse_transform(coeffs) self.assertListEqual(a[:5].tolist(), [ -0.32100770398698036, -0.3201856580843658, -0.318692800914299, -0.3165482915823218, -0.31377942040690143 ]) self.assertListEqual(b[:5].tolist(), [ 0.4174800975360954, 0.4180142260117704, 0.417775492831905, 0.416754380393524, 0.41495338852007846 ])
def test_average_coefficients(self): filepath = path.realpath(path.join(os.getcwd(), path.dirname(__file__))) filepath = path.join(filepath, 'example_data.shp') s = spatial_efd.LoadGeometries(filepath) coeffsList = [] for i in xrange(3): x, y, _ = spatial_efd.ProcessGeometryNorm(s[i]) coeffsList.append(spatial_efd.CalculateEFD(x, y, 10)) avg = spatial_efd.AverageCoefficients(coeffsList) ntest.assert_almost_equal(avg[6].tolist(), [ 0.00049541617818, 0.00515338138093, -0.0005087032263, 9.7046992097e-05 ])
def test_average_sd(self): filepath = path.realpath(path.join(os.getcwd(), path.dirname(__file__))) filepath = path.join(filepath, 'example_data.shp') s = spatial_efd.LoadGeometries(filepath) coeffsList = [] for i in xrange(3): x, y, _ = spatial_efd.ProcessGeometryNorm(s[i]) coeffsList.append(spatial_efd.CalculateEFD(x, y, 10)) avg = spatial_efd.AverageCoefficients(coeffsList) sd = spatial_efd.AverageSD(coeffsList, avg) ntest.assert_almost_equal(sd[3].tolist(), [ 0.000381631249123, 0.00018247277186, 4.6821200993e-05, 9.3013816155e-05 ])
def test_process_geometry_norm(self): filepath = path.realpath(path.join(os.getcwd(), path.dirname(__file__))) filepath = path.join(filepath, 'example_data.shp') s = spatial_efd.LoadGeometries(filepath) x, y, c = spatial_efd.ProcessGeometryNorm(s[1]) self.assertTupleEqual(c, (0.4729141652616648, 0.22570629971140485)) self.assertListEqual(x[:10], [ 0.29533678756476683, 0.35233160621761656, 0.35233160621761656, 0.35751295336787564, 0.35751295336787564, 0.3626943005181347, 0.3626943005181347, 0.36787564766839376, 0.36787564766839376, 0.37305699481865284 ]) self.assertListEqual(y[:10], [ 0.49740932642487046, 0.49740932642487046, 0.49222797927461137, 0.49222797927461137, 0.48704663212435234, 0.48704663212435234, 0.48186528497409326, 0.48186528497409326, 0.47668393782383417, 0.47668393782383417 ])