wiki:RefCardPython

Using Pyraf from Python

This is a wiki-quality reference card for doing various things from pyraf. Send corrections to help@…

Loading pyraf

import pyraf

loading an iraf package "foobar" that is already defined (in login.cl, extern.pkg, etc)

pyraf.iraf.foobar( _doprint=0 )

pyraf.iraf.foo( _doprint=0 )
        # it understands abbreviations just like cl does

set an iraf variable

pyraf.iraf.set(varname='value')

define a task

pyraf.iraf.task(taskname='filename')

Find currently known tasks that match a name prefix:

>>> pyraf.iraffunctions.getAllTasks('apnorm')
['apnormalize', 'apnorm1']
>>>

run an iraf task (package must be loaded or task defined first)

pyraf.iraf.foobar(arg,arg,arg)

pyraf.iraf.foo(arg,arg,arg)
        # it understands abbreviations just like cl does

pyraf.iraf.foobar(p1=arg, parameter2=arg, p3=arg)
        # you can pass parameters by name

pyraf.iraf.foobar( ParList="file.par" )
        # you can say the name of a par file

pyraf.iraffunctions.run( 'foo', args=('a','b','c'), kw={'x':1, 'y':2}, save=0 )
        # run it directly

unlearn (n.b. running a task as above does not change the defaults in the par file)

pyraf.iraf.unlearn('taskname')

pyraf.iraf.foobar.unlearn()

find what executable a task runs

pyraf.iraf.foobar.getFilename()

create an iraf task that calls a python function

lpar to stdout

pyraf.iraf.lpar('taskname')

interactive edit of parameters

pyraf.iraf.foobar.eParam()
        # gui

pyraf.iraf.foobar.tParam()
        # text

pyraf.iraf.foobar.lParam()
        # just list, to stdout

An example from stsdas

python
import pyraf
pyraf.iraf.stsdas()
pyraf.iraf.hst_calib()
pyraf.iraf.synphot()
pyraf.iraf.calcp( "acs,hrc,f555w",  "bb(4500)",  "photlam" )
pyraf.iraf.calcp( spectrum="bb(4500)", obsmode="acs,hrc,f555w", form="photlam" )

Listing defined stuff (these are also available as pyraf commands):

pyraf.iraffunctions.listAll()
pyraf.iraffunctions.listPkgs()
pyraf.iraffunctions.listLoaded()
pyraf.iraffunctions.listTasks() 
pyraf.iraffunctions.listCurrent()
pyraf.iraffunctions.listVars()

get details about a task definition (also available as a pyraf command);

pyraf.iraffunctions.taskinfo('taskname')

control the process cache (also available as a pyraf command):

pyraf.iraffunctions.prcacheOff()
pyraf.iraffunctions.prcacheOn()
pyraf.iraffunctions.prcache()    # list process cache
Last modified 4 years ago Last modified on 11/07/13 11:50:58