Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: add wavedecn and waverecn functions #67

Merged
merged 29 commits into from
Dec 17, 2015

Conversation

grlee77
Copy link
Contributor

@grlee77 grlee77 commented Jul 24, 2015

adds n-dimensional variants of wavedec2 and waverec2.
This was split off from the now closed #52

@grlee77 grlee77 added this to the v0.4.0 milestone Jul 24, 2015
Signal extension mode, see MODES (default: 'sym')
level : int, optional
Decomposition level. If level is None (default) then it will be
calculated using the ``dwt_max_level`` function.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to document here that level needs to be >=0

@kwohlfahrt
Copy link
Member

Looks good at a quick glance. This is one way of working around #54. Personally, I think idwtn should be strict in what input shapes it accepts, and not silently truncate it's input, but for a multilevel transform this is the correct thing to do. Should we then close #54, or still change the behaviour of idwtn?

@kwohlfahrt kwohlfahrt modified the milestones: v0.3.0, v0.4.0 Jul 24, 2015
@grlee77
Copy link
Contributor Author

grlee77 commented Jul 24, 2015

If you want to add documentation on why the behaviour in #54 is expected and mention this as a workaround, I would be okay with that. I don't really know which behaviour is preferable for idwtn,

@grlee77
Copy link
Contributor Author

grlee77 commented Aug 14, 2015

This was rebased using current master. A major overhaul of the tests was done in the last commit to make them more comprehensive and consistent across all dimensions.

@grlee77
Copy link
Contributor Author

grlee77 commented Aug 14, 2015

@kwohlfahrt can you check if the updated implementation of waverecn here looks reasonable to you. I added a utility function called _match_coeff_dims to get things to work now that take is no longer an argument of idwtn.

@kwohlfahrt
Copy link
Member

@grlee77 sorry, I completely missed that I'd been tagged here. The idea looks clean, however in idwtn we allow (and silently ignore) the dictionary to contain keys which are not just combinations of 'a' and 'd', and values which are None. _match_coeff_dims does not handle this at the moment.

There are a few edge cases (e.g. one level being {}) that are not handled as well. I'll write tests and fixes for as many as I can catch and open a PR on your repo. Sorry again for taking so long to respond.

@grlee77
Copy link
Contributor Author

grlee77 commented Oct 26, 2015

I merged @kwolfahrt's code to handle missing or invalid coefficients, but please do not merge just yet. I still want to add a warning in the case of missing coefficients or unexpected extra keys in the detail coefficient dictionary and an exception if any coefficients have the wrong shape.

@grlee77
Copy link
Contributor Author

grlee77 commented Oct 26, 2015

@kwohlfahrt
Please review the most recent commit. I added an enable_warnings argument to _fix_coeffs that raises warnings for the following two cases:

  1. any detail coefficient arrays are None
  2. any keys in the detail coefficient dictionary have invalid names

waverecn itself now raises a warning if any of the detail coefficient dictionaries are empty.

idwtn also uses fix_coeffs, but I did not enable the warnings there yet. Do you think we should do so? If so, perhaps enable_warnings should be False in the waverecn call to _fix_coeffs so we don't raise the same warnings twice (or the call to _fix_coeffs could be removed from waverecn since idwtn is going to call it again anyways).

@kwohlfahrt
Copy link
Member

Sorry for the delay, here are my thoughts:

  1. I think it's probably better to make this an exception, and say all values must be array_like
    • If we're worried about compatibility, a deprecation warning for a release cycle is probably OK. Though iirc we were breaking back-compat so no need to fuss. I'd catch the exception and raise the warning instead, just to get the code for the future written now.
  2. Maybe this too? I'm pretty on the fence about it.

I'm not sure it's necessary to warn if any detail coefficient dictionaries are empty. It's an extension of allowing any other number of coefficients to be missing, so it's not really unusual enough to cause a warning.

I would also enable the warnings/exceptions for idwtn. If it is used everywhere, I don't think the enable_warnings flag should exist, it should just be the behaviour of the function.

@grlee77
Copy link
Contributor Author

grlee77 commented Nov 20, 2015

@kwohlfahrt
see how this looks and let me know if there is a cleaner way to do this.

I removed the warning about empty coefficient dictionaries as suggested.

I now raise a DeprecationWarning if any dictionary entries are None or have an invalid key name. This will become a ValueError after the deprecation period.

@grlee77 grlee77 force-pushed the wavedecn_v2 branch 2 times, most recently from 252645f to a01939d Compare November 25, 2015 23:44
@kwohlfahrt
Copy link
Member

_fix_coeffs should also check if there are (valid) keys that are not the same length. A dictionary containing 'aa' and 'aaa' should be an error.

Given that we 'broke' idwtn already in #125, I don't think the deprecation warning is necessary any more, but up to you.

Otherwise looks good!

@grlee77
Copy link
Contributor Author

grlee77 commented Dec 15, 2015

@kwohlfahrt
any other comments here? If not, feel free to merge it

coeffs_list.append(a)
coeffs_list.reverse()

if len(coeffs_list) < level + 1:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the lines above, this test shouldn't ever fail (and it doesn't break any tests if removed).

grlee77 and others added 18 commits December 16, 2015 14:18
reorganize tests into a logical order and use uniform tolerances across all tests.

merge the separate *_complex tests into the dtype *_accuracies tests to avoid duplicating functionality

add comprehensive mode and wavelet type tests to the 1D and 2D cases to match those previously existing for nD

added dec.slow or PYWT_XSLOW decorators where needed.

In the future if dwt2/idwt2 are refactored to use dwtn/idwtn the PYWT_XSLOW decorator can be removed.
Correctly handle missing coefficients in waverecn, as they are treated in
idwtn.
Previously, empty levels were discarded, they should not be.
…efficients.

Temporarily catch the Exception and raise a warning instead to allow for a deprecation period
…nd restore missing import in test_multidim.py
… are fewer than the number of array dimensions.
…s_modes now that the underlying code is much faster
@grlee77
Copy link
Contributor Author

grlee77 commented Dec 16, 2015

@kwohlfahrt: still waiting on Travis, but I addressed the issue above and added a couple new tests of the axes arguments to dwtn, idwtn.

"""

if not isinstance(coeffs, (list, tuple)):
raise ValueError("Expected sequence of coefficient arrays.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this check is necessary - other sequences should work fine.

@kwohlfahrt
Copy link
Member

Apart from the isinstance check, looks good to me. I don't think we should reject other types of sequence unless there's a particular reason for this.

@grlee77
Copy link
Contributor Author

grlee77 commented Dec 17, 2015

okay. should be good to go now

kwohlfahrt pushed a commit that referenced this pull request Dec 17, 2015
ENH: add wavedecn and waverecn functions
@kwohlfahrt kwohlfahrt merged commit 2a139a3 into PyWavelets:master Dec 17, 2015
@grlee77 grlee77 deleted the wavedecn_v2 branch December 29, 2015 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants