Commits

Neal Schweighart authored f7076b69e9f
removed old test_imrebin from casa6
No tags

casatasks/tests/tasks/test_imrebin.py

Deleted
1 -##########################################################################
2 -# imfit_test.py
3 -#
4 -# Copyright (C) 2008, 2009
5 -# Associated Universities, Inc. Washington DC, USA.
6 -#
7 -# This script is free software; you can redistribute it and/or modify it
8 -# under the terms of the GNU Library General Public License as published by
9 -# the Free Software Foundation; either version 2 of the License, or (at your
10 -# option) any later version.
11 -#
12 -# This library is distributed in the hope that it will be useful, but WITHOUT
13 -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15 -# License for more details.
16 -#
17 -# You should have received a copy of the GNU Library General Public License
18 -# along with this library; if not, write to the Free Software Foundation,
19 -# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
20 -#
21 -# Correspondence concerning AIPS++ should be adressed as follows:
22 -# Internet email: aips2-request@nrao.edu.
23 -# Postal address: AIPS++ Project Office
24 -# National Radio Astronomy Observatory
25 -# 520 Edgemont Road
26 -# Charlottesville, VA 22903-2475 USA
27 -#
28 -# <author>
29 -# Dave Mehringer
30 -# </author>
31 -#
32 -# <summary>
33 -# Test suite for the CASA tool method ia.rebin()
34 -# </summary>
35 -#
36 -# <reviewed reviwer="" date="" tests="" demos="">
37 -# </reviewed
38 -#
39 -# <prerequisite>
40 -# <ul>
41 -# </ul>
42 -# </prerequisite>
43 -#
44 -# <etymology>
45 -# Test for the ia.rebin() tool method
46 -# </etymology>
47 -#
48 -# <synopsis>
49 -# Test the ia.rebin() tool method
50 -# </synopsis>
51 -#
52 -# <example>
53 -#
54 -# This test runs as part of the CASA python unit test suite and can be run from
55 -# the command line via eg
56 -#
57 -# `echo $CASAPATH/bin/casa | sed -e 's$ $/$'` --nologger --log2term -c `echo $CASAPATH | awk '{print $1}'`/code/xmlcasa/scripts/regressions/admin/runUnitTest.py test_ia_rebin[test1,test2,...]
58 -#
59 -# </example>
60 -#
61 -# <motivation>
62 -# To provide a test standard for the ia.rebin() tool method to ensure
63 -# coding changes do not break the associated bits
64 -# </motivation>
65 -#
66 -
67 -###########################################################################
68 -
69 -import os
70 -import shutil
71 -import numpy
72 -import unittest
73 -
74 -from casatools import image, table
75 -from casatasks import imrebin
76 -
77 -_tb = table( )
78 -_ia = image( )
79 -
80 -def alleqnum(x,num,tolerance=0):
81 - if len(x.shape)==1:
82 - for i in range(x.shape[0]):
83 - if not (abs(x[i]-num) < tolerance):
84 - print("x[",i,"]=", x[i])
85 - return False
86 - if len(x.shape)==2:
87 - for i in range(x.shape[0]):
88 - for j in range(x.shape[1]):
89 - if not (abs(x[i][j]-num) < tolerance):
90 - print("x[",i,"][",j,"]=", x[i][j])
91 - return False
92 - if len(x.shape)==3:
93 - for i in range(x.shape[0]):
94 - for j in range(x.shape[1]):
95 - for k in range(x.shape[2]):
96 - if not (abs(x[i][j][k]-num) < tolerance):
97 - print("x[",i,"][",j,"][",k,"]=", x[i][j][k])
98 - return False
99 - if len(x.shape)==4:
100 - for i in range(x.shape[0]):
101 - for j in range(x.shape[1]):
102 - for k in range(x.shape[2]):
103 - for l in range(x.shape[3]):
104 - if not (abs(x[i][j][k][l]-num) < tolerance):
105 - print("x[",i,"][",j,"][",k,"][",l,"]=", x[i][j][k])
106 - return False
107 - if len(x.shape)>4:
108 - stop('unhandled array shape in alleq')
109 - return True
110 -
111 -class imrebin_test(unittest.TestCase):
112 -
113 - def setUp(self):
114 - self._myia = image()
115 -
116 - def tearDown(self):
117 - self._myia.done()
118 - self.assertTrue(len(_tb.showcache()) == 0)
119 -
120 - def test_stretch(self):
121 - """ ia.rebin(): Test stretch parameter"""
122 - yy = self._myia
123 - mymask = "maskim"
124 - yy.fromshape(mymask, [200, 200, 1, 1])
125 - yy.addnoise()
126 - yy.done()
127 - shape = [200,200,1,10]
128 - imagename = "aa.im"
129 - yy.fromshape(imagename, shape)
130 - yy.addnoise()
131 - yy.done()
132 - outfile = "ab.im"
133 - self.assertRaises(
134 - Exception, imrebin, imagename=imagename, outfile=outfile, factor=[2,2,1,1],
135 - mask=mymask + ">0", stretch=False, overwrite=True
136 - )
137 - imrebin(
138 - imagename=imagename, outfile=outfile, factor=[2,2,1,1],
139 - mask=mymask + ">0", stretch=True, overwrite=True
140 - )
141 - yy.open(outfile)
142 - self.assertTrue((yy.shape() == [100, 100, 1, 10]).all())
143 - yy.done()
144 -
145 - def test_general(self):
146 - """ ia.rebin(): General tests"""
147 - # tests moved from imagetest_regression.py and modified
148 -
149 - myia = self._myia
150 - shp2 = [20,40]
151 - d2 = myia.makearray(1.0, [shp2[0], shp2[1]])
152 - #
153 - imagename = "st.im"
154 - myim2 = myia.newimagefromarray(outfile=imagename, pixels=d2)
155 - myim2.done()
156 - outfile = "gk.im"
157 - self.assertRaises(
158 - Exception, imrebin, imagename=imagename, outfile=outfile,
159 - factor=[-100,2], overwrite=True
160 - )
161 - imrebin(
162 - imagename=imagename, outfile=outfile, overwrite=True,
163 - factor=[2,2]
164 - )
165 - myia.open(outfile)
166 - p = myia.getchunk()
167 - self.assertTrue(alleqnum(p,1.0,tolerance=0.0001))
168 - myia.done()
169 -
170 - def test_multibeam(self):
171 - """Test multiple beams"""
172 - myia = self._myia
173 - imagename = "gd.im"
174 - myia.fromshape(imagename, [10, 10, 10])
175 - myia.setrestoringbeam(
176 - major="4arcsec", minor="2arcsec", pa="0deg",
177 - channel=0, polarization=0
178 - )
179 - outfile = "dx.im"
180 - imrebin(
181 - imagename=imagename, outfile=outfile,
182 - factor=[2,2,1]
183 - )
184 -
185 - self.assertRaises(
186 - Exception, imrebin, imagename=imagename, outfile=outfile,
187 - factor=[2,2,2]
188 - )
189 -
190 - def test_crop(self):
191 - """Test crop parameter"""
192 - myia = self._myia
193 - imagename = "xxyy.im"
194 - myia.fromshape(imagename, [20, 20, 20])
195 - factor = [3,3,3]
196 - myia.done()
197 - outfile = "outxdkd.im"
198 - imrebin(imagename=imagename, outfile=outfile, factor=factor, crop=True)
199 - myia.open(outfile)
200 - self.assertTrue((myia.shape() == [6,6,6]).all())
201 - myia.done()
202 - imrebin(imagename=imagename, outfile=outfile, factor=factor, crop=False, overwrite=True)
203 - myia.open(outfile)
204 - self.assertTrue((myia.shape() == [7,7,7]).all())
205 - myia.done()
206 -
207 - def test_dropdeg(self):
208 - """Test dropdeg parameter"""
209 - myia = self._myia
210 - imagename = "kjfasd.im"
211 - myia.fromshape(imagename, [20, 20, 1])
212 - factor = [5,5]
213 - myia.done()
214 - outfile = "dkfajfas.im"
215 - imrebin(imagename=imagename, outfile=outfile, factor=factor, dropdeg=True)
216 - myia.open(outfile)
217 - self.assertTrue((myia.shape() == [4,4]).all())
218 - myia.done()
219 -
220 - def test_box(self):
221 - """Test use of box"""
222 - myia = self._myia
223 - imagename = "erzvd.im"
224 - myia.fromshape(imagename, [30, 30, 1])
225 - factor = [5,5]
226 - myia.done()
227 - outfile = "vcsfea.im"
228 - imrebin(imagename=imagename, outfile=outfile, factor=factor, box="5,5,25,25",crop=True)
229 - myia.open(outfile)
230 - self.assertTrue((myia.shape() == [4,4,1]).all())
231 - myia.done()
232 -
233 - def test_dropdeg2(self):
234 - """ axes that become degenerate when regridded are dropped if dropdeg=True: CAS-5836"""
235 - myia = self._myia
236 - imagename = "kbesd.im"
237 - myia.fromshape(imagename, [20, 20, 20])
238 - factor = [1, 1, 20]
239 - myia.done()
240 - outfile = "kyzb5.im"
241 - imrebin(
242 - imagename=imagename, outfile=outfile,
243 - factor=factor, dropdeg=True
244 - )
245 - myia.open(outfile)
246 - self.assertTrue((myia.shape() == [20,20]).all())
247 - myia.done()
248 -
249 - def test_history(self):
250 - """Test history writing"""
251 - myia = self._myia
252 - imagename = "zz.im"
253 - factor = [1, 1, 20]
254 - myia.fromshape(imagename,[20,20,20])
255 - myia.done()
256 - outfile = "zz_out.im"
257 - imrebin(imagename=imagename, outfile=outfile, factor=factor)
258 - myia.open(outfile)
259 - msgs = myia.history()
260 - myia.done()
261 - teststr = "version"
262 - self.assertTrue(teststr in msgs[-2], "'" + teststr + "' not found")
263 - teststr = "imrebin"
264 - self.assertTrue(teststr in msgs[-1], "'" + teststr + "' not found")
265 -
266 -def suite():
267 - return [imrebin_test]
268 -
269 -if __name__ == '__main__':
270 - unittest.main()
271 -

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

Add shortcut