Commits

Sandra M Castro authored 6415ee9f6fe
Replaced lociteritems and lociterkeys functions with dict.items and dict.keys
No tags

casatasks/src/private/task_flagcmd.py

Modified
1 -from __future__ import absolute_import
2 1 import os
3 2 import copy
4 3 import numpy as np
5 4 from collections import defaultdict
6 5
7 -# get is_CASA6 and is_python3
8 -from casatasks.private.casa_transition import *
9 -if is_CASA6:
10 - from casatasks import casalog
11 - from casatools import ms, quanta, table, agentflagger
12 - from .mstools import write_history
13 - from . import flaghelper as fh
14 -
15 - qalocal = quanta( )
16 - tblocal = table( )
17 -else:
18 - from taskinit import casalog, casac, qa, tb
19 - from mstools import write_history
20 - import flaghelper as fh
21 -
22 - # naked tool constructors ala CASA6
23 - agentflagger = casac.agentflagger
24 - ms = casac.ms
25 -
26 - # not really local
27 - qalocal = qa
28 - tblocal = tb
29 -
30 -# common function to use to get a dictionary item iterator
31 -if is_python3:
32 - def lociteritems(adict):
33 - return adict.items()
34 -else:
35 - def lociteritems(adict):
36 - return adict.iteritems()
6 +from casatasks import casalog
7 +from casatools import ms, quanta, table, agentflagger
8 +from .mstools import write_history
9 +from . import flaghelper as fh
10 +
11 +qalocal = quanta( )
12 +tblocal = table( )
37 13
38 14 def flagcmd(
39 15 vis=None,
40 16 inpmode=None,
41 17 inpfile=None,
42 18 tablerows=None,
43 19 reason=None,
44 20 useapplied=None,
45 21 tbuff=None,
46 22 ants=None,
396 372
397 373 else:
398 374 casalog.post('Warning: empty flag dictionary, nothing to plot'
399 375 )
400 376 elif action == 'extract':
401 377 # Make the command dictionary a string again
402 378 outdict = copy.deepcopy(myflagcmd)
403 379 for key in myflagcmd.keys():
404 380 cmddict = myflagcmd[key]['command']
405 381 cmdline = ""
406 - for k,v in lociteritems(cmddict):
382 + for k,v in cmddict.items():
407 383 cmdline = cmdline + k + '=' + str(v) + ' '
408 384 cmdline.rstrip()
409 385 outdict[key]['command'] = cmdline
410 386
411 387 casalog.post('Returning extracted dictionary')
412 388 return outdict
413 389
414 390
415 391 finally:
416 392 aflocal.done()
417 393
418 394 # Write history only to action='apply' or 'unapply'
419 395 # write history
420 396 if not iscal and (action == 'apply' or action == 'unapply'):
421 397 try:
422 398 param_names = flagcmd.__code__.co_varnames[:flagcmd.__code__.co_argcount]
423 - if is_python3:
424 - vars = locals( )
425 - param_vals = [vars[p] for p in param_names]
426 - else:
427 - param_vals = [eval(p) for p in param_names]
399 + vars = locals( )
400 + param_vals = [vars[p] for p in param_names]
428 401
429 402 write_history(mslocal, vis, 'flagcmd', param_names,
430 403 param_vals, casalog)
431 404
432 405 except Exception as instance:
433 406 casalog.post("*** Error \'%s\' updating HISTORY" % (instance),
434 407 'WARN')
435 408
436 409
437 410 # ************************************************************************
1028 1001 mydash=80*'-'
1029 1002 casalog.post('%-80s'%mydash)
1030 1003 for k in myflags.keys():
1031 1004 # time = myflags[k]['TIME']
1032 1005 row = myflags[k]['id']
1033 1006 reason = myflags[k]['reason']
1034 1007 applied = myflags[k]['applied']
1035 1008
1036 1009 cmddict = myflags[k]['command']
1037 1010 cmdline = ""
1038 - for key,val in lociteritems(cmddict):
1011 + for key,val in cmddict.items():
1039 1012 cmdstr = ""
1040 1013 if isinstance(val, str):
1041 1014 # Add quotes to string values
1042 1015 cmdstr = "'"+val+"'"
1043 1016 val = cmdstr
1044 1017 cmdline = cmdline + key + '=' + str(val) + ' '
1045 1018
1046 1019 # Print to logger
1047 1020 pstr = '%-8s %-32s %-7s %s' % (
1048 1021 row, reason,applied,cmdline)
1053 1026 casalog.post(phdr)
1054 1027 mydash=80*'-'
1055 1028 casalog.post('%-80s'%mydash)
1056 1029 for k in myflags.keys():
1057 1030 cmddict = myflags[k]['command']
1058 1031 reason = myflags[k]['reason']
1059 1032 if 'reason' in cmddict:
1060 1033 cmddict.pop('reason')
1061 1034
1062 1035 cmdline = ""
1063 - for key,val in lociteritems(cmddict):
1036 + for key,val in cmddict.items():
1064 1037 cmdstr = ""
1065 1038 if isinstance(val, str):
1066 1039 # Add quotes to string values
1067 1040 cmdstr = "'"+val+"'"
1068 1041 val = cmdstr
1069 1042 cmdline = cmdline + key + '=' + str(val) + ' '
1070 1043
1071 1044 # Print to logger
1072 1045 pstr = '%-8s %-32s %s' % (k, reason, cmdline)
1073 1046 casalog.post(pstr)
1228 1201
1229 1202 # Print out listing
1230 1203 if myantenna == '' or myantlist.count(ant) > 0:
1231 1204 if myreason == '' or myreaslist.count(reas) > 0:
1232 1205 if listmode == 'online':
1233 1206 pstr = '%8s %12s %8s %32s %48s' % (skey, fid, ant,
1234 1207 reas, timr)
1235 1208 elif listmode == 'cmd':
1236 1209 # Loop over dictionary with commands
1237 1210 cmdline = ""
1238 - for k,v in lociteritems(cmd):
1211 + for k,v in cmd.items():
1239 1212 cmdline = cmdline + k + '=' + str(v) + ' '
1240 1213
1241 1214 cmdline = cmdline.rstrip()
1242 1215 pstr = '%8s %45s %32s %6s %7s %3s %3s %s' % (
1243 1216 skey,
1244 1217 timr,
1245 1218 reas,
1246 1219 typ,
1247 1220 appl,
1248 1221 levl,
1249 1222 sevr,
1250 1223 cmdline,
1251 1224 )
1252 1225 else:
1253 1226 cmdline = ""
1254 - for k,v in lociteritems(cmd):
1227 + for k,v in cmd.items():
1255 1228 cmdline = cmdline + k + '=' + str(v) + ' '
1256 1229
1257 1230 cmdline = cmdline.rstrip()
1258 1231 pstr = '%8s %45s %32s %6s %7s %3s %3s %s' % (
1259 1232 skey,
1260 1233 timr,
1261 1234 reas,
1262 1235 typ,
1263 1236 appl,
1264 1237 levl,
1716 1689 readict[reas]['offset'] = offs
1717 1690 nlegend = len(reakeys)
1718 1691 casalog.post('Will plot ' + str(nlegend) + ' reasons in legend')
1719 1692
1720 1693 if plotname == '':
1721 1694 pl.ion()
1722 1695 else:
1723 1696 pl.ioff()
1724 1697
1725 1698 plotflagperant = defaultdict(list)
1726 - for ipf, flag in lociteritems(plotflag):
1699 + for ipf, flag in plotflag.items():
1727 1700 if not flag['show']:
1728 1701 continue
1729 1702 nflag = flag.copy()
1730 1703 nflag['color'] = readict[flag['reason']]['color']
1731 1704 nflag['offset'] = readict[flag['reason']]['offset']
1732 1705 plotflagperant[flag['antenna']].append(nflag)
1733 1706
1734 1707 nplotted = sum(len(x) for x in plotflagperant.values())
1735 1708 casalog.post('Plotted %d flags' % nplotted)
1736 1709

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut