casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
sdimaging_pg.py
Go to the documentation of this file.
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_sdimaging import sdimaging
00016 from task_sdimaging import casalog
00017 
00018 class sdimaging_pg_:
00019     __name__ = "sdimaging"
00020 
00021     def __init__(self) :
00022        self.__bases__ = (sdimaging_pg_,)
00023        self.__doc__ = self.__call__.__doc__
00024 
00025 
00026     def __call__(self, infile=None, specunit=None, restfreq=None, scanlist=None, field=None, spw=None, antenna=None, stokes=None, gridfunction=None, convsupport=None, truncate=None, gwidth=None, jwidth=None, outfile=None, overwrite=None, imsize=None, cell=None, dochannelmap=None, nchan=None, start=None, step=None, phasecenter=None, ephemsrcname=None, pointingcolumn=None, async=None):
00027 
00028         """SD task: imaging for total power and spectral data
00029   Keyword arguments:
00030         infile -- name of input SD (MS) dataset
00031         specunit -- units for spectral axis
00032                 options: (str) 'channel','km/s','GHz','MHz','kHz','Hz'
00033                 default: 'channel'
00034                 example: this will be the units for nchan, start, and step
00035         restfreq -- rest frequency
00036                 default: '' (refer input data)
00037                 example: 1.0e11, '100GHz'
00038         scanlist -- list of scan numbers to process
00039                 default: [] (use all scans)
00040                 example: [21,22,23,24]
00041                 this selection is in addition to field and spw
00042         field -- field id or selection string for selecting scans by name
00043                 default: -1 (all fields)
00044                 example: 'FLS3a', 0
00045                 this selection is in addition to scanlist and spw
00046         spw -- spectral window id
00047                 default: 0
00048                 example: 1
00049                 this selection is in addition to scanlist and field
00050         antenna -- select data based on antenna name(s) or id(s)
00051                 default: -1 (all baselines, i.e. all antenna in case of auto data)
00052                 example: 0, 'DV01'
00053         stokes -- select data based on stokes or polarization type 
00054                 default: '' (use all polarizations)
00055                 example: 'XX'
00056         gridfunction -- gridding function for imaging
00057                 options: 'BOX' (Box-car), 'SF' (Spheroidal), 
00058                          'PB' (Primary-beam), 'GAUSS' (Gaussian),
00059                          'GJINC' (Gaussian*Jinc)
00060                 default: 'BOX'
00061                 example: 'SF'
00062             >>> gridfunction expandable parameter:
00063                convsupport -- convolution support for 'SF' 
00064                    default: -1 (use default for each gridfunction)
00065                    example: 3
00066                truncate -- truncattion radius of convolution kernel.
00067                            effective only for 'GAUSS' and 'GJINC'.
00068                    default: '-1' (use default for each gridfunction)
00069                    example: 3, '20arcsec', '3pixel'
00070                gwidth -- HWHM for gaussian. Effective only for 
00071                          'GAUSS' and 'GJINC'.
00072                    default: '-1' (use default for each gridfunction)
00073                    example: 3, '20arcsec', '3pixel'
00074                jwidth -- Width of jinc function. Effective only for 
00075                          'GJINC'.
00076                    default: '-1' (use default for each gridfunction)
00077                    example: 3, '20arcsec', '3pixel'
00078         outfile -- output image name
00079                 default: none
00080                 example: 'mySDimage.im'
00081         overwrite -- overwrite option for outfile
00082                 default: False (not overwrite)
00083                 options: True, False
00084                 example: if True, existing file will be overwritten
00085         imsize -- x and y image size in pixels, symmetric for single value
00086                 default: [256,256]
00087                 example: imsize=200 (equivalent to [200,200])
00088         cell -- x and y cell size. default unit arcmin
00089                 default: ['1.0arcmin', '1.0arcmin']
00090                 example: cell=['0.2arcmin, 0.2arcmin']
00091                          cell='0.2arcmin' (equivalent to example above)
00092         dochannelmap -- channel map image or total power image
00093                 default: False (total power)
00094                 options: True (channel map), False
00095             >>> dochannelmap=True expandable parameters
00096                nchan -- number of spectral channel for created image
00097                    default: 1 
00098                    example: 100
00099                start -- reference value of start channel (in units of specunit)
00100                    default: 0 (0th channel if specunit='channel')
00101                    example: 100
00102                step -- width of each spectral channel for created image
00103                    default: 1 (width of 1 channel if specunit='channel')
00104                    example: 100
00105         phasecenter -- image phase center: direction measure or fieldid 
00106                 default: 0
00107                 example: 'J2000 13h44m00 -17d02m00', 'AZEL -123d48m29 15d41m41'
00108         ephemsrcname -- ephemeris source name for moving source
00109                 default: ''
00110                 if the source name in the data matches one of the known 
00111                 solar objects by the system, this task automatically set 
00112                 the source name. 
00113                 example: 'moon' 
00114         pointingcolumn -- pointing data column to use
00115                 option: 'direction', 'target', 'pointing_offset', 'source_offset', 'encoder' 
00116                 default: 'direction'
00117 
00118 
00119         DESCRIPTION:
00120 
00121         Task sdimaging create image from input single-dish data.
00122         The input can be either total power and spectral data. Currently,
00123         this task directly accesses the Measurement Set data only because of 
00124         the data access efficiency. So it differs from other single-dish 
00125         tasks that mostly operate on the ASAP scantable data format.
00126  
00127         Units of spectral axis can be specified via a parameter specunit.
00128         Allowed values for specunit are 'channel', 'GHz', 'MHz', 'kHz', 'Hz', 
00129         and 'km/s'. This parameter is also used as the units of the parameter 
00130         start and step that specify reference value of start channel and 
00131         width of each spectral channel for channel map, respectively. 
00132         The parameter nchan specifies number of channels for created image. 
00133         If you set nchan as -1, the task selects existing all channels and 
00134         combine those data into one channel to create continuum image.
00135 
00136         You can specify field id or name directly. By default, field is set 
00137         to -1 that means the task selects all fields in the data.
00138 
00139         Selection of the antennas can be made by setting antennaid(s) or 
00140         antenna name(s) in string (e.g. '0', 'DV01',etc.) or integer 
00141         (e.g. 0). Defalut value, -1, means that the task selects data from 
00142         all baseline, i.e., data from all antenna when data only contains 
00143         auto-correlation.
00144 
00145         The parameter gridfunction sets gridding function for imaging. 
00146         Currently, the task supports 'BOX' (Box-car), 'SF' (Prolate 
00147         Spheroidal Wave Function), 'GAUSS' (Gaussian), 'GJINC' (Gaussian*
00148         Jinc), where Jinc(x) = J_1(pi*x/c)/(pi*x/c) with a first order 
00149         Bessel function J_1, and 'PB' (Primary Beam). For 'PB', correct 
00150         antenna informations should be included in input file. 
00151 
00152         There are four subparameters for gridfunction: convsupport, truncate, 
00153         gwidth, and jwidth. The convsupport is an integer specifying cut-off 
00154         radius for 'SF' in units of pixel. By default (convsupport=-1), 
00155         the cut-off radius is set to 3 pixels. The truncate is a cut-off 
00156         radius for 'GAUSS' or 'GJINC'. It accepts integer, float, and 
00157         string values of numeric plus unit. Allowed units are angular 
00158         units such as 'deg', 'arcmin', 'arcsec', and 'pixel'. Default unit 
00159         is 'pixel' so that string without unit or numerical values (integer 
00160         or float) will be interpreted as radius in pixel. Default value 
00161         for truncate, which is used when negative radius is set, is 3*HWHM 
00162         for 'GAUSS' and radius at first null for 'GJINC'. The gwidth is 
00163         the HWHM of gaussian for 'GAUSS' and 'GJINC'. Default value is 
00164         sqrt(log(2)) pixel for 'GAUSS' and 2.52*sqrt(log(2)) pixel for 
00165         'GJINC'. The jwidth specifies width of the jinc function (parameter 
00166         'c' in the definition above). Default is 1.55 pixel. Both gwidth 
00167         jwidth allows integer, float, or string of numeric plus unit. 
00168         Default values for gwidth and jwidth are taken from Mangum et al. 
00169         (2007).
00170   
00171         """
00172         a=inspect.stack()
00173         stacklevel=0
00174         for k in range(len(a)):
00175           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00176                 stacklevel=k
00177                 break
00178         myf=sys._getframe(stacklevel).f_globals
00179         myf['__last_task'] = 'sdimaging'
00180         myf['taskname'] = 'sdimaging'
00181         ###
00182         myf['update_params'](func=myf['taskname'],printtext=False)
00183         ###
00184         ###
00185         #Handle globals or user over-ride of arguments
00186         #
00187         function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults))
00188         useLocalDefaults = False
00189 
00190         for item in function_signature_defaults.iteritems():
00191                 key,val = item
00192                 keyVal = eval(key)
00193                 if (keyVal == None):
00194                         #user hasn't set it - use global/default
00195                         pass
00196                 else:
00197                         #user has set it - use over-ride
00198                         if (key != 'self') :
00199                            useLocalDefaults = True
00200                         #myf[key]=keyVal
00201 
00202         myparams = {}
00203         if useLocalDefaults :
00204            for item in function_signature_defaults.iteritems():
00205                key,val = item
00206                keyVal = eval(key)
00207                exec('myparams[key] = keyVal')
00208                if (keyVal == None):
00209                    exec('myparams[key] = '+ key + ' = self.itsdefault(key)')
00210                    keyVal = eval(key)
00211                    if(type(keyVal) == dict) :
00212                       exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']')
00213 
00214         else :
00215             uselessvariable = None 
00216             myparams['infile'] = infile = myf['infile']
00217             myparams['specunit'] = specunit = myf['specunit']
00218             myparams['restfreq'] = restfreq = myf['restfreq']
00219             myparams['scanlist'] = scanlist = myf['scanlist']
00220             myparams['field'] = field = myf['field']
00221             myparams['spw'] = spw = myf['spw']
00222             myparams['antenna'] = antenna = myf['antenna']
00223             myparams['stokes'] = stokes = myf['stokes']
00224             myparams['gridfunction'] = gridfunction = myf['gridfunction']
00225             myparams['convsupport'] = convsupport = myf['convsupport']
00226             myparams['truncate'] = truncate = myf['truncate']
00227             myparams['gwidth'] = gwidth = myf['gwidth']
00228             myparams['jwidth'] = jwidth = myf['jwidth']
00229             myparams['outfile'] = outfile = myf['outfile']
00230             myparams['overwrite'] = overwrite = myf['overwrite']
00231             myparams['imsize'] = imsize = myf['imsize']
00232             myparams['cell'] = cell = myf['cell']
00233             myparams['dochannelmap'] = dochannelmap = myf['dochannelmap']
00234             myparams['nchan'] = nchan = myf['nchan']
00235             myparams['start'] = start = myf['start']
00236             myparams['step'] = step = myf['step']
00237             myparams['phasecenter'] = phasecenter = myf['phasecenter']
00238             myparams['ephemsrcname'] = ephemsrcname = myf['ephemsrcname']
00239             myparams['pointingcolumn'] = pointingcolumn = myf['pointingcolumn']
00240 
00241         if type(scanlist)==int: scanlist=[scanlist]
00242         if type(imsize)==int: imsize=[imsize]
00243         if type(cell)==float: cell=[cell]
00244 
00245         result = None
00246 
00247 #
00248 #    The following is work around to avoid a bug with current python translation
00249 #
00250         mytmp = {}
00251 
00252         mytmp['infile'] = infile
00253         mytmp['specunit'] = specunit
00254         mytmp['restfreq'] = restfreq
00255         mytmp['scanlist'] = scanlist
00256         mytmp['field'] = field
00257         mytmp['spw'] = spw
00258         mytmp['antenna'] = antenna
00259         mytmp['stokes'] = stokes
00260         mytmp['gridfunction'] = gridfunction
00261         mytmp['convsupport'] = convsupport
00262         mytmp['truncate'] = truncate
00263         mytmp['gwidth'] = gwidth
00264         mytmp['jwidth'] = jwidth
00265         mytmp['outfile'] = outfile
00266         mytmp['overwrite'] = overwrite
00267         mytmp['imsize'] = imsize
00268         if type(cell) == str :
00269            mytmp['cell'] = casac.quanta().quantity(cell)
00270         else :
00271            mytmp['cell'] = cell
00272         mytmp['dochannelmap'] = dochannelmap
00273         mytmp['nchan'] = nchan
00274         mytmp['start'] = start
00275         mytmp['step'] = step
00276         mytmp['phasecenter'] = phasecenter
00277         mytmp['ephemsrcname'] = ephemsrcname
00278         mytmp['pointingcolumn'] = pointingcolumn
00279         pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/'
00280         trec = casac.utils().torecord(pathname+'sdimaging.xml')
00281 
00282         casalog.origin('sdimaging')
00283         if not trec.has_key('sdimaging') or not casac.utils().verify(mytmp, trec['sdimaging']) :
00284             return False
00285 
00286 
00287         try :
00288           casalog.post('')
00289           casalog.post('##########################################')
00290           casalog.post('##### Begin Task: sdimaging           #####')
00291           casalog.post('')
00292           result = sdimaging(infile, specunit, restfreq, scanlist, field, spw, antenna, stokes, gridfunction, convsupport, truncate, gwidth, jwidth, outfile, overwrite, imsize, cell, dochannelmap, nchan, start, step, phasecenter, ephemsrcname, pointingcolumn)
00293           casalog.post('')
00294           casalog.post('##### End Task: sdimaging           #####')
00295           casalog.post('##########################################')
00296 
00297 
00298 # saveinputs for individule engine has no use
00299 # saveinputs should alos be removed from casa_in_py.py
00300 #
00301 #
00302 #          saveinputs = myf['saveinputs']
00303 #          saveinputs('sdimaging', 'sdimaging.last', myparams)
00304 #
00305 #
00306         except Exception, instance:
00307           #print '**** Error **** ',instance
00308           pass
00309 
00310         gc.collect()
00311         return result
00312 #
00313 #
00314 ##
00315 #    def paramgui(self, useGlobals=True):
00316 #        """
00317 #        Opens a parameter GUI for this task.  If useGlobals is true, then any relevant global parameter settings are used.
00318 #        """
00319 #        import paramgui
00320 #
00321 #        a=inspect.stack()
00322 #        stacklevel=0
00323 #        for k in range(len(a)):
00324 #          if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00325 #            stacklevel=k
00326 #            break
00327 #        myf = sys._getframe(stacklevel).f_globals
00328 #
00329 #        if useGlobals:
00330 #            paramgui.setGlobals(myf)
00331 #        else:
00332 #            paramgui.setGlobals({})
00333 #
00334 #        paramgui.runTask('sdimaging', myf['_ip'])
00335 #        paramgui.setGlobals({})
00336 #
00337 #
00338 #
00339 #
00340     def defaults(self, param=None):
00341         a=inspect.stack()
00342         stacklevel=0
00343         for k in range(len(a)):
00344           if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00345                 stacklevel=k
00346                 break
00347         myf=sys._getframe(stacklevel).f_globals
00348         a = odict()
00349         a['infile']  = ''
00350         a['specunit']  = ''
00351         a['restfreq']  = ''
00352         a['scanlist']  = []
00353         a['field']  = -1
00354         a['spw']  = 0
00355         a['antenna']  = -1
00356         a['stokes']  = ''
00357         a['gridfunction']  = 'BOX'
00358         a['outfile']  = ''
00359         a['overwrite']  = False
00360         a['imsize']  = [256, 256]
00361         a['cell']  = ['1.0arcmin', '1.0arcmin']
00362         a['dochannelmap']  = False
00363         a['phasecenter']  = ''
00364         a['ephemsrcname']  = ''
00365         a['pointingcolumn']  = 'direction'
00366 
00367         a['async']=False
00368         a['dochannelmap'] = {
00369                     0:{'value':False}, 
00370                     1:odict([{'value':True}, {'nchan':1}, {'start':0}, {'step':1}])}
00371         a['gridfunction'] = {
00372                     0:{'value':'BOX'}, 
00373                     1:{'value':'box'}, 
00374                     2:odict([{'value':'SF'}, {'convsupport':-1}]), 
00375                     3:odict([{'value':'sf'}, {'convsupport':-1}]), 
00376                     4:{'value':'PB'}, 
00377                     5:{'value':'pb'}, 
00378                     6:odict([{'value':'GAUSS'}, {'truncate':-1}, {'gwidth':-1}]), 
00379                     7:odict([{'value':'gauss'}, {'truncate':-1}, {'gwidth':-1}]), 
00380                     8:odict([{'value':'GJINC'}, {'truncate':-1}, {'gwidth':-1}, {'jwidth':-1}]), 
00381                     9:odict([{'value':'gjinc'}, {'truncate':-1}, {'gwidth':-1}, {'jwidth':-1}])}
00382 
00383 ### This function sets the default values but also will return the list of
00384 ### parameters or the default value of a given parameter
00385         if(param == None):
00386                 myf['__set_default_parameters'](a)
00387         elif(param == 'paramkeys'):
00388                 return a.keys()
00389         else:
00390                 if(a.has_key(param)):
00391                    #if(type(a[param]) == dict) :
00392                    #   return a[param][len(a[param])-1]['value']
00393                    #else :
00394                       return a[param]
00395 
00396 
00397 #
00398 #
00399     def check_params(self, param=None, value=None):
00400       a=inspect.stack() 
00401       stacklevel=0
00402       for k in range(len(a)):
00403         if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0):
00404             stacklevel=k
00405             break
00406       myf=sys._getframe(stacklevel).f_globals
00407 
00408 #      print 'param:', param, 'value:', value
00409       try :
00410          if str(type(value)) != "<type 'instance'>" :
00411             value0 = value
00412             value = myf['cu'].expandparam(param, value)
00413             matchtype = False
00414             if(type(value) == numpy.ndarray):
00415                if(type(value) == type(value0)):
00416                   myf[param] = value.tolist()
00417                else:
00418                   #print 'value:', value, 'value0:', value0
00419                   #print 'type(value):', type(value), 'type(value0):', type(value0)
00420                   myf[param] = value0
00421                   if type(value0) != list :
00422                      matchtype = True
00423             else :
00424                myf[param] = value
00425             value = myf['cu'].verifyparam({param:value})
00426             if matchtype:
00427                value = False
00428       except Exception, instance:
00429          #ignore the exception and just return it unchecked
00430          myf[param] = value
00431       return value
00432 
00433 #
00434 #
00435     def description(self, key='sdimaging', subkey=None):
00436         desc={'sdimaging': 'SD task: imaging for total power and spectral data',
00437                'infile': 'name of input SD dataset(only MS is allowed for this task)',
00438                'specunit': 'units for spectral axis (channel,km/s,GHz)',
00439                'restfreq': 'rest frequency',
00440                'scanlist': 'list of scans to use (e.g. [1,2,3,4])',
00441                'field': 'string for selection by field name or id',
00442                'spw': 'spectral window id for imaging',
00443                'antenna': 'antenna name(s) or id(s)',
00444                'stokes': 'stokes or correlation name (e.g. "I", "XX")',
00445                'gridfunction': 'gridding function for imaging ("BOX","SF","PB")',
00446                'convsupport': 'convolution support for gridding',
00447                'truncate': 'truncation radius for gridding',
00448                'gwidth': 'HWHM for gaussian',
00449                'jwidth': 'c-parameter for jinc function',
00450                'outfile': 'output image name',
00451                'overwrite': 'overwrite option',
00452                'imsize': 'x and y image size in pixels, symmetric for single value',
00453                'cell': 'x and y cell size. default unit arcmin',
00454                'dochannelmap': 'True for channel map, False for total power imaging',
00455                'nchan': 'number of spectral channel for created image',
00456                'start': 'reference value of start channel (in units of specunit)',
00457                'step': 'width of each spectral channel (in units of specunit)',
00458                'phasecenter': 'Image phase center: position or field index',
00459                'ephemsrcname': 'ephemeris source name',
00460                'pointingcolumn': 'pointing data column to use',
00461 
00462                'async': 'If true the taskname must be started using sdimaging(...)'
00463               }
00464 
00465 #
00466 # Set subfields defaults if needed
00467 #
00468 
00469         if(desc.has_key(key)) :
00470            return desc[key]
00471 
00472     def itsdefault(self, paramname) :
00473         a = {}
00474         a['infile']  = ''
00475         a['specunit']  = ''
00476         a['restfreq']  = ''
00477         a['scanlist']  = []
00478         a['field']  = -1
00479         a['spw']  = 0
00480         a['antenna']  = -1
00481         a['stokes']  = ''
00482         a['gridfunction']  = 'BOX'
00483         a['convsupport']  = -1
00484         a['truncate']  = -1
00485         a['gwidth']  = -1
00486         a['jwidth']  = -1
00487         a['outfile']  = ''
00488         a['overwrite']  = False
00489         a['imsize']  = [256, 256]
00490         a['cell']  = ['1.0arcmin', '1.0arcmin']
00491         a['dochannelmap']  = False
00492         a['nchan']  = 1
00493         a['start']  = 0
00494         a['step']  = 1
00495         a['phasecenter']  = ''
00496         a['ephemsrcname']  = ''
00497         a['pointingcolumn']  = 'direction'
00498 
00499         if a.has_key(paramname) :
00500               return a[paramname]
00501 sdimaging_pg = sdimaging_pg_()