From 48e600641172e31e9fac734d218e58bec9f253ef Mon Sep 17 00:00:00 2001 From: michael Date: Sun, 29 Jul 2018 21:25:01 -0500 Subject: [PATCH 01/15] first commit to ensure tool chain correct --- pywt/_c99_config.py | 3 +++ pywt/_extensions/_pywt.pyx | 1 + pywt/_extensions/config.pxi | 3 +++ 3 files changed, 7 insertions(+) create mode 100644 pywt/_c99_config.py create mode 100644 pywt/_extensions/config.pxi diff --git a/pywt/_c99_config.py b/pywt/_c99_config.py new file mode 100644 index 000000000..2d22f7670 --- /dev/null +++ b/pywt/_c99_config.py @@ -0,0 +1,3 @@ +# Autogenerated file containing compile-time definitions + +_have_c99_complex = 0 diff --git a/pywt/_extensions/_pywt.pyx b/pywt/_extensions/_pywt.pyx index 93a2485e4..3015f1389 100644 --- a/pywt/_extensions/_pywt.pyx +++ b/pywt/_extensions/_pywt.pyx @@ -250,6 +250,7 @@ def wavelist(family=None, kind='all'): sorting_list.sort() for x, x, name in sorting_list: wavelets.append(name) + wavelets.append('pywtdev_0') return wavelets diff --git a/pywt/_extensions/config.pxi b/pywt/_extensions/config.pxi new file mode 100644 index 000000000..dd2a4514c --- /dev/null +++ b/pywt/_extensions/config.pxi @@ -0,0 +1,3 @@ +# Autogenerated file containing Cython compile-time defines + +DEF HAVE_C99_CPLX = 0 From f018bd352e5fd7f31adb7bd75f8368d7452a810a Mon Sep 17 00:00:00 2001 From: michael Date: Sun, 29 Jul 2018 22:12:34 -0500 Subject: [PATCH 02/15] Naive copy-paste estimate_sigma ripped out of scikit. --- pywt/_c99_config.py | 3 ++ pywt/_extensions/config.pxi | 3 ++ pywt/_thresholding.py | 92 ++++++++++++++++++++++++++++++++++++- 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 pywt/_c99_config.py create mode 100644 pywt/_extensions/config.pxi diff --git a/pywt/_c99_config.py b/pywt/_c99_config.py new file mode 100644 index 000000000..2d22f7670 --- /dev/null +++ b/pywt/_c99_config.py @@ -0,0 +1,3 @@ +# Autogenerated file containing compile-time definitions + +_have_c99_complex = 0 diff --git a/pywt/_extensions/config.pxi b/pywt/_extensions/config.pxi new file mode 100644 index 000000000..dd2a4514c --- /dev/null +++ b/pywt/_extensions/config.pxi @@ -0,0 +1,3 @@ +# Autogenerated file containing Cython compile-time defines + +DEF HAVE_C99_CPLX = 0 diff --git a/pywt/_thresholding.py b/pywt/_thresholding.py index 2b433d8bb..fa2754ed6 100644 --- a/pywt/_thresholding.py +++ b/pywt/_thresholding.py @@ -11,7 +11,10 @@ from __future__ import division, print_function, absolute_import import numpy as np -__all__ = ['threshold', 'threshold_firm'] +from ._multidim import dwtn + + +__all__ = ['threshold', 'threshold_firm', 'estimate_sigma'] def soft(data, value, substitute=0): @@ -245,3 +248,90 @@ def threshold_firm(data, value_low, value_high): if np.any(large_vals[0]): thresholded[large_vals] = data[large_vals] return thresholded + +def estimate_sigma(image, average_sigmas=False, multichannel=False): + """ + Robust wavelet-based estimator of the (Gaussian) noise standard deviation. + Parameters + ---------- + image : ndarray + Image for which to estimate the noise standard deviation. + average_sigmas : bool, optional + If true, average the channel estimates of `sigma`. Otherwise return + a list of sigmas corresponding to each channel. + multichannel : bool + Estimate sigma separately for each channel. + Returns + ------- + sigma : float or list + Estimated noise standard deviation(s). If `multichannel` is True and + `average_sigmas` is False, a separate noise estimate for each channel + is returned. Otherwise, the average of the individual channel + estimates is returned. + Notes + ----- + This function assumes the noise follows a Gaussian distribution. The + estimation algorithm is based on the median absolute deviation of the + wavelet detail coefficients as described in section 4.2 of [1]_. + References + ---------- + .. [1] D. L. Donoho and I. M. Johnstone. "Ideal spatial adaptation + by wavelet shrinkage." Biometrika 81.3 (1994): 425-455. + DOI:10.1093/biomet/81.3.425 + Examples + -------- + >>> import skimage.data + >>> from skimage import img_as_float + >>> img = img_as_float(skimage.data.camera()) + >>> sigma = 0.1 + >>> img = img + sigma * np.random.standard_normal(img.shape) + >>> sigma_hat = estimate_sigma(img, multichannel=False) + """ + if multichannel: + nchannels = image.shape[-1] + sigmas = [estimate_sigma( + image[..., c], multichannel=False) for c in range(nchannels)] + if average_sigmas: + sigmas = np.mean(sigmas) + return sigmas + elif image.shape[-1] <= 4: + msg = ("image is size {0} on the last axis, but multichannel is " + "False. If this is a color image, please set multichannel " + "to True for proper noise estimation.") + warn(msg.format(image.shape[-1])) + coeffs = dwtn(image, wavelet='db2') + detail_coeffs = coeffs['d' * image.ndim] + return _sigma_est_dwt(detail_coeffs, distribution='Gaussian') + +def _sigma_est_dwt(detail_coeffs, distribution='Gaussian'): + """Calculate the robust median estimator of the noise standard deviation. + Parameters + ---------- + detail_coeffs : ndarray + The detail coefficients corresponding to the discrete wavelet + transform of an image. + distribution : str + The underlying noise distribution. + Returns + ------- + sigma : float + The estimated noise standard deviation (see section 4.2 of [1]_). + References + ---------- + .. [1] D. L. Donoho and I. M. Johnstone. "Ideal spatial adaptation + by wavelet shrinkage." Biometrika 81.3 (1994): 425-455. + DOI:10.1093/biomet/81.3.425 + """ + # Consider regions with detail coefficients exactly zero to be masked out + detail_coeffs = detail_coeffs[np.nonzero(detail_coeffs)] + + if distribution.lower() == 'gaussian': + # 75th quantile of the underlying, symmetric noise distribution + # denom = scipy.stats.norm.ppf(0.75) + # magic number to fill in because no scipy + denom = 0.6744897501960817 + sigma = np.median(np.abs(detail_coeffs)) / denom + else: + raise ValueError("Only Gaussian noise estimation is currently " + "supported") + return sigma \ No newline at end of file From 3cb502e7de629fe9ba9a88dd05bd1e05931acb4a Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 31 Jul 2018 21:49:28 -0500 Subject: [PATCH 03/15] Removed image functions. Changed test and example. Comments to match. --- .vscode/settings.json | 3 +++ pywt/_thresholding.py | 47 ++++++++++++--------------------- pywt/tests/test_thresholding.py | 8 ++++++ 3 files changed, 28 insertions(+), 30 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..9a735737c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "C:\\Users\\micha\\Anaconda3\\envs\\pywt_dev\\python.exe" +} \ No newline at end of file diff --git a/pywt/_thresholding.py b/pywt/_thresholding.py index fa2754ed6..8b3f56f99 100644 --- a/pywt/_thresholding.py +++ b/pywt/_thresholding.py @@ -254,51 +254,38 @@ def estimate_sigma(image, average_sigmas=False, multichannel=False): Robust wavelet-based estimator of the (Gaussian) noise standard deviation. Parameters ---------- - image : ndarray - Image for which to estimate the noise standard deviation. - average_sigmas : bool, optional - If true, average the channel estimates of `sigma`. Otherwise return - a list of sigmas corresponding to each channel. - multichannel : bool - Estimate sigma separately for each channel. + data : ndarray + The data used to estimate sigma. + Returns ------- - sigma : float or list - Estimated noise standard deviation(s). If `multichannel` is True and - `average_sigmas` is False, a separate noise estimate for each channel - is returned. Otherwise, the average of the individual channel - estimates is returned. + sigma : float + Estimated noise standard deviation. + Notes ----- This function assumes the noise follows a Gaussian distribution. The estimation algorithm is based on the median absolute deviation of the wavelet detail coefficients as described in section 4.2 of [1]_. + References ---------- .. [1] D. L. Donoho and I. M. Johnstone. "Ideal spatial adaptation by wavelet shrinkage." Biometrika 81.3 (1994): 425-455. DOI:10.1093/biomet/81.3.425 + Examples -------- - >>> import skimage.data - >>> from skimage import img_as_float - >>> img = img_as_float(skimage.data.camera()) - >>> sigma = 0.1 - >>> img = img + sigma * np.random.standard_normal(img.shape) - >>> sigma_hat = estimate_sigma(img, multichannel=False) + >>> import numpy as np + >>> import pywt + >>> data = np.sin(np.linspace(0,10,1000)) + >>> np.random.seed(42) + >>> noise = np.random.normal(0,1,1000) + >>> sigma = pywt.estimate_sigma(data + noise) + >>> print(sigma) + 0.9736668419858439 """ - if multichannel: - nchannels = image.shape[-1] - sigmas = [estimate_sigma( - image[..., c], multichannel=False) for c in range(nchannels)] - if average_sigmas: - sigmas = np.mean(sigmas) - return sigmas - elif image.shape[-1] <= 4: - msg = ("image is size {0} on the last axis, but multichannel is " - "False. If this is a color image, please set multichannel " - "to True for proper noise estimation.") - warn(msg.format(image.shape[-1])) + coeffs = dwtn(image, wavelet='db2') detail_coeffs = coeffs['d' * image.ndim] return _sigma_est_dwt(detail_coeffs, distribution='Gaussian') diff --git a/pywt/tests/test_thresholding.py b/pywt/tests/test_thresholding.py index b618b94ae..22d312e37 100644 --- a/pywt/tests/test_thresholding.py +++ b/pywt/tests/test_thresholding.py @@ -169,6 +169,14 @@ def test_threshold_firm(): assert_(np.all(mt_abs_firm < np.abs(d_hard[mt]))) assert_(np.all(mt_abs_firm > np.abs(d_soft[mt]))) +def test_estimate_sigma(): + sigma_test_data = np.sin(np.linspace(0,10,1000)) + np.random.seed(42) + sigma_test_noise = np.random.normal(0,1,1000) + # TODO: get rid of magic number for test... + # can test by creating a list of noise arrays to pass in with varying sigmas + assert_allclose(pywt.estimate_sigma(sigma_test_data + sigma_test_noise), + 0.9736668419858439) if __name__ == '__main__': run_module_suite() From 25fab8758cc5eaaa1a07f96c4e5f949155c6cf19 Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 31 Jul 2018 21:58:09 -0500 Subject: [PATCH 04/15] Removed temp and vs code files. --- .vscode/settings.json | 3 --- pywt/_c99_config.py | 3 --- pywt/_extensions/config.pxi | 3 --- 3 files changed, 9 deletions(-) delete mode 100644 .vscode/settings.json delete mode 100644 pywt/_c99_config.py delete mode 100644 pywt/_extensions/config.pxi diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 9a735737c..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "python.pythonPath": "C:\\Users\\micha\\Anaconda3\\envs\\pywt_dev\\python.exe" -} \ No newline at end of file diff --git a/pywt/_c99_config.py b/pywt/_c99_config.py deleted file mode 100644 index 2d22f7670..000000000 --- a/pywt/_c99_config.py +++ /dev/null @@ -1,3 +0,0 @@ -# Autogenerated file containing compile-time definitions - -_have_c99_complex = 0 diff --git a/pywt/_extensions/config.pxi b/pywt/_extensions/config.pxi deleted file mode 100644 index dd2a4514c..000000000 --- a/pywt/_extensions/config.pxi +++ /dev/null @@ -1,3 +0,0 @@ -# Autogenerated file containing Cython compile-time defines - -DEF HAVE_C99_CPLX = 0 From 65ce36c7c42c05a4c0df8af5f669fa681d2deb00 Mon Sep 17 00:00:00 2001 From: michael Date: Wed, 1 Aug 2018 14:45:38 -0500 Subject: [PATCH 05/15] Fixed variables in estimate_sigma input. --- pywt/_thresholding.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pywt/_thresholding.py b/pywt/_thresholding.py index 8b3f56f99..e1b3d7a48 100644 --- a/pywt/_thresholding.py +++ b/pywt/_thresholding.py @@ -249,7 +249,7 @@ def threshold_firm(data, value_low, value_high): thresholded[large_vals] = data[large_vals] return thresholded -def estimate_sigma(image, average_sigmas=False, multichannel=False): +def estimate_sigma(data): """ Robust wavelet-based estimator of the (Gaussian) noise standard deviation. Parameters @@ -286,8 +286,8 @@ def estimate_sigma(image, average_sigmas=False, multichannel=False): 0.9736668419858439 """ - coeffs = dwtn(image, wavelet='db2') - detail_coeffs = coeffs['d' * image.ndim] + coeffs = dwtn(data, wavelet='db2') + detail_coeffs = coeffs['d' * data.ndim] return _sigma_est_dwt(detail_coeffs, distribution='Gaussian') def _sigma_est_dwt(detail_coeffs, distribution='Gaussian'): From 1e53ece10d4f500e153d1234f124c67376a210be Mon Sep 17 00:00:00 2001 From: michael Date: Fri, 3 Aug 2018 15:23:30 -0500 Subject: [PATCH 06/15] Fixed PEP8 violations. --- pywt/_thresholding.py | 8 +++++--- pywt/tests/test_thresholding.py | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pywt/_thresholding.py b/pywt/_thresholding.py index e1b3d7a48..0c03da775 100644 --- a/pywt/_thresholding.py +++ b/pywt/_thresholding.py @@ -249,6 +249,7 @@ def threshold_firm(data, value_low, value_high): thresholded[large_vals] = data[large_vals] return thresholded + def estimate_sigma(data): """ Robust wavelet-based estimator of the (Gaussian) noise standard deviation. @@ -273,7 +274,7 @@ def estimate_sigma(data): .. [1] D. L. Donoho and I. M. Johnstone. "Ideal spatial adaptation by wavelet shrinkage." Biometrika 81.3 (1994): 425-455. DOI:10.1093/biomet/81.3.425 - + Examples -------- >>> import numpy as np @@ -285,11 +286,12 @@ def estimate_sigma(data): >>> print(sigma) 0.9736668419858439 """ - + coeffs = dwtn(data, wavelet='db2') detail_coeffs = coeffs['d' * data.ndim] return _sigma_est_dwt(detail_coeffs, distribution='Gaussian') + def _sigma_est_dwt(detail_coeffs, distribution='Gaussian'): """Calculate the robust median estimator of the noise standard deviation. Parameters @@ -321,4 +323,4 @@ def _sigma_est_dwt(detail_coeffs, distribution='Gaussian'): else: raise ValueError("Only Gaussian noise estimation is currently " "supported") - return sigma \ No newline at end of file + return sigma diff --git a/pywt/tests/test_thresholding.py b/pywt/tests/test_thresholding.py index 22d312e37..b02a64a2d 100644 --- a/pywt/tests/test_thresholding.py +++ b/pywt/tests/test_thresholding.py @@ -169,6 +169,7 @@ def test_threshold_firm(): assert_(np.all(mt_abs_firm < np.abs(d_hard[mt]))) assert_(np.all(mt_abs_firm > np.abs(d_soft[mt]))) + def test_estimate_sigma(): sigma_test_data = np.sin(np.linspace(0,10,1000)) np.random.seed(42) From 484856baf9cfb37a18794bde52969cd728d9d152 Mon Sep 17 00:00:00 2001 From: michael Date: Sat, 4 Aug 2018 13:25:14 -0500 Subject: [PATCH 07/15] Remove print from example in doc to get travis to pass 2.7 build. --- pywt/_thresholding.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pywt/_thresholding.py b/pywt/_thresholding.py index 0c03da775..e162c6ad6 100644 --- a/pywt/_thresholding.py +++ b/pywt/_thresholding.py @@ -283,8 +283,6 @@ def estimate_sigma(data): >>> np.random.seed(42) >>> noise = np.random.normal(0,1,1000) >>> sigma = pywt.estimate_sigma(data + noise) - >>> print(sigma) - 0.9736668419858439 """ coeffs = dwtn(data, wavelet='db2') From 407985b84a6d082d11cd39a22fbdf87dc286ab51 Mon Sep 17 00:00:00 2001 From: michael Date: Thu, 16 Aug 2018 23:45:23 -0500 Subject: [PATCH 08/15] Added ability to pass in object with ppf method. --- pywt/_thresholding.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/pywt/_thresholding.py b/pywt/_thresholding.py index e162c6ad6..08996f5ae 100644 --- a/pywt/_thresholding.py +++ b/pywt/_thresholding.py @@ -250,13 +250,17 @@ def threshold_firm(data, value_low, value_high): return thresholded -def estimate_sigma(data): +def estimate_sigma(data, distribution='Gaussian', **kwargs): """ Robust wavelet-based estimator of the (Gaussian) noise standard deviation. Parameters ---------- data : ndarray The data used to estimate sigma. + distribution : str or object with ppf method + The underlying noise distribution. + **kwargs : **kwargs + Keyword arguments to pass into distribution ppf method. Returns ------- @@ -287,18 +291,21 @@ def estimate_sigma(data): coeffs = dwtn(data, wavelet='db2') detail_coeffs = coeffs['d' * data.ndim] - return _sigma_est_dwt(detail_coeffs, distribution='Gaussian') + return _sigma_est_dwt(detail_coeffs, distribution=distribution, **kwargs) -def _sigma_est_dwt(detail_coeffs, distribution='Gaussian'): +def _sigma_est_dwt(detail_coeffs, distribution='Gaussian', **kwargs): """Calculate the robust median estimator of the noise standard deviation. Parameters ---------- detail_coeffs : ndarray The detail coefficients corresponding to the discrete wavelet transform of an image. - distribution : str + distribution : str or object with ppf method The underlying noise distribution. + **kwargs : **kwargs + Keyword arguments to pass into distribution ppf method. + Returns ------- sigma : float @@ -312,13 +319,17 @@ def _sigma_est_dwt(detail_coeffs, distribution='Gaussian'): # Consider regions with detail coefficients exactly zero to be masked out detail_coeffs = detail_coeffs[np.nonzero(detail_coeffs)] - if distribution.lower() == 'gaussian': + if hasattr(distribution, 'ppf'): + if not kwargs: + kwargs = {'q': 0.75} + denom = distribution.ppf(**kwargs) + elif str(distribution).lower() == 'gaussian': # 75th quantile of the underlying, symmetric noise distribution # denom = scipy.stats.norm.ppf(0.75) # magic number to fill in because no scipy denom = 0.6744897501960817 - sigma = np.median(np.abs(detail_coeffs)) / denom else: - raise ValueError("Only Gaussian noise estimation is currently " - "supported") + raise ValueError("Only Gaussian noise estimation or objects with" + " ppf method currently supported") + sigma = np.median(np.abs(detail_coeffs)) / denom return sigma From ed1d9ff512a902013c75fdde19b3825454bd7515 Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 7 May 2019 22:29:27 -0500 Subject: [PATCH 09/15] Fixed test wavelet leftover. --- pywt/_extensions/_pywt.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pywt/_extensions/_pywt.pyx b/pywt/_extensions/_pywt.pyx index 6c2a90c62..a8cc7c350 100644 --- a/pywt/_extensions/_pywt.pyx +++ b/pywt/_extensions/_pywt.pyx @@ -250,7 +250,7 @@ def wavelist(family=None, kind='all'): sorting_list.sort() for x, x, name in sorting_list: wavelets.append(name) - wavelets.append('pywtdev_0') + #wavelets.append('pywtdev_0') return wavelets From 11282daed49af26e79d8cda9ebfab4e0abca81a1 Mon Sep 17 00:00:00 2001 From: Michael John Haas II Date: Mon, 14 Oct 2019 22:40:22 -0500 Subject: [PATCH 10/15] Add estimate_sigma to docs. --- doc/source/ref/thresholding-functions.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/ref/thresholding-functions.rst b/doc/source/ref/thresholding-functions.rst index b0424cad3..f0ef00d67 100644 --- a/doc/source/ref/thresholding-functions.rst +++ b/doc/source/ref/thresholding-functions.rst @@ -12,6 +12,7 @@ Thresholding .. autofunction:: threshold .. autofunction:: threshold_firm +.. autofunction:: estimate_sigma The left panel of the figure below illustrates that non-negative Garotte thresholding is intermediate between soft and hard thresholding. Firm From 606fae6571534ebda0ea9f8502dfb7907f560585 Mon Sep 17 00:00:00 2001 From: Michael John Haas II Date: Mon, 14 Oct 2019 22:41:43 -0500 Subject: [PATCH 11/15] Remove debug wavelet name. --- pywt/_extensions/_pywt.pyx | 1 - 1 file changed, 1 deletion(-) diff --git a/pywt/_extensions/_pywt.pyx b/pywt/_extensions/_pywt.pyx index a8cc7c350..95388c9dc 100644 --- a/pywt/_extensions/_pywt.pyx +++ b/pywt/_extensions/_pywt.pyx @@ -250,7 +250,6 @@ def wavelist(family=None, kind='all'): sorting_list.sort() for x, x, name in sorting_list: wavelets.append(name) - #wavelets.append('pywtdev_0') return wavelets From 0ba3996c9ef4e05147d2792c67b1da98f05ce230 Mon Sep 17 00:00:00 2001 From: Michael John Haas II Date: Mon, 14 Oct 2019 22:42:33 -0500 Subject: [PATCH 12/15] Fixing docstring formatting. --- pywt/_thresholding.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pywt/_thresholding.py b/pywt/_thresholding.py index 2f861a524..82698cf55 100644 --- a/pywt/_thresholding.py +++ b/pywt/_thresholding.py @@ -256,13 +256,14 @@ def threshold_firm(data, value_low, value_high): def estimate_sigma(data, distribution='Gaussian', **kwargs): """ Robust wavelet-based estimator of the (Gaussian) noise standard deviation. + Parameters ---------- data : ndarray The data used to estimate sigma. distribution : str or object with ppf method The underlying noise distribution. - **kwargs : **kwargs + \\**kwargs : \\**kwargs Keyword arguments to pass into distribution ppf method. Returns @@ -286,10 +287,11 @@ def estimate_sigma(data, distribution='Gaussian', **kwargs): -------- >>> import numpy as np >>> import pywt - >>> data = np.sin(np.linspace(0,10,1000)) + >>> data = np.sin(np.linspace(0,10,100)) >>> np.random.seed(42) - >>> noise = np.random.normal(0,1,1000) - >>> sigma = pywt.estimate_sigma(data + noise) + >>> noise = 0.5 * np.random.normal(0,1,100) + >>> pywt.estimate_sigma(data + noise) + 0.45634925413327504 """ coeffs = dwtn(data, wavelet='db2') @@ -306,7 +308,7 @@ def _sigma_est_dwt(detail_coeffs, distribution='Gaussian', **kwargs): transform of an image. distribution : str or object with ppf method The underlying noise distribution. - **kwargs : **kwargs + \\**kwargs : \\**kwargs Keyword arguments to pass into distribution ppf method. Returns From 644a1c5723eaf835e7e3af11d21cb01524d593b6 Mon Sep 17 00:00:00 2001 From: Michael John Haas II Date: Mon, 14 Oct 2019 22:48:14 -0500 Subject: [PATCH 13/15] Add tests for estimate_sigma --- pywt/tests/test_thresholding.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pywt/tests/test_thresholding.py b/pywt/tests/test_thresholding.py index abe69fadf..203cd8e08 100644 --- a/pywt/tests/test_thresholding.py +++ b/pywt/tests/test_thresholding.py @@ -167,3 +167,16 @@ def test_threshold_firm(): mt_abs_firm = np.abs(d_firm[mt]) assert_(np.all(mt_abs_firm < np.abs(d_hard[mt]))) assert_(np.all(mt_abs_firm > np.abs(d_soft[mt]))) + + +def test_estimate_sigma(): + data = np.sin(np.linspace(0, 10, 1000)) + np.random.seed(42) + noise = 0.5 * np.random.normal(0, 1, 1000) + sigma = pywt.estimate_sigma(data + noise) + assert_allclose(sigma, 0.4867884459318056) + + assert_raises(ValueError, pywt.estimate_sigma, data, + distribution='not_a_distribution') + assert_raises(ValueError, pywt.estimate_sigma, data, + distribution=42) From 1f5beee7a9c8f44170102ce737587d191dcca931 Mon Sep 17 00:00:00 2001 From: Michael John Haas II Date: Tue, 15 Oct 2019 13:29:48 -0500 Subject: [PATCH 14/15] change estimate_sigma to estimate_noise --- doc/source/ref/thresholding-functions.rst | 2 +- pywt/_thresholding.py | 6 +++--- pywt/tests/test_thresholding.py | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/source/ref/thresholding-functions.rst b/doc/source/ref/thresholding-functions.rst index f0ef00d67..b09ecb92a 100644 --- a/doc/source/ref/thresholding-functions.rst +++ b/doc/source/ref/thresholding-functions.rst @@ -12,7 +12,7 @@ Thresholding .. autofunction:: threshold .. autofunction:: threshold_firm -.. autofunction:: estimate_sigma +.. autofunction:: estimate_noise The left panel of the figure below illustrates that non-negative Garotte thresholding is intermediate between soft and hard thresholding. Firm diff --git a/pywt/_thresholding.py b/pywt/_thresholding.py index 82698cf55..989971905 100644 --- a/pywt/_thresholding.py +++ b/pywt/_thresholding.py @@ -14,7 +14,7 @@ from ._multidim import dwtn -__all__ = ['threshold', 'threshold_firm', 'estimate_sigma'] +__all__ = ['threshold', 'threshold_firm', 'estimate_noise'] def soft(data, value, substitute=0): @@ -253,7 +253,7 @@ def threshold_firm(data, value_low, value_high): return thresholded -def estimate_sigma(data, distribution='Gaussian', **kwargs): +def estimate_noise(data, distribution='Gaussian', **kwargs): """ Robust wavelet-based estimator of the (Gaussian) noise standard deviation. @@ -290,7 +290,7 @@ def estimate_sigma(data, distribution='Gaussian', **kwargs): >>> data = np.sin(np.linspace(0,10,100)) >>> np.random.seed(42) >>> noise = 0.5 * np.random.normal(0,1,100) - >>> pywt.estimate_sigma(data + noise) + >>> pywt.estimate_noise(data + noise) 0.45634925413327504 """ diff --git a/pywt/tests/test_thresholding.py b/pywt/tests/test_thresholding.py index 203cd8e08..40edc8be9 100644 --- a/pywt/tests/test_thresholding.py +++ b/pywt/tests/test_thresholding.py @@ -169,14 +169,14 @@ def test_threshold_firm(): assert_(np.all(mt_abs_firm > np.abs(d_soft[mt]))) -def test_estimate_sigma(): +def test_estimate_noise(): data = np.sin(np.linspace(0, 10, 1000)) np.random.seed(42) noise = 0.5 * np.random.normal(0, 1, 1000) - sigma = pywt.estimate_sigma(data + noise) + sigma = pywt.estimate_noise(data + noise) assert_allclose(sigma, 0.4867884459318056) - assert_raises(ValueError, pywt.estimate_sigma, data, + assert_raises(ValueError, pywt.estimate_noise, data, distribution='not_a_distribution') - assert_raises(ValueError, pywt.estimate_sigma, data, + assert_raises(ValueError, pywt.estimate_noise, data, distribution=42) From 1c2a6ea56b009d0ab342329507840bccb663f329 Mon Sep 17 00:00:00 2001 From: micha2718l Date: Mon, 4 Mar 2024 14:09:31 -0600 Subject: [PATCH 15/15] removing auto files --- pywt/_c99_config.py | 3 --- pywt/_extensions/config.pxi | 3 --- 2 files changed, 6 deletions(-) delete mode 100644 pywt/_c99_config.py delete mode 100644 pywt/_extensions/config.pxi diff --git a/pywt/_c99_config.py b/pywt/_c99_config.py deleted file mode 100644 index 2d22f7670..000000000 --- a/pywt/_c99_config.py +++ /dev/null @@ -1,3 +0,0 @@ -# Autogenerated file containing compile-time definitions - -_have_c99_complex = 0 diff --git a/pywt/_extensions/config.pxi b/pywt/_extensions/config.pxi deleted file mode 100644 index dd2a4514c..000000000 --- a/pywt/_extensions/config.pxi +++ /dev/null @@ -1,3 +0,0 @@ -# Autogenerated file containing Cython compile-time defines - -DEF HAVE_C99_CPLX = 0