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
DOC: better document how to handle omitted coefficients in multilevel DWT reconstructions #303
Conversation
…fficients are None. Coefficients as None is allowed by idwtn, but for the multilevel waverecn, the shape of the detail coefficients arrays are used to make sure the final shape is correct. This information is lost if the detail coefficients are None. The error message in _fix_coeffs is updated to suggest to the user, the appropriate workaround of using an array of zeros instead.
omitting specific coefficients from the reconstruction
Codecov Report
@@ Coverage Diff @@
## master #303 +/- ##
==========================================
- Coverage 86.22% 86.22% -0.01%
==========================================
Files 21 21
Lines 3092 3099 +7
Branches 535 562 +27
==========================================
+ Hits 2666 2672 +6
- Misses 373 374 +1
Partials 53 53
Continue to review full report at Codecov.
|
@PyWavelets/core can someone take a quick look at this PR as well as #309? They should both be quick to review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've commented on a few minor doc things; my main comment is about the example. I tried to follow the wavedecn one given:
coeffs = pywt.wavedecn(np.ones((4, 4, 4)), 'db1') # from Examples section
coeffs[-2]= {k: numpy.zeros_like(v) for k, v in coeffs[-2].items()}
the output doesn't look quite right
pywt/_multilevel.py
Outdated
@@ -122,6 +122,17 @@ def waverec(coeffs, wavelet, mode='symmetric', axis=-1): | |||
Axis over which to compute the inverse DWT. If not given, the | |||
last axis is used. | |||
|
|||
Notes | |||
----- | |||
It may sometimes desired to run ``waverec`` with some sets of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"sometimes be desired"
pywt/_multilevel.py
Outdated
@@ -251,6 +262,17 @@ def waverec2(coeffs, wavelet, mode='symmetric', axes=(-2, -1)): | |||
------- | |||
2D array of reconstructed data. | |||
|
|||
Notes | |||
----- | |||
It may sometimes desired to run ``waverec2`` with some sets of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"sometimes be desired"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and same for waverecn
pywt/_multilevel.py
Outdated
|
||
Specifically, to ignore all detail coefficients at level 2, one could do:: | ||
|
||
codffs[-2] = {k: numpy.zeros_like(v) for k, v in coeffs[-2].items()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: codffs
--> coeffs
pywt/_multilevel.py
Outdated
|
||
Specifically, to ignore detail coefficients at level 2, one could do:: | ||
|
||
coeffs[-2] == numpy.zeros_like(coeffs[-2]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
numpy
--> np
(in all 3 docstrings)
Well, for that example with np.ones as the input, all detail coefficients are already zero, so setting to zero has no effect. You should still get an array of all ones after The output of the example below looks as I would expect for discarding some detail coefficients: import pywt
import numpy as np
import matplotlib.pyplot as plt
img = pywt.data.camera()
coeffs = pywt.wavedecn(img, 'db1')
coeffs[-2]= {k: np.zeros_like(v) for k, v in coeffs[-2].items()}
imgr = pywt.waverecn(coeffs, 'db1')
fig, axes = plt.subplots(1, 2)
axes[0].imshow(img)
axes[1].imshow(imgr) |
Thanks, that example looks more useful (and correct). Guess we should get around to fixing up the trivial examples with some like the one you provide here at some point. |
Related to the discussion in #302, this PR is intended to clarify issues of running
waverecn
(as well aswaverec
andwaverec2
) with some coefficients omitted. The only truly safe way to do this currently seems to be to replace the undesired coefficient arrays with corresponding arrays of zeros. In general,None
cannot be allowed (as it is for the single-levelidwtn
), as the shapes of the arrays are needed at various places to ensure any extra padding was removed properly:pywt/pywt/_multilevel.py
Lines 148 to 149 in dd7b793
pywt/pywt/_multilevel.py
Lines 296 to 297 in dd7b793
pywt/pywt/_multilevel.py
Line 514 in dd7b793
Here the error message on
None
coefficients is updated to suggest the appropriate workaround and some text is added to the Notes section of the function docstrings.