Querying Splatalogue.net with a Python script
I have written a Python script/module to query the Splatalogue.net spectral line catalog compilation. It does not rely on any SPLAT-VO protocol at all. It queries the database through the normal web interface, which makes it possible to query with the same parameters as through the web interface. Yay! The instructions below is for Ubuntu Linux, but is probably easily adapted to other platforms.
EDIT2: I have rewritten the module and the updated version is now part of astropy.astroquery (http://github.com/astropy). However, the CLI interface is stripped out of this version. Furthermore, according to Splatalogue.net/NRAO, the php interface will be replace by a java onlye sometime this year (https://safe.nrao.edu/wiki/bin/view/Splat/WebHome, see Milestone no 4.) which would mean that I have to update it.
The code is hosted on my Launchpad.net trunk (bazaar versioning):
EDIT: I have moved my code to github (!) https://github.com/vilhelmp/adapy
the file splatsearch (.py, in the “bin” folder on github) is all that is needed from Launchpad. The prerequisite modules are UrlLib2 and ClientForm, for the form submission/HTML parsing.
In Ubuntu the ClientForm (http://wwwsearch.sourceforge.net/old/ClientForm/) module is installed by running
in a terminal. UrlLib should come packed with Python. There is a plan to move the splatsearch script over to use some newer module, like the Mechanize module (http://wwwsearch.sourceforge.net/mechanize/).
EDIT: Mechanize now actually takes care the clientform and urllib (linked) part. I haven’t had time to move the script over to it yet. (Branch and fix perhaps?)
It is runnable from the command line (set it to be runnable “chmod +x splatsearch.py“). After this, running
without any input, from the terminal should give you the usage rundown. Although, first you have to add the path to splatsearch.py to your environment variables. Alternatively run it from the same catalog as the file with:
It can also be used inside your favorite Python script/interactive session with:
Python : from splatsearch import splatsearch
Yes, I guess it is bad programming to name them the same (module and function). After this initial import it is easy to get the idea of how to search and get it to return what/how you want (print on screen, list or dictionary) with:
Python : help splatsearch
My Launchpad.net/github page also hosts other astronomical data analysis and visualization scripts to do different things on interferometric spectral cubes (small FOV, <60 arcsec). The ADAVIS module has e.g. a function for plotting spectrum and at the same time fit Gaussians, take the fitted frequencies and query Splatalogue.net for line identification. It is far from done though, and I have a huge to-do list of things to fix, but most things work well enough.
Happy line identification!