[AstroPy] getting id value from xml files

Grigoris Maravelias gr.maravelias at gmail.com
Wed Apr 1 09:37:58 EDT 2015


Thanks Mike! That works great.
Thanks also for the pull request.

Best
Grigoris
 
On 04/01/2015 02:46 PM, Michael Droettboom wrote:
>
> In the specific case of your file, the INFO elements are all at the
> top level, so they can be obtained through the |.infos| member, e.g.:
>
> |from astropy.io import votable
> vot = votable.parse('file.xml')
>
> def find_by_ID(vot, ID):
>     for info in vot.infos:
>         if info.ID == ID:
>             return info.value
>
> find_by_ID(vot, 'sfr')
> |
>
> But, as I said, this functionality really should be built-in to
> astropy, and PR https://github.com/astropy/astropy/pull/3633 adds this
> to master (and it’s more general because it will search the entire
> file, not just the INFO elements at the top-level).
>
> Mike
>
> On 03/31/2015 11:26 AM, Michael Droettboom wrote:
>
>> On 03/29/2015 05:21 PM, Grigoris Maravelias wrote:
>>> 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|
>>
>> That was just an example if your file happened to have the same
>> layout as what I suggested -- since I hadn't seen your file, I just
>> had to guess.  Chances are your INFO element in question is in a
>> different location, so you'll need to adjust accordingly.
>>
>>>> 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]) 
>>
>> I don't see the target of the citation (maybe just forgot?). 
>>
>> Cheers,
>> Mike
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> 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
>>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20150401/5a586b7a/attachment.html>


More information about the AstroPy mailing list