Coverage for /wheeldirectory/casa-6.7.0-12-py3.10.el8/lib/py/lib/python3.10/site-packages/casatasks/private/mstools.py: 67%
43 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-10-31 19:10 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-10-31 19:10 +0000
3from casatools import ctsys
5def write_history(myms, vis, tname, param_names, param_vals, myclog=None, debug=False):
6 """
7 Update vis with the parameters that task tname was called with.
9 myms - an ms tool instance
10 vis - the MS to write to.
11 tname - name of the calling task.
12 param_names - list of parameter names.
13 param_vals - list of parameter values (in the same order as param_names).
14 myclog - a casalog instance (optional)
15 debug - Turns on debugging print statements on errors if True.
17 Example:
18 The end of split does
20 In python 2.x:
21 param_names = split.func_code.co_varnames[:split.func_code.co_argcount]
22 param_vals = [eval(p) for p in param_names] # Must be done in the task.
23 In python 3.x:
24 vars = locals( )
25 param_names = split.__code__.co_varnames[:split.__code__.co_argcount]
26 param_vals = [vars[p] for p in param_names] # Must be done in the task.
28 write_history(myms, outputvis, 'split', param_names, param_vals,
29 casalog),
30 which appends, e.g.,
32 vis = 'TWHydra_CO3_2.ms'
33 outputvis = 'scan9.ms'
34 datacolumn = 'data'
35 field = ''
36 spw = ''
37 width = 1
38 antenna = ''
39 timebin = '0s'
40 timerange = ''
41 scan = '9'
42 intent = ''
43 array = ''
44 uvrange = ''
45 correlation = ''
46 keepflags = True
48 to the HISTORY of outputvis.
49 """
50 if not hasattr(myms, 'writehistory'):
51 if debug:
52 myclog.post("write_history(myms, %s, %s): myms is not an ms tool" % (vis, tname), 'WARN')
53 return False
54 retval = True
55 isopen = False
56 try:
57 if not myclog and hasattr(casalog, 'post'):
58 myclog = casalog
59 except Exception:
60 # There's no logger to complain to, and I don't want to exit
61 # just because of that.
62 pass
63 try:
64 myms.open(vis, nomodify=False)
65 isopen = True
66 messages = ['taskname={0}'.format(tname)]
67 vestr = 'version: '
68 try:
69 # Don't use myclog.version(); it also prints to the
70 # logger, which is confusing.
71 vestr += ctsys.version_string( ) + ' '
72 vestr += ctsys.version_desc( )
75 except Exception:
76 if hasattr(myclog, 'version'):
77 # Now give it a try.
78 vestr += myclog.version()
79 else:
80 vestr += ' could not be determined' # We tried.
81 messages.append(vestr)
83 # Add the task arguments.
84 for argnum in range(len(param_names)):
85 msg = "%-11s = " % param_names[argnum]
86 val = param_vals[argnum]
87 if type(val) == str:
88 msg += '"'
89 msg += str(val)
90 if type(val) == str:
91 msg += '"'
92 messages.append(msg)
94 myms.writehistory_batch(messages=messages, origin=tname)
96 except Exception as instance:
97 if hasattr(myclog, 'post'):
98 myclog.post("*** Error \"%s\" updating HISTORY of %s" % (instance, vis),
99 'SEVERE')
100 retval = False
101 finally:
102 if isopen:
103 myms.close()
104 return retval