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 import shutil
00069 import casac
00070 from tasks import *
00071 from taskinit import *
00072 from __main__ import *
00073 import unittest
00074
00075 def alleqnum(x,num,tolerance=0):
00076 if len(x.shape)==1:
00077 for i in range(x.shape[0]):
00078 if not (abs(x[i]-num) < tolerance):
00079 print "x[",i,"]=", x[i]
00080 return false
00081 if len(x.shape)==2:
00082 for i in range(x.shape[0]):
00083 for j in range(x.shape[1]):
00084 if not (abs(x[i][j]-num) < tolerance):
00085 print "x[",i,"][",j,"]=", x[i][j]
00086 return false
00087 if len(x.shape)==3:
00088 for i in range(x.shape[0]):
00089 for j in range(x.shape[1]):
00090 for k in range(x.shape[2]):
00091 if not (abs(x[i][j][k]-num) < tolerance):
00092 print "x[",i,"][",j,"][",k,"]=", x[i][j][k]
00093 return false
00094 if len(x.shape)==4:
00095 for i in range(x.shape[0]):
00096 for j in range(x.shape[1]):
00097 for k in range(x.shape[2]):
00098 for l in range(x.shape[3]):
00099 if not (abs(x[i][j][k][l]-num) < tolerance):
00100 print "x[",i,"][",j,"][",k,"][",l,"]=", x[i][j][k]
00101 return false
00102 if len(x.shape)>4:
00103 stop('unhandled array shape in alleq')
00104 return true
00105
00106
00107 class ia_rebin_test(unittest.TestCase):
00108
00109 def setUp(self):
00110 self._myia = iatool()
00111
00112 def tearDown(self):
00113 self._myia.done()
00114
00115 def test_stretch(self):
00116 """ ia.rebin(): Test stretch parameter"""
00117 yy = iatool()
00118 mymask = "maskim"
00119 yy.fromshape(mymask, [200, 200, 1, 1])
00120 yy.addnoise()
00121 yy.done()
00122 shape = [200,200,1,20]
00123 yy.fromshape("", shape)
00124 yy.addnoise()
00125 self.assertRaises(
00126 Exception,
00127 yy.rebin, outfile="", bin=[2,2,1,1],
00128 mask=mymask + ">0", stretch=False
00129 )
00130 zz = yy.rebin(
00131 outfile="", bin=[2,2,1,1],
00132 mask=mymask + ">0", stretch=True
00133 )
00134 self.assertTrue(type(zz) == type(yy))
00135 yy.done()
00136 zz.done()
00137
00138 def test_general(self):
00139 """ ia.rebin(): General tests"""
00140
00141
00142 myia = self._myia
00143 shp2 = [20,40]
00144 d2 = myia.makearray(1.0, [shp2[0], shp2[1]])
00145
00146 myim2 = myia.newimagefromarray(pixels=d2)
00147 self.assertTrue(myim2)
00148
00149 try:
00150 myim2b = true
00151 myim2b = myim2.rebin(bin=[-100,2])
00152 except Exception, e:
00153 myim2b = false
00154 self.assertFalse(myim2b)
00155
00156 myim2b = myim2.rebin("",bin=[2,2])
00157 self.assertTrue(myim2b)
00158 p = myim2b.getchunk()
00159 self.assertTrue(alleqnum(p,1.0,tolerance=0.0001))
00160
00161 ok = myim2.done() and myim2b.done()
00162 self.assertTrue(ok)
00163
00164 def test_multibeam(self):
00165 """Test multiple beams"""
00166 myia = self._myia
00167 myia.fromshape("", [10, 10, 10])
00168 myia.setrestoringbeam(
00169 major="4arcsec", minor="2arcsec", pa="0deg",
00170 channel=0, polarization=0
00171 )
00172 rebin = myia.rebin("", [2, 2, 1])
00173 self.assertTrue(rebin)
00174 exception = False
00175 try:
00176 rebin = myia.rebin("", [2, 2, 2])
00177 except:
00178 exception = True
00179 self.assertTrue(exception)
00180 rebin.done()
00181
00182 def suite():
00183 return [ia_rebin_test]