Loading...
 

Python Equivalents for IDL commands

This page lists Pythonic versions of some of the more common commands from the Goddard IDL astronomy library, plus some useful more general translations for e.g. plotting and IO commands. For a more generic, non-astro specific guide see NumPy for IDL Users or Mapping IDL to Python.

There are often multiple Python equivalents to a given IDL routine, in which case there are multiple entries listed in the Python column below. 

Astronomical Calculations:

Coordinates, Dates, and Magnitudes

IDL
Python
function
AIRTOVAC pyastrolib.airtovac(wave)
astropysics.spec.air_to_vacuum(wave)
Convert air wavelengths to vacuum wavelengths
VACTOAIR pyastrolib.vactoair(wave)
astropysics.spec.vacuum_to_air(wave)
Converts vacuum wavelengths to air wavelengths
ALTAZ2HADEC pyastrolib.altaz2hadec(alt,az,lat) Convert Horizon (Alt-Az) coordinates to Hour Angle and Declination
BPRECESS coords.position("12:34:45 -23:42:32").b1950()
astropysics.coords.FK5Coordinates("12:34:45 -23:42:32").convert(FK4Coordinates)
Convert coordinates from J2000 to B1950
JPRECESS coords.position("12:34:45 -23:42:32").j2000()
astropysics.coords.FK4Coordinates("12:34:45 -23:42:32").convert(FK5Coordinates)
Convert coordinates from B1950 to J2000
CCM_UNRED pyastrolib.ccm_unred(wave,flux,ebv)
astropysics.obstools.CardelliExtinction(ebv).correctFlux(flux,wave)
Deredden a flux vector using the CCM 1989 parameterization
DATE_CONV SLA_CALDJ?
dayconv.py
astropysics.obstools.calendar_to_jd(date)+additional astropysics.obstools.jd_to_? funcs
Convert date to various formats, including Julian Date
DAYCONV dayconv.py
astropysics.obstools.jd_to_calendar(jd)
Converts Julian dates to Gregorian calendar dates
FLUX2MAG pyastrolib.flux2mag(flux)
astropysics.phot.lum_to_mag(flux,0,1,fluxerr)
Convert from flux (ergs/s/cm^2/A) to magnitudes
MAG2FLUX astropysics.phot.mag_to_lum(mag,0,1,magerr) Convert from magnitudes to flux
GLACTC coords.position("12:34:45 -23:42:32").galactic()
astropysics.coords.ICRSCoordinates("12:34:45 -23:42:32").convert(GalacticCoordinates)
Convert between celestial and Galactic coordinates.
HELIO_RV   Return the heliocentric radial velocity of a spectroscopic binary
PLANCK pyastrolib.plank(wave,temp)
astropysics.models.BlackbodyModel(T=temp)(wave)
calculate the Planck function in units of ergs/cm2/s/A
SIXTY, RADEC coords.position((188.681,-22.326)).hmsdms()
pyastrolib.sixty(dd)
pyastrolib.radec(ra,dec,hours="")
astropysics.coords.AngularCoordinate(188.681).hms or .dms
Convert decimal number to sexigesimal
TEN coords.position("12:34:45 -23:42:32").dd()
pyastrolib.ten(dd,mm="",ss="")
astropysics.coords.AngularCoordinate("12:34:45").d
Convert sexigesimal number to decimal

Photometry

IDL/IRAF
Python
function
  astropysics.phot  
find pyastrolib.find Find point sources within an image
synphot pysynphot

synthetic photometry software package suitable for either library or interactive use. Intended as a modern-language successor to the IRAF/STSDAS synphot package.

create a throughput file (wavelength and throughput in dimensionless units between 0 and 1) for each band in your instrument, and a spectrum file or array (wavelength and flux) or black body as a function of temperature. Once you have those, you can simulate an observation and predict the magnitude, something like this:

import pysynphot as psyn
bp = psyn.FileBandpass('your_throughput_file.fits')
sp = psyn.FileSpectrum('spectrum_file.fits')
obs = psyn.Observation(sp, bp)
obs.effstim('abmag')  #gives you the observed magnitude

FITS I/O

IDL
IRAF
Python
function
data=READFITS('file',header) data=pyfits.open('file') open fits file
CHECKFITS data[0].verify() verify file is FITS compliant
WRITEFITS(data,'newfile') data.writeto('newfile') write fits file to disk
SXPAR()
imheader
data[0].header['KEY'] Obtain value of header keyword
SXADDPAR()
hedit
data[0].header['KEY']='value' OR data[0].header.update('KEY','value', 'comment') Add or modify header keyword
SXDELPAR
hedit
del data[0].header['KEY'] Delete header keyword
SXADDHIST data[0].header.add_history('history') Add history keyword
SXADDHIST,/Comment data[0].header.add_comment('comment') Add comment keyword

Image Manipulation

IDL
Python
function
filter_image scipy.ndimage.filters.gaussian_filter Gaussian filter with options for handling the edges.

Math and Statistics

IDL
Python
function
smoothed=smooth(data,3,/edge_truncate) smoothed=scipy.ndimage.filters.uniform_filter(data,size=3) Smooth a multi-dimensional array.

PLOTTING

also see NumPy for IDL users

IDL
Python
function
most IDL plotting commands matplotlib.pyplot.similarname matplotlib has equivalent functions for all standard IDL plots
  Veusz Interactive GUI plotting package
PLOTTERR errorbar (matplotlib) Plot Y vs. X with optional X and Y error bars
plot,x,y,psym=10 pyplot.plot(x,y,drawstyle='steps-mid') Plot a histogram-style stepped bar chart.

ASCII I/O

IDL
Python
function
FORPRINT numpy.savetxt(filename,vec) Print a set of vectors to Terminal or file. Inverse of READCOL.
READCOL

numpy.loadtxt(filename)
data = atpy.Table('data.txt')
data=asciitable.read('data.txt')
data=asciidata.open('data.txt')
col1,col2,col3=readcol("data.txt")
astropysics.io.loadtxt_text_fields and astropysics.io.loadtxt_fixed_column_fields

Read ascii tables
ATPy is the most flexible (reads non-ASCII data formats too), asciitable is the most configurable for custom ASCII table formats.
 
read a wide range of ASCII table formats
SExtractor format only?
not modular, but intuitive.

Array Manipulation

Numpy array manipulation rountines.

IDL
Python
function
REFORM(array,d1,d2) numpy.reshape(array,(d1,d2)) Changes the dimensions of an array without changing the total number of elements.

Miscellaneous (Non-Astronomy) Procedures

IDL
Python
function
STRN(string) str(string) Converts anything to a string for printing.

Page last modified on Friday 16 of March, 2012 15:10:42 EDT