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: Implement mode parameter for spline filtering. #8537

Merged
merged 2 commits into from
Nov 1, 2018

Conversation

jaimefrio
Copy link
Member

This moves us forward along the lines discussed in #8465. None of the interpolation functions can yet use an image filtered with any mode other than 'mirror', but I think it's better to get this in first. If the interpolation functions have not been changed by the next release, we may want to change the docstring to not mislead users.

This PR implements proper spline coefficient calculations for the 'mirror', 'wrap' and 'reflect' modes, based on information obtained from Dr. Philippe Thévenaz. For 'nearest' and 'constant' methods this PR silently switches them to 'mirror': the current implementation of the interpolation functions does a sufficiently good job for those methods, and they have some specific issues, so they didn't seem worth the trouble right now.

@jaimefrio jaimefrio changed the title ENH: Implement mode paramater for spline filtering. ENH: Implement mode parameter for spline filtering. Mar 9, 2018
@charris charris added enhancement A new feature or improvement scipy.ndimage labels Mar 9, 2018
@@ -62,12 +63,24 @@ def spline_filter1d(input, order=3, axis=-1, output=numpy.float64):
output : ndarray or dtype, optional
The array in which to place the output, or the dtype of the returned
array. Default is `numpy.float64`.
%(mode)s
Copy link
Member

Choose a reason for hiding this comment

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

How does this work?

Copy link
Member Author

Choose a reason for hiding this comment

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

The actual text is in ni_docstrings.py, and this gets magically filled in by the @_ni_docstrings.docfiller decorator.

@charris
Copy link
Member

charris commented Mar 9, 2018

I wonder if it wouldn't help to change some of the functions to accept keywords?

@jaimefrio
Copy link
Member Author

Sorry for taking so long, but I struggled a bit with getting the test in test_datatypes.py to work unchanged. I think I took care of all your suggestions, PTAL.

@ilayn
Copy link
Member

ilayn commented Apr 19, 2018

@charris Could you please take another look?

@rgommers rgommers added this to the 1.2.0 milestone Jun 10, 2018
@rgommers
Copy link
Member

This looks great. Not going to dive into the details, since it would take way too long to catch up with @jaimefrio and @charris here.

Would be useful to have an entry in the release notes, seems an important enough improvement. @jaimefrio could you add a few words at https://github.com/scipy/scipy/wiki/Release-note-entries-for-SciPy-1.2.0 ?

@charris
Copy link
Member

charris commented Jun 10, 2018

I'll take another look. IIRC, the code looked OK, my comments were directed at the docstrings.

OK, added another docstring comment :)

It is a surprisingly long time ago that I looked at this. @jaimefrio IIRC, there are some good tests for this, don't recall if they have been merged. I'm trying to avoid the work of digging through the files to check this in detail, in particular, I'd need to track down the source of the asymmetry between the causal and anti-causal initialization, for which I can think of several good, implementation dependent, reasons.

@rgommers
Copy link
Member

@jaimefrio @charris okay to resolve the merge conflict and merge this before the 1.2.x split? seems good to go. I can address the last doc comment if needed

@jaimefrio
Copy link
Member Author

jaimefrio commented Oct 29, 2018 via email

@charris
Copy link
Member

charris commented Oct 30, 2018

Hmm, for some reason I thought this had already gone in. I'll take another look, but I think it looked good to me before. If the tests are decent we should be able to rely on them.

 - Some comment editing.
 - Have a first loop over the coefficients applying the filter gain, rather
   than doing it during the anticausal filtering, as it is better behaved
   numerically.
 - Rearranged arguments of _nd_image.spline_filter1d to have the new `mode`
   arg at the end.
@rgommers
Copy link
Member

rgommers commented Nov 1, 2018

Test coverage for changed functions looks good, and I pushed yet another rebase (all green except for Appveyor lag; previous run with same content was all green). Let's get this in. @charris if you want to give it another sanity check please do!

Thanks @jaimefrio and @charris!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature or improvement scipy.ndimage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants