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

57 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-01 07:19 +0000

1import os 

2 

3from casatools import imager, ms, image, quanta 

4from casatasks import casalog 

5 

6_im = imager( ) 

7_ms = ms( ) 

8_ia = image( ) 

9 

10def ft(vis=None,field=None,spw=None,model=None,nterms=None,reffreq=None,complist=None,incremental=None, usescratch=None): 

11 """ Insert a source model into the MODEL_DATA column of a visibility set: 

12 

13 A source model (souce.model image) or components list is converted into a 

14 model visibility that is inserted into the MODEL_DATA column. This is 

15 needed to use resolved source in gaincal and in fluxscale. (Setjy will 

16 automatically make this ft step.) 

17 

18 The sources currently available are 3C48, 3C138, 3C147, 3C286 

19 at 1.4, 5.0, 8.4, 15, 22, 43 GHz. Their location is site 

20 dependent. In Charlottesville and at the AOC, the models are 

21 in /usr/lib/casapy/data/nrao/VLA/CalModels. 

22 

23 Keyword arguments: 

24 vis -- Name of input visibility file 

25 default: none; example: vis='ngc5921.ms' 

26 field -- Field name list 

27 default: '' ==> all 

28 NOTE: each source must be specified in a multi-source vis. 

29 field = '1328+307' specifies source '1328+307' 

30 field = '4' specified field with index 4 

31 spw -- Spw selection 

32 default: spw = '' (all spw) 

33 model -- Name of input model image 

34 default: None; 

35 example: model='/usr/lib/casapy/data/nrao/VLA/CalModels/3C286_X.im' 

36 Note: The model visibilities are scaled from the model frequency 

37 to the observed frequency of the data. 

38 nterms -- Number of terms used to model the sky frequency dependence 

39 default: 1 

40 example : nterms=3 represents a 2nd order Taylor-polynomial in frequency 

41 and is to be used along with 3 model-image names.  

42 model=['xxx.image.tt0','xxx.image.tt1', 'xxx.image.tt2'] 

43 reffreq -- Reference-frequency about which this Taylor-expansion is defined. 

44 complist -- Name of component list 

45 default: None; ; example: complist='test.cl' 

46 components tool not yet available 

47 incremental -- Add model visibility to the existing MODEL_DATA visibilties 

48 default: False; example: incremental=True 

49 

50 """ 

51 casalog.origin('ft') 

52 

53 #Python script 

54 

55 # Check if datafile exists and open it 

56 if ((type(vis)==str) & (os.path.exists(vis))): 

57 _im.open(vis, usescratch=usescratch) 

58 else: 

59 raise ValueError('Visibility data set not found - please verify the name') 

60 

61 # Select data 

62 _im.selectvis(field=field,spw=spw) 

63 

64 # Define image co-ordinates (all defaults) 

65 #_im.defineimage() 

66 

67 # Check 'model'. The 'xml' allows a variant => do the checking here. 

68 if( (not type(model)==str) and (not (type(model)==list) ) ) : 

69 raise ValueError('The model image must be a string or a list of strings (or \'\' or [])') 

70 

71 # If model is a single string, make it a list 

72 if( type(model)==str ): 

73 model = [model]; 

74 

75 # Check that either a model or a complist has been given. 

76 if( (model==[] or model==['']) and complist=='' ): 

77 raise ValueError('Please specify a model image or component list to ft') 

78 

79 #model is a list now. Check that all elements are strings. If so, check file existence too. 

80 if( type(model)==list ): 

81 for onemodel in model: 

82 if(not type(onemodel)==str): 

83 raise ValueError('Model image names must be strings') 

84 if( (not onemodel=='') and (not os.path.exists(onemodel)) ): 

85 raise ValueError('Model image '+onemodel+' cannot be found') 

86 

87 # Check complist : one string : name of complist file. Check existance on disk. 

88 if( (not complist=='') and (not os.path.exists(complist)) ): 

89 raise ValueError('Componentlist '+complist+' cannot be found') 

90 

91 

92 # If nterms>1, then check that len(model)=nterms [ no multifield for now ] 

93 # Call _im.settaylorterms() 

94 # 

95 if (nterms > 1) : 

96 if(type(model)==str or (not (type(model)==list and len(model)==nterms)) ): 

97 raise ValueError('For nterms>1, please provide a list of nterms model-image names') 

98 # parse the reference-frequency field. 

99 qat=quanta(); 

100 try: 

101 rff=qat.canonical(reffreq); 

102 except Exception: 

103 msg = '*** Error *** In conversion of reffreq=\'',reffreq,'\' to a numerical value' 

104 raise RuntimeError(msg) 

105 

106 reffreqVal=rff['value']; # This is the frequency in Hz 

107 if(reffreqVal==0.0): # if unspecified, set the default from the model image 

108 _ia.open(model[0]); 

109 icsys = _ia.coordsys(); 

110 _ia.close(); 

111 reffreqVal=icsys.referencevalue(type='spectral')['numeric'][0]; 

112 casalog.post('Using reference frequency from model image : '+str(reffreqVal)+' Hz'); 

113 else: 

114 casalog.post('Using reference frequency : '+str(reffreqVal)+' Hz'); 

115 # set nterms and ref-freq 

116 _im.settaylorterms(ntaylorterms=nterms,reffreq=reffreqVal) 

117 

118 # Just checking... 

119 if (nterms < 1) : 

120 raise ValueError('nterms must be greater than or equal to 1') 

121 

122 

123 # Do the forward transform and close. 

124 _im.ft(model=model,complist=complist,incremental=incremental) 

125 _im.close() 

126 

127 

128 #write history 

129 _ms.open(vis,nomodify=False) 

130 _ms.writehistory(message='taskname = ft',origin='ft') 

131 _ms.writehistory(message='vis = "'+str(vis)+'"',origin='ft') 

132 _ms.writehistory(message='field = "'+str(field)+'"',origin='ft') 

133 _ms.writehistory(message='spw = "'+str(spw)+'"',origin='ft') 

134 _ms.writehistory(message='model = "'+str(model)+'"',origin='ft') 

135 _ms.writehistory(message='complist = "'+str(complist)+'"',origin='ft') 

136 _ms.writehistory(message='incremental = "'+str(incremental)+'"',origin='ft') 

137 _ms.close()