<br><br><div class="gmail_quote">On Mon, Jun 29, 2009 at 6:10 PM, Charles R Harris <span dir="ltr"><<a href="mailto:charlesr.harris@gmail.com">charlesr.harris@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br><br><div class="gmail_quote"><div><div></div><div class="h5">On Mon, Jun 29, 2009 at 4:17 PM, Russell E. Owen <span dir="ltr"><<a href="mailto:rowen@u.washington.edu" target="_blank">rowen@u.washington.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
In article<br>
<<a href="mailto:e06186140906291429m3cb339e8ge298f179d811e8a7@mail.gmail.com" target="_blank">e06186140906291429m3cb339e8ge298f179d811e8a7@mail.gmail.com</a>>,<br>
<div><div></div><div> Charles R Harris <<a href="mailto:charlesr.harris@gmail.com" target="_blank">charlesr.harris@gmail.com</a>> wrote:<br>
<br>
> On Mon, Jun 29, 2009 at 3:03 PM, Russell E. Owen<br>
> <<a href="mailto:rowen@u.washington.edu" target="_blank">rowen@u.washington.edu</a>>wrote:<br>
><br>
> > I have an old Numarray C extension (or, rather, a Python package<br>
> > containing a C extension) that I would like to convert to numpy<br>
> > (in a way that is likely to be supported long-term).<br>
> ><br>
> > Options I have found include:<br>
> ><br>
> > - Use the new numpy extension. This seems likely to be fast and<br>
> > future-proof. But I am finding the documentation slow going. Does anyone<br>
> > know of a simple example (e.g. read in an array, create a new array)?<br>
> ><br>
> > - Use the Numarray compatible C API. Simple (and takes advantage of the<br>
> > nice Numarray tutorial example for documentation), but will this be<br>
> > supported in the long term?<br>
> ><br>
> > - Switch to ctypes. Simple in concept. But I'm wondering if I can get<br>
> > distutils to build the resulting package.<br>
> ><br>
> > - Use SWIG. I have some experience with it, but not with numpy arrays.<br>
> ><br>
> > - Use Cython to replace the C code. No idea if this is a long-term<br>
> > supported package.<br>
> ><br>
> > Another option is to try to rewrite in pure python. Perhaps the numpy<br>
> > indexing is sophisticated enough to allow an efficient solution. The C<br>
> > extension computes a radial profile from a 2-d masked array:<br>
> >  radProf(r)= sum of all unmasked pixels at radius r about some<br>
> > specified center index<br>
> > I can easily generate (and cache) a 2-d array of radius index, but is it<br>
> > possible to use that to efficiently generate the desired sum?<br>
> ><br>
> > Any opinions?<br>
> ><br>
><br>
> How big is the extension and what does it do?<br>
<br>
</div></div>It basically contains 2 functions:<br>
1: radProfile: given a masked image (2d array), a radius and a desired<br>
center: compute a new 1d array whose value at index r is the sum of all<br>
unmasked pixels at radius r.<br>
<br>
2: radAsymm: given the same inputs as radProfile, return a (scalar)<br>
measure of radial asymmetry by computing the variance of unmasked pixels<br>
at each radius and combining the results.<br>
<br>
The original source file is about 1000 lines long, of which 1/3 to 1/2<br>
is the basic C code and the rest is Python wrapper.<br>
<div><div></div><div></div></div></blockquote></div></div><div><br>It sounds small enough that you should be able to update it to the numpy interface. What functions do you need? You should also be able to attach a copy (zipped) if it is small enough, which might help us help you.<br>

</div></div></blockquote><div><br>And yes, you could probably do it in cython and save yourself a bit of interface code. I think cython will currently handle 2d arrays without much trouble. But I don't know what the fastest approach would be here.<br>
<br>Chuck <br></div><br></div>