Commits
Sandra Castro authored 3150aa9dde7 Merge
1 - | from __future__ import absolute_import |
2 - | from __future__ import print_function |
3 - | import os |
4 - | import sys |
5 - | import shutil |
6 - | import unittest |
7 - | |
8 - | from casatasks.private.casa_transition import is_CASA6 |
9 - | if is_CASA6: |
10 - | from casatools import ctsys |
11 - | from casatools import ms as mstool |
12 - | from casatools import msmetadata as msmdtool |
13 - | from casatasks import fixplanets |
14 - | |
15 - | ctsys_resolve = ctsys.resolve |
16 - | else: |
17 - | from __main__ import default |
18 - | from tasks import * |
19 - | from taskinit import * |
20 - | |
21 - | def ctsys_resolve(apath): |
22 - | dataPath = os.path.join(os.environ['CASAPATH'].split()[0],'casatestdata/') |
23 - | return os.path.join(dataPath,apath) |
24 - | |
25 - | ''' |
26 - | Unit tests for task fixplanets. |
27 - | |
28 - | Features tested: |
29 - | 1. Does a standard fixplanets work on an MS imported from an ASDM from April 2011 |
30 - | 2. Does the setting of a given direction work on an MS imported from an ASDM from April 2011 |
31 - | 3. Does the setting of a given direction with ref !=J2000 and != sol.sys. object give the expected error? |
32 - | 4. Does the setting of a given direction work with a sol system ref frame |
33 - | 5. Does the use of an ephemeris via the direction parameter work |
34 - | |
35 - | ''' |
36 - | datapath = ctsys_resolve('unittest/fixplanets/') |
37 - | outms = 'uid___A002_X1c6e54_X223-thinned.ms' |
38 - | inpms = os.path.join(datapath, outms) |
39 - | outms2 = 'uid___A002_X1c6e54_X223-thinned.mms/' |
40 - | inpms2 = os.path.join(datapath,outms2) |
41 - | |
42 - | mymst = mstool() |
43 - | mymsmdt = msmdtool() |
44 - | |
45 - | |
46 - | class fixplanets_test1(unittest.TestCase): |
47 - | def setUp(self): |
48 - | res = None |
49 - | shutil.rmtree(outms, ignore_errors=True) |
50 - | shutil.copytree(inpms, outms) |
51 - | shutil.rmtree(outms2, ignore_errors=True) |
52 - | os.system('cp -R '+ inpms2 + ' ' + outms2) |
53 - | if not is_CASA6: |
54 - | default(fixplanets) |
55 - | |
56 - | def tearDown(self): |
57 - | shutil.rmtree(outms, ignore_errors=True) |
58 - | shutil.rmtree(outms2, ignore_errors=True) |
59 - | |
60 - | def verify(self, thems, thefield, theref): |
61 - | therval = True |
62 - | mymsmdt.open(thems) |
63 - | thefieldids = mymsmdt.fieldsforname(thefield) |
64 - | mymsmdt.close() |
65 - | mymst.open(thems) |
66 - | thedir = mymst.getfielddirmeas(fieldid=thefieldids[0]) |
67 - | mymst.close() |
68 - | print("Read direction result %s" % thedir) |
69 - | if not (thedir['refer']==theref): |
70 - | print("ERROR: reference not as expected: expected %s, got %s" % (theref,thedir['refer'])) |
71 - | therval = False |
72 - | return therval |
73 - | |
74 - | def test1(self): |
75 - | '''test1: Does a standard fixplanets work on an MS imported from an ASDM from April 2011''' |
76 - | for myms in [outms,outms2]: |
77 - | fixplanets(myms, 'Titan', True) |
78 - | |
79 - | def test2(self): |
80 - | '''test2: Does the setting of a given direction work on an MS imported from an ASDM from April 2011''' |
81 - | for myms in [outms,outms2]: |
82 - | fixplanets(myms, 'Titan', False, 'J2000 0h0m0s 0d0m0s') |
83 - | self.assertTrue(self.verify(myms, 'Titan', 'J2000')) |
84 - | |
85 - | def test3(self): |
86 - | '''test3: Does the setting of a given direction with ref !=J2000 and != sol.sys. object give the expected error?''' |
87 - | for myms in [outms,outms2]: |
88 - | with self.assertRaises(RuntimeError): |
89 - | fixplanets(myms, 'Titan', False, 'B1950 0h0m0s 0d0m0s') |
90 - | |
91 - | def test4(self): |
92 - | '''test4: Does the setting of a given direction work with a sol system ref frame?''' |
93 - | for myms in [outms,outms2]: |
94 - | fixplanets(myms, 'Titan', False, 'SATURN 0h0m0s 0d0m0s') |
95 - | self.assertTrue(self.verify(myms, 'Titan', 'SATURN')) |
96 - | |
97 - | def test5(self): |
98 - | '''test5: Does a standard fixplanets work on an MS imported from an ASDM from April 2011 with parameter reftime''' |
99 - | for myms in [outms,outms2]: |
100 - | fixplanets(vis=myms, field='Titan', fixuvw=True, reftime='median') |
101 - | |
102 - | def test6(self): |
103 - | '''test6: Does a standard fixplanets with put of bounds parameter reftime give the expected error''' |
104 - | for myms in [outms,outms2]: |
105 - | with self.assertRaises(TypeError): |
106 - | fixplanets(vis=myms, field='Titan', fixuvw=True, reftime='2012/07/11/08:41:32') |
107 - | |
108 - | def test7(self): |
109 - | '''test7: Does a standard fixplanets with wrong parameter reftime give the expected error''' |
110 - | for myms in [outms,outms2]: |
111 - | with self.assertRaises(TypeError): |
112 - | fixplanets(vis=myms, field='Titan', fixuvw=True, reftime='MUDIAN') |
113 - | |
114 - | def test8(self): |
115 - | '''test8: Does a fixplanets with an ephemeris work''' |
116 - | for myms in [outms,outms2]: |
117 - | fixplanets(vis=myms, field='Titan', fixuvw=True, |
118 - | direction=os.path.join(datapath,'Titan_55437-56293dUTC.tab') ) |
119 - | |
120 - | self.assertTrue(os.path.exists(myms+'/FIELD/EPHEM0_Titan.tab')) |
121 - | self.assertTrue(self.verify(myms, 'Titan', 'APP')) |
122 - | |
123 - | def test9(self): |
124 - | '''test9: Does a fixplanets with an ephemeris in mime format work''' |
125 - | os.system('cp '+ os.path.join(datapath,'titan.eml')+' .') |
126 - | for myms in [outms,outms2]: |
127 - | os.system("rm -rf titan.eml.tab") |
128 - | fixplanets( vis=myms, field='Titan', fixuvw=True, direction='titan.eml' ) |
129 - | |
130 - | self.assertTrue(os.path.exists(myms+'/FIELD/EPHEM0_Titan.tab')) |
131 - | self.assertTrue(self.verify(myms, 'Titan', 'J2000')) |
132 - | |
133 - | def suite(): |
134 - | return [fixplanets_test1] |
135 - | |
136 - | if is_CASA6: |
137 - | if __name__ == '__main__': |
138 - | unittest.main() |