Skip to content

Commit

Permalink
Merge pull request #55 from aaren/issue38
Browse files Browse the repository at this point in the history
ENH: API changes
  • Loading branch information
rgommers committed Nov 24, 2015
2 parents e2426ae + c582eb2 commit f443dbd
Show file tree
Hide file tree
Showing 37 changed files with 544 additions and 385 deletions.
2 changes: 1 addition & 1 deletion demo/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


wavelets = [pywt.Wavelet(n) for n in wavelet_names]
mode = pywt.MODES.zpd
mode = pywt.Modes.zero

times_dwt = [[] for i in range(len(wavelets))]
times_idwt = [[] for i in range(len(wavelets))]
Expand Down
2 changes: 1 addition & 1 deletion demo/dwt_signal_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
x = np.linspace(0.082, 2.128, num=1024)[::-1]
data2 = np.sin(40 * np.log(x)) * np.sign((np.log(x)))

mode = pywt.MODES.sp1
mode = pywt.Modes.smooth


def plot_signal_decomp(data, w, title):
Expand Down
2 changes: 1 addition & 1 deletion demo/dwt_swt_show_coeffs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
x = np.linspace(0.082, 2.128, num=1024)[::-1]
data2 = np.sin(40 * np.log(x)) * np.sign((np.log(x)))

mode = pywt.MODES.sp1DWT = 1
mode = pywt.Modes.sp1DWT = 1


def plot_coeffs(data, w, title, use_dwt=True):
Expand Down
5 changes: 3 additions & 2 deletions demo/image_blender.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def load_image(path, mode=None, size=None):
return im


