[AstroPy] getting id value from xml files

Grigoris Maravelias gr.maravelias at gmail.com
Sun Mar 29 17:21:36 EDT 2015


Hi Mike! I just found time to check it...

On 03/27/2015 02:43 PM, Michael Droettboom wrote:
> The you could do:
> |from astropy.io import votable
> vot = votable.parse("file.xml")
> value = vot.resources[0].infos[0].value|
|I tried that but returns an error:
|
|ERROR: IndexError: list index out of range [__main__]
Traceback (most recent call last):
  File "./xml_extractor.py", line 21, in <module>
    value = vot.resources[0].infos[0].value
IndexError: list index out of range|
>
> I assume you are asking how to do this with astropy.io.votable?
>
> INFO tags can appear in a number of places in a VOTable file, so
> without seeing the whole file, it’s hard to say.
>
> For example, if you had a file like:
>
> |<VOTABLE>
>   <RESOURCE>
>     <INFO ID="sfr" name="sfr" value="1.34267351483e-40"/>
>   </RESOURCE>
> </VOTABLE>
> |
You are almost correct. I provide an original xml file (see [1]) where
you can see that I have two resource ids with assigned data on them (as
far as I can understand). The following code:

from astropy.table import Table
from astropy.io.votable import parse

xmlfile = parse('bla.xml')

flm = Table.read(xmlfile,table_id='Flambda')
fnu = Table.read(xmlfile,table_id='Fnu')

flm_old = flm['ssp_old']
flm_young = flm['ssp_young']
flm_add = flm_old+flm_young

can successfully read the the tables flm/fln as dictionaries (with
corresponding data arrays). But as you see there is a number of info ids
outside the resource elements, which are the ones that I would like to
access (more easily than just read the file).

I do not know if this helps.

Best
Grigoris

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20150329/222e8da5/attachment.html>


More information about the AstroPy mailing list