casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
listvis_regression.py
Go to the documentation of this file.
00001 ##########################################################################
00002 # listvis_regression.py
00003 #
00004 # Regression test for task listvis.
00005 #
00006 # Current number of test scenarios: 4
00007 # 
00008 # The testing is performed by comparing the listvis output at runtime
00009 # with "standards" contained in the data repository.  "Metadata" (all 
00010 # output that is not a floating point number) is compared character by
00011 # character; any difference will cause the test to fail.  "Data" (all
00012 # floating point numbers in output) are assumed to be sequential 
00013 # amplitude-phase pairs and are required to be equal to within a 
00014 # minimum precision value specified below in this script.  
00015 #
00016 # Measurement sets are built from scratch using functions defined in this 
00017 # script.
00018 
00019 import time
00020 import listing as lt
00021 import regression_utility as tstutl
00022 
00023 startTime = time.time()
00024 
00025 print "BEGIN: listvis_regression.py"
00026 
00027 testPassed = 0
00028 testFailed = 0
00029 pathName = os.environ.get('CASAPATH').split()[0]
00030 automate = True # set to false for testing or debugging
00031 regressionDir = 'listvis_regression'
00032 if (not os.path.exists(regressionDir)): os.mkdir(regressionDir)
00033 
00034 if(automate): 
00035     print "Running in automated mode."
00036     print "  - All MS data will be rebuilt from scratch."
00037     print "  - All test files will be removed after testing."
00038 else:
00039     print "Running in non-automated mode!"
00040 
00041 # For testing:
00042 # casalog.filter('DEBUG2')
00043 
00044 #=============================================================================
00045 def load_ngc4826(prefix,msname):
00046     ##########################################################################
00047     #                                                                        
00048     # Clear out previous run results
00049     print "Removing files and directories: ngc4826.tutorial.*"
00050     os.system('rm -rf '+prefix+'ngc4826.tutorial.*')
00051     ##########################################################################
00052     # Import and concatenate sources
00053     #
00054     # Data Description:
00055     #
00056     # N4826 - BIMA SONG Data                                                 #
00057     #                                                                        #
00058     # This data is from the BIMA Survey of Nearby Galaxies (BIMA SONG)       #
00059     # Helfer, Thornley, Regan, et al., 2003, ApJS, 145, 259                  #
00060     #
00061     # 16apr98
00062     #   source=ngc4826
00063     #   phasecal=1310+323
00064     #   fluxcal=3c273, Flux = 23 Jy on 16apr98
00065     #   passcal= none - data were observed with online bandpass correction.
00066     #
00067     # NOTE: This data has been filled into MIRIAD, line-length correction 
00068     #   done, and then exported as separate files for each source.
00069     #   3c273 was not line length corrected since it was observed
00070     #   for such a short amount of time that it did not need it.  
00071     #
00072     # From miriad: source Vlsr = 408; delta V is 20 km/s 
00073     #
00074     # NOTE: This data contains correlations of only one polarization, 'YY'.
00075     # The antennas contain 'X' and 'Y' feeds, but the 'X' data was not 
00076     # correlated.
00077     #
00078     ##########################################################################
00079     # [ This section derived from the 2008 summer school tutorial. ]
00080     # [ http://casa.nrao.edu/Tutorial/SIworkshop2008/Scripts/ngc4826_tutorial.py ]
00081     #
00082     # USB spectral windows written separately by miriad for 16apr98
00083     # Assumes these are in sub-directory called "fitsfiles" of working directory
00084     print '--Importuvfits (16apr98)--'
00085     default('importuvfits')
00086 
00087     print "Starting from the uvfits files exported by miriad"
00088     print "The USB spectral windows were written separately by miriad for 16apr98"
00089 
00090     pathName = os.environ.get('CASAPATH').split()[0] 
00091     localData = pathName + '/data/regression/ngc4826/'
00092     importuvfits(fitsfile= localData + 'fitsfiles/3c273.fits5',        vis=prefix+'ngc4826.tutorial.3c273.5.ms')
00093     importuvfits(fitsfile= localData + 'fitsfiles/3c273.fits6',        vis=prefix+'ngc4826.tutorial.3c273.6.ms')
00094     importuvfits(fitsfile= localData + 'fitsfiles/3c273.fits7',        vis=prefix+'ngc4826.tutorial.3c273.7.ms')
00095     importuvfits(fitsfile= localData + 'fitsfiles/3c273.fits8',        vis=prefix+'ngc4826.tutorial.3c273.8.ms')
00096     importuvfits(fitsfile= localData + 'fitsfiles/1310+323.ll.fits9',  vis=prefix+'ngc4826.tutorial.1310+323.ll.9.ms')
00097     importuvfits(fitsfile= localData + 'fitsfiles/1310+323.ll.fits10', vis=prefix+'ngc4826.tutorial.1310+323.ll.10.ms')
00098     importuvfits(fitsfile= localData + 'fitsfiles/1310+323.ll.fits11', vis=prefix+'ngc4826.tutorial.1310+323.ll.11.ms')
00099     importuvfits(fitsfile= localData + 'fitsfiles/1310+323.ll.fits12', vis=prefix+'ngc4826.tutorial.1310+323.ll.12.ms')
00100     importuvfits(fitsfile= localData + 'fitsfiles/1310+323.ll.fits13', vis=prefix+'ngc4826.tutorial.1310+323.ll.13.ms')
00101     importuvfits(fitsfile= localData + 'fitsfiles/1310+323.ll.fits14', vis=prefix+'ngc4826.tutorial.1310+323.ll.14.ms')
00102     importuvfits(fitsfile= localData + 'fitsfiles/1310+323.ll.fits15', vis=prefix+'ngc4826.tutorial.1310+323.ll.15.ms')
00103     importuvfits(fitsfile= localData + 'fitsfiles/1310+323.ll.fits16', vis=prefix+'ngc4826.tutorial.1310+323.ll.16.ms')
00104     importuvfits(fitsfile= localData + 'fitsfiles/ngc4826.ll.fits5',   vis=prefix+'ngc4826.tutorial.ngc4826.ll.5.ms')
00105     importuvfits(fitsfile= localData + 'fitsfiles/ngc4826.ll.fits6',   vis=prefix+'ngc4826.tutorial.ngc4826.ll.6.ms')
00106     importuvfits(fitsfile= localData + 'fitsfiles/ngc4826.ll.fits7',   vis=prefix+'ngc4826.tutorial.ngc4826.ll.7.ms')
00107     importuvfits(fitsfile= localData + 'fitsfiles/ngc4826.ll.fits8',   vis=prefix+'ngc4826.tutorial.ngc4826.ll.8.ms')
00108     #
00109     ##########################################################################
00110     #
00111     print '--Concat--'
00112     default('concat')
00113     concat(vis=[prefix+'ngc4826.tutorial.3c273.5.ms',
00114                 prefix+'ngc4826.tutorial.3c273.6.ms',
00115                 prefix+'ngc4826.tutorial.3c273.7.ms',
00116                 prefix+'ngc4826.tutorial.3c273.8.ms',
00117                 prefix+'ngc4826.tutorial.1310+323.ll.9.ms',
00118                 prefix+'ngc4826.tutorial.1310+323.ll.10.ms',
00119                 prefix+'ngc4826.tutorial.1310+323.ll.11.ms',
00120                 prefix+'ngc4826.tutorial.1310+323.ll.12.ms',
00121                 prefix+'ngc4826.tutorial.1310+323.ll.13.ms',
00122                 prefix+'ngc4826.tutorial.1310+323.ll.14.ms',
00123                 prefix+'ngc4826.tutorial.1310+323.ll.15.ms',
00124                 prefix+'ngc4826.tutorial.1310+323.ll.16.ms',
00125                 prefix+'ngc4826.tutorial.ngc4826.ll.5.ms',
00126                 prefix+'ngc4826.tutorial.ngc4826.ll.6.ms',
00127                 prefix+'ngc4826.tutorial.ngc4826.ll.7.ms',
00128                 prefix+'ngc4826.tutorial.ngc4826.ll.8.ms'],
00129            concatvis=msname,
00130            freqtol="",dirtol="1arcsec",async=False)
00131 #=============================================================================
00132 
00133 #=============================================================================
00134 def load_jupiter6cm(prefix,msname):
00135     ######################################################################
00136     #                                                                    #
00137     # This is a VLA 6cm dataset that was observed in 1999 to set the     #
00138     # flux scale for calibration of the VLA.  Included in the program    #
00139     # were observations of the planets, including Jupiter.               #
00140     #                                                                    #
00141     # This is D-config VLA 6cm (4.85GHz) obs
00142     # Check the observational status summary
00143     # Primary beam FWHM = 45'/f_GHz = 557"
00144     # Synthesized beam FWHM = 14"
00145     # RMS in 10min (600s) = 0.06 mJy (thats now, but close enough)
00146     #
00147     ######################################################################
00148     # [ This section derived from the Jupiter 6cm VLA Use Case Script. ]
00149     # [ http://casa.nrao.edu/casatraining.shtml#scripts ]
00150 
00151     # Clean up old files
00152     os.system('rm -rf '+prefix+'*')    
00153     # This is the output MS file name
00154     msfile = msname
00155 
00156     # Get to path to the CASA home and stip off the name
00157     pathname=os.environ.get('CASAPATH').split()[0]
00158     # This is where the UVFITS data should be
00159     fitsdata=pathname+'/data/regression/jupiter6cm/jupiter6cm.fits'
00160     # Can also be found online at
00161     #http://casa.nrao.edu/Data/VLA/Planets6cm/planets_6cm.fits
00162 
00163     # Import the data from FITS to MS
00164     print '--Import--'
00165     print "Use importuvfits to read UVFITS and make an MS"
00166     # Set up the MS filename and save as new global variable
00167     print "MS will be called "+msfile
00168     # Use task importuvfits
00169     importuvfits(fitsfile=fitsdata,vis=msfile)
00170 #=============================================================================
00171 
00172 # # # # TESTS BEGIN HERE # # # # # # # # # # # # # # # # # # # # # # # # # # #
00173 
00174 testNum = 0
00175 
00176 ##########################################################################                                                                        
00177 # TEST1
00178 # Using ngc4826 data.  This data contains multiple spectral windows with
00179 # variable numbers of channels; only one correlation, YY.
00180 #
00181 testNum += 1
00182 print ""
00183 print "* TEST " + str(testNum) + ": using ngc4826 tutorial data"
00184 print ""
00185 
00186 prefix = regressionDir+'/test'+str(testNum)+'/'
00187 msname = prefix+"ngc4826.tutorial.ms"  
00188 outputFilename = prefix+'listvis.ngc4826.short.out'
00189 localData = pathName + '/data/regression/ngc4826/'
00190 standardFilename = localData+'listvis.short.out'
00191 
00192 #Remove existing data or load data from scratch?
00193 if (not lt.resetData([msname], automate)):
00194     print "Using preexisting data."
00195     lt.removeOut(outputFilename)
00196 else:
00197     print "Building data from scratch."
00198     tstutl.maketestdir(prefix) # create test dir, overwrite preexisting
00199     load_ngc4826(prefix,msname) # Build data from scratch
00200 
00201 # Setup listvis input and run
00202 default(listvis)
00203 vis                 = msname            #  Name of input visibility file
00204 options             =       'ap'        #  List options: ap only
00205 datacolumn          =     'data'        #  Column to list: data, corrected, model, residual
00206 field               =         ''        #  Field names or index to be listed: ''==>all
00207 spw                 =  '0~1:0~9'        #  Spectral window:channels: '\*'==>all, spw='1:5~57'
00208 selectdata          =       True        #  Other data selection parameters
00209 antenna             =      '6&7'        #  Antenna/baselines: ''==>all, antenna = '3'
00210 timerange           = '<03:33:48'       #  Time range: ''==>all
00211 correlation         =         ''        #  Correlations: ''==>all, correlation = 'RR RL'
00212 scan                =         ''        #  Scan numbers
00213 feed                =         ''        #  Multi-feed numbers (Not yet implemented)
00214 array               =         ''        #  Array numbers (Not yet implemented)
00215 uvrange             =         ''        #  uv range: ''==>all; not yet implemented
00216 average             =         ''        #  Averaging mode: ==>none (Not yet implemented)
00217 showflags           =      False        #  Show flagged data (Not yet implemented)
00218 pagerows            =         20        #  Rows per page
00219 listfile            = outputFilename   #  Output file
00220 async               =      False        #  If true the taskname must be started using listvis(...)
00221 go(listvis)
00222 
00223 comparefilename = prefix + 'compare_' + str(testNum)
00224 if (lt.runTests(outputFilename,standardFilename,'1.000',comparefilename)):
00225     print "passed listvis output test"
00226     testPassed +=1
00227 else:
00228     print "failed listvis output test"
00229     testFailed +=1
00230     
00231 ##########################################################################                                                                        
00232 # TEST 2 - NGC4826 defaults
00233 # Run listvis using default values.  Using ngc4826 data from above.
00234 #
00235 testNum += 1
00236 print ""
00237 print "* TEST " + str(testNum) + ": default test; using ngc4826 tutorial data."
00238 print """
00239 - Using default input values, except for 'vis' and 'listfile'.
00240 - This data has multiple spws with variable numbers of channels.
00241   *** listvis does not handle this data appropriately.    ***
00242   *** WARNing messages will be sent to the logger.        ***
00243   *** This is a known issue.  The test should still pass. ***
00244 
00245 """
00246 
00247 prefix = regressionDir+'/test'+str(testNum)+'/'
00248 outputFilename = prefix + 'listvis.ngc4826.default.out'
00249 standardFilename = localData+'listvis.default.out'
00250 
00251 tstutl.maketestdir(prefix) # create test dir, overwrite preexisting
00252 if (not lt.resetData([msname], automate)):
00253     print "Using data from test 1."
00254 else:
00255     print "Building data from scratch."
00256     msname = prefix+"ngc4826.tutorial.ms"  
00257     load_ngc4826(prefix,msname) # Build data from scratch
00258 
00259 default(listvis)
00260 vis                 = msname #  Name of input visibility file
00261 spw                 = '0'    #  Do not list too much 
00262 listfile            = outputFilename        #  Output file
00263 go(listvis)
00264 
00265 comparefilename = prefix + 'compare_' + str(testNum)
00266 if (lt.runTests(outputFilename,standardFilename,'1.000',comparefilename)):
00267     print "passed listvis output test"
00268     testPassed +=1
00269 else:
00270     print "failed listvis output test"
00271     testFailed +=1
00272 
00273 ##########################################################################                                                                        
00274 # TEST - jupiter6cm
00275 # Run listvis using all available (non-default) parameters.
00276 #
00277 testNum += 1
00278 print ""
00279 print "* TEST " + str(testNum) + ": jupiter 6cm test, use all available parameters"
00280 print ""
00281 
00282 prefix = regressionDir+'/test'+str(testNum)+'/'
00283 msname = prefix+"jupiter6cm.demo.ms"  
00284 outputFilename = prefix+'listvis.jupiter6cm.nondefault.out'
00285 localData = pathName + '/data/regression/jupiter6cm/'
00286 standardFilename = localData+'listvis.nondefault.out'
00287 
00288 #Remove existing data or load data from scratch?
00289 if (not lt.resetData([msname], automate)):
00290     print "Using preexisting data."
00291     lt.removeOut(outputFilename)
00292 else:
00293     print "Building data from scratch."
00294     tstutl.maketestdir(prefix) # create test dir, overwrite preexisting
00295     load_jupiter6cm(prefix,msname) # Build data from scratch
00296 
00297 default(listvis)
00298 vis                 = msname                   #  Name of input visibility file
00299 options             =       'ap'               #  List options: ap only
00300 datacolumn          =     'data'               #  Column to list: data, corrected, model, residual
00301 field               =       '12'               #  Field names or index to be listed: ''==>all
00302 spw                 =        '0'               #  Spectral window:channels: '\*'==>all, spw='1:5~57'
00303 selectdata          =       True               #  Other data selection parameters
00304 antenna             =    '16&22'               #  Antenna/baselines: ''==>all, antenna = '3'
00305 timerange           = '<1999/04/16/18:31:36.6' #  Time range: ''==>all
00306 correlation         = 'LL LR RR'               #  Correlations: ''==>all, correlation = 'RR RL'
00307 scan                =       '76'               #  Scan numbers
00308 feed                =         ''               #  Multi-feed numbers (Not yet implemented)
00309 array               =         ''               #  Array numbers (Not yet implemented)
00310 uvrange             =         ''               #  uv range: ''==>all; not yet implemented
00311 average             =         ''               #  Averaging mode: ==>none (Not yet implemented)
00312 showflags           =      False               #  Show flagged data (Not yet implemented)
00313 pagerows            =          5               #  Rows per page
00314 listfile            = outputFilename           #  Output file
00315 async               =      False               #  If true the taskname must be started using listvis(...)
00316 go(listvis)
00317 
00318 comparefilename = prefix + 'compare_' + str(testNum)
00319 if (lt.runTests(outputFilename,standardFilename,'1.000',comparefilename)):
00320     print "passed listvis output test"
00321     testPassed +=1
00322 else:
00323     print "failed listvis output test"
00324     testFailed +=1
00325 
00326 ##########################################################################                                                                        
00327 # TEST - jupiter6cm, mostly defaults
00328 # Run listvis using mostly default values.  Some selection is required;
00329 # otherwise the output file will be 227MB!
00330 # Using jupiter6cm data from above.
00331 #
00332 testNum += 1
00333 print ""
00334 print "* TEST " + str(testNum) + ": jupiter 6cm data, mostly defaults"
00335 print ""
00336 
00337 prefix = regressionDir+'/test'+str(testNum)+'/'
00338 outputFilename = prefix + 'listvis.jupiter6cm.default.out'
00339 standardFilename = localData+'listvis.default.out'
00340 
00341 tstutl.maketestdir(prefix) # create test dir, overwrite preexisting
00342 #Remove existing data or load data from scratch?
00343 if (not lt.resetData([msname], automate)):
00344     print "Using data from previous test."
00345 else:
00346     print "Building data from scratch."
00347     msname = prefix+"jupiter6cm.demo.ms"  
00348     load_jupiter6cm(prefix,msname) # Build data from scratch
00349 
00350 default(listvis)
00351 vis                 = msname            #  Name of input visibility file
00352 selectdata          =       True        #  Other data selection parameters
00353 scan                =        '76'        #  Scan numbers
00354 listfile            = outputFilename    #  Output file
00355 go(listvis)
00356 
00357 comparefilename = prefix + 'compare_' + str(testNum)
00358 if (lt.runTests(outputFilename,standardFilename,'1.000',comparefilename)):
00359     print "passed listvis output test"
00360     testPassed +=1
00361 else:
00362     print "failed listvis output test"
00363     testFailed +=1
00364 
00365 ##########################################################################                                                                        
00366 # TEST 5
00367 # Using single dish data OrionS_rawACSmod.  This data contains multiple
00368 # numbers of channels and DATA_FLOAT column (CAS-2138)
00369 #
00370 testNum += 1
00371 print ""
00372 print "* TEST " + str(testNum) + ": using single dish data OrionS_rawACSmod"
00373 print ""
00374 
00375 prefix = regressionDir+'/test'+str(testNum)+'/'
00376 msname = prefix+"OrionS_rawACSmod"  
00377 outputFilename = prefix+'listvis.orion.short.out'
00378 localData = pathName + '/data/regression/ATST5/OrionS/'
00379 standardFilename = localData+'listvis.orionshort.out'
00380 
00381 #Remove existing data or load data from scratch?
00382 if (not lt.resetData([msname], automate)):
00383     print "Using preexisting data."
00384     lt.removeOut(outputFilename)
00385 else:
00386     print "Building data from scratch."
00387     tstutl.maketestdir(prefix) # create test dir, overwrite preexisting
00388     shutil.copytree(localData+'OrionS_rawACSmod', msname)
00389 
00390 # Setup listvis input and run
00391 default(listvis)
00392 vis                 = msname            #  Name of input visibility file
00393 options             =       'ap'        #  List options: ap only
00394 datacolumn          =     'float_data'  #  Column to list: data, corrected, model, residual
00395 field               =         ''        #  Field names or index to be listed: ''==>all
00396 spw                 =  '0:1200~1205'    #  Spectral window:channels: '\*'==>all, spw='1:5~57'
00397 selectdata          =       True        #  Other data selection parameters
00398 showflags           =      False        #  Show flagged data (Not yet implemented)
00399 pagerows            =         20        #  Rows per page
00400 listfile            = outputFilename   #  Output file
00401 async               =      False        #  If true the taskname must be started using listvis(...)
00402 go(listvis)
00403 
00404 comparefilename = prefix + 'compare_' + str(testNum)
00405 if (lt.runTests(outputFilename,standardFilename,'1.000',comparefilename)):
00406     print "passed listvis output test"
00407     testPassed +=1
00408 else:
00409     print "failed listvis output test"
00410     testFailed +=1
00411 
00412 ##########################################################################                                                                        
00413 # Test complete, summarize.
00414 #
00415 
00416 print ""
00417 print "* listvis regression test complete"
00418 print "SUMMARY:"
00419 print "  number of tests PASSED: " + str(testPassed)
00420 print "  number of tests FAILED: " + str(testFailed)
00421 print ""
00422 
00423 if testFailed > 0:
00424     print ''
00425     print 'Regression FAILED'
00426     print ''
00427 else:
00428     print ''
00429     print 'Regression PASSED'
00430     print ''
00431 
00432 print "END: listvis_regression.py"
00433 
00434 if (testFailed > 0):
00435     regstate = False
00436 else:
00437     regstate = True
00438     
00439 endTime = time.time()