def blend_images(base, texture, wavelet, level, mode='sp1', base_gain=None,
def blend_images(base, texture, wavelet, level, mode='smooth', base_gain=None,
texture_gain=None):
"""Blend loaded images at `level` of granularity using `wavelet`"""

Expand Down Expand Up @@ -150,7 +150,8 @@ def main():
type="int", default=4,
help="decomposition level [default: %default]")
parser.add_option("-m", "--mode", dest="mode", metavar="MODE",
default='sym', help="decomposition mode. Adjust this if"
default='symmetric',
help="decomposition mode. Adjust this if"
" getting edge artifacts [default: %default]")
parser.add_option("-x", "--base_gain", dest="base_gain", metavar="BG",
type="float", default=None,
Expand Down
2 changes: 1 addition & 1 deletion demo/wp_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
arr = np.fromstring(im.tostring(), np.uint8)
arr.shape = (im.size[1], im.size[0])

wp2 = WaveletPacket2D(arr, 'db2', 'sym', maxlevel=2)
wp2 = WaveletPacket2D(arr, 'db2', 'symmetric', maxlevel=2)

# Show original figure
plt.imshow(arr, interpolation="nearest", cmap=plt.cm.gray)
Expand Down
2 changes: 1 addition & 1 deletion demo/wp_scalogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
cmap = plt.cm.cool

# Construct wavelet packet
wp = pywt.WaveletPacket(data, wavelet, 'sym', maxlevel=level)
wp = pywt.WaveletPacket(data, wavelet, 'symmetric', maxlevel=level)
nodes = wp.get_level(level, order=order)
labels = [n.path for n in nodes]
values = np.array([n.data for n in nodes], 'd')
Expand Down
12 changes: 6 additions & 6 deletions doc/source/ref/2d-dwt-and-idwt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Single level ``dwt2``
~~~~~~~~~~~~~~~~~~~~~

.. function:: dwt2(data, wavelet[, mode='sym'])
.. function:: dwt2(data, wavelet[, mode='symmetric'])

The :func:`dwt2` function performs single level 2D Discrete Wavelet Transform.

Expand All @@ -20,7 +20,7 @@ Single level ``dwt2``
:param wavelet: |wavelet|

:param mode: |mode| This is only important when DWT was performed
in :ref:`periodization <MODES.per>` mode.
in :ref:`periodization <Modes.periodization>` mode.

.. compound::

Expand Down Expand Up @@ -71,7 +71,7 @@ access to particular type of the output coefficients.
Single level ``idwt2``
~~~~~~~~~~~~~~~~~~~~~~

.. function:: idwt2(coeffs, wavelet[, mode='sym'])
.. function:: idwt2(coeffs, wavelet[, mode='symmetric'])

The :func:`idwt2` function reconstructs data from the given coefficients
set by performing single level 2D Inverse Discrete Wavelet Transform.
Expand All @@ -84,7 +84,7 @@ Single level ``idwt2``
:param wavelet: |wavelet|

:param mode: |mode| This is only important when the :func:`dwt` was performed
in the :ref:`periodization <MODES.per>` mode.
in the :ref:`periodization <Modes.periodization>` mode.

**Example:**

Expand All @@ -101,7 +101,7 @@ Single level ``idwt2``
2D multilevel decomposition using ``wavedec2``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. function:: wavedec2(data, wavelet[, mode='sym'[, level=None]])
.. function:: wavedec2(data, wavelet[, mode='symmetric'[, level=None]])

.. compound::

Expand Down Expand Up @@ -139,7 +139,7 @@ Single level ``idwt2``
2D multilevel reconstruction using ``waverec2``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. function:: waverec2(coeffs, wavelet[, mode='sym'])
.. function:: waverec2(coeffs, wavelet[, mode='symmetric'])

Performs multilevel reconstruction from the given coefficients set.

Expand Down
16 changes: 8 additions & 8 deletions doc/source/ref/dwt-discrete-wavelet-transform.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ functions used to perform single- and multilevel Discrete Wavelet Transforms.
Single level ``dwt``
--------------------

.. function:: dwt(data, wavelet[, mode='sym'])
.. function:: dwt(data, wavelet[, mode='symmetric'])

The :func:`dwt` function is used to perform single level, one dimensional
Discrete Wavelet Transform.

::

(cA, cD) = dwt(data, wavelet, mode='sym')
(cA, cD) = dwt(data, wavelet, mode='symmetric')

:param data: |data|

Expand All @@ -37,11 +37,11 @@ Single level ``dwt``
available options and the :func:`dwt_coeff_len` function for information on
getting the expected result length:

* for all :ref:`modes <ref-modes>` except :ref:`periodization <MODES.per>`::
* for all :ref:`modes <ref-modes>` except :ref:`periodization <Modes.periodization>`::

len(cA) == len(cD) == floor((len(data) + wavelet.dec_len - 1) / 2)

* for :ref:`periodization <MODES.per>` mode (``"per"``)::
* for :ref:`periodization <Modes.periodization>` mode (``"periodization"``)::

len(cA) == len(cD) == ceil(len(data) / 2)

Expand All @@ -60,7 +60,7 @@ Single level ``dwt``
Multilevel decomposition using ``wavedec``
------------------------------------------

.. function:: wavedec(data, wavelet, mode='sym', level=None)
.. function:: wavedec(data, wavelet, mode='symmetric', level=None)

.. compound::

Expand Down Expand Up @@ -105,7 +105,7 @@ Multilevel decomposition using ``wavedec``
Partial Discrete Wavelet Transform data decomposition ``downcoef``
------------------------------------------------------------------

.. function:: downcoef(part, data, wavelet[, mode='sym'[, level=1]])
.. function:: downcoef(part, data, wavelet[, mode='symmetric'[, level=1]])

Similar to :func:`~pywt.dwt`, but computes only one set of coefficients.
Useful when you need only approximation or only details at the given level.
Expand Down Expand Up @@ -162,11 +162,11 @@ Result coefficients length - ``dwt_coeff_len``
.. function:: dwt_coeff_len(data_len, filter_len, mode)

Based on the given *input data length*, Wavelet *decomposition filter length*
and :ref:`signal extension mode <MODES>`, the :func:`dwt_coeff_len` function
and :ref:`signal extension mode <Modes>`, the :func:`dwt_coeff_len` function
calculates length of resulting coefficients arrays that would be created while
performing :func:`dwt` transform.

For :ref:`periodization <MODES.per>` mode this equals::
For :ref:`periodization <Modes.periodization>` mode this equals::

ceil(data_len / 2)

Expand Down
18 changes: 9 additions & 9 deletions doc/source/ref/idwt-inverse-discrete-wavelet-transform.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Inverse Discrete Wavelet Transform (IDWT)
Single level ``idwt``
---------------------

.. function:: idwt(cA, cD, wavelet[, mode='sym'[, correct_size=0]])
.. function:: idwt(cA, cD, wavelet[, mode='symmetric'[, correct_size=0]])

The :func:`idwt` function reconstructs data from the given coefficients by
performing single level Inverse Discrete Wavelet Transform.
Expand All @@ -23,7 +23,7 @@ Single level ``idwt``
:param wavelet: |wavelet|

:param mode: |mode| This is only important when DWT was performed in
:ref:`periodization <MODES.per>` mode.
:ref:`periodization <Modes.periodization>` mode.

:param correct_size: Typically, *cA* and *cD* coefficients lists must have
equal lengths in order to perform IDWT. Setting
Expand All @@ -40,8 +40,8 @@ Single level ``idwt``
.. sourcecode:: python

>>> import pywt
>>> (cA, cD) = pywt.dwt([1,2,3,4,5,6], 'db2', 'sp1')
>>> print pywt.idwt(cA, cD, 'db2', 'sp1')
>>> (cA, cD) = pywt.dwt([1,2,3,4,5,6], 'db2', 'smooth')
>>> print pywt.idwt(cA, cD, 'db2', 'smooth')
[ 1. 2. 3. 4. 5. 6.]

One of the neat features of :func:`idwt` is that one of the *cA* and *cD*
Expand All @@ -54,9 +54,9 @@ Single level ``idwt``
.. sourcecode:: python

>>> import pywt
>>> (cA, cD) = pywt.dwt([1,2,3,4,5,6], 'db2', 'sp1')
>>> A = pywt.idwt(cA, None, 'db2', 'sp1')
>>> D = pywt.idwt(None, cD, 'db2', 'sp1')
>>> (cA, cD) = pywt.dwt([1,2,3,4,5,6], 'db2', 'smooth')
>>> A = pywt.idwt(cA, None, 'db2', 'smooth')
>>> D = pywt.idwt(None, cD, 'db2', 'smooth')
>>> print A + D
[ 1. 2. 3. 4. 5. 6.]

Expand All @@ -65,7 +65,7 @@ Single level ``idwt``
Multilevel reconstruction using ``waverec``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. function:: waverec(coeffs, wavelet[, mode='sym'])
.. function:: waverec(coeffs, wavelet[, mode='symmetric'])

Performs multilevel reconstruction of signal from the given list of
coefficients.
Expand Down Expand Up @@ -117,7 +117,7 @@ Direct reconstruction with ``upcoef``

>>> import pywt
>>> data = [1,2,3,4,5,6]
>>> (cA, cD) = pywt.dwt(data, 'db2', 'sp1')
>>> (cA, cD) = pywt.dwt(data, 'db2', 'smooth')
>>> print pywt.upcoef('a', cA, 'db2') + pywt.upcoef('d', cD, 'db2')
[-0.25 -0.4330127 1. 2. 3. 4. 5.
6. 1.78589838 -1.03108891]
Expand Down
36 changes: 15 additions & 21 deletions doc/source/ref/other-functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Other functions
Single-level n-dimensional Discrete Wavelet Transform.
------------------------------------------------------

.. function:: dwtn(data, wavelet[, mode='sym'])
.. function:: dwtn(data, wavelet[, mode='symmetric'])

Performs single-level n-dimensional Discrete Wavelet Transform.

Expand All @@ -33,48 +33,42 @@ Single-level n-dimensional Discrete Wavelet Transform.
}


