Skip to main content

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):

http://bazaar.launchpad.net/~magnusp-snm/+junk/ADAVIS/files/

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

sudo apt-get install python-clientform

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

splatsearch.py --help

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:

./splatsearch.py [parameters]


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!







Comments

  1. Just an update: your code in astroquery was significantly modified, but a pretty stable & useful version is now available:
    astroquery.readthedocs.org/en/latest/splatalogue.html

    ReplyDelete
    Replies
    1. Yes I saw that last week after I updated my code, great work! I updated my splatalogue code to not use mechanize (only standard Python 2 and 3 libs) and to fetch the export file directly

      Delete

Post a Comment

Popular posts from this blog

Screen brightness using Fn keys in i3wm on Lenovo Thinkpad X260

Screen brightness using Fn keys in i3wm

I got a new laptop for work, Lenovo Thinkpad X260. Installed Ubuntu 16.04 Xenial Xerus without much problem.
There are several Fn-hotkeys for the F1-F12 keys, most of them do not work out of the box in Ubuntu, at least not when running i3-window manager.
I managed to solve it in the end. This is how. Part of this solution is from
http://ttrmw.co.uk/linux/hardware_button_brightness.html
Thanks for that!

Changing the brightness I figured out that the brightness can be changed with

$ sudo echo VALUE > /sys/class/backlight/intel_backlight/brightness

where VALUE is between 0 and what is given by the output

$ cat /sys/class/backlight/intel_backlight/max_brightness

These paths might be different for you, so you have to figure it out, and edit the paths in the script below to fit your needs.
The script So I created a script that changes the brightness, as mentioned it borrows heavily from the above mentioned page, but there are some changes.

I save it a…

Installing IRAM GILDAS on Ubuntu

    Figure: Screenshot of GILDAS MAPPIN in action viewing an imported FITS spectral cube.

Fore information on IRAM GILDAS, see http://www.iram.fr/IRAMFR/GILDAS/

NOTE: Updated for Ubuntu 16.04 Xenial Xerus and above.
Nowadays the readme file on the IRAM webpage gives pretty good instructions for Linux as well: http://www.iram.fr/~gildas/dist/gildas.README

First download the source code from http://www.iram.fr/~gildas/dist/index.html
named "gildas-src-mmmyya.tar.gz" where "mmm" is month e.g. Oct, and "yy" is year e.g. 16 and "a" is some letter which signifies the release number, starting with a.

Unpack and enter the directory (it will be installed in the same directory as the unpacked directory, but with "exe" instead of "src" in the name):
tar -xvzf gildas-src-mmmyya.tar
cd gildas-src-mmmyyaFor the new GNOME3 framework, we still need to download libgtk2.0. Hence the dependencies are (including optional dependencies):
sudo apt install gf…

Installing SMA MIRIAD on Ubuntu (2014/05)

What is MIRIAD? See http://bima.astro.umd.edu/miriad/ for information.

Edit : Tested on the Ubuntu 13.04 Raring Ringtail
Edit2 : Tested on the Ubuntu 13.10 Saucy Salamander
Edit3 : Tested on the Ubuntu 14.04 Trusty Tahr

I am not 100% sure about the prerequisites, it should work with the ones below, however (especially after installing IRAM GILDAS).
sudo apt-get install build-essential pgplot5 gfortran libreadline-dev libforms-bin csh cvs Then go and grab the latest binary release from :
ftp://ftp.astro.umd.edu/progs/carma/miriad_201X.X/NOTE: Got into catalog with highest number. At time of writing this is "2014.7". Choose miriad_linux64_u14_gfortran.tar.gz for Ubuntu.
Unpack it where you want it to install:
tar zxf miriad_linux64_BINARY_gfortran.tar.gz where "BINARY" is your Ubuntu version i.e.  miriad_linux64_u14_gfortran.tar.gz for Ubuntu 14.04.

Enter the catalog and run the "install script":
cd miriad
install/make_miriad_starts then to source the miriad binari…