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_imview import imview 00016 from task_imview import casalog 00017 00018 class imview_pg_: 00019 __name__ = "imview" 00020 00021 def __init__(self) : 00022 self.__bases__ = (imview_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, raster=None, contour=None, zoom=None, axes=None, out=None, async=None): 00027 00028 """View an image 00029 The imview task provides access to a subset of all of the configuration 00030 options for loading and configuring the display of images in the casaviewer. 00031 This interface will evolve and eventually provide access to nearly all of 00032 the image options available in the casaviewer. 00033 00034 To simply create a casaviewer to set up interactively, you can use: 00035 00036 imview 00037 00038 To open a particular image: 00039 00040 imview "ngc5921.clean.image" 00041 00042 to open an image and overlay a contour: 00043 00044 imview "ngc5921.clean.image", "ngc5921.clean.image" 00045 00046 or equivalently: 00047 00048 imview( raster="ngc5921.clean.image", contour="ngc5921.clean.image" ) 00049 00050 to output an image: 00051 00052 imview( raster="ngc5921.clean.image", out="ngc5921-01.png" ) 00053 00054 00055 There are five optional parameters for imview -- raster, contour, zoom, 00056 axes, and out. Each of these parameters can take a few different forms and 00057 are treated as python dictionaries: 00058 00059 raster -- (string) image file to open 00060 (dict) file (string) => image file to open 00061 scaling (float) => scaling power cycles 00062 range (float*2) => data range 00063 colormap (string) => name of colormap 00064 colorwedge (bool) => show color wedge? 00065 contour -- (string) file to load as a contour 00066 (dict) file (string) => file to load 00067 levels (float*N) => relative levels 00068 base (numeric) => zero in relative levels 00069 unit (numeric) => one in the relative levels 00070 zoom -- (int) integral zoom level 00071 (string) region file to load as the zoom region 00072 (dict) blc (numeric*2) => bottom left corner 00073 trc (numeric*2) => top right corner 00074 coord (string) => pixel or world 00075 channel (int) => chanel to display 00076 (dict) <region record> => record loaded 00077 e.g. rg.fromfiletorecord( ) 00078 axes -- (string*3) demension to display on the x, y, and z axes 00079 (dict) x => dimension for x-axes 00080 y => dimension for y-axes 00081 z => dimension for z-axes 00082 out -- (string) file with a supported extension 00083 [jpg, pdf, eps, ps, png, xbm, xpm, ppm] 00084 (dict) file (string) => filename 00085 format (string) => valid ext (filename ext overrides) 00086 scale (numeric) => scale for non-eps, non-ps output 00087 dpi (numeric) => dpi for eps or ps output 00088 orient (string) => portrait or landscape 00089 00090 Examples: 00091 00092 1) A subset (zoom) of a raster image. Note the notation of curly brackets: 00093 00094 imview(raster="ngc5921.clean.image", out="ngc5921-02.png", 00095 zoom={'channel': 10, 'blc': [113,109], 'trc': [141,136]} ) 00096 00097 00098 2) An overlay of a raster image, ngc5921.clean.image, with a 00099 contour map of the same image ngc5921.clean.image. Data ranges 00100 are selected, as well as the colormap and the scaling cycles 00101 of the raster image. Contours are autogenerated and The x-axis 00102 will be Declination. The image is written out to a file named 00103 myout.png in the png format. 00104 00105 imview(raster={'file': 'ngc5921.clean.image', 00106 'range': [-0.01,0.03], 00107 'colormap': 'Hot Metal 2', 00108 'scaling': -1}, 00109 contour={'file': 'ngc5921.clean.image'}, 00110 axes={'x':'Declination'} , 00111 zoom={'channel': 7, 'blc': [75,75], 'trc': [175,175], 00112 'coord': 'pixel'}, 00113 out='myout.png') 00114 00115 3) As example (2) but with an integral zoom level and no output to a file 00116 00117 imview(raster={'file': 'ngc5921.clean.image', 00118 'range': [-0.01,0.03], 00119 'colormap': 'Hot Metal 2'}, 00120 contour={'file': 'ngc5921.clean.image'}, 00121 axes={'x':'Declination'} , 00122 zoom=2) 00123 00124 4) Now, the contour levels are explicitely given, a region file is used 00125 to define the zoom area 00126 00127 imview(raster={'file': 'ngc5921.clean.image', 00128 'range': [-0.01,0.03], 00129 'colormap': 'Hot Metal 2'}, 00130 contour={'file': 'ngc5921.clean.image', 00131 'levels': [-0.2, 0.2, 0.25, 0.3, 0.35, 0.4, 0.6, 0.8] }, 00132 zoom='myregion.rgn') 00133 00134 specifying "zoom={'file': 'myregion.rgn', 'channel': 10}" would result 00135 in the same level of zoom and would display channel number 10 from 00136 the cube. 00137 00138 00139 00140 """ 00141 a=inspect.stack() 00142 stacklevel=0 00143 for k in range(len(a)): 00144 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00145 stacklevel=k 00146 break 00147 myf=sys._getframe(stacklevel).f_globals 00148 myf['__last_task'] = 'imview' 00149 myf['taskname'] = 'imview' 00150 ### 00151 myf['update_params'](func=myf['taskname'],printtext=False) 00152 ### 00153 ### 00154 #Handle globals or user over-ride of arguments 00155 # 00156 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00157 useLocalDefaults = False 00158 00159 for item in function_signature_defaults.iteritems(): 00160 key,val = item 00161 keyVal = eval(key) 00162 if (keyVal == None): 00163 #user hasn't set it - use global/default 00164 pass 00165 else: 00166 #user has set it - use over-ride 00167 if (key != 'self') : 00168 useLocalDefaults = True 00169 #myf[key]=keyVal 00170 00171 myparams = {} 00172 if useLocalDefaults : 00173 for item in function_signature_defaults.iteritems(): 00174 key,val = item 00175 keyVal = eval(key) 00176 exec('myparams[key] = keyVal') 00177 if (keyVal == None): 00178 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00179 keyVal = eval(key) 00180 if(type(keyVal) == dict) : 00181 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00182 00183 else : 00184 uselessvariable = None 00185 myparams['raster'] = raster = myf['raster'] 00186 myparams['contour'] = contour = myf['contour'] 00187 myparams['zoom'] = zoom = myf['zoom'] 00188 myparams['axes'] = axes = myf['axes'] 00189 myparams['out'] = out = myf['out'] 00190 00191 00192 result = None 00193 00194 # 00195 # The following is work around to avoid a bug with current python translation 00196 # 00197 mytmp = {} 00198 00199 mytmp['raster'] = raster 00200 mytmp['contour'] = contour 00201 mytmp['zoom'] = zoom 00202 mytmp['axes'] = axes 00203 mytmp['out'] = out 00204 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00205 trec = casac.utils().torecord(pathname+'imview.xml') 00206 00207 casalog.origin('imview') 00208 if not trec.has_key('imview') or not casac.utils().verify(mytmp, trec['imview']) : 00209 return False 00210 00211 00212 try : 00213 casalog.post('') 00214 casalog.post('##########################################') 00215 casalog.post('##### Begin Task: imview #####') 00216 casalog.post('') 00217 result = imview(raster, contour, zoom, axes, out) 00218 casalog.post('') 00219 casalog.post('##### End Task: imview #####') 00220 casalog.post('##########################################') 00221 00222 00223 # saveinputs for individule engine has no use 00224 # saveinputs should alos be removed from casa_in_py.py 00225 # 00226 # 00227 # saveinputs = myf['saveinputs'] 00228 # saveinputs('imview', 'imview.last', myparams) 00229 # 00230 # 00231 except Exception, instance: 00232 #print '**** Error **** ',instance 00233 pass 00234 00235 gc.collect() 00236 return result 00237 # 00238 # 00239 ## 00240 # def paramgui(self, useGlobals=True): 00241 # """ 00242 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00243 # """ 00244 # import paramgui 00245 # 00246 # a=inspect.stack() 00247 # stacklevel=0 00248 # for k in range(len(a)): 00249 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00250 # stacklevel=k 00251 # break 00252 # myf = sys._getframe(stacklevel).f_globals 00253 # 00254 # if useGlobals: 00255 # paramgui.setGlobals(myf) 00256 # else: 00257 # paramgui.setGlobals({}) 00258 # 00259 # paramgui.runTask('imview', myf['_ip']) 00260 # paramgui.setGlobals({}) 00261 # 00262 # 00263 # 00264 # 00265 def defaults(self, param=None): 00266 a=inspect.stack() 00267 stacklevel=0 00268 for k in range(len(a)): 00269 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00270 stacklevel=k 00271 break 00272 myf=sys._getframe(stacklevel).f_globals 00273 a = odict() 00274 a['raster'] = [] 00275 a['contour'] = [] 00276 a['zoom'] = 1 00277 a['axes'] = [] 00278 a['out'] = '' 00279 00280 a['async']=False 00281 00282 ### This function sets the default values but also will return the list of 00283 ### parameters or the default value of a given parameter 00284 if(param == None): 00285 myf['__set_default_parameters'](a) 00286 elif(param == 'paramkeys'): 00287 return a.keys() 00288 else: 00289 if(a.has_key(param)): 00290 #if(type(a[param]) == dict) : 00291 # return a[param][len(a[param])-1]['value'] 00292 #else : 00293 return a[param] 00294 00295 00296 # 00297 # 00298 def check_params(self, param=None, value=None): 00299 a=inspect.stack() 00300 stacklevel=0 00301 for k in range(len(a)): 00302 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00303 stacklevel=k 00304 break 00305 myf=sys._getframe(stacklevel).f_globals 00306 00307 # print 'param:', param, 'value:', value 00308 try : 00309 if str(type(value)) != "<type 'instance'>" : 00310 value0 = value 00311 value = myf['cu'].expandparam(param, value) 00312 matchtype = False 00313 if(type(value) == numpy.ndarray): 00314 if(type(value) == type(value0)): 00315 myf[param] = value.tolist() 00316 else: 00317 #print 'value:', value, 'value0:', value0 00318 #print 'type(value):', type(value), 'type(value0):', type(value0) 00319 myf[param] = value0 00320 if type(value0) != list : 00321 matchtype = True 00322 else : 00323 myf[param] = value 00324 value = myf['cu'].verifyparam({param:value}) 00325 if matchtype: 00326 value = False 00327 except Exception, instance: 00328 #ignore the exception and just return it unchecked 00329 myf[param] = value 00330 return value 00331 00332 # 00333 # 00334 def description(self, key='imview', subkey=None): 00335 desc={'imview': 'View an image', 00336 'raster': '(Optional) Raster filename (string) or complete raster config dictionary. The allowed dictionary keys are file (string), scaling (numeric), range (2 element numeric vector), colormap (string), and colorwedge (bool).', 00337 'contour': '(Optional) Contour filename (string) or complete contour config dictionary. The allowed dictionary keys are file (string), levels (numeric vector), unit (float), and base (float).', 00338 'zoom': '(Optional) zoom can specify intermental zoom (integer), zoom region read from a file (string) or dictionary specifying the zoom region. The dictionary can have two forms. It can be either a simple region specified with blc (2 element vector) and trc (2 element vector) [along with an optional coord key ("pixel" or "world"; pixel is the default) or a complete region rectangle e.g. loaded with "rg.fromfiletorecord( )". The dictionary can also contain a channel (integer) field which indicates which channel should be displayed.', 00339 'axes': '(Optional) this can either be a three element vector (string) where each element describes what should be found on each of the x, y, and z axes or a dictionary containing fields "x", "y" and "z" (string).', 00340 'out': '(Optional) Output filename or complete output config dictionary. If a string is passed, the file extension is used to determine the output type (jpg, pdf, eps, ps, png, xbm, xpm, or ppm). If a dictionary is passed, it can contain the fields, file (string), scale (float), dpi (int), or orient (landscape or portrait). The scale field is used for the bitmap formats (i.e. not ps or pdf) and the dpi parameter is used for scalable formats (pdf or ps).', 00341 00342 'async': 'If true the taskname must be started using imview(...)' 00343 } 00344 00345 # 00346 # Set subfields defaults if needed 00347 # 00348 00349 if(desc.has_key(key)) : 00350 return desc[key] 00351 00352 def itsdefault(self, paramname) : 00353 a = {} 00354 a['raster'] = [] 00355 a['contour'] = [] 00356 a['zoom'] = 1 00357 a['axes'] = [] 00358 a['out'] = '' 00359 00360 if a.has_key(paramname) : 00361 return a[paramname] 00362 imview_pg = imview_pg_()