Integrating wavelet functions - :func:`intwave`
Integrating wavelet functions - :func:`integrate_wavelet`
-----------------------------------------------

.. function:: intwave(wavelet[, precision=8])
.. function:: integrate_wavelet(wavelet[, precision=8])

Integration of wavelet function approximations as well as any other signals
can be performed using the :func:`pywt.intwave` function.
Integration of wavelet function approximations can be performed
using the :func:`pywt.integrate_wavelet` function.

The result of the call depends on the *wavelet* argument:

* for orthogonal wavelets - an integral of the wavelet function specified
on an x-grid::
* for orthogonal and continuous wavelets - an integral of the
wavelet function specified on an x-grid::

[int_psi, x] = intwave(wavelet, precision)
[int_psi, x_grid] = integrate_wavelet(wavelet, precision)

* for other wavelets - integrals of decomposition and reconstruction
wavelet functions and a corresponding x-grid::

[int_psi_d, int_psi_r, x] = intwave(wavelet, precision)

* for a tuple of coefficients data and a x-grid - an integral of function
and the given x-grid is returned (the x-grid is used for computations).::

[int_function, x] = intwave((data, x), precision)
* for other wavelets - integrals of decomposition and
reconstruction wavelet functions and a corresponding x-grid::

[int_psi_d, int_psi_r, x_grid] = integrate_wavelet(wavelet, precision)

**Example:**

.. sourcecode:: python

>>> import pywt
>>> wavelet1 = pywt.Wavelet('db2')
>>> [int_psi, x] = pywt.intwave(wavelet1, precision=5)
>>> [int_psi, x] = pywt.integrate_wavelet(wavelet1, precision=5)
>>> wavelet2 = pywt.Wavelet('bior1.3')
>>> [int_psi_d, int_psi_r, x] = pywt.intwave(wavelet2, precision=5)
>>> [int_psi_d, int_psi_r, x] = pywt.integrate_wavelet(wavelet2, precision=5)


Central frequency of *psi* wavelet function
-------------------------------------------

.. function:: centfrq(wavelet[, precision=8])
centfrq((function_approx, x))
.. function:: central_frequency(wavelet[, precision=8])
central_frequency((function_approx, x))

:param wavelet: :class:`Wavelet`, wavelet name string or
`(wavelet function approx., x grid)` pair
Expand Down

0 comments on commit f443dbd

Please sign in to comment.