1 + | |
2 + | |
3 + | |
4 + | |
5 + | |
6 + | |
7 + | |
8 + | |
9 + | |
10 + | |
11 + | |
12 + | |
13 + | |
14 + | |
15 + | |
16 + | |
17 + | |
18 + | |
19 + | |
20 + | |
21 + | |
22 + | |
23 + | |
24 + | |
25 + | |
26 + | |
27 + | |
28 + | |
29 + | |
30 + | |
31 + | CASA6 = False |
32 + | try: |
33 + | import casatools |
34 + | from casatasks import ft |
35 + | from casatools import table, ctsys, componentlist |
36 + | tb = table() |
37 + | cl = componentlist() |
38 + | CASA6 = True |
39 + | except ImportError: |
40 + | from __main__ import default |
41 + | from tasks import * |
42 + | from taskinit import * |
43 + | |
44 + | from casa_stack_manip import stack_frame_find |
45 + | casa_stack_rethrow = stack_frame_find().get('__rethrow_casa_exceptions', False) |
46 + | import sys |
47 + | import os |
48 + | import unittest |
49 + | import shutil |
50 + | import numpy as np |
51 + | |
52 + | |
53 + | |
54 + | |
55 + | |
56 + | if CASA6: |
57 + | datapath = casatools.ctsys.resolve('unittest/ft/uid___X02_X3d737_X1_01_small.ms') |
58 + | modelpath = casatools.ctsys.resolve('unittest/ft/uid___X02_X3d737_X1_01_small.model') |
59 + | |
60 + | |
61 + | else: |
62 + | datapath = os.environ.get('CASAPATH').split()[0] + 'uid___X02_X3d737_X1_01_small.ms' |
63 + | modelpath = os.environ.get('CASAPATH').split()[0] + '/casatestdata/unittest/ft/uid___X02_X3d737_X1_01_small.model' |
64 + | |
65 + | |
66 + | datacopy = 'ft_test_copy.ms' |
67 + | modelcopy = 'ft_test_model_copy.model' |
68 + | |
69 + | nonStandardGridCopy = 'ft_test_nonstandard_gridder.model' |
70 + | |
71 + | ftcomponentlist = 'ft_test_comp_list.cl' |
72 + | |
73 + | def getColList(table): |
74 + | tb.open(table) |
75 + | columns = tb.colnames() |
76 + | tb.close() |
77 + | |
78 + | return columns |
79 + | |
80 + | class ft_test(unittest.TestCase): |
81 + | |
82 + | def setUp(self): |
83 + | if not CASA6: |
84 + | default(calstat) |
85 + | |
86 + | if not os.path.exists(datacopy): |
87 + | shutil.copytree(datapath, datacopy) |
88 + | if not os.path.exists(modelcopy): |
89 + | shutil.copytree(modelpath, modelcopy) |
90 + | |
91 + | |
92 + | |
93 + | def tearDown(self): |
94 + | shutil.rmtree(datacopy) |
95 + | shutil.rmtree(modelcopy) |
96 + | |
97 + | |
98 + | if os.path.exists(ftcomponentlist): |
99 + | shutil.rmtree(ftcomponentlist) |
100 + | |
101 + | def test_takesModel(self): |
102 + | ''' Test that a MODEL_DATA column is added to the MS when a *.model is provided ''' |
103 + | ft(vis=datacopy, model=modelcopy, usescratch=True) |
104 + | |
105 + | |
106 + | columns = getColList(datacopy) |
107 + | |
108 + | self.assertTrue('MODEL_DATA' in columns, msg='No MODEL_DATA added to the MS') |
109 + | |
110 + | def test_useScratch(self): |
111 + | ''' Test that when usescratch=True the model visibilites are stored in the MODEL_DATA column ''' |
112 + | |
113 + | ft(datacopy, model=modelcopy, usescratch=False) |
114 + | |
115 + | |
116 + | columns = getColList(datacopy) |
117 + | |
118 + | self.assertFalse('MODEL_DATA' in columns) |
119 + | |
120 + | ft(vis=datacopy, model=modelcopy, usescratch=True) |
121 + | |
122 + | |
123 + | columns = getColList(datacopy) |
124 + | |
125 + | self.assertTrue('MODEL_DATA' in columns) |
126 + | |
127 + | def test_takesComponentList(self): |
128 + | ''' Test that a MODEL_DATA column is added to the MS when a component list is provided ''' |
129 + | |
130 + | cl.addcomponent(shape='point', flux=1, fluxunit='Jy', spectrumtype='spectral index', |
131 + | index=-0.8, freq='1,23GHz', dir='J2000 12h33m45.3s -23d01m11.2s') |
132 + | cl.rename(ftcomponentlist) |
133 + | cl.close() |
134 + | |
135 + | ft(vis=datacopy, complist=ftcomponentlist, usescratch=True) |
136 + | |
137 + | |
138 + | columns = getColList(datacopy) |
139 + | |
140 + | self.assertTrue('MODEL_DATA' in columns) |
141 + | |
142 + | def test_multiTermImage(self): |
143 + | ''' Test that multi-term Images are properly handled ''' |
144 + | |
145 + | ft(vis=datacopy, model=modelcopy, usescratch=True) |
146 + | |
147 + | |
148 + | columns = getColList(datacopy) |
149 + | |
150 + | self.assertTrue('MODEL_DATA' in columns, msg='No MODEL_DATA added to the MS') |
151 + | |
152 + | def test_addModel(self): |
153 + | ''' Test that with incremental=True the new model will be added instead of replacing the old one ''' |
154 + | |
155 + | pass |
156 + | |
157 + | def test_componentListModelPriority(self): |
158 + | ''' Test that when a model and comp list are provided only the model is used ''' |
159 + | |
160 + | cl.addcomponent(shape='point', flux=1, fluxunit='Jy', spectrumtype='spectral index', |
161 + | index=-0.8, freq='1,23GHz', dir='J2000 12h33m45.3s -23d01m11.2s') |
162 + | cl.rename(ftcomponentlist) |
163 + | cl.close() |
164 + | |
165 + | ft(vis=datacopy, model=modelcopy, usescratch=True) |
166 + | |
167 + | |
168 + | tb.open(datacopy) |
169 + | model_only = tb.getcol('MODEL_DATA') |
170 + | print(np.mean(model_only)) |
171 + | tb.close() |
172 + | |
173 + | |
174 + | shutil.rmtree(datacopy) |
175 + | shutil.copytree(datapath, datacopy) |
176 + | |
177 + | |
178 + | ft(vis=datacopy, model=modelcopy, complist=ftcomponentlist, usescratch=True) |
179 + | |
180 + | tb.open(datacopy) |
181 + | model_complist = tb.getcol('MODEL_DATA') |
182 + | print(np.mean(model_complist)) |
183 + | tb.close() |
184 + | |
185 + | |
186 + | |
187 + | self.fail() |
188 + | |
189 + | def test_modelReplace(self): |
190 + | ''' When incremental = False the existing model should be replaced in MODEL_DATA ''' |
191 + | |
192 + | cl.addcomponent(shape='point', flux=1, fluxunit='Jy', spectrumtype='spectral index', |
193 + | index=-0.8, freq='1,23GHz', dir='J2000 12h33m45.3s -23d01m11.2s') |
194 + | cl.rename(ftcomponentlist) |
195 + | cl.close() |
196 + | |
197 + | |
198 + | ft(vis=datacopy, complist=ftcomponentlist, usescratch=True) |
199 + | |
200 + | |
201 + | tb.open(datacopy) |
202 + | originalMean = np.mean(tb.getcol('MODEL_DATA')) |
203 + | tb.close() |
204 + | |
205 + | |
206 + | ft(vis=datacopy, model=modelcopy, usescratch=True) |
207 + | |
208 + | tb.open(datacopy) |
209 + | finalMean = np.mean(tb.getcol('MODEL_DATA')) |
210 + | tb.close() |
211 + | |
212 + | self.assertFalse(np.isclose(finalMean, originalMean)) |
213 + | |
214 + | def test_spwSelection(self): |
215 + | ''' Test spw selection parameter ''' |
216 + | ft(vis=datacopy, model=modelcopy, usescratch=True, spw='0') |
217 + | |
218 + | |
219 + | tb.open(datacopy) |
220 + | finalMean = np.mean(tb.getcol('MODEL_DATA')) |
221 + | tb.close() |
222 + | |
223 + | self.assertTrue(np.isclose(finalMean, (0.0001953125+0j))) |
224 + | |
225 + | def test_fieldSelection(self): |
226 + | ''' Test the field selection parameter ''' |
227 + | ft(vis=datacopy, model=modelcopy, usescratch=True, field='0') |
228 + | |
229 + | |
230 + | tb.open(datacopy) |
231 + | finalMean = np.mean(tb.getcol('MODEL_DATA')) |
232 + | tb.close() |
233 + | |
234 + | self.assertTrue(np.isclose(finalMean, (0.11119791666666667+0j))) |
235 + | |
236 + | |
237 + | |
238 + | def suite(): |
239 + | return[ft_test] |
240 + | |
241 + | if __name__ == '__main__': |
242 + | unittest.main() |
243 + | |