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_exportfits import exportfits 00016 from task_exportfits import casalog 00017 00018 class exportfits_pg_: 00019 __name__ = "exportfits" 00020 00021 def __init__(self) : 00022 self.__bases__ = (exportfits_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, imagename=None, fitsimage=None, velocity=None, optical=None, bitpix=None, minpix=None, maxpix=None, overwrite=None, dropstokes=None, stokeslast=None, async=None): 00027 00028 """Convert a CASA image to a FITS file 00029 00030 CASA-produced images can be written to disk for transporting 00031 to other software packages. No subimaging of the fits image 00032 can be made with this task. 00033 00034 Keyword arguments: 00035 imagename -- Name of input CASA image 00036 default: none; example: imagename='3C273XC1.image' 00037 fitsimage -- Name of ouput image FITS file 00038 default: none; example='3C273XC1.fits' 00039 velocity -- Use velocity (rather than frequency) as spectral axis 00040 default: False 00041 optical -- Use the optical (rather than radio) velocity convention 00042 default: False; 00043 bitpix -- Bits per pixel 00044 default: -32 (floating point) 00045 <Options: -32 (floating point), 16 (integer)> 00046 minpix -- Minimum pixel value 00047 default: 0 = autoscale 00048 maxpix -- Maximum pixel value 00049 default: 0 = autoscale 00050 overwrite -- Overwrite pre-existing imagename 00051 default=False; example: overwrite=True 00052 dropstokes -- Drop Stokes axis? 00053 default: False; example: dropstokes=True 00054 stokeslast -- Put Stokes axis last in header? 00055 default: True; example: stokeslast=False 00056 async -- Run asynchronously 00057 default = False; 00058 00059 """ 00060 a=inspect.stack() 00061 stacklevel=0 00062 for k in range(len(a)): 00063 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00064 stacklevel=k 00065 break 00066 myf=sys._getframe(stacklevel).f_globals 00067 myf['__last_task'] = 'exportfits' 00068 myf['taskname'] = 'exportfits' 00069 ### 00070 myf['update_params'](func=myf['taskname'],printtext=False) 00071 ### 00072 ### 00073 #Handle globals or user over-ride of arguments 00074 # 00075 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00076 useLocalDefaults = False 00077 00078 for item in function_signature_defaults.iteritems(): 00079 key,val = item 00080 keyVal = eval(key) 00081 if (keyVal == None): 00082 #user hasn't set it - use global/default 00083 pass 00084 else: 00085 #user has set it - use over-ride 00086 if (key != 'self') : 00087 useLocalDefaults = True 00088 #myf[key]=keyVal 00089 00090 myparams = {} 00091 if useLocalDefaults : 00092 for item in function_signature_defaults.iteritems(): 00093 key,val = item 00094 keyVal = eval(key) 00095 exec('myparams[key] = keyVal') 00096 if (keyVal == None): 00097 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00098 keyVal = eval(key) 00099 if(type(keyVal) == dict) : 00100 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00101 00102 else : 00103 uselessvariable = None 00104 myparams['imagename'] = imagename = myf['imagename'] 00105 myparams['fitsimage'] = fitsimage = myf['fitsimage'] 00106 myparams['velocity'] = velocity = myf['velocity'] 00107 myparams['optical'] = optical = myf['optical'] 00108 myparams['bitpix'] = bitpix = myf['bitpix'] 00109 myparams['minpix'] = minpix = myf['minpix'] 00110 myparams['maxpix'] = maxpix = myf['maxpix'] 00111 myparams['overwrite'] = overwrite = myf['overwrite'] 00112 myparams['dropstokes'] = dropstokes = myf['dropstokes'] 00113 myparams['stokeslast'] = stokeslast = myf['stokeslast'] 00114 00115 00116 result = None 00117 00118 # 00119 # The following is work around to avoid a bug with current python translation 00120 # 00121 mytmp = {} 00122 00123 mytmp['imagename'] = imagename 00124 mytmp['fitsimage'] = fitsimage 00125 mytmp['velocity'] = velocity 00126 mytmp['optical'] = optical 00127 mytmp['bitpix'] = bitpix 00128 mytmp['minpix'] = minpix 00129 mytmp['maxpix'] = maxpix 00130 mytmp['overwrite'] = overwrite 00131 mytmp['dropstokes'] = dropstokes 00132 mytmp['stokeslast'] = stokeslast 00133 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00134 trec = casac.utils().torecord(pathname+'exportfits.xml') 00135 00136 casalog.origin('exportfits') 00137 if not trec.has_key('exportfits') or not casac.utils().verify(mytmp, trec['exportfits']) : 00138 return False 00139 00140 00141 try : 00142 casalog.post('') 00143 casalog.post('##########################################') 00144 casalog.post('##### Begin Task: exportfits #####') 00145 casalog.post('') 00146 result = exportfits(imagename, fitsimage, velocity, optical, bitpix, minpix, maxpix, overwrite, dropstokes, stokeslast) 00147 casalog.post('') 00148 casalog.post('##### End Task: exportfits #####') 00149 casalog.post('##########################################') 00150 00151 00152 # saveinputs for individule engine has no use 00153 # saveinputs should alos be removed from casa_in_py.py 00154 # 00155 # 00156 # saveinputs = myf['saveinputs'] 00157 # saveinputs('exportfits', 'exportfits.last', myparams) 00158 # 00159 # 00160 except Exception, instance: 00161 #print '**** Error **** ',instance 00162 pass 00163 00164 gc.collect() 00165 return result 00166 # 00167 # 00168 ## 00169 # def paramgui(self, useGlobals=True): 00170 # """ 00171 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00172 # """ 00173 # import paramgui 00174 # 00175 # a=inspect.stack() 00176 # stacklevel=0 00177 # for k in range(len(a)): 00178 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00179 # stacklevel=k 00180 # break 00181 # myf = sys._getframe(stacklevel).f_globals 00182 # 00183 # if useGlobals: 00184 # paramgui.setGlobals(myf) 00185 # else: 00186 # paramgui.setGlobals({}) 00187 # 00188 # paramgui.runTask('exportfits', myf['_ip']) 00189 # paramgui.setGlobals({}) 00190 # 00191 # 00192 # 00193 # 00194 def defaults(self, param=None): 00195 a=inspect.stack() 00196 stacklevel=0 00197 for k in range(len(a)): 00198 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00199 stacklevel=k 00200 break 00201 myf=sys._getframe(stacklevel).f_globals 00202 a = odict() 00203 a['imagename'] = '' 00204 a['fitsimage'] = '' 00205 a['velocity'] = False 00206 a['optical'] = False 00207 a['bitpix'] = -32 00208 a['minpix'] = 0 00209 a['maxpix'] = -1 00210 a['overwrite'] = False 00211 a['dropstokes'] = False 00212 a['stokeslast'] = True 00213 00214 a['async']=False 00215 00216 ### This function sets the default values but also will return the list of 00217 ### parameters or the default value of a given parameter 00218 if(param == None): 00219 myf['__set_default_parameters'](a) 00220 elif(param == 'paramkeys'): 00221 return a.keys() 00222 else: 00223 if(a.has_key(param)): 00224 #if(type(a[param]) == dict) : 00225 # return a[param][len(a[param])-1]['value'] 00226 #else : 00227 return a[param] 00228 00229 00230 # 00231 # 00232 def check_params(self, param=None, value=None): 00233 a=inspect.stack() 00234 stacklevel=0 00235 for k in range(len(a)): 00236 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00237 stacklevel=k 00238 break 00239 myf=sys._getframe(stacklevel).f_globals 00240 00241 # print 'param:', param, 'value:', value 00242 try : 00243 if str(type(value)) != "<type 'instance'>" : 00244 value0 = value 00245 value = myf['cu'].expandparam(param, value) 00246 matchtype = False 00247 if(type(value) == numpy.ndarray): 00248 if(type(value) == type(value0)): 00249 myf[param] = value.tolist() 00250 else: 00251 #print 'value:', value, 'value0:', value0 00252 #print 'type(value):', type(value), 'type(value0):', type(value0) 00253 myf[param] = value0 00254 if type(value0) != list : 00255 matchtype = True 00256 else : 00257 myf[param] = value 00258 value = myf['cu'].verifyparam({param:value}) 00259 if matchtype: 00260 value = False 00261 except Exception, instance: 00262 #ignore the exception and just return it unchecked 00263 myf[param] = value 00264 return value 00265 00266 # 00267 # 00268 def description(self, key='exportfits', subkey=None): 00269 desc={'exportfits': 'Convert a CASA image to a FITS file', 00270 'imagename': 'Name of input CASA image', 00271 'fitsimage': 'Name of output image FITS file', 00272 'velocity': 'Use velocity (rather than frequency) as spectral axis', 00273 'optical': 'Use the optical (rather than radio) velocity convention', 00274 'bitpix': 'Bits per pixel', 00275 'minpix': 'Minimum pixel value (if minpix > maxpix, value is automatically determined)', 00276 'maxpix': 'Maximum pixel value (if minpix > maxpix, value is automatically determined)', 00277 'overwrite': 'Overwrite pre-existing imagename', 00278 'dropstokes': 'Drop the Stokes axis?', 00279 'stokeslast': 'Put Stokes axis last in header?', 00280 00281 'async': 'If true the taskname must be started using exportfits(...)' 00282 } 00283 00284 if(desc.has_key(key)) : 00285 return desc[key] 00286 00287 def itsdefault(self, paramname) : 00288 a = {} 00289 a['imagename'] = '' 00290 a['fitsimage'] = '' 00291 a['velocity'] = False 00292 a['optical'] = False 00293 a['bitpix'] = -32 00294 a['minpix'] = 0 00295 a['maxpix'] = -1 00296 a['overwrite'] = False 00297 a['dropstokes'] = False 00298 a['stokeslast'] = True 00299 00300 if a.has_key(paramname) : 00301 return a[paramname] 00302 exportfits_pg = exportfits_pg_()