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_viewer import viewer 00016 from task_viewer import casalog 00017 00018 class viewer_pg_: 00019 __name__ = "viewer" 00020 00021 def __init__(self) : 00022 self.__bases__ = (viewer_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, infile=None, displaytype=None, channel=None, zoom=None, outfile=None, outscale=None, outdpi=None, outformat=None, outlandscape=None, gui=None, async=None): 00027 00028 """View an image or visibility data set 00029 00030 examples of usage: 00031 00032 viewer 00033 viewer "myimage.im" 00034 viewer "mymeasurementset.ms" 00035 viewer "myrestorefile.rstr" 00036 00037 viewer "myimage.im", "contour" 00038 00039 viewer "'myimage1.im' - 2 * 'myimage2.im'", "lel" 00040 00041 00042 Keyword arguments: 00043 infile -- Name of file to visualize 00044 default: '' 00045 example: infile='ngc5921.image' 00046 If no infile is specified the Load Data window 00047 will appear for selecting data. 00048 displaytype -- (optional): method of rendering data 00049 visually (raster, contour, vector or marker). 00050 You can also set this parameter to 'lel' and 00051 provide an lel expression for infile (advanced). 00052 default: 'raster' 00053 example: displaytype='contour' 00054 00055 Note: the filetype parameter is optional; typing of 00056 data files is now inferred: 00057 example: viewer infile='my.im' 00058 obsolete: viewer infile='my.im', filetype='raster' 00059 the filetype is still used to load contours, etc. 00060 00061 00062 """ 00063 a=inspect.stack() 00064 stacklevel=0 00065 for k in range(len(a)): 00066 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00067 stacklevel=k 00068 break 00069 myf=sys._getframe(stacklevel).f_globals 00070 myf['__last_task'] = 'viewer' 00071 myf['taskname'] = 'viewer' 00072 ### 00073 myf['update_params'](func=myf['taskname'],printtext=False) 00074 ### 00075 ### 00076 #Handle globals or user over-ride of arguments 00077 # 00078 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00079 useLocalDefaults = False 00080 00081 for item in function_signature_defaults.iteritems(): 00082 key,val = item 00083 keyVal = eval(key) 00084 if (keyVal == None): 00085 #user hasn't set it - use global/default 00086 pass 00087 else: 00088 #user has set it - use over-ride 00089 if (key != 'self') : 00090 useLocalDefaults = True 00091 #myf[key]=keyVal 00092 00093 myparams = {} 00094 if useLocalDefaults : 00095 for item in function_signature_defaults.iteritems(): 00096 key,val = item 00097 keyVal = eval(key) 00098 exec('myparams[key] = keyVal') 00099 if (keyVal == None): 00100 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00101 keyVal = eval(key) 00102 if(type(keyVal) == dict) : 00103 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00104 00105 else : 00106 uselessvariable = None 00107 myparams['infile'] = infile = myf['infile'] 00108 myparams['displaytype'] = displaytype = myf['displaytype'] 00109 myparams['channel'] = channel = myf['channel'] 00110 myparams['zoom'] = zoom = myf['zoom'] 00111 myparams['outfile'] = outfile = myf['outfile'] 00112 myparams['outscale'] = outscale = myf['outscale'] 00113 myparams['outdpi'] = outdpi = myf['outdpi'] 00114 myparams['outformat'] = outformat = myf['outformat'] 00115 myparams['outlandscape'] = outlandscape = myf['outlandscape'] 00116 myparams['gui'] = gui = myf['gui'] 00117 00118 00119 result = None 00120 00121 # 00122 # The following is work around to avoid a bug with current python translation 00123 # 00124 mytmp = {} 00125 00126 mytmp['infile'] = infile 00127 mytmp['displaytype'] = displaytype 00128 mytmp['channel'] = channel 00129 mytmp['zoom'] = zoom 00130 mytmp['outfile'] = outfile 00131 mytmp['outscale'] = outscale 00132 mytmp['outdpi'] = outdpi 00133 mytmp['outformat'] = outformat 00134 mytmp['outlandscape'] = outlandscape 00135 mytmp['gui'] = gui 00136 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00137 trec = casac.utils().torecord(pathname+'viewer.xml') 00138 00139 casalog.origin('viewer') 00140 if not trec.has_key('viewer') or not casac.utils().verify(mytmp, trec['viewer']) : 00141 return False 00142 00143 00144 try : 00145 casalog.post('') 00146 casalog.post('##########################################') 00147 casalog.post('##### Begin Task: viewer #####') 00148 casalog.post('') 00149 result = viewer(infile, displaytype, channel, zoom, outfile, outscale, outdpi, outformat, outlandscape, gui) 00150 casalog.post('') 00151 casalog.post('##### End Task: viewer #####') 00152 casalog.post('##########################################') 00153 00154 00155 # saveinputs for individule engine has no use 00156 # saveinputs should alos be removed from casa_in_py.py 00157 # 00158 # 00159 # saveinputs = myf['saveinputs'] 00160 # saveinputs('viewer', 'viewer.last', myparams) 00161 # 00162 # 00163 except Exception, instance: 00164 #print '**** Error **** ',instance 00165 pass 00166 00167 gc.collect() 00168 return result 00169 # 00170 # 00171 ## 00172 # def paramgui(self, useGlobals=True): 00173 # """ 00174 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00175 # """ 00176 # import paramgui 00177 # 00178 # a=inspect.stack() 00179 # stacklevel=0 00180 # for k in range(len(a)): 00181 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00182 # stacklevel=k 00183 # break 00184 # myf = sys._getframe(stacklevel).f_globals 00185 # 00186 # if useGlobals: 00187 # paramgui.setGlobals(myf) 00188 # else: 00189 # paramgui.setGlobals({}) 00190 # 00191 # paramgui.runTask('viewer', myf['_ip']) 00192 # paramgui.setGlobals({}) 00193 # 00194 # 00195 # 00196 # 00197 def defaults(self, param=None): 00198 a=inspect.stack() 00199 stacklevel=0 00200 for k in range(len(a)): 00201 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00202 stacklevel=k 00203 break 00204 myf=sys._getframe(stacklevel).f_globals 00205 a = odict() 00206 a['infile'] = '' 00207 a['displaytype'] = 'raster' 00208 a['channel'] = 0 00209 a['zoom'] = 1 00210 a['outfile'] = '' 00211 a['outscale'] = 1.0 00212 a['outdpi'] = 300 00213 a['outformat'] = 'jpg' 00214 a['outlandscape'] = False 00215 a['gui'] = True 00216 00217 a['async']=False 00218 00219 ### This function sets the default values but also will return the list of 00220 ### parameters or the default value of a given parameter 00221 if(param == None): 00222 myf['__set_default_parameters'](a) 00223 elif(param == 'paramkeys'): 00224 return a.keys() 00225 else: 00226 if(a.has_key(param)): 00227 #if(type(a[param]) == dict) : 00228 # return a[param][len(a[param])-1]['value'] 00229 #else : 00230 return a[param] 00231 00232 00233 # 00234 # 00235 def check_params(self, param=None, value=None): 00236 a=inspect.stack() 00237 stacklevel=0 00238 for k in range(len(a)): 00239 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00240 stacklevel=k 00241 break 00242 myf=sys._getframe(stacklevel).f_globals 00243 00244 # print 'param:', param, 'value:', value 00245 try : 00246 if str(type(value)) != "<type 'instance'>" : 00247 value0 = value 00248 value = myf['cu'].expandparam(param, value) 00249 matchtype = False 00250 if(type(value) == numpy.ndarray): 00251 if(type(value) == type(value0)): 00252 myf[param] = value.tolist() 00253 else: 00254 #print 'value:', value, 'value0:', value0 00255 #print 'type(value):', type(value), 'type(value0):', type(value0) 00256 myf[param] = value0 00257 if type(value0) != list : 00258 matchtype = True 00259 else : 00260 myf[param] = value 00261 value = myf['cu'].verifyparam({param:value}) 00262 if matchtype: 00263 value = False 00264 except Exception, instance: 00265 #ignore the exception and just return it unchecked 00266 myf[param] = value 00267 return value 00268 00269 # 00270 # 00271 def description(self, key='viewer', subkey=None): 00272 desc={'viewer': 'View an image or visibility data set', 00273 'infile': ' (Optional) Name of file to visualize.', 00274 'displaytype': ' (Optional) Type of visual rendering (raster, contour, vector or marker). lel if an lel expression is given for infile (advanced).', 00275 'channel': ' (Optional) access a specific channel in the image cube', 00276 'zoom': ' (Optional) zoom in/out by increments', 00277 'outfile': ' (Optional) name of the output file to generate', 00278 'outscale': ' (Optional) amount to scale output bitmap formats (non-PS, non-PDF)', 00279 'outdpi': ' (Optional) output DPI for PS/PDF', 00280 'outformat': ' (Optional) format of the output e.g. jpg or pdf (this is overridden by the output files extension', 00281 'outlandscape': ' (Optional) should the output mode be landscape (PS or PDF)', 00282 'gui': ' (Optional) Display the panel in a GUI.', 00283 00284 'async': 'If true the taskname must be started using viewer(...)' 00285 } 00286 00287 # 00288 # Set subfields defaults if needed 00289 # 00290 00291 if(desc.has_key(key)) : 00292 return desc[key] 00293 00294 def itsdefault(self, paramname) : 00295 a = {} 00296 a['infile'] = '' 00297 a['displaytype'] = 'raster' 00298 a['channel'] = 0 00299 a['zoom'] = 1 00300 a['outfile'] = '' 00301 a['outscale'] = 1.0 00302 a['outdpi'] = 300 00303 a['outformat'] = 'jpg' 00304 a['outlandscape'] = False 00305 a['gui'] = True 00306 00307 if a.has_key(paramname) : 00308 return a[paramname] 00309 viewer_pg = viewer_pg_()