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

JJ Kavelaars jjk at uvic.ca
Tue Apr 16 18:57:31 EDT 2013


Hi Tom,

Thanks for the pointer.  

Also, I see that mapping of 'name' from VOTable to Table has been resolved so, I gather, one doesn't loose content on moving into a Table object.  Great!

JJ


On 2013-04-16, at 3:15 PM, Tom Aldcroft wrote:

> 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 at 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 at scipy.org
>> http://mail.scipy.org/mailman/listinfo/astropy
>> 




More information about the AstroPy mailing list