00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 import shutil
00070 import casac
00071 from tasks import *
00072 from taskinit import *
00073 from __main__ import *
00074 import unittest
00075
00076 good_image = "reorder_in.fits"
00077 cas_2364im = "CAS-2364.im"
00078
00079 def run_transpose(imagename, outfile, order):
00080 myia = iatool()
00081 myia.open(imagename)
00082 print "*** order " + str(order)
00083 res = myia.transpose(outfile=outfile, order=order)
00084 myia.close()
00085 return res
00086
00087 def run_imtrans(imagename, outfile, order):
00088 return imtrans(imagename=imagename, outfile=outfile, order=order)
00089
00090
00091 class imtrans_test(unittest.TestCase):
00092
00093 def setUp(self):
00094 datapath=os.environ.get('CASAPATH').split()[0]+'/data/regression/unittest/imtrans/'
00095 shutil.copy(datapath + good_image, good_image)
00096
00097 def tearDown(self):
00098 os.remove(good_image)
00099
00100 def test_exceptions(self):
00101 """imtrans: Test various exception cases"""
00102
00103 def testit(imagename, outfile, order):
00104 for i in [0,1]:
00105 if (i==0):
00106 self.assertRaises(Exception, run_transpose, imagename, outfile, order)
00107 else:
00108 self.assertFalse(run_imtrans(imagename, outfile, order))
00109
00110
00111 testit("", "blah", "012")
00112
00113
00114 testit(good_image, "blah", "01")
00115 testit(good_image, "blah", 10)
00116 testit(good_image, "blah", ["r", "d"])
00117
00118
00119 testit(good_image, "blah", "0123")
00120 testit(good_image, "blah", 1230)
00121 testit(good_image, "blah", ["r", "d", "f", "s"])
00122
00123
00124 testit(good_image, "blah", "123")
00125 testit(good_image, "blah", ["r", "d", "s"])
00126 testit(good_image, "blah", ["r", "d", "r"])
00127 testit(good_image, "blah", 103)
00128
00129 def test_straight_copy(self):
00130 """No actual transposing"""
00131 imagename = good_image
00132 myia = iatool()
00133 myia.open(imagename)
00134 expecteddata = myia.getchunk()
00135 expectednames = myia.coordsys().names()
00136 myia.close()
00137 count = 0
00138 for order in ["012", 12, ['r', 'd', 'f'], ["righ", "declin", "freq"]]:
00139 for code in [run_transpose, run_imtrans]:
00140 newim = code(imagename, "straight_copy_" + str(count), order)
00141 gotdata = newim.getchunk()
00142 gotnames = newim.coordsys().names()
00143 newim.close()
00144 self.assertTrue((expecteddata == gotdata).all())
00145 self.assertTrue(expectednames == gotnames)
00146 count += 1
00147
00148 def test_transpose(self):
00149 """Test transposing"""
00150 imagename = good_image
00151 myia = iatool()
00152 myia.open(imagename)
00153 expecteddata = myia.getchunk()
00154 expectednames = myia.coordsys().names()
00155 myia.done()
00156 count = 0
00157 for order in ["120", 120, ['d', 'f', 'r'], ["declin", "freq", "righ"]]:
00158 for code in [run_transpose, run_imtrans]:
00159 for outname in ["transpose_" + str(count), ""]:
00160 newim = code(imagename, outname, order)
00161 gotdata = newim.getchunk()
00162 inshape = expecteddata.shape
00163 for i in range(inshape[0]):
00164 for j in range(inshape[1]):
00165 for k in range(inshape[2]):
00166 self.assertTrue(expecteddata[i][j][k] == gotdata[j][k][i])
00167 gotnames = newim.coordsys().names()
00168 newim.close()
00169 self.assertTrue(expectednames[0] == gotnames[2])
00170 self.assertTrue(expectednames[1] == gotnames[0])
00171 self.assertTrue(expectednames[2] == gotnames[1])
00172 count += 1
00173
00174 def test_cas_2364(self):
00175 "test CAS-2364 fix"
00176 datapath=os.environ.get('CASAPATH').split()[0]+'/data/regression/unittest/imtrans/'
00177 shutil.copytree(datapath + cas_2364im, cas_2364im)
00178 order="0132"
00179 out1 = "blah.im"
00180 myia = iatool()
00181 myia.open(cas_2364im)
00182 myia.transpose(out1, order)
00183 myia.close()
00184
00185 myia.open(out1)
00186 self.assertTrue(myia)
00187 myia.close()
00188 out1 = "blah2.im"
00189 imtrans(outfile=out1, order=order)
00190 myia.open(out1)
00191 self.assertTrue(myia)
00192 myia.close()
00193 shutil.rmtree(cas_2364im)
00194
00195
00196 def suite():
00197 return [imtrans_test]