casa
$Rev:20696$
|
00001 # 00002 # This file was generated using xslt from its XML file 00003 # 00004 # Copyright 2009, Associated Universities Inc., Washington DC 00005 # 00006 import sys 00007 import os 00008 from casac import * 00009 import string 00010 from taskinit import casalog 00011 #from taskmanager import tm 00012 import task_imval 00013 def imval(imagename='', region='', box='', chans='', stokes=''): 00014 00015 """Get the data value(s) and/or mask value in an image. 00016 The data point(s) to be retrieved are those found in the specified 00017 region, which may be: 00018 1. A region file from the viewer (region parameter) 00019 2. A region specified by a set of rectangular 00020 pixel coordinates, the channel ranges and/or the Stokes. 00021 00022 For directed output, run as 00023 myoutput = imval() 00024 00025 00026 Keyword arguments: 00027 imagename -- Name of input image 00028 Default: none; Example: imagename='ngc5921_task.im' 00029 region -- region file or name. 00030 Use the viewer, then region manager to select regions of 00031 the image to process. Similar to box, but graphical 00032 Or the name of a region stored with the image, 00033 use rg.namesintable() 00034 to retrieve the list of names. 00035 Default: none 00036 Example: region='myimage.im.rgn' 00037 region='region1' 00038 box -- A box region on the directional plane 00039 Only pixel values acceptable at this time. 00040 Default: '' (referencepixel values for the Directional coord); 00041 Example: box='10,10,50,50' 00042 box = '10,10,30,30,35,35,50,50' (two boxes) 00043 box = '-1,-1' (all points) 00044 chans -- channel numbers 00045 Range of channel numbers to include in statistics 00046 All spectral windows are included 00047 Default:''= all; Example: chans='3~20'; 00048 chans='-1' (all channels) 00049 stokes -- Stokes parameters to analyze. 00050 Default: none (all); Example: stokes='IQUV'; 00051 stokes='I,Q' 00052 stokes='-1' (all stokes values) 00053 Options: 'I','Q','U','V','RR','RL','LR','LL','XX','YX','XY','YY', ... 00054 00055 General procedure: 00056 00057 1. Specify inputs, then 00058 00059 2. myoutput = imval() 00060 or specify inputs directly in calling sequence to task 00061 myoutput = imsval(imagename='image.im', etc) 00062 00063 3. myoutput['KEYS'] will contain the result associated with any 00064 of the keys given below 00065 00066 KEYS CURRENTLY AVAILABLE 00067 blc - absolute PIXEL coordinate of the bottom left corner of 00068 the bounding box surrounding the selected region 00069 trc - the absolute PIXEL coordinate of the top right corner 00070 of the bounding box surrOunding the selected region 00071 axes - List the data stored in each axis of the data block. 00072 unit - unit of the returned data values. 00073 data - data value(s) found in the given region 00074 mask - mask value(s) found in the given region 00075 00076 NOTE: The data returned is in the same order as it is internally 00077 stored, typically RA, DEC, spectral, stokes. Also both the data 00078 and mask values are returned as Python Numpy arrays, for more 00079 information on how to manipulate them see 00080 http://numpy.scipy.org/#array_interface 00081 00082 00083 Additional Examples 00084 # The value and mask value at a single point (5,17,2,Q) 00085 imval( 'myImage', box='5,5,17,17', chans=2, stokes='Q' ) 00086 00087 # Select and report on two box regions 00088 # box 1, bottom-left coord is 2,3 and top-right coord is 14,15 00089 # box 2, bottom-left coord is 30,31 and top-right coord is 42,43 00090 # Note that only the boxes for the 00091 imval( 'myImage', box='2,3,14,15;30,31,42,43' ) 00092 00093 # Select the same two box regions but only channels 4 and 5 00094 imval( 'myImage', box='2,3,14,15;30,31,42,43', chan='4~5' ) 00095 00096 # Select all channels greater the 20 as well as channel 0. 00097 # Then the mean and standard deviation are printed 00098 # Note that the data returned is a Python numpy array which 00099 # has built in operations such as min, max, and means as 00100 # demonstrated here. 00101 results = imval( 'myImage', chans='>20;0' ) 00102 imval_data=results['data'] 00103 mask=results['mask'] 00104 # holds the absolute coordinates of the associated pixels in imval_data 00105 coords = results['coords'] 00106 print "Data max: ", imval_data.max(), " mean is ", imval_data.mean() 00107 swapped_data=imval_data.swapaxes(0,2) 00108 swapped_mask=mask.swapaxes(0,2) 00109 print "Data values for 21st channel: \n", swapped_data[0] 00110 print "Mask values for 21st channel: \n", swapped_mask[0] 00111 00112 """ 00113 00114 # 00115 # The following is work around to avoid a bug with current python translation 00116 # 00117 mytmp = {} 00118 00119 mytmp['imagename'] = imagename 00120 mytmp['region'] = region 00121 mytmp['box'] = box 00122 mytmp['chans'] = chans 00123 mytmp['stokes'] = stokes 00124 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00125 trec = casac.utils().torecord(pathname+'imval.xml') 00126 00127 casalog.origin('imval') 00128 if trec.has_key('imval') and casac.utils().verify(mytmp, trec['imval']) : 00129 result = task_imval.imval(imagename, region, box, chans, stokes) 00130 00131 else : 00132 result = False 00133 return result