astropy/photutils — pull request #4 by astrofrog (2012-05-28 17:58:45+00:00)
Title: Exact elliptical aperture photometry

Here's the implementation of the exact elliptical aperture photometry. This was a bit more painful to write, but I believe it's all correct. I'm going to run some intensive calculations comparing the results to monte-carlo calculations (I've already done this, but will run and document more extensive tests). For info:

In [1]: import numpy as np

In [2]: import photutils

In [3]: data = np.ones((100, 100))

In [4]: xc = [10., 20., 30., 40.]

In [5]: yc = [10., 20., 30., 40.]

In [6]: photutils.aperture_elliptical(data, xc, yc, 3., 5., 1., subpixels=5)
Out[6]: array([ 47.16, 47.16, 47.16, 47.16])

In [7]: photutils.aperture_elliptical(data, xc, yc, 3., 5., 1., subpixels=10)
Out[7]: array([ 47.12, 47.12, 47.12, 47.12])

In [8]: photutils.aperture_elliptical(data, xc, yc, 3., 5., 1., subpixels=20)
Out[8]: array([ 47.145, 47.145, 47.145, 47.145])

In [9]: photutils.aperture_elliptical(data, xc, yc, 3., 5., 1., subpixels='exact')
Out[9]: array([ 47.1238898, 47.1238898, 47.1238898, 47.1238898])

In [10]: print np.pi * 3. * 5.
47.1238898038

In [11]: %timeit photutils.aperture_elliptical(data, xc, yc, 3., 5., 1., subpixels=5)
100 loops, best of 3: 2.26 ms per loop

In [12]: %timeit photutils.aperture_elliptical(data, xc, yc, 3., 5., 1., subpixels=10)
100 loops, best of 3: 4.43 ms per loop

In [13]: %timeit photutils.aperture_elliptical(data, xc, yc, 3., 5., 1., subpixels=20)
100 loops, best of 3: 18.9 ms per loop

In [14]: %timeit photutils.aperture_elliptical(data, xc, yc, 3., 5., 1., subpixels='exact')
100 loops, best of 3: 4.18 ms per loop

However, before we merge this in, I want to check something, as it wasn't clear to me:

* Your elliptical photometry code appears to assume that the position angle of the ellipse goes clockwise. My Cython code assumes anti-clockwise as I thought that was the convention, so when I realized you were doing it differently, I added a ``-`` in the call to the Cython code. However, do we want to instead switch to using anti-clockwise position angles?

* We also assumed different things for ``a`` and ``b``. I assumed it was the diameters, and you assumed the radii. Which do we want to go with?

* I had switched the circular photometry to be exact by default since the overhead was not big compared to ``subpixels=5``. Do we want to do the same here? (although ``exact`` is twice as slow as ``subpixels=5``). We could always have ``exact`` be the default when possible, and put a note that people who care about performance can try ``subpixels``? (i.e. I think it's better for the code to be twice as slow but 100% accurate by default)

I'm going to work on accuracy tests for the photometry and will add them to this PR. In the mean time, let me know what you think about the above points.