Coverage for /wheeldirectory/casa-6.7.0-12-py3.10.el8/lib/py/lib/python3.10/site-packages/casatasks/private/task_rmfit.py: 15%
40 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-10-31 17:39 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-10-31 17:39 +0000
1import tempfile
2import shutil
4from casatasks import casalog
5from casatools import image, imagepol
6from .ialib import write_image_history
8def rmfit(
9 imagename, rm, rmerr, pa0, pa0err, nturns, chisq,
10 sigma, rmfg, rmmax, maxpaerr
11):
12 casalog.origin('prom')
13 myia = image()
14 myia.dohistory(False)
15 mypo = imagepol()
16 tmpim = ""
17 try:
18 if len(imagename) == 0:
19 raise ValueError("imagename must be specified.")
20 if type(imagename) == type(['s']):
21 # negative axis value means concatenate along spectral axis
22 tmpim = tempfile.mkdtemp(suffix=".im", prefix="_rmfit_concat")
23 myia = myia.imageconcat(
24 outfile=tmpim, infiles=imagename, relax=True,
25 axis=-1, overwrite=True
26 )
27 if not myia:
28 raise RuntimeError("Unable to concatenate images.")
29 myia.done()
30 mypo.open(tmpim)
31 else:
32 if not mypo.open(imagename):
33 raise RuntimeError("Cannot create image analysis tool using " + imagename)
34 mypo.rotationmeasure(
35 rm=rm, rmerr=rmerr, pa0=pa0, pa0err=pa0err, nturns=nturns, chisq=chisq,
36 sigma=sigma, rmfg=rmfg, rmmax=rmmax, maxpaerr=maxpaerr
37 )
38 try:
39 param_names = rmfit.func_code.co_varnames[:rmfit.func_code.co_argcount]
40 param_vals = [eval(p) for p in param_names]
41 for im in [rm, rmerr, pa0, pa0err, nturns, chisq]:
42 write_image_history(
43 im, sys._getframe().f_code.co_name,
44 param_names, param_vals, casalog
45 )
46 except Exception as instance:
47 casalog.post("*** Error \'%s\' updating HISTORY" % (instance), 'WARN')
48 # tasks no longer return bools
49 finally:
50 if (myia):
51 myia.done()
52 if (mypo):
53 mypo.done()
54 if len(tmpim) > 0:
55 try:
56 shutil.rmtree(tmpim)
57 except Exception as exc:
58 casalog.post("Could not remove " + tmpim + " because " + str(exc))