Commits

Neal Schweighart authored 5ed5cc5ca24
Added current version of the ft req test
No tags

casa5/gcwrap/python/scripts/tests/test_req_task_ft.py

Added
1 +##########################################################################
2 +# test_req_task_ft.py
3 +#
4 +# Copyright (C) 2018
5 +# Associated Universities, Inc. Washington DC, USA.
6 +#
7 +# This script is free software; you can redistribute it and/or modify it
8 +# under the terms of the GNU Library General Public License as published by
9 +# the Free Software Foundation; either version 2 of the License, or (at your
10 +# option) any later version.
11 +#
12 +# This library is distributed in the hope that it will be useful, but WITHOUT
13 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15 +# License for more details.
16 +#
17 +# [Add the link to the JIRA ticket here once it exists]
18 +#
19 +# Based on the requirements listed in plone found here:
20 +# https://casa.nrao.edu/casadocs/casa-5.4.0/global-task-list/task_ft/about
21 +#
22 +# Test_logreturn checks to make sure a logfile is generated and populated
23 +# Test_dictreturn checks that the result is a python dict object containing keys specified in the documentation
24 +# Test_takescal checks that a caltable is accepted and non-cal tables are rejected
25 +# Test_axis checks that different axis vaules will provide different information
26 +# Test_axisvals checks that the values for axis provided in the documentatin are accepted as valid values
27 +# Test_datacolumn checks that different datacolumn values provide different information
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 +# Gaincaltest and gaussian model with noise
53 +# Need model w/o standard gridder
54 +# Need new model for model/complist preference?
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 + #multitermpath = 'PLACEHOLDER'
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 + #multitermpath = 'PLACEHOLDER'
65 +
66 +datacopy = 'ft_test_copy.ms'
67 +modelcopy = 'ft_test_model_copy.model'
68 +#multitermcopy = 'ft_test_multi_term.model'
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 + #if not os.path.exists(multitermcopy):
91 + #shutil.copytree(multitermpath, multitermcopy)
92 +
93 + def tearDown(self):
94 + shutil.rmtree(datacopy)
95 + shutil.rmtree(modelcopy)
96 + #shutil.rmtree(multitermcopy)
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 + # Find the MODEL_DATA column
106 + columns = getColList(datacopy)
107 + # Make sure MODEL_DATA is in the MS ONLY IF USESCRATCH=TRUE
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 + # first test that no MODEL_DATA column is created when usescratch = False
113 + ft(datacopy, model=modelcopy, usescratch=False)
114 +
115 + # get the columns list
116 + columns = getColList(datacopy)
117 + # Make sure there is no MODEL_DATA
118 + self.assertFalse('MODEL_DATA' in columns)
119 +
120 + ft(vis=datacopy, model=modelcopy, usescratch=True)
121 +
122 + # Find the MODEL_DATA column
123 + columns = getColList(datacopy)
124 + # Check that the MODEL_DATA column exists
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 + # Create the complist to use in the test
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 + # Run the ft command
135 + ft(vis=datacopy, complist=ftcomponentlist, usescratch=True)
136 +
137 + # Find the MODEL_DATA column
138 + columns = getColList(datacopy)
139 + # Check that the MODEL_DATA column exists
140 + self.assertTrue('MODEL_DATA' in columns)
141 +
142 + def test_multiTermImage(self):
143 + ''' Test that multi-term Images are properly handled '''
144 + # Change to multiterm
145 + ft(vis=datacopy, model=modelcopy, usescratch=True)
146 +
147 + # Find the MODEL_DATA column
148 + columns = getColList(datacopy)
149 + # Make sure MODEL_DATA is in the MS ONLY IF USESCRATCH=TRUE
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 + # Create the complist to use in the test
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 + # First run ft with only the model
165 + ft(vis=datacopy, model=modelcopy, usescratch=True)
166 +
167 + # Get the MODEL_DATA col
168 + tb.open(datacopy)
169 + model_only = tb.getcol('MODEL_DATA')
170 + print(np.mean(model_only))
171 + tb.close()
172 +
173 + # start with a fresh copy of the data
174 + shutil.rmtree(datacopy)
175 + shutil.copytree(datapath, datacopy)
176 +
177 + # Now run ft with both
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 + # The result should be the same MODEL_DATA col for both
186 + # self.assertTrue(np.all(np.isclose(model_only, model_complist)))
187 + self.fail()
188 +
189 + def test_modelReplace(self):
190 + ''' When incremental = False the existing model should be replaced in MODEL_DATA '''
191 + # Create the complist to use in the test
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 + # Run ft with the complist
198 + ft(vis=datacopy, complist=ftcomponentlist, usescratch=True)
199 +
200 + # Get the mean of the MODEL_DATA
201 + tb.open(datacopy)
202 + originalMean = np.mean(tb.getcol('MODEL_DATA'))
203 + tb.close()
204 +
205 + # Run ft with a new model
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 + # get the mean value of MODEL_DATA
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 + # get the mean value of MODEL_DATA
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 + # Test for nterms and reffreq, requires additional models
237 +
238 +def suite():
239 + return[ft_test]
240 +
241 +if __name__ == '__main__':
242 + unittest.main()
243 +

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut