Commits

David Mehringer authored ebdc682afb9
add test to verify correct beam is place in metadata

casatasks/tests/tasks/test_task_imsmooth.py

Modified
69 69 for j in range(shape[1]):
70 70 y = shape[1]/2 - j
71 71 xfac = x*x*fac/(xfwhm*xfwhm)
72 72 yfac = y*y*fac/(yfwhm*yfwhm)
73 73 values[i, j] = math.exp(-(xfac + yfac));
74 74 return values
75 75
76 76
77 77 class imsmooth_test(unittest.TestCase):
78 78
79 + cas_13827_in = 'cas_13827.im'
80 + cas_13827_out = 'cas_13827.conv'
81 +
79 82 def setUp(self):
80 83 self.tst = 'imsmooth_'
81 84 if(os.path.exists(image_names[0])):
82 85 for file in image_names:
83 86 os.system('rm -rf ' +file)
84 87
85 88 for file in image_names:
86 89 os.system('cp -RH '+ os.path.join(datapath,file)+' ' + file)
87 90 self.ia = image()
88 91 for f in [targetres_im, tiny]:
101 104 os.system('rm -rf sub'+'*')
102 105 for ff in [targetres_im, tiny]:
103 106 if(os.path.exists(ff)):
104 107 os.system('rm -rf ' +ff)
105 108 for ff in image_names:
106 109 os.system('rm -rf ' + ff)
107 110 if os.path.exists("test_image2dconvolver_multibeam.im"):
108 111 shutil.rmtree("test_image2dconvolver_multibeam.im")
109 112 if os.path.exists( 'garbage.rgn' ):
110 113 os.remove('garbage.rgn')
114 + for im in (self.cas_13827_in, self.cas_13827_out):
115 + if os.path.exists(im):
116 + os.system(f'rm -rf {im}')
117 +
111 118
112 119 ####################################################################
113 120 # Incorrect inputs to parameters. The parameters are:
114 121 # imagename
115 122 # outfile
116 123 # kernel
117 124 # major
118 125 # minor
119 126 # mask
120 127 # region
1009 1016 self.assertTrue(_near(gotbeam[j], expbeam[j], 2e-7))
1010 1017 self.assertTrue(abs(got.getchunk(blc=blc, trc=trc) - expec.getchunk()).max() < 3e-5)
1011 1018 got.done()
1012 1019 expec.done()
1013 1020 myia.done()
1014 1021 got.done()
1015 1022
1016 1023 def test_targetres(self):
1017 1024 """Test targetres parameter"""
1018 1025 myia = self.ia
1019 - imagename = self.tst+"tres1.im"
1026 + imagename = f'{self.tst}tres1.im'
1020 1027 myia.fromshape(imagename, [100, 100])
1021 1028 csys = myia.coordsys()
1022 1029 csys.setunits(["arcsec", "arcsec"])
1023 1030 csys.setincrement([-1, 1])
1024 1031 myia.setcoordsys(csys.torecord())
1025 1032 myia.setrestoringbeam(major="6arcsec", minor="3arcsec", pa="0deg")
1026 1033 shape = myia.shape()
1027 1034 values = make_gauss2d(shape, 3.0, 6.0)
1028 1035 expected = make_gauss2d(shape, 5.0, 10.0)
1029 1036 myia.putchunk(values)
1111 1118 subim.done()
1112 1119 expected[:, :, k] = convim.getchunk()
1113 1120 gotbeam = convim.restoringbeam()
1114 1121
1115 1122 if targetres:
1116 1123 self._compare_beams(gotbeam, {"major": major, "minor": minor, "pa": pa})
1117 1124
1118 1125 ebeam.append(gotbeam)
1119 1126 convim.done()
1120 1127 if targetres:
1121 - outfile = self.tst+"tres3" + unit[0]
1128 + outfile = f'{self.tst}tres3{unit[0]}'
1122 1129 else:
1123 - outfile = self.tst+"tres4" + unit[0]
1130 + outfile = f'{self.tst}tres4{unit[0]}'
1124 1131 run_imsmooth(
1125 1132 imagename=imagename, kernel="gaussian",
1126 1133 major=major, minor=minor, pa=pa, targetres=targetres,
1127 1134 outfile=outfile
1128 1135 )
1129 1136 outia.open(outfile)
1130 1137 for k in range(shape[2]):
1131 1138 gotbeam = outia.restoringbeam(channel=k)
1132 1139 self._compare_beams(gotbeam, ebeam[k])
1133 1140 maxdiff = (abs(outia.getchunk()-expected)).max()
1134 1141 self.assertTrue(maxdiff < 1e-6)
1135 1142 myia.done()
1136 1143 outia.done()
1137 1144
1138 1145 myia.open(imagename)
1139 1146 myia.setrestoringbeam(
1140 1147 major="6arcsec", minor="3arcsec", pa="0deg"
1141 1148 )
1142 1149 myia.done()
1143 - outfile = self.tst+"tres6"
1150 + outfile = f'{self.tst}tres6'
1144 1151 with self.assertRaises(RuntimeError):
1145 1152 run_imsmooth(
1146 1153 imagename=imagename, kernel="gaussian",
1147 1154 major="5.99arcsec", minor="2.99arcsec", pa="0deg",
1148 1155 targetres=True, outfile=outfile
1149 1156 )
1157 + # CAS-13827, verify beam placed in output image header is the specified
1158 + # beam, not the fitted beam
1159 + myia.fromshape(self.cas_13827_in, [512, 512, 1, 1], overwrite=True)
1160 + csys = myia.coordsys()
1161 + inc = csys.increment()['numeric']
1162 + inc[:2] /= 60
1163 + csys.setincrement(inc)
1164 + myia.setcoordsys(csys.torecord())
1165 + csys.done()
1166 + myia.setbrightnessunit('Jy/beam')
1167 + myia.setrestoringbeam(major='3arcsec', minor='3arcsec', pa='0deg')
1168 + myia.done()
1169 + major = '3.2arcsec'
1170 + minor = '3.1arcsec'
1171 + pa = '60deg'
1172 + imsmooth(
1173 + self.cas_13827_in, outfile=self.cas_13827_out, targetres=True,
1174 + major=major, minor=minor, pa=pa, overwrite=True
1175 + )
1176 + myia.open(self.cas_13827_out)
1177 + beam = myia.restoringbeam()
1178 + myia.done()
1179 + self.assertEqual(
1180 + _qa.quantity(beam['major']), _qa.quantity(major),
1181 + 'Incorrect beam in image metadata'
1182 + )
1183 + self.assertEqual(
1184 + _qa.quantity(beam['minor']), _qa.quantity(minor),
1185 + 'Incorrect beam in image metadata'
1186 + )
1187 + self.assertEqual(
1188 + _qa.quantity(beam['positionangle']), _qa.quantity(pa),
1189 + 'Incorrect beam in image metadata'
1190 + )
1191 +
1150 1192
1151 1193 def test_overwrite(self):
1152 1194 """ test overwrite parameter """
1153 1195 myia = self.ia
1154 1196 outfile = self.tst+"test_overwrite.im"
1155 1197 myia.fromshape(outfile, [200, 200])
1156 1198 imagename = self.tst+"input_overwrite"
1157 1199 myia.fromshape(imagename, [200, 200])
1158 1200 myia.done()
1159 1201 run_imsmooth(

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

Add shortcut