[AstroPy] POLL: vision for a common Astronomy package

Prasanth oneaufs at gmail.com
Wed Jul 6 07:02:08 EDT 2011


The particular instance of SOFA, though, is perhaps an example of the
> problem we facing in wrapping existing libraries.  IMHO, they are
> usually quite un-pythonic in both implementation and interface, and
> wrappings typically follow similar forms (e.g. pysofa follows the sofa
> interface very closely). If the goal here is a python library and
> framework, we want to leverage the advantages of the language itself
> in terms of style and programming idioms.  And especially given the
> compilation/packaging issues noted by Mark, Ole, and many others, it
> has to be worth the trouble to write wrappers that end up with such in
> interface... SWIG is great at making direct wrappings, but I haven't
> really seen it go beyond that.  More recent schemes like ctypes or
> Cython seem to be easier to compile and are easier to make more
> pythonic, but at some point it becomes more efficient to just
> implement the algorithm using numpy (possibly with the help of a small
> C extension if speed is a problem).
In my experience, the pythonic part of the implementation essentially comes
down to having proper Python objects that map the data structures used by
the C library. It is quite easy to come up with such objects in Cython.  I
switched to Cython after finding this easier than SWIG.

Need for other objects will depend on the application that uses the library.
For example, an application may need a Position object, where as this may
not be necessary for just wrapping the library. The Position object methods
can call wrapped functions, for example to convert angle to HMS format or
calculate separation between two points.

I have an example<https://github.com/phn/pytpm/blob/master/examples/conversion_example.py>
using objects, that wrap C structures, from the PyTPM library, which is an
interface to the TPM library. The equivalent C code is at this
This is just a wrapper to the library and not a full astrometry application,
and hence don't have objects that are not needed for calling C functions.

This is also pretty fast. I use this
read in the Hipparcos data set into IPython (the data i/o takes a while
since I am doing simple list.append operations), and then  ran the %timeit
magic command, to perform FK5 J2000 to Galactic conversion. This was done on
a laptop running Ubuntu 11.04 and IPython .10 with Python 2.6.

>>> %timeit convert.convert(ra=raj2000, dec=dej2000,s2=tpm.TPM_S04)
1 loops, best of 3: 4.86 s per loop
>>> %timeit convert.convert(ra=raj2000, dec=dej2000,s2=tpm.TPM_S04)
1 loops, best of 3: 4.97 s per loop
>>> %timeit convert.convert(ra=raj2000, dec=dej2000,s2=tpm.TPM_S04)
1 loops, best of 3: 5.21 s per loop
>>> %timeit convert.convert(ra=raj2000, dec=dej2000,s2=tpm.TPM_S04)
1 loops, best of 3: 4.95 s per loop
>>> %timeit convert.convert(ra=raj2000, dec=dej2000,s2=tpm.TPM_S04)
1 loops, best of 3: 5.1 s per loop

The PyTPM library does not use Numpy, but since it simply iterates over
input values passing Numpy 1D arrays will cause no problem. I do this in the
unofficial /unsanctioned fork of the astrolib.coords package, which includes
PyTPM, available here <https://github.com/phn/coords>. The code there is
fast as well. This package would be an example of an astrometry application,
something that can be added to astropy, and hence needs to have objects
etc., that make it easier to use. As of now it just has some functions.


On Tue, Jul 5, 2011 at 11:19 PM, Prasanth <oneaufs at gmail.com> wrote:
> > Hello,
> >
> >>
> >> Are you proposing that I must agree to the SOFA terms
> >> of use (which are more restrictive than GPL or BSD licensing) before I
> >> can use Astropy?
> >
> >
> > I think that the SOFA license and terms of use are much more liberal than
> > GPL. The only requirement is that the developer retains the copyright
> > notice, and none of the derived components carry the prefix "iau". It can
> be
> > used for commercial purposes. Also, I couldn't find anything in the SOFA
> > license that prevents a developer from even making a closed source
> > application.
> > Prasanth
> > _______________________________________________
> > AstroPy mailing list
> > AstroPy at scipy.org
> > http://mail.scipy.org/mailman/listinfo/astropy
> >
> >
> --
> Erik Tollerud
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20110706/707b5881/attachment.html>

More information about the AstroPy mailing list