source: trunk/test/test_scantable.py@ 1722

Last change on this file since 1722 was 1600, checked in by Malte Marquarding, 15 years ago

Ticket #170: python derived class for nice access e.g. units and doc strings

File size: 5.0 KB
Line 
1import unittest
2import datetime
3from asap import scantable, selector, rcParams
4rcParams["verbose"] = False
5
6class ScantableTest(unittest.TestCase):
7 def setUp(self):
8
9 self.st = scantable("data/MOPS.rpf", average=True)
10
11 def test_init(self):
12 st = scantable("data/MOPS.rpf", average=False)
13 self.assertEqual(st.ncycle(), 32)
14 st = scantable("data/MOPS.rpf", average=True)
15 self.assertEqual(st.ncycle(), 2)
16 st = scantable("data/MOPS.rpf", unit="Jy")
17 self.assertEqual(st.get_fluxunit(), "Jy")
18 st = scantable("data/MOPS.rpf", unit="K")
19 self.assertEqual(st.get_fluxunit(), "K")
20 self.assertRaises(RuntimeError, scantable, "data/MOPS.rpf", unit="junk")
21 st = scantable(["data/MOPS.rpf","data/MOPS.rpf"], average=False)
22 self.assertEqual(st.nscan(), 4)
23
24 def test_copy(self):
25 st = self.st.copy()
26 self.assertNotEqual(id(st), id(self.st))
27
28 def test_drop_scan(self):
29 st = self.st.drop_scan([1])
30 self.assertEqual(st.nscan(), 1)
31
32 def test_get_scan(self):
33 st = self.st.get_scan([1])
34 self.assertEqual(st.nscan(), 1)
35 st = self.st.get_scan("Orion_SiO_R")
36 self.assertEqual(st.get_sourcename()[-1], "Orion_SiO_R")
37 self.assertEqual(st.nscan(), 1)
38
39 def test_get_spectrum(self):
40 spec = self.st.get_spectrum(0)
41 self.assertAlmostEqual(max(spec), 215.279830933)
42
43 def test_get_mask(self):
44 spec = self.st.get_mask(0)
45 self.assertEqual(len(spec), 4096)
46
47 def test_set_spectrum(self):
48 spec = [ 1.0 for i in range(self.st.nchan()) ]
49 self.st.set_spectrum(spec, 0)
50 spec1 = self.st.get_spectrum(0)
51 self.assertAlmostEqual(max(spec1), 1.0)
52
53 def test_selection(self):
54 sel = selector()
55 sel.set_polarisations("YY")
56 self.st.set_selection(sel)
57 self.assertEqual(self.st.getpolnos(), (1,))
58 sel1 = self.st.get_selection()
59 self.assertEqual(sel1.get_pols(), [1])
60 self.st.set_selection(pols="XX")
61 self.assertEqual(self.st.getpolnos(), (0,))
62
63 def test_stats(self):
64 stats = { 'min': 113.767166138,
65 'max':215.279830933, 'sumsq':128759200.0,
66 'sum':720262.375, 'mean':175.845306396,
67 'var':513.95324707, 'stddev':22.6705360413,
68 'avdev':16.3966751099, 'rms':177.300170898,
69 'median':182.891845703}
70 for k,v in stats.iteritems():
71 sval = self.st.stats(stat=k)
72 self.assertAlmostEqual(sval[0], v)
73 msk = self.st.create_mask([0,100], [3900,4096])
74 self.assertAlmostEqual(self.st.stats("sum", msk)[0], 35216.87890625)
75
76 def test_get_column_names(self):
77 cnames = ['SCANNO', 'CYCLENO', 'BEAMNO', 'IFNO',
78 'POLNO', 'FREQ_ID', 'MOLECULE_ID', 'REFBEAMNO',
79 'TIME', 'INTERVAL', 'SRCNAME', 'SRCTYPE',
80 'FIELDNAME', 'SPECTRA', 'FLAGTRA', 'TSYS',
81 'DIRECTION', 'AZIMUTH', 'ELEVATION',
82 'OPACITY', 'TCAL_ID', 'FIT_ID',
83 'FOCUS_ID', 'WEATHER_ID', 'SRCVELOCITY',
84 'SRCPROPERMOTION', 'SRCDIRECTION',
85 'SCANRATE']
86 self.assertEqual(self.st.get_column_names(), cnames)
87
88 def test_get_tsys(self):
89 self.assertAlmostEqual(self.st.get_tsys()[0], 175.830429077)
90
91 def test_get_time(self):
92 self.assertEqual(self.st.get_time(0), '2008/03/12/09:32:50')
93 dt = datetime.datetime(2008,3,12,9,32,50)
94 self.assertEqual(self.st.get_time(0, True), dt)
95
96 def test_get_inttime(self):
97 self.assertAlmostEqual(self.st.get_inttime()[0], 30.720016479)
98
99 def test_get_sourcename(self):
100 self.assertEqual(self.st.get_sourcename(0), 'Orion_SiO_R')
101 self.assertEqual(self.st.get_sourcename()[:2], ['Orion_SiO_R', 'Orion_SiO'])
102
103 def test_get_azimuth(self):
104 self.assertAlmostEqual(self.st.get_azimuth()[0], 5.628767013)
105
106 def test_get_elevation(self):
107 self.assertAlmostEqual(self.st.get_elevation()[0], 1.01711678504)
108
109 def test_get_parangle(self):
110 self.assertAlmostEqual(self.st.get_parangle()[0], 2.5921990871)
111
112 def test_get_direction(self):
113 self.assertEqual(self.st.get_direction()[0], '05:35:14.5 -04.52.29.5')
114
115 def test_get_directionval(self):
116 dv = self.st.get_directionval()[0]
117 self.assertAlmostEqual(dv[0], 1.4627692699)
118 self.assertAlmostEqual(dv[1], -0.0850824415)
119
120 def test_unit(self):
121 self.st.set_unit('')
122 self.st.set_unit('GHz')
123 self.st.set_unit('km/s')
124 self.assertRaises(RuntimeError, self.st.set_unit, 'junk')
125 self.assertEquals(self.st.get_unit(), 'km/s')
126
127 def test_average_pol(self):
128 ap = self.st.average_pol()
129 self.assertEqual(ap.npol(), 1)
130
131 def test_drop_scan(self):
132 s0 = self.st.drop_scan(1)
133 self.assertEqual(s0.getscannos(), (0,))
134 s1 = self.st.drop_scan([0])
135 self.assertEqual(s1.getscannos(), (1,))
136
137
138if __name__ == '__main__':
139 unittest.main()
Note: See TracBrowser for help on using the repository browser.