00001
00002
00003 import os
00004 import shutil
00005
00006 from __main__ import default
00007 from tasks import *
00008 from taskinit import *
00009 import unittest
00010
00011 class exportasdm_test(unittest.TestCase):
00012
00013
00014 vis_b = 'test.ms'
00015 vis_c = 'M100-X220-shortened.ms'
00016 vis_d = 'ngc4826.tutorial.ngc4826.ll.5.ms'
00017 vis_e = 'g19_d2usb_targets_line-shortened.ms'
00018 vis_f = 'Itziar.ms'
00019 vis_g = 'M51.ms'
00020 out = 'exportasdm-output.asdm'
00021 rval = False
00022
00023 def setUp(self):
00024 self.rval = False
00025
00026
00027 if(not os.path.exists(self.vis_b)):
00028 os.system('cp -R '+os.environ['CASAPATH'].split()[0]+'/data/regression/fits-import-export/input/test.ms .')
00029 if(not os.path.exists(self.vis_c)):
00030 os.system('cp -R '+os.environ['CASAPATH'].split()[0]+'/data/regression/exportasdm/input/M100-X220-shortened.ms .')
00031 if(not os.path.exists(self.vis_d)):
00032 importuvfits(fitsfile=os.environ['CASAPATH'].split()[0]+'/data/regression/ngc4826/fitsfiles/ngc4826.ll.fits5',
00033 vis=self.vis_d)
00034 if(not os.path.exists(self.vis_e)):
00035 os.system('cp -R '+os.environ['CASAPATH'].split()[0]+'/data/regression/cvel/input/g19_d2usb_targets_line-shortened.ms .')
00036 if(not os.path.exists(self.vis_f)):
00037 os.system('cp -R '+os.environ['CASAPATH'].split()[0]+'/data/regression/exportasdm/input/Itziar.ms .')
00038 if(not os.path.exists(self.vis_g)):
00039 os.system('cp -R '+os.environ['CASAPATH'].split()[0]+'/data/regression/exportasdm/input/M51.ms .')
00040
00041 default(exportasdm)
00042
00043 def tearDown(self):
00044 os.system('rm -rf myinput.ms')
00045 os.system('rm -rf ' + self.out)
00046
00047
00048 def verify_asdm(self,asdmname, withPointing):
00049 print "Verifying asdm ", asdmname
00050 if(not os.path.exists(asdmname)):
00051 print "asdm ", asdmname, " doesn't exist."
00052 raise Exception
00053
00054 allTables = [ "Antenna.xml",
00055 "ASDM.xml",
00056
00057
00058
00059 "ConfigDescription.xml",
00060 "CorrelatorMode.xml",
00061 "DataDescription.xml",
00062 "ExecBlock.xml",
00063 "Feed.xml",
00064 "Field.xml",
00065
00066
00067 "Main.xml",
00068 "PointingModel.xml",
00069 "Polarization.xml",
00070 "Processor.xml",
00071 "Receiver.xml",
00072 "SBSummary.xml",
00073 "Scan.xml",
00074 "Source.xml",
00075 "SpectralWindow.xml",
00076 "State.xml",
00077 "Station.xml",
00078 "Subscan.xml",
00079 "SwitchCycle.xml"
00080 ]
00081 isOK = True
00082
00083 xmllint_ok = (os.system('xmllint --version') == 0)
00084 for fileName in allTables:
00085 filePath = asdmname+'/'+fileName
00086 if(not os.path.exists(filePath)):
00087 print "ASDM table file ", filePath, " doesn't exist."
00088 isOK = False
00089 elif(xmllint_ok):
00090
00091 rval = os.system('xmllint --noout '+filePath)
00092 if(rval !=0):
00093 print "Table ", filePath, " is not a well formed XML document."
00094 isOK = False
00095 if(isOK and not xmllint_ok):
00096 print "Note: Test of XML well-formedness not possible since xmllint not available."
00097 else:
00098 print "Note: xml validation not possible since ASDM DTDs (schemas) not yet online."
00099
00100 if(not os.path.exists(asdmname+"/ASDMBinary")):
00101 print "ASDM binary directory "+asdmname+"/ASDMBinary doesn't exist."
00102 isOK = False
00103
00104 if(withPointing and not os.path.exists(asdmname+"/Pointing.bin")):
00105 print "ASDM binary file "+asdmname+"/Pointing.bin doesn't exist."
00106 isOK = False
00107
00108 if (not isOK):
00109 raise Exception
00110
00111
00112 def test1(self):
00113 '''Test 1: Testing default'''
00114 myvis = self.vis_b
00115 os.system('rm -rf myinput.ms')
00116 os.system('cp -R ' + myvis + ' myinput.ms')
00117 self.rval = exportasdm()
00118 self.assertFalse(self.rval)
00119
00120 def test2(self):
00121 '''Test 2: small input MS, default output, v3'''
00122 myvis = self.vis_b
00123 os.system('rm -rf myinput.ms')
00124 os.system('cp -R ' + myvis + ' myinput.ms')
00125 self.rval = exportasdm(
00126 vis = 'myinput.ms',
00127 asdm = self.out,
00128 archiveid="S1",
00129 verbose=True,
00130 apcorrected=False,
00131 useversion='v3')
00132
00133 self.assertNotEqual(self.rval,False)
00134 omsname = "test"+str(2)+self.out
00135 os.system('rm -rf '+omsname+'; mv exportasdm-output.asdm '+omsname)
00136 self.verify_asdm(omsname, False)
00137
00138 def test3(self):
00139 '''Test 3: simulated input MS, default output, v3'''
00140 myvis = self.vis_f
00141 os.system('rm -rf myinput.ms')
00142 os.system('cp -R ' + myvis + ' myinput.ms')
00143 self.rval = exportasdm(vis = 'myinput.ms',asdm = self.out,archiveid="S1", useversion='v3')
00144 self.assertNotEqual(self.rval,False)
00145 omsname = "test"+str(3)+self.out
00146 os.system('rm -rf '+omsname+'; mv exportasdm-output.asdm '+omsname)
00147 self.verify_asdm(omsname, True)
00148
00149 def test4(self):
00150 '''Test 4: real input MS, default output, v3'''
00151 myvis = self.vis_d
00152 os.system('rm -rf myinput.ms')
00153 os.system('cp -R ' + myvis + ' myinput.ms')
00154 self.rval = exportasdm(
00155 vis = 'myinput.ms',
00156 asdm = self.out,
00157 archiveid="S1",
00158 apcorrected=False,
00159 useversion='v3'
00160 )
00161
00162 self.assertNotEqual(self.rval,False)
00163 omsname = "test"+str(4)+self.out
00164 os.system('rm -rf '+omsname+'; mv exportasdm-output.asdm '+omsname)
00165 self.verify_asdm(omsname, False)
00166
00167 def test5(self):
00168 '''Test 5: real input MS, MS has several SPWs observed in parallel, v3 - not supported, expected error'''
00169 myvis = self.vis_e
00170 os.system('rm -rf myinput.ms')
00171 os.system('cp -R ' + myvis + ' myinput.ms')
00172 self.rval = exportasdm(
00173 vis = 'myinput.ms',
00174 asdm = self.out,
00175 archiveid="S1",
00176 apcorrected=False,
00177 useversion = 'v3'
00178 )
00179
00180 self.assertFalse(self.rval)
00181
00182 def test6(self):
00183 '''Test 6: simulated input MS with pointing table, default output, v3'''
00184 myvis = self.vis_g
00185 os.system('rm -rf myinput.ms')
00186 os.system('cp -R ' + myvis + ' myinput.ms')
00187 self.rval = exportasdm(
00188 vis = 'myinput.ms',
00189 asdm = self.out,
00190 archiveid="S002",
00191 apcorrected=False,
00192 useversion = 'v3'
00193 )
00194
00195 self.assertNotEqual(self.rval,False)
00196 omsname = "test"+str(6)+self.out
00197 os.system('rm -rf '+omsname+'; mv exportasdm-output.asdm '+omsname)
00198 self.verify_asdm(omsname, True)
00199
00200 def test7(self):
00201 '''Test 7: v3, simulated input MS, default output'''
00202 myvis = self.vis_f
00203 os.system('rm -rf myinput.ms')
00204 os.system('cp -R ' + myvis + ' myinput.ms')
00205 self.rval = exportasdm(vis = 'myinput.ms',asdm = self.out,archiveid="S1", useversion='v3')
00206 self.assertNotEqual(self.rval,False)
00207 omsname = "test"+str(7)+self.out
00208 os.system('rm -rf '+omsname+'; mv exportasdm-output.asdm '+omsname)
00209 self.verify_asdm(omsname, True)
00210
00211 def test8(self):
00212 '''Test 8: v3, real input MS, default output'''
00213 myvis = self.vis_d
00214 os.system('rm -rf myinput.ms')
00215 os.system('cp -R ' + myvis + ' myinput.ms')
00216 self.rval = exportasdm(
00217 vis = 'myinput.ms',
00218 asdm = self.out,
00219 archiveid="S1",
00220 apcorrected=False,
00221 useversion='v3'
00222 )
00223
00224 self.assertNotEqual(self.rval,False)
00225 omsname = "test"+str(8)+self.out
00226 os.system('rm -rf '+omsname+'; mv exportasdm-output.asdm '+omsname)
00227 self.verify_asdm(omsname, False)
00228
00229 def test9(self):
00230 '''Test 9: v3, simulated input MS with pointing table, default output'''
00231 myvis = self.vis_g
00232 os.system('rm -rf myinput.ms')
00233 os.system('cp -R ' + myvis + ' myinput.ms')
00234 self.rval = exportasdm(
00235 vis = 'myinput.ms',
00236 asdm = self.out,
00237 archiveid="S002",
00238 apcorrected=False,
00239 useversion='v3'
00240 )
00241
00242 self.assertNotEqual(self.rval,False)
00243 omsname = "test"+str(9)+self.out
00244 os.system('rm -rf '+omsname+'; mv exportasdm-output.asdm '+omsname)
00245 self.verify_asdm(omsname, True)
00246
00247 def test10(self):
00248 '''Test 10: v3, ALMA input MS with pointing table and various shortcomings, default output'''
00249 myvis = self.vis_c
00250 os.system('rm -rf myinput.ms')
00251 os.system('cp -R ' + myvis + ' myinput.ms')
00252 self.rval = exportasdm(
00253 vis = 'myinput.ms',
00254 asdm = self.out,
00255 archiveid="S002",
00256 apcorrected=False,
00257 useversion='v3'
00258 )
00259
00260 self.assertNotEqual(self.rval,False)
00261 omsname = "test"+str(10)+self.out
00262 os.system('rm -rf '+omsname+'; mv exportasdm-output.asdm '+omsname)
00263 self.verify_asdm(omsname, True)
00264
00265
00266 class exportasdm_test2(unittest.TestCase):
00267
00268 vis_b = 'test.ms'
00269 vis_c = 'M100-X220-shortened.ms'
00270 vis_d = 'ngc4826.tutorial.ngc4826.ll.5.ms'
00271 vis_e = 'g19_d2usb_targets_line-shortened.ms'
00272 vis_f = 'Itziar.ms'
00273 vis_g = 'M51.ms'
00274
00275 def setUp(self):
00276 pass
00277
00278 def tearDown(self):
00279 shutil.rmtree(self.vis_c,ignore_errors=True)
00280 shutil.rmtree(self.vis_b,ignore_errors=True)
00281 shutil.rmtree(self.vis_d,ignore_errors=True)
00282 shutil.rmtree(self.vis_e,ignore_errors=True)
00283 shutil.rmtree(self.vis_f,ignore_errors=True)
00284 shutil.rmtree(self.vis_g,ignore_errors=True)
00285 os.system('rm -rf test*exportasdm*.asdm')
00286
00287 def test1a(self):
00288 '''Exportasdm: Cleanup'''
00289 pass
00290
00291 def suite():
00292 return [exportasdm_test,exportasdm_test2]
00293