diff --git a/wafo/tests/test_sg_filter.py b/wafo/tests/test_sg_filter.py new file mode 100644 index 0000000..ba416be --- /dev/null +++ b/wafo/tests/test_sg_filter.py @@ -0,0 +1,78 @@ +''' +Created on 26. feb. 2016 + +@author: pab +''' + +import unittest +import numpy as np +from wafo.sg_filter import HampelFilter, SavitzkyGolay, Kalman +from numpy.ma.testutils import assert_array_almost_equal + + +class Test(unittest.TestCase): + def test_kalman(self): + # V0 = 12 + h = np.atleast_2d(1) # voltimeter measure the voltage itself + q = 1e-9 # variance of process noise as the car operates + r = 0.05 ** 2 # variance of measurement error + b = 0 # no system input + u = 0 # no system input + filt = Kalman(R=r, A=1, Q=q, H=h, B=b) + + # Generate random voltages and watch the filter operate. + n = 50 + + # truth = np.random.randn(n) * np.sqrt(q) + V0 + truth = np.array([12.0000146639, 12.0000065349, 12.0000032619, 11.9999884321, 11.9999738705, 11.9999717554, 12.000012208, 12.0000269596, 12.0000235391, 12.0000420788, 11.9999763588, 12.0000272251, 11.9999278487, 11.9999775611, 12.0000280208, 11.9999788802, 11.9999531533, 11.9999963402, 11.9999318055, 11.9999537065, 12.0000011098, 11.9999750291, 12.000012755, 11.9999355349, 11.9999960117, 12.0000033276, 12.0000100317, 11.9999962376, 12.0000527124, 12.000019087, 12.0000273276, 11.9999461331, 12.0000527385, 11.9999990413, 11.9999850764, 12.0000031025, 11.9999868222, 11.9999830042, 11.9999881952, 12.0000064122, 12.0000343455, 11.9999779108, 12.0000134648, 12.0000329604, 12.0000536949, 11.999990415, 11.9999935299, 11.9999850717, 12.0000048284, 12.000060395]) # @IgnorePep8 + # print(', '.join(['{0}'.format(y) for y in truth])) + # noise = np.random.randn(n) * np.sqrt(r) + noise = np.array([0.0621366489443, 0.0247330994998, 0.109271521369, -0.0567657373852, -0.0315244553453, -0.0025701462034, 0.00181288937042, 0.109022849782, 0.0241169949603, -0.0543790728855, 0.0380117839575, 0.0582078684346, -0.0734606815139, -0.0665977120387, 0.0270631615171, 0.0369150024436, 0.0788445252483, 0.0111006834355, 0.0169567513801, 0.057081645789, -0.0293106512335, 0.0120282068494, 0.0211769283138, -0.0703228625119, -0.0222740803259, 0.0636500853308, 0.0302268639638, 0.0823316446844, 0.0504871636818, -0.0295402185417, 0.0780534199429, -0.0275453184976, -0.0613567940452, -0.0416930336494, -0.0972202720552, 0.0367572628693, 0.0150242119742, -0.0269063072041, 0.0654834111234, 0.0281867030757, -0.0978716452136, -0.0209143055692, -0.0236015624104, 0.0215804707908, -0.0525669442916, -0.00999304544556, -0.120029281573, -0.0255283929591, -0.00426938028504, -0.0487170747831]) # @IgnorePep8 + # print('noise') + # print(', '.join(['{0}'.format(y) for y in noise])) + z = truth + noise # measurement + x = np.zeros(n) + + for i, zi in enumerate(z): + x[i] = filt(zi, u) # perform a Kalman filter iteration + + print(', '.join(['{0}'.format(y) for y in x])) + assert_array_almost_equal(x, [12.0621513128, 12.0434454699, 12.065388589, 12.0348470726, 12.0215675093, 12.0175398445, 12.0152948689, 12.0270143185, 12.0266950063, 12.0185917138, 12.0203550503, 12.0235117738, 12.0160466547, 12.0101417447, 12.0112717378, 12.0128731715, 12.0167512202, 12.0164370857, 12.0164608484, 12.0184896738, 12.0162133963, 12.0160220138, 12.0162467099, 12.0126366982, 12.0112399981, 12.01325607, 12.0138850472, 12.0163296762, 12.0175094638, 12.0159415984, 12.0179463317, 12.0165228489, 12.0141641309, 12.0125210028, 12.0093846209, 12.0101451843, 12.0102767167, 12.0092975878, 12.0107382282, 12.01117469, 12.0085152867, 12.0078138971, 12.0070834443, 12.0074137537, 12.0060816948, 12.0057319401, 12.0030552687, 12.0024592874, 12.0023220236, 12.0013021198]) # @IgnorePep8 + + def test_savitzky_golay(self): + t = np.linspace(-4, 4, 100) + # noise = np.random.normal(0, 0.05, t.shape) + noise = np.array([-0.0100738410948, 0.0434144660993, -0.00378151879776, 0.0113356386249, 0.00435077505515, -0.0477602072563, 0.0373494077292, -0.0133865881648, -0.058259106898, 0.0661995082581, -0.0302004598725, 0.0251073570423, 0.0504480752083, 0.00591197638959, -0.0936100824835, -0.0475801028574, 0.164260739963, 0.000309393717298, 0.0145265378376, 0.0451974209359, -0.0296464887607, 0.00113264461646, 0.0203243951278, 0.0250086489045, 0.0286663554031, 0.0162585459204, -0.0285237485127, 0.0841528003829, -0.0449728982279, 0.0549796633406, -0.0968901623365, 0.0306727572312, -0.06950957371, 0.00598396964893, 0.0583904237732, 0.0271856795988, 0.0503237614252, 0.179978222833, 0.0909965842309, -0.037723727536, 0.0766788834896, -0.135152061379, -0.0275445486266, 0.00437867535899, -0.0272885999582, -0.0167170993005, 0.0522077667657, -0.044618733434, -0.0323362657615, 0.0122726298648, 0.0311304227245, -0.106361849439, 0.0526578516171, 0.0600674983294, 0.0745276212563, -0.0488453979797, -0.000833273665862, 0.0232768529385, 0.0138869047145, -0.0581069396022, 0.0321001340163, -0.023975724861, -0.0281919023447, 0.0341550408589, -0.0128104984676, -0.0214928514613, -0.0930630211028, -0.086094936458, 0.0169055851217, -0.0106085935018, 0.0114499301052, 0.120823119533, 0.0401375561218, 0.0979979215035, -0.015930504967, 0.0730359376807, -0.0369380623571, 0.0628171477772, -0.0271592027456, -0.0805267873905, -0.047314352792, -0.00693573205681, -0.0276294819462, -0.00896110691771, 0.0248482543453, 0.0877066047642, -0.0325533337143, -0.0638923240986, 0.0512523528302, 0.0720952473332, 0.00555629231342, 0.0562912258368, 0.0518574742355, -0.0599288505845, 0.0129657160415, -0.0025435076237, -0.0136966498082, 0.0260013064028, 0.0315561663839, -0.0293194006299]) # @IgnorePep8 + # print(', '.join(['{0}'.format(y) for y in noise])) + y = np.exp(-t**2) + noise + ysg = SavitzkyGolay(n=20, degree=2).smooth(y) + # print(', '.join(['{0}'.format(y) for y in ysg])) + assert_array_almost_equal(ysg,[0.08136940307, 0.0628995512206, 0.0459066440291, 0.0303906814954, 0.0163516636196, 0.00378959040169, -0.00729553815838, -0.0169037220606, -0.0250349613049, -0.0316892558914, -0.03686660582, -0.0405670110908, -0.0427904717036, -0.0435369876586, -0.0428065589558, -0.0405991855951, -0.0369148675765, -0.0317536049001, -0.0251153975657, -0.0170002455736, -0.00740814892354, 0.00138883298422, 0.00903982318392, 0.0156981288342, 0.0262571138525, 0.038712235996, 0.0497401536595, 0.0708145615737, 0.0930139468092, 0.115399487253, 0.145859174356, 0.181612636791, 0.217133614374, 0.257717904903, 0.300137304571, 0.345750694351, 0.392370647909, 0.447698806473, 0.498669071812, 0.552242388661, 0.602481962016, 0.649961345551, 0.695325299394, 0.735374047294, 0.773010811455, 0.805919165272, 0.834865852047, 0.854796400219, 0.86842923705, 0.871717227059, 0.870973756546, 0.854091989437, 0.838398655214, 0.810673923439, 0.783634317013, 0.749908334726, 0.714315301461, 0.67175727743, 0.634614314389, 0.593943523363, 0.54497174327, 0.497539947485, 0.442464744684, 0.39039262486, 0.339641566641, 0.287962531039, 0.243889096129, 0.20650960823, 0.165038163827, 0.127423305227, 0.098217909507, 0.0723906956301, 0.0457840790019, 0.0325691800506, 0.0207065223098, 0.0137400799931, 0.00547944733578, -0.000268557810876, -0.00301934919753, -0.00213643706217, -0.0101846106787, -0.0170002602175, -0.0225833856784, -0.0269339870616, -0.030052064367, -0.0319376175946, -0.0325906467444, -0.0320111518164, -0.0301991328106, -0.0271545897271, -0.0228775225657, -0.0173679313266, -0.0106258160097, -0.00265117661497, 0.00655598685753, 0.0169956744078, 0.0286678860359, 0.0415726217417, 0.0557098815254, 0.0710796653868]) # @IgnorePep8 + + def test_hampelfilter(self): + + Y = np.array([4979, 5002, 5004, 5000, 4987, 4989, 5008, 5013, 5000, 4996, 5026, 5000, 5003, 4988, 4991, 5017, 5013, 5004, 4990, 4997, 5010, 5007, 5001, 4970, 5002, 4986, 5032, 5003, 4994, 5001, 4988, 4998, 5002, 4996, 4988, 5009, 5003, 4986, 4996, 4994, 4997, 5003, 5012, 5002, 5001, 5006, 5006, 4986, 4998, 4978, 4995, 4999, 4987, 5015, 5009, 5016, 4995, 5007, 5013, 4996, 5018, 4992, 4989, 4994, 4991, 4995, 5018, 5007, 5008, 4990, 5010, 4986, 5009, 4999, 5008, 5000, 5001, 5000, 5004, 5032, 5009, 5005, 5014, 5000, 4992, 4994, 4991, 4993, 5000, 5005, 4993, 5003, 4995, 4980, 4995, 4999, 5007, 5000, 4988, 4982, 5030, 4997, 4993, 5009, 4993, 5020, 5010, 4997, 4987, 4999, 5006, 4984, 5000, 4987, 4986, 5006, 5002, 5001, 5003, 4996, 4994, 5002, 4989, 4998, 4996, 5007, 4993, 4998, 5001, 4989, 5012, 5001, 5010, 4996, 5004, 5008, 5002, 5024, 4997, 5001, 5010, 5023, 4996, 5018, 5002, 4990, 5009, 4997, 5016, 5000, 5013, 5008, 4990, 5011, 4996, 5010, 5004, 5023, 4999, 5004, 4996, 5011, 4998, 5000, 4988, 5000, 4993, 4998, 5000, 5006, 5010, 4988, 5000, 4997, 4995, 4996, 5005, 5003, 5009, 5009, 4997, 5010, 5014, 4990, 5013, 5015, 5011, 4987, 5004, 4999, 5030, 5000, 5000, 4999, 5013, 5012, 5001, 5012, 4995, 4997, 4995, 4985, 4989, 5007, 5010, 4997, 5011, 4995, 5000, 5011, 4998, 4991, 5021, 5003, 4985, 4991, 4995, 5018, 4979, 5003, 5011, 5009, 5001, 4998, 5008, 4994, 5016, 4992, 5008, 4993, 4983, 5010, 5023, 4975, 4987, 4994, 5002, 4984, 5005, 5006, 5005, 5000, 4996, 5000, 4999, 5004, 4994, 5000, 4981, 5001, 4994, 4993, 5000, 5004, 5001, 4992, 5002, 5006, 4997, 4987, 5001, 5008, 5011, 4995, 5006, 4976, 4999, 4989, 5008, 4996, 4997, 5006, 5005, 5007, 4990, 5010, 4996, 4998, 5000, 5014, 5002, 5001, 4996, 4997, 5000, 5003, 5000, 4986, 5013, 5001, 4990, 4990, 5010, 5000, 5021, 5000, 5006, 4995, 5012, 5019, 5000, 5006, 4999, 5007, 5014, 5000, 4994, 4991, 5010, 4985, 4988, 5007, 5005, 5000, 5005, 4997, 4995, 4987, 5000, 5000, 5009, 5000, 4999, 5011, 5018, 4994, 5000, 4995, 5000, 5008, 4994, 4992, 5000, 4998, 4992, 5006, 4996, 5000, 5018, 5000, 5022, 5002, 5007, 5000, 5012, 5014, 5010, 4997, 4996, 5014, 4995, 4991, 5006, 4992, 5008, 5004, 4995, 5016, 4974, 5005, 5000, 4985, 5002, 5000, 5009, 4991, 4995, 5004, 4987, 5014, 4986, 5008, 4985, 4995, 5010, 5000, 5001, 5013, 4988, 5001, 5002, 4986, 4985, 5001, 4995, 5004, 4998, 4998, 4992, 5003, 5000, 4991, 4998, 5002, 5011, 4986, 5013, 4997, 5000, 4997, 5003, 5014, 4998, 5002, 5006, 5015, 4992, 4992, 4995, 4998, 4994, 5007, 4977, 5004, 5005, 4990, 4991, 5001, 5010, 4991, 4990, 5006, 5004, 5004, 4997, 5001, 4992, 5000, 5000, 4996, 4987, 4993, 5001, 5006, 4999, 4993, 4999, 5001, 5001, 5014, 4985, 5010, 5006, 4989, 5002, 5011, 4999, 5010, 5005, 5002, 5010, 4990, 4994, 5000, 4985, 5010, 5000, 4999, 5000, 4977, 5007, 5005, 4990, 5000, 4985, 5003, 5009, 5012, 5012, 5000, 5018, 4997, 5002, 4992, 4999, 4997, 5005, 5009, 4989, 5005, 4988, 5001, 5000, 5018, 4999, 5005, 4997, 5015, 5001, 4988, 4983, 5013, 4992, 5002, 5012, 4999, 5013, 5000, 4988, 4989, 4996, 5000, 5002, 4999, 5021, 4991, 5009, 5005, 4994, 5000, 4994, 4985, 4999, 4980, 5013, 5014, 5000, 4996, 5008, 5028, 5002, 5004, 4999, 5012, 4992, 5002, 4987, 5004, 5009, 5004, 5013, 4989, 5027, 4992, 5016, 5007, 5003, 5013, 5003, 4983, 5000, 4987, 5001, 4998, 4994, 4998, 4997, 5023, 4971, 5001, 4990, 5025, 5003, 4996, 5006, 5005, 4995, 4994, 5023, 5003, 5005, 4991, 5001, 5028, 4996, 5001, 5005, 5001, 5001, 5028, 4983, 5000, 5005, 5001, 4999, 5003, 4982, 5000, 5012, 5011, 5008, 5000, 4998, 4994, 4988, 5013, 4998, 5017, 4991, 5007, 5016, 5007, 4997, 4974, 4997, 5006, 5003, 5010, 5003, 4997, 4997, 4994, 4998, 4987, 5004, 4974, 5009, 5006, 5009, 4984, 5010, 5023, 5000, 5008, 4992, 5008, 4993, 5010, 5012, 4989, 5002, 4993, 5007, 4985, 4990, 4988, 4997, 5000, 4994, 5004, 4981, 5000, 4999, 5003, 4988, 5006, 5019, 5003, 4992, 4977, 4998, 4987, 4995, 4987, 5000, 4986, 4998, 4996, 5008, 5011, 5009, 5000, 4999, 5010, 4999, 5009, 5010, 4992, 4998, 4994, 5009, 4998, 5013, 5011, 4997, 5016, 4995, 5003, 4986, 5010, 4995, 4986, 5025, 4990, 5010, 4990, 4996, 5000, 5002, 4994, 5002, 5000, 5020, 4995, 5003, 5006, 5000, 4997, 4996, 5010, 4992, 5013, 4998, 4988, 4999, 5004, 5004, 5002, 5002, 5001, 4986, 5011, 5012, 4988, 5000, 5000, 5012, 5004, 5004, 4984, 5012, 4998, 5005, 5005, 5005, 4995, 4971, 5006, 5000, 5008, 5015, 4999, 4999, 4996, 5000, 4992, 5019, 5020, 4999, 4991, 5020, 5000, 5002, 5000, 5003, 4985, 4990, 5011, 5012, 4997, 4989, 4999, 5006, 4997, 4992, 4999, 4985, 4999, 5012, 5003, 4989, 5010, 5010, 5012, 4990, 4986, 5014, 5000, 4994, 5017, 4995, 5005, 5003, 5000, 5000, 4988, 5018, 5007, 5009, 5002, 5004, 4999, 5026, 4987, 4986, 5000, 4994, 5012, 5022, 4996, 5002, 4986, 4990, 4989, 5030, 4997, 5002, 5004, 4999, 5000, 4992, 4977, 4997, 4998, 5000, 4987, 5032, 4998, 5014, 4978, 5001, 4988, 5006, 5003, 5005, 5021, 5005, 5000, 5003, 4990, 4991, 4990, 5016, 5006, 4981, 5002, 4998, 4989, 4995, 5007, 5004, 5019, 5001, 5004, 5000, 4996, 4988, 5022, 5003, 5009, 4998, 5003, 4991, 5000, 4988, 5004, 5002, 4991, 4998, 4996, 4991, 5013, 5007, 5010, 5004, 5006, 5007, 4993, 5000, 5002, 4992, 4999, 4992, 5001, 4989, 4992, 5015, 5011, 5008, 5004, 4990, 4995, 4993, 5004, 4995, 4982, 5008, 5000, 4993, 5000, 5000, 4991, 5005, 5008, 5003, 4994, 4997, 5012, 4995, 5009, 5020, 5010, 5019, 4979, 5013, 4990, 5002, 5000, 5015, 4989, 5009, 4998, 5004, 5010, 4988, 4994, 5004, 4985, 4998, 4991, 4985, 4994, 4986, 5010, 4990, 5002, 5005, 5008, 5004, 4988, 4980, 5005, 4994, 5004, 4998, 4990, 5010, 5003, 5011, 4992, 5009, 5003, 5013, 4996, 4997, 4989, 4992, 5002, 4992, 4996, 4999, 5000, 5009, 4990, 4992, 5020, 4981, 5011, 5000, 5008, 4997, 4994, 4982, 5014, 5013, 4996, 5002, 5011, 5003, 5000, 5015, 4999, 5001, 5002, 5018, 4984, 5022, 5009, 5006, 5009, 5000, 4974, 4991, 5020, 5000, 4987, 5003, 4987, 5003, 5002, 5016, 4997, 5022, 5005, 4998, 4999, 5001, 5000, 5008, 5000, 5001, 4994, 4991, 4997, 4990, 4991, 4995, 5008, 5007, 4994, 5000, 5007, 4988, 5014, 5003, 4998, 4995, 5000, 5000, 5004], dtype=float) # @IgnorePep8 + # randint = np.random.randint + # Y = 5000 + np.int_(10*np.random.randn(1000)) + # outliers = randint(0, 1000, size=(10,)) + outliers = np.array([470, 795, 399, 614, 864, 37, 815, 112, 69, 16]) + # noise = randint(1000, size=(10,)) + noise = np.array([932, 286, 736, 427, 858, 63, 243, 264, 668, 844]) + # print(', '.join(['{0:d}'.format(y) for y in Y])) + Y[outliers] = Y[outliers] + noise + YY, _res = HampelFilter(fulloutput=True)(Y) + assert_array_almost_equal(YY[outliers], [5002, 5000, 5003, 5008, 5000, + 4997, 4998, 4999, 5009, 4997]) + assert_array_almost_equal(np.int_(YY), [5001, 5002, 5004, 5000, 4987, 4989, 5008, 5013, 5000, 4996, 5000, 5000, 5003, 4988, 4991, 5017, 4997, 5004, 4990, 4997, 5010, 5007, 5001, 4970, 5002, 4986, 5032, 5003, 4994, 5001, 4988, 4998, 5002, 4996, 4988, 5009, 5003, 4997, 4996, 4994, 4997, 5003, 5012, 5002, 5001, 5006, 5006, 4986, 4998, 4978, 4995, 4999, 4987, 5015, 5009, 5016, 4995, 5007, 5013, 4996, 5018, 4992, 4989, 4994, 4991, 4995, 5018, 5007, 5008, 5009, 5010, 5008, 5009, 4999, 5000, 5000, 5001, 5000, 5004, 5005, 5009, 5005, 5014, 5000, 4992, 4994, 4991, 4993, 5000, 5005, 4993, 5003, 4995, 4980, 4995, 4999, 5007, 5000, 4988, 4982, 5030, 4997, 4993, 5009, 4993, 5020, 5010, 4997, 4987, 4999, 5006, 4984, 4999, 4987, 4986, 5006, 5002, 5001, 5003, 4996, 4994, 5002, 4989, 4998, 4996, 5007, 4993, 4998, 5001, 4989, 5012, 5001, 5010, 4996, 5004, 5008, 5002, 5004, 4997, 5001, 5010, 5023, 4996, 5018, 5002, 4990, 5009, 4997, 5016, 5000, 5013, 5008, 4990, 5011, 4996, 5010, 5004, 5023, 4999, 5004, 4996, 5011, 4998, 5000, 4998, 5000, 4993, 4998, 5000, 5006, 5010, 4988, 5000, 4997, 4995, 4996, 5005, 5003, 5009, 5009, 4997, 5010, 5014, 5011, 5013, 5015, 5011, 4987, 5004, 4999, 5000, 5000, 5000, 4999, 5001, 5012, 5001, 5012, 4995, 4997, 4995, 4985, 4989, 5007, 5010, 4997, 5011, 4995, 5000, 5011, 4998, 4991, 5021, 5003, 4985, 4991, 4995, 5018, 4979, 5003, 5011, 5009, 5001, 4998, 5008, 4994, 5016, 4992, 5008, 4993, 4983, 5010, 5023, 4975, 4987, 4994, 5002, 5002, 5005, 5006, 5005, 5000, 4996, 5000, 4999, 5004, 5000, 5000, 4981, 5001, 4994, 4993, 5000, 5004, 5001, 4992, 5002, 5006, 4997, 4987, 5001, 5008, 5011, 4995, 5006, 4976, 4999, 4989, 5008, 4996, 4997, 5006, 5005, 5007, 4990, 5010, 4996, 4998, 5000, 5000, 5002, 5001, 4996, 4997, 5000, 5003, 5000, 5000, 5013, 5001, 4990, 4990, 5010, 5000, 5021, 5000, 5006, 4995, 5012, 5019, 5000, 5006, 4999, 5007, 5014, 5000, 4994, 4991, 5010, 4985, 4988, 5007, 5005, 5000, 5005, 4997, 4995, 4987, 5000, 5000, 5000, 5000, 4999, 5011, 5018, 4994, 5000, 4995, 5000, 5008, 4994, 4992, 5000, 4998, 4992, 5006, 4996, 5000, 5018, 5000, 5002, 5002, 5007, 5000, 5012, 5014, 5010, 4997, 4996, 5014, 4995, 4991, 5006, 4992, 5008, 5004, 4995, 5016, 5000, 5005, 5000, 4985, 5002, 5000, 5009, 4991, 4995, 5004, 4987, 5014, 4986, 5008, 4985, 4995, 5010, 5000, 5001, 5001, 5001, 5001, 5002, 4986, 5001, 5001, 4995, 5004, 4998, 4998, 4992, 5003, 5000, 4991, 4998, 5002, 5011, 5000, 5013, 4997, 5000, 5003, 5003, 5014, 4998, 5002, 5006, 5015, 4992, 4992, 4995, 4998, 4994, 5007, 4977, 5004, 5005, 4990, 4991, 4991, 4991, 4991, 5004, 5006, 5004, 5004, 4997, 5001, 4992, 5000, 5000, 4996, 4987, 4993, 5001, 5006, 4999, 4993, 4999, 5001, 5001, 5014, 4985, 5010, 5006, 4989, 5002, 5011, 4999, 5010, 5005, 5002, 5010, 4990, 4994, 5000, 4985, 5000, 5000, 4999, 5000, 5000, 5007, 5005, 4990, 5000, 4985, 5003, 5009, 5012, 5012, 5000, 5002, 4997, 5002, 4992, 4999, 4997, 5005, 5009, 4989, 5005, 4988, 5001, 5000, 5000, 4999, 5005, 4997, 5015, 5001, 4988, 4983, 5013, 4992, 5002, 5012, 4999, 5013, 5000, 4988, 4989, 4996, 5000, 5002, 4999, 5002, 4991, 5009, 5005, 4994, 5000, 4994, 4985, 4999, 4980, 5013, 5014, 5000, 4996, 5008, 5002, 5002, 5004, 4999, 5012, 4992, 5002, 4987, 5004, 5009, 5004, 5013, 4989, 5027, 4992, 5016, 5007, 5003, 5013, 5003, 5001, 5000, 4987, 5001, 4998, 4994, 4998, 4997, 4997, 4971, 5001, 4990, 5001, 5003, 4996, 5006, 5005, 4995, 5005, 5023, 5003, 5005, 4991, 5001, 5001, 4996, 5001, 5005, 5001, 5001, 5001, 5001, 5000, 5005, 5001, 4999, 5003, 5001, 5000, 5012, 5011, 5008, 5000, 4998, 4994, 4988, 5013, 4998, 5017, 4991, 5007, 5016, 5007, 4997, 5003, 4997, 5006, 5003, 5010, 5003, 4997, 4997, 4994, 4998, 4987, 5004, 5004, 5009, 5006, 5009, 5009, 5010, 5023, 5000, 5008, 5008, 5008, 4993, 5010, 5012, 4989, 5002, 4993, 4990, 4985, 4990, 4988, 4997, 5000, 4994, 5004, 5000, 5000, 4999, 5003, 5003, 5006, 5019, 5003, 4992, 4977, 4998, 4987, 4995, 4987, 5000, 4986, 4998, 4996, 5008, 5011, 5009, 5000, 5009, 5010, 4999, 5009, 5010, 4992, 4998, 4994, 5009, 4998, 5013, 5011, 4997, 5016, 4995, 5003, 4986, 5010, 4995, 4986, 5025, 4990, 5010, 4990, 4996, 5000, 5002, 4994, 5002, 5000, 5002, 4995, 5003, 5006, 5000, 4997, 4996, 4998, 4992, 5013, 4998, 4988, 4999, 5004, 5004, 5002, 5002, 5001, 4986, 5011, 5012, 4988, 5000, 5000, 5012, 5004, 5004, 4984, 5004, 5005, 5005, 5005, 5005, 5005, 5005, 5006, 5000, 5008, 5015, 4999, 4999, 4996, 5000, 4992, 5019, 5020, 4999, 4991, 5000, 5000, 5002, 5000, 5003, 4985, 4990, 5011, 5012, 4997, 4989, 4999, 4997, 4997, 4992, 4999, 4985, 4999, 5012, 5003, 5010, 5010, 5010, 5012, 5010, 4986, 5014, 5000, 4994, 5017, 4995, 5005, 5003, 5000, 5000, 4988, 5018, 5007, 5009, 5002, 5004, 4999, 5000, 4987, 4986, 5000, 4994, 5012, 5022, 4996, 5002, 4986, 4990, 4989, 4997, 4997, 5002, 5004, 4999, 5000, 4992, 4998, 4997, 4998, 5000, 5000, 5032, 4998, 5014, 4978, 5001, 5003, 5006, 5003, 5005, 5005, 5005, 5000, 5003, 4990, 4991, 4990, 5016, 5006, 4981, 4998, 4998, 4989, 4995, 5007, 5004, 5004, 5001, 5004, 5000, 4996, 4988, 5000, 5003, 5009, 4998, 5003, 4991, 5000, 4988, 5004, 5002, 4991, 4998, 4996, 4991, 5013, 5007, 5010, 5004, 5006, 5007, 4993, 5000, 5002, 4992, 4999, 4992, 5001, 4989, 4992, 5015, 5011, 5008, 5004, 4990, 4995, 4993, 5004, 5000, 4982, 5008, 5000, 4993, 5000, 5000, 4991, 5005, 5008, 5003, 4994, 4997, 5012, 4995, 5009, 5020, 5010, 5019, 4979, 5013, 4990, 5002, 5000, 5015, 4989, 5009, 4998, 5004, 5010, 4988, 4994, 5004, 4985, 4998, 4991, 4985, 4994, 4986, 5010, 4990, 5002, 5005, 5008, 5004, 4988, 5004, 5005, 4994, 5004, 4998, 4990, 5010, 5003, 5011, 4992, 5009, 5003, 5013, 4996, 4997, 4989, 4992, 5002, 4992, 4996, 4999, 5000, 5009, 4990, 4992, 5020, 4981, 5011, 5000, 5008, 4997, 4994, 4982, 5014, 5013, 4996, 5002, 5011, 5003, 5000, 5002, 4999, 5001, 5002, 5018, 4984, 5022, 5009, 5006, 5009, 5000, 4974, 4991, 5020, 5000, 4987, 5003, 5002, 5003, 5002, 5016, 4997, 5002, 5005, 4998, 4999, 5001, 5000, 5000, 5000, 5001, 4994, 4991, 4997, 4990, 4991, 4995, 5008, 5007, 4994, 5000, 5007, 4988, 5014, 5003, 4998, 4995, 5000, 5000, 5004]) # @IgnorePep8 + + YY1, _res1 = HampelFilter(dx=1, t=3, adaptive=0.1, fulloutput=True)(Y) + assert_array_almost_equal(np.int_(YY1), [4999, 5002, 5004, 5000, 4987, 4989, 5008, 5013, 5000, 4996, 5026, 5000, 5003, 4988, 4991, 5017, 5003, 5004, 4990, 4997, 5010, 5007, 5001, 4970, 5002, 4986, 5032, 5003, 4994, 5001, 4988, 4998, 5002, 4996, 4988, 5009, 5003, 5001, 4996, 4994, 4997, 5003, 5012, 5002, 5001, 5006, 5006, 4986, 4998, 4978, 4995, 4999, 4987, 5015, 5009, 5016, 4995, 5007, 5013, 4996, 5018, 4992, 4989, 4994, 4991, 4995, 5018, 5007, 5008, 5006, 5010, 4986, 5009, 4999, 5008, 5000, 5001, 5000, 5004, 5004, 5009, 5005, 5014, 5000, 4992, 4994, 4991, 4993, 5000, 5005, 4993, 5003, 4995, 4980, 4995, 4999, 5007, 5000, 4988, 4982, 5030, 4997, 4993, 5009, 4993, 5020, 5010, 4997, 4987, 4999, 5006, 4984, 4998, 4987, 4986, 5006, 5002, 5001, 5003, 4996, 4994, 5002, 4989, 4998, 4996, 5007, 4993, 4998, 5001, 4989, 5012, 5001, 5010, 4996, 5004, 5008, 5002, 5024, 4997, 5001, 5010, 5023, 4996, 5018, 5002, 4990, 5009, 4997, 5016, 5000, 5013, 5008, 4990, 5011, 4996, 5010, 5004, 5023, 4999, 5004, 4996, 5011, 4998, 5000, 4988, 5000, 4993, 4998, 5000, 5006, 5010, 4988, 5000, 4997, 4995, 4996, 5005, 5003, 5009, 5009, 4997, 5010, 5014, 5009, 5013, 5015, 5011, 5005, 5004, 4999, 5002, 5000, 5000, 4999, 5013, 5012, 5001, 5012, 4995, 4997, 4995, 4985, 4989, 5007, 5010, 4997, 5011, 4995, 5000, 5011, 4998, 4991, 5021, 5003, 4985, 4991, 4995, 5018, 4979, 5003, 5011, 5009, 5001, 4998, 5008, 4994, 5016, 4992, 5008, 4993, 4983, 5010, 5023, 4975, 4987, 4994, 5002, 4984, 5005, 5006, 5005, 5000, 4996, 5000, 4999, 5004, 4994, 5000, 4981, 5001, 4994, 4993, 5000, 5004, 5001, 4992, 5002, 5006, 4997, 4987, 5001, 5008, 5011, 4995, 5006, 4976, 4999, 4989, 5008, 4996, 4997, 5006, 5005, 5007, 4990, 5010, 4996, 4998, 5000, 5000, 5002, 5001, 4996, 4997, 5000, 5003, 5000, 4986, 5013, 5001, 4990, 4990, 5010, 5000, 5021, 5000, 5006, 4995, 5012, 5019, 5000, 5006, 4999, 5007, 5014, 5000, 4994, 4991, 5010, 4985, 4988, 5007, 5005, 5000, 5005, 4997, 4995, 4999, 5000, 5000, 5009, 5000, 4999, 5011, 5018, 4994, 5000, 4995, 5000, 5008, 4994, 4992, 5000, 4998, 4992, 5006, 4996, 5000, 5018, 5000, 5022, 5002, 5007, 5000, 5012, 5014, 5010, 4997, 4996, 5014, 4995, 4991, 5006, 4992, 5008, 5004, 4995, 5016, 5000, 5005, 5000, 4985, 5002, 5000, 5009, 4991, 4995, 5004, 4987, 5014, 4986, 5008, 4985, 4995, 5010, 5000, 5001, 5013, 4988, 5001, 5002, 4986, 4985, 5001, 4995, 5004, 4998, 4998, 4992, 5003, 5000, 4991, 4998, 5002, 5011, 4986, 5013, 4997, 5000, 5002, 5003, 5014, 4998, 5002, 5006, 5015, 4992, 4992, 4995, 4998, 4994, 5007, 4977, 5004, 5005, 4990, 4991, 5001, 5010, 4991, 4990, 5006, 5004, 5004, 4997, 5001, 4992, 5000, 5000, 4996, 4987, 4993, 5001, 5006, 4999, 4993, 4999, 5001, 5001, 5014, 4985, 5010, 5006, 4989, 5002, 5011, 4999, 5010, 5005, 5002, 5010, 4990, 4994, 5000, 4985, 5010, 5000, 4999, 5000, 4977, 5007, 5005, 4990, 5000, 4985, 5003, 5009, 5012, 5012, 5000, 5003, 4997, 5002, 4992, 4999, 4997, 5005, 5009, 4989, 5005, 4988, 5001, 5000, 5000, 4999, 5005, 4997, 5015, 5001, 4988, 4983, 5013, 4992, 5002, 5012, 4999, 5013, 5000, 4988, 4989, 4996, 5000, 5002, 4999, 5021, 4991, 5009, 5005, 4994, 5000, 4994, 4985, 4999, 4980, 5013, 5014, 5000, 4996, 5008, 5028, 5002, 5004, 4999, 5012, 4992, 5002, 4987, 5004, 5009, 5004, 5013, 4989, 5027, 4992, 5016, 5007, 5003, 5013, 5003, 4999, 5000, 4987, 5001, 4998, 4994, 4998, 4997, 4998, 4998, 5001, 4990, 5025, 5003, 4996, 5006, 5005, 4995, 4994, 5023, 5003, 5005, 4991, 5001, 5001, 4996, 5001, 5005, 5001, 5001, 5000, 5000, 5000, 5005, 5001, 4999, 5003, 4982, 5000, 5012, 5011, 5008, 5000, 4998, 4994, 4988, 5013, 4998, 5017, 4991, 5007, 5016, 5007, 4997, 4974, 4997, 5006, 5003, 5010, 5003, 4997, 4997, 4994, 4998, 4987, 5004, 5001, 5009, 5006, 5009, 4984, 5010, 5023, 5000, 5008, 5007, 5008, 4993, 5010, 5012, 4989, 5002, 4993, 5007, 4985, 4990, 4988, 4997, 5000, 4994, 5004, 4981, 5000, 4999, 5003, 4988, 5006, 5019, 5003, 4992, 4977, 4998, 4987, 4995, 4987, 5000, 4986, 4998, 4996, 5008, 5011, 5009, 5000, 4999, 5010, 4999, 5009, 5010, 4992, 4998, 4994, 5009, 4998, 5013, 5011, 4997, 5016, 4995, 5003, 4986, 5010, 4995, 4986, 5025, 4990, 5010, 4990, 4996, 5000, 5002, 4994, 5002, 5000, 5001, 4995, 5003, 5006, 5000, 4997, 4996, 5010, 4992, 5013, 4998, 4988, 4999, 5004, 5004, 5002, 5002, 5001, 4986, 5011, 5012, 4988, 5000, 5000, 5012, 5004, 5004, 4984, 5012, 4998, 5005, 5005, 5005, 4995, 5004, 5006, 5000, 5008, 5015, 4999, 4999, 4996, 5000, 4992, 5019, 5020, 4999, 4991, 5020, 5000, 5002, 5000, 5003, 4985, 4990, 5011, 5012, 4997, 4989, 4999, 5006, 4997, 4992, 4999, 4985, 4999, 5012, 5003, 4989, 5010, 5010, 5012, 4990, 4986, 5014, 5000, 4994, 5017, 4995, 5005, 5003, 5000, 5000, 4988, 5018, 5007, 5009, 5002, 5004, 4999, 5026, 4987, 4986, 5000, 4994, 5012, 5022, 4996, 5002, 4986, 4990, 4989, 4997, 4997, 5002, 5004, 4999, 5000, 4992, 4999, 4997, 4998, 5000, 5002, 5032, 4998, 5014, 4978, 5001, 4988, 5006, 5003, 5005, 5002, 5005, 5000, 5003, 4990, 4991, 4990, 5016, 5006, 4981, 4999, 4998, 4989, 4995, 5007, 5004, 5019, 5001, 5004, 5000, 4996, 4988, 5001, 5003, 5009, 4998, 5003, 4991, 5000, 4988, 5004, 5002, 4991, 4998, 4996, 4991, 5013, 5007, 5010, 5004, 5006, 5007, 4993, 5000, 5002, 4992, 4999, 4992, 5001, 4989, 4992, 5015, 5011, 5008, 5004, 4990, 4995, 4993, 5004, 5000, 4982, 5008, 5000, 4993, 5000, 5000, 4991, 5005, 5008, 5003, 4994, 4997, 5012, 4995, 5009, 5020, 5010, 5019, 4979, 5013, 4990, 5002, 5000, 5015, 4989, 5009, 4998, 5004, 5010, 4988, 4994, 5004, 4985, 4998, 4991, 4985, 4994, 4986, 5010, 4990, 5002, 5005, 5008, 5004, 4988, 4980, 5005, 4994, 5004, 4998, 4990, 5010, 5003, 5011, 4992, 5009, 5003, 5013, 4996, 4997, 4989, 4992, 5002, 4992, 4996, 4999, 5000, 5009, 4990, 4992, 5020, 4981, 5011, 5000, 5008, 4997, 4994, 4982, 5014, 5013, 4996, 5002, 5011, 5003, 5000, 5015, 4999, 5001, 5002, 5018, 4984, 5022, 5009, 5006, 5009, 5000, 4974, 4991, 5020, 5000, 4987, 5003, 4987, 5003, 5002, 5016, 4997, 5022, 5005, 4998, 4999, 5001, 5000, 4999, 5000, 5001, 4994, 4991, 4997, 4990, 4991, 4995, 5008, 5007, 4994, 5000, 5007, 4988, 5014, 5003, 4998, 4995, 5000, 5000, 5004]) # @IgnorePep8 + + YY2, _res2 = HampelFilter(dx=3, t=0, fulloutput=True)(Y) # Y0 = + assert_array_almost_equal(np.int_(YY2), [5001, 5000, 4994, 5000, 5002, 5000, 5000, 5000, 5000, 5003, 5000, 5000, 5000, 5003, 5003, 5003, 4997, 5004, 5007, 5004, 5001, 5001, 5001, 5002, 5002, 5001, 5001, 5001, 4998, 5001, 4998, 4996, 4998, 4998, 5002, 5002, 4996, 4997, 5003, 5003, 5002, 5001, 5002, 5003, 5003, 5002, 5001, 4998, 4998, 4995, 4995, 4998, 4999, 4999, 5007, 5009, 5009, 5009, 5007, 4996, 4996, 4994, 4994, 4994, 4994, 4995, 5007, 5008, 5008, 5009, 5008, 5008, 5008, 5001, 5000, 5001, 5001, 5004, 5004, 5005, 5005, 5005, 5005, 5000, 4994, 4994, 4994, 4993, 4994, 4995, 4995, 4995, 4995, 4995, 4999, 4995, 4995, 4999, 4999, 4997, 4997, 4993, 4997, 5009, 4997, 4997, 4999, 4999, 4999, 4999, 4997, 4987, 4999, 5002, 5001, 5002, 5001, 5001, 5002, 5001, 4998, 4996, 4996, 4996, 4998, 4998, 4998, 4998, 5001, 5001, 5001, 5001, 5004, 5004, 5004, 5004, 5002, 5004, 5008, 5002, 5010, 5002, 5002, 5009, 5002, 5002, 5002, 5002, 5008, 5008, 5008, 5008, 5008, 5008, 5008, 5004, 5004, 5004, 5004, 5004, 5000, 4999, 5000, 4998, 4998, 4998, 5000, 5000, 5000, 5000, 5000, 5000, 4997, 4997, 4997, 5000, 5003, 5003, 5005, 5009, 5009, 5009, 5010, 5011, 5011, 5011, 5004, 5011, 5004, 5000, 5000, 5000, 5000, 5001, 5001, 5001, 5001, 5001, 4997, 4995, 4995, 4995, 4997, 4997, 4997, 5000, 5007, 5000, 4998, 5000, 5000, 5000, 4998, 4995, 4995, 4995, 4995, 4995, 5003, 5003, 5003, 5003, 5003, 5008, 5001, 5001, 4998, 4994, 4994, 5008, 4993, 4993, 4993, 4994, 4994, 4994, 4994, 5002, 5002, 5002, 5000, 5000, 5000, 5000, 5000, 4999, 5000, 4999, 4994, 4994, 5000, 5000, 5000, 5000, 5001, 5001, 5001, 5001, 5001, 5002, 5001, 5001, 5001, 5001, 4999, 4999, 4996, 4997, 4997, 4999, 5005, 5005, 5005, 5005, 5005, 5000, 5000, 5000, 5001, 5000, 5000, 5000, 5001, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5001, 5000, 5000, 5000, 5006, 5006, 5006, 5006, 5006, 5006, 5007, 5006, 5000, 5000, 5000, 5000, 4994, 4994, 4994, 5000, 5005, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 4995, 5000, 4998, 4998, 4998, 4996, 4998, 5000, 5000, 5000, 5002, 5002, 5002, 5007, 5007, 5010, 5007, 5007, 5010, 5010, 4997, 4997, 4996, 4996, 5004, 4995, 5004, 5004, 5004, 5004, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 4995, 4995, 4995, 4995, 4995, 5000, 5000, 5001, 5000, 5001, 5001, 5001, 5001, 5001, 4995, 5001, 4998, 4998, 4998, 4998, 4998, 4998, 4998, 4998, 5000, 5000, 5000, 4998, 5000, 5002, 5003, 5003, 5003, 5002, 5003, 5006, 5003, 5002, 4998, 4998, 4995, 4995, 4994, 4995, 4998, 4998, 4994, 5001, 5001, 5001, 4991, 4991, 5001, 5004, 5004, 5001, 5001, 5001, 5000, 5000, 4997, 4996, 4996, 5000, 4999, 4996, 4999, 4999, 5001, 5001, 4999, 5001, 5001, 5001, 5002, 5006, 5002, 5006, 5005, 5002, 5005, 5005, 5002, 5002, 5000, 5000, 5000, 4999, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5003, 5003, 5003, 5003, 5009, 5009, 5009, 5002, 5000, 4999, 4999, 4999, 4999, 4999, 4999, 5001, 5001, 5001, 5000, 5001, 5000, 5001, 5001, 5001, 4999, 5001, 4997, 5001, 5001, 4999, 5002, 5002, 5000, 5000, 4999, 4999, 5000, 4999, 4999, 4999, 5000, 5002, 5002, 5000, 5000, 4994, 4999, 4994, 4994, 4999, 4999, 4999, 5000, 5008, 5008, 5004, 5002, 5004, 5004, 5002, 5002, 5002, 5002, 5004, 5004, 5004, 5004, 5004, 5009, 5007, 5007, 5007, 5007, 5003, 5003, 5003, 5001, 5000, 4998, 4998, 4998, 4998, 4998, 4998, 4997, 4998, 5001, 5001, 5001, 5003, 5003, 5003, 5003, 5003, 5005, 5003, 5001, 5003, 5003, 5001, 5001, 5001, 5001, 5001, 5001, 5001, 5001, 5001, 5001, 5001, 5000, 5000, 5001, 5001, 5003, 5003, 5000, 5000, 5000, 5000, 4998, 4998, 4998, 4998, 5007, 5007, 5007, 5007, 4997, 5006, 5003, 5003, 5003, 5003, 5003, 5003, 4998, 4997, 4997, 4997, 4997, 4998, 5004, 5004, 5006, 5009, 5009, 5008, 5009, 5008, 5008, 5008, 5008, 5008, 5008, 5002, 5002, 5002, 4993, 4990, 4993, 4993, 4994, 4994, 4994, 4997, 4999, 5000, 4999, 5000, 5000, 5003, 5003, 5003, 4998, 4998, 4995, 4992, 4992, 4987, 4995, 4995, 4996, 4998, 5000, 5000, 5000, 5008, 5008, 5009, 5009, 5000, 4999, 4999, 4999, 4998, 4998, 4998, 4998, 5009, 5009, 5003, 5003, 5003, 4997, 4995, 4995, 4995, 4995, 4995, 4995, 4996, 5000, 4996, 5000, 5000, 5000, 5000, 5002, 5002, 5002, 5000, 5000, 5000, 5000, 5000, 4998, 4997, 4998, 4999, 4999, 5002, 5002, 5002, 5002, 5002, 5002, 5002, 5001, 5000, 5000, 5004, 5004, 5000, 5004, 5004, 5004, 5004, 5005, 5005, 5005, 5005, 5005, 5005, 5005, 5000, 5000, 5000, 5000, 4999, 4999, 4999, 4999, 4999, 5000, 5000, 5002, 5000, 5000, 5000, 5000, 5000, 5002, 5000, 4997, 4997, 4999, 4999, 4997, 4997, 4997, 4999, 4999, 4999, 4999, 4999, 5003, 5010, 5010, 5003, 5010, 5010, 5000, 5000, 4995, 5000, 5003, 5000, 5000, 5000, 5000, 5003, 5003, 5002, 5004, 5004, 5007, 5004, 5002, 5000, 4999, 4999, 5000, 4996, 5000, 5000, 4996, 4996, 4996, 4996, 4997, 4997, 4999, 5000, 5000, 4999, 4999, 4998, 4998, 4998, 4998, 4998, 5000, 5000, 5001, 5001, 5001, 5001, 5003, 5003, 5005, 5005, 5005, 5003, 5003, 5000, 5000, 5000, 4991, 4991, 4998, 4998, 4998, 4998, 4998, 5004, 5001, 5004, 5004, 5004, 5001, 5001, 5001, 5003, 5000, 5003, 5003, 5003, 5000, 5000, 5000, 5000, 4998, 4998, 4996, 4998, 4998, 4998, 5004, 5006, 5007, 5007, 5006, 5004, 5002, 5000, 4999, 4999, 4999, 4992, 4992, 4999, 5001, 5004, 5004, 5004, 5004, 5004, 5004, 4995, 4995, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5003, 5003, 5003, 5003, 5009, 5010, 5010, 5010, 5010, 5010, 5002, 5002, 5000, 5002, 5000, 5002, 5004, 5004, 4998, 5004, 4998, 4998, 4994, 4991, 4994, 4991, 4991, 4991, 4991, 4994, 5002, 5004, 5004, 5002, 5004, 5004, 5004, 4998, 4994, 4998, 5003, 5003, 5003, 5003, 5003, 5009, 5003, 5003, 4997, 4997, 4997, 4996, 4996, 4996, 4996, 4999, 4999, 4996, 4999, 4999, 5000, 5000, 5000, 5000, 5000, 4997, 5000, 5000, 4997, 4997, 5002, 5003, 5003, 5003, 5002, 5002, 5002, 5002, 5001, 5002, 5002, 5006, 5009, 5009, 5006, 5006, 5006, 5000, 5000, 5000, 4991, 5000, 5002, 5002, 5002, 5003, 5003, 5003, 5002, 5001, 5000, 5001, 5000, 5000, 5000, 5000, 5000, 4997, 4994, 4994, 4994, 4995, 4995, 4995, 5000, 5000, 5007, 5003, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000]) # @IgnorePep8 + # print(', '.join(['{0:d}'.format(int(y)) for y in YY2])) + + +if __name__ == "__main__": + # import sys;sys.argv = ['', 'Test.test_hampelfilter'] + unittest.main()