casa
$Rev:20696$
|
00001 # 00002 # Run this script to create the MMS data needed to run the Python unit tests 00003 # of some tasks. This script will try to find the location of the data repository 00004 # based on the value of CASAPATH. The MSs will be read from the unittest directory 00005 # of the data repository. The output MMSs will be created in the local directory 00006 # under unittest_mms/<taskname>. The MMS directory will be removed if the command 00007 # is repeated for the same task. 00008 # 00009 00010 00011 import os 00012 import sys 00013 import re 00014 import getopt 00015 import pprint 00016 import traceback 00017 import shutil 00018 import partitionhelper as ph 00019 00020 # ---------- ADD NEW TASKS HERE ---------------- 00021 # These tasks have been verified to work on MMS. 00022 TASKLIST = [ 00023 'bandpass', 00024 'flagdata', 00025 'fluxscale', 00026 'gaincal', 00027 'gencal', 00028 'listhistory', 00029 'listobs', 00030 'listvis', # shared with fixplanets 00031 'plotms', 00032 'split', 00033 'uvcontsub', 00034 'vishead', 00035 'wvrgcal', 00036 'concat' # shared with virtualconcat 00037 ] 00038 00039 # NOTE: task 'fixplanets' uses data from task 'listvis' 00040 00041 # NOTE: task 'concat' only works with MMSs if the first input MS is a normal MS; 00042 # the test data is also needed for testing virtualconcat 00043 00044 # Try to get the data repository path from the system 00045 DATAPATH = os.environ.get('CASAPATH').split()[0] + '/data/regression/' 00046 00047 def usage(): 00048 print '=========================================================================' 00049 print '\nmake_mmsdata will create Multi-MS data for CASA tasks.' 00050 print 'Usage:\n' 00051 print 'casapy [casapy-options] -c make_mmsdata.py [options] <tasks>\n' 00052 print 'Options:' 00053 print ' no option print this message and exit.' 00054 print ' --all run the script for all tasks in TASKLIST.' 00055 print ' --ignore do no create MMS for the given <tasks>.' 00056 print ' --list print the list of tasks from TASKLIST and exit.' 00057 print 'NOTE: it will look for MS data in the data repository under unittest.\r' 00058 print '==========================================================================' 00059 00060 00061 def selectList(nolist): 00062 '''Return the subtracted list of tasks 00063 nolist --> list of tasks to ignore''' 00064 00065 newlist = [] 00066 for t in TASKLIST: 00067 if t not in nolist: 00068 newlist.append(t) 00069 00070 return newlist 00071 00072 00073 # Function to call partitionhelper.convertToMMS() 00074 def mmstest(mytask): 00075 00076 TESTPATH = DATAPATH + 'unittest/' 00077 INPPATH = TESTPATH + mytask 00078 MMSPATH = './unittest_mms/'+mytask 00079 00080 print '--------- Will create MMS data for test_'+mytask 00081 ph.convertToMMS(inpdir=INPPATH, mmsdir=MMSPATH, createmslink=True, cleanup=True) 00082 00083 00084 # Location of the data repository 00085 if not os.environ.has_key('CASAPATH'): 00086 print 'ERROR: Could not find variable CASAPATH' 00087 os._exit(2) 00088 00089 00090 def main(thislist): 00091 00092 if thislist == []: 00093 print 'Need list of tasks to run.' 00094 usage() 00095 os._exit(0) 00096 00097 00098 # Loop through task list 00099 for t in thislist: 00100 if t not in TASKLIST: 00101 print 'ERROR: task '+t+' is not in TASKLIST. Run this script with -l for the full list.' 00102 os._exit(0) 00103 00104 mmstest(t) 00105 00106 from tasks import partition 00107 00108 if 'listvis' in thislist: 00109 # NOTE for test_listvis data: 00110 # You need to run partition by hand to create an MMS for the single-dish data set 00111 SDPATH = DATAPATH + 'unittest/listvis/' 00112 SDMMS = './unittest_mms/listvis/' 00113 00114 partition(vis=SDPATH+'OrionS_rawACSmod', outputvis=SDMMS+'OrionS_rawACSmod.mms', datacolumn='float_data', createmms=True) 00115 00116 if 'split' in thislist: 00117 # some additional MMSs 00118 SPLITMMSPATH = './unittest_mms/split/' 00119 specialcase = ['0420+417/0420+417.ms', 00120 'viewertest/ctb80-vsm.ms', 00121 'split/labelled_by_time+ichan.ms'] 00122 for myms in specialcase: 00123 shutil.rmtree(SPLITMMSPATH+os.path.basename(myms), ignore_errors=True) 00124 partition(vis=DATAPATH+myms, outputvis=SPLITMMSPATH+os.path.basename(myms), datacolumn='all') 00125 00126 # workaround for a partition shortcoming: column keywords not copied 00127 tb.open(SPLITMMSPATH+'hasfc.mms/SUBMSS/hasfc.0000.ms/', nomodify=False) 00128 tb.putcolkeyword('FLAG_CATEGORY','CATEGORY', ['FLAG_CMD', 'ORIGINAL', 'USER']) 00129 tb.close() 00130 00131 00132 if 'wvrgcal' in thislist: 00133 WVRGCALMMSPATH = './unittest_mms/wvrgcal/' 00134 WVRGCALPATH = DATAPATH+'unittest/wvrgcal/input/' 00135 origwd = os.getcwd() 00136 os.chdir(WVRGCALMMSPATH) 00137 shutil.rmtree('input', ignore_errors=True) 00138 os.mkdir('input') 00139 os.chdir('input') 00140 mydirs = os.listdir(WVRGCALPATH) 00141 for d in mydirs: 00142 print d 00143 if os.path.splitext(d)[1]=='.ms': 00144 partition(vis=WVRGCALPATH+d, outputvis=d, datacolumn='all', numsubms=5) 00145 else: 00146 os.symlink(WVRGCALPATH+d, d) 00147 os.chdir(origwd) 00148 00149 if ('concat' in thislist): 00150 CONCATMMSPATH = './unittest_mms/concat/' 00151 CONCATPATH = DATAPATH+'unittest/concat/input/' 00152 origwd = os.getcwd() 00153 os.chdir(CONCATMMSPATH) 00154 shutil.rmtree('input', ignore_errors=True) 00155 os.mkdir('input') 00156 os.chdir('input') 00157 mydirs = os.listdir(CONCATPATH) 00158 for d in mydirs: 00159 print d 00160 if os.path.splitext(d)[1]=='.ms': 00161 partition(vis=CONCATPATH+d, outputvis=d, datacolumn='all', numsubms=6) 00162 else: 00163 os.symlink(CONCATPATH+d, d) 00164 os.chdir(origwd) 00165 00166 00167 if __name__ == "__main__": 00168 00169 # Get command line arguments 00170 if "-c" in sys.argv: 00171 # It is called with casapy ... -c make_mmsdata.py from the command line, 00172 i = sys.argv.index("-c") 00173 if len(sys.argv) >= i + 2 and \ 00174 re.compile("make_mmsdata\.py$").search(sys.argv[i + 1]): 00175 00176 try: 00177 # Get only this script options 00178 opts,args=getopt.getopt(sys.argv[i+2:], "ail", ["all", "ignore","list"]) 00179 00180 except getopt.GetoptError, err: 00181 # Print help information and exit: 00182 print str(err) # will print something like "option -a not recognized" 00183 usage() 00184 os._exit(2) 00185 00186 # List of tests to run 00187 tasknames = [] 00188 00189 ignore = False 00190 all = False 00191 00192 # Print help and exit 00193 if opts == [] and args == []: 00194 usage() 00195 os._exit(0) 00196 00197 elif opts != []: 00198 for o, a in opts: 00199 if o in ("-a", "--all"): 00200 all = True 00201 tasknames = TASKLIST 00202 break 00203 00204 elif o in ("-i", "--ignore"): 00205 # Will ignore the tasks given in args 00206 ignore = True 00207 break 00208 00209 elif o in ("-l", "--list"): 00210 print 'List of tasks to create MMS for:' 00211 pprint.pprint(TASKLIST) 00212 os._exit(0) 00213 00214 else: 00215 assert False, "unhandled option" 00216 00217 # Get tasks 00218 if args == [] and ignore: 00219 print "ERROR: --ignore needs a list of tasks." 00220 usage() 00221 os._exit(0) 00222 00223 if args != [] and not all: 00224 tasknames = args 00225 if ignore: 00226 tasknames = selectList(args) 00227 00228 try: 00229 main(tasknames) 00230 except: 00231 traceback.print_exc() 00232 00233 00234 00235