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_imstat 00013 def imstat(imagename='', axes=-1, region='', box='', chans='', stokes='', listit=True, verbose=True, mask='', stretch=False, logfile='', append=True): 00014 00015 """Displays statistical information from an image or image region 00016 00017 Many parameters are determined from the specified region of an image. 00018 For this version, the region can be specified by a set of rectangular 00019 pixel coordinates, the channel ranges and the Stokes. 00020 00021 For directed output, run as 00022 myoutput = imstat() 00023 00024 00025 Keyword arguments: 00026 imagename Name of input image 00027 Default: none; Example: imagename='ngc5921_task.im' 00028 axes axes to compute statistics over. -1 => all axes. 00029 region Region of interest. See help par.region. 00030 box A box region specified in pixels on the directional plane 00031 Default: none (whole 2-D plane); 00032 Example: box='10,10,50,50' 00033 box = '10,10,30,30,35,35,50,50' (two boxes) 00034 chans Zero based channel numbers 00035 Range of channel numbers to include in statistics 00036 All spectral windows are included 00037 Default:''= all; Example: chans='3~20' 00038 stokes Stokes parameters to analyze. 00039 Default: all; Example: stokes='IQUV'; 00040 Example:stokes='I,Q' 00041 Options: 'I','Q','U','V','RR','RL','LR','LL','XX','YX','XY','YY', ... 00042 listit Print stats and bounding box to logger? 00043 verbose Print additional messages to logger? 00044 mask Mask to use. See help par.mask. Default is none. 00045 stretch Stretch the mask if necessary and possible? See help par.stretch 00046 logfile Name of file to write fit results. 00047 append If logfile exists, append to it (True) or overwrite it (False). 00048 00049 00050 General procedure: 00051 00052 1. Specify inputs, then 00053 00054 2. myoutput = imstat() 00055 or specify inputs directly in calling sequence to task 00056 myoutput = imstat(imagename='image.im', etc) 00057 00058 3. myoutput['KEYS'] will contain the result associated with any 00059 of the keys given below 00060 00061 KEYS CURRENTLY AVAILABLE 00062 blc - absolute PIXEL coordinate of the bottom left corner of 00063 the bounding box surrounding the selected region 00064 blcf - Same as blc, but uses WORLD coordinates instead of pixels 00065 trc - the absolute PIXEL coordinate of the top right corner 00066 of the bounding box surrounding the selected region 00067 trcf - Same as trc, but uses WORLD coordinates instead of pixels 00068 flux - the integrated flux density if the beam is defined and 00069 the if brightness units are $Jy/beam$ 00070 npts - the number of unmasked points used 00071 max - the maximum pixel value 00072 min - minimum pixel value 00073 maxpos - absolute PIXEL coordinate of maximum pixel value 00074 maxposf - Same as maxpos, but uses WORLD coordinates instead of pixels 00075 minpos - absolute pixel coordinate of minimum pixel value 00076 minposf - Same as minpos, but uses WORLD coordinates instead of pixels 00077 sum - the sum of the pixel values: $\sum I_i$ 00078 sumsq - the sum of the squares of the pixel values: $\sum I_i^2$ 00079 mean - the mean of pixel values: 00080 $\bar{I} = \sum I_i / n$ 00081 sigma - the standard deviation about the mean: 00082 $\sigma^2 = (\sum I_i - \bar{I})^2 / (n-1)$ 00083 rms - the root mean square: 00084 $\sqrt {\sum I_i^2 / n}$ 00085 median - the median pixel value 00086 medabsdevmed - the median of the absolute deviations from the 00087 median 00088 quartile - the inter-quartile range. Find the points 00089 which are 25% largest and 75% largest (the median is 00090 50% largest), find their difference and divide that 00091 difference by 2. 00092 00093 Additional Examples 00094 # Selected two box region 00095 # box 1, bottom-left coord is 2,3 and top-right coord is 14,15 00096 # box 2, bottom-left coord is 30,31 and top-right coord is 42,43 00097 imstat( 'myImage', box='2,3,14,15;30,31,42,43' ) 00098 00099 # Select the same two box regions but only channels 4 and 5 00100 imstat( 'myImage', box='2,3,14,15;30,31,42,43', chan='4~5' ) 00101 00102 # Select all channels greater the 20 as well as channel 0. 00103 # Then the mean and standard deviation are printed 00104 results = imstat( 'myImage', chans='>20;0' ) 00105 print "Mean is: ", results['mean'], " s.d. ", results['sigma'] 00106 00107 # Find statistical information for the Q stokes value only 00108 # then the I stokes values only, and printing out the statistical 00109 # values that we are interested in. 00110 s1 = imstat( 'myimage', stokes='Q' ) 00111 s2 = imstat( 'myimage', stokes='I' ) 00112 print " | MIN | MAX | MEAN" 00113 print " Q | ",s1['min'][0]," | ",s1['max'][0]," | ",," | ",s1['mean'][0] 00114 print " I | ",s2['min'][0]," | ",s2['max'][0]," | ",," | ",s2['mean'][0] 00115 00116 # evaluate statistics for each spectral plane in an ra x dec x frequency image 00117 ia.fromshape("", [20,30,40]) 00118 # give pixels non-zero values 00119 ia.addnoise() 00120 # These are the display axes, the calculation of statistics occurs 00121 # for each (hyper)plane along axes not listed in the axes parameter, 00122 # in this case axis 2 (the frequency axis) 00123 # display the rms for each frequency plane (your mileage will vary with 00124 # the values). 00125 stats = ia.statistics(axes=[0,1]) 00126 stats["rms"] 00127 Out[10]: 00128 array([ 0.99576014, 1.03813124, 0.97749186, 0.97587883, 1.04189885, 00129 1.03784776, 1.03371549, 1.03153074, 1.00841606, 0.947155 , 00130 0.97335404, 0.94389403, 1.0010221 , 0.97151822, 1.03942156, 00131 1.01158476, 0.96957082, 1.04212773, 1.00589049, 0.98696715, 00132 1.00451481, 1.02307892, 1.03102005, 0.97334671, 0.95209879, 00133 1.02088714, 0.96999902, 0.98661619, 1.01039267, 0.96842754, 00134 0.99464947, 1.01536798, 1.02466023, 0.96956468, 0.98090756, 00135 0.9835844 , 0.95698935, 1.05487967, 0.99846411, 0.99634868]) 00136 00137 00138 00139 """ 00140 00141 # 00142 # The following is work around to avoid a bug with current python translation 00143 # 00144 mytmp = {} 00145 00146 mytmp['imagename'] = imagename 00147 mytmp['axes'] = axes 00148 mytmp['region'] = region 00149 mytmp['box'] = box 00150 mytmp['chans'] = chans 00151 mytmp['stokes'] = stokes 00152 mytmp['listit'] = listit 00153 mytmp['verbose'] = verbose 00154 mytmp['mask'] = mask 00155 mytmp['stretch'] = stretch 00156 mytmp['logfile'] = logfile 00157 mytmp['append'] = append 00158 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00159 trec = casac.utils().torecord(pathname+'imstat.xml') 00160 00161 casalog.origin('imstat') 00162 if trec.has_key('imstat') and casac.utils().verify(mytmp, trec['imstat']) : 00163 result = task_imstat.imstat(imagename, axes, region, box, chans, stokes, listit, verbose, mask, stretch, logfile, append) 00164 00165 else : 00166 result = False 00167 return result