olebole / python-cpl

Python bindings for CPL recipes
http://pypi.python.org/pypi/python-cpl
GNU General Public License v2.0
10 stars 5 forks source link

feature request: use included xml association files #3

Open sirpercival opened 9 years ago

sirpercival commented 9 years ago

The dataset I just downloaded includes a nightly association file (XML). Would it be possible for python-cpl to use that natively? (I may write something to parse it anyway, but it seems like a useful tool to include...)

olebole commented 9 years ago

Can you post a link to the documentation of this file?

sirpercival commented 9 years ago

Sure, here you go: http://archive.eso.org/cms/faq/calselector-what-is-the-xml-file-that-comes-in-each-dataset.html

sirpercival commented 9 years ago

So, the way I'm doing it is to use xml.etree, using an xpath to traverse the tree. So, for example, if I wanted to grab flats from assoc.xml:

from xml.etree import ElementTree as ET
association = 'assoc.xml'
xm = ET.parse(association)
flats = [x.attrib['name']+'.fits' for x in xm.findall('./associatedFiles' +
                'association[@category="SW_SP_FLAT"]/mainFiles/file')]