Commits

Darrell Schiebel authored 6d0dd92e95d Merge
Merge branch 'master' into CAS-14073

casatasks/src/private/task_imsmooth.py

Modified
66 66 #
67 67 # <todo>
68 68 # </todo>
69 69
70 70 from __future__ import absolute_import
71 71 import inspect
72 72 import os
73 73 import sys
74 74 import numpy
75 75
76 -# get is_CASA6 and is_python3
77 -from casatasks.private.casa_transition import *
78 -if is_CASA6:
79 - from casatools import image, regionmanager, quanta
80 - from casatasks import casalog
81 - from .ialib import write_image_history
82 -
83 - _qa = quanta( )
84 -else:
85 - from taskinit import *
86 - from ialib import write_image_history
87 -
88 - image = iatool
89 - regionmanager = rgtool
90 -
91 - # not a local tool
92 - _qa = qa
76 +from casatools import image, regionmanager, quanta
77 +from casatasks import casalog
78 +from .ialib import write_image_history
79 +_qa = quanta()
93 80
94 81 from casatasks.private.callabletask import log_origin_setter
95 82
96 83
97 84 @log_origin_setter
98 85 def imsmooth(
99 86 imagename, kernel, major, minor, pa, targetres, kimage, scale, region,
100 87 box, chans, stokes, mask, outfile, stretch, overwrite, beam
101 88 ):
102 89
108 95 not (
109 96 gkernel or bkernel or ckernel or ikernel
110 97 )
111 98 ):
112 99 raise ValueError('Unsupported kernel, ' + kernel)
113 100
114 101 if (not ikernel and type(beam) == str):
115 102 if len(beam) != 0:
116 103 err = "beam cannot be a non-empty string"
117 104 casalog.post(err, "SEVERE")
118 - raise Exception(err)
105 + raise ValueError(err)
119 106 beam = {}
120 107
121 108 # First check to see if the output file exists. If it
122 109 # does then we abort. CASA doesn't allow files to be
123 110 # over-written, just a policy.
124 111 if ( len( outfile ) < 1 ):
125 112 outfile = 'imsmooth_results.im'
126 113 casalog.post( "The outfile paramter is empty, consequently the" \
127 114 +" smoothed image will be\nsaved on disk in file, " \
128 115 + outfile, 'WARN')
165 152 targetres = True
166 153 if (beam and (major or minor or pa)):
167 154 raise ValueError("You may specify only beam or the set of major/minor/pa")
168 155 if not beam:
169 156 if not major:
170 157 raise ValueError("Major axis must be specified")
171 158 if not minor:
172 159 raise ValueError("Minor axis must be specified")
173 160 if not pa:
174 161 raise ValueError("Position angle must be specified")
175 -
162 +
176 163 outia = _myia.convolve2d(
177 164 axes=[0,1], region=reg, major=major,
178 165 minor=minor, pa=pa, outfile=outfile,
179 166 mask=mask, stretch=stretch, targetres=targetres,
180 167 overwrite=overwrite, beam=beam
181 168 )
182 169 elif (bkernel ):
183 170 if not major or not minor:
184 171 raise ValueError("Both major and minor must be specified.")
185 172 # BOXCAR KERNEL
213 200 _myia.open(imagename)
214 201 outia = _myia.convolve(
215 202 outfile=outfile, kernel=kimage, scale=scale, region=reg,
216 203 mask=mask, overwrite=overwrite, stretch=stretch
217 204 )
218 205 else:
219 206 raise ValueError('Unrecognized kernel type: ' + kernel)
220 207
221 208 try:
222 209 param_names = imsmooth.__code__.co_varnames[:imsmooth.__code__.co_argcount]
223 - if is_python3:
224 - vars = locals( )
225 - param_vals = [vars[p] for p in param_names]
226 - else:
227 - param_vals = [eval(p) for p in param_names]
210 + param_vals = [eval(p) for p in param_names]
228 211 write_image_history(
229 212 outia, sys._getframe().f_code.co_name,
230 213 param_names, param_vals, casalog
231 214 )
232 215 except Exception as instance:
233 216 casalog.post("*** Error \'%s\' updating HISTORY" % (instance), 'WARN')
234 217
235 218 finally:
236 219 _myia.done()
237 220 if outia: outia.done()

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

Add shortcut