Source
import os
from stat import S_ISDIR, ST_MODE
from casatools import image
from casatools import ctsys
from .. import casalog
from . import cvt
locimage = image
def _getvestr():
return 'version: ' + ctsys.version_info( )
def write_image_history(myia, tname, param_names, param_vals, myclog=None):
"""
Update image attached to image tool with the parameters that task tname was called with.
myia - attached image tool or image name (string)
tname - name of the calling task.
param_names - list of parameter names.
param_vals - list of parameter values (in the same order as param_names).
myclog - a casalog instance (optional)
"""
param_names = cvt.as_list(param_names)
param_vals = cvt.as_list(param_vals)
myia_is_string = type(myia) == str
if myia_is_string:
if not myia:
# empty string
return
_ia = locimage()
_ia.open(myia)
elif not hasattr(myia, 'sethistory'):
return False
else:
_ia = myia
try:
if not myclog and hasattr(casalog, 'post'):
myclog = casalog
except Exception as instance:
# There's no logger to complain to, and I don't want to exit
# just because of that.
pass
try:
vestr = _getvestr()
_ia.sethistory(tname, vestr)
# Write the arguments.
s = tname + "("
n = len(param_names)
for argnum in range(n):
s += str(param_names[argnum]) + "="
val = param_vals[argnum]
sval = str(val)
if len(sval) > 300:
s += "..."
else:
if type(val) == str:
s += '"'