[AstroPy] How to append to a astropy.io.votable

Tom Aldcroft aldcroft@head.cfa.harvard....
Tue Apr 16 17:15:25 CDT 2013


Hi JJ,

If you want to add a column you should first convert the VOtable into
an astropy Table object, e.g.:

  >>> from astropy.table import MaskedColumn
  >>> table = t.to_table()  # where t is the VOtable from your example
  >>> new_col = MaskedColumn(data=<computed values>, name='newColumn')
  >>> table.add_column(new_col)

The use of MaskedColumn assumes there might be missing (masked) values
in your <computed values>.  If not you can just use Column.

Note that in the upcoming 0.3 version of astropy (or the current dev
version), you can replace the last two lines with:

  >>> data['newColumn'] = <computed values>

See also:
 http://docs.astropy.org/en/v0.2.1/io/votable/index.html#converting-to-from-an-astropy-table-table

Cheers,
Tom

On Tue, Apr 16, 2013 at 5:43 PM, JJ Kavelaars <jjk@uvic.ca> wrote:
> Hi,
>
> i've been using atpy for VOTable manipulation and I'm working to switch to astropy.io.votable.
>
> I don't see how 'add_column' to a table object?
>
> et.
>
>>>> from astropy.io.votable import parse
>>>> from astropy.io.votable.tree import Field
>
>>>> t = parse('filename.vot').get_first_table()
>>>> t.fields.append(Field(t,name='newColumn',datatype='int'))
>>>> print t.array['newColumn']
> ERROR: ValueError: field named newColumn not found. [numpy.ma.core]
>
> ???
>
> I'd like to add a column to t where that column contains a computed value based on one of t's other columns.
>
>
> Hints appreciated.
>
> JJ
>
> --
>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy@scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy
>


More information about the AstroPy mailing list