Commits

Mark Kettenis authored and Ville Suoranta committed c59b754007b Merge
Pull request #912: CAS-14517: Add more importfitsidi tests

Merge in CASA/casa6 from CAS-14517 to master * commit '140f25e73f41b13effb39e85f6b57e1965872901': CAS-14517: Add more importfitsidi tests

casatasks/tests/tasks/test_task_importfitsidi.py

Modified
24 24 # https://casadocs.readthedocs.io/en/stable/api/tt/casatasks.data.importfitsidi.html
25 25 #
26 26 ##########################################################################
27 27 import os
28 28 import sys
29 29 import shutil
30 30 import numpy
31 31 import unittest
32 32
33 33 from casatools import ctsys, ms, table
34 -from casatasks import importfitsidi
34 +from casatasks import importfitsidi, casalog
35 35
36 36 _ms = ms( )
37 37 _tb = table( )
38 38
39 +logpath = casalog.logfile()
40 +
39 41 datapath = ctsys.resolve('unittest/importfitsidi/')
42 +filepath = ctsys.resolve('testlog.log')
40 43
41 44 myname = 'importfitsidi-unit-test'
42 45
43 46 # default dataset name
44 47 my_dataset_names = ['n09q2_1_1-shortened.IDI1',
45 48 'n09q2_1_1-shortened-part1.IDI1',
46 49 'n09q2_1_1-shortened-part2.IDI1',
47 50 'emerlin_multiuv.IDI1',
48 51 '1331_3030_C-Band_5GHz__64.000_128.fits',
49 - 'VLBA_TL015A_tl015arecor_BIN0_SRC0_1_201020T164655.idifits']
52 + 'VLBA_TL015A_tl015arecor_BIN0_SRC0_1_201020T164655.idifits',
53 + 'VLBA_VSN000397_file69.uvfits']
50 54
51 55 # name of the resulting MS
52 56 msname = my_dataset_names[0]+'.ms'
53 57
54 58 def checktable(thename, theexpectation):
55 59 global msname, myname
56 60 _tb.open(msname+"/"+thename)
57 61 if thename == "":
58 62 thename = "MAIN"
59 63 for mycell in theexpectation:
103 107 res = None
104 108
105 109 for fname in my_dataset_names:
106 110 if(os.path.exists(fname)):
107 111 os.remove(fname)
108 112 datasetPath = os.path.join(datapath,fname)
109 113 datasetPath = ctsys.resolve(datasetPath)
110 114 shutil.copy(datasetPath, fname)
111 115
112 116 def tearDown(self):
117 + casalog.setlogfile(logpath)
118 + if os.path.exists(filepath):
119 + os.remove(filepath)
113 120 for fname in my_dataset_names:
114 121 os.remove(fname)
115 122 shutil.rmtree(msname,ignore_errors=True)
116 123 shutil.rmtree(msname+'.flagversions',ignore_errors=True)
117 124
118 125 def test1(self):
119 126 '''fitsidi-import: Test good input'''
120 127 retValue = {'success': True, 'msgs': "", 'error_msgs': '' }
121 128
122 129 self.res = importfitsidi(my_dataset_names[0], msname, scanreindexgap_s=100., constobsid=True)
1153 1160 ['UT1_UTC', 4, -0.172797, 1E-8],
1154 1161 ['PM', 4, [9.20370292E-7, 1.55251885E-6], 1E-14],
1155 1162 ]
1156 1163 results = checktable(name, expected)
1157 1164 if not results:
1158 1165 retValue['success']=False
1159 1166 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
1160 1167
1161 1168 self.assertTrue(retValue['success'])
1162 1169
1170 + def test9(self):
1171 + '''fitsidi-import: Test import from multiple arrays'''
1172 + retValue = {'success': True, 'msgs': "", 'error_msgs': '' }
1173 +
1174 + casalog.setlogfile('testlog.log')
1175 + self.res = importfitsidi([my_dataset_names[0],my_dataset_names[6]], msname,
1176 + constobsid=True, scanreindexgap_s=5)
1177 + print(myname, ": Success! Now checking output ...")
1178 + print(myname, ": MS exists. All tables present. Try opening as MS ...")
1179 + try:
1180 + _ms.open(msname)
1181 + except:
1182 + print(myname, ": Error Cannot open MS table", tablename)
1183 + retValue['success']=False
1184 + retValue['error_msgs']=retValue['error_msgs']+'Cannot open MS table '+tablename
1185 + else:
1186 + _ms.close()
1187 + print(myname, ": OK. Checking tables in detail ...")
1188 + retValue['success']=True
1189 +
1190 + # Test that observation IDs are different (despite constobsid=True)
1191 + # Test data from both observations to verify that digital
1192 + # corrections are applied correctly.
1193 + name = ""
1194 + expected = [
1195 + ['OBSERVATION_ID', 638, 0, 0],
1196 + ['UVW', 638, [171529.37575288, -786712.70341456, 210321.20978818], 1E-8],
1197 + ['EXPOSURE', 638, 2.0, 1E-8],
1198 + ['DATA', 638, [[-0.00224198+0.00067056j,
1199 + -0.00475123+0.0024323j,
1200 + -0.00416393+0.00212671j,
1201 + -0.00565350+0.00340364j,
1202 + -0.00527357+0.00011977j,
1203 + -0.00292699+0.00131954j,
1204 + -0.00429945+0.00035823j,
1205 + -0.00545671-0.00033945j,
1206 + -0.00646004+0.00037293j,
1207 + -0.00419376-0.00115011j,
1208 + -0.00508117+0.00045939j,
1209 + -0.00501660-0.00047975j,
1210 + -0.00444734-0.00101535j,
1211 + -0.00384988-0.00102731j,
1212 + -0.00551326+0.00101364j,
1213 + -0.00337701+0.00080481j]], 1E-8],
1214 + ['OBSERVATION_ID', 8511, 1, 0],
1215 + ['UVW', 8511, [828914.03079271, 439115.74358212, -3087211.83269717], 1E-8],
1216 + ['EXPOSURE', 8511, 2.0971519947052, 1E-8],
1217 + ['DATA', 8511, [[-0.0005048021+0.0006272711j,
1218 + 0.0004651772-0.0004499542j,
1219 + 0.0002667628-0.0001897688j,
1220 + -0.0009842832-0.0005429656j,
1221 + -0.0001268085-0.0007897264j,
1222 + -0.0004823971-0.0002412655j,
1223 + 0.0009139312+0.0002414373j,
1224 + 0.0000649303-0.0012320010j,
1225 + -0.0002075107-0.0009946608j,
1226 + -0.0004472813+0.0009435851j,
1227 + 0.0011783736-0.0003215929j,
1228 + 0.0003143105-0.0002393110j,
1229 + -0.0007472970-0.0006453455j,
1230 + -0.0002369661-0.0000927994j,
1231 + 0.0007526718+0.0009522775j,
1232 + 0.0006285428-0.0002970326j]], 1E-8],
1233 + ]
1234 + results = checktable(name, expected)
1235 + if not results:
1236 + retValue['success']=False
1237 + retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
1238 +
1239 + self.assertTrue(retValue['success'])
1240 +
1241 + with open('testlog.log') as logf:
1242 + success = ('The input files stem from different telescopes.' in logf.read())
1243 + self.assertTrue(success)
1244 +
1245 + def test10(self):
1246 + '''fitsidi-import: Test import of VLBA archival data'''
1247 + retValue = {'success': True, 'msgs': "", 'error_msgs': '' }
1248 +
1249 + casalog.setlogfile('testlog.log')
1250 + self.res = importfitsidi(my_dataset_names[6], msname)
1251 + print(myname, ": Success! Now checking output ...")
1252 + mscomponents = set(["table.dat",
1253 +# "table.f0",
1254 + "table.f1",
1255 + "table.f2",
1256 + "table.f3",
1257 + "table.f4",
1258 + "table.f5",
1259 + "table.f6",
1260 + "table.f7",
1261 + "table.f8",
1262 + "ANTENNA/table.dat",
1263 + "DATA_DESCRIPTION/table.dat",
1264 + "FEED/table.dat",
1265 + "FIELD/table.dat",
1266 + "FLAG_CMD/table.dat",
1267 + "HISTORY/table.dat",
1268 + "OBSERVATION/table.dat",
1269 + "POINTING/table.dat",
1270 + "POLARIZATION/table.dat",
1271 + "PROCESSOR/table.dat",
1272 + "SPECTRAL_WINDOW/table.dat",
1273 + "STATE/table.dat",
1274 + "ANTENNA/table.f0",
1275 + "DATA_DESCRIPTION/table.f0",
1276 + "FEED/table.f0",
1277 + "FIELD/table.f0",
1278 + "FLAG_CMD/table.f0",
1279 + "HISTORY/table.f0",
1280 + "OBSERVATION/table.f0",
1281 + "POINTING/table.f0",
1282 + "POLARIZATION/table.f0",
1283 + "PROCESSOR/table.f0",
1284 + "SPECTRAL_WINDOW/table.f0",
1285 + "STATE/table.f0"
1286 + ])
1287 + for name in mscomponents:
1288 + if not os.access(msname+"/"+name, os.F_OK):
1289 + print(myname, ": Error ", msname+"/"+name, "doesn't exist ...")
1290 + retValue['success']=False
1291 + retValue['error_msgs']=retValue['error_msgs']+msname+'/'+name+' does not exist'
1292 + else:
1293 + print(myname, ": ", name, "present.")
1294 + print(myname, ": MS exists. All tables present. Try opening as MS ...")
1295 + try:
1296 + _ms.open(msname)
1297 + except:
1298 + print(myname, ": Error Cannot open MS table", tablename)
1299 + retValue['success']=False
1300 + retValue['error_msgs']=retValue['error_msgs']+'Cannot open MS table '+tablename
1301 + else:
1302 + _ms.close()
1303 + print(myname, ": OK. Checking tables in detail ...")
1304 + retValue['success']=True
1305 +
1306 + # check main table first
1307 + name = ""
1308 + # col name, row number, expected value, tolerance
1309 + expected = [
1310 + ['UVW', 15, [828914.03079271, 439115.74358212, -3087211.83269717], 1E-8],
1311 + ['EXPOSURE', 15, 2.0971519947052, 1E-8],
1312 + ['DATA', 15, [[-0.0005048021+0.0006272711j,
1313 + 0.0004651772-0.0004499542j,
1314 + 0.0002667628-0.0001897688j,
1315 + -0.0009842832-0.0005429656j,
1316 + -0.0001268085-0.0007897264j,
1317 + -0.0004823971-0.0002412655j,
1318 + 0.0009139312+0.0002414373j,
1319 + 0.0000649303-0.0012320010j,
1320 + -0.0002075107-0.0009946608j,
1321 + -0.0004472813+0.0009435851j,
1322 + 0.0011783736-0.0003215929j,
1323 + 0.0003143105-0.0002393110j,
1324 + -0.0007472970-0.0006453455j,
1325 + -0.0002369661-0.0000927994j,
1326 + 0.0007526718+0.0009522775j,
1327 + 0.0006285428-0.0002970326j]], 1E-8],
1328 + ]
1329 + results = checktable(name, expected)
1330 + if not results:
1331 + retValue['success']=False
1332 + retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
1333 +
1334 + self.assertTrue(retValue['success'])
1335 +
1336 + # Check that appropriate warnings are issued for unimplemented functionality
1337 + with open('testlog.log') as logf:
1338 + success = ('Data needs FFT artifact corrections' in logf.read())
1339 + self.assertTrue(success)
1340 + with open('testlog.log') as logf:
1341 + success = ('Data was correlated with HANNING taper' in logf.read())
1342 + self.assertTrue(success)
1343 +
1344 +
1163 1345 if __name__ == '__main__':
1164 1346 unittest.main()

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

Add shortcut