Commits

consistent error (except) handling, task+test imtrans, CAS-13126, CAS-13018
No tags

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

Modified
111 111 """No actual transposing"""
112 112 imagename = good_image
113 113 myia = image()
114 114 myia.open(imagename)
115 115 expecteddata = myia.getchunk()
116 116 expectednames = myia.coordsys().names()
117 117 myia.close()
118 118 count = 0
119 119 for order in ["012", 12, ['r', 'd', 'f'], ["righ", "declin", "freq"]]:
120 120 outfile = "straight_copy_" + str(count)
121 - self.assertTrue(run_imtrans(imagename, outfile, order))
121 + run_imtrans(imagename, outfile, order)
122 + self.assertTrue(os.path.exists(outfile))
122 123 myia.open(outfile)
123 124 gotdata = myia.getchunk()
124 125 gotnames = myia.coordsys().names()
125 126 myia.done()
126 127 self.assertTrue((expecteddata == gotdata).all())
127 128 self.assertTrue(expectednames == gotnames)
128 129 count += 1
129 130
130 131 def test_transpose(self):
131 132 """Test transposing"""
132 133 imagename = good_image
133 134 myia = image()
134 135 myia.open(imagename)
135 136 expecteddata = myia.getchunk()
136 137 expectednames = myia.coordsys().names()
137 138 myia.done()
138 139 count = 0
139 140 for order in ["120", 120, ['d', 'f', 'r'], ["declin", "freq", "righ"]]:
140 141 outname = "transpose_" + str(count)
141 - self.assertTrue(run_imtrans(imagename, outname, order))
142 + run_imtrans(imagename, outname, order)
143 + self.assertTrue(os.path.exists(outname))
142 144 myia.open(outname)
143 145 gotdata = myia.getchunk()
144 146 inshape = expecteddata.shape
145 147 for i in range(inshape[0]):
146 148 for j in range(inshape[1]):
147 149 for k in range(inshape[2]):
148 150 self.assertTrue(expecteddata[i][j][k] == gotdata[j][k][i])
149 151 gotnames = myia.coordsys().names()
150 152 myia.done()
151 153 self.assertTrue(expectednames[0] == gotnames[2])
152 154 self.assertTrue(expectednames[1] == gotnames[0])
153 155 self.assertTrue(expectednames[2] == gotnames[1])
154 156 count += 1
155 157
156 158 def test_cas_2364(self):
157 159 "test CAS-2364 fix"
158 160 shutil.copytree(ctsys_resolve(os.path.join(datapath, cas_2364im)), cas_2364im)
159 161 order = "0132"
160 162 out1 = "blah2.im"
161 - self.assertTrue(imtrans(imagename=cas_2364im, outfile=out1, order=order))
163 + imtrans(imagename=cas_2364im, outfile=out1, order=order)
164 + self.assertTrue(os.path.exists(out1))
162 165 myia = image()
163 166 # to verify fix, just open the image. bug was that exception was thrown when opening output from reorder
164 167 myia.open(out1)
165 168 self.assertTrue(myia)
166 169 myia.done()
167 170
168 171 def test_history(self):
169 172 """Test history records are written"""
170 173 myia = image()
171 174 imagename = "zz.im"
172 175 myia.fromshape(imagename, [10,10,4,10])
173 176 order = "3210"
174 177 outfile = "zz_out.im"
175 - self.assertTrue(
176 - imtrans(imagename=imagename, outfile=outfile, order=order)
177 - )
178 + imtrans(imagename=imagename, outfile=outfile, order=order)
179 + self.assertTrue(os.path.exists(outfile))
178 180 myia.open(outfile)
179 181 msgs = myia.history()
180 182 myia.done()
181 183 teststr = "version"
182 184 self.assertTrue(teststr in msgs[-2], "'" + teststr + "' not found")
183 185 teststr = "imtrans"
184 186 self.assertTrue(teststr in msgs[-1], "'" + teststr + "' not found")
185 187 myia.open(imagename)
186 188 myia.done()
187 189
188 190 def test_imageinfo(self):
189 191 """Verify image info is copied"""
190 192 myia = image()
191 193 imname = "imageinfo_test.im"
192 194 myia.fromshape(imname, [10,20,30])
193 195 myia.setbrightnessunit("Jy/beam")
194 196 myia.setrestoringbeam("4arcmin", "3arcmin", "0deg")
195 197 outfile = "imageinfo_test_out.im"
196 - self.assertTrue(imtrans(imname, outfile, "201"))
198 + imtrans(imname, outfile, "201")
199 + self.assertTrue(os.path.exists(outfile))
197 200 myia.open(outfile)
198 201 self.assertEqual(
199 202 myia.brightnessunit(), "Jy/beam",
200 203 "brightness unit not copied"
201 204 )
202 205 self.assertTrue(
203 206 myia.restoringbeam(), "restoring beam not copied"
204 207 )
205 208 myia.done()
206 209 myia.open(imname)

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

Add shortcut