4

I have a lot of VO tables like this one:

http://svo2.cab.inta-csic.es/theory/fps3/fps.php?ID=2MASS/2MASS.H

but I am not actually interested in the tables themselves, only in the metadata a.k.a. PARAMeters. Is there an easy way to get these (as there is for FITS table headers) in python/astropy?

The only thing I found was some nested for-loop:

from astropy.table import Table
H = Table.read('2MASS.2MASS.H.xml')

for resource in H.resources:
    for param in resource.params:
        print param.name, param.value

EDIT: What I actually want is to get a list/dict of PARAM value and a list of corresponding PARAM names...

fjaellet
  • 43
  • 7

2 Answers2

5

You can use iter_fields_and_params to iterate over all FIELD and PARAM tags in the file. In VOTable land, the only difference between a FIELD and a PARAM is that a PARAM has a constant value, so these are logically grouped together.

mdboom
  • 271
  • 2
  • 4
  • Thanks Michael! But how do I then actually access the "generator object" that iter_fields_and_params produces? `**AttributeError**: 'generator' object has no attribute 'name'`. Sorry, this is all really new to me.. – fjaellet May 04 '15 at 12:44
0

Workaround: Accessing each of the individual PARAM values is easy. E.g.:

print H.get_field_by_id('filterID').value

Although this is not entirely clear from the astropy docs, accessing the PARAM values (once you know the PARAM names) works exactly in the same fashion as for FIELDs...

fjaellet
  • 43
  • 7