casa
$Rev:20696$
|
00001 #! /usr/bin/env python 00002 # -*- coding: utf-8 -*- 00003 import sys 00004 import string 00005 import inspect 00006 00007 from parameter_check import * 00008 00009 00010 def importarchive( 00011 archivefiles=None, 00012 vis=None, 00013 bandname=None, 00014 freqtol=None, 00015 ): 00016 """Convert VLA archive file(s) to a CASA visibility data set (MS): 00017 00018 ....Keyword arguments: 00019 ....archivefiles -- Name of input VLA archive file(s) 00020 ........default: <unset> 00021 ........example: archivefiles=['AP314_A950519.xp1','AP314_A950519.xp2'] 00022 ....vis -- Name of output visibility file (MS) 00023 ........default: <unset>; example: vis='NGC7538.ms' 00024 ....bandname -- VLA Frequency band 00025 ........default: <unset> - all bands; example: bandname='K' 00026 ........<Options: '4'=48-96 MHz,'P'=298-345 MHz,'L'=1.15-1.75 GHz, 00027 ........'C'=4.2-5.1 GHz,'X'=6.8-9.6 GHz,'U'=13.5-16.3 GHz, 00028 ........'K'=20.8-25.8 GHz,'Q'=38-51 GHz> 00029 ....#projectname -- Observing project name 00030 ....#....default: <unset>; example='AP314' 00031 ....freqtol -- Tolerance in frequency shift in naming spectral windows 00032 ........default: channel width of current spectral window in Hz 00033 ........example: 150000.0 00034 .... 00035 00036 ....""" 00037 00038 a = inspect.stack() 00039 stacklevel = 0 00040 for k in range(len(a)): 00041 if string.find(a[k][1], 'casapy.py') > 0: 00042 stacklevel = k 00043 break 00044 myf = sys._getframe(len(a) - stacklevel).f_globals 00045 # myf=sys._getframe(1).f_globals 00046 vftask = myf['vftask'] 00047 vlafiller = vftask.fill 00048 # fg = myf['fg'] 00049 aflocal = casac.agentflagger() 00050 # ## 00051 # Handle globals or user over-ride of arguments 00052 function_signature_defaults = \ 00053 dict(zip(importarchive.func_code.co_varnames, 00054 importarchive.func_defaults)) 00055 for item in function_signature_defaults.iteritems(): 00056 (key, val) = item 00057 keyVal = eval(key) 00058 if keyVal == None: 00059 # user hasn't set it - use global/default 00060 pass 00061 else: 00062 # user has set it - use over-ride 00063 # sys._getframe().f_globals[key]=keyVal 00064 myf[key] = keyVal 00065 00066 archivefiles = myf['archivefiles'] 00067 vis = myf['vis'] 00068 bandname = myf['bandname'] 00069 freqtol = myf['freqtol'] 00070 # 00071 # ## 00072 00073 # Add type/menu/range error checking here 00074 if type(archivefiles) == str: 00075 archivefiles = [archivefiles] 00076 arg_names = ['archivefiles', 'vis', 'bandname', 'freqtol'] 00077 arg_values = [archivefiles, vis, bandname, freqtol] 00078 arg_types = [list, str, str, float] 00079 try: 00080 parameter_checktype(arg_names, arg_values, arg_types) 00081 parameter_checkmenu('bandname', bandname, [ 00082 '4', 00083 'P', 00084 'L', 00085 'C', 00086 'X', 00087 'U', 00088 'K', 00089 'Q', 00090 ]) 00091 except TypeError, e: 00092 print 'importarchive -- TypeError: ', e 00093 return 00094 except ValueError, e: 00095 print 'importarchive -- OptionError: ', e 00096 return 00097 # ## 00098 00099 # Python script 00100 i = 0 00101 overwrite = True 00102 try: 00103 for archivefile in archivefiles: 00104 if i > 0: 00105 overwrite = False 00106 vlafiller(msname=vis, inputfile=archivefile, 00107 overwrite=overwrite, bandname=bandname, 00108 freqtol=freqtol) 00109 i = i + 1 00110 00111 # write history 00112 if (type(vis) == str) & os.path.exists(vis): 00113 ms.open(vis, nomodify=False) 00114 else: 00115 raise Exception, \ 00116 'Visibility data set not found - please verify the name' 00117 ms.writehistory(message='taskname = importuvfits', 00118 origin='importuvfits') 00119 ms.writehistory(message='fitsfile = "' + str(fitsfile) + '"' 00120 , origin='importuvfits') 00121 ms.writehistory(message='vis = "' + str(vis) + '"', 00122 origin='importuvfits') 00123 ms.close() 00124 except: 00125 00126 print '*** Error ***' 00127 00128 ok = aflocal.open(vis) 00129 ok = aflocal.saveflagversion('Original', 00130 comment='Original flags at import into CASA' 00131 , merge='save') 00132 ok = aflocal.done() 00133 saveinputs = myf['saveinputs'] 00134 saveinputs('importarchive', 'importarchive.last') 00135 00136