Commits

Neal Schweighart authored 40dd8f2bc04
Added merged test_imdev

casa5/gcwrap/python/scripts/tests/test_imdev.py

Renamed
21 21 #
22 22 #
23 23 ##########################################################################
24 24
25 25 CASA6 = False
26 26 try:
27 27 import casatools
28 28 from casatasks import imdev
29 29 tb = casatools.table()
30 30 ia = casatools.image()
31 + # imports from merged test_imdev
32 + from casatools import regionmanager as rgtool
31 33 CASA6 = True
32 34 except ImportError:
33 35 from __main__ import default
34 36 from tasks import *
35 37 from taskinit import *
38 +
36 39 import sys
37 40 import os
38 41 import unittest
39 42 import shutil
40 43 import numpy
41 44 import numbers
45 +import math
42 46
43 47 ### DATA ###
44 48
45 49 if CASA6:
46 50 dataroot = casatools.ctsys.resolve('unittest/imdev/')
47 51
48 52
49 53 else:
50 54 dataroot = os.environ.get('CASAPATH').split()[0] + '/casatestdata/unittest/imdev/'
51 55
52 56 datapath = os.path.join(dataroot, 'orion_tfeather.im')
53 57 datapath2 = os.path.join(dataroot, 'ngc5921.clean.image')
54 58 stokespath = os.path.join(dataroot, 'image_input_processor.im')
55 59 interppath = os.path.join(dataroot, 'f2h_quantile.im')
60 +reference_path = dataroot+'/imdev_reference/'
61 +
56 62 input0 = dataroot + "100x100x2.im"
57 -ref0 = dataroot + "imdev_reference/ref0.im"
63 +ref0 = reference_path + "ref0.im"
64 +# Merged test data
65 +ref1 = reference_path + "ref1.im"
66 +ref2 = reference_path + "ref2.im"
67 +ref3 = reference_path + "ref3.im"
68 +ref4 = reference_path + "ref4.im"
69 +ref5 = reference_path + "ref5.im"
70 +ref6 = reference_path + "ref6.im"
71 +ref7 = reference_path + "ref7.im"
58 72
59 73
60 74 def imArray(image):
61 75
62 76 tb.open(image)
63 77 arrayVal = tb.getcol('map')
64 78 tb.close()
65 79
66 80 return arrayVal
67 81
68 82 output = 'testimage.im'
69 83 output2 = 'testimage2.im'
70 84 output3 = 'testimage3.im'
71 85
72 86
73 87
74 88 class imdev_test(unittest.TestCase):
89 +
90 + ### Compare function from merged test_imdev
91 + def _compare(self, resold, resnew, helpstr):
92 + mytype = type(resold)
93 + self.assertTrue(mytype == type(resnew), helpstr + ": types differ")
94 + if mytype == dict:
95 + for k in resold.keys():
96 + self._compare(resold[k], resnew[k], helpstr)
97 + elif mytype == numpy.ndarray:
98 + oldarray = resold.ravel()
99 + newarray = resnew.ravel()
100 + self.assertTrue(
101 + len(oldarray) == len(newarray),
102 + helpstr + ": array lengths not equal"
103 + )
104 + for i in range(len(oldarray)):
105 + self._compare(oldarray[i], newarray[i], helpstr)
106 + elif mytype == str:
107 + self.assertTrue(
108 + resold == resnew,
109 + helpstr + ": string inequality, old = " + resold + ", new = " + resnew
110 + )
111 + elif isinstance(resold, numbers.Integral) or mytype == numpy.int32:
112 + self.assertTrue(
113 + resold == resnew,
114 + helpstr + ": integral inequality, old = " + str(resold) + ", new = " + str(resnew)
115 + )
116 + elif isinstance(resold, numbers.Real):
117 + self.assertTrue(
118 + resold == resnew
119 + or abs(resnew / resold - 1) < 1e-6,
120 + helpstr + "float inequality: old = " + str(resold)
121 + + ", new = " + str(resnew)
122 + )
123 + else:
124 + self.assertTrue(False, "Unhandled type " + str(mytype))
125 + ###
75 126
76 127
77 128 def setUp(self):
78 129 if not CASA6:
79 130 default(imdev)
80 131
81 132 self.res = None
82 133 self._myia = casatools.image()
83 134
84 135 def tearDown(self):
92 143 shutil.rmtree(output3)
93 144
94 145 if os.path.exists('testcopy.im'):
95 146 shutil.rmtree('testcopy.im')
96 147
97 148 if os.path.exists("mycirc_out.im"):
98 149 shutil.rmtree("mycirc_out.im")
99 150
100 151 if os.path.exists("mycirc.im"):
101 152 shutil.rmtree("mycirc.im")
153 +
154 + if os.path.exists("out0.im"):
155 + shutil.rmtree("out0.im")
102 156
103 157 self._myia.done()
104 158 self.assertTrue(len(tb.showcache()) == 0)
105 159 tb.done()
106 160
107 161
108 162 def _compare(self, resold, resnew, helpstr):
109 163 mytype = type(resold)
110 164 self.assertTrue(mytype == type(resnew), helpstr + ": types differ")
111 165 if mytype == dict:
404 458 imagename=imagename, outfile=outfile, xlength="40pix",
405 459 ylength="", stattype="sum", grid=[20, 20]
406 460 )
407 461 myia.open(outfile)
408 462 self.assertTrue(
409 463 numpy.isclose(myia.getchunk()[50, 50], 1257.0, 1e-7),
410 464 "incorrect grid pixel value"
411 465 )
412 466 myia.done()
413 467
468 + # Merged test cases from test_imdev
414 469
470 + def test001(self):
471 + """Every pixel is a grid point"""
472 + outname = "out0.im"
473 + imdev(
474 + input0, outname, grid=[1, 1], xlength="4pix", ylength="4pix",
475 + stattype="npts", interp="cub", anchor=[0, 0], statalg="cl"
476 + )
477 + self._myia.open(ref0)
478 + expec = self._myia.getchunk()
479 + self._myia.open(outname)
480 + got = self._myia.getchunk()
481 + self._myia.done()
482 + self._compare(got, expec, "imstatimage test 1")
483 +
484 + def test_circle(self):
485 + """test circles work correctly CAS-10296"""
486 + myia = self._myia
487 + imagename = "mycirc.im"
488 + myia.fromshape(imagename, [100, 100])
489 + bb = myia.getchunk()
490 + bb[:] = 1
491 + myia.putchunk(bb)
492 + myia.done()
493 + outfile = "mycirc_out.im"
494 + imdev(
495 + imagename=imagename, outfile=outfile, xlength="40pix",
496 + ylength="", stattype="sum", grid=[20, 20]
497 + )
498 + myia.open(outfile)
499 + self.assertTrue(
500 + numpy.isclose(myia.getchunk()[50, 50], 1257.0, 1e-7),
501 + "incorrect grid pixel value"
502 + )
503 + myia.done()
415 504
416 505
417 506
418 507 def suite():
419 508 return[imdev_test]
420 509
421 510 if __name__ == '__main__':
422 511 unittest.main()

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

Add shortcut