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 casac 00010 import string 00011 import time 00012 import inspect 00013 import gc 00014 import numpy 00015 from odict import odict 00016 from taskmanager import tm 00017 from task_pclean import pclean 00018 class pclean_cli_: 00019 __name__ = "pclean" 00020 __async__ = {} 00021 rkey = None 00022 i_am_a_casapy_task = None 00023 # The existence of the i_am_a_casapy_task attribute allows help() 00024 # (and other) to treat casapy tasks as a special case. 00025 00026 def __init__(self) : 00027 self.__bases__ = (pclean_cli_,) 00028 self.__doc__ = self.__call__.__doc__ 00029 00030 self.parameters={'vis':None, 'imagename':None, 'imsize':None, 'cell':None, 'phasecenter':None, 'stokes':None, 'mask':None, 'field':None, 'spw':None, 'ftmachine':None, 'alg':None, 'scales':None, 'cyclefactor':None, 'majorcycles':None, 'niter':None, 'gain':None, 'threshold':None, 'weighting':None, 'robust':None, 'npixels':None, 'mode':None, 'nterms':None, 'start':None, 'nchan':None, 'width':None, 'restfreq':None, 'interactive':None, 'npercycle':None, 'wprojplanes':None, 'facets':None, 'overwrite':None, 'uvtaper':None, 'outertaper':None, 'timerange':None, 'uvrange':None, 'antenna':None, 'scan':None, 'observation':None, 'pbcor':None, 'minpb':None, 'clusterdef':None, 'async':None} 00031 00032 00033 def result(self, key=None): 00034 #### here we will scan the task-ids in __async__ 00035 #### and add any that have completed... 00036 if key is not None and self.__async__.has_key(key) and self.__async__[key] is not None: 00037 ret = tm.retrieve(self.__async__[key]) 00038 if ret['state'] == "done" : 00039 self.__async__[key] = None 00040 elif ret['state'] == 'crashed' : 00041 self.__async__[key] = None 00042 return ret 00043 return None 00044 00045 00046 def __call__(self, vis=None, imagename=None, imsize=None, cell=None, phasecenter=None, stokes=None, mask=None, field=None, spw=None, ftmachine=None, alg=None, scales=None, cyclefactor=None, majorcycles=None, niter=None, gain=None, threshold=None, weighting=None, robust=None, npixels=None, mode=None, nterms=None, start=None, nchan=None, width=None, restfreq=None, interactive=None, npercycle=None, wprojplanes=None, facets=None, overwrite=None, uvtaper=None, outertaper=None, timerange=None, uvrange=None, antenna=None, scan=None, observation=None, pbcor=None, minpb=None, clusterdef=None, async=None): 00047 00048 """Invert and deconvolve images with parallel engines 00049 00050 Keyword arguments: 00051 Invert and deconvolve images with parallel engines 00052 Form images from visibilities. Handles continuum and spectral line 00053 cubes using module pcont and pcube respectively. 00054 00055 vis -- Name of input visibility file 00056 default: none; example: vis='ngc5921.ms' 00057 00058 imagename -- Pre-name of output CASA image. (only the prefix) 00059 default: none; 00060 example: imagename='m2', output images are: 00061 m2.image; cleaned and restored image 00062 With or without primary beam correction 00063 m2.psf; point-spread function (dirty beam) 00064 m2.model; image of clean components 00065 m2.mask; image containing clean regions, when interative=True 00066 00067 imsize -- Image pixel size (x,y). DOES NOT HAVE TO BE A POWER OF 2 00068 default: [256,256]; 00069 example: imsize=[350,350] 00070 imsize=500 is equivalent to imsize=[500, 500] 00071 Avoid odd-numbered imsize. 00072 00073 cell -- Cell size (x,y) 00074 default: '1.0arcsec'; 00075 example: cell=['0.5arcsec', '0.5arcsec'] or 00076 cell=['1arcmin', '1arcmin'] 00077 cell='1arcsec' is equivalent to cell=['1arcsec', '1arcsec'] 00078 NOTE:cell=2.0 => cell=['2arcsec', '2arcsec'] 00079 00080 phasecenter -- direction measure or fieldid for the mosaic center 00081 default: '' => first field selected; 00082 example: phasecenter=6 00083 or phasecenter='J2000 19h30m00 -40d00m00' 00084 00085 mask -- mask image to be used for CLEANing. As long as the image has 00086 the same shape (size), mask images from a previous 00087 interactive session can be used for a new execution. 00088 Only an image mask is allowed at this stage. Text formats not allowed yet. 00089 00090 field -- Select fields in MS. Use field id(s) or field name(s). 00091 ['go listobs' to obtain the list id's or names] 00092 default: ''= all fields 00093 If field string is a non-negative integer, it is assumed to 00094 be a field index otherwise, it is assumed to be a field name 00095 examples: 00096 field='0~2'; field ids 0,1,2 00097 field='0,4,5~7'; field ids 0,4,5,6,7 00098 field='3C286,3C295'; field named 3C286 and 3C295 00099 field = '3,4C*'; field id 3, all names starting with 4C 00100 00101 spw --Select spectral window/channels 00102 NOTE: This selects the data passed as the INPUT to mode 00103 default: ''=all spectral windows and channels 00104 examples: 00105 spw='0~2,4'; spectral windows 0,1,2,4 (all channels) 00106 spw='0:5~61'; spw 0, channels 5 to 61 00107 spw='< 2'; spectral windows less than 2 (i.e. 0,1) 00108 spw='0,10,3:3~45'; spw 0,10 all channels, spw 3, 00109 channels 3 to 45. 00110 spw='0~2:2~6'; spw 0,1,2 with channels 2 through 6 in each. 00111 spw='0:0~10;15~60'; spectral window 0 with channels 00112 0-10,15-60 00113 spw='0:0~10,1:20~30,2:1;2;3'; spw 0, channels 0-10, 00114 spw 1, channels 20-30, and spw 2, channels, 1,2 and 3 00115 00116 ftmachine -- Fourier Transform Engine (Gridding method) 00117 Options: 00118 'ft' (standard interferometric gridding), 00119 'sd' (standard single dish), 00120 'mosaic' (grid using PB as convolution function). 00121 'wproject' (wprojection gridder to correct for widefield 'w' term errors) 00122 default: 'ft' 00123 00124 alg -- Deconvolution algorithm 00125 Options: 'clark', 'hogbom', 'multiscale' 00126 default: 'clark' 00127 00128 cyclefactor -- Controls the threshhold at which the 00129 deconvolution cycle will pause to degrid and subtract the 00130 model from the visibilities (Cotton-Schwab (CS) major cycle). 00131 With poor PSFs, reconcile often (cyclefactor=4 or 5) for 00132 reliability. 00133 With good PSFs, use cyclefactor = 1.5 to 2.0 for speed. 00134 Note: threshold = cyclefactor * max sidelobe * max residual 00135 default: 1.5; example: cyclefactor=4 00136 cyclefactor=0 allows the user to control number of CS major cycle 00137 >>> majorcycles -- integer number of CS major cycles to do 00138 default: 1; 00139 example: majorcycles=10 00140 00141 niter -- Maximum number iterations, 00142 if niter=0, then no CLEANing is done ("invert" only) 00143 default: 500; 00144 example: niter=5000 00145 00146 threshold -- Flux level (residual peak) at which to stop CLEANing 00147 default: '0.0mJy'; 00148 example: 00149 threshold='2.3mJy' (always include units) 00150 threshold='0.0023Jy' 00151 threshold='0.0023Jy/beam' (okay also) 00152 00153 weighting -- Weighting to apply to visibilities: 00154 Options: 'natural','uniform','briggs', 00155 'superuniform','radial' 00156 default: 'natural'; 00157 example: weighting='uniform'; 00158 00159 scales -- list of scales in pixel for multiscale clean 00160 default: [0] 00161 example: scales=[0, 3, 10] 00162 00163 mode -- type of image to be generated 00164 Options: 'continuum', 'cube' 00165 default: 'continuum' 00166 example: 00167 mode='cube'; Use with nchan, start, step to specify 00168 output image cube. 00169 NOTE: mode='velocity' or 'channel' or 'frequency' 00170 are aliased to mode='cube' for backward compatibility 00171 and comfort. 00172 00173 >>> mode='cube' expandable parameters 00174 nchan -- Total number of channels in the output image. 00175 Example: nchan=100. 00176 Default: -1; Automatically selects enough channels to cover 00177 data selected by 'spw' and consistent with 'start' and 'step' 00178 It is often easiest to leave nchan at the default value. 00179 start -- First channel, velocity, or frequency. 00180 if start is an integer pclean will assume it is the a channel index 00181 if start is in units of velocity or frequency it will take it as such 00182 00183 If the user use the the ms channel as starting pclean will assign 00184 the first channel of the image to the data channel frequency in LSRK 00185 of the first 00186 spw selected at the first time seen in the data and the direction of the 00187 source selected. 00188 If the data is not in the LSRK frame the user should be aware that the 00189 data channel indicated may not fall on the first image channel as time goes. 00190 00191 example:start=5 00192 start can be in units of frequency or velocity too 00193 When velocity units is used it is obvious then that it is referring to the line 00194 whose restfrequency is provided by the user or is default one for the source 00195 in the MS/SOURCE table. 00196 examples: start='5.0km/s', or start='22.3GHz'. 00197 width -- Output channel width 00198 should be in the same units as start 00199 default=1; >1 indicates channel averaging 00200 if start is an integer, width has to be an integer defining the image channel 00201 width by the number of channels of first spectral window selected 00202 example: width=4. 00203 when start is in frequency or velocity units then the width has to be in the same units. default=''; 00204 00205 examples: width='1.0km/s', or width='24.2kHz'. 00206 00207 00208 interactive -- Create a mask interactively or not. 00209 interactive clean allows the user to build the cleaning 00210 mask interactively using the viewer. 00211 00212 default: False; 00213 example: interactive=True 00214 The viewer will open with the image displayed. Select the 00215 region for the mask and double click in the middle of it. 00216 00217 >>> npercycle -- Number of iteration in between viewer interactions. 00218 default=100 00219 00220 pbcor -- Output primary beam-corrected image 00221 If pbcor=False, the final output image is NOT corrected for 00222 the PB pattern (particularly important for mosaics), and 00223 therefore is not "flux correct". Correction can also be 00224 done after the fact using immath to divide 00225 <imagename>.image by the <imagename>.flux image. 00226 default: pbcor=False; output un-corrected image 00227 example: pbcor=True; output pb-corrected image (masked outside 00228 minpb) 00229 00230 >>> minpb -- Minimum PB level to use for pb-correction and pb-based masking. 00231 default=0.2; 00232 example: minpb=0.01 00233 When ftmachine is *not* 'mosaic' : 00234 minpb is applied to the flux image (sensitivity-weighted pb). 00235 When ftmachine='mosaic' : 00236 minpb is applied to the flux.pbcoverage image 00237 00238 overwrite -- If False use existing model image of same name to continue clean 00239 if True the imagename.model and other associated images are overwitten 00240 if they exist 00241 default: True 00242 00243 00244 timerange -- Select data based on time range: 00245 default: '' (all); examples, 00246 timerange = 'YYYY/MM/DD/hh:mm:ss~YYYY/MM/DD/hh:mm:ss' 00247 Note: if YYYY/MM/DD is missing date defaults to first 00248 day in data set 00249 timerange='09:14:0~09:54:0' picks 40 min on first day 00250 timerange='25:00:00~27:30:00' picks 1 hr to 3 hr 00251 30min on NEXT day 00252 timerange='09:44:00' pick data within one integration 00253 of time 00254 timerange='>10:24:00' data after this time 00255 For multiple MS input, a list of timerange strings can be 00256 used: 00257 uvrange -- Select data within uvrange (default units meters) 00258 default: '' (all); example: 00259 uvrange='0~1000klambda'; uvrange from 0-1000 kilo-lambda 00260 uvrange='>4klambda';uvranges greater than 4 kilo lambda 00261 antenna -- Select data based on antenna/baseline 00262 default: '' (all) 00263 If antenna string is a non-negative integer, it is 00264 assumed to be an antenna index, otherwise, it is 00265 considered an antenna name. 00266 antenna='5&6'; baseline between antenna index 5 and 00267 index 6. 00268 antenna='VA05&VA06'; baseline between VLA antenna 5 00269 and 6. 00270 antenna='5&6;7&8'; baselines 5-6 and 7-8 00271 antenna='5'; all baselines with antenna index 5 00272 antenna='05'; all baselines with antenna number 05 00273 (VLA old name) 00274 antenna='5,6,9'; all baselines with antennas 5,6,9 00275 index number 00276 scan -- Scan number range. 00277 default: '' (all) 00278 example: scan='1~5 00279 observation -- Observation ID range. 00280 default: '' (all) 00281 example: observation='1~5' 00282 00283 00284 clusterdef -- Name of a file that contains the cluster definition. 00285 NOTE: there is a chapter in the cookbook on how to 00286 define this file 00287 If clusterdef='' (the default) then all the cores, if possible, 00288 of the machine on 00289 which casapy is run will be used. 00290 00291 Example of a cube imaging run: 00292 00293 pclean(vis="ngc5921.ms.contsub",imagename="loulou",imsize=[2500, 2500], 00294 cell=['15.0arcsec', '15.0arcsec'],phasecenter="",stokes="I",field="0",spw="*", 00295 ftmachine="ft",alg="hogbom",majorcycles=2, niter=6000,gain=0.1, 00296 threshold="8mJy",weighting="briggs",robust=0.5,npixels=0,mode="cube", 00297 start=5,nchan=46,width=1,interactive=True,overwrite=True,uvtaper=False, 00298 outertaper=[''],pbcor=True) 00299 00300 Example of a continuum run: 00301 00302 pclean(vis='sim100g_4chan15kRows.ms', 00303 imagename='hundredG_cont', imsize=[1500, 1500], 00304 cell=['0.135arcsec', '0.135arcsec'], mode='continuum', phasecenter='0', 00305 field='0', spw='*', ftmachine='wproject', wprojplanes=128, 00306 threshold='0.1mJy', 00307 majorcycles=4, niter=10000, alg='clark', 00308 weighting='natural', 00309 overwrite=True) 00310 00311 00312 """ 00313 if not hasattr(self, "__globals__") or self.__globals__ == None : 00314 self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals 00315 #casac = self.__globals__['casac'] 00316 casalog = self.__globals__['casalog'] 00317 #casalog = casac.casac.logsink() 00318 self.__globals__['__last_task'] = 'pclean' 00319 self.__globals__['taskname'] = 'pclean' 00320 ### 00321 self.__globals__['update_params'](func=self.__globals__['taskname'],printtext=False,ipython_globals=self.__globals__) 00322 ### 00323 ### 00324 #Handle globals or user over-ride of arguments 00325 # 00326 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00327 useLocalDefaults = False 00328 00329 for item in function_signature_defaults.iteritems(): 00330 key,val = item 00331 keyVal = eval(key) 00332 if (keyVal == None): 00333 #user hasn't set it - use global/default 00334 pass 00335 else: 00336 #user has set it - use over-ride 00337 if (key != 'self') : 00338 useLocalDefaults = True 00339 00340 myparams = {} 00341 if useLocalDefaults : 00342 for item in function_signature_defaults.iteritems(): 00343 key,val = item 00344 keyVal = eval(key) 00345 exec('myparams[key] = keyVal') 00346 self.parameters[key] = keyVal 00347 if (keyVal == None): 00348 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00349 keyVal = eval(key) 00350 if(type(keyVal) == dict) : 00351 if len(keyVal) > 0 : 00352 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00353 else : 00354 exec('myparams[key] = ' + key + ' = {}') 00355 00356 else : 00357 async = self.parameters['async'] 00358 myparams['vis'] = vis = self.parameters['vis'] 00359 myparams['imagename'] = imagename = self.parameters['imagename'] 00360 myparams['imsize'] = imsize = self.parameters['imsize'] 00361 myparams['cell'] = cell = self.parameters['cell'] 00362 myparams['phasecenter'] = phasecenter = self.parameters['phasecenter'] 00363 myparams['stokes'] = stokes = self.parameters['stokes'] 00364 myparams['mask'] = mask = self.parameters['mask'] 00365 myparams['field'] = field = self.parameters['field'] 00366 myparams['spw'] = spw = self.parameters['spw'] 00367 myparams['ftmachine'] = ftmachine = self.parameters['ftmachine'] 00368 myparams['alg'] = alg = self.parameters['alg'] 00369 myparams['scales'] = scales = self.parameters['scales'] 00370 myparams['cyclefactor'] = cyclefactor = self.parameters['cyclefactor'] 00371 myparams['majorcycles'] = majorcycles = self.parameters['majorcycles'] 00372 myparams['niter'] = niter = self.parameters['niter'] 00373 myparams['gain'] = gain = self.parameters['gain'] 00374 myparams['threshold'] = threshold = self.parameters['threshold'] 00375 myparams['weighting'] = weighting = self.parameters['weighting'] 00376 myparams['robust'] = robust = self.parameters['robust'] 00377 myparams['npixels'] = npixels = self.parameters['npixels'] 00378 myparams['mode'] = mode = self.parameters['mode'] 00379 myparams['nterms'] = nterms = self.parameters['nterms'] 00380 myparams['start'] = start = self.parameters['start'] 00381 myparams['nchan'] = nchan = self.parameters['nchan'] 00382 myparams['width'] = width = self.parameters['width'] 00383 myparams['restfreq'] = restfreq = self.parameters['restfreq'] 00384 myparams['interactive'] = interactive = self.parameters['interactive'] 00385 myparams['npercycle'] = npercycle = self.parameters['npercycle'] 00386 myparams['wprojplanes'] = wprojplanes = self.parameters['wprojplanes'] 00387 myparams['facets'] = facets = self.parameters['facets'] 00388 myparams['overwrite'] = overwrite = self.parameters['overwrite'] 00389 myparams['uvtaper'] = uvtaper = self.parameters['uvtaper'] 00390 myparams['outertaper'] = outertaper = self.parameters['outertaper'] 00391 myparams['timerange'] = timerange = self.parameters['timerange'] 00392 myparams['uvrange'] = uvrange = self.parameters['uvrange'] 00393 myparams['antenna'] = antenna = self.parameters['antenna'] 00394 myparams['scan'] = scan = self.parameters['scan'] 00395 myparams['observation'] = observation = self.parameters['observation'] 00396 myparams['pbcor'] = pbcor = self.parameters['pbcor'] 00397 myparams['minpb'] = minpb = self.parameters['minpb'] 00398 myparams['clusterdef'] = clusterdef = self.parameters['clusterdef'] 00399 00400 if type(imsize)==int: imsize=[imsize] 00401 if type(cell)==float: cell=[cell] 00402 if type(scales)==int: scales=[scales] 00403 if type(outertaper)==str: outertaper=[outertaper] 00404 00405 result = None 00406 00407 # 00408 # The following is work around to avoid a bug with current python translation 00409 # 00410 mytmp = {} 00411 00412 mytmp['vis'] = vis 00413 mytmp['imagename'] = imagename 00414 mytmp['imsize'] = imsize 00415 if type(cell) == str : 00416 mytmp['cell'] = casac.casac.qa.quantity(cell) 00417 else : 00418 mytmp['cell'] = cell 00419 mytmp['phasecenter'] = phasecenter 00420 mytmp['stokes'] = stokes 00421 mytmp['mask'] = mask 00422 mytmp['field'] = field 00423 mytmp['spw'] = spw 00424 mytmp['ftmachine'] = ftmachine 00425 mytmp['alg'] = alg 00426 mytmp['scales'] = scales 00427 mytmp['cyclefactor'] = cyclefactor 00428 mytmp['majorcycles'] = majorcycles 00429 mytmp['niter'] = niter 00430 mytmp['gain'] = gain 00431 mytmp['threshold'] = threshold 00432 mytmp['weighting'] = weighting 00433 mytmp['robust'] = robust 00434 mytmp['npixels'] = npixels 00435 mytmp['mode'] = mode 00436 mytmp['nterms'] = nterms 00437 mytmp['start'] = start 00438 mytmp['nchan'] = nchan 00439 mytmp['width'] = width 00440 mytmp['restfreq'] = restfreq 00441 mytmp['interactive'] = interactive 00442 mytmp['npercycle'] = npercycle 00443 mytmp['wprojplanes'] = wprojplanes 00444 mytmp['facets'] = facets 00445 mytmp['overwrite'] = overwrite 00446 mytmp['uvtaper'] = uvtaper 00447 mytmp['outertaper'] = outertaper 00448 mytmp['timerange'] = timerange 00449 mytmp['uvrange'] = uvrange 00450 mytmp['antenna'] = antenna 00451 mytmp['scan'] = scan 00452 mytmp['observation'] = observation 00453 mytmp['pbcor'] = pbcor 00454 mytmp['minpb'] = minpb 00455 mytmp['clusterdef'] = clusterdef 00456 # 00457 # This task is never suppose to use the task manager to run async 00458 # 00459 async=False 00460 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00461 trec = casac.casac.utils().torecord(pathname+'pclean.xml') 00462 00463 casalog.origin('pclean') 00464 try : 00465 #if not trec.has_key('pclean') or not casac.casac.utils().verify(mytmp, trec['pclean']) : 00466 #return False 00467 00468 casac.casac.utils().verify(mytmp, trec['pclean'], True) 00469 scriptstr=[''] 00470 saveinputs = self.__globals__['saveinputs'] 00471 saveinputs('pclean', 'pclean.last', myparams, self.__globals__,scriptstr=scriptstr) 00472 if async : 00473 count = 0 00474 keybase = time.strftime("%y%m%d.%H%M%S") 00475 key = keybase + "_" + str(count) 00476 while self.__async__.has_key(key) : 00477 count += 1 00478 key = keybase + "_" + str(count) 00479 result = tm.execute('pclean', vis, imagename, imsize, cell, phasecenter, stokes, mask, field, spw, ftmachine, alg, scales, cyclefactor, majorcycles, niter, gain, threshold, weighting, robust, npixels, mode, nterms, start, nchan, width, restfreq, interactive, npercycle, wprojplanes, facets, overwrite, uvtaper, outertaper, timerange, uvrange, antenna, scan, observation, pbcor, minpb, clusterdef) 00480 print "Use: " 00481 print " tm.retrieve(return_value) # to retrieve the status" 00482 print 00483 self.rkey = key 00484 self.__async__[key] = result 00485 else : 00486 tname = 'pclean' 00487 spaces = ' '*(18-len(tname)) 00488 casalog.post('\n##########################################'+ 00489 '\n##### Begin Task: ' + tname + spaces + ' #####') 00490 casalog.post(scriptstr[1][1:]+'\n', 'INFO') 00491 result = pclean(vis, imagename, imsize, cell, phasecenter, stokes, mask, field, spw, ftmachine, alg, scales, cyclefactor, majorcycles, niter, gain, threshold, weighting, robust, npixels, mode, nterms, start, nchan, width, restfreq, interactive, npercycle, wprojplanes, facets, overwrite, uvtaper, outertaper, timerange, uvrange, antenna, scan, observation, pbcor, minpb, clusterdef) 00492 casalog.post('##### End Task: ' + tname + ' ' + spaces + ' #####'+ 00493 '\n##########################################') 00494 00495 except Exception, instance: 00496 if(self.__globals__.has_key('__rethrow_casa_exceptions') and self.__globals__['__rethrow_casa_exceptions']) : 00497 raise 00498 else : 00499 #print '**** Error **** ',instance 00500 tname = 'pclean' 00501 casalog.post('An error occurred running task '+tname+'.', 'ERROR') 00502 pass 00503 00504 gc.collect() 00505 return result 00506 # 00507 # 00508 # 00509 def paramgui(self, useGlobals=True, ipython_globals=None): 00510 """ 00511 Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00512 """ 00513 import paramgui 00514 if not hasattr(self, "__globals__") or self.__globals__ == None : 00515 self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals 00516 00517 if useGlobals: 00518 if ipython_globals == None: 00519 myf=self.__globals__ 00520 else: 00521 myf=ipython_globals 00522 00523 paramgui.setGlobals(myf) 00524 else: 00525 paramgui.setGlobals({}) 00526 00527 paramgui.runTask('pclean', myf['_ip']) 00528 paramgui.setGlobals({}) 00529 00530 # 00531 # 00532 # 00533 def defaults(self, param=None, ipython_globals=None, paramvalue=None, subparam=None): 00534 if not hasattr(self, "__globals__") or self.__globals__ == None : 00535 self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals 00536 if ipython_globals == None: 00537 myf=self.__globals__ 00538 else: 00539 myf=ipython_globals 00540 00541 a = odict() 00542 a['vis'] = '' 00543 a['imagename'] = '' 00544 a['imsize'] = [256, 256] 00545 a['cell'] = ['1.0arcsec', '1.0arcsec'] 00546 a['phasecenter'] = '' 00547 a['stokes'] = 'I' 00548 a['mask'] = '' 00549 a['field'] = '' 00550 a['spw'] = '' 00551 a['ftmachine'] = 'ft' 00552 a['alg'] = 'clark' 00553 a['cyclefactor'] = 1.5 00554 a['niter'] = 500 00555 a['gain'] = 0.1 00556 a['threshold'] = '0.0Jy' 00557 a['weighting'] = 'natural' 00558 a['mode'] = 'continuum' 00559 a['interactive'] = False 00560 a['overwrite'] = True 00561 a['uvtaper'] = False 00562 a['timerange'] = '' 00563 a['uvrange'] = '' 00564 a['antenna'] = '' 00565 a['scan'] = '' 00566 a['observation'] = '' 00567 a['pbcor'] = False 00568 a['minpb'] = 0.2 00569 a['clusterdef'] = '' 00570 00571 a['async']=False 00572 a['mode'] = { 00573 0:odict([{'value':'continuum'}, {'nterms':1}]), 00574 1:odict([{'value':'mfs'}, {'nterms':1}]), 00575 2:odict([{'value':'cube'}, {'start':0}, {'nchan':2}, {'width':1}, {'restfreq':''}]), 00576 3:odict([{'value':'channel'}, {'start':0}, {'nchan':2}, {'width':1}, {'restfreq':''}]), 00577 4:odict([{'value':'frequency'}, {'start':'0GHz'}, {'nchan':2}, {'width':'1Hz'}, {'restfreq':''}]), 00578 5:odict([{'value':'velocity'}, {'start':'0km/s'}, {'nchan':2}, {'width':'1m/s'}, {'restfreq':''}])} 00579 a['cyclefactor'] = { 00580 0:{'value':1.5}, 00581 1:odict([{'value':0.0}, {'majorcycles':1}])} 00582 a['ftmachine'] = { 00583 0:{'value':'ft'}, 00584 1:odict([{'value':'wproject'}, {'wprojplanes':128}, {'facets':1}]), 00585 2:{'value':'mosaic'}, 00586 3:{'value':'sd'}} 00587 a['alg'] = { 00588 0:{'value':'clark'}, 00589 1:{'value':'hogbom'}, 00590 2:odict([{'value':'multiscale'}, {'scales':[1]}])} 00591 a['weighting'] = { 00592 0:{'value':'natural'}, 00593 1:{'value':'radial'}, 00594 2:{'value':'uniform'}, 00595 3:odict([{'value':'briggs'}, {'robust':0.0}, {'npixels':0}]), 00596 4:odict([{'value':'briggsabs'}, {'npixels':0}, {'robust':0.0}]), 00597 5:{'value':'radial'}, 00598 6:odict([{'value':'superuniform'}, {'npixels':0}])} 00599 a['uvtaper'] = { 00600 0:{'value':False}, 00601 1:odict([{'value':True}, {'outertaper':[]}])} 00602 a['interactive'] = { 00603 0:{'value':False}, 00604 1:odict([{'value':True}, {'npercycle':100}])} 00605 00606 ### This function sets the default values but also will return the list of 00607 ### parameters or the default value of a given parameter 00608 if(param == None): 00609 myf['__set_default_parameters'](a) 00610 elif(param == 'paramkeys'): 00611 return a.keys() 00612 else: 00613 if(paramvalue==None and subparam==None): 00614 if(a.has_key(param)): 00615 return a[param] 00616 else: 00617 return self.itsdefault(param) 00618 else: 00619 retval=a[param] 00620 if(type(a[param])==dict): 00621 for k in range(len(a[param])): 00622 valornotval='value' 00623 if(a[param][k].has_key('notvalue')): 00624 valornotval='notvalue' 00625 if((a[param][k][valornotval])==paramvalue): 00626 retval=a[param][k].copy() 00627 retval.pop(valornotval) 00628 if(subparam != None): 00629 if(retval.has_key(subparam)): 00630 retval=retval[subparam] 00631 else: 00632 retval=self.itsdefault(subparam) 00633 else: 00634 retval=self.itsdefault(subparam) 00635 return retval 00636 00637 00638 # 00639 # 00640 def check_params(self, param=None, value=None, ipython_globals=None): 00641 if ipython_globals == None: 00642 myf=self.__globals__ 00643 else: 00644 myf=ipython_globals 00645 # print 'param:', param, 'value:', value 00646 try : 00647 if str(type(value)) != "<type 'instance'>" : 00648 value0 = value 00649 value = myf['cu'].expandparam(param, value) 00650 matchtype = False 00651 if(type(value) == numpy.ndarray): 00652 if(type(value) == type(value0)): 00653 myf[param] = value.tolist() 00654 else: 00655 #print 'value:', value, 'value0:', value0 00656 #print 'type(value):', type(value), 'type(value0):', type(value0) 00657 myf[param] = value0 00658 if type(value0) != list : 00659 matchtype = True 00660 else : 00661 myf[param] = value 00662 value = myf['cu'].verifyparam({param:value}) 00663 if matchtype: 00664 value = False 00665 except Exception, instance: 00666 #ignore the exception and just return it unchecked 00667 myf[param] = value 00668 return value 00669 # 00670 # 00671 def description(self, key='pclean', subkey=None): 00672 desc={'pclean': 'Invert and deconvolve images with parallel engines', 00673 'vis': 'Name of input visibility file', 00674 'imagename': 'Pre-name of output images', 00675 'imsize': 'Image size in pixels (nx,ny), symmetric for single value', 00676 'cell': 'The image cell size in arcseconds. ', 00677 'phasecenter': 'Image center: direction or field index', 00678 'stokes': 'Stokes params to image (eg I,IV,IQ,IQUV)', 00679 'mask': 'mask image', 00680 'field': 'Field Name or id', 00681 'spw': 'Spectral windows e.g. \'0~3\', \'\' is all', 00682 'ftmachine': 'Fourier Transform Engine (\'ft\', \'sd\', \'mosaic\' or \'wproject\')', 00683 'alg': 'Deconvolution algorithm (\'clark\', \'hogbom\', \'multiscale\')', 00684 'scales': 'Scales to use in deconvolution', 00685 'cyclefactor': 'Control number of major cycle, threshold of cycle=residualPeak*psfSidelobe*cyclefactor ', 00686 'majorcycles': 'Number of major cycles', 00687 'niter': 'Maximum number of iterations', 00688 'gain': 'Gain to use in deconvolution', 00689 'threshold': 'Flux level to stop cleaning, must include units: \'1.0mJy\'', 00690 'weighting': 'Type of weighting', 00691 'robust': 'Briggs robustness parameter', 00692 'npixels': 'number of pixels for superuniform or briggs weighting', 00693 'mode': 'Clean mode (\'continuum\', \'cube\')', 00694 'nterms': 'number of terms for multifrequency synthesis', 00695 'start': 'Begin the output cube at the frequency of this channel in the MS in channel number or frequency or velocity', 00696 'nchan': 'Number of channels (planes) in output image', 00697 'width': 'width of output channel ', 00698 'restfreq': 'rest frequency to assign to image cube for velocity translattion', 00699 'interactive': 'Interactive clean', 00700 'npercycle': 'niter per cycle of interactive clean', 00701 'wprojplanes': 'Number of w-projection planes for convolution', 00702 'facets': 'Number of facats along each axis', 00703 'overwrite': 'Overwrite an existing model image', 00704 'uvtaper': 'Apply additional uv tapering of visibilities', 00705 'outertaper': 'uv-taper on outer baselines in uv-plane', 00706 'timerange': 'Range of time to select from data', 00707 'uvrange': 'Select data within uvrange ', 00708 'antenna': 'Select data based on antenna/baseline', 00709 'scan': 'Scan number range', 00710 'observation': 'Observation ID range', 00711 'pbcor': 'Correct for the primary beam post deconvolution', 00712 'minpb': 'Fractional of peak of pb coverage where to stop the pb correction', 00713 'clusterdef': 'File that contains cluster definition', 00714 00715 'async': 'If true the taskname must be started using pclean(...)' 00716 } 00717 00718 # 00719 # Set subfields defaults if needed 00720 # 00721 00722 if(desc.has_key(key)) : 00723 return desc[key] 00724 00725 def itsdefault(self, paramname) : 00726 a = {} 00727 a['vis'] = '' 00728 a['imagename'] = '' 00729 a['imsize'] = [256, 256] 00730 a['cell'] = ['1.0arcsec', '1.0arcsec'] 00731 a['phasecenter'] = '' 00732 a['stokes'] = 'I' 00733 a['mask'] = '' 00734 a['field'] = '' 00735 a['spw'] = '' 00736 a['ftmachine'] = 'ft' 00737 a['alg'] = 'clark' 00738 a['scales'] = [0] 00739 a['cyclefactor'] = 1.5 00740 a['majorcycles'] = 1 00741 a['niter'] = 500 00742 a['gain'] = 0.1 00743 a['threshold'] = '0.0Jy' 00744 a['weighting'] = 'natural' 00745 a['robust'] = 0.0 00746 a['npixels'] = 0 00747 a['mode'] = 'continuum' 00748 a['nterms'] = 1 00749 a['start'] = 0 00750 a['nchan'] = 1 00751 a['width'] = 1 00752 a['restfreq'] = '' 00753 a['interactive'] = False 00754 a['npercycle'] = 100 00755 a['wprojplanes'] = 128 00756 a['facets'] = 1 00757 a['overwrite'] = True 00758 a['uvtaper'] = False 00759 a['outertaper'] = [''] 00760 a['timerange'] = '' 00761 a['uvrange'] = '' 00762 a['antenna'] = '' 00763 a['scan'] = '' 00764 a['observation'] = '' 00765 a['pbcor'] = False 00766 a['minpb'] = 0.2 00767 a['clusterdef'] = '' 00768 00769 #a = sys._getframe(len(inspect.stack())-1).f_globals 00770 00771 if self.parameters['mode'] == 'continuum': 00772 a['nterms'] = 1 00773 00774 if self.parameters['mode'] == 'mfs': 00775 a['nterms'] = 1 00776 00777 if self.parameters['mode'] == 'cube': 00778 a['start'] = 0 00779 a['nchan'] = 2 00780 a['width'] = 1 00781 a['restfreq'] = '' 00782 00783 if self.parameters['mode'] == 'channel': 00784 a['start'] = 0 00785 a['nchan'] = 2 00786 a['width'] = 1 00787 a['restfreq'] = '' 00788 00789 if self.parameters['mode'] == 'frequency': 00790 a['start'] = '0GHz' 00791 a['nchan'] = 2 00792 a['width'] = '1Hz' 00793 a['restfreq'] = '' 00794 00795 if self.parameters['mode'] == 'velocity': 00796 a['start'] = '0km/s' 00797 a['nchan'] = 2 00798 a['width'] = '1m/s' 00799 a['restfreq'] = '' 00800 00801 if self.parameters['cyclefactor'] == 0.0: 00802 a['majorcycles'] = 1 00803 00804 if self.parameters['ftmachine'] == 'wproject': 00805 a['wprojplanes'] = 128 00806 a['facets'] = 1 00807 00808 if self.parameters['alg'] == 'multiscale': 00809 a['scales'] = [1] 00810 00811 if self.parameters['weighting'] == 'briggs': 00812 a['robust'] = 0.0 00813 a['npixels'] = 0 00814 00815 if self.parameters['weighting'] == 'briggsabs': 00816 a['npixels'] = 0 00817 a['robust'] = 0.0 00818 00819 if self.parameters['weighting'] == 'superuniform': 00820 a['npixels'] = 0 00821 00822 if self.parameters['uvtaper'] == True: 00823 a['outertaper'] = [] 00824 00825 if self.parameters['interactive'] == True: 00826 a['npercycle'] = 100 00827 00828 if a.has_key(paramname) : 00829 return a[paramname] 00830 pclean_cli = pclean_cli_()