|
|||
NRAO Home > CASA > CASA Cookbook and User Reference Manual |
|
1.4.3 Getting Return Values
Some tasks and tools return a record (usually a Python dictionary) to the interface. For example, the imstat task (§ 6.7) returns a dictionary with the image statistics in it. To catch these return values into a Python variable, you MUST assign that variable to the task call, e.g.
or
imagename = ’ngc5921.clean.image’
xstat = imstat()
Note that tools that return values work in the same way (§ 1.4.6).
You can print or use the return value in Python for controlling scripts. For example,
CASA <2>: xstat
Out[2]:
{’blc’: array([0, 0, 0, 0]),
’blcf’: ’15:24:08.404, +04.31.59.181, I, 1.41281e+09Hz’,
’flux’: array([ 4.15292207]),
’max’: array([ 0.05240594]),
’maxpos’: array([134, 134, 0, 38]),
’maxposf’: ’15:21:53.976, +05.05.29.998, I, 1.41374e+09Hz’,
’mean’: array([ 1.62978083e-05]),
’medabsdevmed’: array([ 0.00127287]),
’median’: array([ -1.10467618e-05]),
’min’: array([-0.0105249]),
’minpos’: array([160, 1, 0, 30]),
’minposf’: ’15:21:27.899, +04.32.14.923, I, 1.41354e+09Hz’,
’npts’: array([ 3014656.]),
’quartile’: array([ 0.00254587]),
’rms’: array([ 0.00201818]),
’sigma’: array([ 0.00201811]),
’sum’: array([ 49.1322855]),
’sumsq’: array([ 12.27880404]),
’trc’: array([255, 255, 0, 45]),
’trcf’: ’15:19:52.390, +05.35.44.246, I, 1.41391e+09Hz’}
CASA <3>: myrms = xstat[’rms’][0]
CASA <4>: print 10.0*myrms
0.0201817648485
If you do not catch the return variable, it will be lost
or
imagename = ’ngc5921.clean.image’
imstat()
and spewed to terminal. Note that go will trap and lose the return value, e.g.
imagename = ’ngc5921.clean.image’
go
will not dump the return to the terminal either.
NOTE: You cannot currently catch a return value from a task run asynchronously (§ 1.4.4).
More information about CASA may be found at the
CASA web page
Copyright © 2010 Associated Universities Inc., Washington, D.C.
This code is available under the terms of the GNU General Public Lincense
Home |
Contact Us |
Directories |
Site Map |
Help |
Privacy Policy |
Search