Thursday, December 6, 2012

Code release: pyrmsynth - Fast RM synthesis in Python

Another in what will be a series of code release posts. It's not that I've been some kind of coding superhero lately, but that I've got a backlog of code to release in the wild and am only now finding time to do it.

Last week I released pyrmsynth, a fast, Python based RM synthesis package including a CLEAN algorithm for simple deconvolution. This is the RM synthesis software that I wrote for the LOFAR collaboration, and has been in use on their compute cluster for some time. 

The pyrmsynth package is both an application for performing RM synthesis on multi-frequency polarized imaging data, as well as a library of sorts for writing your own applications. If your imaging data is in FITS format, or can be converted into FITS, then the included application will probably do the trick for you out of the box. Or, if you have data in another format, you can write your own file I/O and data parsing script, and use the included RMSynth and RMClean classes to actually perform the RM synthesis on your data.

The advantage of using this package is its flexibility and relative speed. The interface is written in Python, so writing scripts for I/O, data manipulation, and visualization is easy. It's also easy to modify and extend the core functionality, if you need to. Despite being mainly written in Python, the code is still fast for two reasons: 
  1. We use FFTs to perform the imaging
  2. We have written gridding code in Cython (which generates C code) to enable usage of FFTs. 
FFTs require that the data is defined at regular intervals, but because sampling of λ2 space is generally unevenly spaced, this is not true for the case of RM synthesis. We use a fancy binning method known as gridding to sample the data at regular intervals, thereby enabling use of the speedy FFT routine. The gridding would itself be slow if written in pure Python, so instead we have implemented it in C (via Cython), and the result is a very fast code. On my machine, with the current version, I can process (with CLEAN and including file I/O) 10,000 lines of sight in ~6 seconds.

pyrmsynth is released under GPLv3. Contributions are welcome for feature additions, bug fixes, documentation, etc. Just contact me or fork the project on github and get cracking.

No comments:

Post a Comment