7 Handy Functions

eparam(*args, **kw) invokes a GUI parameter editor.

lparam(), dparam(), update() and unlearn() work like their namesakes in the IRAF CL, except that multiple task names may be given:

--> # The arguments may be strings ...
--> lparam("imcopy", "hedit")
--> # ... or IrafTask objects.
--> lparam(iraf.imcopy, iraf.hedit)

The setVerbose(value=1, **kw) function sets the verbosity level that determines how much extra information is printed when running a task. You can use print iraf.Verbose to see the current verbosity level, which defaults to 0. The default value=1 for setVerbose results in only slightly more output. Use value=2 (the maximum) for considerably more output, very likely more than you would want to see on a regular basis, but possibly useful for debugging.

The saveToFile(savefile, **kw) and restoreFromFile(savefile, doprint=1, **kw) functions respectively write the IRAF environment to savefile and read from that file. IRAF filename syntax may be used for savefile, e.g. home$pyraf.save. The default doprint=1 means that the tasks and packages at the CL level will be listed; this is equivalent to typing ``?'' in PyRAF.

envget(var, default=None) is similar to the IRAF CL envget() function. The show command can also be used to print the value of an environment variable. The variable may either be one defined in IRAF or in the host operating system. If the variable is not defined, a KeyError exception will be raised, unless default is not None, in which case the value of default will be returned. These options (the ability to catch an exception and the default parameter) are new with the PyRAF version of envget.

osfn(filename) returns the operating-system file name equivalent of filename. This works the same as the IRAF function of the same name.

mktemp(root) appends a string based on the process ID and a letter (or two) to root and returns the resulting string, similar to the IRAF function of the same name. This is intended to return a unique string each time it is called.

nint(x) returns the nearest integer to x. If x is an odd multiple of 0.5, rounding is done away from zero (i.e. nint(0.5) is 1, and nint(-0.5) is -1). The type of the result is integer.

frac(x) returns the fractional part of x, or 0.0 if x is an integer. The returned value has the same sign as x.

real(x) accepts a float, integer or string and returns a float, similar to the corresponding IRAF function. If x is float it is returned unchanged. If it is a string the contents can be numerical, or it can be in d:m:s.s or d:m.m format.

--> print iraf.real("57:18:30")
57.3083333333
--> print iraf.real("57:18.5")
57.3083333333

clDms(x, digits=1, seconds=1) returns x as a string in degrees, minutes, seconds (d:m:s.s) format, with digits figures after the decimal point. If seconds=0, the result is degrees, minutes and decimals of minutes.

--> print iraf.clDms(89.3083333333)
89:18:30.0
--> print iraf.clDms(89.3083333333, digits=3, seconds=0)
89:18.500

An alternative is to use the `%h' or `%m' format with the printf function, which works with PyRAF and with the IRAF CL.

cl> printf("%12.1h\n", 89.3083333333) | scan (s1)
cl> print(s1)
89:18:30.0
cl> printf("%12.3m\n", 89.3083333333) | scan (s1)
cl> print(s1)
89:18.500
--> iraf.printf("%12.1h", 89.3083333333, Stdout=1)[0]
'  89:18:30.0'
--> iraf.printf("%12.3m", 89.3083333333, Stdout=1)[0]
'   89:18.500'

radix(value, base=10, length=0) returns a string with value converted to base. The base must be an integer between 2 and 36 inclusive. If length is specified, the output string will be padded on the left with zeros to a minimum length of length.

--> print iraf.radix(0x21, 2)
100001
--> print iraf.radix(31, 2, 7)
0011111

There is also a radix function in the IRAF CL:

cl> print(radix(21x, 2))
100001
cl> print(radix(31, 2))
11111

pyexecute(filename) has been described before. This uses the Python execfile() function on filename, in the namespace of the current IRAF package. IRAF environment variables and syntax can be used for filename. Optional arguments include PkgName and PkgBinary.

Questions or comments? Contact help@stsci.edu
Documented updated on