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_immoments 00013 def immoments(imagename='', moments=[0], axis='spectral', region='', box='', chans='', stokes='', mask='', includepix=-1, excludepix=-1, outfile='', stretch=False): 00014 00015 """Compute moments from an image 00016 The spectral moment distributions at each pixel are 00017 determined. See the cookbook and User Reference Manual for 00018 mathematical details. 00019 00020 The main control of the calculation is given by parameter 00021 moments: 00022 00023 moments=-1 - mean value of the spectrum 00024 moments=0 - integrated value of the spectrum 00025 moments=1 - intensity weighted coordinate;traditionally used to get 00026 'velocity fields' 00027 moments=2 - intensity weighted dispersion of the coordinate; traditionally 00028 used to get "velocity dispersion" 00029 moments=3 - median of I 00030 moments=4 - median coordinate 00031 moments=5 - standard deviation about the mean of the spectrum 00032 moments=6 - root mean square of the spectrum 00033 moments=7 - absolute mean deviation of the spectrum 00034 moments=8 - maximum value of the spectrum 00035 moments=9 - coordinate of the maximum value of the spectrum 00036 moments=10 - minimum value of the spectrum 00037 moments=11 - coordinate of the minimum value of the spectrum 00038 00039 Keyword arguments: 00040 imagename Name of input image 00041 default: none; example: imagename="ngc5921_task.image" 00042 moments List of moments you would like to compute 00043 default: 0 (integrated spectrum);example: moments=[0,1] 00044 see list above 00045 axis The moment axis 00046 default: (spectral axis); example: axis=spec 00047 options: ra, dec, lattitude, longitude, spectral, stokes 00048 mask Mask to use. See help par.mask. Default is none. 00049 stretch Stretch the input mask if necessary and possible. See below. 00050 region Region specification. See help par.region. Default is to not use a region. 00051 box A box region on the directional plane 00052 Only pixel values acceptable. 00053 Default: none (whole 2-D plane); 00054 Example: box="10,10,50,50" 00055 box = "10,10,30,30,35,35,50,50" (two boxes) 00056 chans channel numbers 00057 Range of channel numbers to include in statistics 00058 All spectral windows are included 00059 Default:""= all; Example: chans="3~20" 00060 stokes Stokes parameters to analyze. 00061 Default: none (all); Example: stokes="IQUV"; 00062 Example:stokes="I,Q" 00063 Options: "I","Q","U","V","RR","RL","LR","LL","XX","YX","XY","YY", ... 00064 includepix Range of pixel values to include 00065 default: [-1] (all pixels); example=[0.02,100.0] 00066 excludepix Range of pixel values to exclude 00067 default: [-1] (don"t exclude pixels); example=[100.,200.] 00068 outfile Output image file name (or root for multiple moments) 00069 default: "" (input+auto-determined suffix);example: outfile="source_moment" 00070 00071 If stretch is true and if the number of mask dimensions is less than 00072 or equal to the number of image dimensions and some axes in the 00073 mask are degenerate while the corresponding axes in the image are not, 00074 the mask will be stetched in the degenerate axis dimensions. For example, 00075 if the input image has shape [100, 200, 10] and the input 00076 mask has shape [100, 200, 1] and stretch is true, the mask will be 00077 stretched along the third dimension to shape [100, 200, 10]. However if 00078 the mask is shape [100, 200, 2], stretching is not possible and an 00079 error will result. 00080 00081 Example for finding the 1-momment, intensity-weighted 00082 coordinate, often used for finding velocity fields. 00083 immoments( axis="spec", imagename="myimage", moment=1, outfile="velocityfields" ) 00084 00085 Example finding the spectral mean, -1 moment, on a specified region 00086 of the image as defined by the box and stokes parameters 00087 taskname="immoments" 00088 default() 00089 imagename = "myimage" 00090 moment = -1 00091 00092 axis = "spec" 00093 stoke = "I" 00094 box = [55,12,97,32] 00095 go 00096 00097 Example using a mask created with a second file to select the 00098 data used to calculate the 0-moments, integrated values. In 00099 this case the mask is from the calibrated.im file and all values 00100 that have a value greater than 0.5 will be positive in the mask.. 00101 immoments( "clean.image", axis="spec", mask="calibrated.im>0.5", outfile="mom_withmask.im" ) 00102 00103 If an image has multiple (per-channel beams) and the moment axis is equal to the 00104 spectral axis, each channel will be convolved with a beam that is equal to the beam 00105 having the largest area in the beamset prior to moment determination. 00106 00107 00108 00109 """ 00110 if type(moments)==int: moments=[moments] 00111 00112 # 00113 # The following is work around to avoid a bug with current python translation 00114 # 00115 mytmp = {} 00116 00117 mytmp['imagename'] = imagename 00118 mytmp['moments'] = moments 00119 mytmp['axis'] = axis 00120 mytmp['region'] = region 00121 mytmp['box'] = box 00122 mytmp['chans'] = chans 00123 mytmp['stokes'] = stokes 00124 mytmp['mask'] = mask 00125 mytmp['includepix'] = includepix 00126 mytmp['excludepix'] = excludepix 00127 mytmp['outfile'] = outfile 00128 mytmp['stretch'] = stretch 00129 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00130 trec = casac.utils().torecord(pathname+'immoments.xml') 00131 00132 casalog.origin('immoments') 00133 if trec.has_key('immoments') and casac.utils().verify(mytmp, trec['immoments']) : 00134 result = task_immoments.immoments(imagename, moments, axis, region, box, chans, stokes, mask, includepix, excludepix, outfile, stretch) 00135 00136 else : 00137 result = False 00138 return result