Coverage for /wheeldirectory/casa-6.7.0-12-py3.10.el8/lib/py/lib/python3.10/site-packages/casatasks/private/task_imrebin.py: 12%
41 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 sys
3from casatools import image, regionmanager
4from casatasks import casalog
5from .ialib import write_image_history
7def imrebin(
8 imagename, outfile, factor, region, box, chans, stokes, mask,
9 dropdeg, overwrite, stretch, crop
10):
11 casalog.origin('imrebin')
12 valid = True
13 # because there is a bug in the tasking layer that allows float
14 # arrays through when the spec is for intArray
15 for x in factor:
16 if x != int(x):
17 valid = False
18 break
19 if not valid:
20 for i in range(len(factor)):
21 factor[i] = int(factor[i])
22 casalog.post(
23 "factor is not an int array, it will be adjusted to "
24 + str(factor),
25 'WARN'
26 )
27 myia = image( )
28 myia.dohistory(False)
29 outia = None
30 try:
31 if (not myia.open(imagename)):
32 raise RuntimeError("Cannot create image analysis tool using %s" % imagename)
33 if (len(outfile) == 0):
34 raise ValueError("outfile must be specified.")
35 if (type(region) != type({})):
36 myrg = regionmanager( )
37 reg = myrg.frombcs(
38 csys=myia.coordsys().torecord(), shape=myia.shape(), box=box,
39 chans=chans, stokes=stokes, stokescontrol="a", region=region
40 )
41 else:
42 reg = region
43 outia = myia.rebin(
44 outfile=outfile, bin=factor, region=reg, mask=mask, dropdeg=dropdeg,
45 overwrite=overwrite, stretch=stretch, crop=crop
46 )
48 try:
49 param_names = imrebin.__code__.co_varnames[:imrebin.__code__.co_argcount]
50 vars = locals( )
51 param_vals = [vars[p] for p in param_names]
53 write_image_history(
54 outia, sys._getframe().f_code.co_name,
55 param_names, param_vals, casalog
56 )
57 except Exception as instance:
58 casalog.post("*** Error \'%s\' updating HISTORY" % (instance), 'WARN')
60 finally:
61 if myia:
62 myia.done()
63 if outia:
64 outia.done()
65 if myrg:
66 myrg.done()