astropy/astropy — pull request #155 by astrofrog (2012-02-08 23:00:17+00:00)
Title: NaN-friendly convolution

This pull request implements convolution functions for multi-dimensional arrays, with proper support for NaN values (which scipy's ``convolve`` does not have, but which is needed for Astronomical images).

The current code has the following limitations:

* Only 2D convolution is supported at this time

* No documentation has been added

* The tests are not yet exhaustive

I want to address all these points before we consider merging in the code. However, I wanted to open the pull request to get feedback on the existing code, before extending the code to 1D and 3D+, and writing more tests, since these will involve significantly more code.

The only function intended for users is:

from astropy.nddata.convolve import convolve

This calls the different Cython functions depending on dimensionality and boundary treatment. The reason for implementing the four different Cython functions is that it is significantly faster than constantly checking the boundary option inside a single Cython function.

The ``convolve`` function's docstring should explain all the options.

I decided to include this in ``astropy.nddata`` to mirror ``scipy.ndimage`` (rather than putting it in ``astropy.tools``. I think that is the right thing to do. I think that ``convolve`` should be callable directly as above, but of course we can also add a ``convolve`` method for ``NDData`` objects that then relies on ``nddata.convolve``.

The treatment of the edges and NaN values is inspired by IDL's CONVOL function (e.g. http://star.pst.qub.ac.uk/idl/CONVOL.html).

Performance-wise, the speed is very similar to scipy's ``convolve`` when ``boundary=None``, and slightly worse for other boundary options, but that is the price to pay for dealing with the NaN values correctly.

Let me know what you think!