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_imsmooth 00013 def imsmooth(imagename='', kernel='gauss', major='2.0arcsec', minor='2.0arcsec', pa='0deg', targetres=False, region='', box='', chans='', stokes='', mask='', outfile='', stretch=False, overwrite=False, beam=''): 00014 00015 """Smooth an image or portion of an image 00016 This task performs a Fourier-based convolution to 'smooth' the 00017 image. Smoothing is typically performed in order to reduce the noise in 00018 an image. 00019 00020 Keyword arguments: 00021 imagename -- Input image name 00022 Default: none; Example: imagename='ngc5921_task.im' 00023 outfile -- Output smoothed image file name 00024 default: 'imsmooth_results.im'; 00025 example: outfile='my.image.smooth'; 00026 kernel -- Type of kernel to use when smoothing (gaussian or boxcar). 00027 default: 'gauss'; example: kernel='gauss' 00028 options: 'gauss' or 'boxcar' 00029 major -- Depends on the kernel type, see explanation below. 00030 minor -- Depends on the kernel type, see explanation below. 00031 pa -- position angle to use for gaussian kernel, unused for boxcar. 00032 beam -- When kernel="gauss", this parameter can be used instead of major, 00033 minor, and pa to specify the gaussian parameters. See details below. 00034 targetres -- Used only for gaussian kernels. If True, major, minor, and 00035 pa, or beam, are the resolution of the output image. If false, a gaussian 00036 with these parameters is convolved with the input image to produce 00037 the output image. 00038 mask -- Mask to use. See help par.mask. Default is none. 00039 region -- region file or name. 00040 Use the viewer, then region manager to select regions of 00041 the image to process. Similar to box, but graphical 00042 Or the name of a region stored with the image, 00043 use rg.namesintable() 00044 to retrieve the list of names. 00045 Default: none 00046 Example: region='myimage.im.rgn' 00047 region='region1' 00048 box -- A box region on the directional plane 00049 ONLY pixel values acceptable at this time. 00050 Default: none (whole 2-D plane); Example: box='10,10,50,50' 00051 chans -- channel numbers to select for the continuum, 00052 ONLY channel numbers accepted at this time. 00053 Default: none (all); 00054 Example: chans='3~6;>40' 00055 stokes -- Stokes parameters to image 00056 Example: 'I' 00057 Default: none (all); 00058 Options: 'I','Q','U','V','RR','RL','LR','LL','XX','YX','XY','YY', ... 00059 00060 Kernel Parameters 00061 ----------------- 00062 Finally, and most importantly the kernel is specified via the 00063 major and minor parameters. 00064 00065 Gaussian kernel: major and minor are the full width at half maximum 00066 (FWHM) of the Gaussian. pa is the position angle 00067 of the gaussian. In addition, the targetres parameter 00068 indicates if the specified gaussian is to be the 00069 resolution of the final image (True) or if it is to 00070 be used to convolve the input image to create the 00071 output image. If True, the input image must have 00072 a restoring beam in its header. 00073 If the image has multiple beams and targetres=True, 00074 all planes in the image will be convolved so that the 00075 resulting resolution is that specified by the beam parameter. 00076 If the image has multiple beams and targetres=False, each plane 00077 will be convolved with a Gaussian specified by beam (and hence, in 00078 general, the output image will also have multiple beams that vary 00079 with spectral channel and/or polarization). 00080 Boxcar kernel: major, length of the box along the y-axis and 00081 minor, length of the box along the x-axis 00082 00083 The major, minor, and pa parameters can be specified in one of three ways 00084 Quantity -- for example major=qa.quantity(1, 'arcsec') 00085 Note that you can use pixel units, such as 00086 major=qa.quantity(1, 'pix') 00087 String -- for example minor='1pix' or major='0.5km' 00088 (i.e. a string that the Quanta quantity function accepts). 00089 Numeric -- for example major=10. 00090 In this case, the units of major and minor are assumed to 00091 be in arcsec and units of pa are assumed to be degrees. 00092 00093 In the case of a Gaussian, the beam parameter offers an alternate way of 00094 describing the convolving Gaussian. If used, neither major, minor, 00095 nor pa can be specified. The beam parameter must have exactly three 00096 fields: "major", "minor", and "pa" (or "positionangle"). This is, not coincidentally, 00097 the record format for the output of ia.restoringbeam(). For example 00098 00099 beam = {"major": "5arcsec", "minor": "2arcsec", "pa": "20deg"} 00100 00101 If both beam and any of major, minor, and/or pa is specified for a Gaussian kernel, 00102 an exception will be thrown. 00103 00104 Note: Using pixel units allows you to convolve axes with different units. 00105 00106 # EXAMPLE 1 00107 # smoothing with a gaussian kernel 20arseconds by 10 arseconds 00108 imsmooth( imagename='my.image', kernel='gauss', major='10arcsec', minor='10arcsec') 00109 00110 # EXAMPLE 2 00111 # Smoothing using pixel coordinates and a boxcar kernel. 00112 imsmooth( imagename='new.image', major='20pix', minor='10pix', kernel='boxcar') 00113 00114 00115 """ 00116 00117 # 00118 # The following is work around to avoid a bug with current python translation 00119 # 00120 mytmp = {} 00121 00122 mytmp['imagename'] = imagename 00123 mytmp['kernel'] = kernel 00124 mytmp['major'] = major 00125 mytmp['minor'] = minor 00126 mytmp['pa'] = pa 00127 mytmp['targetres'] = targetres 00128 mytmp['region'] = region 00129 mytmp['box'] = box 00130 mytmp['chans'] = chans 00131 mytmp['stokes'] = stokes 00132 mytmp['mask'] = mask 00133 mytmp['outfile'] = outfile 00134 mytmp['stretch'] = stretch 00135 mytmp['overwrite'] = overwrite 00136 mytmp['beam'] = beam 00137 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00138 trec = casac.utils().torecord(pathname+'imsmooth.xml') 00139 00140 casalog.origin('imsmooth') 00141 if trec.has_key('imsmooth') and casac.utils().verify(mytmp, trec['imsmooth']) : 00142 result = task_imsmooth.imsmooth(imagename, kernel, major, minor, pa, targetres, region, box, chans, stokes, mask, outfile, stretch, overwrite, beam) 00143 00144 else : 00145 result = False 00146 return result