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_flagcmd import flagcmd 00016 from task_flagcmd import casalog 00017 00018 class flagcmd_pg_: 00019 __name__ = "flagcmd" 00020 00021 def __init__(self) : 00022 self.__bases__ = (flagcmd_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, vis=None, inpmode=None, inpfile=None, tablerows=None, reason=None, useapplied=None, tbuff=None, ants=None, action=None, flagbackup=None, clearall=None, rowlist=None, plotfile=None, savepars=None, outfile=None, async=None): 00027 00028 """Flagging task based on batches of flag-commands 00029 00030 Flag commands follow the mode and parameter names from the flagdata task 00031 (also explained below). The available modes are: manual, clip, shadow, quack, 00032 elevation, tfcrop, rflag, extend and unflag. 00033 00034 The flagcmd task will flag data based on the commands input on inpmode: 00035 table = input from FLAG_CMD table in MS 00036 list = input from a file or a (Python) list of command strings 00037 xml = input from Flag.xml in the MS given by vis 00038 00039 Batch operations include : apply/unapply/list/plot/clear/extract 00040 00041 IMPORTANT: The FLAG_CMD sub-table is meant only for meta-data selections such as online flags. 00042 Using it to save other parameters (from modes such as clip, quack, shadow, etc) is 00043 possible but carries a risk that in future releases these parameters maybe renamed 00044 or changed their default values. Use it at your own risk! There will be no automatic 00045 way to rename any parameter that changes in the future. 00046 00047 NOTE on flagging calibration tables. 00048 ----------------------------------- 00049 00050 It is possible to flag cal tables using this task, although we recommend using the flagdata 00051 task for this. 00052 00053 When using this task to flag cal tables, only the apply and list actions are supported. 00054 Because cal tables do not have a FLAG_CMD sub-table, the default inpmode='table' can only 00055 be used if an MS is given in the inpfile parameter so that flags from the MS are applied to 00056 the cal table. Otherwise, the flag commands must be given using inpmode='list', either from a 00057 file or from a list of strings. See below for more information about these parameters. 00058 Data selection for calibration tables is limited to field, antenna and spw at the moment. 00059 00060 00061 Keyword arguments: 00062 00063 vis -- Name of input visibility file or calibration table. 00064 default: '' (none) 00065 example1: vis='uid___A002_X2a5c2f_X54.ms' or 00066 example2: vis='cal-X54.B1' 00067 00068 -- INPUT of flag commands -- 00069 00070 inpmode -- Input mode for flag commands. 00071 options: 'table','list','xml' 00072 default: 'table' 00073 00074 inpmode "table" -- input commands from FLAG_CMD table of MS. 00075 00076 inpfile -- path to MS containing FLAG_CMD 00077 default: '' (read from FLAG_CMD table in the MS specified via 'vis') 00078 00079 Main use is to read flags from internal FLAG_CMD, 00080 but by setting inpfile to a different MS you can 00081 use this to copy the flags from one MS to another. 00082 00083 One use case is to read the flag commands from an MS given in 00084 inpfile and apply them to a cal table given in vis. Example: 00085 00086 flagcmd(vis='cal-X54.B1', inpmode='table', inpfile='uid___A002_X2a5c2f_X54.ms', action='apply') 00087 00088 tablerows -- list of rows of the FLAG_CMD table to read 00089 default: [] (read all rows) 00090 example: [0,1,2,10] 00091 00092 NOTE: currently only takes integer lists, not 00093 parseable strings with ranges. Use the Python 00094 range function to generate ranges, e.g. 00095 tablerows = range(0,30) + range(50,55) 00096 instead of '0~29,50~54' for now. 00097 00098 reason -- select flag commands based on REASON(s) 00099 default: 'any' (all flags regardless of reason) 00100 can be a string, or list of strings 00101 example: reason='FOCUS_ERROR' 00102 reason=['FOCUS_ERROR','SUBREFLECTOR_ERROR'] 00103 00104 NOTE: what is within the string is literally 00105 mateched, e.g. reason='' matches only blank reasons, 00106 and reason = 'FOCUS_ERROR,SUBREFLECTOR_ERROR' 00107 matches this compound reason string only 00108 00109 useapplied -- select the flag commands of rows that have APPLIED=True 00110 options: True,False 00111 default: False 00112 00113 If useapplied=True it will read in both applied and 00114 unapplied flags 00115 00116 00117 inpmode "list" -- input commands from an ASCII file or via a list of strings. 00118 00119 inpfile -- name of an ASCII file or a list of strings. 00120 default: '' 00121 options: [] or '' with filename. 00122 example1: the following commands can be saved into a file and given 00123 to the task (e.g. save it to flags.txt). 00124 00125 scan='1~3' mode='manual' 00126 mode='clip' clipminmax=[0,2] correlation='ABS_XX' clipoutside=False 00127 spw='9' mode='tfcrop' correlation='ABS_YY' ntime=51.0 00128 mode='extend' extendpols=True 00129 00130 flagcmd(vis, inpmode='list',inpfile='flags.txt') 00131 00132 example2: the same commands can be written in a Python list of strings and given 00133 to the task. 00134 cmd=["scan='1~3' mode='manual'", 00135 "mode='clip' clipminmax=[0,2] correlation='ABS_XX' clipoutside=False", 00136 "spw='9' mode='tfcrop' correlation='ABS_YY' ntime=51.0", 00137 "mode='extend' extendpols=True"] 00138 00139 flagcmd(vis, inpmode='list',inpfile=cmd) 00140 00141 00142 reason -- select flag commands based on REASON(s) 00143 default: 'any' (all flags regardless of reason) 00144 can be a string, or list of strings 00145 example: reason='FOCUS_ERROR' 00146 reason=['FOCUS_ERROR','SUBREFLECTOR_ERROR'] 00147 00148 NOTE: what is within the string is literally 00149 mateched, e.g. reason='' matches only blank reasons, 00150 and reason = 'FOCUS_ERROR,SUBREFLECTOR_ERROR' 00151 matches this compound reason string only 00152 00153 00154 inpmode "xml" -- input online flags from Flag.xml file in the MS. This mode 00155 is not available for cal tables. 00156 00157 tbuff -- (float) time padding buffer (seconds, default=1.0) 00158 00159 ants -- select flags based on antenna, 00160 e.g. antenna='ea01' 00161 default: '' (all flags regardless of antenna) 00162 00163 reason -- select flag commands based on REASON(s), 00164 default: 'Any' (all flags regardless of reason) 00165 can be a string, or list of strings 00166 example: reason='FOCUS_ERROR' 00167 reason=['FOCUS_ERROR','SUBREFLECTOR_ERROR'] 00168 00169 NOTE: what is within the string is literally 00170 mateched, e.g. reason='' matches only blank reasons, 00171 and reason = 'FOCUS_ERROR,SUBREFLECTOR_ERROR' 00172 matches this compound reason string only 00173 00174 --ACTIONS-- 00175 00176 action -- operation to perform on MS and/or in flag commands from inpfile 00177 options: 'apply','clear','list','plot','unapply','extract' 00178 default: 'apply' 00179 00180 action "apply" -- apply flags to MS or cal table. 00181 00182 This operation will apply the commands chosen by inpmode. 00183 If inpmode='table' it will set the APPLIED column to True. 00184 00185 flagbackup -- Automatically backup MS/cal table FLAG column before applying. 00186 options: True,False 00187 default: True 00188 00189 00190 action "unapply" -- unapply flags in MS. (Not available for cal tables) 00191 00192 This operation will unapply the commands chosen by inpmode. 00193 If inpmode='table' it will set the APPLIED column to False. 00194 00195 IMPORTANT: In order to guarantee that only the data selected in 00196 the command is unapplied, the framework will first unapply the selected 00197 rows and then re-apply the overlapping data that got unapplied in the 00198 first pass. This is a true unapply action, but it will take longer to 00199 process because it will re-apply all the remaining commands that have 00200 APPLIED = True! 00201 00202 flagbackup -- Automatically backup MS FLAG column before unapplying? 00203 options: True,False 00204 default: True 00205 00206 00207 action "list" -- list and/or save flag commands. 00208 00209 This operation will list the commands chosen by inpmode on the screen 00210 and save them to the MS or to a file without applying. It will save the commands 00211 to outfile if the parameter savepars is set to True. If outfile is None, it 00212 will save the commands to the MS given in vis. 00213 00214 00215 action "plot" -- plot flags (ant vs. time). (Not available for cal tables) 00216 00217 This operation will plot the flags chosen by inpmode to a 00218 matplotlib gui or to a file. These will be sorted by 00219 antenna vs. time. Most useful for showing the online 00220 flags. 00221 00222 plotfile -- output plot file 00223 default: '' (plot to matplotlib window) 00224 00225 WARNING: will only reliably plot individual flags 00226 per antenna and timerange (e.g. direct from xml) 00227 00228 action "clear" -- clear flags from FLAG_CMD in MS. (Not available for cal tables) 00229 00230 This operation will delete the selected flag rows from 00231 the internal FLAG_CMD table of the MS. 00232 00233 NOTE: choosing this option will disregard anything you 00234 set in inpmode and will always work on the FLAG_CMD table 00235 in vis. 00236 00237 clearall -- really clear all flags? 00238 default: False (will not clear) 00239 00240 rowlist -- list of FLAG_CMD rows to clear 00241 default: [] (all flags in table) 00242 example: [0,1,2,10] 00243 00244 NOTE: currently only takes integer lists, not 00245 parseable strings with ranges. Use the Python 00246 range function to generate ranges, e.g. 00247 rowlist = range(0,30) + range(50,55) 00248 instead of '0~29,50~54' for now. 00249 00250 WARNING: this can be dangerous, and you must set clearall=True 00251 to use this!!! This will delete the specified rows from the 00252 internal FLAG_CMD table for vis regardless of what mode is set 00253 to (useful for when you import from xml or file), and decide to 00254 redo it). This action will NOT unapply the commands. 00255 00256 00257 action "extract" -- extract internal flag dictionary. (Not available for cal tables) 00258 00259 This option will return the internal flagging dictionary to 00260 python. 00261 00262 00263 savepars -- Save the flag commands to the FLAG_CMD table of the MS or to an output text file. 00264 default: False 00265 options: True/False 00266 00267 outfile -- Name of output file to save the flag commands. 00268 default: ' '; it will save the commands in the FLAG_CMD table of the MS. 00269 example: outfile='flags.txt' will save the parameters in a text file. 00270 00271 =========================================================================== 00272 00273 -- Internal FLAG_CMD input 'inpmode' useage -- 00274 00275 (For inpmode='table') 00276 00277 * It is a good idea to use action='list' first to see what is there 00278 before doing anything else, e.g. 00279 00280 inpmode = 'table' 00281 action = 'list' 00282 00283 * To apply the flags stored in the FLAG_CMD table in the MS, 00284 simply set inpmode='table' and action='apply', e.g. 00285 00286 inpmode = 'table' 00287 action = 'apply' 00288 useapplied = False 00289 00290 This is the default setup of flagcmd. 00291 00292 * To merely save to FLAG_CMD but not apply, then 00293 00294 inpmode = 'table' 00295 inpfile = 'other.ms' 00296 action = 'list' 00297 00298 * To save commands from a file into the MS without applying. 00299 00300 inpmode = 'list' 00301 inpfile = 'flags.txt' 00302 action = 'list' 00303 00304 If you need to select only certain rows from the FLAG_CMD table, 00305 use the tablerows parameter to control this. Currently this must 00306 be a list of individual row numbers (0-based), e.g. 00307 00308 tablerows = [0,1,2,3,10,11] 00309 00310 or 00311 00312 tablerows = range(29) 00313 00314 NOTE: the useapplied=True/False tag is important if you are 00315 going to (re)apply flags marked as APPLIED True in FLAG_CMD. 00316 It is common to have a "failed" flagging operation mark the flags 00317 as already applied and then they don't show up when you re-run 00318 (e.g. in 'list'). Set useapplied=True so that it will use these 00319 anyway. 00320 00321 * To apply the flag commands from an MS to a calibration table. 00322 00323 vis = 'mycaltable' 00324 inpmode = 'table' 00325 inpfile = 'myMS.ms' 00326 action = 'apply' 00327 00328 00329 -- Online flag input inpmode useage -- 00330 00331 (For inpmode='xml') 00332 00333 * To list the online flags stored in the Flag.xml file in the 00334 MS, simply set: 00335 00336 inpmode = 'xml' 00337 action = 'list' 00338 savepars = False 00339 00340 * It is then straightforward to save these to FLAG_CMD 00341 00342 inpmode = 'xml' 00343 action = 'list' 00344 savepars = True 00345 00346 * To directly apply the online flags stored in the Flag.xml file in the 00347 MS, set inpmode='xml' and desired buffer, e.g. 00348 00349 inpmode = 'xml' 00350 tbuff = 1.0 # pad flag times by 1 sec 00351 action = 'apply' 00352 set savepars to save or not the commands in the MS 00353 00354 * You can also specify a set of reasons (a comma separated list) 00355 for flags to apply, e.g. 00356 00357 reason = 'FOCUS_ERROR,SUBREFLECTOR_ERROR' # select these flags 00358 reason = 'ANTENNA_NOT_ON_SOURCE' 00359 00360 NOTE: The online flag time buffer tbuff is specified in 00361 seconds, but in fact should be keyed to the intrinsic online 00362 integration time. This is particularly true for EVLA data, 00363 were a tbuff value of 0.5x to 1.5x the integration time is 00364 needed (currently you should use 1.5x for data taken in 00365 early 2011 or before). 00366 00367 Because the Flag.xml is copied to the MS by importevla, 00368 you can re-apply the online flags with an increased tbuff 00369 simply by running with inpmode='xml' and optype='apply', e.g. 00370 00371 inpmode = 'xml' 00372 tbuff = 15.0 # pad flag times by 15 sec for 10sec integrations 00373 optype = 'apply' 00374 00375 if you originally used a smaller value (e.g. 1.0) by mistake 00376 or you want to try longer values. Note these will be added to 00377 the FLAG_CMD table which you would have to clean up manually 00378 if you care about this. 00379 00380 00381 -- Flag command useage -- 00382 00383 (For inpmode='list') 00384 00385 * For example, a series of commands might be: 00386 00387 antenna='ea01' timerange='00:00:00~01:00:00' 00388 antenna='ea11' timerange='00:00:00~03:00:00' spw='0~4' 00389 mode='clip' clipminmax=[0,5] correlation='ABS_ALL' 00390 mode='quack' quackmode='end' quackinterval=1.0 00391 mode='shadow' 00392 00393 Any other mode can also use selection (see the help of flagdata): 00394 00395 mode='shadow' antenna='ea01,ea02,ea03' 00396 mode='quack' quackmode='end' quackinterval=1.0 antenna='ea22' 00397 00398 These commands can be saved in an ASCII file, e.g. "myflags.txt" 00399 and input using inpmode='list', e.g. 00400 00401 flagcmd(vis='myvis.ms',inpmode='list',inpfile='myflags.txt') 00402 00403 or input from the interface 00404 00405 flagcmd(vis='myvis.ms',inpmode='list', 00406 inpfile=["mode='shadow'", 00407 "mode='clip' clipminmax=[0,5] correlation='ABS_ALL'", 00408 "mode='quack' quackmode='end' quackinterval=1.0", 00409 "antenna='ea01' timerange='00:00:00~01:00:00'", 00410 "antenna='ea11' timerange='00:00:00~03:00:00' spw='0~4'"]) 00411 00412 00413 -- ACTIONs -- 00414 00415 The action parameter controls what flagcmd will actually do with the 00416 flag commands: 00417 00418 * action = 'apply' 00419 00420 This will apply the selected commands to the data. 00421 00422 If inpmode='table' and inpfile='' then the APPLIED column in FLAG_CMD 00423 will be set to True. 00424 00425 * action = 'unapply' 00426 00427 This will effectively unapply any commands on the selected data. 00428 00429 * action = 'list' 00430 00431 List what is selected and or save in the MS or in a file. It is wise to do 00432 this first before doing any other action. It will list the output in the logger 00433 and save them to the FLAG_CMD table of the MS when savepars=True and outfile = '' or 00434 to a file if outfile is non-blank. 00435 00436 * action = 'plot' 00437 00438 Will pop up a little matplotlib GUI (if outfile='') or plot to a 00439 file. Currently only gives an antenna vs time plot, mostly useful 00440 for looking at the online flags. 00441 00442 * action = 'clear' 00443 00444 DANGER! This can be used to totally delete rows from the FLAG_CMD 00445 table. It ignores what inpmode is pointing to and always works 00446 on FLAG_CMD. Use at your own peril but sometimes you need to just 00447 blow that table away, e.g. 00448 00449 vis = msfile 00450 optype = 'clear' 00451 rowlist = [] # all rows 00452 clearall = True # disarm the safety 00453 00454 Note you have to explicitly set clearall=True to arm the deletion 00455 (a minimal precaution). 00456 00457 * action = 'extract' 00458 00459 This option will return the internal flagging dictionary to 00460 python. This will allow a power-user to manipulate these 00461 commands directly (e.g. for plotting etc.). For example, 00462 00463 myflagd = flagcmd(vis=msfile,useapplied=True,action='extract') 00464 00465 will extract all the commands (including those already applied) 00466 in the FLAG_CMD MS table. 00467 00468 NOTE: There is no extant description of the format of this 00469 dictionary, as it is an internal device used by the flagcmd 00470 task. This action is provided for the convenience of 00471 advanced users. 00472 00473 00474 ------- FLAG COMMAND SYNTAX ------- 00475 00476 The command syntax is based on the flagdata parameters. 00477 00478 Basic Syntax Rules 00479 00480 Commands are a string (which may contain internal "strings") consisting of 00481 KEY=VALUE pairs separated by whitespace (see examples below). 00482 00483 NOTE: There should be no whitespace between KEY=VALUE or within each KEY or 00484 VALUE, since the simple parser first breaks command lines on whitespace, 00485 then on "=". 00486 00487 Each key should only appear once on a given command line/string 00488 00489 There is an implicit "mode" for each command, with the default 00490 being 'manual' if not given. 00491 00492 Comment lines can start with '#' and will be ignored. 00493 00494 00495 1. Data selection parameters (used by all flagging modes) 00496 00497 timerange='' 00498 antenna='' 00499 spw='' 00500 correlation='' 00501 field='' 00502 scan='' 00503 feed='' 00504 array='' 00505 uvrange='' 00506 intent='' 00507 observation='' 00508 00509 Note: a command consisting only of selection key-value pairs is a 00510 basic "manual" operation, ie. flag the data meeting the selection. 00511 00512 00513 2. Modes specific parameters with default values (for further details and updated 00514 default values, refer to the task flagdata). 00515 00516 2.1 Mode manual. 00517 autocorr=False 00518 00519 2.2 Mode clip. 00520 datacolumn='DATA' 00521 clipminmax=[] 00522 clipoutside=True 00523 channelavg=False 00524 clipzeros=False 00525 00526 2.3 Mode shadow. 00527 tolerance=0.0 00528 addantenna='' 00529 00530 2.4 Mode quack. 00531 quackinterval=1.0 00532 quackmode='beg' 00533 quackincrement=False 00534 00535 2.5 Mode elevation. 00536 lowerlimit=0.0 00537 upperlimit=90.0 00538 00539 2.6 Mode tfcrop. 00540 ntime='scan' 00541 combinescans=False 00542 datacolumn='DATA' 00543 timecutoff=4.0 00544 freqcutoff=3.0 00545 timefit='line' 00546 freqfit='poly' 00547 maxnpieces=7 00548 flagdimension='freqtime' 00549 usewindowstats='none' 00550 halfwin=1 00551 00552 2.7 Mode extend. 00553 ntime='scan' 00554 combinescans=False 00555 extendpols=True 00556 growtime=50.0 00557 growfreq=50.0 00558 growaround=False 00559 flagneartime=False 00560 flagnearfreq=False 00561 00562 2.8 Mode rflag. 00563 ntime='scan' 00564 combinescans=False 00565 datacolumn='DATA' 00566 winsize=3 00567 timedev='' 00568 freqdev='' 00569 timedevscale=5.0 00570 freqdevscale=5.0 00571 spectralmax=1000000.0 00572 spectralmin=0.0 00573 00574 2.9 Mode unflag. 00575 00576 00577 3. Basic elaboration options for online and interface use 00578 00579 id='' # flag ID tag (not necessary) 00580 reason='' # reason string for flag 00581 flagtime='' # a timestamp for when this flag was generated (for 00582 user history use) 00583 00584 NOTE: there is no flagtime column in FLAG_CMD at 00585 this time, but we will propose to add this as an 00586 optional column 00587 00588 NOTE: These are currently ignored and not used. 00589 00590 4. Extended elaboration options for online and interface use 00591 Note: these are FLAG_CMD columns, but their use is not clear but included 00592 here for compatibility and future expansion 00593 00594 level=N # flagging "level" for flags with same reason 00595 severity=N # Severity code for the flag, on a scale of 0-10 in order 00596 of increasing severity; user specified 00597 00598 00599 00600 """ 00601 a=inspect.stack() 00602 stacklevel=0 00603 for k in range(len(a)): 00604 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00605 stacklevel=k 00606 break 00607 myf=sys._getframe(stacklevel).f_globals 00608 myf['__last_task'] = 'flagcmd' 00609 myf['taskname'] = 'flagcmd' 00610 ### 00611 myf['update_params'](func=myf['taskname'],printtext=False) 00612 ### 00613 ### 00614 #Handle globals or user over-ride of arguments 00615 # 00616 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00617 useLocalDefaults = False 00618 00619 for item in function_signature_defaults.iteritems(): 00620 key,val = item 00621 keyVal = eval(key) 00622 if (keyVal == None): 00623 #user hasn't set it - use global/default 00624 pass 00625 else: 00626 #user has set it - use over-ride 00627 if (key != 'self') : 00628 useLocalDefaults = True 00629 #myf[key]=keyVal 00630 00631 myparams = {} 00632 if useLocalDefaults : 00633 for item in function_signature_defaults.iteritems(): 00634 key,val = item 00635 keyVal = eval(key) 00636 exec('myparams[key] = keyVal') 00637 if (keyVal == None): 00638 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00639 keyVal = eval(key) 00640 if(type(keyVal) == dict) : 00641 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00642 00643 else : 00644 uselessvariable = None 00645 myparams['vis'] = vis = myf['vis'] 00646 myparams['inpmode'] = inpmode = myf['inpmode'] 00647 myparams['inpfile'] = inpfile = myf['inpfile'] 00648 myparams['tablerows'] = tablerows = myf['tablerows'] 00649 myparams['reason'] = reason = myf['reason'] 00650 myparams['useapplied'] = useapplied = myf['useapplied'] 00651 myparams['tbuff'] = tbuff = myf['tbuff'] 00652 myparams['ants'] = ants = myf['ants'] 00653 myparams['action'] = action = myf['action'] 00654 myparams['flagbackup'] = flagbackup = myf['flagbackup'] 00655 myparams['clearall'] = clearall = myf['clearall'] 00656 myparams['rowlist'] = rowlist = myf['rowlist'] 00657 myparams['plotfile'] = plotfile = myf['plotfile'] 00658 myparams['savepars'] = savepars = myf['savepars'] 00659 myparams['outfile'] = outfile = myf['outfile'] 00660 00661 if type(tablerows)==int: tablerows=[tablerows] 00662 if type(rowlist)==int: rowlist=[rowlist] 00663 00664 result = None 00665 00666 # 00667 # The following is work around to avoid a bug with current python translation 00668 # 00669 mytmp = {} 00670 00671 mytmp['vis'] = vis 00672 mytmp['inpmode'] = inpmode 00673 mytmp['inpfile'] = inpfile 00674 mytmp['tablerows'] = tablerows 00675 mytmp['reason'] = reason 00676 mytmp['useapplied'] = useapplied 00677 mytmp['tbuff'] = tbuff 00678 mytmp['ants'] = ants 00679 mytmp['action'] = action 00680 mytmp['flagbackup'] = flagbackup 00681 mytmp['clearall'] = clearall 00682 mytmp['rowlist'] = rowlist 00683 mytmp['plotfile'] = plotfile 00684 mytmp['savepars'] = savepars 00685 mytmp['outfile'] = outfile 00686 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00687 trec = casac.utils().torecord(pathname+'flagcmd.xml') 00688 00689 casalog.origin('flagcmd') 00690 if not trec.has_key('flagcmd') or not casac.utils().verify(mytmp, trec['flagcmd']) : 00691 return False 00692 00693 00694 try : 00695 casalog.post('') 00696 casalog.post('##########################################') 00697 casalog.post('##### Begin Task: flagcmd #####') 00698 casalog.post('') 00699 result = flagcmd(vis, inpmode, inpfile, tablerows, reason, useapplied, tbuff, ants, action, flagbackup, clearall, rowlist, plotfile, savepars, outfile) 00700 casalog.post('') 00701 casalog.post('##### End Task: flagcmd #####') 00702 casalog.post('##########################################') 00703 00704 00705 # saveinputs for individule engine has no use 00706 # saveinputs should alos be removed from casa_in_py.py 00707 # 00708 # 00709 # saveinputs = myf['saveinputs'] 00710 # saveinputs('flagcmd', 'flagcmd.last', myparams) 00711 # 00712 # 00713 except Exception, instance: 00714 #print '**** Error **** ',instance 00715 pass 00716 00717 gc.collect() 00718 return result 00719 # 00720 # 00721 ## 00722 # def paramgui(self, useGlobals=True): 00723 # """ 00724 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00725 # """ 00726 # import paramgui 00727 # 00728 # a=inspect.stack() 00729 # stacklevel=0 00730 # for k in range(len(a)): 00731 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00732 # stacklevel=k 00733 # break 00734 # myf = sys._getframe(stacklevel).f_globals 00735 # 00736 # if useGlobals: 00737 # paramgui.setGlobals(myf) 00738 # else: 00739 # paramgui.setGlobals({}) 00740 # 00741 # paramgui.runTask('flagcmd', myf['_ip']) 00742 # paramgui.setGlobals({}) 00743 # 00744 # 00745 # 00746 # 00747 def defaults(self, param=None): 00748 a=inspect.stack() 00749 stacklevel=0 00750 for k in range(len(a)): 00751 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00752 stacklevel=k 00753 break 00754 myf=sys._getframe(stacklevel).f_globals 00755 a = odict() 00756 a['vis'] = '' 00757 a['inpmode'] = 'table' 00758 a['action'] = 'apply' 00759 a['savepars'] = False 00760 00761 a['async']=False 00762 a['inpmode'] = { 00763 0:odict([{'value':'table'}, {'inpfile':''}, {'tablerows':[]}, {'reason':'any'}, {'useapplied':False}]), 00764 1:odict([{'value':'list'}, {'inpfile':''}, {'reason':'any'}]), 00765 2:odict([{'value':'xml'}, {'tbuff':0.0}, {'ants':''}, {'reason':'any'}])} 00766 a['action'] = { 00767 0:odict([{'value':'apply'}, {'flagbackup':True}]), 00768 1:odict([{'value':'unapply'}, {'flagbackup':True}]), 00769 2:{'value':'list'}, 00770 3:odict([{'value':'plot'}, {'plotfile':''}]), 00771 4:odict([{'value':'clear'}, {'clearall':False}, {'rowlist':[]}])} 00772 a['savepars'] = { 00773 0:{'value':False}, 00774 1:odict([{'value':True}, {'outfile':''}])} 00775 00776 ### This function sets the default values but also will return the list of 00777 ### parameters or the default value of a given parameter 00778 if(param == None): 00779 myf['__set_default_parameters'](a) 00780 elif(param == 'paramkeys'): 00781 return a.keys() 00782 else: 00783 if(a.has_key(param)): 00784 #if(type(a[param]) == dict) : 00785 # return a[param][len(a[param])-1]['value'] 00786 #else : 00787 return a[param] 00788 00789 00790 # 00791 # 00792 def check_params(self, param=None, value=None): 00793 a=inspect.stack() 00794 stacklevel=0 00795 for k in range(len(a)): 00796 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00797 stacklevel=k 00798 break 00799 myf=sys._getframe(stacklevel).f_globals 00800 00801 # print 'param:', param, 'value:', value 00802 try : 00803 if str(type(value)) != "<type 'instance'>" : 00804 value0 = value 00805 value = myf['cu'].expandparam(param, value) 00806 matchtype = False 00807 if(type(value) == numpy.ndarray): 00808 if(type(value) == type(value0)): 00809 myf[param] = value.tolist() 00810 else: 00811 #print 'value:', value, 'value0:', value0 00812 #print 'type(value):', type(value), 'type(value0):', type(value0) 00813 myf[param] = value0 00814 if type(value0) != list : 00815 matchtype = True 00816 else : 00817 myf[param] = value 00818 value = myf['cu'].verifyparam({param:value}) 00819 if matchtype: 00820 value = False 00821 except Exception, instance: 00822 #ignore the exception and just return it unchecked 00823 myf[param] = value 00824 return value 00825 00826 # 00827 # 00828 def description(self, key='flagcmd', subkey=None): 00829 desc={'flagcmd': 'Flagging task based on batches of flag-commands', 00830 'vis': 'Name of MS file or calibration table to flag', 00831 'inpmode': 'Input mode for flag commands(table/list/xml)', 00832 'inpfile': 'Source of flag commands', 00833 'tablerows': 'Rows of inpfile to read', 00834 'reason': 'Select by REASON types', 00835 'useapplied': 'Select commands whose rows have APPLIED column set to True', 00836 'tbuff': 'Time buffer (sec) to pad flags', 00837 'ants': 'Allowed flag antenna names to select by', 00838 'action': 'Action to perform in MS and/or in inpfile (apply/unapply/list/plot/clear/extract)', 00839 'flagbackup': 'Automatically backup the FLAG column before execution', 00840 'clearall': 'Delete all rows from FLAG_CMD', 00841 'rowlist': 'FLAG_CMD rows to clear', 00842 'plotfile': 'Name of output file to save plot', 00843 'savepars': 'Save flag commands to the MS or to a file', 00844 'outfile': 'Name of output file to save commands', 00845 00846 'async': 'If true the taskname must be started using flagcmd(...)' 00847 } 00848 00849 # 00850 # Set subfields defaults if needed 00851 # 00852 00853 if(desc.has_key(key)) : 00854 return desc[key] 00855 00856 def itsdefault(self, paramname) : 00857 a = {} 00858 a['vis'] = '' 00859 a['inpmode'] = 'table' 00860 a['inpfile'] = '' 00861 a['tablerows'] = [] 00862 a['reason'] = 'any' 00863 a['useapplied'] = False 00864 a['tbuff'] = 0.0 00865 a['ants'] = '' 00866 a['action'] = 'apply' 00867 a['flagbackup'] = True 00868 a['clearall'] = False 00869 a['rowlist'] = [] 00870 a['plotfile'] = '' 00871 a['savepars'] = False 00872 a['outfile'] = '' 00873 00874 if a.has_key(paramname) : 00875 return a[paramname] 00876 flagcmd_pg = flagcmd_pg_()