By Taro Sato (taro at ap.smu.ca)
NOTE: This is a page for my old side programming project, on astrophysical computing. I just moved it here since I haven’t been tracking access and therefore I don’t know if there has been any serious interest in doing k correction on Python rather than IDL. If anyone is seriously interested in doing k correction with Python, this whole thing can be made into an open source project for communal use (if we can obtain an approval from the original library developer).
KCorrect is an attempt to wrap some of the utilities available in kcorrect written by Michael Blanton into an easy-to-use Python package. kcorrect is a collection of C/IDL codes which implements k corrections and photometric redshifts with broad-band photometry (and much more).
Motivation
With NumPy quickly maturing into the standard platform for scientific computing with Python, there should be an increasing interest in carrying out astronomical data analysis on Python in near future. Python is a well-designed programming language offering astronomers a simple-to-use yet very powerful platform with all the advantages of a modern programming language (e.g., object orientation, exceptions, namespace) as well as the simplicity of a scripting language, not to mention it is FREE. We (actually I…as of now) hope to contribute to the increase in the usage of Python among astrophysicists.
Conditions of Use
Since KCorrect is simply a Python wrapper to kcorrect (v4_1_4), users are requested to follow the conditions of use described in kcorrect distribution website.
No extra citation is necessary on the use of the Python version. I changed my mind because there are too many people who are not very sincere. Please acknowledge the use of this Python version clearly, if you ever use a portion of this program in your published work
Also, please do not modify the program yourself. If you wish to do that, please consider contributing to the project instead, rather than secretly using it to your liking and don’t even acknowledge somebody else’s effort on which you build your work.
Although we do attemp to ensure that users obtain similar results to the IDL version when desired, bugs are a fact of life; please report bugs and comments to Taro Sato (email address given above) if you suspect the problems occur with the Python version.
General Description
The general concepts of k corrections are well documented in Michael Blanton’s kcorrect distribution website; users of KCorrect are urged to learn the principles behind the software by throughly reading his documentation. There is also an article written by David Hogg which may be of interest for users of kcorrect.
The KCorrect Python port project is totally a volunteer effort by those who love to code in Python, so we have not implemented all the rich functionalities already available in the IDL version of kcorrect (it is slow going without external contributions; please let me know if you can contribute a tiny bit).
Currently Available Functionalities
- Core implementation of k correction
- High-level interface for some redshift surveys (so far only SDSS and DEEP)
Installing KCorrect
This version of KCorrect requires the following software to be already installed on your machine:
- Python 2.5.2 or better (http://www.python.org/)
- NumPy 1.3 or better (http://www.scipy.org/Download/)
- SWIG 1.3.36 or better (http://www.swig.org/)
Download the snapshot version here. README.txt included in the tarball has a detailed installation instruction. If you already have a working installation of the IDL version of kcorrect (which is a requirement), the standard python method
$ python setup.py install
should simply work.
Usage
Here is an example IPython session:
In [1]: import KCorrect as KC
In [2]: maggie = [1., 4.78, 10.96, 14.45, 19.05]
In [3]: maggie_ivar = [1100., 28., 7.7, 4.4, 2.5]
In [4]: redshift = 0.03
In [5]: filters = KC.FilterList(['sdss_u0.par','sdss_g0.par','sdss_r0.par',
...: 'sdss_i0.par','sdss_z0.par'])
In [6]: kc = KC.KCorrect()
In [7]: kc.set_data(redshift, filters, maggie, maggie_ivar)
In [8]: print kc.kcorrect(band_shift=0.1)
[[-0.38402203 -0.33727303 -0.19066639 -0.15796432 -0.13370053]]
The above example is to be compared to the one given at kcorrect distribution website. What we wanted to do with the Python version is to hide the part of implementation that users really do not want to deal with (e.g., conversions to “AB maggies,” preserving the projection table or the template spectra, etc.). A more typical usage goes like this:
In [11]: redshift = [1.029, 0.9581]
In [12]: deepmag = [[23.112, 22.363, 21.690],[24.668, 23.878, 23.248]]
In [13]: kc = KC.KCorrectDEEP(cosmo=(0.3,0.7,1.0))
In [14]: kc.set_data(redshift, deepmag)
In [15]: print kc.absmag()
[[-21.2052002 -21.69138336 -21.85865593]
[-19.35534096 -19.64371872 -19.71680069]]
In [16]: vega2ab = KC.vega2ab(kc.filter_list)
In [17]: print kc.absmag() - vega2ab
[[-21.0925668 -21.93185531 -22.3164852 ]
[-19.24270756 -19.88419066 -20.17462996]]
In [18]: bessell = KC.FilterList(['bessell_V.par','bessell_R.par'])
In [19]: print kc.appmag(filter_list=bessell)
[[ 22.75250435 22.36059952]
[ 24.18490219 23.83894157]]
Note that the classes in KCorrect package are designed so that users need to define the minimal set of input data. Fine tuning of parameters (e.g., assumed cosmology above) can generally be done using optinal input arguments. We also implement some auxiliary functions such as:
In [28]: KC.get_available_filters()
which returns the list of all available filter file names.
Documentation
At this point, no fancy documentation is available besides this web page. We strive to document the software using Python’s native docstrings. For example, doing
In [29]: help(KC.KCorrectDEEP)
should give you more detailed information about KCorrectDEEP class in KCorrect package.