Coverage for /wheeldirectory/casa-6.7.0-12-py3.10.el8/lib/py/lib/python3.10/site-packages/casatasks/private/task_imcontsub.py: 16%
45 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-10-31 18:48 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-10-31 18:48 +0000
1import os
2import re
3import sys
5from casatools import image, regionmanager
6from casatasks import casalog
7from .ialib import write_image_history
9def imcontsub(
10 imagename, linefile, contfile, fitorder,
11 region, box, chans, stokes
12):
13 casalog.origin('imcontsub')
15 if ( len( linefile ) > 0 ):
16 if ( os.path.exists( linefile ) ):
17 raise ValueError('Error: file ' + linefile
18 +' already exists, please delete before continuing.',\
19 'SEVERE' )
20 else:
21 casalog.post("The linefile parameter is empty, consequently the"
22 +" spectral line image will NOT be\nsaved on disk.", \
23 'WARN')
25 if ( len( contfile ) > 0 ):
26 if ( os.path.exists( contfile ) ):
27 raise ValueError('Error: Unable to continue file '+contfile\
28 +' already exists, please delete before continuing.')
29 else:
30 casalog.post("The contfile parameter is empty, consequently the"
31 +" continuum image will NOT be\nsaved on disk.", \
32 'WARN')
34 _myia = image()
35 _myia.dohistory(False)
36 _myia.open(imagename)
37 mycsys = _myia.coordsys()
38 if isinstance(box, list):
39 box = ', '.join([str(b) for b in box])
41 # Don't mix chans up with reg! reg selects a subset for output, and chans
42 # selects a subset to define the line-free channels.
43 myrg = regionmanager()
44 reg = myrg.frombcs(
45 csys=mycsys.torecord(), shape=_myia.shape(),
46 box=box, stokes=stokes, stokescontrol="f",
47 region=region
48 )
49 channels = []
50 if chans != None and len(chans) > 0:
51 channels = myrg.selectedchannels(chans, _myia.shape())
53 try:
54 # Now do the continuum subtraction.
55 lineim = _myia.continuumsub(
56 outline=linefile, outcont=contfile, region=reg,
57 channels=channels, fitorder=fitorder,
58 overwrite=False
59 )
60 if not lineim:
61 raise Exception("ia.continuumsub did not complete successfully")
62 try:
63 param_names = imcontsub.__code__.co_varnames[:imcontsub.__code__.co_argcount]
64 local_vars = locals( )
65 param_vals = [local_vars[p] for p in param_names]
67 for x in [lineim, contfile]:
68 write_image_history(
69 x, sys._getframe().f_code.co_name,
70 param_names, param_vals, casalog
71 )
72 except Exception as instance:
73 casalog.post("*** Error \'%s\' updating HISTORY" % (instance), 'WARN')
74 lineim.done()
76 finally:
77 _myia.done()
78 if (lineim):
79 lineim.done()
80 if ( reg != None ):
81 del reg