casa
$Rev:20696$
|
00001 # This task is designed such that the user does not need to know the 00002 # internal structure of the MS in order to change important bits of information. 00003 # (A user with advanced knowlege of the MS can use the tb tool instead.) 00004 # To accomplish this, I use a keyword dictionary that relates a "keyword" to 00005 # an MS subtable and column. The keywords should correspond to FITS keywords 00006 # whenever possible. 00007 # 00008 # The name vishead is a misnomer because casa tables do not have headers in the 00009 # sense that FITS files do. The name derives from the IMHEAD, GETHEAD 00010 # and PUTHEAD verbs in AIPS. 00011 # 00012 # Implementation: The task open/closes the MS for each keyword 00013 # to read or write (and an extra time to check existence before reading). 00014 # This is not very effective (in list mode, or when using this task in a loop; 00015 # however expert users can always use the table tool directly. 00016 00017 from taskinit import * 00018 from vishead_util import * 00019 00020 def vishead(vis, mode=None, listitems=None, hdkey=None, hdindex=None, hdvalue=None): 00021 """Documentation goes here?""" 00022 00023 casalog.origin('vishead') 00024 casalog.post("parameter vis: " + str(vis), 'DEBUG1' ) 00025 casalog.post("parameter mode: " + str(mode), 'DEBUG1') 00026 casalog.post("parameter listitems: " + str(listitems), 'DEBUG1') 00027 casalog.post("parameter hdkey: " + str(hdkey), 'DEBUG1') 00028 casalog.post("parameter hdindex: " + str(hdindex), 'DEBUG1') 00029 casalog.post("parameter hdvalue: " + str(hdvalue), 'DEBUG1') 00030 00031 # Define vishead keywords 00032 keywords = { 00033 # Keywords from OBSERVATION TABLE 00034 # time_range 00035 'log': ['OBSERVATION', 'LOG', digest], #OPT AoAoS 00036 'schedule' :['OBSERVATION', 'SCHEDULE', digest], #array 00037 # flag_row 00038 'observer' :['OBSERVATION', 'OBSERVER', digest], #array 00039 'project' :['OBSERVATION', 'PROJECT', digest], #array 00040 'release_date' :['OBSERVATION', 'RELEASE_DATE', valref2localDate], #array 00041 'schedule_type' :['OBSERVATION', 'SCHEDULE_TYPE', digest], #array 00042 'telescope':['OBSERVATION', 'TELESCOPE_NAME', digest], #array 00043 00044 # Keywords from FIELD TABLE 00045 'field' :['FIELD', 'NAME', digest], # also in pointing table(!) 00046 # so watch out when changing 00047 'ptcs': ['FIELD', 'PHASE_DIR', valref2direction_strs], #OPT 00048 'fld_code': ['FIELD', 'CODE', digest], #OPT 00049 00050 # Keywords from SPECTRAL_WINDOW TABLE 00051 # not sure if all of these can freely edited by 00052 # the user without messing up the MS' internal consistency... 00053 00054 #don't allow change 'meas_freq_ref' :['SPECTRAL_WINDOW', 'MEAS_FREQ_REF'], 00055 #don't allow change 'ref_frequency' :['SPECTRAL_WINDOW', 'REF_FREQUENCY'], 00056 00057 #per channel 'chan_freq' :['SPECTRAL_WINDOW', 'CHAN_FREQ'], 00058 00059 #per channel 'chan_width' :['SPECTRAL_WINDOW', 'CHAN_WIDTH'], 00060 00061 #per channel 'effective_bw' :['SPECTRAL_WINDOW', 'EFFECTIVE_BW'], 00062 #'resolution' :['SPECTRAL_WINDOW', 'RESOLUTION'], 00063 'freq_group_name' :['SPECTRAL_WINDOW', 'FREQ_GROUP_NAME', digest], 00064 # don't allow change: 'total_bandwidth' :['SPECTRAL_WINDOW', 'TOTAL_BANDWIDTH'], 00065 'spw_name' :['SPECTRAL_WINDOW', 'NAME', digest], 00066 00067 # Keywords from SOURCE TABLE 00068 'source_name' :['SOURCE', 'NAME', digest], #OPT 00069 'cal_grp': ['SOURCE', 'CALIBRATION_GROUP', digest] #OPT 00070 00071 #MS_VERSION (probably not) 00072 } 00073 00074 try: 00075 # In list mode, list the keywords. 00076 if mode == 'list' or mode == '': 00077 00078 #tb.open(vis) 00079 #tb.summary() 00080 00081 values = {} 00082 if not listitems: 00083 listitems = keywords.keys() 00084 listitems.sort() 00085 for key in listitems: 00086 if keywords.has_key(key): 00087 kwtuple = keywords.get(key) 00088 if keyword_exists(vis, kwtuple): 00089 casalog.post(' ' + str(kwtuple[0]) + \ 00090 ' -> ' + str(kwtuple[1]), 'DEBUG1') 00091 values[key] = getput_keyw('get', vis, kwtuple, '') 00092 if len(kwtuple) > 2: 00093 casalog.post(key + ': ' + str(kwtuple[2](values[key])), 00094 'INFO') 00095 else: 00096 casalog.post(key + ': ' + str(values[key]), 'INFO') 00097 else: 00098 casalog.post(key + ': <undefined>', 'INFO') 00099 else: 00100 casalog.post("Unrecognized item: " + key, 'WARN') 00101 00102 return values 00103 00104 # In summary mode, just list the MS basic info. 00105 elif mode == 'summary': 00106 ms.open(vis) 00107 ms.summary() 00108 ms.close() 00109 print "Summary information is listed in logger" 00110 00111 # In GET/PUT mode, focus on 1 particular bit of MS data 00112 elif (mode=='get' or mode=='put'): 00113 if(not keywords.has_key(hdkey)): 00114 raise Exception, "hdkey " + str(hdkey) +" is not a recognized keyword. Your options are " + str(keywords.keys()) 00115 00116 # get/put the data specified by hdkey 00117 if mode == 'get': 00118 value = getput_keyw(mode, vis, keywords[hdkey], hdindex) 00119 casalog.post(hdkey+': '+str(value)) 00120 return value 00121 else: 00122 getput_keyw(mode, vis, keywords[hdkey], hdindex, hdvalue) 00123 casalog.post(hdkey + ' set to ' + str(hdvalue)) 00124 00125 except Exception, instance: 00126 casalog.post( str('*** Error *** ') + str(instance), 'SEVERE') 00127 00128 return