Commits

consistent error (except) handling, task sdpolaverage ->CASA6, CAS-13125, CAS-13018
No tags

casatasks/src/tasks/task_sdpolaverage.py

Modified
99 99 pdh = ParallelDataHelper('sdpolaverage', locals())
100 100
101 101 # When dealing with MMS, process in parallel or sequential
102 102 # disableparallel is a hidden parameter. Only for debugging purposes!
103 103 if disableparallel:
104 104 pdh.bypassParallelProcessing(1)
105 105 else:
106 106 pdh.bypassParallelProcessing(0)
107 107
108 108 # Validate input and output parameters
109 - try:
110 - pdh.setupIO()
111 - except Exception as instance:
112 - casalog.post('%s' % instance, 'ERROR')
113 - return False
109 + pdh.setupIO()
114 110
115 111 # Process the input Multi-MS
116 112 if ParallelDataHelper.isMMSAndNotServer(infile) == True and monolithic_processing == False:
117 113 '''
118 114 retval{'status': True, 'axis':''} --> can run in parallel
119 115 retval{'status': False, 'axis':'value'} --> treat MMS as monolithic MS, set new axis for output MMS
120 116 retval{'status': False, 'axis':''} --> treat MMS as monolithic MS, create an output MS
121 117 '''
122 118
123 119 retval = pdh.validateInputParams()
134 130 pdh.override__args('createmms', True)
135 131 pdh.override__args('monolithic_processing', True)
136 132 separationaxis = retval['axis']
137 133 pdh.override__args('separationaxis', retval['axis'])
138 134 casalog.post("Will process the input MMS as a monolithic MS", 'WARN')
139 135 casalog.post("Will create an output MMS with separation axis \'%s\'" % retval['axis'], 'WARN')
140 136
141 137 # MMS is processed in parallel
142 138 else:
143 139 createmms = False
144 - try:
145 - pdh.override__args('createmms', False)
146 - pdh.setupCluster('sdpolaverage')
147 - pdh.go()
148 - except Exception as instance:
149 - casalog.post('%s' % instance, 'ERROR')
150 - return False
151 -
152 - return True
140 + pdh.override__args('createmms', False)
141 + pdh.setupCluster('sdpolaverage')
142 + pdh.go()
143 + return
153 144
154 145 # Create an output Multi-MS
155 146 if createmms == True:
156 147
157 148 # Check the heuristics of separationaxis and the requested transformations
158 149 pval = pdh.validateOutputParams()
159 150 if pval == 0:
160 - raise Exception(
151 + raise RuntimeError(
161 152 'Cannot create MMS using separationaxis=%s with some of the requested transformations.'
162 153 % separationaxis
163 154 )
164 155
165 - try:
166 - pdh.setupCluster('sdpolaverage')
167 - pdh.go()
168 - monolithic_processing = False
169 - except Exception as instance:
170 - casalog.post('%s' % instance, 'ERROR')
171 - return False
172 -
173 - return True
156 + pdh.setupCluster('sdpolaverage')
157 + pdh.go()
158 + monolithic_processing = False
159 + return
174 160
175 161 # Create a local copy of the MSTransform tool
176 162 mtlocal = mstransformer()
177 163 mslocal = ms()
178 164
179 165 try:
180 166 # Gather all the parameters in a dictionary.
181 167 config = {}
182 168
183 169 if keepflags:
222 208 raise ValueError('Parameter tileshape must have 1 or 3 elements.')
223 209
224 210 config['tileshape'] = tileshape
225 211
226 212 if combinespws:
227 213 casalog.post('Combine spws %s into new output spw'%spw)
228 214 config['combinespws'] = True
229 215
230 216 # Only parse chanaverage if chanbin is valid
231 217 if chanaverage and isinstance(chanbin, int) and chanbin <= 1:
232 - raise Exception('Parameter chanbin must be > 1 to do channel averaging')
218 + raise ValueError('Parameter chanbin must be > 1 to do channel averaging')
233 219
234 220 # Validate the case of int or list chanbin
235 221 if chanaverage and pdh.validateChanBin():
236 222 casalog.post('Parse channel averaging parameters')
237 223 config['chanaverage'] = True
238 224
239 225 # convert numpy types, until CAS-6493 is not fixed
240 226 chanbin = fh.evaluateNumpyType(chanbin)
241 227 config['chanbin'] = chanbin
242 228
266 252 config['outframe'] = outframe
267 253 if phasecenter != '':
268 254 config['phasecenter'] = phasecenter
269 255 config['veltype'] = veltype
270 256 config['preaverage'] = preaverage
271 257
272 258 # Only parse timeaverage parameters when timebin > 0s
273 259 if timeaverage:
274 260 tb = quanta.convert(quanta.quantity(timebin), 's')['value']
275 261 if not tb > 0:
276 - raise Exception("Parameter timebin must be > '0s' to do time averaging")
262 + raise ValueError("Parameter timebin must be > '0s' to do time averaging")
277 263
278 264 if timeaverage:
279 265 casalog.post('Parse time averaging parameters')
280 266 config['timeaverage'] = True
281 267 config['timebin'] = timebin
282 268 config['timespan'] = timespan
283 269 config['maxuvwdistance'] = maxuvwdistance
284 270
285 271 polaverage_ = polaverage.strip()
286 272 if polaverage_ != '':
310 296 casalog.post('%s' % config, 'DEBUG')
311 297 mtlocal.config(config)
312 298
313 299 # Open the MS, select the data and configure the output
314 300 mtlocal.open()
315 301
316 302 # Run the tool
317 303 casalog.post('Apply the transformations')
318 304 mtlocal.run()
319 305
306 + finally:
320 307 mtlocal.done()
321 308
322 - except Exception as instance:
323 - mtlocal.done()
324 - casalog.post('%s' % instance, 'ERROR')
325 - return False
326 309
327 310 # Update the FLAG_CMD sub-table to reflect any spw/channels selection
328 311 # If the spw selection is by name or FLAG_CMD contains spw with names, skip the updating
329 312
330 313 if ((spw != '') and (spw != '*')) or chanaverage == True:
331 314 isopen = False
332 315
333 316 try:
334 317 mytb = table()
335 318 mytb.open(outfile + '/FLAG_CMD', nomodify=False)
408 391 cmds[rownum] = cmd
409 392 if mademod:
410 393 casalog.post('Updating FLAG_CMD', 'INFO')
411 394 mytb.putcol('COMMAND', cmds)
412 395
413 396 else:
414 397 casalog.post('FLAG_CMD table contains spw selection by name. Will not update it!','DEBUG')
415 398
416 399 mytb.close()
417 400
418 - except Exception as instance:
401 + finally:
419 402 if isopen:
420 403 mytb.close()
421 404 mslocal = None
422 405 mytb = None
423 - casalog.post("*** Error \'%s\' updating FLAG_CMD" % (instance),
424 - 'SEVERE')
425 - return False
426 406
427 407 mytb = None
428 408
429 409 # Write history to output MS, not the input ms.
430 410 try:
431 411 param_names = sdpolaverage.__code__.co_varnames[:sdpolaverage.__code__.co_argcount]
432 412 param_vals = [eval(p) for p in param_names]
433 413 write_history(mslocal, outfile, 'sdpolaverage', param_names,
434 414 param_vals, casalog)
435 415 except Exception as instance:
436 416 casalog.post("*** Error \'%s\' updating HISTORY" % (instance),
437 417 'WARN')
438 - return False
439 418
440 419 mslocal = None
441 -
442 - return True

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

Add shortcut