00001
00002
00003 myname = 'test_task_exportasdm'
00004
00005 import os
00006
00007 vis_b = 'test.ms'
00008
00009 vis_d = 'ngc4826.tutorial.ngc4826.ll.5.ms'
00010 vis_e = 'g19_d2usb_targets_line-shortened.ms'
00011 vis_f = 'Itziar.ms'
00012 vis_g = 'M51.ms'
00013
00014
00015
00016 if(not os.path.exists(vis_b)):
00017 os.system('cp -R '+os.environ['CASADATA']+'/regression/fits-import-export/input/test.ms .')
00018
00019
00020 if(not os.path.exists(vis_d)):
00021 importuvfits(fitsfile=os.environ['CASADATA']+'/regression/ngc4826/fitsfiles/ngc4826.ll.fits5', vis=vis_d)
00022 if(not os.path.exists(vis_e)):
00023 os.system('cp -R '+os.environ['CASADATA']+'/regression/cvel/input/g19_d2usb_targets_line-shortened.ms .')
00024 if(not os.path.exists(vis_f)):
00025 os.system('cp -R '+os.environ['CASADATA']+'/regression/exportasdm/input/Itziar.ms .')
00026 if(not os.path.exists(vis_g)):
00027 os.system('cp -R '+os.environ['CASADATA']+'/regression/exportasdm/input/M51.ms .')
00028
00029
00030 def verify_asdm(asdmname, withPointing):
00031 print "Verifying asdm ", asdmname
00032 if(not os.path.exists(asdmname)):
00033 print "asdm ", asdmname, " doesn't exist."
00034 raise Exception
00035
00036 allTables = [ "Antenna.xml",
00037 "ASDM.xml",
00038
00039
00040
00041 "ConfigDescription.xml",
00042 "CorrelatorMode.xml",
00043 "DataDescription.xml",
00044 "ExecBlock.xml",
00045 "Feed.xml",
00046 "Field.xml",
00047
00048
00049 "Main.xml",
00050 "PointingModel.xml",
00051 "Polarization.xml",
00052 "Processor.xml",
00053 "Receiver.xml",
00054 "SBSummary.xml",
00055 "Scan.xml",
00056 "Source.xml",
00057 "SpectralWindow.xml",
00058 "State.xml",
00059 "Station.xml",
00060 "Subscan.xml",
00061 "SwitchCycle.xml"
00062 ]
00063 isOK = True
00064 for fileName in allTables:
00065 filePath = asdmname+'/'+fileName
00066 if(not os.path.exists(filePath)):
00067 print "ASDM table file ", filePath, " doesn't exist."
00068 isOK = False
00069 else:
00070
00071 rval = os.system('xmllint --noout '+filePath)
00072 if(rval !=0):
00073 print "Table ", filePath, " is not a well formed XML document."
00074 isOK = False
00075
00076 print "Note: xml validation not possible since ASDM DTDs (schemas) not yet online."
00077
00078 if(not os.path.exists(asdmname+"/ASDMBinary")):
00079 print "ASDM binary directory "+asdmname+"/ASDMBinary doesn't exist."
00080 isOK = False
00081
00082 if(withPointing and not os.path.exists(asdmname+"/Pointing.bin")):
00083 print "ASDM binary file "+asdmname+"/Pointing.bin doesn't exist."
00084 isOK = False
00085
00086 if (not isOK):
00087 raise Exception
00088
00089
00090
00091 keeptestlist = True
00092
00093 try:
00094 print "List of tests to be executed ...", testlist
00095 except:
00096 print "Global variable testlist not set."
00097 testlist = []
00098 if (testlist==[]):
00099 print "testlist empty. Executing all tests."
00100 testlist = range(0,100)
00101 keeptestlist = False
00102
00103 total = 0
00104 failures = 0
00105 rval = False
00106
00107 testnumber = 1
00108 if (testnumber in testlist):
00109 myvis = vis_b
00110 os.system('rm -rf exportasdm-output.asdm myinput.ms')
00111 os.system('cp -R ' + myvis + ' myinput.ms')
00112 default('exportasdm')
00113 total += 1
00114 try:
00115 print "\n>>>> Test ", testnumber, ", input MS: ", myvis
00116 print "Testing default."
00117 rval = exportasdm()
00118 if not rval:
00119 print myname, ': *** Error as expected ***'
00120 else:
00121 print "Failed ..."
00122 failures +=1
00123 except:
00124 print myname, ': *** Unexpected error ***'
00125 failures += 1
00126
00127
00128 testnumber = 2
00129 if (testnumber in testlist):
00130 myvis = vis_b
00131 os.system('rm -rf exportasdm-output.asdm myinput.ms')
00132 os.system('cp -R ' + myvis + ' myinput.ms')
00133 default('exportasdm')
00134 total += 1
00135 try:
00136 print "\n>>>> Test ", testnumber, ", input MS: ", myvis
00137 print "small input MS, default output"
00138 rval = exportasdm(
00139 vis = 'myinput.ms',
00140 asdm = 'exportasdm-output.asdm',
00141 archiveid="S1",
00142 verbose=True,
00143 apcorrected=False
00144 )
00145 print "rval is ", rval
00146 if not rval:
00147 raise Exception
00148 omsname = "test"+str(testnumber)+'exportasdm-output.asdm'
00149 os.system('rm -rf '+omsname+'; mv exportasdm-output.asdm '+omsname)
00150 verify_asdm(omsname, False)
00151 except:
00152 print myname, ': *** Unexpected error ***'
00153 failures += 1
00154
00155 testnumber = 3
00156 if (testnumber in testlist):
00157 myvis = vis_f
00158 os.system('rm -rf exportasdm-output.asdm myinput.ms')
00159 os.system('cp -R ' + myvis + ' myinput.ms')
00160 default('exportasdm')
00161 total += 1
00162 try:
00163 print "\n>>>> Test ", testnumber, ", input MS: ", myvis
00164 print "simulated input MS, default output"
00165 rval = exportasdm(
00166 vis = 'myinput.ms',
00167 asdm = 'exportasdm-output.asdm',
00168 archiveid="S1"
00169 )
00170 print "rval is ", rval
00171 if not rval:
00172 raise Exception
00173 omsname = "test"+str(testnumber)+'exportasdm-output.asdm'
00174 os.system('rm -rf '+omsname+'; mv exportasdm-output.asdm '+omsname)
00175 verify_asdm(omsname, True)
00176 except:
00177 print myname, ': *** Unexpected error ***'
00178 failures += 1
00179
00180 testnumber = 4
00181 if (testnumber in testlist):
00182 myvis = vis_d
00183 os.system('rm -rf exportasdm-output.asdm myinput.ms')
00184 os.system('cp -R ' + myvis + ' myinput.ms')
00185 default('exportasdm')
00186 total += 1
00187 try:
00188 print "\n>>>> Test ", testnumber, ", input MS: ", myvis
00189 print "real input MS, default output"
00190 rval = exportasdm(
00191 vis = 'myinput.ms',
00192 asdm = 'exportasdm-output.asdm',
00193 archiveid="S1",
00194 apcorrected=False
00195 )
00196 print "rval is ", rval
00197 if not rval:
00198 raise Exception
00199 omsname = "test"+str(testnumber)+'exportasdm-output.asdm'
00200 os.system('rm -rf '+omsname+'; mv exportasdm-output.asdm '+omsname)
00201 verify_asdm(omsname, False)
00202 except:
00203 print myname, ': *** Unexpected error ***'
00204 failures += 1
00205
00206 testnumber = 5
00207 if (testnumber in testlist):
00208 myvis = vis_e
00209 os.system('rm -rf exportasdm-output.asdm myinput.ms')
00210 os.system('cp -R ' + myvis + ' myinput.ms')
00211 default('exportasdm')
00212 total += 1
00213 try:
00214 print "\n>>>> Test ", testnumber, ", input MS: ", myvis
00215 print "real input MS, MS has several SPWs observed in parallel - not supported, expected error"
00216 rval = exportasdm(
00217 vis = 'myinput.ms',
00218 asdm = 'exportasdm-output.asdm',
00219 archiveid="S1",
00220 apcorrected=False
00221 )
00222 print "rval is ", rval
00223 if not rval:
00224 print myname, ': *** Error as expected ***'
00225 else:
00226 print "Failed ..."
00227 failures +=1
00228 except:
00229 print myname, ': *** Unexpected error ***'
00230 failures += 1
00231
00232 testnumber = 6
00233 if (testnumber in testlist):
00234 myvis = vis_g
00235 os.system('rm -rf exportasdm-output.asdm myinput.ms')
00236 os.system('cp -R ' + myvis + ' myinput.ms')
00237 default('exportasdm')
00238 total += 1
00239 try:
00240 print "\n>>>> Test ", testnumber, ", input MS: ", myvis
00241 print "simulated input MS with pointing table, default output"
00242 rval = exportasdm(
00243 vis = 'myinput.ms',
00244 asdm = 'exportasdm-output.asdm',
00245 archiveid="S002",
00246 apcorrected=False
00247 )
00248 print "rval is ", rval
00249 if not rval:
00250 raise Exception
00251 omsname = "test"+str(testnumber)+'exportasdm-output.asdm'
00252 os.system('rm -rf '+omsname+'; mv exportasdm-output.asdm '+omsname)
00253 verify_asdm(omsname, True)
00254 except:
00255 print myname, ': *** Unexpected error ***'
00256 failures += 1
00257
00258
00259
00260 print "Tests = ", total
00261 print "Failures = ", failures
00262
00263
00264 if not keeptestlist:
00265 testlist = []