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

65 statements  

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

1import os 

2import sys 

3import shutil 

4 

5from casatasks import casalog 

6from casatools import ms as mstool 

7from casatools import table as tbtool 

8from .mslisthelper import check_mslist 

9 

10def testconcat(vislist,testconcatvis,freqtol,dirtol,copypointing): 

11 """ 

12 The list of data sets given in the vis argument are concatenated into an output 

13 data set in concatvis without copying the bulk data of the main table. 

14 This is useful for obtaining the information in the merged subtables without 

15 actually performing a time-consuming concatenation disk. 

16 

17 Keyword arguments: 

18 vis -- Name of input visibility files for which the subtables are to be combined 

19 default: none; example: vis = 'mydata.ms', 

20 example: vis=['src2.ms','ngc5921.ms','ngc315.ms'] 

21  

22 testconcatvis -- Name of MS that will contain the concatenated subtables 

23 default: none; example: testconcatvis='test.ms' 

24  

25 freqtol -- Frequency shift tolerance for considering data to be in the same 

26 spwid. The number of channels must also be the same. 

27 default: '' do not combine unless frequencies are equal 

28 example: freqtol='10MHz' will not combine spwid unless they are 

29 within 10 MHz. 

30 Note: This option is useful to conbine spectral windows with very slight 

31 frequency differences caused by Doppler tracking, for example. 

32  

33 dirtol -- Direction shift tolerance for considering data as the same field 

34 default: '' means always combine. 

35 example: dirtol='1.arcsec' will not combine data for a field unless 

36 their phase center differ by less than 1 arcsec. If the field names 

37 are different in the input data sets, the name in the output data 

38 set will be the first relevant data set in the list. 

39 

40 copypointing -- copy all rows of the pointing table 

41 default: True 

42 """ 

43 

44 ### 

45 try: 

46 casalog.origin('testconcat') 

47 t = tbtool() 

48 m = mstool() 

49 #break the reference between vis and vislist as we modify vis 

50 if(type(vislist)==str): 

51 vis=[vislist] 

52 else: 

53 vis=list(vislist) 

54 

55 # test the consistency of the setup of the different MSs 

56 casalog.post('Checking MS setup consistency ...', 'INFO') 

57 try: 

58 mydiff = check_mslist(vis, ignore_tables=['SORTED_TABLE', 'ASDM*'], testcontent=False) 

59 except Exception as instance: 

60 raise RuntimeError("*** Error \'%s\' while checking MS setup consistency" % (instance)) 

61 

62 if mydiff != {}: 

63 casalog.post('The setup of the input MSs is not fully consistent. The concatenation may fail', 'WARN') 

64 casalog.post('and/or the affected columns may contain partially only default data.', 'WARN') 

65 casalog.post(str(mydiff), 'WARN') 

66 

67 if((type(testconcatvis)!=str) or (len(testconcatvis.split()) < 1)): 

68 raise Exception ('parameter testconcatvis is invalid') 

69 if(vis.count(testconcatvis) > 0): 

70 vis.remove(testconcatvis) 

71 

72 if(os.path.exists(testconcatvis)): 

73 raise Exception ('Visibility data set '+testconcatvis+' exists. Will not overwrite.') 

74 else: 

75 if(len(vis) >0): 

76 casalog.post('copying structure of '+vis[0]+' to '+testconcatvis , 'INFO') 

77 # Copy procedure which does not copy the bulk data of the main table 

78 t.open(vis[0]) 

79 tmptb = t.copy(newtablename=testconcatvis, deep=True, valuecopy=True, norows=True) # copy only table structure 

80 tmptb.close() 

81 t.close() 

82 # copy content of subtables 

83 thesubtables = [f.name for f in os.scandir(vis[0]) if f.is_dir()] 

84 

85 for subt in thesubtables: 

86 if not (subt[0]=='.'): 

87 t.open(vis[0]+'/'+subt) 

88 no_rows = False 

89 if (subt=='POINTING' and not copypointing): 

90 casalog.post('*** copypointing==False: resulting MS will have empty POINTING table', 'INFO') 

91 no_rows = True 

92 tmptb = t.copy(testconcatvis+'/'+subt, deep=False, valuecopy=True, norows=no_rows) 

93 tmptb.close() 

94 t.close() 

95 vis.remove(vis[0]) 

96 # determine handling switch value 

97 handlingswitch = 1 

98 if not copypointing: 

99 handlingswitch = 3 

100 

101 m.open(testconcatvis,False) # nomodify=False to enable writing 

102 

103 for elvis in vis : 

104 casalog.post('concatenating subtables from '+elvis+' into '+testconcatvis , 'INFO') 

105 

106 m.concatenate(msfile=elvis,freqtol=freqtol,dirtol=dirtol,handling=handlingswitch) 

107 

108 m.writehistory(message='taskname=testconcat',origin='testconcat') 

109 m.writehistory(message='vis = "'+str(testconcatvis)+'"',origin='testconcat') 

110 m.writehistory(message='concatvis = "'+str(elvis)+'"',origin='testconcat') 

111 m.writehistory(message='freqtol = "'+str(freqtol)+'"',origin='testconcat') 

112 m.writehistory(message='dirtol = "'+str(dirtol)+'"',origin='testconcat') 

113 m.writehistory(message='copypointing = "'+str(copypointing)+'"',origin='concat') 

114 

115 m.close() 

116 

117 except Exception as instance: 

118 print('*** Error ***',instance) 

119 raise Exception (instance) 

120