VO Tables#

Create a VO Table from an Astropy Table#

There are several ways of doing this, and there are a few object layers here, which can be confusing:

Although some things can be done with generic astropy Tables, other VO operations can only be done with VO Tables or VOTableFile objects.

This is easiest to see with an example.

import io, numpy

from astropy import table as aptable
from astropy.io import votable as apvot

Create a table with only two columns starting from an astropy Table#

myaptable=aptable.Table(
    numpy.array([
            [19.0186,       46.7304],
            [20.2887,       40.4703],
            [125.886,       21.3377],
            [136.002,       21.9679],
            [141.057,       40.6372],
            [146.700,       22.0116],
            [148.785,       14.2922],
            [149.751,       17.8168],
            [175.039,       15.3270],
            [191.542,       30.7317],
            [194.913,       28.8959],
            [199.026,       41.5011],
            [206.577,       43.8511],
            [209.963,       38.1821],
            [213.556,       15.6214],
            [219.967,       42.7421],
            [226.693,       12.8502],
            [237.489,       20.8057],
            [241.519,       20.8014],
            [317.088,       18.2002],
            [329.235,       6.64845],
            [333.830,       37.3012] ]),
    names=["RA","DEC"])

print(type(myaptable))
print(myaptable)
<class 'astropy.table.table.Table'>
   RA     DEC  
------- -------
19.0186 46.7304
20.2887 40.4703
125.886 21.3377
136.002 21.9679
141.057 40.6372
  146.7 22.0116
148.785 14.2922
149.751 17.8168
175.039  15.327
191.542 30.7317
194.913 28.8959
199.026 41.5011
206.577 43.8511
209.963 38.1821
213.556 15.6214
219.967 42.7421
226.693 12.8502
237.489 20.8057
241.519 20.8014
317.088 18.2002
329.235 6.64845
 333.83 37.3012

Then convert this to a VOTableFile object which contains a nested set of resources and tables (in this case, only one of each)#

myvotablefile = apvot.from_table(myaptable)
print(type(myvotablefile))

for r in myvotablefile.resources:
    mytable=r
    for t in r.tables:
        print(t)
<class 'astropy.io.votable.tree.VOTableFile'>
   RA     DEC  
------- -------
19.0186 46.7304
20.2887 40.4703
125.886 21.3377
136.002 21.9679
141.057 40.6372
  146.7 22.0116
148.785 14.2922
149.751 17.8168
175.039  15.327
191.542 30.7317
194.913 28.8959
199.026 41.5011
206.577 43.8511
209.963 38.1821
213.556 15.6214
219.967 42.7421
226.693 12.8502
237.489 20.8057
241.519 20.8014
317.088 18.2002
329.235 6.64845
 333.83 37.3012