Commits

Neal Schweighart authored 27e84b0a23f
Moved the merged req test to casatasks

casatasks/tests/tasks/test_importuvfits.py

Deleted
1 -import os
2 -import numpy
3 -import sys
4 -import shutil
5 -import unittest
6 -
7 -import numpy as np
8 -
9 -from casatasks import importuvfits
10 -
11 -from casatools import ctsys
12 -from casatools import ms as mstool
13 -from casatools import msmetadata as msmdtool
14 -from casatools import table as tbtool
15 -from casatools import quanta
16 -
17 -'''
18 -Unit tests for UVFITS I/O tasks.
19 -
20 -Features tested:
21 - 0. Can multiple spws with the same # of channels be exported to UVFITS
22 - using padwithflags?
23 - 1. When that UVFITS file is read back in, is its data still correct?
24 -'''
25 -
26 -datapath = ctsys.resolve('unittest/importuvfits/')
27 -
28 -def check_eq(val, expval, tol=None):
29 - """Checks that val matches expval within tol."""
30 - try:
31 - if tol:
32 - are_eq = abs(val - expval) < tol
33 - else:
34 - are_eq = val == expval
35 - if hasattr(are_eq, 'all'):
36 - are_eq = are_eq.all()
37 - if not are_eq:
38 - raise ValueError('!=')
39 - except ValueError:
40 - raise ValueError("%r != %r" % (val, expval))
41 -
42 -
43 -class importuvfits_test(unittest.TestCase):
44 - # 06/13/2010: This seemed to be the only MS in the regression repo
45 - # that is a good test of padwithflag.
46 - inpms = 'cvel/input/ANTEN_sort_hann_for_cvel_reg.ms'
47 -
48 - origms = 'start.ms' # Just a copy of inpms
49 - fitsfile = 'hanningsmoothed.UVF'
50 - msfromfits = 'end.ms'
51 -
52 - records = {}
53 - need_to_initialize = True # Do once, at start.
54 - do_teardown = False # Do once, after initializing and filling records.
55 - # Its value here should not really matter.
56 -
57 - def setUp(self):
58 - self.qa = quanta( )
59 - #pass
60 - #if self.need_to_initialize:
61 - # self.initialize()
62 -
63 - #def initialize(self):
64 - # The realization that need_to_initialize needs to be
65 - # a class variable more or less came from
66 - # http://www.gossamer-threads.com/lists/python/dev/776699
67 - # self.__class__.need_to_initialize = False
68 -
69 - # if not os.path.exists(self.origms):
70 - # Copying is technically unnecessary for split,
71 - # but self.self.origms is shared by other tests, so making
72 - # it readonly might break them.
73 - # shutil.copytree(datapath + self.inpms, self.origms)
74 -
75 - # if os.path.exists(self.fitsfile):
76 - # os.remove(self.fitsfile)
77 -
78 - # try:
79 - # exportuvfits(self.origms, self.fitsfile, padwithflags=True)
80 - # self.records['exported'] = os.path.exists(self.fitsfile)
81 -
82 - # if self.records['exported']:
83 - # importuvfits(self.fitsfile, self.msfromfits)
84 - # except Exception, e:
85 - # print "Error exporting or importing uv data"
86 - # raise e
87 -
88 -
89 - def tearDown(self):
90 - if self.do_teardown:
91 - self.qa.done( )
92 - shutil.rmtree(self.origms)
93 - shutil.rmtree(self.msfromfits)
94 - os.remove(self.fitsfile)
95 - self.do_teardown = False
96 -
97 - #def test_sts(self):
98 - # """Subtables, time avg. without correlation selection"""
99 - # self.check_subtables('', [(4, 1)])
100 -
101 - #def test_data(self):
102 - # """DATA[2], time avg. without correlation selection"""
103 - # check_eq(self.records['']['data'],
104 - # numpy.array([[ 0.14428490-0.03145669j],
105 - # [-0.00379944+0.00710297j],
106 - # [-0.00381106-0.00066403j],
107 - # [ 0.14404297-0.04763794j]]),
108 - # 0.0001)
109 -
110 - #def test_wt(self):
111 - # """WEIGHT[5], time avg. without correlation selection"""
112 - # check_eq(self.records['']['weight'],
113 - # numpy.array([143596.34375, 410221.34375,
114 - # 122627.1640625, 349320.625]),
115 - # 1.0)
116 -
117 - def test_receptor_angle(self):
118 - """CAS-7081: Test receptor angle is preserved"""
119 - myms = mstool()
120 - msname = os.path.join(datapath, "uvfits_test.ms")
121 - self.assertTrue(myms.open(msname), "Input dataset not found")
122 - uvfits = "xyz.uvfits"
123 - self.assertTrue(myms.tofits(uvfits), "Failed to write uvfits")
124 - myms.done()
125 - feed = "/FEED"
126 - mytb = tbtool()
127 - mytb.open(msname + feed)
128 - rec_ang = "RECEPTOR_ANGLE"
129 - expec = mytb.getcol(rec_ang)
130 - mytb.done()
131 - importname = "kf.ms"
132 - importuvfits(fitsfile=uvfits, vis=importname)
133 - mytb.open(importname + feed)
134 - got = mytb.getcol(rec_ang)
135 - mytb.done()
136 - self.assertTrue(np.max(np.abs(got-expec)) < 1e-7, "Receptor angles not preserved")
137 -
138 -def suite():
139 - return [importuvfits_test]
140 -
141 -if __name__ == '__main__':
142 - unittest.main()

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

Add shortcut