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 import os
00066 import casac
00067 from tasks import *
00068 from taskinit import *
00069 import hashlib
00070 import shutil
00071 from __main__ import *
00072 import unittest
00073
00074 class ia_imageconcat_test(unittest.TestCase):
00075
00076 def setUp(self):
00077 self._myia = iatool()
00078
00079 def tearDown(self):
00080 self._myia.done()
00081
00082
00083 def test_multibeam(self):
00084 """Test concatenating images with different beams"""
00085 myia = self._myia
00086 shape = [4, 4, 20]
00087 myia.fromshape("", shape)
00088 print "*** here 1"
00089 blc1=[0, 0, 0]
00090 trc1=[shape[0]-1, shape[1]-1, shape[2]/2-1]
00091 rg1 = rg.box(blc=blc1, trc=trc1)
00092 im1 = "image1.im"
00093 sub1 = myia.subimage(im1, region=rg1)
00094 im2 = "image2.im"
00095 blc2 = [0, 0, trc1[2]+1]
00096 trc2 = [shape[0]-1, shape[1]-1, shape[2]-1]
00097 rg2 = rg.box(blc=blc2, trc=trc2)
00098 sub2 = myia.subimage(im2, region=rg2)
00099 major = qa.quantity("3arcmin")
00100 minor = qa.quantity("2arcmin")
00101 pa = qa.quantity("0deg")
00102 major2 = qa.quantity("4arcmin")
00103 minor2 = qa.quantity("3arcmin")
00104 pa2 = qa.quantity("10deg")
00105 major3 = qa.quantity("5arcmin")
00106 minor3 = qa.quantity("4arcmin")
00107 pa3 = qa.quantity("20deg")
00108 print "*** here 2"
00109
00110
00111 sub1.setbrightnessunit("Jy/pixel")
00112 sub2.setrestoringbeam(major=major, minor=minor, pa=pa)
00113 sub2.setbrightnessunit("Jy/beam")
00114 self.assertRaises(Exception, myia.imageconcat, "", [im1, im2])
00115 concat = myia.imageconcat("", [im1, im2], relax=True)
00116 self.assertTrue((concat.shape() == shape).all())
00117
00118
00119 sub1.setbrightnessunit("Jy/beam")
00120 sub1.setrestoringbeam(major=major, minor=minor, pa=pa)
00121 sub2.setbrightnessunit("Jy/beam")
00122 sub2.setrestoringbeam(remove=True)
00123 sub2.setrestoringbeam(
00124 major=major2, minor=minor2, pa=pa2,
00125 channel=0, polarization=-1
00126 )
00127
00128 sub2.setrestoringbeam(
00129 major=major3, minor=minor3, pa=pa3,
00130 channel=5, polarization=-1
00131 )
00132 concat = myia.imageconcat("", [im1, im2])
00133 for i in range(concat.shape()[2]):
00134 beam = concat.restoringbeam(channel=i)
00135 if i < sub1.shape()[2]:
00136 self.assertTrue(qa.eq(qa.quantity(beam["major"]), major))
00137 self.assertTrue(qa.eq(qa.quantity(beam["minor"]), minor))
00138 self.assertTrue(qa.eq(qa.quantity(beam["positionangle"]), pa))
00139 elif i == sub1.shape()[2] + 5:
00140 self.assertTrue(qa.eq(qa.quantity(beam["major"]), major3))
00141 self.assertTrue(qa.eq(qa.quantity(beam["minor"]), minor3))
00142 self.assertTrue(qa.eq(qa.quantity(beam["positionangle"]), pa3))
00143 else:
00144 self.assertTrue(qa.eq(qa.quantity(beam["major"]), major2))
00145 self.assertTrue(qa.eq(qa.quantity(beam["minor"]), minor2))
00146 self.assertTrue(qa.eq(qa.quantity(beam["positionangle"]), pa2))
00147
00148
00149 sub1.setbrightnessunit("Jy/beam")
00150 sub1.setrestoringbeam(major=major, minor=minor, pa=pa)
00151 sub2.setrestoringbeam(remove=True)
00152 sub2.setbrightnessunit("Jy/beam")
00153 sub2.setrestoringbeam(major=major, minor=minor, pa=pa)
00154 concat = myia.imageconcat("", [im1, im2])
00155 beam = concat.restoringbeam()
00156 self.assertTrue(qa.eq(qa.quantity(beam["major"]), major))
00157 self.assertTrue(qa.eq(qa.quantity(beam["minor"]), minor))
00158 self.assertTrue(qa.eq(qa.quantity(beam["positionangle"]), pa))
00159
00160
00161 sub1.setbrightnessunit("Jy/beam")
00162 sub1.setrestoringbeam(major=major, minor=minor, pa=pa)
00163 sub2.setrestoringbeam(remove=True)
00164 sub2.setbrightnessunit("Jy/beam")
00165 sub2.setrestoringbeam(major=major2, minor=minor2, pa=pa2)
00166 concat = myia.imageconcat("", [im1, im2])
00167 for i in range(concat.shape()[2]):
00168 beam = concat.restoringbeam(channel=i)
00169 if i < sub1.shape()[2]:
00170 self.assertTrue(qa.eq(qa.quantity(beam["major"]), major))
00171 self.assertTrue(qa.eq(qa.quantity(beam["minor"]), minor))
00172 self.assertTrue(qa.eq(qa.quantity(beam["positionangle"]), pa))
00173 else:
00174 self.assertTrue(qa.eq(qa.quantity(beam["major"]), major2))
00175 self.assertTrue(qa.eq(qa.quantity(beam["minor"]), minor2))
00176 self.assertTrue(qa.eq(qa.quantity(beam["positionangle"]), pa2))
00177
00178
00179 sub2.setbrightnessunit("Jy/beam")
00180 sub2.setrestoringbeam(remove=True)
00181 sub2.setrestoringbeam(major=major, minor=minor, pa=pa)
00182 sub1.setbrightnessunit("Jy/beam")
00183 sub1.setrestoringbeam(remove=True)
00184 sub1.setrestoringbeam(
00185 major=major2, minor=minor2, pa=pa2,
00186 channel=0, polarization=-1
00187 )
00188 sub1.setrestoringbeam(
00189 major=major3, minor=minor3, pa=pa3,
00190 channel=5, polarization=-1
00191 )
00192 concat = myia.imageconcat("", [im1, im2])
00193 for i in range(concat.shape()[2]):
00194 beam = concat.restoringbeam(channel=i)
00195 if i == 5:
00196 self.assertTrue(qa.eq(qa.quantity(beam["major"]), major3))
00197 self.assertTrue(qa.eq(qa.quantity(beam["minor"]), minor3))
00198 self.assertTrue(qa.eq(qa.quantity(beam["positionangle"]), pa3))
00199 elif i < sub1.shape()[2]:
00200 self.assertTrue(qa.eq(qa.quantity(beam["major"]), major2))
00201 self.assertTrue(qa.eq(qa.quantity(beam["minor"]), minor2))
00202 self.assertTrue(qa.eq(qa.quantity(beam["positionangle"]), pa2))
00203 else:
00204 self.assertTrue(qa.eq(qa.quantity(beam["major"]), major))
00205 self.assertTrue(qa.eq(qa.quantity(beam["minor"]), minor))
00206 self.assertTrue(qa.eq(qa.quantity(beam["positionangle"]), pa))
00207
00208
00209 sub1.setbrightnessunit("Jy/beam")
00210 sub1.setrestoringbeam(remove=True)
00211 sub1.setrestoringbeam(major=major, minor=minor, pa=pa)
00212 sub2.setrestoringbeam(remove=True)
00213 sub2.setbrightnessunit("Jy/beam")
00214 sub2.setrestoringbeam(major=major, minor=minor, pa=pa)
00215 concat = myia.imageconcat("", [im1, im2])
00216 beam = concat.restoringbeam()
00217 self.assertTrue(qa.eq(qa.quantity(beam["major"]), major))
00218 self.assertTrue(qa.eq(qa.quantity(beam["minor"]), minor))
00219 self.assertTrue(qa.eq(qa.quantity(beam["positionangle"]), pa))
00220
00221
00222 def suite():
00223 return [ia_imageconcat_test]