[AstroPy] How can I create a VOtable from a python list?

Thomas Robitaille thomas.robitaille at gmail.com
Wed Mar 6 10:57:10 EST 2013


Hi Jean-Baptiste,

Astropy actually already supports the same kind of file access to VO
tables that ATpy does - if you have an Astropy Table object, you can
do:

t = Table(...)
t.write('my_table.xml', format='votable')

to read a VO table:

t = Table.read('my_table.xml')

(format should be auto-detected)

We've been working on merging the ATpy functionality bit by bit (in
fact astropy.table started from the base Table class in ATpy). Astropy
can now be used as a full replacement to ATpy for VO tables, HDF5
tables, and ASCII tables. We will add support for FITS files, which
leaves only the SQL as being ATpy-specific (whether this gets merged
in future into Astropy remains to be decided).

Cheers,
Tom


On 6 March 2013 15:28, Jean-Baptiste Marquette <marquett at iap.fr> wrote:
> Hi all,
>
> May I suggest to have a look at ATpy, where VOTable are natively recognized:
> http://atpy.github.com/ ?
>
> BTW, I would be very grateful if both AstroPy and ATpy could merge…
>
> Cheers,
> Jean-Baptiste
>
> Le 6 mars 2013 à 15:08, Michael Droettboom a écrit :
>
> The general approach you're taking here -- to create a Table and then
> convert it to a VOTable -- is the right one here.  The Table class has a
> much richer set of things it can convert to and from (it's sort of our
> "hub" class for everything that's table like).
>
> However, I don't believe it supports construction from a list in the way
> you're trying.  There is a doc page about constructing a table here,
> that may be helpful:
>
> https://astropy.readthedocs.org/en/v0.2/table/construct_table.html
>
> That said, I tried to convert your example to the form where the Table
> is constructed from a Numpy structured array, and still ran into the
> same exception:
>
> from astropy import table
>
> from astropy.io import votable
>
> import numpy as np
>
> x = np.array(
>
>     [("CIG12",1.2345,0,2,999,"COMMENT"),
>
>      ("CIG122",1.23452,0,2,9992,"COMMENT2")],
>
>     dtype=[('a', str), ('b', float), ('c', int), ('d', int), ('e', int),
> ('f', str)])
>
> print x.dtype
>
> t = table.Table(x)
>
> votable = votable.tree.VOTableFile.from_table(t)
>
>
> So maybe we're both still doing something wrong.  I've Cc'd Tom
> Aldcroft, the primary author of the Table class, as he might have more
> insight.
>
> Mike
>
>
> On 03/04/2013 06:43 AM, Susana Sanchez wrote:
>
> Hello all,
>
>
> How can I create a VOtable from a list (a python list) of rows using
> astropy?
>
>
> Reading the documentation, I found the method "from_table" of the
>
> class VOTableFile, this method needs as argument an instance of the
>
> class astropy.table.table.Table, so I did the following:
>
>
> t=astropy.table.table.Table([["CIG12",1.2345,0,2,999,"COMMENT"],["CIG122",1.23452,0,2,9992,"COMMENT2"]])
>
> votable = VOTableFile()
>
> votable.from_table(t)
>
>
>
> But here I got this error:
>
>
> /usr/local/lib/python2.6/dist-packages/numpy/ma/core.pyc in
>
> __new__(cls, data, mask, dtype, copy, subok, ndmin, fill_value,
>
> keep_mask, hard_mask, shrink, **options)
>
>    2692             # Or assume it's a sequence of bool/int
>
>
>    2693             except TypeError:
>
> -> 2694                 mask = np.array([tuple([m] * len(mdtype)) for
>
> m in mask],
>
>    2695                                  dtype=mdtype)
>
>    2696             # Make sure the mask and the data have the same shape
>
>
> TypeError: 'NoneType' object is not iterable
>
>
>
> Reading the error message,  I thought it could be related with the
>
> mask, so I tried to create the mask of the table t (with the method
>
> t.create_mask()), and then to build the VOTableFile from this table,
>
> but I got the same error.
>
>
> I would be very gratefully, If anyone can help me or give me any hint.
>
>
> Thanks,
>
> Susana.
>
> _______________________________________________
>
> AstroPy mailing list
>
> AstroPy at scipy.org
>
> http://mail.scipy.org/mailman/listinfo/astropy
>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy
>
>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy
>



More information about the AstroPy mailing list