casa
$Rev:20696$
|
00001 # 00002 # This file was generated using xslt from its XML file 00003 # 00004 # Copyright 2008, Associated Universities Inc., Washington DC 00005 # 00006 import sys 00007 import os 00008 from casac import * 00009 import string 00010 import time 00011 import inspect 00012 import gc 00013 import numpy 00014 from odict import odict 00015 from task_feather import feather 00016 from task_feather import casalog 00017 00018 class feather_pg_: 00019 __name__ = "feather" 00020 00021 def __init__(self) : 00022 self.__bases__ = (feather_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, imagename=None, highres=None, lowres=None, sdfactor=None, effdishdiam=None, showplot=None, async=None): 00027 00028 """Combine two images using their Fourier transforms 00029 00030 Feathering is a simple method for combining two images with different 00031 spatial resolution. The processing steps are: 00032 00033 1. Regrid the low-resolution image to a temporary copy matching the 00034 resolution of the high-resolution image, 00035 2. Transform each image to the spatial-frequency plane (gridded). 00036 3. Scale the low-resolution image (uv-grid) by the ratio of the 00037 volumes of the two 'clean beams' (high-res/low-res). 00038 4. Add to this, the uv-grid of the high-resolution image, scaled by 00039 (1-wt) where 'wt' is the Fourier transform of the 'clean beam' 00040 defined in the low-resolution image. 00041 5. Transform back to the image plane. 00042 00043 Both input images must have a well-defined beam shape for this task to work. 00044 This could be a 'clean beam' for interferometric images, and a 'primary-beam' 00045 for a single-dish image. 00046 00047 The two images must also have the same flux density normalization scale. 00048 00049 Keyword arguments: 00050 imagename -- Name of output feathered image 00051 default: none; example: imagename='orion_combined.im' 00052 highres -- Name of high resolution (interferometer) image 00053 default: none; example: highres='orion_vla.im' 00054 This image is often a clean image obtained from synthesis 00055 observations. 00056 lowres -- Name of low resolution (single dish) image 00057 default: none; example: lowres='orion_gbt.im' 00058 This image is often a image from a single-dish observations 00059 or a clean image obtained from lower resolution synthesis 00060 observations. 00061 sdfactor -- value by which to scale the Single Dish image. Default is 1.0 00062 Basically modifying the flux scale of the SD image 00063 effdishdiam -- New effective SingleDish diameter to use in m. Obviously one can only reduce the dish effective dish diameter in feathering. Default -1.0 means leave as is. 00064 showplot -- If True will plot the cuts across the feathring function 00065 00066 00067 Comments: 00068 00069 This task can be used as one method of combining single-dish and 00070 interferometric images after they have been separately made. 00071 00072 The clean task allows another method of combining single-dish and 00073 interferometric data. The single-dish image can be used as a starting 00074 model for the interferometric image-reconstruction. If there is 00075 some overlap between the spatial-frequencies contained in the 00076 single-dish image and the interferometer sampling function, then, 00077 such a starting model will help constrain the solutions on the 00078 short-baselines of the interferometric data. 00079 00080 00081 00082 """ 00083 a=inspect.stack() 00084 stacklevel=0 00085 for k in range(len(a)): 00086 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00087 stacklevel=k 00088 break 00089 myf=sys._getframe(stacklevel).f_globals 00090 myf['__last_task'] = 'feather' 00091 myf['taskname'] = 'feather' 00092 ### 00093 myf['update_params'](func=myf['taskname'],printtext=False) 00094 ### 00095 ### 00096 #Handle globals or user over-ride of arguments 00097 # 00098 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00099 useLocalDefaults = False 00100 00101 for item in function_signature_defaults.iteritems(): 00102 key,val = item 00103 keyVal = eval(key) 00104 if (keyVal == None): 00105 #user hasn't set it - use global/default 00106 pass 00107 else: 00108 #user has set it - use over-ride 00109 if (key != 'self') : 00110 useLocalDefaults = True 00111 #myf[key]=keyVal 00112 00113 myparams = {} 00114 if useLocalDefaults : 00115 for item in function_signature_defaults.iteritems(): 00116 key,val = item 00117 keyVal = eval(key) 00118 exec('myparams[key] = keyVal') 00119 if (keyVal == None): 00120 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00121 keyVal = eval(key) 00122 if(type(keyVal) == dict) : 00123 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00124 00125 else : 00126 uselessvariable = None 00127 myparams['imagename'] = imagename = myf['imagename'] 00128 myparams['highres'] = highres = myf['highres'] 00129 myparams['lowres'] = lowres = myf['lowres'] 00130 myparams['sdfactor'] = sdfactor = myf['sdfactor'] 00131 myparams['effdishdiam'] = effdishdiam = myf['effdishdiam'] 00132 myparams['showplot'] = showplot = myf['showplot'] 00133 00134 00135 result = None 00136 00137 # 00138 # The following is work around to avoid a bug with current python translation 00139 # 00140 mytmp = {} 00141 00142 mytmp['imagename'] = imagename 00143 mytmp['highres'] = highres 00144 mytmp['lowres'] = lowres 00145 mytmp['sdfactor'] = sdfactor 00146 mytmp['effdishdiam'] = effdishdiam 00147 mytmp['showplot'] = showplot 00148 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00149 trec = casac.utils().torecord(pathname+'feather.xml') 00150 00151 casalog.origin('feather') 00152 if not trec.has_key('feather') or not casac.utils().verify(mytmp, trec['feather']) : 00153 return False 00154 00155 00156 try : 00157 casalog.post('') 00158 casalog.post('##########################################') 00159 casalog.post('##### Begin Task: feather #####') 00160 casalog.post('') 00161 result = feather(imagename, highres, lowres, sdfactor, effdishdiam, showplot) 00162 casalog.post('') 00163 casalog.post('##### End Task: feather #####') 00164 casalog.post('##########################################') 00165 00166 00167 # saveinputs for individule engine has no use 00168 # saveinputs should alos be removed from casa_in_py.py 00169 # 00170 # 00171 # saveinputs = myf['saveinputs'] 00172 # saveinputs('feather', 'feather.last', myparams) 00173 # 00174 # 00175 except Exception, instance: 00176 #print '**** Error **** ',instance 00177 pass 00178 00179 gc.collect() 00180 return result 00181 # 00182 # 00183 ## 00184 # def paramgui(self, useGlobals=True): 00185 # """ 00186 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00187 # """ 00188 # import paramgui 00189 # 00190 # a=inspect.stack() 00191 # stacklevel=0 00192 # for k in range(len(a)): 00193 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00194 # stacklevel=k 00195 # break 00196 # myf = sys._getframe(stacklevel).f_globals 00197 # 00198 # if useGlobals: 00199 # paramgui.setGlobals(myf) 00200 # else: 00201 # paramgui.setGlobals({}) 00202 # 00203 # paramgui.runTask('feather', myf['_ip']) 00204 # paramgui.setGlobals({}) 00205 # 00206 # 00207 # 00208 # 00209 def defaults(self, param=None): 00210 a=inspect.stack() 00211 stacklevel=0 00212 for k in range(len(a)): 00213 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00214 stacklevel=k 00215 break 00216 myf=sys._getframe(stacklevel).f_globals 00217 a = odict() 00218 a['imagename'] = '' 00219 a['highres'] = '' 00220 a['lowres'] = '' 00221 a['sdfactor'] = 1.0 00222 a['effdishdiam'] = -1.0 00223 a['showplot'] = False 00224 00225 a['async']=False 00226 00227 ### This function sets the default values but also will return the list of 00228 ### parameters or the default value of a given parameter 00229 if(param == None): 00230 myf['__set_default_parameters'](a) 00231 elif(param == 'paramkeys'): 00232 return a.keys() 00233 else: 00234 if(a.has_key(param)): 00235 #if(type(a[param]) == dict) : 00236 # return a[param][len(a[param])-1]['value'] 00237 #else : 00238 return a[param] 00239 00240 00241 # 00242 # 00243 def check_params(self, param=None, value=None): 00244 a=inspect.stack() 00245 stacklevel=0 00246 for k in range(len(a)): 00247 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00248 stacklevel=k 00249 break 00250 myf=sys._getframe(stacklevel).f_globals 00251 00252 # print 'param:', param, 'value:', value 00253 try : 00254 if str(type(value)) != "<type 'instance'>" : 00255 value0 = value 00256 value = myf['cu'].expandparam(param, value) 00257 matchtype = False 00258 if(type(value) == numpy.ndarray): 00259 if(type(value) == type(value0)): 00260 myf[param] = value.tolist() 00261 else: 00262 #print 'value:', value, 'value0:', value0 00263 #print 'type(value):', type(value), 'type(value0):', type(value0) 00264 myf[param] = value0 00265 if type(value0) != list : 00266 matchtype = True 00267 else : 00268 myf[param] = value 00269 value = myf['cu'].verifyparam({param:value}) 00270 if matchtype: 00271 value = False 00272 except Exception, instance: 00273 #ignore the exception and just return it unchecked 00274 myf[param] = value 00275 return value 00276 00277 # 00278 # 00279 def description(self, key='feather', subkey=None): 00280 desc={'feather': 'Combine two images using their Fourier transforms', 00281 'imagename': 'Name of output feathered image', 00282 'highres': 'Name of high resolution (interferometer) image', 00283 'lowres': 'Name of low resolution (single dish) image', 00284 'sdfactor': 'Scale factor to apply to Single Dish image', 00285 'effdishdiam': 'New effective SingleDish diameter to use in m ', 00286 'showplot': 'Show plot of feather function', 00287 00288 'async': 'If true the taskname must be started using feather(...)' 00289 } 00290 00291 if(desc.has_key(key)) : 00292 return desc[key] 00293 00294 def itsdefault(self, paramname) : 00295 a = {} 00296 a['imagename'] = '' 00297 a['highres'] = '' 00298 a['lowres'] = '' 00299 a['sdfactor'] = 1.0 00300 a['effdishdiam'] = -1.0 00301 a['showplot'] = False 00302 00303 if a.has_key(paramname) : 00304 return a[paramname] 00305 feather_pg = feather_pg_()