diff --git a/wafo/kdetools/tests/data.py b/wafo/kdetools/tests/data.py new file mode 100644 index 0000000..68ee9a3 --- /dev/null +++ b/wafo/kdetools/tests/data.py @@ -0,0 +1,40 @@ +''' +Created on 29. des. 2016 + +@author: pab +''' +# N = 20 +# DATA1D = np.random.rayleigh(1, size=(N,)) +# print(DATA1D.tolist()) +DATA1D = [0.6493244636902034, 0.6562823794215175, 1.0905183896319681, + 0.42206966930980305, 3.2401808457841033, 0.4527768130472434, + 1.2078346032213523, 0.7042615640603758, 1.1514223608901017, + 0.9233030250922233, 1.0709559676055374, 0.7132605765584901, + 0.6560730230166847, 0.734614714549834, 1.0404525505934663, + 0.6750474427282895, 0.8801082165600141, 1.7235435044161305, + 1.2660483754981589, 0.9811765136936577] +# DATA2D = np.random.rayleigh(1, size=(2, N)) +DATA2D = [[0.38103275, 0.35083136, 0.90024207, 1.88230239, 0.96815399, + 0.57392873, 1.63367908, 1.20944125, 2.03887811, 0.81789145, + 0.69302049, 1.40856592, 0.92156032, 2.14791432, 2.04373821, + 0.69800708, 0.58428735, 1.59128776, 2.05771405, 0.87021964], + [1.44080694, 0.39973751, 1.331243, 2.48895822, 1.18894158, + 1.40526085, 1.01967897, 0.81196474, 1.37978932, 2.03334689, + 0.870329, 1.25106862, 0.5346619, 0.47541236, 1.51930093, + 0.58861519, 1.19780448, 0.81548296, 1.56859488, 1.60653533]] +# DATA3D = np.random.rayleigh(1, size=(3, N)) +DATA3D = [[0.932896, 0.89522635, 0.80636346, 1.32283371, 0.27125435, + 1.91666304, 2.30736635, 1.13662384, 1.73071287, 1.06061127, + 0.99598512, 2.16396591, 1.23458213, 1.12406686, 1.16930431, + 0.73700592, 1.21135139, 0.46671506, 1.3530304, 0.91419104], + [0.62759088, 0.23988169, 2.04909823, 0.93766571, 1.19343762, + 1.94954931, 0.84687514, 0.49284897, 1.05066204, 1.89088505, + 0.840738, 1.02901457, 1.0758625, 1.76357967, 0.45792897, + 1.54488066, 0.17644313, 1.6798871, 0.72583514, 2.22087245], + [1.69496432, 0.81791905, 0.82534709, 0.71642389, 0.89294732, + 1.66888649, 0.69036947, 0.99961448, 0.30657267, 0.98798713, + 0.83298728, 1.83334948, 1.90144186, 1.25781913, 0.07122458, + 2.42340852, 2.41342037, 0.87233305, 1.17537114, 1.69505988]] + +if __name__ == '__main__': + pass diff --git a/wafo/kdetools/tests/test_gridding.py b/wafo/kdetools/tests/test_gridding.py index 46cf4e6..8e8db21 100644 --- a/wafo/kdetools/tests/test_gridding.py +++ b/wafo/kdetools/tests/test_gridding.py @@ -7,23 +7,14 @@ from __future__ import division import unittest import numpy as np from numpy.testing import assert_allclose -from numpy import array import wafo.kdetools.gridding as wkg +from wafo.kdetools.tests.data import DATA1D, DATA2D, DATA3D class TestKdeTools(unittest.TestCase): @staticmethod def test_gridcount_1d(): - # N = 20 - # data = np.random.rayleigh(1, size=(N,)) - # print(data.tolist()) - data = [0.6493244636902034, 0.6562823794215175, 1.0905183896319681, - 0.42206966930980305, 3.2401808457841033, 0.4527768130472434, - 1.2078346032213523, 0.7042615640603758, 1.1514223608901017, - 0.9233030250922233, 1.0709559676055374, 0.7132605765584901, - 0.6560730230166847, 0.734614714549834, 1.0404525505934663, - 0.6750474427282895, 0.8801082165600141, 1.7235435044161305, - 1.2660483754981589, 0.9811765136936577] + data = DATA1D x = np.linspace(0, max(data) + 1, 10) dx = x[1] - x[0] @@ -38,17 +29,7 @@ class TestKdeTools(unittest.TestCase): @staticmethod def test_gridcount_2d(): N = 20 - # data = np.random.rayleigh(1, size=(2, N)) - data = array([ - [0.38103275, 0.35083136, 0.90024207, 1.88230239, 0.96815399, - 0.57392873, 1.63367908, 1.20944125, 2.03887811, 0.81789145, - 0.69302049, 1.40856592, 0.92156032, 2.14791432, 2.04373821, - 0.69800708, 0.58428735, 1.59128776, 2.05771405, 0.87021964], - [1.44080694, 0.39973751, 1.331243, 2.48895822, 1.18894158, - 1.40526085, 1.01967897, 0.81196474, 1.37978932, 2.03334689, - 0.870329, 1.25106862, 0.5346619, 0.47541236, 1.51930093, - 0.58861519, 1.19780448, 0.81548296, 1.56859488, 1.60653533]]) - + data = DATA2D x = np.linspace(0, max(np.ravel(data)) + 1, 5) dx = x[1] - x[0] X = np.vstack((x, x)) @@ -66,21 +47,7 @@ class TestKdeTools(unittest.TestCase): @staticmethod def test_gridcount_3d(): N = 20 - # data = np.random.rayleigh(1, size=(3, N)) - data = np.array([ - [0.932896, 0.89522635, 0.80636346, 1.32283371, 0.27125435, - 1.91666304, 2.30736635, 1.13662384, 1.73071287, 1.06061127, - 0.99598512, 2.16396591, 1.23458213, 1.12406686, 1.16930431, - 0.73700592, 1.21135139, 0.46671506, 1.3530304, 0.91419104], - [0.62759088, 0.23988169, 2.04909823, 0.93766571, 1.19343762, - 1.94954931, 0.84687514, 0.49284897, 1.05066204, 1.89088505, - 0.840738, 1.02901457, 1.0758625, 1.76357967, 0.45792897, - 1.54488066, 0.17644313, 1.6798871, 0.72583514, 2.22087245], - [1.69496432, 0.81791905, 0.82534709, 0.71642389, 0.89294732, - 1.66888649, 0.69036947, 0.99961448, 0.30657267, 0.98798713, - 0.83298728, 1.83334948, 1.90144186, 1.25781913, 0.07122458, - 2.42340852, 2.41342037, 0.87233305, 1.17537114, 1.69505988]]) - + data = DATA3D x = np.linspace(0, max(np.ravel(data)) + 1, 3) dx = x[1] - x[0] X = np.vstack((x, x, x)) @@ -103,17 +70,7 @@ class TestKdeTools(unittest.TestCase): def test_gridcount_4d(): N = 20 - # data = np.random.rayleigh(1, size=(2, N)) - data = array([ - [0.38103275, 0.35083136, 0.90024207, 1.88230239, 0.96815399, - 0.57392873, 1.63367908, 1.20944125, 2.03887811, 0.81789145], - [0.69302049, 1.40856592, 0.92156032, 2.14791432, 2.04373821, - 0.69800708, 0.58428735, 1.59128776, 2.05771405, 0.87021964], - [1.44080694, 0.39973751, 1.331243, 2.48895822, 1.18894158, - 1.40526085, 1.01967897, 0.81196474, 1.37978932, 2.03334689], - [0.870329, 1.25106862, 0.5346619, 0.47541236, 1.51930093, - 0.58861519, 1.19780448, 0.81548296, 1.56859488, 1.60653533]]) - + data = np.reshape(DATA2D, (4, -1)) x = np.linspace(0, max(np.ravel(data)) + 1, 3) dx = x[1] - x[0] X = np.vstack((x, x, x, x)) diff --git a/wafo/kdetools/tests/test_kdetools.py b/wafo/kdetools/tests/test_kdetools.py index 3c7f689..60d9022 100644 --- a/wafo/kdetools/tests/test_kdetools.py +++ b/wafo/kdetools/tests/test_kdetools.py @@ -9,6 +9,7 @@ import numpy as np from numpy.testing import assert_allclose import wafo.objects as wo import wafo.kdetools as wk +from wafo.kdetools.tests.data import DATA2D # import scipy.stats as st @@ -165,16 +166,7 @@ class TestKde(unittest.TestCase): def test_KDE2D(self): # N = 20 # data = np.random.rayleigh(1, size=(2, N)) - data = np.array([ - [0.38103275, 0.35083136, 0.90024207, 1.88230239, 0.96815399, - 0.57392873, 1.63367908, 1.20944125, 2.03887811, 0.81789145, - 0.69302049, 1.40856592, 0.92156032, 2.14791432, 2.04373821, - 0.69800708, 0.58428735, 1.59128776, 2.05771405, 0.87021964], - [1.44080694, 0.39973751, 1.331243, 2.48895822, 1.18894158, - 1.40526085, 1.01967897, 0.81196474, 1.37978932, 2.03334689, - 0.870329, 1.25106862, 0.5346619, 0.47541236, 1.51930093, - 0.58861519, 1.19780448, 0.81548296, 1.56859488, 1.60653533]]) - + data = DATA2D x = np.linspace(0, max(np.ravel(data)) + 1, 3) kde0 = wk.KDE(data, hs=0.5, alpha=0.0, inc=512) diff --git a/wafo/kdetools/tests/test_kernels.py b/wafo/kdetools/tests/test_kernels.py index ccbf4c1..e771d94 100644 --- a/wafo/kdetools/tests/test_kernels.py +++ b/wafo/kdetools/tests/test_kernels.py @@ -9,6 +9,7 @@ import numpy as np from numpy.testing import assert_allclose from numpy import inf import wafo.kdetools.kernels as wkk +from wafo.kdetools.tests.data import DATA3D class TestKernels(unittest.TestCase): @@ -80,19 +81,7 @@ class TestKernels(unittest.TestCase): class TestSmoothing(unittest.TestCase): def setUp(self): - self.data = np.array([ - [0.932896, 0.89522635, 0.80636346, 1.32283371, 0.27125435, - 1.91666304, 2.30736635, 1.13662384, 1.73071287, 1.06061127, - 0.99598512, 2.16396591, 1.23458213, 1.12406686, 1.16930431, - 0.73700592, 1.21135139, 0.46671506, 1.3530304, 0.91419104], - [0.62759088, 0.23988169, 2.04909823, 0.93766571, 1.19343762, - 1.94954931, 0.84687514, 0.49284897, 1.05066204, 1.89088505, - 0.840738, 1.02901457, 1.0758625, 1.76357967, 0.45792897, - 1.54488066, 0.17644313, 1.6798871, 0.72583514, 2.22087245], - [1.69496432, 0.81791905, 0.82534709, 0.71642389, 0.89294732, - 1.66888649, 0.69036947, 0.99961448, 0.30657267, 0.98798713, - 0.83298728, 1.83334948, 1.90144186, 1.25781913, 0.07122458, - 2.42340852, 2.41342037, 0.87233305, 1.17537114, 1.69505988]]) + self.data = DATA3D self.gauss = wkk.Kernel('gaussian') def test_hns(self):