[AstroPy] saving a votable as a xml file using astropy

Michael Droettboom mdroe at stsci.edu
Tue Feb 26 12:20:41 EST 2013


Yes, exactly.

Cheers,
Mike

On 02/26/2013 03:35 AM, Susana Sanchez Exposito wrote:
> Thanks Mike,
>
> At first, I was not sure what you mean, because I didn't find any
> attribute of VOTableFile for the data array, which can be modified.
> Then I realized the method VOTableFile.get_first_table() returns a
> *reference* of the first table (I thought it would return a *copy* of
> the table), so I guess the way you said is the way I code below, isn't
> it?:
>
> #Open the votable
> votable = parse("cig22.xml")
>
> #Get a reference of the table
> table=votable.get_first_table()
>
> #Modify the table
> table.array['CIG Number'][0]="CIG SUSANA"
>
> #The  cig_s.xml table will contain the before modification
> votable.to_xml("cig_s.xml")
>
>
> Regards and thanks again for your help.
> Susana.
>
>
>
>
> 2013/2/25 Michael Droettboom <mdroe at stsci.edu>:
>> VOTable is actually a container format for multiple tables, so you can only
>> save that entire container to XML.
>>
>> The best thing to do to make modifications to save back out would be to
>> retain a reference to the top-level VOTableFile object (not the
>> votable.tree.Table object), and call `to_xml` on that.  That approach should
>> also maintain all of the metadata (what the original names and IDs were).
>>
>> Hope that helps, and feel free to ping me if you need more detail.
>>
>> Mike
>>
>>
>> On 02/25/2013 12:46 PM, Susana Sanchez wrote:
>>
>> Hi again,
>>
>> This time I have the doubt saving votables as xml. As I said in my
>> previous mail, I want to show the VOTable in a nice way using Qt
>> library, I also want to allow the users can modify this votable and
>> then save the changes.
>>
>> Reading the documentation I saw that the astropy.io.votable.tree.Table
>> has the method .to_xml, but probably I am not using it  well because I
>> get this error:
>>
>> In [159]: table =
>> parse_single_table("/home/susana/Documents/guipsy/examples/tables/cig22.xml",pedantic=False)
>> In [160]: table.to_xml("./cig22_changed.xml")
>> ---------------------------------------------------------------------------
>> AttributeError                            Traceback (most recent call last)
>>
>> /home/susana/<ipython console> in <module>()
>>
>> /usr/local/lib/python2.6/dist-packages/astropy/io/votable/tree.pyc in
>> to_xml(self, w, **kwargs)
>>     2518
>>     2519     def to_xml(self, w, **kwargs):
>> -> 2520         with w.tag(
>>     2521             u'TABLE',
>>     2522             attrib=w.object_attrs(
>>
>> AttributeError: 'str' object has no attribute 'tag'
>>
>>
>> Finally I got this way to save the xml:
>>
>> #Open the votable
>> table =
>> astropy.io.votable.parse_single_table("/home/susana/Documents/guipsy/examples/tables/cig22.xml",pedantic=False)
>>
>> #Modify the table
>> table.array['CIG Number'][0]="CIG SUSANA"
>>
>> #Create a VOTableFile instance of the table
>> votable= VOTableFile.from_table(table.to_table())
>>
>> #Save the xml
>> votable.to_xml('cig22S.xml')
>>
>>
>> I have two questions/comments:
>>
>> 1) Is this way correct? Or maybe there is a better way to save the
>> changes made in a VOtable?
>>
>> 2) The VOTable created,  'cig22S.xml', is ok, but the fields have lost
>> the 'name' value. Now, the 'ID' and the 'name' have the same value
>> (the original value of ID).
>>
>>
>>
>> Thanks again,
>> 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
>>
>
>




More information about the AstroPy mailing list