Coverage for /wheeldirectory/casa-6.7.0-12-py3.10.el8/lib/py/lib/python3.10/site-packages/casatasks/private/task_vishead.py: 11%

44 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-10-31 19:53 +0000

1# This task is designed such that the user does not need to know the 

2# internal structure of the MS in order to change important bits of information. 

3# (A user with advanced knowlege of the MS can use the tb tool instead.) 

4# To accomplish this, I use a keyword dictionary that relates a "keyword" to 

5# an MS subtable and column. The keywords should correspond to FITS keywords 

6# whenever possible. 

7# 

8# The name vishead is a misnomer because casa tables do not have headers in the  

9# sense that FITS files do. The name derives from the IMHEAD, GETHEAD 

10# and PUTHEAD verbs in AIPS. 

11# 

12# Implementation: The task open/closes the MS for each keyword 

13# to read or write (and an extra time to check existence before reading). 

14# This is not very effective (in list mode, or when using this task in a loop; 

15# however expert users can always use the table tool directly. 

16 

17from casatools import ms 

18from casatasks import casalog 

19from .vishead_util import * 

20_ms = ms( ) 

21 

22def vishead(vis, mode=None, listitems=None, hdkey=None, hdindex=None, hdvalue=None): 

23 """Documentation goes here?""" 

24 

25 casalog.origin('vishead') 

26 casalog.post("parameter vis: " + str(vis), 'DEBUG1' ) 

27 casalog.post("parameter mode: " + str(mode), 'DEBUG1') 

28 casalog.post("parameter listitems: " + str(listitems), 'DEBUG1') 

29 casalog.post("parameter hdkey: " + str(hdkey), 'DEBUG1') 

30 casalog.post("parameter hdindex: " + str(hdindex), 'DEBUG1') 

31 casalog.post("parameter hdvalue: " + str(hdvalue), 'DEBUG1') 

32 

33 # Define vishead keywords 

34 keywords = { 

35 # Keywords from OBSERVATION TABLE 

36 # time_range 

37 'log': ['OBSERVATION', 'LOG', digest], #OPT AoAoS 

38 'schedule' :['OBSERVATION', 'SCHEDULE', digest], #array 

39 # flag_row 

40 'observer' :['OBSERVATION', 'OBSERVER', digest], #array 

41 'project' :['OBSERVATION', 'PROJECT', digest], #array 

42 'release_date' :['OBSERVATION', 'RELEASE_DATE', valref2localDate], #array 

43 'schedule_type' :['OBSERVATION', 'SCHEDULE_TYPE', digest], #array 

44 'telescope':['OBSERVATION', 'TELESCOPE_NAME', digest], #array 

45 

46 # Keywords from FIELD TABLE 

47 'field' :['FIELD', 'NAME', digest], # also in pointing table(!) 

48 # so watch out when changing 

49 'ptcs': ['FIELD', 'PHASE_DIR', valref2direction_strs], #OPT 

50 'fld_code': ['FIELD', 'CODE', digest], #OPT 

51 

52 # Keywords from SPECTRAL_WINDOW TABLE 

53 # not sure if all of these can freely edited by 

54 # the user without messing up the MS' internal consistency... 

55 

56 #don't allow change 'meas_freq_ref' :['SPECTRAL_WINDOW', 'MEAS_FREQ_REF'], 

57 #don't allow change 'ref_frequency' :['SPECTRAL_WINDOW', 'REF_FREQUENCY'], 

58 

59 #per channel 'chan_freq' :['SPECTRAL_WINDOW', 'CHAN_FREQ'], 

60 

61 #per channel 'chan_width' :['SPECTRAL_WINDOW', 'CHAN_WIDTH'], 

62 

63 #per channel 'effective_bw' :['SPECTRAL_WINDOW', 'EFFECTIVE_BW'], 

64 #'resolution' :['SPECTRAL_WINDOW', 'RESOLUTION'], 

65 'freq_group_name' :['SPECTRAL_WINDOW', 'FREQ_GROUP_NAME', digest], 

66 # don't allow change: 'total_bandwidth' :['SPECTRAL_WINDOW', 'TOTAL_BANDWIDTH'],  

67 'spw_name' :['SPECTRAL_WINDOW', 'NAME', digest], 

68 

69 # Keywords from SOURCE TABLE 

70 'source_name' :['SOURCE', 'NAME', digest], #OPT 

71 'cal_grp': ['SOURCE', 'CALIBRATION_GROUP', digest] #OPT 

72 

73 #MS_VERSION (probably not) 

74 } 

75 

76 # In list mode, list the keywords. 

77 if mode == 'list' or mode == '': 

78 

79 #tb.open(vis) 

80 #tb.summary() 

81 

82 values = {} 

83 if not listitems: 

84 listitems = list(keywords.keys()) 

85 listitems.sort() 

86 for key in listitems: 

87 if key in keywords: 

88 kwtuple = keywords.get(key) 

89 if keyword_exists(vis, kwtuple): 

90 casalog.post(' ' + str(kwtuple[0]) + \ 

91 ' -> ' + str(kwtuple[1]), 'DEBUG1') 

92 values[key] = getput_keyw('get', vis, kwtuple, '') 

93 if len(kwtuple) > 2: 

94 casalog.post(key + ': ' + str(kwtuple[2](values[key])), 

95 'INFO') 

96 else: 

97 casalog.post(key + ': ' + str(values[key]), 'INFO') 

98 else: 

99 casalog.post(key + ': <undefined>', 'INFO') 

100 else: 

101 casalog.post("Unrecognized item: " + key, 'WARN') 

102 

103 return values 

104 

105 # In summary mode, just list the MS basic info. 

106 elif mode == 'summary': 

107 _ms.open(vis) 

108 _ms.summary() 

109 _ms.close() 

110 casalog.post("Summary information is listed in logger") 

111 

112 # In GET/PUT mode, focus on 1 particular bit of MS data 

113 elif (mode=='get' or mode=='put'): 

114 if not hdkey in keywords: 

115 raise Exception("hdkey " + str(hdkey) +" is not a recognized keyword. Your options are " + str(keywords.keys())) 

116 

117 # get/put the data specified by hdkey 

118 if mode == 'get': 

119 value = getput_keyw(mode, vis, keywords[hdkey], hdindex) 

120 casalog.post(hdkey+': '+str(value)) 

121 return value 

122 else: 

123 getput_keyw(mode, vis, keywords[hdkey], hdindex, hdvalue) 

124 casalog.post(hdkey + ' set to ' + str(hdvalue))