|
|||
NRAO Home > CASA > CASA Cookbook and User Reference Manual |
|
6.8 Extracting data from an image (imval)
The imval task will extract the values of the data and mask from a specified region of an image and place in the task return value as a Python dictionary.
The inputs are:
imagename = ’’ # Name of the input image
region = ’’ # Image Region. Use viewer
box = ’’ # Select one or more box regions
chans = ’’ # Select the channel(spectral) range
stokes = ’’ # Stokes params to image (I,IV,IQU,IQUV)
async = False
Area selection using box and region is detailed in § 6.1.1 and § 6.1.5 respectively. By default, box=’’ will extract the image information at the reference pixel on the direction axes.
Plane selection is controlled by chans and stokes. See § 6.1.2 for details on plane selection. By default, chans=’’ and stokes=’’ will extract the image information in all channels and Stokes planes.
For instance,
will extract the Stokes I value or spectrum at pixel 144,144, while
will extract a 21 by 21 pixel region.
Extractions are returned in NumPy arrays in the return value dictionary, plus some extra elements describing the axes and selection:
CASA <3>: xval
Out[3]:
{’axes’: [[0, ’Right Ascension’],
[1, ’Declination’],
[3, ’Frequency’],
[2, ’Stokes’]],
’blc’: [128, 128, 0, 0],
’data’: array([ 0.89667124]),
’mask’: array([ True], dtype=bool),
’trc’: [128, 128, 0, 0],
’unit’: ’Jy/beam.km/s’}
extracts the reference pixel value in this 1-plane image. Note that the ’data’ and ’mask’ elements are NumPy arrays, not Python lists.
To extract a spectrum from a cube:
CASA <9>: xval
Out[9]:
{’axes’: [[0, ’Right Ascension’],
[1, ’Declination’],
[3, ’Frequency’],
[2, ’Stokes’]],
’blc’: [125, 125, 0, 0],
’data’: array([ 8.45717848e-04, 1.93370355e-03, 1.53750915e-03,
2.88399984e-03, 2.38683447e-03, 2.89159478e-04,
3.16268904e-03, 9.93389636e-03, 1.88773088e-02,
3.01138610e-02, 3.14478502e-02, 4.03211266e-02,
3.82498614e-02, 3.06552909e-02, 2.80734301e-02,
1.72479432e-02, 1.20884273e-02, 6.13593217e-03,
9.04005766e-03, 1.71429547e-03, 5.22095338e-03,
2.49114982e-03, 5.30831399e-04, 4.80734324e-03,
1.19265869e-05, 1.29435991e-03, 3.75700940e-04,
2.34788167e-03, 2.72604497e-03, 1.78467855e-03,
9.74952069e-04, 2.24676146e-03, 1.82263291e-04,
1.98463408e-06, 2.02975096e-03, 9.65532148e-04,
1.68218743e-03, 2.92119570e-03, 1.29359076e-03,
-5.11484570e-04, 1.54162932e-03, 4.68662125e-04,
-8.50282842e-04, -7.91683051e-05, 2.95954203e-04,
-1.30133145e-03]),
’mask’: array([ True, True, True, True, True, True, True, True, True,
True, True, True, True, True, True, True, True, True,
True, True, True, True, True, True, True, True, True,
True, True, True, True, True, True, True, True, True,
True, True, True, True, True, True, True, True, True, True], dtype=bool),
’trc’: [125, 125, 0, 45],
’unit’: ’Jy/beam’}
To extract a region from the plane of a cube:
CASA <14>: xval
Out[14]:
{’axes’: [[0, ’Right Ascension’],
[1, ’Declination’],
[3, ’Frequency’],
[2, ’Stokes’]],
’blc’: [126, 128, 0, 23],
’data’: array([[ 0.00938627, 0.01487772],
[ 0.00955847, 0.01688832],
[ 0.00696965, 0.01501907],
[ 0.00460964, 0.01220793],
[ 0.00358087, 0.00990202]]),
’mask’: array([[ True, True],
[ True, True],
[ True, True],
[ True, True],
[ True, True]], dtype=bool),
’trc’: [130, 129, 0, 23],
’unit’: ’Jy/beam’}
CASA <15>: print xval[’data’][0][1]
0.0148777160794
In this example, a rectangular box was extracted, and you can see the order in the array and how to address specific elements.
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