Last modified: December 2013

URL: https://cxc.cfa.harvard.edu/ciao/ahelp/paramio_pset.html
Jump to: Description · Examples · See Also


AHELP for CIAO 4.15

pset

Context: paramio

Synopsis

Set a parameter value.

Syntax

pset(paramfile, parname, value)
pset(paramfile, dictionary)

Description

This function is essentially the same as the command-line version (see "ahelp tools pset").

As with most of the paramio routines, the parameter file can be specified by either name or using the output of paramopen(). To set just one parameter value you use the three-argument form of pset(), namely:

pset(paramfile, parname, value)

To set the values of multiple parameters you use the two-argument form where the second argument is a Python dictionary, where the keys are the parameter names and their values are the new parameter values.

The paramio module is not available by default; see "ahelp paramio" for information on loading the module.


Examples

Example 1

>>> from paramio import *
>>> punlearn("dmcopy")
>>> pset("dmcopy", "infile", "in.fits")
>>> print(pget("dmcopy", "infile"))
in.fits
>>> pset("dmcopy", "verbose", "3")
>>> print(pget("dmcopy", "verbose"))
3

Here we use the pset() function to set the "infile" and "verbose" parameters of "dmcopy". We then use pget() to check the values.

Note that the verbose value had to be given as a string; the pseti() routine should be used if the input value is an integer.

Example 2

>>> punlearn("dmcopy")
>>> pardict = { "infile": "in.fits", "outfile": "out.fits" }
>>> parfict["clobber"] = "yes"
>>> pset("dmcopy", pardict )
>>> print(pget("dmcopy", "infile"))
in.fits
>>> print(pget("dmcopy", "outfile"))
out.fits
>>> print(pget("dmcopy", "clobber"))
yes

The pset() command can set multiple parameters for a tool at once by using a Python dictionary. The keys of the dictionary are the parameter names, and the stored values are used to set the parameter values.

Example 3

>>> punlearn("dmcopy")
>>> fp = paramopen("dmcopy")
>>> pset(fp, "verbose", "3")
>>> print(pget(fp, "verbose"))
3
>>> paramclose(fp)
>>> print(pget("dmcopy", "verbose"))
0

If pset() is called with the name of the parameter file, then it opens the file with a mode of "rwL" which means that the value will be stored in the file even if the parameter is a hidden one. This behaviour is shown in the first example when pset() is used to set the value of the "verbose" parameter.

However, in the current example we have used paramopen() to open the parameter file, and have done so with the mode set to "r" (the default value). Therefore the "verbose" parameter will only equal "3" whilst the parameter file is still open. Once it is closed all knowledge of changes to the parameter file are lost, which is why the final pget() call returns "0" instead of "3".

If the paramopen() call is changed to

fp = paramopen("dmcopy", "rwL")

then the final pget() call would display 3.

See Also

paramio
paccess, paramclose, paramio, paramopen, pget, pgets, plist, pquery, punlearn